@hyzyn/dsh-tty 0.20.1 → 0.20.2

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/client.js CHANGED
@@ -2005,9 +2005,20 @@ void main() {
2005
2005
  .tt_tunnelEndpoints {
2006
2006
  display: flex;
2007
2007
  align-items: center;
2008
- gap: 8px;
2008
+ gap: 8px 10px;
2009
2009
  flex-wrap: wrap;
2010
2010
  }
2011
+ /*
2012
+ * \u4E00\u7AEF + \u5B83\u7684\u51FA\u5411\u7BAD\u5934\uFF08"\u8DF3"\uFF09\u3002\u7BAD\u5934\u5FC5\u987B\u8DDF\u6E90\u7AEF\u70B9\u540C\u7EC4\uFF1A\u7559\u5728\u5916\u9762\u65F6\u7A84\u5BB9\u5668\u4F1A\u5148\u6362\u884C\u6210
2013
+ * \u300C\u7AEF\u70B9 A / \u2192 / \u7AEF\u70B9 B\u300D\u2014\u2014\u7BAD\u5934\u5B64\u96F6\u96F6\u5360\u4E00\u884C\uFF0C\u8BFB\u4E0D\u51FA\u5B83\u8FDE\u7684\u662F\u54EA\u4E24\u7AEF\u3002
2014
+ */
2015
+ .tt_tunnelHop {
2016
+ display: flex;
2017
+ align-items: center;
2018
+ gap: 8px;
2019
+ flex: 1 1 auto;
2020
+ min-width: 0;
2021
+ }
2011
2022
  /* \u4E00\u4E2A\u7AEF\u70B9 = \u4E3B\u673A + \u5192\u53F7 + \u7AEF\u53E3\uFF1B\u7528\u540C\u4E00\u5E95\u8272\u8FDE\u6210\u4E00\u4F53\uFF0C\u770B\u5F97\u51FA\u662F\u4E00\u7EC4 */
2012
2023
  .tt_tunnelEndpoint {
2013
2024
  display: flex;
@@ -2040,7 +2051,9 @@ void main() {
2040
2051
  /* \u4E2D\u95F4\u7684\u5206\u9694\u5192\u53F7 */
2041
2052
  .tt_tunnelColon {
2042
2053
  flex: none;
2043
- padding: 0 2px;
2054
+ /* 4px \u800C\u4E0D\u662F 2px\uFF1A\u5360\u4F4D\u7B26\u88AB\u88C1\u77ED\u65F6\uFF0C\u5192\u53F7\u4E0E\u622A\u65AD\u6587\u672C\u4E4B\u95F4\u8981\u6709\u6E05\u695A\u7684\u95F4\u9694\uFF0C
2055
+ \u5426\u5219\u300C\u670D\u52A1\u5668\u4FA7\u4E3B\u673A\uFF08\u5982 db\u300D+\u300C:\u300D\u4F1A\u8BFB\u6210\u4E00\u4E32 */
2056
+ padding: 0 4px;
2044
2057
  color: var(--tt-label-3);
2045
2058
  user-select: none;
2046
2059
  }
@@ -2061,6 +2074,22 @@ void main() {
2061
2074
  .tt_tunnelArrow[data-direction='remote'] {
2062
2075
  transform: rotate(180deg);
2063
2076
  }
2077
+ /* \u65B9\u5411\u884C\uFF08\u5206\u6BB5\u63A7\u4EF6 + \u8FDE\u63A5\u7C3F\u4E0B\u62C9\uFF09\uFF1A\u7A84\u5BB9\u5668\u4E0B\u8BA9\u4E0B\u62C9\u53EF\u6536\u7F29\u5E76\u5141\u8BB8\u6362\u884C\uFF0C\u522B\u9876\u51FA\u5361\u7247\u53F3\u7F18 */
2078
+ .tt_tunnelHead .tt_cardInput {
2079
+ flex: 1 1 180px;
2080
+ min-width: 0;
2081
+ }
2082
+ /* \u52A8\u4F5C\u884C\uFF08\u4FDD\u5B58 / \u53D6\u6D88 + \u8BF4\u660E\uFF09\uFF1A\u6309\u94AE\u4E0D\u53C2\u4E0E\u6536\u7F29\uFF08\u5426\u5219\u6587\u5B57\u4F1A\u88AB\u6324\u6210\u7AD6\u6392\uFF09\uFF0C\u8BF4\u660E\u81EA\u5DF1\u6362\u884C */
2083
+ .tt_tunnelActions .tt_cardSave,
2084
+ .tt_tunnelActions .tt_toolBtn {
2085
+ flex: none;
2086
+ white-space: nowrap;
2087
+ }
2088
+ .tt_tunnelActions .tt_cardHint {
2089
+ flex: 1 1 220px;
2090
+ min-width: 0;
2091
+ margin-top: 0;
2092
+ }
2064
2093
  /* \u5206\u6BB5\u63A7\u4EF6\uFF08\u672C\u5730 / \u8FDC\u7A0B\uFF09\uFF1A\u4E24\u4E2A\u503C\u4E0D\u503C\u5F97\u7528\u4E0B\u62C9\u6846\uFF0C\u4E00\u6B21\u70B9\u51FB\u5C31\u80FD\u5207 */
2065
2094
  .tt_segmented {
2066
2095
  display: inline-flex;
@@ -2624,6 +2653,8 @@ void main() {
2624
2653
  flex-direction: row;
2625
2654
  align-items: center;
2626
2655
  gap: var(--tt-gap-md);
2656
+ /* \u7A84\u5BB9\u5668\u91CC\u5B81\u53EF\u6362\u884C\u4E5F\u4E0D\u6A2A\u5411\u6EA2\u51FA\uFF08\u4E0B\u62C9\u6846\u9ED8\u8BA4 min-width:auto \u4F1A\u9876\u51FA\u5361\u7247\uFF09 */
2657
+ flex-wrap: wrap;
2627
2658
  }
2628
2659
  .tt_cardHint {
2629
2660
  margin-top: 2px;
@@ -2678,7 +2709,7 @@ void main() {
2678
2709
  }
2679
2710
  }
2680
2711
  `;var fn="\0global";function cr(e,t){return e===null?fn:typeof e=="string"&&e!==""?e:typeof t=="string"&&t!==""?t:fn}function _n(e,t){return e===fn?!0:typeof t=="string"&&t!==""&&e===t}function pn(e){return String(e??"").trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_").replace(/^_+|_+$/g,"")}function rl(e,t,r,s){let o=pn(r),i=pn(e);if(o===""||i==="")return"";let n=pn(t),a=["DSH_TTY",o,i];return n!==""&&n!=="22"&&a.push(n),a.push(s),a.join("_")}function Hi(e){let t=Number(e);return Number.isInteger(t)&&t>=1&&t<=65535?t:0}function il(e,t,r){return`${e}-${t==="remote"?"R":"L"}${String(r)}`}function sl(e,t=[]){let r=e??{},s=String(r.bookName??"")||String(t[0]??"")||"";if(s==="")return{ok:!1,error:"\u8BF7\u5148\u5728\u8FDE\u63A5\u7C3F\u91CC\u6DFB\u52A0 SSH \u6761\u76EE"};if(r.direction==="remote"){let a=Hi(r.remotePort),f=Hi(r.localTargetPort);return a<1||f<1?{ok:!1,error:"\u8FDC\u7A0B\u76D1\u542C\u7AEF\u53E3\u4E0E\u672C\u5730\u76EE\u6807\u7AEF\u53E3\u5FC5\u586B\uFF081~65535\uFF09"}:{ok:!0,tunnel:{name:il(s,"remote",a),bookName:s,direction:"remote",remotePort:a,localTargetHost:"",localTargetPort:f,enabled:!0}}}let o=Hi(r.localPort),i=String(r.remoteHost??"").trim(),n=Hi(r.remotePort);return o<1||i===""||n<1?{ok:!1,error:"\u672C\u5730\u7AEF\u53E3\u3001\u8FDC\u7A0B\u4E3B\u673A\u3001\u8FDC\u7A0B\u7AEF\u53E3\u5FC5\u586B"}:{ok:!0,tunnel:{name:il(s,"local",o),bookName:s,direction:"local",localPort:o,remoteHost:i,remotePort:n,enabled:!0}}}function nl(e,t){return(Array.isArray(e)?e:[]).find(r=>String(r?.name??"")===String(t))}function Yu(e,t,r){return(Array.isArray(e)?e:[]).find(s=>String(s?.name??"")!==String(t)&&String(s?.name??"")===String(r))}function ol(e,t,r){let s=Array.isArray(e)?e:[],o=s.find(a=>String(a?.name??"")===String(t));if(o===void 0)return{ok:!1,error:`\u96A7\u9053\u300C${String(t)}\u300D\u5DF2\u4E0D\u5B58\u5728\uFF08\u53EF\u80FD\u88AB\u53E6\u4E00\u4E2A\u7A97\u53E3\u5220\u9664\uFF09`};if(Yu(s,t,r.name)!==void 0)return{ok:!1,error:`\u5DF2\u5B58\u5728\u540C\u540D\u96A7\u9053\u300C${String(r.name)}\u300D\u2014\u2014\u8BF7\u5148\u5904\u7406\u90A3\u6761\u540C\u540D\u7684\u3002`};let n={...r,enabled:o.enabled!==!1};return{ok:!0,tunnels:s.map(a=>String(a?.name??"")===String(t)?n:a)}}function Xu(e){let t=e?.byId;if(!(t===null||typeof t!="object"))for(let r of Object.keys(t)){let s=t[r]?.retainedBy?.mainView??0;if(typeof s=="number"&&s>0)return r}}function Ju(e){let t=e?.current;return typeof t=="string"&&t!==""?t:Xu(e)}function al(e){let t=Ju(e);if(t===void 0)return;let r=e?.byId?.[t]?.cwd;return typeof r=="string"&&r!==""?r:void 0}function ll(e){return e==null?{text:"",state:""}:e.exited===!0?{text:e.statusText??"\u4F1A\u8BDD\u5DF2\u9000\u51FA",state:e.statusState??""}:e.live===!0?{text:e.statusText??"\u5DF2\u8FDE\u63A5",state:e.statusState??"connected"}:e.errored===!0?{text:e.statusText??"\u8FDE\u63A5\u51FA\u9519",state:e.statusState??"error"}:{text:e.statusText??"\u8FDE\u63A5\u4E2D\u2026",state:e.statusState??""}}function cl(e,t){return typeof e!="string"||e===""?!0:e===t}function hl(e,t){return e===null?!1:e!==t}function $e(e){if(!Number.isFinite(e)||e<=0)return"";if(e<1024)return String(e)+" B";let t=["KB","MB","GB","TB"],r=e,s=-1;do r/=1024,s+=1;while(r>=1024&&s<t.length-1);return(r>=100?r.toFixed(0):r.toFixed(1))+" "+t[s]}function Fr(e){if(!Number.isFinite(e)||e<=0)return"";if(e<1024)return"<1 KB/s";let t=["KB","MB","GB","TB"],r=e,s=-1;do r/=1024,s+=1;while(r>=1024&&s<t.length-1);return(r>=100?r.toFixed(0):r.toFixed(1))+" "+t[s]+"/s"}function ul(e){return Number.isFinite(e)?e>=90?"danger":e>=70?"warn":"":""}function dl(e){return!Number.isFinite(e)||e<0?"\u65E0":e<1024?Math.round(e)+" B/s":Fr(e)||"\u65E0"}function Zu(e){if(!Number.isFinite(e)||e<0)return"\u65E0";let t=Math.floor(e),r=Math.floor(t/604800),s=Math.floor(t%604800/86400),o=Math.floor(t%86400/3600),i=Math.floor(t%3600/60),n=[];return r>0&&n.push(r+"w"),(r>0||s>0)&&n.push(s+"d"),(r>0||s>0||o>0)&&n.push(o+"h"),(r>0||s>0||o>0||i>0)&&n.push(i+"m"),n.length>0?n.join(""):t+"s"}function Qu(e,t){return!Number.isFinite(e)||!Number.isFinite(t)||t<=0?"\u65E0":($e(e)||"0 B")+"/"+($e(t)||"0 B")}function fl(e,t){let r=e[t];return Number.isFinite(r)?t==="tempC"?r>-100&&r<200?r:null:t==="cores"?r>=1&&r<=4096?r:null:t==="cpuPct"||t==="memPct"||t==="diskPct"?r>=0&&r<=100?r:null:t==="uptimeSec"?r>=0&&r<=100*365*24*3600?r:null:t==="tcpConns"?r>=0&&r<=1e7?r:null:t==="rxRate"||t==="txRate"?r>=0&&r<=2**40?r:null:r>=0&&r<=2**50?r:null:null}var ef=["cpuPct","cores","memUsed","memTotal","memPct","diskUsed","diskTotal","diskPct","uptimeSec","tcpConns","rxRate","txRate","tempC"];function _l(e){return e===null||typeof e!="object"||Array.isArray(e)?!1:ef.some(t=>fl(e,t)!==null)}var tf=8e3;function pl(e,t=Date.now()){return t-(e||0)<=tf}var gl=23,gn=[{key:"cpuPct",label:"CPU",kind:"pct",slot:4},{key:"memPct",label:"\u5185\u5B58",kind:"pct",slot:4},{key:"diskPct",label:"\u78C1\u76D8",kind:"pct",slot:4},{key:"cores",label:"\u6838\u5FC3",kind:"count",slot:4},{key:"mem",label:"\u5185\u5B58",kind:"pair",slot:17,used:"memUsed",total:"memTotal"},{key:"uptimeSec",label:"\u5728\u7EBF",kind:"uptime",slot:13},{key:"tcpConns",label:"TCP",kind:"count",slot:6},{key:"disk",label:"\u78C1\u76D8",kind:"pair",slot:17,used:"diskUsed",total:"diskTotal"},{key:"tempC",label:"CPU\u6E29\u5EA6",kind:"temp",slot:8},{key:"net",label:"\u7F51\u7EDC",kind:"net",slot:gl}];function vl(e){let t=e!==null&&typeof e=="object"&&!Array.isArray(e)?e:{},r=o=>fl(t,o),s=(o,i,n,a=o.slot)=>({key:o.key,label:o.label,kind:o.kind,slot:a,pct:n??null,value:i,title:o.label+": "+i});return gn.map(o=>{if(o.kind==="pct"){let n=r(o.key);return s(o,n===null?"\u65E0":Math.round(n)+"%",n)}if(o.kind==="pair")return s(o,Qu(r(o.used),r(o.total)),null);if(o.kind==="uptime")return s(o,Zu(r(o.key)),null);if(o.kind==="temp"){let n=r(o.key);return s(o,n===null?"\u65E0":n.toFixed(1)+"\xB0C",null)}if(o.kind==="net"){let n=r("rxRate"),a=r("txRate");return n===null&&a===null?s(o,"\u65E0",null,0):s(o,"\u2193"+dl(n)+" \u2191"+dl(a),null,gl)}let i=r(o.key);return s(o,i===null?"\u65E0":String(i),null)})}var rf="/api/dsh-tty/ws";function sf(){return(location.protocol==="https:"?"wss:":"ws:")+"//"+location.host+rf}function br(){return _t!==null&&typeof _t.describe=="function"?_t:null}function fr(e){let t=String(e??"").trim();return t.startsWith("env:")?t.slice(4).trim():""}function nf(){let e=new Set;for(let t of Lt)for(let r of[t?.password,t?.passphrase]){let s=fr(r);s!==""&&e.add(s)}return[...e]}async function of(){try{let t=await(await fetch("/api/dsh-tty/credential-refs",{cache:"no-store"})).json();if(t.ok&&Array.isArray(t.names))return t.names.filter(r=>typeof r=="string"&&r!=="")}catch{}return[]}async function Ml(){return[...new Set([...nf(),...await of()])].sort()}async function Rl(e){let t=br();if(t===null)return{error:_t===null?"\u5BBF\u4E3B\u672A\u63D0\u4F9B\u51ED\u636E\u670D\u52A1\uFF08remote.credentials\uFF09":"\u51ED\u636E\u670D\u52A1\u4E0D\u5B8C\u6574"};try{let r=await t.describe([e]),s=r?.ok===!0?r.value?.[e]:void 0;return s===void 0?{unreported:!0}:{view:{configured:s.configured===!0,writable:s.writable===!0,source:typeof s.source=="string"?s.source:""}}}catch(r){return{error:r instanceof Error?r.message:String(r)}}}async function af(e,t){let r=br();if(r===null||typeof r.set!="function")return{error:"\u5BBF\u4E3B\u672A\u63D0\u4F9B\u51ED\u636E\u670D\u52A1\uFF08remote.credentials\uFF09\uFF0C\u65E0\u6CD5\u5B58\u5165"};try{return await r.set(e,t),{value:"env:"+e}}catch(s){return{error:"\u5B58\u5165\u51ED\u636E\u5B58\u50A8\u5931\u8D25\uFF1A"+(s instanceof Error?s.message:String(s))}}}async function Tl(e){let t=br();if(t===null||typeof t.unset!="function")return{error:"\u5BBF\u4E3B\u672A\u63D0\u4F9B\u51ED\u636E\u670D\u52A1\uFF08remote.credentials\uFF09\uFF0C\u65E0\u6CD5\u6E05\u9664"};try{return await t.unset(e),{}}catch(r){return{error:"\u6E05\u9664\u5931\u8D25\uFF1A"+(r instanceof Error?r.message:String(r))}}}async function Al(e,t,r,s,o,i){if(e!==!0)return{};let n=String(t??"").trim();if(n===""||n.startsWith("env:"))return{};let a=rl(r,s,o,i);return a===""?{error:"\u5148\u586B\u300C\u4E3B\u673A\u300D\u548C\u300C\u7528\u6237\u540D\u300D\u518D\u5B58\u5165\u2014\u2014\u5F15\u7528\u540D\u7531\u8FD9\u4E24\u8005\u6D3E\u751F"}:af(a,n)}function os(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():"t"+Date.now().toString(36)+Math.random().toString(36).slice(2,10)}var Fi;function si(){document.getElementById("dsh-tty-style")||(Fi=document.createElement("style"),Fi.id="dsh-tty-style",Fi.textContent=tl+`
2681
- `+el,document.head.appendChild(Fi))}var as='<svg viewBox="0 0 16 16" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3 5l3.5 3L3 11"/><path d="M8.5 11H13"/></svg>',lf='<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" aria-hidden="true"><circle cx="7" cy="7" r="4.4"/><path d="M10.4 10.4L14 14"/></svg>',cf='<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2.5 4.5h11"/><path d="M6 4.5V3a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v1.5"/><path d="M4.5 4.5l.7 8.1a1 1 0 0 0 1 .9h3.6a1 1 0 0 0 1-.9l.7-8.1"/></svg>',hf='<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="5.5" y="5.5" width="8" height="8" rx="1.4"/><path d="M3.5 10.5h-1v-8h8v1"/></svg>',df='<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="3.5" y="3" width="9" height="11" rx="1.4"/><rect x="5.5" y="1.5" width="5" height="3" rx="1" fill="var(--dsw-alias-bg-base,#fff)"/></svg>',uf='<svg viewBox="0 0 16 16" width="13" height="13" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M13.5 8a5.5 5.5 0 1 1-1.6-3.9"/><path d="M13.7 1.8v2.7H11"/></svg>',ff='<svg viewBox="0 0 16 16" width="13" height="13" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M1.8 12.8V4.2a1 1 0 0 1 1-1h3l1.4 1.6h6a1 1 0 0 1 1 1v7a1 1 0 0 1-1 1H2.8a1 1 0 0 1-1-1z"/></svg>',Dl='<svg viewBox="0 0 16 16" width="13" height="13" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4.5 5.5L2 8l2.5 2.5"/><path d="M11.5 5.5L14 8l-2.5 2.5"/><path d="M2.8 8h10.4"/></svg>',_f='<svg viewBox="0 0 16 16" width="13" height="13" fill="currentColor" stroke="none" aria-hidden="true"><circle cx="3.4" cy="8" r="1.35"/><circle cx="8" cy="8" r="1.35"/><circle cx="12.6" cy="8" r="1.35"/></svg>',pf='<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" aria-hidden="true"><path d="M4 8h8"/></svg>',ls='<svg viewBox="0 0 16 16" width="13" height="13" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" aria-hidden="true"><path d="M4.5 4.5l7 7"/><path d="M11.5 4.5l-7 7"/></svg>',gf='<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" aria-hidden="true"><path d="M8 3.6v8.8"/><path d="M3.6 8h8.8"/></svg>',Jr='<svg viewBox="0 0 16 16" width="15" height="15" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2 12.4V3.9a.9.9 0 0 1 .9-.9h2.9l1.4 1.6h5.9a.9.9 0 0 1 .9.9v6.9a.9.9 0 0 1-.9.9H2.9a.9.9 0 0 1-.9-.9z"/></svg>',Bl='<svg viewBox="0 0 16 16" width="15" height="15" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4 2.6h4.4l3.6 3.6v7.2a.9.9 0 0 1-.9.9H4.9a.9.9 0 0 1-.9-.9V3.5a.9.9 0 0 1 .9-.9z"/><path d="M8.2 2.7v3.4h3.4"/></svg>',Pl='<svg viewBox="0 0 16 16" width="15" height="15" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M6.4 9.6l3.2-3.2"/><path d="M9.2 4.6l1-1a2.5 2.5 0 0 1 3.5 3.5l-1 1"/><path d="M6.8 11.4l-1 1a2.5 2.5 0 0 1-3.5-3.5l1-1"/></svg>',On='<svg viewBox="0 0 16 16" width="15" height="15" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M8 12.6V4.2"/><path d="M4.4 7.8L8 4.2l3.6 3.6"/></svg>',Ol='<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M8 3v7.2"/><path d="M5 7.4L8 10.4l3-3"/><path d="M3.4 12.8h9.2"/></svg>',vf='<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M8 10.4V3.2"/><path d="M5 6.2L8 3.2l3 3"/><path d="M3.4 12.8h9.2"/></svg>',In='<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M11.2 2.9l1.9 1.9-7.3 7.3-2.4.5.5-2.4z"/></svg>',_r='<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3 4.6h10"/><path d="M6.2 4.6V3.4a.8.8 0 0 1 .8-.8h2a.8.8 0 0 1 .8.8v1.2"/><path d="M4.6 4.6l.6 8a.9.9 0 0 0 .9.8h3.8a.9.9 0 0 0 .9-.8l.6-8"/></svg>',Nn='<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M13.2 8a5.2 5.2 0 1 1-1.5-3.7"/><path d="M13.4 2.2v2.6h-2.6"/></svg>',Il='<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2 12.4V3.9a.9.9 0 0 1 .9-.9h2.9l1.4 1.6h5.9a.9.9 0 0 1 .9.9v6.9a.9.9 0 0 1-.9.9H2.9a.9.9 0 0 1-.9-.9z"/><path d="M8 6.6v3.6"/><path d="M6.2 8.4h3.6"/></svg>',Nl='<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3.4 8h9"/><path d="M9.2 4.8L12.4 8l-3.2 3.2"/></svg>',Hl='<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12.6 8h-9"/><path d="M6.8 4.8L3.6 8l3.2 3.2"/></svg>',mf='<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M8 3.4v9"/><path d="M4.8 9.2L8 12.4l3.2-3.2"/></svg>',bf='<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="2.4" y="3.2" width="11.2" height="4" rx="1.2"/><rect x="2.4" y="8.8" width="11.2" height="4" rx="1.2"/><path d="M5 5.2h.01"/><path d="M5 10.8h.01"/></svg>',wf='<svg viewBox="0 0 16 16" width="15" height="15" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M8 2.6l5.8 10.4H2.2z"/><path d="M8 6.4v3.2"/><path d="M8 11.6h.01"/></svg>',Sf='<svg viewBox="0 0 16 16" width="15" height="15" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" aria-hidden="true"><circle cx="8" cy="8" r="5.6"/><path d="M8 7.2v3.6"/><path d="M8 5.1h.01"/></svg>',Fl='<svg viewBox="0 0 16 16" width="15" height="15" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="8" cy="8" r="5.6"/><path d="M6 6l4 4"/><path d="M10 6l-4 4"/></svg>',yf='<svg viewBox="0 0 16 16" width="15" height="15" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M8 2.8v5"/><path d="M11.6 4.6a5.2 5.2 0 1 1-7.2 0"/></svg>',Wl='<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="5.6" cy="6" r="2.8"/><path d="M7.8 7.9l5.4 5.4"/><path d="M10.6 10.7l1.2-1.2"/></svg>',$l=null,_e=null,se=null,Vi=null,Zr=null,_t=null,jt=null,Gt=null,ut=null,zr=null,Ur=null,Gi=null,Ye=null,jr=null,ze=null,Xe=null,Ne=null,pr=null,Qr=!1,qr=null,Ae=!1,Pe=null,Yi=null,wr=null,Yt=null,Xi=null,qt=null,Kr=1e3,Ji="dsh-tty:tabs",ne=new Map,ni=new Set,Hn=()=>ni.size>0,Sn=new Set,me=null,oi=0,Wi=!1,Je=null,gr=null,Lt=[],Zi=!0,rt=null,it=null,Vr=null,$r=null,yn=null,Cn=new Set;function cs(e){return Cn.add(e),()=>Cn.delete(e)}cs(({tab:e,addAction:t})=>{Vt&&e.exited&&t(uf,"\u91CD\u65B0\u6253\u5F00","\u4EE5\u539F\u8FDE\u63A5\u4FE1\u606F\u91CD\u5F00\u4F1A\u8BDD",()=>es(e.sid))});cs(({tab:e,addAction:t})=>{Vt&&t(ff,"SFTP","\u6253\u5F00\u8BE5\u8FDE\u63A5\u7684\u6587\u4EF6\u6D4F\u89C8\uFF08SFTP\uFF09",()=>us(e.spawnSpec,e.sid))});cs(({bookName:e,addAction:t})=>{if(!Vt)return;let r=e!==""?sc(e):0;if(r>0){t(Dl,"\u96A7\u9053 "+r,"\u67E5\u770B\u8BE5\u8FDE\u63A5\u7684\u7AEF\u53E3\u8F6C\u53D1\u96A7\u9053",s=>Ql(s.currentTarget,e));return}e!==""&&t(_f,"\u66F4\u591A","\u66F4\u591A\u64CD\u4F5C\uFF08\u7AEF\u53E3\u8F6C\u53D1\u2026\uFF09",s=>Jf(s.currentTarget,e))});function ai(e,t){if(jt===null)return;jt.textContent=e.split("\u2014\u2014")[0],jt.title=e,Gt.dataset.state=t,Vi!==null&&(Vi.style.display=t==="connected"?"none":""),wr!==null&&(wr.textContent=e),Yt!==null&&(Yt.dataset.state=t);let r=document.querySelector("[data-dsh-tty-entry] .tt_sidebarBadgeDot");r!==null&&(r.dataset.state=t)}function vn(e,t,r){let s=typeof e=="string"&&e!==""?e:null;if(s!==null){let o=ne.get(s);o!==void 0&&(o.statusText=t,o.statusState=r)}cl(s,me)&&(Zr=s,ai(t,r))}function $i(e,t){Zr=null,ai(e,t)}function Fn(){if(!hl(Zr,me))return;let e=me===null?void 0:ne.get(me);Zr=e===void 0?null:me;let t=ll(e);ai(t.text,t.state)}function be(e){_e!==null&&_e.readyState===WebSocket.OPEN&&_e.send(JSON.stringify(e))}function Cf(){let e=[],t=document.createDocumentFragment();for(let r of gn){let s=document.createElement("span");s.className="tt_statsItem";let o=document.createElement("span");o.className="tt_statsLabel",o.textContent=r.label,s.appendChild(o);let i=null,n=null;r.kind==="pct"&&(i=document.createElement("span"),i.className="tt_statsMeter",n=document.createElement("span"),n.className="tt_statsMeterFill",i.appendChild(n),s.appendChild(i));let a=document.createElement("span");a.className="tt_statsValue",s.appendChild(a),t.appendChild(s),e.push({item:s,value:a,meter:i,fill:n,slot:null})}return rt!==null&&rt.appendChild(t),e}function xf(e,t){let r=vl(t!==void 0?t.stats:null);for(let s=0;s<e.length;s+=1){let o=e[s],i=r[s];if(i!==void 0&&(o.slot!==i.slot&&(o.slot=i.slot,o.value.style.minWidth=i.slot>0?i.slot+"ch":""),o.value.textContent!==i.value&&(o.value.textContent=i.value),o.item.getAttribute("title")!==i.title&&o.item.setAttribute("title",i.title),o.fill!==null&&o.meter!==null)){let n=i.pct===null?"0%":Math.max(0,Math.min(100,i.pct)).toFixed(1)+"%";o.fill.style.width!==n&&(o.fill.style.width=n);let a=ul(i.pct);o.meter.dataset.level!==a&&(o.meter.dataset.level=a)}}}function hs(){$r=null,yn=null}function kf(){if(se===null||Ae||!Zi)return!1;let e=Ze();return e===void 0||e.embedded===!0||e.exited===!0||e.stats===null||e.stats===void 0?!1:pl(e.statsAt)}function ml(){if(Ae)return;let e=Ze();if(!(e===void 0||e.embedded===!0||e.fit===null)){try{e.fit.fit()}catch{return}try{e.spawned&&!e.exited&&Cr(e)}catch{}}}function Xt(){try{Ef()}catch(e){console.warn("[dsh-tty] \u72B6\u6001\u6761\u6E32\u67D3\u5931\u8D25\uFF08\u5DF2\u6536\u8D77\uFF09: "+(e instanceof Error?e.message:String(e)));try{rt!==null&&(rt.hidden=!0,rt.textContent=""),hs(),ze!==null&&delete ze.dataset.stats}catch{}}}function Ef(){if(ze===null||rt===null)return;let e=kf(),t=ze.dataset.stats!==void 0!==e;if(!e){t&&delete ze.dataset.stats,rt.hidden=!0,$r!==null&&(rt.textContent="",hs()),t&&ml();return}rt.hidden=!1,$r===null&&($r=Cf());let r=Ze(),s=r===void 0?"":r.sid+":"+String(r.statsAt||0);s!==yn&&(yn=s,xf($r,r)),t&&(ze.dataset.stats="",ml())}function zl(){Vr===null&&(Vr=setInterval(()=>Xt(),1e3))}function Ul(){Vr!==null&&(clearInterval(Vr),Vr=null)}function jl(){if(se===null||Ae||!Zi)return null;let e=Ze();return e===void 0||e.embedded===!0||e.exited===!0?null:e.sid}function li(){let e=jl();e!==it&&(it!==null&&be({t:"statsOff",sid:it}),it=e,e!==null&&be({t:"statsOn",sid:e}))}function Lf(e){if(e!==jl()){li();return}it!==null&&it!==e&&be({t:"statsOff",sid:it}),it=e,be({t:"statsOn",sid:e})}function Ze(){return me!==null?ne.get(me):void 0}function xn(){try{return al($l?.list?.getSnapshot?.())}catch{return}}function Mf(e){if(!(e.term===null||e.exited)){try{if(e.term.buffer.active.length<=e.term.rows)return}catch{return}e.term.reset(),be({t:"refresh",sid:e.sid})}}var zi=null;function ql(e){zi!==null&&clearTimeout(zi),zi=setTimeout(()=>{zi=null;let t=Ze();t!==void 0&&Mf(t)},e??200)}var Rf=["password","passphrase"];function bl(e){if(e===null||typeof e!="object"||e.t!=="ssh")return e;let t=e.credsStripped===!0,r={...e};for(let s of Rf){let o=r[s];typeof o=="string"&&o!==""&&!o.startsWith("env:")&&(delete r[s],t=!0)}return t&&(r.credsStripped=!0),r}var Kl=1;function Ft(){try{let e=[...ne.values()].filter(t=>!t.exited&&t.embedded!==!0).map(t=>({sid:t.sid,spawnSpec:bl(t.spawnSpec),label:t.label}));e.length===0||se===null?sessionStorage.removeItem(Ji):sessionStorage.setItem(Ji,JSON.stringify({v:Kl,tabs:e})),Tf([...ne.values()].filter(t=>t.embedded!==!0).map(t=>({spawnSpec:bl(t.spawnSpec),label:t.label})))}catch(e){console.warn("[dsh-tty] \u6807\u7B7E\u6301\u4E45\u5316\u5931\u8D25\uFF08\u672C\u6B21\u5237\u65B0\u540E\u6807\u7B7E\u5217\u8868\u53EF\u80FD\u4E22\u5931\uFF09: "+(e instanceof Error?e.message:String(e)))}}var kn="dsh-tty:persist-specs";function Tf(e){try{let t=e.filter(r=>ci(r.spawnSpec)).map(r=>({spawnSpec:r.spawnSpec,label:r.label}));t.length===0?localStorage.removeItem(kn):localStorage.setItem(kn,JSON.stringify(t))}catch{}}function Af(){try{let e=localStorage.getItem(kn);if(e===null)return[];let t=JSON.parse(e);return Array.isArray(t)?t.filter(r=>r!==null&&typeof r=="object"&&ci(r.spawnSpec)):[]}catch{return[]}}function Df(){try{let e=sessionStorage.getItem(Ji);if(e===null)return[];let t=JSON.parse(e);return Array.isArray(t)?t.filter(r=>r!==null&&typeof r=="object"&&typeof r.sid=="string"&&r.sid!==""&&r.spawnSpec!==null&&typeof r.spawnSpec=="object"):t!==null&&typeof t=="object"&&t.v===Kl&&Array.isArray(t.tabs)?t.tabs.filter(r=>r!==null&&typeof r=="object"&&typeof r.sid=="string"&&r.sid!==""&&r.spawnSpec!==null&&typeof r.spawnSpec=="object"):[]}catch{return[]}}function Qi(e,t){let r=_e;return new Promise(s=>{let o=null,i=n=>{let a;try{a=JSON.parse(n.data)}catch{return}a.t===e&&(o!==null&&clearTimeout(o),r.removeEventListener("message",i),s(r===_e?a:null))};o=setTimeout(()=>{r.removeEventListener("message",i),s(null)},t),r.addEventListener("message",i)})}function Cr(e){if(e===void 0||e.fit===void 0)return;let t=e.fit.proposeDimensions();t!==void 0&&be({t:"resize",sid:e.sid,cols:t.cols,rows:t.rows})}function Bf(e){if(e===void 0||e.fit===void 0)return;let t=e.term,r=t!==null&&t.buffer!==void 0?t.buffer.active:null,s=r==null?null:{atBottom:r.viewportY>=r.baseY,line:r.viewportY};try{e.fit.fit()}catch{return}if(s!==null)try{s.atBottom?t.scrollToBottom():t.scrollToLine(Math.min(s.line,t.buffer.active.baseY))}catch{}e.exited||Cr(e)}function hr(e,t,r,s){if(e.overlayEl===null||e.overlayEl===void 0)return;let o=e.overlayEl;if(t===""||t===void 0){o.textContent="";return}let i=s==="error"||s==="info"?s:"exited";o.innerHTML='<div class="tt_overlayCard" data-kind="'+i+'"><span class="tt_overlayIcon">'+(i==="error"?Fl:i==="info"?Nn:yf)+'</span><span class="tt_overlayText"><span class="tt_overlayMain"></span>'+(r===void 0||r===""?"":'<span class="tt_overlayHint"></span>')+"</span></div>",o.querySelector(".tt_overlayMain").textContent=t,r!==void 0&&r!==""&&(o.querySelector(".tt_overlayHint").textContent=r)}function Pf(e,t){try{let r=getComputedStyle(document.documentElement).getPropertyValue(e).trim();return r!==""?r:t}catch{return t}}function xr(e){let t=Pf("--dsw-alias-state-business-primary","#7c9cff"),r=new El.Terminal({cursorBlink:!0,cursorStyle:"bar",cursorInactiveStyle:"outline",fontSize:13,fontFamily:'"JetBrains Mono", "SF Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace',fontWeight:400,fontWeightBold:600,lineHeight:1.35,scrollback:5e3,convertEol:!1,allowProposedApi:!0,theme:{background:"#0b0e14",foreground:"#d7dce5",cursor:t,cursorAccent:"#0b0e14",selectionBackground:"rgba(124, 156, 255, .30)",black:"#1b2028",red:"#f07178",green:"#7ec699",yellow:"#e6b673",blue:"#7aa2f7",magenta:"#c792ea",cyan:"#7fdbca",white:"#c8d0dc",brightBlack:"#556070",brightRed:"#ff8b92",brightGreen:"#9fe0b4",brightYellow:"#f5cc8c",brightBlue:"#9ab8ff",brightMagenta:"#dbb3ff",brightCyan:"#a3f0e2",brightWhite:"#eef2f8"}}),s=new Ll.FitAddon,o=new To;r.loadAddon(s),r.loadAddon(o),r.loadAddon(new Ao);let i=document.createElement("div");i.className="tt_term";let n=document.createElement("div");n.className="tt_overlay",n.addEventListener("click",()=>{n.textContent="",es(e.sid)}),n.setAttribute("role","button"),n.setAttribute("aria-label","\u91CD\u65B0\u6253\u5F00\u4F1A\u8BDD"),n.tabIndex=0,n.addEventListener("keydown",a=>{(a.key==="Enter"||a.key===" "||a.key==="Spacebar")&&(a.preventDefault(),n.textContent="",es(e.sid))}),i.appendChild(n),r.open(i);try{s.fit()}catch{}try{let a=new Qa;a.onContextLoss(()=>{try{a.dispose()}catch{}}),r.loadAddon(a)}catch{}r.onData(a=>{be({t:"input",sid:e.sid,d:a})}),r.onResize(()=>{ci(e.spawnSpec)&&ql(200)}),r.attachCustomKeyEventHandler(a=>e.embedded===!0?!0:(a.ctrlKey||a.metaKey)&&a.key.toLowerCase()==="f"?(a.preventDefault(),_c(),!1):!0),e.term=r,e.fit=s,e.search=o,e.termEl=i,e.overlayEl=n}function wl(e){return e===null||typeof e!="object"?"":["t","name","host","port","username","command","cwd","persist","persistName"].map(r=>r+"="+String(e[r]??"")).join("\0")}function Of(e){let t=wl(e);if(t==="")return null;for(let r of ne.values())if(r.exited!==!0&&r.embedded!==!0&&wl(r.spawnSpec)===t)return r;return null}function ei(e,t){let r=os(),s={sid:r,term:null,fit:null,search:null,termEl:null,overlayEl:null,exited:!1,spawned:!1,spawnSpec:e??u_(),label:t};return xr(s),ne.set(r,s),oi+=1,Ue(),Wt(r),ds(s),Ft(),s}function If(e){if(Array.isArray(e))for(let t of e){if(t===null||typeof t!="object"||t.owner!=="agent")continue;let r=typeof t.sid=="string"?t.sid:"";if(r===""||ne.has(r))continue;let s={sid:r,term:null,fit:null,search:null,termEl:null,overlayEl:null,exited:!1,spawned:!1,agentOwned:!0,spawnSpec:{t:"spawn",cwd:typeof t.cwd=="string"?t.cwd:xn()},label:"agent"+(t.kind==="ssh"&&typeof t.target=="string"&&t.target!==""?" \xB7 "+t.target:"")};xr(s),ne.set(r,s),oi+=1,Ue(),Nf()&&s.termEl!==null&&ze!==null&&me===null&&Wt(r),be({t:"attach",sid:r}),Hf()}}function Nf(){return se!==null&&Ae!==!0}function Hf(){try{Ft()}catch{}}function Ff(e){if(If(e),!Array.isArray(e))return;let t=new Set(e.filter(r=>r!==null&&typeof r=="object"&&r.owner==="agent").map(r=>r.sid));for(let[r,s]of[...ne])s.agentOwned===!0&&(t.has(r)||s.exited!==!0&&s.live===!0&&(s.exited=!0,s.live=!1,Ue()))}function Wf(e){if(ne.has(e.sid))return ne.get(e.sid);let t={sid:e.sid,term:null,fit:null,search:null,termEl:null,overlayEl:null,exited:!1,spawned:!1,spawnSpec:e.spawnSpec,label:typeof e.label=="string"?e.label:void 0};xr(t),ne.set(t.sid,t),oi+=1,Ue(),Wt(t.sid),be({t:"attach",sid:t.sid})}function $f(e){if(!(e?.spawnSpec?.credsStripped!==!0||e.term===null))try{e.term.writeln("\x1B[2m[dsh-tty] \u51FA\u4E8E\u5B89\u5168\u8003\u8651\uFF0C\u660E\u6587\u5BC6\u7801/\u53E3\u4EE4\u4E0D\u968F\u6D4F\u89C8\u5668\u5B58\u50A8\u4FDD\u7559\uFF0C\u672C\u6B21\u8FDE\u63A5\u9700\u8981\u91CD\u65B0\u8F93\u5165\uFF1A\u91CD\u5F00\u6807\u7B7E\u65F6\u518D\u586B\u4E00\u6B21\uFF0C\u6216\u5728\u8BBE\u7F6E\u5361\u7247\u628A\u51ED\u636E\u6362\u6210 env: \u5F15\u7528\uFF08\u503C\u5B58\u5BBF\u4E3B\u51ED\u636E\u5B58\u50A8\uFF09\u3002\x1B[0m")}catch{}}function ds(e){$f(e);let t=e.fit!==null?e.fit.proposeDimensions():void 0,r={...e.spawnSpec,sid:e.sid,cols:t!==void 0?t.cols:80,rows:t!==void 0?t.rows:24};if(_e===null||_e.readyState!==WebSocket.OPEN){Sn.add({tab:e,frame:r});return}be(r)}function Sl(e){let t={sid:os(),term:null,fit:null,search:null,termEl:null,overlayEl:null,exited:!1,spawned:!1,spawnSpec:e.spawnSpec,label:typeof e.label=="string"?e.label:void 0};xr(t),ne.set(t.sid,t),oi+=1,Ue(),Wt(t.sid),ds(t)}function es(e){let t=ne.get(e);if(t===void 0)return;if(t.embedded===!0){Xl(t);return}let r=t.spawnSpec,s=t.label;if(t.exited||be({t:"kill",sid:e}),t.term!==null)try{t.term.dispose()}catch{}t.termEl!==null&&t.termEl.remove(),ne.delete(e);let o={sid:os(),term:null,fit:null,search:null,termEl:null,overlayEl:null,exited:!1,spawned:!1,spawnSpec:r,label:s};xr(o),ne.set(o.sid,o),Ue(),Wt(o.sid),ds(o),Ft()}function yl(e){let t=ne.get(e);if(t!==void 0){if(st!==null&&st.ownerKey===e&&Yr(!0),t.exited||be({t:"kill",sid:e}),ne.delete(e),ni.delete(e),t.term!==null)try{t.term.dispose()}catch{}if(t.termEl!==null&&t.termEl.remove(),me===e){me=null;let r=[...ne.entries()].filter(([,s])=>s.embedded!==!0).map(([s])=>s).pop()??null;r!==null&&Wt(r)}Ue(),Fn(),[...ne.values()].some(r=>r.embedded!==!0)?Ft():ii()}}function Vl(e){let t=typeof e?.command=="string"?e.command.trim():"";if(t==="")throw new Error("ttyTerminal \u9700\u8981 command");if(/[\r\n\0]/.test(t))throw new Error("command \u5FC5\u987B\u662F\u5355\u884C");return t}function Gl(e,t){return typeof e?.book=="string"&&e.book!==""?{t:"ssh",name:e.book,command:t}:e?.spec!==null&&typeof e?.spec=="object"?{t:"ssh",...e.spec,command:t}:{t:"spawn",...typeof e?.cwd=="string"&&e.cwd!==""?{cwd:e.cwd}:{},command:t}}function zf(e){let t=e.controller;t===void 0||t.observer!==null||(t.observer=new ResizeObserver(()=>{if(!(t.disposed||t.tab!==e||e.term===null)){try{e.fit.fit()}catch{return}e.spawned&&!e.exited&&Cr(e)}}),t.observer.observe(t.hostEl))}function Yl(e,t,r){let s={sid:os(),term:null,fit:null,search:null,termEl:null,overlayEl:null,exited:!1,spawned:!1,embedded:!0,controller:e,spawnSpec:t,label:r};return xr(s),ne.set(s.sid,s),ni.add(s.sid),e.hostEl.appendChild(s.termEl),zf(s),ds(s),s}function Xl(e){let t=e.controller;if(!(t===void 0||t.disposed)){e.exited||be({t:"kill",sid:e.sid});try{e.term?.dispose()}catch{}return e.termEl?.remove(),ne.delete(e.sid),ni.delete(e.sid),t.observer!==null&&(t.observer.disconnect(),t.observer=null),t.tab=Yl(t,e.spawnSpec,e.label),me===e.sid&&(me=t.tab.sid,Fn()),t.tab}}function Uf(e,t){if(!(e instanceof HTMLElement))throw new Error("ttyTerminal.mount \u9700\u8981 HTMLElement \u4F5C\u4E3A\u6302\u8F7D\u70B9");let r=Vl(t),s=Gl(t,r),o=typeof t?.label=="string"&&t.label!==""?t.label:void 0;si();let i={hostEl:e,tab:null,observer:null,disposed:!1};return i.tab=Yl(i,s,o),__(),()=>jf(i)}function jf(e){if(e.disposed)return;e.disposed=!0,e.observer!==null&&(e.observer.disconnect(),e.observer=null);let t=e.tab;if(t!==null){t.exited||be({t:"kill",sid:t.sid});try{t.term?.dispose()}catch{}t.termEl?.remove(),ne.delete(t.sid),ni.delete(t.sid),e.tab=null}if(se===null&&!Hn()&&_e!==null){Qr=!0;try{_e.close()}catch{}_e=null}}var qf=460,Kf=280,Vf=320,Gf=160,st=null,dr=qf,ur=Vf;function Wn(){let e=se!==null?se.querySelector(".tt_modal"):null,t=e!==null?e:se;return t!==null?t.getBoundingClientRect():null}var $n=e=>e==="bottom"?Gf:Kf;function Yf(e){let t=Wn();if(t===null)return 900;let r=e==="bottom"?t.height:t.width;return Math.max($n(e),Math.round(r*.72))}function Gr(e,t){return Math.min(Yf(e),Math.max($n(e),Math.round(t)))}function Ui(){let e=st;if(e!==null){if(e.collapsed){e.el.style.width="",e.el.style.height="",e.el.style.flexBasis="";return}if(e.side==="bottom"){ur=Gr("bottom",ur),e.el.style.width="",e.el.style.height=String(ur)+"px",e.el.style.flexBasis=String(ur)+"px";return}dr=Gr("right",dr),e.el.style.height="",e.el.style.width=String(dr)+"px",e.el.style.flexBasis=String(dr)+"px"}}function Yr(e){let t=st;if(t!==null){if(st=null,t.disposed=!0,e&&t.onClose!==null)try{t.onClose()}catch(r){console.warn("[dsh-tty] ttyPanel.onClose \u629B\u9519\uFF1A"+(r instanceof Error?r.message:String(r)))}try{t.el.remove()}catch{}Xe!==null&&delete Xe.dataset.side}}function Jl(e){if(Bn(),Xe===null)throw new Error("ttyPanel.mountPane\uFF1A\u7EC8\u7AEF\u9762\u677F\u672A\u5C31\u7EEA");st!==null&&Yr(!0),si();let t=cr(e?.ownerSid,me),r=e?.side==="bottom"?"bottom":"right",s=Math.max(r==="bottom"?120:200,Math.round(typeof e?.min=="number"&&Number.isFinite(e.min)?e.min:$n(r)));if(typeof e?.size=="number"&&Number.isFinite(e.size)){let l=Gr(r,e.size);r==="bottom"?ur=l:dr=l}let o=document.createElement("div");o.className="tt_dockPane",o.dataset.side=r,Xe.dataset.side=r,o.innerHTML='<div class="tt_dockPaneResize" title="'+(r==="bottom"?"\u62D6\u52A8\u8C03\u6574\u9AD8\u5EA6":"\u62D6\u52A8\u8C03\u6574\u5BBD\u5EA6")+'"></div><div class="tt_dockPaneHead"><span class="tt_dockPaneTitle"></span><span class="tt_dockPaneHint"></span><span class="tt_dockPaneSpacer"></span><button class="tt_dockPaneFold" type="button"></button><button class="tt_dockPaneClose" type="button" title="\u5173\u95ED\u4FA7\u680F">'+ls+'</button></div><div class="tt_dockPaneBody"></div>',Xe.appendChild(o);let i=o.querySelector(".tt_dockPaneTitle"),n=o.querySelector(".tt_dockPaneHint"),a=o.querySelector(".tt_dockPaneBody"),f=o.querySelector(".tt_dockPaneFold"),c=o.querySelector(".tt_dockPaneClose"),p=o.querySelector(".tt_dockPaneResize"),g={el:o,element:a,disposed:!1,collapsed:!1,side:r,minSize:s,ownerKey:t,onClose:typeof e?.onClose=="function"?e.onClose:null},S=()=>r==="bottom"?g.collapsed?On:mf:g.collapsed?Hl:Nl,_=l=>{g.collapsed=l===!0,g.collapsed?o.dataset.collapsed="1":delete o.dataset.collapsed,f.innerHTML=S(),f.title=g.collapsed?"\u5C55\u5F00\u4FA7\u680F":"\u6536\u8D77\u4FA7\u680F",f.setAttribute("aria-label",f.title),Ui()};return g.setTitle=l=>{i.textContent=typeof l=="string"?l:""},g.setHint=l=>{n.textContent=typeof l=="string"?l:""},g.isCollapsed=()=>g.collapsed===!0,g.collapse=()=>_(!0),g.expand=()=>_(!1),g.toggle=()=>_(!g.collapsed),g.dispose=()=>{g.disposed||st!==g||Yr(!1)},p.addEventListener("mousedown",l=>{if(l.button!==0||g.collapsed)return;l.preventDefault();let d=l.clientX,h=l.clientY,u=o.getBoundingClientRect(),v=b=>{r==="bottom"?ur=Gr("bottom",Math.max(s,u.height+(h-b.clientY))):dr=Gr("right",Math.max(s,u.width+(d-b.clientX))),Ui()},y=()=>{document.removeEventListener("mousemove",v),document.removeEventListener("mouseup",y),document.body.style.userSelect=""};document.body.style.userSelect="none",document.addEventListener("mousemove",v),document.addEventListener("mouseup",y)}),p.addEventListener("dblclick",()=>_(!g.collapsed)),f.addEventListener("click",()=>_(!g.collapsed)),c.addEventListener("click",()=>Yr(!0)),g.setTitle(typeof e?.title=="string"?e.title:""),g.setHint(typeof e?.hint=="string"?e.hint:""),_(e?.collapsed===!0),st=g,Ui(),Zl(),g}function Zl(){let e=st;if(e!==null){if(_n(e.ownerKey,me)){delete e.el.dataset.dockHidden,Xe!==null&&(Xe.dataset.side=e.side);return}e.el.dataset.dockHidden="1",Xe!==null&&delete Xe.dataset.side}}function Wt(e){let t=ne.get(e);if(t!==void 0&&t.embedded!==!0){me=e;for(let[r,s]of ne)s.embedded!==!0&&s.termEl!==null&&(s.termEl.style.display=r===e?"":"none");t.embedded!==!0&&ze!==null&&t.termEl!==null&&t.termEl.parentElement!==ze&&ze.appendChild(t.termEl),li(),Xt(),Ue(),Kt(),Zl();try{t.fit.fit()}catch{}t.spawned&&!t.exited&&Cr(t),hr(t,t.exited?"\u4F1A\u8BDD\u5DF2\u9000\u51FA":"",t.exited?"\u70B9\u51FB\u91CD\u65B0\u6253\u5F00":"","exited"),Fn()}}function mn(e){if(ut===null)return;let t=ne.get(e);if(t===void 0)return;let s=ut.querySelector(`[data-sid="${e}"]`)?.querySelector(".tt_tabDot");s!=null&&(s.dataset.state=t.exited?"exited":t.live===!0?"connected":t.errored===!0?"error":"connecting")}var bn=!1;function Ue(){if(ut===null)return;if(ut.querySelector(".tt_tabRename")!==null){bn||(bn=!0,setTimeout(()=>{bn=!1,Ue()},1e3));return}ut.textContent="";for(let[r,s]of ne){if(s.embedded===!0)continue;let o=document.createElement("button");o.className="tt_tab",o.dataset.sid=r,r===me&&(o.dataset.active="");let i=document.createElement("span");i.className="tt_tabDot",i.dataset.state=s.exited?"exited":s.live===!0?"connected":s.errored===!0?"error":"connecting",o.appendChild(i);let n=document.createElement("span");n.className="tt_tabLabel",n.textContent=s.label||"\u7EC8\u7AEF "+ec(r),n.addEventListener("dblclick",f=>{f.stopPropagation(),Zf(r,o)});let a=document.createElement("span");a.className="tt_tabClose",a.title="\u5173\u95ED",a.textContent="\u2715",a.setAttribute("role","button"),a.setAttribute("aria-label","\u5173\u95ED\u6807\u7B7E\uFF1A"+(s.label||"")),a.tabIndex=0,a.addEventListener("keydown",f=>{(f.key==="Enter"||f.key===" "||f.key==="Spacebar")&&(f.preventDefault(),f.stopPropagation(),yl(r))}),o.title=n.textContent,o.appendChild(n),o.appendChild(a),o.addEventListener("click",f=>{if(f.target.closest(".tt_tabClose")!==null){f.stopPropagation(),yl(r);return}Wt(r)}),ut.appendChild(o)}let e=ut.querySelector("[data-active]");e!==null&&typeof e.scrollIntoView=="function"&&e.scrollIntoView({block:"nearest",inline:"nearest"});let t=document.createElement("button");t.className="tt_tabAdd",t.title="\u65B0\u5EFA\uFF08\u672C\u5730 / SSH\uFF09",t.innerHTML=gf,t.addEventListener("click",()=>{r_(t)}),ut.appendChild(t)}function Xf(e){return e?.direction==="remote"?`\u8FDC\u7A0B:${e.remoteHost||"127.0.0.1"}:${String(e.remotePort??0)} \u2192 \u672C\u673A:${String(e.localTargetPort??0)}`:`\u672C\u673A:${String(e?.localPort??0)} \u2192 ${e?.remoteHost??"?"}:${String(e?.remotePort??0)}`}function Kt(){if(zr===null||Gi===null||jr===null||Ur===null)return;jr.textContent="";let e=Ze(),t=e?.spawnSpec??{};if(e===void 0||t.t!=="ssh"){zr.dataset.hidden="";return}delete zr.dataset.hidden;let r=Number(t.port);Gi.textContent=typeof e.target=="string"&&e.target!==""?e.target:typeof t.name=="string"&&t.name!==""?t.name:String(t.username??"")+"@"+String(t.host??"")+(Number.isInteger(r)&&r!==22?":"+r:""),Ye!==null&&(e.persistTmux===!0?(Ye.textContent="tmux",Ye.dataset.state="ok",Ye.title="\u5DF2\u7531 tmux \u6258\u7BA1 \u2014 \u65AD\u7EBF / \u5BBF\u4E3B\u91CD\u542F\u540E\u6309\u540D\u63A5\u56DE\u73B0\u573A"):t.persist===!0&&e.spawned===!0?(Ye.textContent="\u672A\u6301\u4E45\u5316",Ye.dataset.state="warn",Ye.title="\u8BF7\u6C42\u4E86\u6301\u4E45\u4F1A\u8BDD\uFF0C\u4F46 tmux \u4E0D\u53EF\u7528 \u2014 \u5F53\u524D\u4E3A\u666E\u901A\u4F1A\u8BDD"):(Ye.textContent="",delete Ye.dataset.state,Ye.removeAttribute("title")));let s=e.exited?"exited":e.live===!0?"connected":e.errored===!0?"error":"connecting";Ur.dataset.state=s,Ur.title=s==="connected"?"\u5DF2\u8FDE\u63A5":s==="connecting"?"\u8FDE\u63A5\u4E2D":s==="error"?"\u8FDE\u63A5\u51FA\u9519":"\u4F1A\u8BDD\u5DF2\u9000\u51FA";let o=(n,a,f,c)=>{let p=document.createElement("button");p.type="button",p.className="tt_toolBtn tt_connAct",p.title=f,p.innerHTML=n+"<span></span>",p.lastElementChild.textContent=a,p.addEventListener("click",c),jr.appendChild(p)};if(typeof t.command=="string"&&t.command!=="")return;let i=typeof t.name=="string"?t.name:"";for(let n of Cn)try{n({tab:e,spec:t,bookName:i,addAction:o})}catch(a){console.warn("[dsh-tty] connbar action failed: "+(a instanceof Error?a.message:String(a)))}}function Jf(e,t){if(vr!==null){ji();return}let r=document.createElement("div");r.className="tt_addMenu tt_connMore",vr=r,Rn(r,"\u7AEF\u53E3\u8F6C\u53D1","\u5728 \u8BBE\u7F6E \u2192 \u63D2\u4EF6 \u2192 \u7EC8\u7AEF\u9762\u677F \u91CC\u914D\u7F6E",()=>{ji(),Ql(e,t)},void 0,Dl),document.body.appendChild(r);let s=e.getBoundingClientRect(),o=r.offsetWidth,n=s.left+o>window.innerWidth-8?s.right-o:s.left;r.style.left=Math.max(8,Math.min(n,window.innerWidth-o-8))+"px",r.style.top=s.bottom+6+"px";let a=f=>{vr===r&&(r.contains(f.target)||e.contains(f.target)||ji())};Ki=a,setTimeout(()=>document.addEventListener("mousedown",a,!0),0)}function ji(){Ki!==null&&(document.removeEventListener("mousedown",Ki,!0),Ki=null),vr!==null&&(vr.remove(),vr=null)}var Ut=null,qi=null,vr=null,Ki=null;function ts(){qi!==null&&(document.removeEventListener("mousedown",qi,!0),qi=null),Ut!==null&&(Ut.remove(),Ut=null)}function Ql(e,t){if(Ut!==null){ts();return}let r=document.createElement("div");r.className="tt_tunnelPop";let s=document.createElement("div");s.className="tt_tunnelPopTitle",s.textContent="\u7AEF\u53E3\u8F6C\u53D1 \u2014 "+t,r.appendChild(s);let o=document.createElement("div");o.textContent="\u52A0\u8F7D\u4E2D\u2026",r.appendChild(o);let i=document.createElement("span");i.className="tt_cardHint",i.textContent="\u589E\u5220/\u542F\u505C\u5728 \u63D2\u4EF6\u914D\u7F6E \u2192 \u7EC8\u7AEF\u9762\u677F \u7684\u7AEF\u53E3\u8F6C\u53D1\u533A\u5757\u7EF4\u62A4",r.appendChild(i),document.body.appendChild(r),Ut=r;let n=e.getBoundingClientRect();r.style.top=String(n.bottom+6)+"px",r.style.left=String(Math.max(8,n.right-340))+"px";let a=f=>{Ut===r&&(r.contains(f.target)||e.contains(f.target)||ts())};qi=a,setTimeout(()=>document.addEventListener("mousedown",a,!0),0),(async()=>{let f=[];try{let g=await(await fetch("/api/dsh-tty/tunnels",{cache:"no-store"})).json();g.ok&&Array.isArray(g.tunnels)&&(f=g.tunnels)}catch{}if(Ut!==r)return;o.textContent="";let c=zn.filter(p=>p?.bookName===t&&p?.enabled!==!1);if(c.length===0){let p=document.createElement("span");p.className="tt_cardHint",p.textContent="\u8BE5\u8FDE\u63A5\u6682\u65E0\u542F\u7528\u7684\u96A7\u9053",o.appendChild(p);return}for(let p of c){let g=f.find(h=>h?.name===p?.name),S=g?.state??"stopped",_=document.createElement("div");_.className="tt_tunnelPopRow";let l=document.createElement("span");l.className="tt_connDot",l.dataset.state=S==="active"?"connected":S==="error"?"error":"connecting";let d=document.createElement("span");d.className="tt_connTarget",d.title=String(g?.error??g?.lastForwardError??""),d.textContent=Xf(p)+" \xB7 "+S,_.appendChild(l),_.appendChild(d),o.appendChild(_)}})()}function ec(e){let t=1;for(let r of ne.keys()){if(r===e)return String(t);t+=1}return String(t)}function Zf(e,t){let r=ne.get(e);if(r===void 0||t.querySelector(".tt_tabRename")!==null)return;let s=t.querySelector(".tt_tabLabel");if(s===null)return;let o=document.createElement("input");o.className="tt_tabRename",o.value=r.label||"\u7EC8\u7AEF "+ec(e),s.replaceWith(o),o.focus(),o.select();let i=!1,n=()=>{if(i)return;i=!0;let f=o.value.trim();r.label=f!==""?f:void 0,Ue(),Ft()},a=()=>{i||(i=!0,Ue())};o.addEventListener("keydown",f=>{f.stopPropagation(),f.key==="Enter"?n():f.key==="Escape"&&a()}),o.addEventListener("blur",n),o.addEventListener("click",f=>f.stopPropagation())}var zn=[],tc="dialog",Nt="off",Ht={maxDownloadMb:1024,maxUploadMb:2048,maxUploadFiles:1e3},mr=null,It=null,rs=null,Vt=!1;function rc(e){Vt=e,rs!==null&&rs.set(e)}function Qf(e){rc(!(e!==null&&typeof e=="object"&&e.enabled===!1)),e!==null&&typeof e=="object"&&typeof e.statsEnabled=="boolean"&&e.statsEnabled!==Zi&&(Zi=e.statsEnabled,li(),Xt())}function ti(e){Qf(e),e!==null&&typeof e=="object"&&Array.isArray(e.sshHosts)&&(Lt=e.sshHosts),e!==null&&typeof e=="object"&&Array.isArray(e.tunnels)&&(zn=e.tunnels),e!==null&&typeof e=="object"&&(e.sftpStyle==="dual"||e.sftpStyle==="dialog")&&(tc=e.sftpStyle),e!==null&&typeof e=="object"&&(e.persistence==="tmux"||e.persistence==="off")&&(Nt=e.persistence),e!==null&&typeof e=="object"&&typeof e.sftpLimits=="object"&&e.sftpLimits!==null&&(Ht={...Ht,...e.sftpLimits}),e!==null&&typeof e=="object"&&Number.isInteger(e.maxSessions)&&e.maxSessions>=1&&(mr=e.maxSessions)}function e_(e,t){let r=t==="error"||t==="info"?t:"warn",s=document.createElement("div");s.className="tt_toast",s.dataset.kind=r,s.innerHTML='<span class="tt_toastIcon">'+(r==="error"?Fl:r==="info"?Sf:wf)+'</span><span class="tt_toastText"></span>',s.lastElementChild.textContent=e,document.body.appendChild(s),setTimeout(()=>s.remove(),4e3)}async function ic(){try{be({t:"sessions"});let e=await Qi("sessions",3e3);if(e!==null&&Array.isArray(e.list))return It=e.list.length,It}catch{}return null}async function is(){if(await ic(),mr===null||It===null||It<mr)return null;let e=[...ne.values()].filter(s=>!s.exited).length,t=Math.max(0,It-e),r=`\u4F1A\u8BDD\u6570\u5DF2\u8FBE\u4E0A\u9650\uFF08\u5171 ${It} \u4E2A / \u4E0A\u9650 ${mr}\uFF1A\u672C\u7A97\u53E3 ${e} \u4E2A${t>0?" + \u5176\u4ED6\u7A97\u53E3 "+t+" \u4E2A":""}\uFF09\u2014\u2014\u5173\u95ED\u4E0D\u7528\u7684\u7A97\u53E3/\u6807\u7B7E\uFF0C\u6216\u5728\u8BBE\u7F6E\u5361\u7247\u8C03\u5927\u300C\u5E76\u53D1\u4F1A\u8BDD\u4E0A\u9650\u300D`;return e_(r),r}function t_(){return mr!==null&&It!==null&&It>=mr}function Un(){return Math.random().toString(36).slice(2,10)+Date.now().toString(36).slice(-4)}function sc(e){return zn.filter(t=>t?.bookName===e&&t?.enabled!==!1).length}function En(e){let t=Number(e?.port),r=Number.isInteger(t)&&t!==22?":"+t:"",s=e?.auth==="key"?"key":e?.auth==="password"?"password":"agent",o=e?.agentForward===!0?" \xB7 fwd":"";return String(e?.username??"")+"@"+String(e?.host??"")+r+" \xB7 "+s+o}async function Ln(e,t){let r=await fetch("/api/dsh-tty/probe",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({...e,bookRecord:t===!0})}),s=await r.json().catch(()=>({}));return s&&s.ok===!1&&s.error?{error:String(s.error)}:s&&s.result?{result:s.result}:{error:String(s&&s.error?s.error:"\u8FDE\u63A5\u6D4B\u8BD5\u5931\u8D25\uFF08HTTP "+r.status+"\uFF09")}}function Mn(e,t){if(!e)return"\u8FDE\u63A5\u6D4B\u8BD5\u2026";let r=e,s=typeof r.tcp?.ms=="number"?r.tcp.ms:null,o=typeof r.auth?.ms=="number"?r.auth.ms:null,i=[];r.tcp?.ok&&i.push("TCP "+(s!==null?s+"ms":"\u901A")),r.banner?.ok&&i.push("banner \u6B63\u5E38");let n=r.hostkey?.state;if(n==="matched"?i.push("\u4E3B\u673A\u5BC6\u94A5\u5339\u914D"):n==="recorded"?i.push("\u4E3B\u673A\u5BC6\u94A5\u5DF2\u8BB0\u5F55\uFF08TOFU\uFF09"):n==="mismatch"&&i.push("\u4E3B\u673A\u5BC6\u94A5\u4E0D\u5339\u914D\uFF01"),r.auth?.ok)return"\u2705 \u8FDE\u63A5\u6210\u529F\uFF1A"+(o!==null?"\u8BA4\u8BC1\u901A\u8FC7\uFF08"+o+"ms\uFF09":"\u8BA4\u8BC1\u901A\u8FC7")+(i.length?" \xB7 "+i.join(" \xB7 "):"");let a=r.auth?.error||r.tcp?.error||"\u672A\u77E5\u9519\u8BEF";return(t?.prefix||"\u274C \u8FDE\u63A5\u5931\u8D25\uFF1A")+a+(i.length?" \xB7 "+i.join(" \xB7 "):"")}async function jn(){try{let t=await(await fetch("/api/dsh-tty/config",{cache:"no-store"})).json();if(t.ok&&typeof t.config=="object"&&t.config!==null){let r=Lt;ti(t.config),Je!==null&&Lt!==r&&Tn(Je)}}catch{}}function nc(e){Je!==null&&(e.target instanceof Element&&(Je.contains(e.target)||e.target.closest(".tt_tabAdd")!==null)||ft())}function r_(e){if(Je!==null){ft();return}jn(),ic().then(()=>{Je!==null&&Tn(Je)});let t=document.createElement("div");t.className="tt_addMenu",Je=t,Tn(t),document.body.appendChild(t);let r=e.getBoundingClientRect(),s=t.offsetWidth,i=r.left+s>window.innerWidth-8?r.right-s:r.left;t.style.left=Math.max(8,Math.min(i,window.innerWidth-s-8))+"px",t.style.top=r.bottom+6+"px",document.addEventListener("mousedown",nc,!0)}function ft(){Je!==null&&(document.removeEventListener("mousedown",nc,!0),Je.remove(),Je=null)}function Rn(e,t,r,s,o,i){let n=document.createElement("button");if(n.type="button",n.className="tt_addMenuItem",o===!0&&(n.setAttribute("data-soldout",""),n.title="\u4F1A\u8BDD\u6570\u5DF2\u8FBE\u4E0A\u9650\u2014\u2014\u70B9\u51FB\u67E5\u770B\u600E\u4E48\u529E"),i!==void 0){let c=document.createElement("span");c.className="tt_addMenuIcon",c.innerHTML=i,n.appendChild(c)}let a=document.createElement("span");a.className="tt_addMenuText";let f=document.createElement("span");if(f.className="tt_addMenuMain",f.textContent=t,a.appendChild(f),r!==""){let c=document.createElement("span");c.className="tt_addMenuSub",c.textContent=r,a.appendChild(c)}n.appendChild(a),n.addEventListener("click",s),e.appendChild(n)}function Tn(e){e.textContent="";let t=t_();Rn(e,"\u672C\u5730\u7EC8\u7AEF",Nt==="tmux"?"tmux \u6258\u7BA1 \xB7 \u5BBF\u4E3B\u91CD\u542F\u540E\u53EF\u6062\u590D":"\u5728\u5F53\u524D\u4F1A\u8BDD\u5DE5\u4F5C\u76EE\u5F55\u6253\u5F00",async()=>{await is()||(ft(),ei())},t,as);let r=document.createElement("div");r.className="tt_addMenuSep",e.appendChild(r);let s=document.createElement("div");s.className="tt_addMenuTitle",s.textContent="SSH \u8FDE\u63A5\u7C3F",e.appendChild(s);for(let i of Lt){if(i===null||typeof i!="object"||typeof i.name!="string"||i.name==="")continue;let n=document.createElement("div");n.className="tt_addMenuRow";let a=document.createElement("button");a.type="button",a.className="tt_addMenuItem",t&&(a.setAttribute("data-soldout",""),a.title="\u4F1A\u8BDD\u6570\u5DF2\u8FBE\u4E0A\u9650\u2014\u2014\u70B9\u51FB\u67E5\u770B\u600E\u4E48\u529E");let f=document.createElement("span");f.className="tt_addMenuIcon",f.innerHTML=bf;let c=document.createElement("span");c.className="tt_addMenuText";let p=document.createElement("span");p.className="tt_addMenuMain",p.textContent=i.name;let g=document.createElement("span");g.className="tt_addMenuSub";let S=sc(i.name);g.textContent=En(i)+(S>0?" \xB7 \u21C4"+String(S):""),c.appendChild(p),c.appendChild(g),a.appendChild(f),a.appendChild(c),a.addEventListener("click",async()=>{if(await is())return;ft();let d=Nt==="tmux"&&i.persist!==!1?{persist:!0,persistName:Un()}:{};ei({t:"ssh",name:i.name,...d},i.name)});let _=document.createElement("button");_.type="button",_.className="tt_addMenuEdit",_.title="SFTP \u6587\u4EF6\u6D4F\u89C8",_.innerHTML=Jr,_.addEventListener("click",()=>{ft(),us({name:i.name})});let l=document.createElement("button");l.type="button",l.className="tt_addMenuEdit",l.title="\u7F16\u8F91\u8FDE\u63A5",l.innerHTML=In,l.addEventListener("click",()=>{ft(),Cl(i)}),n.appendChild(a),n.appendChild(_),n.appendChild(l),e.appendChild(n)}if(Lt.length===0){let i=document.createElement("div");i.className="tt_addMenuTitle",i.textContent="\uFF08\u7A7A \u2014 \u5728\u8BBE\u7F6E\u5361\u7247\u6216\u300CSSH \u8FDE\u63A5\u2026\u300D\u91CC\u4FDD\u5B58\uFF09",e.appendChild(i)}let o=document.createElement("div");o.className="tt_addMenuSep",e.appendChild(o),Rn(e,"SSH \u8FDE\u63A5\u2026","\u624B\u52A8\u586B\u5199\u4E3B\u673A / \u7528\u6237 / \u8BA4\u8BC1\u65B9\u5F0F",()=>{ft(),Cl()},!1,Wl)}function Cl(e){if(gr!==null)return;let t=e!==null&&typeof e=="object"?e:null,r=t!==null,s=document.createElement("div");s.className="tt_sshBackdrop";let o=document.createElement("div");o.className="tt_sshCard";let i=document.createElement("div");i.className="tt_sshTitle",i.innerHTML=Wl+"<span></span>",i.lastElementChild.textContent=r?"\u7F16\u8F91\u8FDE\u63A5 \xB7 "+String(t.name??""):"SSH \u8FDE\u63A5",o.appendChild(i);let n=N=>{let x=document.createElement("div");return x.className="tt_sshSection",x.textContent=N,x},a={},f=(N,x,O)=>{let H=document.createElement("label");H.className="tt_sshRow";let $=document.createElement("span");$.className="tt_cardLabel",$.textContent=x,H.appendChild($);let U;if(O?.select!==void 0){U=document.createElement("select");for(let X of O.select){let ee=document.createElement("option");ee.value=X.value,ee.textContent=X.label,U.appendChild(ee)}}else U=document.createElement("input"),U.type=O?.type??"text",U.placeholder=O?.placeholder??"";return U.className="tt_cardInput",U.autocomplete="off",U.spellcheck=!1,H.appendChild(U),a[N]=U,H};o.appendChild(n("\u8FDE\u63A5"));let c=document.createElement("div");c.className="tt_sshGrid",c.appendChild(f("host","\u4E3B\u673A",{placeholder:"example.com \u6216 IP"})),c.appendChild(f("port","\u7AEF\u53E3",{placeholder:"22"})),o.appendChild(c),o.appendChild(f("username","\u7528\u6237\u540D",{placeholder:"root"})),o.appendChild(n("\u8BA4\u8BC1")),o.appendChild(f("auth","\u8BA4\u8BC1\u65B9\u5F0F",{select:[{value:"agent",label:"agent \u2014 \u4F7F\u7528\u672C\u673A ssh-agent"},{value:"key",label:"key \u2014 \u79C1\u94A5\u6587\u4EF6"},{value:"password",label:"password \u2014 \u5BC6\u7801"}]}));let p=f("keyPath","\u79C1\u94A5\u8DEF\u5F84",{placeholder:"~/.ssh/id_ed25519"}),g=f("passphrase","\u79C1\u94A5\u53E3\u4EE4\uFF08\u53EF\u7A7A\uFF09",{type:"password"}),S=f("password","\u5BC6\u7801",{type:"password"}),_=(N,x)=>{let O=document.createElement("div");O.className="tt_sshRow tt_envRow";let H=document.createElement("input");H.type="text",H.className="tt_cardInput",H.placeholder="\u6216\uFF1A\u9009\u62E9\u51ED\u636E\u5B58\u50A8\u91CC\u7684\u5F15\u7528\u540D",H.title="\u5019\u9009 = \u51ED\u636E\u5B58\u50A8\u91CC\u5DF2\u6709\u7684\u5F15\u7528\u540D + \u672C\u673A\u8FDE\u63A5\u7C3F\u91CC\u5728\u7528\u7684\u5F15\u7528\u540D",H.autocomplete="off",H.spellcheck=!1;let $=document.createElement("span");$.className="tt_cardHint tt_envEmpty",$.textContent=x,$.hidden=!0,H.hidden=!0;let U=document.createElement("div");U.className="tt_envList",U.dataset.hidden="";let X=[],ee=()=>{if(U.textContent="",X.length===0){let K=document.createElement("span");K.className="tt_cardHint",K.textContent=x,U.appendChild(K);return}let re=H.value.trim().toUpperCase(),Q=re===""?X:X.filter(K=>K.toUpperCase().includes(re));for(let K of Q.slice(0,30)){let J=document.createElement("button");J.type="button",J.className="tt_envItem",J.textContent=K;let oe="env:"+K,ie=null,he=()=>{ie!==null&&(clearTimeout(ie),ie=null),J.textContent=K,delete J.dataset.danger};J.addEventListener("mousedown",Ce=>Ce.preventDefault()),J.addEventListener("click",()=>{let Ce=N.value;if(Ce===""||Ce.startsWith("env:")||ie!==null){he(),N.value=oe,N.focus(),N.dispatchEvent(new Event("change"));return}J.textContent=K+"\uFF08\u518D\u70B9\u8986\u76D6\u5DF2\u586B\uFF09",J.dataset.danger="",ie=setTimeout(he,4e3)}),U.appendChild(J)}if(Q.length>30){let K=document.createElement("span");K.className="tt_envMore",K.textContent="\u8FD8\u6709 "+(Q.length-30)+" \u4E2A \u2014 \u7EE7\u7EED\u8F93\u5165\u7B5B\u9009",U.appendChild(K)}else if(Q.length===0){let K=document.createElement("span");K.className="tt_envMore",K.textContent="\u6CA1\u6709\u5339\u914D\u7684\u5F15\u7528",U.appendChild(K)}};return H.addEventListener("input",ee),H.addEventListener("focus",()=>{X.length>0&&delete U.dataset.hidden}),H.addEventListener("blur",()=>{H.value.trim()===""&&(U.dataset.hidden="")}),O.appendChild(H),O.appendChild($),O.appendChild(U),{row:O,setNames(re){X=Array.isArray(re)?re:[];let Q=X.length>0;H.hidden=!Q,$.hidden=Q,ee()}}},l=(N,x)=>{let O=document.createElement("div");O.className="tt_sshRow tt_credRow";let H=document.createElement("label");H.className="tt_credToggle";let $=document.createElement("input");$.type="checkbox",$.className="tt_cardCheckbox";let U=document.createElement("span");U.textContent="\u4FDD\u5B58\u65F6\u5B58\u5165\u51ED\u636E\u5B58\u50A8",H.appendChild($),H.appendChild(U),$.checked=_t!==null,H.title="\u52FE\u9009\u540E\uFF0C\u70B9\u300C\u4FDD\u5B58\u4FEE\u6539\u300D\u6216\u300C\u8FDE\u63A5\uFF08\u5E76\u4FDD\u5B58\uFF09\u300D\u65F6\u628A\u5BC6\u7801\u5199\u8FDB\u5B98\u65B9\u51ED\u636E\u5B58\u50A8\uFF0C\u5B57\u6BB5\u91CC\u53EA\u7559 env: \u5F15\u7528\uFF08\u503C\u5728 ~/.dsh/.credentials.yaml\uFF0C\u4E0D\u8FDB\u73AF\u5883\u3001\u4E0D\u56DE\u4F20\u6D4F\u89C8\u5668\uFF1B\u6321\u4E0D\u4F4F\u540C\u7528\u6237\u8FDB\u7A0B\u4E0E agent\uFF09\u3002\u4E0D\u52FE\u9009\u5219\u6309\u73B0\u72B6\u660E\u6587\u5199\u8FDB\u8BBE\u7F6E\u6587\u4EF6\u3002\u80FD\u7528\u5BC6\u94A5 / agent \u5C31\u522B\u5B58\u5BC6\u7801\u3002";let X=document.createElement("button");X.type="button",X.className="tt_toolBtn tt_credClear",X.textContent="\u6E05\u9664\u5DF2\u5B58\u51ED\u636E",X.dataset.hidden="";let ee=document.createElement("span");ee.className="tt_credStatus",O.appendChild(H),O.appendChild(X),O.appendChild(ee);let re=(J,oe)=>{ee.textContent=J,ee.dataset.kind=oe},Q=async()=>{let J=fr(N.value),oe=J!=="";if(H.hidden=oe,X.hidden=!oe,ee.hidden=!1,br()===null){$.disabled=!0,$.checked=!1,X.disabled=!0,re(_t===null?"\u5BBF\u4E3B\u672A\u63D0\u4F9B\u51ED\u636E\u670D\u52A1\uFF08remote.credentials\uFF09\uFF0C\u53EA\u80FD\u660E\u6587\u4FDD\u5B58":"\u51ED\u636E\u670D\u52A1\u4E0D\u5B8C\u6574\uFF0C\u53EA\u80FD\u660E\u6587\u4FDD\u5B58","muted");return}if($.disabled=!1,!oe){ee.hidden=!0,re("","plain");return}let ie=await Rl(J);if(ie.unreported===!0){re("\u5F15\u7528 "+J+"\uFF1A\u5BBF\u4E3B\u672A\u62A5\u544A\u72B6\u6001","plain");return}if(ie.error!==void 0){re("\u8BFB\u53D6\u51ED\u636E\u72B6\u6001\u5931\u8D25\uFF1A"+ie.error,"error");return}let he=ie.view;re(he.configured?"\u5DF2\u5B58\u5165"+(he.source!==""?"\uFF08\u6765\u6E90 "+he.source+"\uFF09":"")+" \xB7 "+J:"\u5F15\u7528 "+J+"\uFF1A\u5B58\u50A8\u91CC\u8FD8\u6CA1\u6709\u8FD9\u4E2A\u503C",he.configured?"ok":"plain"),X.disabled=he.configured!==!0||he.writable!==!0};X.addEventListener("click",()=>{(async()=>{let J=fr(N.value);if(J==="")return;let oe=await Tl(J);if(oe.error!==void 0){re(oe.error,"error");return}N.value="",await Q()})()});let K=async()=>{let J=await Al($.checked===!0,N.value,a.host.value,a.port.value,a.username.value,x);return J.value!==void 0&&(N.value=J.value,await Q()),J};return N.addEventListener("change",()=>{Q()}),{row:O,refresh:Q,storeIfRequested:K}},d=_(a.passphrase,"\u8FD8\u6CA1\u6709\u522B\u7684\u8FDE\u63A5\u7528\u8FC7\u51ED\u636E\u5F15\u7528 \u2014 \u53EF\u5728\u79C1\u94A5\u53E3\u4EE4\u6846\u76F4\u63A5\u624B\u8F93 env:NAME"),h=_(a.password,"\u8FD8\u6CA1\u6709\u522B\u7684\u8FDE\u63A5\u7528\u8FC7\u51ED\u636E\u5F15\u7528 \u2014 \u52FE\u4E0A\u9762\u7684\u300C\u4FDD\u5B58\u65F6\u5B58\u5165\u51ED\u636E\u5B58\u50A8\u300D\u65B0\u5EFA\u4E00\u4E2A\uFF0C\u6216\u76F4\u63A5\u5728\u5BC6\u7801\u6846\u624B\u8F93 env:NAME"),u=l(a.password,"PASSWORD");(async()=>{let N=await Ml();d.setNames(N),h.setNames(N)})(),o.appendChild(p),o.appendChild(g),o.appendChild(d.row),o.appendChild(S),o.appendChild(u.row),o.appendChild(h.row),o.appendChild(n("\u9009\u9879"));let v=document.createElement("label");v.className="tt_cardRow";let y=document.createElement("input");y.type="checkbox",y.className="tt_cardCheckbox";let b=document.createElement("span");b.className="tt_cardLabel",b.textContent="agent forwarding\uFF08\u8FDC\u7A0B\u53EF\u7528\u672C\u5730 ssh-agent \u94A5\u5319\uFF0C\u5982\u8FDC\u7A0B git clone\uFF09",v.appendChild(y),v.appendChild(b),o.appendChild(v);let C=document.createElement("label");C.className="tt_cardRow";let m=document.createElement("input");m.type="checkbox",m.className="tt_cardCheckbox";let E=document.createElement("span");E.className="tt_cardLabel",E.textContent="\u6301\u4E45\u4F1A\u8BDD\uFF08tmux \u6258\u7BA1\uFF0C\u65AD\u7EBF/\u91CD\u542F\u540E\u6062\u590D\u73B0\u573A\uFF1B\u8FDC\u7A0B\u9700\u5B89\u88C5 tmux\uFF09",C.appendChild(m),C.appendChild(E),m.checked=Nt==="tmux",Nt==="tmux"&&o.appendChild(C);let P=document.createElement("label");P.className="tt_cardRow";let B=document.createElement("input");B.type="checkbox",B.className="tt_cardCheckbox";let F=document.createElement("span");F.className="tt_cardLabel",F.textContent="\u4FDD\u5B58\u5230\u8FDE\u63A5\u7C3F\uFF08\u540C\u540D\u8986\u76D6\uFF09",P.appendChild(B),P.appendChild(F),o.appendChild(P);let R=f("name","\u8FDE\u63A5\u7C3F\u540D\u79F0",{placeholder:"\u7559\u7A7A\u5219\u7528\u4E3B\u673A\u540D"});R.style.display="none",o.appendChild(R),B.addEventListener("change",()=>{R.style.display=B.checked?"":"none",B.checked&&a.name.value.trim()===""&&a.host.value.trim()!==""&&(a.name.value=a.host.value.trim()),B.checked&&a.name.focus()}),r&&(P.style.display="none",a.name.value=String(t.name??""),R.style.display="",a.host.value=String(t.host??""),a.port.value=String(t.port??22),a.username.value=String(t.username??""),a.auth.value=t.auth==="key"||t.auth==="password"?String(t.auth):"agent",a.keyPath.value=String(t.keyPath??""),a.passphrase.value=String(t.passphrase??""),a.password.value=String(t.password??""),y.checked=t.agentForward===!0,m.checked=Nt==="tmux");let j=document.createElement("div");j.className="tt_sshStatus";let A=document.createElement("div");A.className="tt_sshError";let T=document.createElement("div");T.className="tt_sshProbeResult",j.appendChild(A),j.appendChild(T),o.appendChild(j);let W=()=>{A.textContent="";let N=a.host.value.trim(),x=a.username.value.trim(),O=Number(a.port.value);if((!Number.isInteger(O)||O<1||O>65535)&&(O=22),N===""||x==="")return A.textContent="\u4E3B\u673A\u4E0E\u7528\u6237\u540D\u5FC5\u586B",null;let H=a.auth.value,$={host:N,port:O,username:x,auth:H};if(H==="key"){let U=a.keyPath.value.trim();if(U==="")return A.textContent="auth=key \u9700\u8981\u79C1\u94A5\u8DEF\u5F84",null;$.keyPath=U;let X=a.passphrase.value;X!==""&&($.passphrase=X)}if(H==="password"){let U=a.password.value;if(U==="")return A.textContent="auth=password \u9700\u8981\u5BC6\u7801",null;$.password=U}return y.checked&&($.agentForward=!0),$},D=document.createElement("div");D.className="tt_sshActions";let w=document.createElement("div");w.className="tt_sshActionsGroup";let L=document.createElement("div");L.className="tt_sshActionsGroup",D.appendChild(w),D.appendChild(L);let k=document.createElement("button");k.type="button",k.className="tt_toolBtn",k.textContent="\u53D6\u6D88";let M=document.createElement("button");M.type="button",M.className="tt_cardSave",M.textContent="\u8FDE\u63A5",w.appendChild(k);let z=document.createElement("button");z.type="button",z.className="tt_toolBtn",z.textContent="\u6587\u4EF6\u6D4F\u89C8",z.title="\u4E0D\u52A8\u7EC8\u7AEF\uFF0C\u76F4\u63A5\u4EE5\u5F53\u524D\u586B\u5199\u7684\u4FE1\u606F\u6253\u5F00 SFTP \u6587\u4EF6\u6D4F\u89C8",z.addEventListener("click",()=>{A.textContent="";let N=a.host.value.trim(),x=a.username.value.trim(),O=Number(a.port.value);if((!Number.isInteger(O)||O<1||O>65535)&&(O=22),N===""||x===""){A.textContent="\u4E3B\u673A\u4E0E\u7528\u6237\u540D\u5FC5\u586B";return}let H=a.auth.value,$={host:N,port:O,username:x,auth:H};if(H==="key"){let U=a.keyPath.value.trim();if(U===""){A.textContent="auth=key \u9700\u8981\u79C1\u94A5\u8DEF\u5F84";return}$.keyPath=U;let X=a.passphrase.value;X!==""&&($.passphrase=X)}if(H==="password"){let U=a.password.value;if(U===""){A.textContent="auth=password \u9700\u8981\u5BC6\u7801";return}$.password=U}y.checked&&($.agentForward=!0),Ot(),us($)}),w.appendChild(z);let q=null;r&&(q=document.createElement("button"),q.type="button",q.className="tt_toolBtn",q.textContent="\u4FDD\u5B58\u4FEE\u6539",q.addEventListener("click",()=>{A.textContent="";let N=a.host.value.trim(),x=a.username.value.trim();if(N===""||x===""){A.textContent="\u4E3B\u673A\u4E0E\u7528\u6237\u540D\u5FC5\u586B";return}let O=Number(a.port.value);(!Number.isInteger(O)||O<1||O>65535)&&(O=22);let H=a.auth.value,U={name:a.name.value.trim()||N,host:N,port:O,username:x,auth:H,keyPath:H==="key"?a.keyPath.value.trim():"",passphrase:a.passphrase.value,password:a.password.value,agentForward:y.checked,persist:m.checked};if(H==="key"&&U.keyPath===""){A.textContent="auth=key \u9700\u8981\u79C1\u94A5\u8DEF\u5F84";return}q!==null&&(q.disabled=!0),(async()=>{let X=await u.storeIfRequested();if(X.error!==void 0){A.textContent=X.error,q!==null&&(q.disabled=!1);return}X.value!==void 0&&(U.password=X.value);let ee=await s_(String(t.name??""),U);if(q!==null&&(q.disabled=!1),ee!==void 0){A.textContent="\u4FDD\u5B58\u5931\u8D25\uFF1A"+ee;return}Ot()})()}),w.appendChild(q));let Y=document.createElement("button");Y.type="button",Y.className="tt_toolBtn",Y.textContent="\u8BD5\u8FDE",Y.title="\u6309\u5F53\u524D\u586B\u5199\u8BCA\u65AD\u8FDE\u63A5\uFF08TCP \u2192 \u4E3B\u673A\u5BC6\u94A5 \u2192 \u8BA4\u8BC1\uFF09\uFF1B\u4E0D\u4F1A\u65B0\u5EFA\u4F1A\u8BDD\uFF0C\u4E5F\u4E0D\u8BB0\u5F55\u4E3B\u673A\u6307\u7EB9",Y.addEventListener("click",()=>{let N=W();N!==null&&(T.className="tt_sshProbeResult",T.textContent="\u8FDE\u63A5\u6D4B\u8BD5\u4E2D\u2026",Y.disabled=!0,Ln(N,!1).then(x=>{Y.disabled=!1,x.result?(T.className="tt_sshProbeResult"+(x.result.auth?.ok===!0?" tt_sshProbeOk":" tt_sshProbeBad"),T.textContent=Mn(x.result)):(T.className="tt_sshProbeResult tt_sshProbeBad",T.textContent="\u274C \u8FDE\u63A5\u5931\u8D25\uFF1A"+String(x.error||"\u672A\u77E5\u9519\u8BEF"))}))}),w.appendChild(Y),L.appendChild(M),o.appendChild(D);let Z=()=>{p.style.display=a.auth.value==="key"?"":"none",g.style.display=a.auth.value==="key"?"":"none",d.row.style.display=a.auth.value==="key"?"":"none",S.style.display=a.auth.value==="password"?"":"none",h.row.style.display=a.auth.value==="password"?"":"none",u.row.style.display=a.auth.value==="password"?"":"none"};a.auth.addEventListener("change",Z),Z(),u.refresh(),k.addEventListener("click",()=>Ot()),s.addEventListener("mousedown",N=>{N.target===s&&Ot()}),M.addEventListener("click",async()=>{A.textContent="";let N=await is();if(N!==null){A.textContent=N;return}let x=a.host.value.trim(),O=a.username.value.trim(),H=Number(a.port.value);if((!Number.isInteger(H)||H<1||H>65535)&&(H=22),x===""||O===""){A.textContent="\u4E3B\u673A\u4E0E\u7528\u6237\u540D\u5FC5\u586B";return}let $=a.auth.value,U={t:"ssh",host:x,port:H,username:O,auth:$};if($==="key"){let Q=a.keyPath.value.trim();Q!==""&&(U.keyPath=Q);let K=a.passphrase.value;K!==""&&(U.passphrase=K)}if($==="password"){let Q=a.password.value;Q!==""&&(U.password=Q)}y.checked&&(U.agentForward=!0),m.checked&&(U.persist=!0,U.persistName=Un());let X=H!==22?O+"@"+x+":"+H:O+"@"+x,ee=Q=>{Ot(),se!==null&&ei(U,Q!==""?Q:X)};if(!B.checked){ee("");return}let re=a.name.value.trim()||x;M.disabled=!0,(async()=>{let Q=await u.storeIfRequested();if(Q.error!==void 0){A.textContent=Q.error,M.disabled=!1;return}let K=Q.value??U.password??"",J=await i_({name:re,host:x,port:H,username:O,auth:$,keyPath:U.keyPath??"",passphrase:U.passphrase??"",password:K,agentForward:y.checked,persist:m.checked});if(M.disabled=!1,J!==void 0){A.textContent="\u4FDD\u5B58\u8FDE\u63A5\u7C3F\u5931\u8D25\uFF1A"+J;return}ee(re)})()}),s.appendChild(o),document.body.appendChild(s),gr=s,a.host.focus()}function Ot(){gr!==null&&(gr.remove(),gr=null)}async function i_(e){let t=[...Lt.filter(r=>r?.name!==e.name),e];try{let r=await fetch("/api/dsh-tty/config",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({sshHosts:t})}),s=await r.json().catch(()=>({}));if(!r.ok||!s.ok)return String(s.error||"HTTP "+r.status);ti(s.config);return}catch(r){return String(r&&r.message?r.message:r)}}async function s_(e,t){if(t.name!==e&&Lt.some(s=>s?.name===t.name))return"\u8FDE\u63A5\u7C3F\u91CC\u5DF2\u6709\u540C\u540D\u6761\u76EE: "+t.name;let r=Lt.map(s=>s?.name===e?t:s);try{let s=await fetch("/api/dsh-tty/config",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({sshHosts:r})}),o=await s.json().catch(()=>({}));if(!s.ok||!o.ok)return String(o.error||"HTTP "+s.status);ti(o.config);return}catch(s){return String(s&&s.message?s.message:s)}}function n_(e,t,r){let s=cr(r,me);if(ac(s))return;let o=document.createElement("div");o.className="tt_sftpDualCard";let i=document.createElement("div");i.className="tt_sftpTitleRow";let n=document.createElement("div");n.className="tt_sshTitle",n.innerHTML=Jr+"<span></span>",n.lastElementChild.textContent="SFTP \u53CC\u680F \xB7 "+t;let a=document.createElement("button");a.type="button",a.className="tt_close",a.title="\u5173\u95ED",a.innerHTML=ls,a.addEventListener("click",()=>yr(s)),i.appendChild(n),i.appendChild(a),o.appendChild(i);let f=document.createElement("div");f.className="tt_sftpStatus";let c=(w,L)=>{f.textContent=w,L===void 0?delete f.dataset.state:f.dataset.state=L},p=!1,g=(w,L)=>{if(!(p||_.local.busy||_.remote.busy)){p=!0;for(let k of[_.local,_.remote])k.setBusy(!0);c(w,"busy"),Promise.resolve().then(L).catch(k=>{(k===null||typeof k!="object"||k.name!=="TransferCanceledError")&&A.fail("\u5931\u8D25"),c(String(k&&k.message?k.message:k),"error")}).finally(()=>{p=!1;for(let k of[_.local,_.remote])k.setBusy(!1)})}},S=w=>{_[w].bar.after(d),d.style.display="",h.focus(),h.select()},_={},l=(w,L)=>{let k={kind:w,path:"",busy:!1},M=document.createElement("div");M.className="tt_sftpPane";let z=document.createElement("div");z.className="tt_sftpPaneHead";let q=document.createElement("span");q.textContent=L;let Y=document.createElement("span");Y.className="tt_sftpPaneMeta",z.appendChild(q),z.appendChild(Y),M.appendChild(z);let Z=document.createElement("div");Z.className="tt_sftpBar";let N=document.createElement("input");N.type="text",N.className="tt_sftpPath",N.placeholder=w==="local"?"\u672C\u673A\u8DEF\u5F84\uFF08\u56DE\u8F66\u8DF3\u8F6C\uFF09":"\u8FDC\u7A0B\u8DEF\u5F84\uFF08\u56DE\u8F66\u8DF3\u8F6C\uFF09",N.spellcheck=!1,N.autocomplete="off";let x=document.createElement("button");x.type="button",x.className="tt_toolBtn",x.innerHTML=Nn+"<span>\u5237\u65B0</span>";let O=document.createElement("button");O.type="button",O.className="tt_toolBtn",O.innerHTML=Il+"<span>\u65B0\u5EFA\u76EE\u5F55</span>",Z.appendChild(N),Z.appendChild(x),Z.appendChild(O),M.appendChild(Z);let H=document.createElement("div");H.className="tt_sftpList",M.appendChild(H),k.bar=Z;let $=K=>{k.busy=K;for(let J of[x,O])J.disabled=K;N.disabled=K},U=async(K,J)=>{let oe=w==="local"?"/api/dsh-tty/local-fs/":"/api/dsh-tty/sftp/",ie=w==="local"?J:{...e,...J},he=await fetch(oe+K,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(ie)}),Ce=await he.json().catch(()=>({}));if(!he.ok||Ce.ok!==!0)throw new Error(String(Ce.error||"HTTP "+he.status));return Ce},X=(K,J)=>{if(!(k.busy||p))return $(!0),c(K,"busy"),Promise.resolve().then(J).catch(oe=>c(String(oe&&oe.message?oe.message:oe),"error")).finally(()=>$(!1))},ee=(K,J)=>{if(K===void 0||K==="")throw new Error("\u76EE\u5F55\u5C1A\u672A\u5B9A\u4F4D\u5B8C\u6210");return K.endsWith("/")||K.endsWith("\\")?K+J:K+"/"+J},re=K=>{let J=ee(k.path,K.name),oe=[];K.isDir===!0?oe.push("\u76EE\u5F55"):oe.push($e(Number(K.size))||"\u2014");let ie=cc(Number(K.mtime));ie!==""&&oe.push(ie);let he=C(K.isDir?Jr:K.isSymlink?Pl:Bl,K.name,oe.join(" \xB7 "),K.isDir===!0?"dir":K.isSymlink===!0?"link":"file"),Ce=()=>k.loadDir(k.path),de=w==="local"?_.remote:_.local;return K.isDir===!0&&he.addEventListener("click",ve=>{ve.target instanceof Element&&ve.target.closest(".tt_sftpAct")!==null||k.loadDir(J)}),m(he,w==="local"?Nl:Hl,"\u4F20\u8F93\u5230"+(w==="local"?"\u8FDC\u7A0B":"\u672C\u673A")+"\uFF1A"+de.path,()=>{if(k.path===""||de.path===""){c("\u4E24\u4FA7\u76EE\u5F55\u5C1A\u672A\u5B9A\u4F4D\u5B8C\u6210\uFF0C\u7B49\u5217\u8868\u52A0\u8F7D\u540E\u518D\u4F20\u8F93","error");return}A.reset(),A.pulse(0),g("\u4F20\u8F93 "+K.name+"\u2026",async()=>{let ve=await fetch("/api/dsh-tty/local-fs/transfer",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({action:"start",direction:w==="local"?"up":"down",...e,localPath:w==="local"?J:ee(de.path,K.name),remotePath:w==="local"?ee(de.path,K.name):J})}),pe=await ve.json().catch(()=>({}));if(!ve.ok||pe.ok!==!0)throw A.fail("\u4F20\u8F93\u5931\u8D25"),new Error(String(pe.error||"HTTP "+ve.status));let Oe=pe.job?.id;if(typeof Oe!="string"||Oe==="")throw A.fail("\u4F20\u8F93\u5931\u8D25"),new Error("\u670D\u52A1\u7AEF\u672A\u8FD4\u56DE\u4EFB\u52A1 id");await T(Oe,K.name)==="canceled"?(A.reset(),c("\u5DF2\u53D6\u6D88\u4F20\u8F93 "+K.name)):(A.done("\u5B8C\u6210"),setTimeout(()=>A.reset(),1500),c("\u5DF2\u4F20\u8F93 "+K.name)),await de.loadDir(de.path)})}),w!=="local"&&K.isDir!==!0&&m(he,Ol,"\u4E0B\u8F7D "+K.name,()=>{P(K,J)}),m(he,In,"\u91CD\u547D\u540D "+K.name,()=>{h.placeholder="\u65B0\u540D\u79F0",h.value=K.name,S(w),y=async()=>{let ve=h.value.trim();ve===""||ve===K.name||(b(),await k.runTask("\u91CD\u547D\u540D "+K.name+"\u2026",async()=>{await U("rename",{from:J,to:ee(k.path,ve)}),await Ce()}))}}),E(he,()=>k.runTask("\u5220\u9664 "+K.name+"\u2026",async()=>{await U("remove",{path:J,recursive:K.isDir===!0}),await Ce(),c("\u5DF2\u5220\u9664 "+K.name)}),K),he},Q=K=>{if(H.textContent="",k.path!==""&&k.path!=="/"&&/^[A-Za-z]:[\\/]?$/.test(k.path)===!1){let ie=C(On,"..\uFF08\u4E0A\u7EA7\u76EE\u5F55\uFF09","","up");ie.addEventListener("click",()=>{let he=w==="local"?l_(k.path):hc(k.path);he!==null&&k.loadDir(he)}),H.appendChild(ie)}let J=Array.isArray(K)?K:[];if(J.length===0){let ie=document.createElement("div");ie.className="tt_addMenuTitle",ie.textContent="\uFF08\u7A7A\u76EE\u5F55\uFF09",H.appendChild(ie);return}let oe=500;for(let ie of J.slice(0,oe))ie===null||typeof ie!="object"||typeof ie.name!="string"||ie.name===""||H.appendChild(re(ie));if(J.length>oe){let ie=document.createElement("div");ie.className="tt_addMenuTitle",ie.textContent=`\u2026\u5176\u4F59 ${String(J.length-oe)} \u9879\u672A\u6E32\u67D3\uFF08\u5171 ${String(J.length)} \u9879\uFF09\u2014\u2014\u7528\u4E0A\u65B9\u8DEF\u5F84\u6846\u8DF3\u8F6C\u5230\u5B50\u76EE\u5F55\u5B9A\u4F4D`,H.appendChild(ie)}};return k.loadDir=async K=>{try{let J=await U("list",{path:K??k.path});k.path=typeof J.path=="string"&&J.path!==""?J.path:k.path,N.value=k.path;let oe=Array.isArray(J.entries)?J.entries.length:0;Q(J.entries),Y.textContent=String(oe)+" \u9879",c(k.path)}catch(J){c(String(J&&J.message?J.message:J),"error")}},k.runTask=X,k.setBusy=$,_[w]=k,x.addEventListener("click",()=>{k.runTask("\u52A0\u8F7D\u4E2D\u2026",()=>k.loadDir(k.path))}),O.addEventListener("click",()=>{k.busy||p||(h.placeholder="\u65B0\u76EE\u5F55\u540D\uFF08\u76F8\u5BF9\u5F53\u524D\u76EE\u5F55\uFF09",h.value="",S(w),y=async()=>{let K=h.value.trim();K!==""&&(b(),await k.runTask("\u521B\u5EFA\u76EE\u5F55 "+K+"\u2026",async()=>{await U("mkdir",{path:ee(k.path,K),parents:!0}),await k.loadDir(k.path)}))})}),N.addEventListener("keydown",K=>{if(K.key!=="Enter"||(K.preventDefault(),k.busy||p))return;let J=N.value.trim();J!==""&&k.runTask("\u52A0\u8F7D\u4E2D\u2026",()=>k.loadDir(J))}),M},d=document.createElement("div");d.className="tt_sftpEditor",d.style.display="none";let h=document.createElement("input");h.type="text",h.className="tt_cardInput",h.spellcheck=!1,h.autocomplete="off";let u=document.createElement("button");u.type="button",u.className="tt_toolBtn",u.textContent="\u786E\u5B9A";let v=document.createElement("button");v.type="button",v.className="tt_toolBtn",v.textContent="\u53D6\u6D88",d.appendChild(h),d.appendChild(u),d.appendChild(v);let y=null,b=()=>{d.style.display="none",h.value="",y=null};u.addEventListener("click",()=>{y?.()}),v.addEventListener("click",b),h.addEventListener("keydown",w=>{w.key==="Enter"?(w.preventDefault(),y?.()):w.key==="Escape"&&(w.stopPropagation(),b())});let C=(w,L,k,M)=>{let z=document.createElement("button");z.type="button",z.className="tt_sftpRow";let q=document.createElement("span");q.className="tt_sftpIcon",q.innerHTML=w,M!==void 0&&(q.dataset.kind=M);let Y=document.createElement("span");if(Y.className="tt_sftpName",Y.textContent=L,Y.title=L,z.appendChild(q),z.appendChild(Y),k!==""){let Z=document.createElement("span");Z.className="tt_sftpMeta",Z.textContent=k,z.appendChild(Z)}return z},m=(w,L,k,M)=>{let z=document.createElement("button");z.type="button",z.className="tt_sftpAct",z.innerHTML=L,z.title=k,z.addEventListener("click",q=>{q.stopPropagation(),M()}),w.appendChild(z)},E=(w,L,k)=>{let M=document.createElement("button");M.type="button",M.className="tt_sftpAct",M.innerHTML=_r,M.title="\u5220\u9664 "+k.name+(k.isDir?"\uFF08\u542B\u5185\u5BB9\uFF09":"");let z=null;M.addEventListener("click",q=>{if(q.stopPropagation(),z!==null){clearTimeout(z),z=null,M.innerHTML=_r,delete M.dataset.danger,L();return}M.textContent="\u786E\u8BA4?",M.dataset.danger="",z=setTimeout(()=>{z=null,M.innerHTML=_r,delete M.dataset.danger},4e3)}),w.appendChild(M)},P=(w,L)=>_.remote.runTask("\u4E0B\u8F7D "+w.name+"\u2026",async()=>{A.reset();let k;try{k=await uc("/api/dsh-tty/sftp/download",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({...e,path:L})},(M,z)=>{A.set(M,z)},Ht.maxDownloadMb,M=>A.setCancel(M))}catch(M){if(An(M)){A.reset(),c("\u5DF2\u53D6\u6D88\u4E0B\u8F7D "+w.name);return}throw A.fail("\u4E0B\u8F7D\u5931\u8D25"),M}A.done("\u5B8C\u6210"),fc(k,w.name),setTimeout(()=>A.reset(),1500),c("\u5DF2\u4E0B\u8F7D "+w.name+"\uFF08"+($e(k.size)||String(k.size)+" B")+"\uFF09")}),B=l("local","\u672C\u673A"),F=l("remote","\u8FDC\u7A0B");_.local.wrap=B,_.remote.wrap=F;let R=document.createElement("div");R.className="tt_sftpDual",R.appendChild(B),R.appendChild(F),o.appendChild(R),o.appendChild(d);let j=document.createElement("div");j.className="tt_sftpFoot";let A=dc();j.appendChild(A.el),j.appendChild(f),o.appendChild(j);let T=async(w,L)=>{let k=!1;A.setCancel(()=>{k||(k=!0,fetch("/api/dsh-tty/local-fs/transfer",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({action:"cancel",job:w})}).catch(()=>{}))});try{for(;;){await new Promise(Y=>setTimeout(Y,400));let M=await fetch("/api/dsh-tty/local-fs/transfer",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({action:"status",job:w})}),z=await M.json().catch(()=>({}));if(!M.ok||z.ok!==!0){if(k)return"canceled";throw new Error(String(z.error||"HTTP "+M.status))}let q=z.job;if(q===null||typeof q!="object")throw new Error("\u670D\u52A1\u7AEF\u8FD4\u56DE\u4E86\u975E\u6CD5\u7684\u4EFB\u52A1\u72B6\u6001");if(q.state==="running"){let Y=typeof q.current=="string"&&q.current!==""?q.current:L;c("\u4F20\u8F93 "+Y+"\u2026","busy"),Number.isFinite(q.total)&&q.total>0?A.set(Number(q.bytes)||0,q.total):A.pulse(Number(q.bytes)||0);continue}if(q.state==="canceled")return"canceled";if(q.state!=="done")throw new Error(String(q.error||"\u4F20\u8F93\u5931\u8D25"));return"done"}}finally{A.setCancel(null)}},W=Wn(),D=W===null?420:Math.round(W.height*.56);lc(o,"SFTP \u53CC\u680F \xB7 "+t,D,s),_.local.loadDir(""),_.remote.loadDir("")}var Mt=null,pt=null;function oc(){return pt!==null&&_n(pt.ownerKey,me)?pt.ownerKey:cr(void 0,me)}var ac=(e=oc())=>Mt!==null||pt!==null&&pt.ownerKey===e;function lc(e,t,r,s){let o=cr(s,me),i=st!==null&&st.ownerKey===o;if(se!==null&&!Ae&&Xe!==null&&!i)try{let a=Jl({title:t,side:"bottom",size:r,min:200,ownerSid:o,onClose:()=>yr(o)});a.element.appendChild(e),pt=a;return}catch(a){console.warn("[dsh-tty] SFTP \u6302\u5230\u7EC8\u7AEF\u6302\u8F7D\u4F4D\u5931\u8D25\uFF0C\u56DE\u9000\u5BF9\u8BDD\u6846\uFF1A"+(a instanceof Error?a.message:String(a)))}let n=document.createElement("div");n.className="tt_sshBackdrop",n.appendChild(e),n.addEventListener("mousedown",a=>{a.target===n&&yr()}),document.body.appendChild(n),Mt=n}var Xr=null;function o_(){let e=Xr;if(Xr=null,e!==null)try{e.click()}catch{}}function a_(e){let t=new TextEncoder().encode(e),r="";for(let s of t)r+=String.fromCharCode(s);return btoa(r).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function cc(e){let t=new Date(e);if(Number.isNaN(t.getTime()))return"";let r=s=>String(s).padStart(2,"0");return t.getFullYear()+"-"+r(t.getMonth()+1)+"-"+r(t.getDate())+" "+r(t.getHours())+":"+r(t.getMinutes())}function hc(e){let t=String(e).replace(/\/+$/,""),r=t.lastIndexOf("/");return r<=0?"/":t.slice(0,r)}function l_(e){let t=String(e).trim();if(t===""||(t=t.replace(/[\\/]+$/,""),t===""))return null;let r=t.match(/^([A-Za-z]:)(.*)$/);if(r!==null){let o=r[2];if(o==="")return null;let i=Math.max(o.lastIndexOf("\\"),o.lastIndexOf("/"));return i<=0?r[1]+"\\":r[1]+o.slice(0,i)}if(t.startsWith("\\\\")||t.startsWith("//")){let o=t.slice(2);if(o.split(/[\\/]/).filter(a=>a!=="").length<=2)return null;let n=Math.max(o.lastIndexOf("\\"),o.lastIndexOf("/"));return t.slice(0,2)+o.slice(0,n)}let s=t.lastIndexOf("/");return s<=0?s===0?"/":null:t.slice(0,s)}function Wr(e,t){return e.endsWith("/")?e+t:e+"/"+t}function dc(){let e=document.createElement("div");e.className="tt_sftpProgress";let t=document.createElement("div");t.className="tt_sftpTrack";let r=document.createElement("div");r.className="tt_sftpFill",t.appendChild(r);let s=document.createElement("span");s.className="tt_sftpPct",s.textContent="";let o=document.createElement("button");o.type="button",o.className="tt_sftpCancel",o.title="\u53D6\u6D88\u4F20\u8F93",o.textContent="\u2715",o.style.display="none";let i=null;o.addEventListener("click",_=>{_.stopPropagation();let l=i;l!==null&&(o.disabled=!0,l())}),e.appendChild(t),e.appendChild(s),e.appendChild(o);let n=_=>{s.textContent=_},a="",f=-1,c=_=>{_!==a&&(a=_,s.textContent=_)},p=_=>{let l=Math.round(_);l!==f&&(f=l,r.style.width=l+"%")},g=()=>{i=null,Xr===o&&(Xr=null),o.style.display="none",o.disabled=!1};return{el:e,reset(){delete e.dataset.active,delete e.dataset.state,a="",f=-1,this._last=void 0,this._lastAt=0,this._rate=void 0,r.style.width="0%",s.textContent="",g()},setCancel(_){if(_==null){g();return}i=_,Xr=o,o.disabled=!1,o.style.display=""},set(_,l){e.dataset.active="",delete e.dataset.state;let d=Date.now();if(this._last!==void 0&&d>this._lastAt){let h=(_-this._last)/((d-this._lastAt)/1e3);this._rate=this._rate===void 0?h:this._rate*.7+h*.3}if(this._last=_,this._lastAt=d,Number.isFinite(l)&&l>0){let h=Math.min(100,Math.max(0,_/l*100));p(h);let u=this._rate!==void 0&&this._rate>=0?Fr(this._rate):"";c(Math.round(h)+"%"+(u!==""?" \xB7 "+u:""))}else{r.style.width="";let h=this._rate!==void 0&&this._rate>=0?Fr(this._rate):"";c($e(_)+(h!==""?" \xB7 "+h:""))}},pulse(_){e.dataset.active="",delete e.dataset.state,r.style.width="45%",r.style.transition="none",setTimeout(()=>{r.style.transition="width .15s linear"},30);let l=Date.now();if(this._last!==void 0&&l>this._lastAt){let h=(_-this._last)/((l-this._lastAt)/1e3);this._rate=this._rate===void 0?h:this._rate*.7+h*.3}this._last=_,this._lastAt=l;let d=this._rate!==void 0&&this._rate>=0?Fr(this._rate):"";c((Number.isFinite(_)?$e(_):"\u2026")+(d!==""?" \xB7 "+d:""))},done(_){e.dataset.active="",e.dataset.state="done",r.style.width="100%",f=100,g(),c(_!==void 0&&_!==""?_:"\u5B8C\u6210")},fail(_){e.dataset.active="",e.dataset.state="error",g(),c(_!==void 0&&_!==""?_:"\u5931\u8D25")},text(_){delete e.dataset.state,_===void 0||_===""?(e.dataset.active="",a="",s.textContent=""):(e.dataset.active="",r.style.width="",f=-1,c(_))}}}async function uc(e,t,r,s=0,o=null){let i=s>0?s*1024*1024:0,n=typeof AbortController=="function"?new AbortController:null,a=!1;n!==null&&(t={...t,signal:n.signal},typeof o=="function"&&o(()=>{a=!0,n.abort()}));let f=await fetch(e,t);if(!f.ok){let d="HTTP "+f.status;try{let h=await f.json();h!==null&&typeof h=="object"&&typeof h.error=="string"&&(d=h.error)}catch{}throw new Error(d)}let c=Number(f.headers.get("content-length")),p=Number.isFinite(c)&&c>0;if(i>0&&p&&c>i){try{await f.body?.cancel()}catch{}throw new Error("\u6587\u4EF6\u8D85\u8FC7\u4E0B\u8F7D\u4E0A\u9650\uFF08"+$e(i)+"\uFF09\uFF1A\u8BF7\u7528\u53CC\u680F \u21E6 \u76F4\u4F20\u6216\u7EC8\u7AEF scp/rsync")}let g=f.body;if(g===null||typeof g.getReader!="function"){let d=await f.blob();if(i>0&&d.size>i)throw new Error("\u6587\u4EF6\u8D85\u8FC7\u4E0B\u8F7D\u4E0A\u9650\uFF08"+$e(i)+"\uFF09\uFF1A\u8BF7\u7528\u53CC\u680F \u21E6 \u76F4\u4F20\u6216\u7EC8\u7AEF scp/rsync");return p&&r(c,c),d}let S=g.getReader(),_=[],l=0;try{for(;;){let{done:d,value:h}=await S.read();if(d)break;if(h!==void 0&&h.byteLength>0){if(l+=h.byteLength,i>0&&l>i){try{await S.cancel()}catch{}throw new Error("\u6587\u4EF6\u8D85\u8FC7\u4E0B\u8F7D\u4E0A\u9650\uFF08"+$e(i)+"\uFF09\uFF1A\u8BF7\u7528\u53CC\u680F \u21E6 \u76F4\u4F20\u6216\u7EC8\u7AEF scp/rsync")}_.push(h),r(l,p?c:NaN)}}}catch(d){if(a||d!==null&&typeof d=="object"&&d.name==="AbortError"){try{await S.cancel()}catch{}throw new Sr}throw d}return new Blob(_,{type:"application/octet-stream"})}var Sr=class extends Error{constructor(){super("\u5DF2\u53D6\u6D88"),this.name="TransferCanceledError"}};function An(e){return e instanceof Sr}function fc(e,t){let r=URL.createObjectURL(e),s=document.createElement("a");s.href=r,s.download=t,s.click(),setTimeout(()=>URL.revokeObjectURL(r),3e4)}async function c_(e){if(e==null)return[];let t=typeof e.items<"u"?[...e.items]:[],r=[];for(let c of t){let p=typeof c.webkitGetAsEntry=="function"?c.webkitGetAsEntry():null;p!==null&&r.push(p)}if(r.length===0)return[...e.files??[]].map(c=>({relPath:c.name,file:c}));let s=[],o=Ht.maxUploadFiles,i=Ht.maxUploadMb>0?Ht.maxUploadMb*1024*1024:0,n=()=>o>0&&s.length>=o,a=0,f=(c,p)=>new Promise(g=>{if(n()){g();return}if(c.isFile===!0){c.file(l=>{i>0&&a+(l.size??0)>i?s._limitExceeded=!0:(s.push({relPath:p+c.name,file:l}),a+=l.size??0),g()},()=>g());return}if(c.isDirectory!==!0){g();return}let S=c.createReader(),_=()=>{S.readEntries(async l=>{if(l.length===0){g();return}for(let d of l){if(n())break;await f(d,p+c.name+"/")}if(n()){g();return}_()},()=>g())};_()});for(let c of r)await f(c,"");return s}function us(e,t){let r=cr(t,me);if(ac(r))return;let s=e!==null&&typeof e=="object"?e:{},o={};if(typeof s.name=="string"&&s.name!=="")o.name=s.name;else{for(let O of["host","username","auth","keyPath","passphrase","password"])typeof s[O]=="string"&&s[O]!==""&&(o[O]=s[O]);let x=Number(s.port);Number.isInteger(x)&&x>=1&&x<=65535&&(o.port=x),s.agentForward===!0&&(o.agentForward=!0)}let i=o.name??(o.username!==void 0?o.username+"@"+String(o.host??""):String(o.host??""));if(tc==="dual"){n_(o,i,r);return}let n=document.createElement("div");n.className="tt_sftpCard";let a=document.createElement("div");a.className="tt_sftpTitleRow";let f=document.createElement("div");f.className="tt_sshTitle",f.innerHTML=Jr+"<span></span>",f.lastElementChild.textContent="SFTP \xB7 "+i;let c=document.createElement("button");c.type="button",c.className="tt_close",c.title="\u5173\u95ED",c.innerHTML=ls,c.addEventListener("click",()=>yr(r)),a.appendChild(f),a.appendChild(c),n.appendChild(a);let p=document.createElement("div");p.className="tt_sftpBar";let g=document.createElement("input");g.type="text",g.className="tt_sftpPath",g.placeholder="\u8FDC\u7A0B\u8DEF\u5F84\uFF08\u56DE\u8F66\u8DF3\u8F6C\uFF09",g.spellcheck=!1,g.autocomplete="off";let S=document.createElement("button");S.type="button",S.className="tt_toolBtn",S.innerHTML=Nn+"<span>\u5237\u65B0</span>";let _=document.createElement("button");_.type="button",_.className="tt_toolBtn",_.innerHTML=Il+"<span>\u65B0\u5EFA\u76EE\u5F55</span>";let l=document.createElement("button");l.type="button",l.className="tt_toolBtn",l.innerHTML=vf+"<span>\u4E0A\u4F20</span>",l.title="\u9009\u62E9\u6587\u4EF6\u4E0A\u4F20\uFF1B\u4E5F\u53EF\u4EE5\u628A\u6587\u4EF6 / \u6587\u4EF6\u5939\u76F4\u63A5\u62D6\u8FDB\u5217\u8868";let d=document.createElement("input");d.type="file",d.multiple=!0,d.style.display="none",p.appendChild(g),p.appendChild(S),p.appendChild(_),p.appendChild(l),n.appendChild(p),n.appendChild(d);let h=document.createElement("div");h.className="tt_sftpEditor",h.style.display="none";let u=document.createElement("input");u.type="text",u.className="tt_cardInput",u.spellcheck=!1,u.autocomplete="off";let v=document.createElement("button");v.type="button",v.className="tt_toolBtn",v.textContent="\u786E\u5B9A";let y=document.createElement("button");y.type="button",y.className="tt_toolBtn",y.textContent="\u53D6\u6D88",h.appendChild(u),h.appendChild(v),h.appendChild(y),n.appendChild(h);let b=null,C=()=>{h.style.display="none",b=null};v.addEventListener("click",()=>{b?.()}),y.addEventListener("click",C),u.addEventListener("keydown",x=>{x.key==="Enter"?(x.preventDefault(),b?.()):x.key==="Escape"&&(x.stopPropagation(),C())});let m=document.createElement("div");m.className="tt_sftpList",n.appendChild(m);let E=document.createElement("div");E.className="tt_sftpFoot";let P=document.createElement("div");P.className="tt_sftpStatus";let B=dc();E.appendChild(B.el),E.appendChild(P),n.appendChild(E);let F={path:"",busy:!1},R=(x,O)=>{P.textContent=x,O===void 0?delete P.dataset.state:P.dataset.state=O},j=x=>{F.busy=x;for(let O of[S,_,l])O.disabled=x;g.disabled=x},A=async(x,O)=>{let H=await fetch("/api/dsh-tty/sftp/"+x,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({...o,...O})}),$=await H.json().catch(()=>({}));if(!H.ok||$.ok!==!0)throw new Error(String($.error||"HTTP "+H.status));return $},T=async(x,O)=>{if(!F.busy){j(!0),R(x,"busy");try{await O()}catch(H){R(String(H&&H.message?H.message:H),"error")}finally{j(!1)}}},W=(x,O,H,$)=>{let U=document.createElement("button");U.type="button",U.className="tt_sftpRow";let X=document.createElement("span");X.className="tt_sftpIcon",X.innerHTML=x,$!==void 0&&(X.dataset.kind=$);let ee=document.createElement("span");if(ee.className="tt_sftpName",ee.textContent=O,ee.title=O,U.appendChild(X),U.appendChild(ee),H!==""){let re=document.createElement("span");re.className="tt_sftpMeta",re.textContent=H,U.appendChild(re)}return U},D=(x,O,H,$)=>{let U=document.createElement("button");U.type="button",U.className="tt_sftpAct",U.innerHTML=O,U.title=H,U.addEventListener("click",X=>{X.stopPropagation(),$()}),x.appendChild(U)},w=(x,O,H)=>{let $=document.createElement("button");$.type="button",$.className="tt_sftpAct",$.innerHTML=_r,$.title="\u5220\u9664 "+O.name+(O.isDir?"\uFF08\u542B\u5185\u5BB9\uFF09":"");let U=null;$.addEventListener("click",X=>{if(X.stopPropagation(),!F.busy){if(U!==null){clearTimeout(U),U=null,$.innerHTML=_r,delete $.dataset.danger,T("\u5220\u9664 "+O.name+"\u2026",async()=>{await A("remove",{path:H,recursive:O.isDir===!0}),await k(F.path),R("\u5DF2\u5220\u9664 "+O.name)});return}$.textContent="\u786E\u8BA4?",$.dataset.danger="",U=setTimeout(()=>{U=null,$.innerHTML=_r,delete $.dataset.danger},4e3)}}),x.appendChild($)},L=x=>{if(m.textContent="",F.path!==""&&F.path!=="/"){let $=W(On,"..\uFF08\u4E0A\u7EA7\u76EE\u5F55\uFF09","","up");$.addEventListener("click",()=>{T("\u52A0\u8F7D\u4E2D\u2026",()=>k(hc(F.path)))}),m.appendChild($)}let O=Array.isArray(x)?x:[];if(O.length===0){let $=document.createElement("div");$.className="tt_addMenuTitle",$.textContent="\uFF08\u7A7A\u76EE\u5F55\uFF09",m.appendChild($);return}let H=500;for(let $ of O.slice(0,H)){if($===null||typeof $!="object"||typeof $.name!="string"||$.name==="")continue;let U=Wr(F.path,$.name),X=[];$.isDir===!0?X.push("\u76EE\u5F55"):X.push($e(Number($.size))||"\u2014");let ee=cc(Number($.mtime));ee!==""&&X.push(ee);let re=W($.isDir?Jr:$.isSymlink?Pl:Bl,$.name,X.join(" \xB7 "),$.isDir===!0?"dir":$.isSymlink===!0?"link":"file");$.isDir===!0?re.addEventListener("click",Q=>{Q.target instanceof Element&&Q.target.closest(".tt_sftpAct")!==null||T("\u52A0\u8F7D\u4E2D\u2026",()=>k(U))}):(re.addEventListener("click",Q=>{Q.target instanceof Element&&Q.target.closest(".tt_sftpAct")!==null||M($,U)}),D(re,Ol,"\u4E0B\u8F7D "+$.name,()=>{M($,U)})),D(re,In,"\u91CD\u547D\u540D "+$.name,()=>{u.placeholder="\u65B0\u540D\u79F0",u.value=$.name,h.style.display="",u.focus(),u.select(),b=async()=>{let Q=u.value.trim();Q===""||Q===$.name||(C(),await T("\u91CD\u547D\u540D "+$.name+"\u2026",async()=>{await A("rename",{from:U,to:Wr(F.path,Q)}),await k(F.path)}))}}),w(re,$,U),m.appendChild(re)}if(O.length>H){let $=document.createElement("div");$.className="tt_addMenuTitle",$.textContent=`\u2026\u5176\u4F59 ${String(O.length-H)} \u9879\u672A\u6E32\u67D3\uFF08\u5171 ${String(O.length)} \u9879\uFF09\u2014\u2014\u7528\u4E0A\u65B9\u8DEF\u5F84\u6846\u8DF3\u8F6C\u5230\u5B50\u76EE\u5F55\u5B9A\u4F4D`,m.appendChild($)}},k=async x=>{try{let O=await A("list",{path:x??F.path});F.path=typeof O.path=="string"&&O.path!==""?O.path:"/",g.value=F.path;let H=Array.isArray(O.entries)?O.entries.length:0;L(O.entries),R(F.path+" \u2014 "+String(H)+" \u9879")}catch(O){R(String(O&&O.message?O.message:O),"error")}},M=(x,O)=>T("\u4E0B\u8F7D "+x.name+"\u2026",async()=>{B.reset();let H;try{H=await uc("/api/dsh-tty/sftp/download",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({...o,path:O})},($,U)=>{B.set($,U)},Ht.maxDownloadMb,$=>B.setCancel($))}catch($){if(An($)){B.reset(),R("\u5DF2\u53D6\u6D88\u4E0B\u8F7D "+x.name);return}throw B.fail("\u4E0B\u8F7D\u5931\u8D25"),$}B.done("\u5B8C\u6210"),fc(H,x.name),setTimeout(()=>B.reset(),1500),R("\u5DF2\u4E0B\u8F7D "+x.name+"\uFF08"+($e(H.size)||String(H.size)+" B")+"\uFF09")}),z=(x,O,H,$,U)=>new Promise((X,ee)=>{let re=a_(JSON.stringify({...o,path:Wr(F.path,O)})),Q=new XMLHttpRequest;U.abort=()=>{U.stopped=!0,Q.abort()},Q.open("POST","/api/dsh-tty/sftp/upload"),Q.setRequestHeader("x-dsh-sftp-meta",re);let K=$>1?String(H)+"/"+String($)+" ":"";R("\u4E0A\u4F20 "+K+O,"busy"),Q.upload.addEventListener("progress",ie=>{ie.lengthComputable?B.set(ie.loaded,ie.total):B.pulse(0)});let J=!1,oe=ie=>{J||(J=!0,ie===null?X():ee(ie))};Q.addEventListener("load",()=>{if(Q.status===200){$===1&&B.done("\u4E0A\u4F20\u5B8C\u6210"),oe(null);return}if(U.stopped)return;B.fail("\u4E0A\u4F20\u5931\u8D25");let ie="HTTP "+Q.status;try{let he=JSON.parse(Q.responseText);he!==null&&typeof he=="object"&&typeof he.error=="string"&&(ie=he.error)}catch{}oe(new Error(ie))}),Q.addEventListener("error",()=>{if(U.stopped){oe(new Sr);return}B.fail("\u4E0A\u4F20\u5931\u8D25"),oe(new Error("\u7F51\u7EDC\u9519\u8BEF"))}),Q.addEventListener("abort",()=>{oe(new Sr)}),Q.send(x)}),q=async x=>T("\u4E0A\u4F20\u4E2D\u2026",async()=>{let O=Ht;if(O.maxUploadFiles>0&&x.length>O.maxUploadFiles){R("\u6587\u4EF6\u6570\u8D85\u8FC7\u4E0A\u9650\uFF08"+String(O.maxUploadFiles)+"\uFF09\uFF1A\u672C\u6B21 "+String(x.length)+" \u4E2A\uFF0C\u8BF7\u5206\u6279\u4E0A\u4F20","error"),B.fail("\u8D85\u9650");return}let H=O.maxUploadMb>0?O.maxUploadMb*1024*1024:0,$=x.find(Q=>H>0&&(Q.file?.size??0)>H);if($!==void 0){R("\u6587\u4EF6\u8D85\u8FC7\u4E0A\u4F20\u4E0A\u9650\uFF08"+$e(H)+"\uFF09\uFF1A"+String($.relPath??"")+"\uFF0C\u8BF7\u7528\u53CC\u680F \u21E8 \u76F4\u4F20\u6216\u7EC8\u7AEF scp/rsync","error"),B.fail("\u8D85\u9650");return}if(x._limitExceeded===!0){R("\u6587\u4EF6\u603B\u5927\u5C0F\u8D85\u8FC7\u4E0A\u4F20\u4E0A\u9650\uFF1A\u8BF7\u5206\u6279\u4E0A\u4F20\uFF08\u6216\u7528\u53CC\u680F \u21E8 \u76F4\u4F20\uFF09","error"),B.fail("\u8D85\u9650");return}let U=new Set;for(let Q of x){let K=Q.relPath.lastIndexOf("/");if(K<=0)continue;let J=Q.relPath.slice(0,K);U.has(J)||(U.add(J),await A("mkdir",{path:Wr(F.path,J),parents:!0}).catch(()=>{}))}B.reset();let X={stopped:!1,abort:null};B.setCancel(()=>X.abort?.());let ee=0,re=0;try{for(let Q of x){if(X.stopped)break;ee+=1,X.abort=null;try{await z(Q.file,Q.relPath,ee,x.length,X),re+=1}catch(K){if(An(K)||X.stopped)break;throw K}}}finally{B.setCancel(null)}if(X.stopped){B.reset(),R("\u5DF2\u53D6\u6D88\u4E0A\u4F20\uFF08\u5DF2\u4F20 "+String(re)+"/"+String(x.length)+" \u4E2A\uFF09"),await k(F.path);return}B.done("\u5168\u90E8\u5B8C\u6210"),setTimeout(()=>B.reset(),1500),R("\u4E0A\u4F20\u5B8C\u6210 "+String(x.length)+" \u4E2A\u6587\u4EF6"),await k(F.path)});S.addEventListener("click",()=>{T("\u52A0\u8F7D\u4E2D\u2026",()=>k(F.path))}),_.addEventListener("click",()=>{F.busy||(u.placeholder="\u65B0\u76EE\u5F55\u540D\uFF08\u76F8\u5BF9\u5F53\u524D\u76EE\u5F55\uFF09",u.value="",h.style.display="",u.focus(),b=async()=>{let x=u.value.trim();x!==""&&(C(),await T("\u521B\u5EFA\u76EE\u5F55 "+x+"\u2026",async()=>{await A("mkdir",{path:Wr(F.path,x)}),await k(F.path)}))})}),l.addEventListener("click",()=>{F.busy===!1&&d.click()}),d.addEventListener("change",()=>{let x=[...d.files??[]].map(O=>({relPath:O.name,file:O}));d.value="",x.length>0&&q(x)});let Y=0,Z=x=>{x?m.dataset.drag="":delete m.dataset.drag};n.addEventListener("dragenter",x=>{x.preventDefault(),Y+=1,Z(!0)}),n.addEventListener("dragover",x=>{x.preventDefault()}),n.addEventListener("dragleave",()=>{Y=Math.max(0,Y-1),Y===0&&Z(!1)}),n.addEventListener("drop",x=>{x.preventDefault(),Y=0,Z(!1),!F.busy&&c_(x.dataTransfer).then(O=>{(O.length>0||O._limitExceeded===!0)&&q(O)})}),g.addEventListener("keydown",x=>{if(x.key!=="Enter"||(x.preventDefault(),F.busy))return;let O=g.value.trim();O!==""&&T("\u52A0\u8F7D\u4E2D\u2026",()=>k(O))});let N=Wn();lc(n,"SFTP \xB7 "+i,N===null?340:Math.round(N.height*.46),r),T("\u8FDE\u63A5\u4E2D\u2026",()=>k(""))}function yr(e){let t=e===void 0?oc():e,r=Mt,s=pt!==null&&pt.ownerKey===t?pt:null;r===null&&s===null||(o_(),Mt=null,s!==null&&(pt=null),r!==null&&r.remove(),s!==null&&s.dispose())}function _c(){if(Ne===null)return;let e=Ne.style.display==="none"||Ne.style.display==="";Ne.style.display=e?"":"none";let t=se!==null?se.querySelector("[data-act=search]"):null;t!==null&&(e?t.dataset.on="":delete t.dataset.on),e&&Ne.focus()}var h_={matchBackground:"#3d2b00",matchBorder:"#8a5a00",activeMatchBackground:"#b06a00",activeMatchBorder:"#ffb84d",matchOverviewRuler:"#8a5a00",activeMatchColorOverviewRuler:"#ffb84d"};function d_(e){let t=Ze();if(t===void 0||t.search===void 0)return;let r=Ne.value;if(r==="")return;let s={decorations:h_};e?t.search.findPrevious(r,s):t.search.findNext(r,s)}function xl(){Qr||se===null&&!Hn()||qt!==null||(qt=setTimeout(()=>{qt=null,ss()},Kr),Kr=Math.min(Kr*2,5e3))}function ci(e){return e!==null&&typeof e=="object"&&e.persist===!0&&typeof e.persistName=="string"&&e.persistName!==""}function Dn(e){return ci(e)||e!==null&&typeof e=="object"&&typeof e.command=="string"&&e.command!==""}function u_(){return Nt==="tmux"?{t:"spawn",cwd:xn(),persist:!0,persistName:Un()}:{t:"spawn",cwd:xn()}}async function pc(){if(!wn){wn=!0;try{await f_()}finally{wn=!1}}}var wn=!1;async function f_(){if(await jn(),se===null){await p_();return}let e=Df(),t=Af();if(![...ne.values()].some(n=>n.embedded!==!0)){if(e.length>0||t.length>0){be({t:"sessions"});let n=await Qi("sessions",4e3),a=new Map;if(n!==null&&Array.isArray(n.list))for(let c of n.list)c!==null&&typeof c=="object"&&c.attachable===!0&&a.set(c.sid,c);let f=new Set;for(let c of e){if(a.has(c.sid))Wf(c);else if(Dn(c.spawnSpec))Sl(c);else continue;ci(c.spawnSpec)&&f.add(c.spawnSpec.persistName)}for(let c of t){let p=c.spawnSpec.persistName;f.has(p)||(Sl(c),f.add(p))}Ft()}if(![...ne.values()].some(n=>n.embedded!==!0)){if(await is())return;ei()}return}let r=[...ne.values()].filter(n=>!n.exited&&(n.embedded!==!0||n.spawned===!0)),s=r.filter(n=>Dn(n.spawnSpec)),o=null;if(s.length>0){be({t:"sessions"});let n=await Qi("sessions",4e3),a=new Set((n!==null&&Array.isArray(n.list)?n.list:[]).map(f=>f?.sid).filter(f=>typeof f=="string"));o=s.filter(f=>!a.has(f.sid));for(let f of o)es(f.sid)}let i=o!==null?new Set(o.map(n=>n.sid)):new Set;for(let n of r)i.has(n.sid)||be({t:"attach",sid:n.sid})}function __(){_e!==null&&(_e.readyState===WebSocket.OPEN||_e.readyState===WebSocket.CONNECTING)||ss()}async function p_(){let e=[...ne.values()].filter(s=>s.embedded===!0&&!s.exited);if(e.length===0)return;be({t:"sessions"});let t=await Qi("sessions",4e3),r=new Set((t!==null&&Array.isArray(t.list)?t.list:[]).map(s=>s?.sid).filter(s=>typeof s=="string"));for(let s of e)s.spawned===!0&&(r.has(s.sid)?be({t:"attach",sid:s.sid}):Dn(s.spawnSpec)?Xl(s):(s.exited=!0,s.live=!1,hr(s,"\u4F1A\u8BDD\u5DF2\u7ED3\u675F","\u70B9\u51FB\u91CD\u65B0\u6267\u884C","exited")))}function ss(){if(_e!==null){try{_e.close()}catch{}_e=null}Qr=!1,clearTimeout(qt),qt=null,Wi=!0,$i("\u8FDE\u63A5\u4E2D\u2026","");try{_e=new WebSocket(sf())}catch(e){Wi=!1,$i("\u8FDE\u63A5\u5931\u8D25\uFF1A"+e.message,"error"),xl();return}_e.onopen=()=>{Wi=!1,Kr=1e3,it=null,$i("\u5DF2\u8FDE\u63A5","connected");for(let e of[...Sn])Sn.delete(e),ne.has(e.tab.sid)&&be(e.frame);pc()},_e.onmessage=e=>{let t;try{t=JSON.parse(e.data)}catch{return}let r=t.sid;if(t.t==="ready"){let s=typeof t.target=="string"?t.target:"";vn(r,t.kind==="ssh"?"SSH "+(s!==""?s+" ":"")+"\u5DF2\u8FDE\u63A5":"\u5DF2\u8FDE\u63A5 pid="+t.pid,"connected");let o=ne.get(r);if(o!==void 0){if(o.exited=!1,o.spawned=!0,o.live=!0,o.errored=!1,o.target=s,o.persistTmux=t.persist===!0,t.kind==="ssh"&&s!==""&&!o.label&&(o.label=s,Ue()),Kt(),mn(r),hr(o,""),Cr(o),t.persist===!0){let i=document.fonts!==void 0&&document.fonts.ready!==void 0?document.fonts.ready:Promise.resolve();Promise.race([i,new Promise(n=>setTimeout(n,500))]).then(()=>ql(150))}ri(),Lf(r),Ft()}}else if(t.t==="sessions")Ff(t.list);else if(t.t==="data"){let s=ne.get(r);s!==void 0&&s.term!==null&&(s.term.write(String(t.d??"")),w_())}else if(t.t==="exit"){let s=ne.get(r);if(s!==void 0){s.exited=!0,s.live=!1,s.stats=null,r===me&&Xt();let o=t.code!==null&&t.code!==void 0?"code="+t.code:"",i=t.signal!==null&&t.signal!==void 0?"signal="+t.signal:"";vn(r,"\u5DF2\u9000\u51FA "+[o,i].filter(Boolean).join(" "),""),Kt(),mn(r),hr(s,"\u4F1A\u8BDD\u5DF2\u9000\u51FA","\u70B9\u51FB\u91CD\u65B0\u6253\u5F00","exited"),ri(),Ft()}}else if(t.t==="stats")try{let s=ne.get(r);if(s!==void 0){let o=t.stats;s.stats=_l(o)?o:null,s.statsAt=Date.now(),r===me&&Xt()}}catch(s){console.warn("[dsh-tty] stats \u5E27\u5904\u7406\u5931\u8D25\uFF08\u5DF2\u5FFD\u7565\uFF09: "+(s instanceof Error?s.message:String(s)))}else if(t.t==="error")if(vn(r,"\u9519\u8BEF\uFF1A"+String(t.m??""),"error"),typeof r=="string"){let s=ne.get(r);s!==void 0&&(s.live||(s.errored=!0),Kt(),mn(r),hr(s,"\u8FDE\u63A5\u51FA\u9519",String(t.m??"")+" \xB7 \u70B9\u51FB\u91CD\u8BD5","error"))}else g_("\u70B9\u51FB\u91CD\u8BD5")},_e.onclose=()=>{if(Wi=!1,!Qr){$i("\u8FDE\u63A5\u65AD\u5F00 \u2014 \u81EA\u52A8\u91CD\u8FDE\u4E2D","error");for(let e of ne.values())e.exited||hr(e,"\u8FDE\u63A5\u65AD\u5F00","\u81EA\u52A8\u91CD\u8FDE\u4E2D\u2026","info");xl()}},_e.onerror=()=>{}}function g_(e){pr!==null&&(pr.textContent=e)}function Bn(){(se===null||Ae)&&Pn()}function gc(){return typeof navigator<"u"&&navigator.clipboard!==void 0&&typeof navigator.clipboard.writeText=="function"}async function v_(e){if(gc())try{return await navigator.clipboard.writeText(e),!0}catch{}let t=document.createElement("textarea");t.value=e,t.style.position="fixed",t.style.opacity="0",document.body.appendChild(t),t.select();let r=!1;try{r=document.execCommand("copy")}catch{r=!1}return t.remove(),r||ai("\u590D\u5236\u5931\u8D25\uFF1A\u5F53\u524D\u73AF\u5883\u4E0D\u5141\u8BB8\u8BBF\u95EE\u526A\u8D34\u677F\uFF08http \u8BBF\u95EE\u65F6\u8BF7\u6539\u7528 localhost \u6216\u7EC8\u7AEF\u5185\u5FEB\u6377\u952E\uFF09","error"),r}async function m_(e){if(gc()&&typeof navigator.clipboard.readText=="function")try{let s=await navigator.clipboard.readText();return s!==""&&be({t:"input",sid:e.sid,d:s}),!0}catch{}let t=document.createElement("textarea");t.style.position="fixed",t.style.opacity="0",document.body.appendChild(t),t.focus();let r=!1;try{r=document.execCommand("paste");let s=r?t.value:"";s!==""&&be({t:"input",sid:e.sid,d:s})}catch{r=!1}return t.remove(),r||ai("\u6D4F\u89C8\u5668\u4E0D\u5141\u8BB8\u7F51\u9875\u8BFB\u53D6\u526A\u8D34\u677F\uFF08http \u8BBF\u95EE\u65F6\u5E38\u89C1\uFF09\uFF1A\u8BF7\u5728\u7EC8\u7AEF\u91CC\u6309 Ctrl+V / Cmd+V \u7C98\u8D34","error"),r}function Pn(){if(se!==null){Ae&&vc();return}si(),se=document.createElement("div"),se.className="tt_modalBackdrop",se.innerHTML='<div class="tt_modal"><div class="tt_header"><span class="tt_titleIcon">'+as+'</span><div class="tt_tabs"></div><div class="tt_status"><span class="tt_statusDot"></span><span class="tt_statusText">\u521D\u59CB\u5316\u2026</span></div><input class="tt_searchInput" style="display:none" placeholder="\u641C\u7D22 (Enter \u4E0B\u4E00\u4E2A, Shift+Enter \u4E0A\u4E00\u4E2A)" /><span class="tt_toolGroup"><button class="tt_toolBtn tt_iconBtn" data-act="search" title="\u641C\u7D22 (Ctrl+F)">'+lf+'</button><button class="tt_toolBtn tt_iconBtn" data-act="clear" title="\u6E05\u5C4F">'+cf+'</button><button class="tt_toolBtn tt_iconBtn" data-act="copy" title="\u590D\u5236\u9009\u4E2D\u5185\u5BB9">'+hf+'</button><button class="tt_toolBtn tt_iconBtn" data-act="paste" title="\u7C98\u8D34">'+df+'</button></span><span class="tt_winGroup"><button class="tt_min" title="\u6700\u5C0F\u5316\uFF08\u4F1A\u8BDD\u4FDD\u6301\u8FD0\u884C\uFF0C\u72B6\u6001\u5E76\u5165\u4FA7\u8FB9\u680F\u5165\u53E3\uFF09">'+pf+'</button><button class="tt_close" title="\u5173\u95ED\u9762\u677F\uFF08\u7ED3\u675F\u4F1A\u8BDD\uFF0C\u6807\u7B7E\u4FDD\u7559\uFF0C\u91CD\u5F00\u5373\u6062\u590D\u5217\u8868\uFF09">'+ls+'</button></span></div><div class="tt_connbar" data-hidden><div class="tt_connArea"><span class="tt_connDot"></span><span class="tt_connTarget">\u2014</span><span class="tt_connBadge"></span></div><div class="tt_connActions"></div></div><div class="tt_work"><div class="tt_body"><div class="tt_statsBar" hidden></div><div class="tt_overlay"></div></div></div></div>',document.body.appendChild(se),Vi=se.querySelector(".tt_status"),jt=se.querySelector(".tt_statusText"),Gt=se.querySelector(".tt_statusDot"),ut=se.querySelector(".tt_tabs"),zr=se.querySelector(".tt_connbar"),Ur=se.querySelector(".tt_connDot"),Gi=se.querySelector(".tt_connTarget"),Ye=se.querySelector(".tt_connBadge"),jr=se.querySelector(".tt_connActions"),Xe=se.querySelector(".tt_work"),ze=se.querySelector(".tt_body"),rt=se.querySelector(".tt_statsBar"),hs(),it=null,zl(),pr=se.querySelector(".tt_body > .tt_overlay"),Ne=se.querySelector(".tt_searchInput"),pr.addEventListener("click",()=>{pr.textContent="",ss()});let e=se.querySelector("[data-act=search]");e.addEventListener("click",()=>{_c(),Ne.style.display!=="none"&&Ne.focus()}),e.dataset.on="",Ne.addEventListener("keydown",t=>{t.key==="Enter"?(t.preventDefault(),d_(t.shiftKey)):t.key==="Escape"&&(t.stopPropagation(),Ne.style.display="none")}),se.querySelector("[data-act=clear]").addEventListener("click",()=>{let t=Ze();t!==void 0&&t.term!==null&&t.term.clear()}),se.querySelector("[data-act=copy]").addEventListener("click",()=>{let t=Ze();if(t===void 0||t.term===null)return;let r=t.term.getSelection();r!==""&&v_(r)}),se.querySelector("[data-act=paste]").addEventListener("click",()=>{let t=Ze();t!==void 0&&m_(t)}),se.querySelector(".tt_min").addEventListener("click",()=>{ns()}),se.querySelector(".tt_close").addEventListener("click",()=>{ii()}),se.addEventListener("mousedown",t=>{t.target===se&&ns()}),document.addEventListener("keydown",mc),qr=new ResizeObserver(()=>{Ae||(Ui(),Bf(Ze()))}),qr.observe(ze),Ue(),Kt(),_e!==null&&_e.readyState===WebSocket.OPEN?pc():ss()}function b_(){Pe=document.createElement("div"),Pe.className="tt_dock",Pe.title="\u70B9\u51FB\u6062\u590D\u7EC8\u7AEF\u7A97\u53E3",Pe.innerHTML='<span class="tt_dockTitle">'+as+'<span>\u7EC8\u7AEF</span><span class="tt_dockCount"></span></span><span class="tt_dockStatus"></span><span class="tt_dockDot"></span><button class="tt_dockClose" title="\u5173\u95ED\u9762\u677F\uFF08\u7ED3\u675F\u4F1A\u8BDD\uFF0C\u6807\u7B7E\u4FDD\u7559\uFF0C\u91CD\u5F00\u5373\u6062\u590D\u5217\u8868\uFF09">\u2715</button>',Yi=Pe.querySelector(".tt_dockCount"),wr=Pe.querySelector(".tt_dockStatus"),Yt=Pe.querySelector(".tt_dockDot");let e=[...ne.values()].filter(t=>!t.exited).length;Yi.textContent=ne.size>0?"\xB7 "+e+"/"+ne.size:"",jt!==null&&(wr.textContent=jt.textContent),Gt!==null&&(Yt.dataset.state=Gt.dataset.state??""),Pe.addEventListener("click",t=>{if(t.target.closest(".tt_dockClose")!==null){t.stopPropagation(),ii();return}vc()}),document.body.appendChild(Pe)}function ns(){se===null||Ae||(ft(),Ot(),Ae=!0,Mt!==null&&(Mt.style.display="none"),Ne!==null&&(Ne.style.display="none"),se.dataset.minimized="",Ul(),li(),Xt(),document.querySelector("[data-dsh-tty-entry]")!==null?ri():(b_(),Pe.classList.add("tt_dockCompact")))}function ri(){let e=document.querySelector("[data-dsh-tty-entry]");if(e===null)return;let t=e.querySelector(".tt_sidebarEntryBadge");if(!Ae){t!==null&&t.remove(),delete e.dataset.minimized,e.removeAttribute("title");return}t===null&&(t=document.createElement("span"),t.className="tt_sidebarEntryBadge",t.innerHTML='<span class="tt_sidebarBadgeDot"></span><span class="tt_sidebarBadgeCount"></span>',e.appendChild(t)),e.dataset.minimized="",e.title="\u7EC8\u7AEF\u5DF2\u6700\u5C0F\u5316 \u2014 \u70B9\u51FB\u6062\u590D";let r=[...ne.values()].filter(o=>!o.exited).length;t.querySelector(".tt_sidebarBadgeCount").textContent=r+"/"+ne.size;let s=t.querySelector(".tt_sidebarBadgeDot");s!==null&&Gt!==null&&(s.dataset.state=Gt.dataset.state??"")}function w_(){if(!Ae)return;let e=document.querySelector("[data-dsh-tty-entry] .tt_sidebarBadgeDot")??Yt;e!==null&&(e.dataset.active="",clearTimeout(Xi),Xi=setTimeout(()=>{delete e.dataset.active},900))}function vc(){if(se===null||!Ae)return;Ae=!1,delete se.dataset.minimized,Mt!==null&&(Mt.style.display=""),clearTimeout(Xi),Pe!==null&&(Pe.remove(),Pe=null),Yi=null,wr=null,Yt=null,ri(),zl(),li(),Xt();let e=Ze();if(e!==void 0&&e.fit!==void 0){try{e.fit.fit()}catch{}e.spawned&&!e.exited&&Cr(e)}e!==void 0&&e.term!==null&&e.term.focus()}function ii(){if(se===null)return;Yr(!0);let e=Hn();if(Qr=!e,Ae=!1,ft(),ji(),ts(),Ot(),yr(),clearTimeout(Xi),clearTimeout(qt),qt=null,Kr=1e3,Pe!==null&&(Pe.remove(),Pe=null),Yi=null,wr=null,Yt=null,ri(),_e!==null){for(let t of ne.values())!t.exited&&t.embedded!==!0&&be({t:"kill",sid:t.sid});if(!e){try{_e.close()}catch{}_e=null}}qr!==null&&(qr.disconnect(),qr=null);for(let[t,r]of[...ne])if(r.embedded!==!0){if(r.term!==null)try{r.term.dispose()}catch{}ne.delete(t)}me=null,Zr=null,document.removeEventListener("keydown",mc),se.remove(),se=null,Xe=null,Vi=null,jt=null,Gt=null,ut=null,zr=null,Ur=null,Gi=null,Ye=null,jr=null,ts(),Ul(),rt=null,hs(),it=null,ze=null,pr=null,Ne=null,oi=0;try{sessionStorage.removeItem(Ji)}catch{}}function mc(e){if(e.key==="Escape"&&se!==null){if(e.preventDefault(),Mt!==null){yr();return}if(gr!==null){Ot();return}if(Je!==null){ft();return}ns()}}function S_(){let e=document.querySelector('[data-pane="sidebar"], [class*="sidebarCol"]');if(e!==null)return e.querySelector('[class*="logoRow"]')?.parentElement??e.firstElementChild}function y_(e){let t=e.querySelector('button[class*="newSession"]');if(t!==null)return t;for(let r of e.children)if(r.tagName==="BUTTON")return r}function C_(){let e=document.createElement("div");return e.dataset.dshTtyEntry="",e.className="tt_sidebarEntry",e.setAttribute("role","button"),e.setAttribute("aria-label","\u7EC8\u7AEF"),e.tabIndex=0,e.innerHTML='<span class="tt_sidebarEntryIcon">'+as+'</span><span class="tt_sidebarEntryLabel">\u7EC8\u7AEF</span>',e.addEventListener("click",t=>{t.preventDefault(),Pn()}),e.addEventListener("keydown",t=>{(t.key==="Enter"||t.key===" "||t.key==="Spacebar")&&(t.preventDefault(),Pn())}),e}function kl(e,t){let r=y_(e);if(r===void 0)return!1;if(t.parentElement!==e){let s=r.closest('[class*="logoRow"]'),o=s!==null&&s.parentElement===e?s:r,i=Array.from(e.children).filter(n=>n instanceof HTMLElement&&n.matches("[data-dsh-global-search-entry], [data-dsh-rss-entry], [data-dsh-taskboard-entry], [data-dsh-ssh-entry], [data-dsh-tty-entry]"));if(i.length>0){let n=i[i.length-1];e.insertBefore(t,n.nextSibling)}else e.insertBefore(t,o.nextElementSibling)}return!0}function x_(){if(si(),typeof document<"u"&&document.querySelector("[data-dsh-tty-entry]")!==null)return()=>{};let e=C_(),t,r=!1,s=()=>{if(t!==void 0&&!t.isConnected&&(i.disconnect(),t=void 0,r=!1),r){if(document.body.contains(e))return;i.disconnect(),t=void 0,r=!1}t??(t=S_()),t!==void 0&&(r=kl(t,e),r&&i.observe(t,{childList:!0,subtree:!0}))},o=new MutationObserver(()=>{s()});o.observe(document.body,{childList:!0,subtree:!0});let i=new MutationObserver(()=>{if(t===void 0||!t.isConnected){r=!1,s();return}t.contains(e)||(r=kl(t,e))});return s(),()=>{o.disconnect(),i.disconnect(),e.remove()}}window.__ModuleLoader__.load({id:"@hyzyn/dsh-tty",factory:e=>{let t={},r=e("react"),{jsx:s,jsxs:o}=e("react/jsx-runtime"),i="M11.8486 5.5L11.4238 5.92383L8.69727 8.65137C8.44157 8.90706 8.21562 9.13382 8.01172 9.29785C7.79912 9.46883 7.55595 9.61756 7.25 9.66602C7.08435 9.69222 6.91565 9.69222 6.75 9.66602C6.44405 9.61756 6.20088 9.46883 5.98828 9.29785C5.78438 9.13382 5.55843 9.13382 5.30273 8.65137L2.57617 5.92383L2.15137 5.5L3 4.65137L3.42383 5.07617L6.15137 7.80273C6.42595 8.07732 6.59876 8.24849 6.74023 8.3623C6.87291 8.46904 6.92272 8.47813 6.9375 8.48047C6.97895 8.48703 7.02105 8.48703 7.0625 8.48047C7.07728 8.47813 7.12709 8.46904 7.25977 8.3623C7.40124 8.24849 7.57405 8.07732 7.84863 7.80273L10.5762 5.07617L11 4.65137L11.8486 5.5Z";function n(f){let c=f&&f.view,p=c==="page",[g,S]=r.useState(p),[_,l]=r.useState(null),[d,h]=r.useState(!1),[u,v]=r.useState(!1),[y,b]=r.useState({kind:"",text:""}),[C,m]=r.useState([]),[E,P]=r.useState(!1),B=I=>s("div",{className:"tt_cardSection",children:I}),F=async()=>{try{let V=await(await fetch("/api/dsh-tty/config",{cache:"no-store"})).json();V.ok&&typeof V.config=="object"&&V.config!==null?(l(V.config),ti(V.config)):b({kind:"error",text:String(V.error||"\u8BFB\u53D6\u914D\u7F6E\u5931\u8D25")})}catch(I){b({kind:"error",text:String(I&&I.message?I.message:I)})}},R=async()=>{try{let V=await(await fetch("/api/dsh-tty/shells",{cache:"no-store"})).json();V.ok&&Array.isArray(V.shells)&&m(V.shells)}catch{}};r.useEffect(()=>{g&&!d&&(h(!0),F(),R())},[g]);let j=(I,V)=>l(G=>({...G||{},[I]:V})),A=(I,V)=>l(G=>({...G||{},sftpLimits:{...G?.sftpLimits??{},[I]:V}})),[T,W]=r.useState(null),[D,w]=r.useState(null),[L,k]=r.useState(""),[M,z]=r.useState(null),[q,Y]=r.useState(""),[Z,N]=r.useState(""),[x,O]=r.useState(""),H=r.useRef(null),[$,U]=r.useState(!1),[X,ee]=r.useState({text:"",kind:""}),[re,Q]=r.useState(!1),[K,J]=r.useState({running:!1,ok:!1,text:""}),[oe,ie]=r.useState({}),[he,Ce]=r.useState([]),[de,ve]=r.useState({direction:"local",localPort:"",remoteHost:"",remotePort:"",localTargetPort:"",bookName:""}),[pe,Oe]=r.useState(null);r.useEffect(()=>{if(!g)return;let I=!0,V=async()=>{try{let ae=await(await fetch("/api/dsh-tty/tunnels",{cache:"no-store"})).json();I&&ae.ok&&Array.isArray(ae.tunnels)&&Ce(ae.tunnels)}catch{}};V();let G=setInterval(V,2e3);return()=>{I=!1,clearInterval(G)}},[g]);let je=I=>V=>ve(G=>({...G||{},[I]:V.target.value})),Qe=(I,V)=>ve(G=>({...G||{},[I]:V})),Jt=I=>I?.direction==="remote"?`\u8FDC\u7A0B:${I.remoteHost||"127.0.0.1"}:${String(I.remotePort??0)} \u2192 \u672C\u673A:${String(I.localTargetPort??0)}`:`\u672C\u673A:${String(I?.localPort??0)} \u2192 ${I?.remoteHost??"?"}:${String(I?.remotePort??0)}`,et=(_?.sshHosts??[]).find(I=>I?.name===de?.bookName),gt=async I=>{try{let V=await fetch("/api/dsh-tty/config",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({tunnels:I})}),G=await V.json().catch(()=>({}));return!V.ok||!G.ok?(b({kind:"error",text:String(G.error||"\u4FDD\u5B58\u96A7\u9053\u5931\u8D25")}),!1):!0}catch(V){return b({kind:"error",text:String(V&&V.message?V.message:V)}),!1}},ue=()=>sl(de,(Array.isArray(_?.sshHosts)?_.sshHosts:[]).map(I=>I?.name)),fs=I=>{b({kind:"",text:""}),Oe(String(I?.name??"")),ve({direction:I?.direction==="remote"?"remote":"local",bookName:String(I?.bookName??""),localPort:I?.localPort?String(I.localPort):"",remoteHost:String(I?.remoteHost??""),remotePort:I?.remotePort?String(I.remotePort):"",localTargetPort:I?.localTargetPort?String(I.localTargetPort):""})},bc=()=>{Oe(null),b({kind:"",text:""}),ve(I=>({...I||{},localPort:"",remoteHost:"",remotePort:"",localTargetPort:""}))},wc=()=>{b({kind:"",text:""});let I=ue();if(!I.ok){b({kind:"error",text:I.error});return}let V=I.tunnel,G=Array.isArray(_?.tunnels)?_.tunnels:[];if(nl(G,V.name)!==void 0){b({kind:"error",text:`\u5DF2\u5B58\u5728\u540C\u540D\u96A7\u9053\u300C${V.name}\u300D\u2014\u2014\u540C\u4E00\u300C\u8FDE\u63A5\u7C3F\u6761\u76EE + \u65B9\u5411 + \u7AEF\u53E3\u300D\u53EA\u80FD\u6709\u4E00\u6761\u3002\u6539\u7AEF\u53E3\u4F1A\u5F97\u5230\u65B0\u540D\u5B57\uFF0C\u6216\u5148\u5220\u6389\u65E7\u7684\u90A3\u6761\u3002`});return}let te=[...G,V];l(ae=>({...ae||{},tunnels:te})),ve(ae=>({...ae||{},localPort:"",remoteHost:"",remotePort:"",localTargetPort:""})),gt(te).then(ae=>{ae&&b({kind:"ok",text:`\u96A7\u9053\u300C${V.name}\u300D\u5DF2\u751F\u6548`})})},Sc=()=>{if(pe===null)return;b({kind:"",text:""});let I=ue();if(!I.ok){b({kind:"error",text:I.error});return}let V=Array.isArray(_?.tunnels)?_.tunnels:[],G=ol(V,pe,I.tunnel);if(!G.ok){G.error.includes("\u5DF2\u4E0D\u5B58\u5728")&&Oe(null),b({kind:"error",text:G.error});return}let te=G.tunnels;l(ae=>({...ae||{},tunnels:te})),gt(te).then(ae=>{if(ae!==!0){l(le=>({...le||{},tunnels:V}));return}Oe(null),ve(le=>({...le||{},localPort:"",remoteHost:"",remotePort:"",localTargetPort:""})),b({kind:"ok",text:`\u96A7\u9053\u300C${I.tunnel.name}\u300D\u5DF2\u66F4\u65B0`})})},qn=(I,V)=>{l(G=>({...G||{},tunnels:I})),gt(I).then(G=>{G!==!0&&l(te=>({...te||{},tunnels:V}))})},yc=I=>{let V=Array.isArray(_?.tunnels)?_.tunnels:[];pe!==null&&String(I??"")===pe&&(Oe(null),ve(G=>({...G||{},localPort:"",remoteHost:"",remotePort:"",localTargetPort:""}))),qn(V.filter(G=>G?.name!==I),V)},Cc=(I,V)=>{let G=Array.isArray(_?.tunnels)?_.tunnels:[];qn(G.map(te=>te?.name===I?{...te,enabled:V}:te),G)},xc=I=>{W(I?.name??null),k(""),J({running:!1,ok:!1,text:""}),Y(""),N(""),_s(),U(_t!==null),w({name:I?.name??"",host:I?.host??"",port:String(I?.port??22),username:I?.username??"",auth:I?.auth==="key"||I?.auth==="password"?I.auth:"agent",keyPath:I?.keyPath??"",passphrase:I?.passphrase??"",password:I?.password??"",agentForward:I?.agentForward===!0,persist:I?.persist!==!1}),Ml().then(V=>z(V)),ps(I?.password??"")},Kn=()=>{W(null),w(null),k(""),J({running:!1,ok:!1,text:""}),Y(""),N(""),_s()},kc=async()=>{if(D===null)return;let I=D.name.trim(),V=D.host.trim(),G=D.username.trim();if(I===""||V===""||G===""){k("\u540D\u79F0\u3001\u4E3B\u673A\u3001\u7528\u6237\u540D\u5FC5\u586B");return}let te=Number(D.port);if((!Number.isInteger(te)||te<1||te>65535)&&(te=22),(_?.sshHosts??[]).some(le=>le?.name===I&&I!==T)){k("\u8FDE\u63A5\u7C3F\u91CC\u5DF2\u6709\u540C\u540D\u6761\u76EE: "+I);return}if(D.auth==="key"&&D.keyPath.trim()===""){k("auth=key \u9700\u8981\u79C1\u94A5\u8DEF\u5F84");return}k("");let ae=D.password;if(D.auth==="password"){let le=await Al($,D.password,V,te,G,"PASSWORD");if(le.error!==void 0){k(le.error);return}le.value!==void 0&&(ae=le.value)}l(le=>({...le||{},sshHosts:(Array.isArray(le?.sshHosts)?le.sshHosts:[]).map(we=>we?.name===T?{name:I,host:V,port:te,username:G,auth:D.auth,keyPath:D.keyPath.trim(),passphrase:D.passphrase,password:ae,agentForward:D.agentForward,persist:D.persist===!0}:we)})),ie(le=>{let we={...le};return delete we[I],T!==I&&delete we[T],we}),W(null),w(null),J({running:!1,ok:!1,text:""}),b({kind:"ok",text:"\u5DF2\u4FEE\u6539\u6761\u76EE\u300C"+I+"\u300D\u2014 \u968F\u300C\u4FDD\u5B58\u300D\u5199\u5165\u914D\u7F6E"})},Ec=I=>{T===I&&Kn(),ie(V=>{let G={...V};return delete G[I],G}),l(V=>({...V||{},sshHosts:(Array.isArray(V?.sshHosts)?V.sshHosts:[]).filter(G=>G?.name!==I)}))},Lc=async I=>{let V=I?.name??"";if(V==="")return;let G={host:I?.host??"",port:Number(I?.port)||22,username:I?.username??"",auth:I?.auth==="key"||I?.auth==="password"?I.auth:"agent",keyPath:I?.keyPath??"",passphrase:I?.passphrase??"",password:I?.password??"",agentForward:I?.agentForward===!0};ie(ae=>({...ae,[V]:{running:!0,text:"\u8FDE\u63A5\u6D4B\u8BD5\u4E2D\u2026"}}));let te=await Ln(G,!0);ie(ae=>{let le=ae[V]||{};if(te.result){let we=te.result.auth?.ok===!0;return{...ae,[V]:{running:!1,ok:we,text:Mn(te.result)}}}return{...ae,[V]:{running:!1,ok:!1,text:"\u274C \u8FDE\u63A5\u5931\u8D25\uFF1A"+String(te.error||"\u672A\u77E5\u9519\u8BEF")}}})},Mc=async I=>{let V=(Array.isArray(_?.hostKeys)?_.hostKeys:[]).filter(G=>!(G?.host===I?.host&&Number(G?.port)===Number(I?.port)));l(G=>({...G||{},hostKeys:V}));try{let G=await fetch("/api/dsh-tty/config",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({hostKeys:V})}),te=await G.json().catch(()=>({}));!G.ok||!te.ok?b({kind:"error",text:String(te.error||"\u5220\u9664\u4E3B\u673A\u5BC6\u94A5\u8BB0\u5F55\u5931\u8D25")}):b({kind:"ok",text:"\u5DF2\u5220\u9664\u4E3B\u673A\u5BC6\u94A5\u8BB0\u5F55\uFF08\u4E0B\u6B21\u8FDE\u63A5\u91CD\u65B0\u8BB0\u5F55\u6307\u7EB9\uFF09"})}catch(G){b({kind:"error",text:String(G&&G.message?G.message:G)})}},Rc=async()=>{b({kind:"",text:""});try{let V=await(await fetch("/api/dsh-tty/ssh-config",{cache:"no-store"})).json();if(!V.ok){b({kind:"error",text:String(V.error||"\u8BFB\u53D6 ~/.ssh/config \u5931\u8D25")});return}let G=Array.isArray(V.entries)?V.entries:[],te=[...Array.isArray(_?.sshHosts)?_.sshHosts:[]],ae=new Set(te.map(ce=>ce?.name)),le=0,we=0;for(let ce of G)if(!(ce===null||typeof ce!="object"||typeof ce.name!="string")){if(ae.has(ce.name)){we+=1;continue}ae.add(ce.name),te.push({name:ce.name,host:String(ce.host??ce.name),port:Number(ce.port)||22,username:String(ce.username??""),auth:ce.auth==="key"?"key":"agent",keyPath:String(ce.keyPath??""),passphrase:"",password:"",agentForward:!1}),le+=1}l(ce=>({...ce||{},sshHosts:te})),b(le===0?{kind:"ok",text:we>0?`\u6CA1\u6709\u65B0\u6761\u76EE\uFF08${we} \u6761\u540C\u540D\u8DF3\u8FC7\uFF09`:"~/.ssh/config \u91CC\u6CA1\u6709\u53EF\u5BFC\u5165\u7684\u5177\u4F53\u4E3B\u673A"}:{kind:"ok",text:`\u5DF2\u5BFC\u5165 ${le} \u6761\uFF08\u540C\u540D\u8DF3\u8FC7 ${we} \u6761\uFF09\uFF0C\u968F\u300C\u4FDD\u5B58\u300D\u5199\u5165\u914D\u7F6E`})}catch(I){b({kind:"error",text:String(I&&I.message?I.message:I)})}},Vn=I=>I===null||typeof I!="object"?[]:Array.isArray(I.fingerprints)?I.fingerprints.filter(V=>typeof V=="string"&&V!==""):typeof I.fingerprint=="string"&&I.fingerprint!==""?[I.fingerprint]:[],Tc=async()=>{b({kind:"",text:""});try{let V=await(await fetch("/api/dsh-tty/known-hosts",{cache:"no-store"})).json();if(!V.ok){b({kind:"error",text:String(V.error||"\u8BFB\u53D6 ~/.ssh/known_hosts \u5931\u8D25")});return}let G=Array.isArray(V.entries)?V.entries:[],te=[...Array.isArray(_?.hostKeys)?_.hostKeys:[]],ae=new Map;for(let ce of te)ce===null||typeof ce!="object"||ae.set(String(ce.host??"")+":"+String(ce.port??22),{record:ce,fps:new Set(Vn(ce))});let le=0,we=0;for(let ce of G){if(ce===null||typeof ce!="object"||typeof ce.host!="string")continue;let vt=Array.isArray(ce.fingerprints)?ce.fingerprints.filter(Mr=>typeof Mr=="string"&&Mr!==""):[];if(typeof ce.fingerprint=="string"&&ce.fingerprint!==""&&vt.push(ce.fingerprint),vt.length===0)continue;let Xn=ce.host+":"+String(ce.port??22),$t=ae.get(Xn);if($t!==void 0){let Mr=!1;for(let Jn of vt)$t.fps.has(Jn)||$t.fps.size>=8||($t.fps.add(Jn),Mr=!0);if(!Mr){we+=1;continue}delete $t.record.fingerprint,$t.record.fingerprints=[...$t.fps],le+=1;continue}let gs={host:ce.host,port:Number(ce.port)||22,fingerprints:[...new Set(vt)].slice(0,8)};ae.set(Xn,{record:gs,fps:new Set(gs.fingerprints)}),te.push(gs),le+=1}if(le===0){b({kind:"ok",text:we>0?`\u6CA1\u6709\u65B0\u6307\u7EB9\uFF08${we} \u6761\u5DF2\u5B58\u5728\uFF09`:"known_hosts \u91CC\u6CA1\u6709\u53EF\u5BFC\u5165\u7684\u5177\u4F53\u4E3B\u673A"});return}l(ce=>({...ce||{},hostKeys:te}));try{let ce=await fetch("/api/dsh-tty/config",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({hostKeys:te})}),vt=await ce.json().catch(()=>({}));if(!ce.ok||!vt.ok){b({kind:"error",text:String(vt.error||"\u4FDD\u5B58 hostKeys \u5931\u8D25")});return}b({kind:"ok",text:`\u5DF2\u5BFC\u5165 ${le} \u6761\u4E3B\u673A\u7684\u6307\u7EB9\uFF08\u8DF3\u8FC7 ${we} \u6761\u5DF2\u5B58\u5728\uFF09`+(V.truncated===!0?"\uFF1B\u6CE8\u610F\uFF1Aknown_hosts \u8D85\u8FC7 500 \u6761\u4E3B\u673A\uFF0C\u672C\u6B21\u4EC5\u5BFC\u5165\u524D 500 \u6761":"")})}catch(ce){b({kind:"error",text:String(ce&&ce.message?ce.message:ce)})}}catch(I){b({kind:"error",text:String(I&&I.message?I.message:I)})}},Ac=async()=>{v(!0),b({kind:"",text:""});let I={};for(let V of["enabled","announceToAgent","maxSessions","shell","term","colorTerm","cwd","reconnectGraceSec","shellIntegration","sftpStyle","persistence","endOnPageClose","statsEnabled"]){let G=(_||{})[V];G!==void 0&&G!==""&&(I[V]=G)}I.sshHosts=Array.isArray(_?.sshHosts)?_.sshHosts:[],I.tunnels=Array.isArray(_?.tunnels)?_.tunnels:[],_?.sftpLimits&&typeof _.sftpLimits=="object"&&(I.sftpLimits={maxDownloadMb:Number(_.sftpLimits.maxDownloadMb)||0,maxUploadMb:Number(_.sftpLimits.maxUploadMb)||0,maxUploadFiles:Number(_.sftpLimits.maxUploadFiles)||0});try{let V=await fetch("/api/dsh-tty/config",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(I)}),G=await V.json();!V.ok||!G.ok?b({kind:"error",text:String(G.error||"\u4FDD\u5B58\u5931\u8D25")}):(b({kind:"ok",text:"\u5DF2\u4FDD\u5B58\u5E76\u70ED\u751F\u6548"}),G.config&&(l(G.config),ti(G.config)))}catch(V){b({kind:"error",text:String(V&&V.message?V.message:V)})}v(!1)},_s=()=>{H.current!==null&&(clearTimeout(H.current),H.current=null),O("")},ps=async I=>{let V=fr(I);if(br()===null){U(!1),Q(!1),ee({text:_t===null?"\u5BBF\u4E3B\u672A\u63D0\u4F9B\u51ED\u636E\u670D\u52A1\uFF08remote.credentials\uFF09\uFF0C\u53EA\u80FD\u660E\u6587\u4FDD\u5B58":"\u51ED\u636E\u670D\u52A1\u4E0D\u5B8C\u6574\uFF0C\u53EA\u80FD\u660E\u6587\u4FDD\u5B58",kind:"muted"});return}if(V===""){Q(!1),ee({text:"",kind:""});return}let G=await Rl(V);if(G.unreported===!0){Q(!1),ee({text:"\u5F15\u7528 "+V+"\uFF1A\u5BBF\u4E3B\u672A\u62A5\u544A\u72B6\u6001",kind:"plain"});return}if(G.error!==void 0){Q(!1),ee({text:"\u8BFB\u53D6\u51ED\u636E\u72B6\u6001\u5931\u8D25\uFF1A"+G.error,kind:"error"});return}let te=G.view;ee({text:te.configured?"\u5DF2\u5B58\u5165"+(te.source!==""?"\uFF08\u6765\u6E90 "+te.source+"\uFF09":"")+" \xB7 "+V:"\u5F15\u7528 "+V+"\uFF1A\u5B58\u50A8\u91CC\u8FD8\u6CA1\u6709\u8FD9\u4E2A\u503C",kind:te.configured?"ok":"plain"}),Q(te.configured===!0&&te.writable===!0)},Dc=async()=>{let I=fr(D?.password??"");if(I==="")return;let V=await Tl(I);if(V.error!==void 0){ee({text:V.error,kind:"error"});return}w(G=>({...G||{},password:""})),ee({text:"",kind:""}),Q(!1)},Bc=(I,V)=>{let G=String(D?.[I]??"");if(G===""||G.startsWith("env:")||x===V){_s(),w(te=>({...te||{},[I]:"env:"+V})),Y(""),I==="password"&&ps("env:"+V);return}O(V),H.current!==null&&clearTimeout(H.current),H.current=setTimeout(()=>{H.current=null,O("")},4e3)},Gn=(I,V)=>{if(M===null)return null;if(M.length===0)return s("span",{className:"tt_cardHint",children:V});let G=q===I,te=Z.trim().toUpperCase(),ae=te===""?M:M.filter(le=>le.toUpperCase().includes(te));return o("div",{className:"tt_credPicker",children:[s("input",{className:"tt_cardInput",value:G?Z:"",placeholder:"\u6216\uFF1A\u9009\u62E9\u51ED\u636E\u5B58\u50A8\u91CC\u7684\u5F15\u7528\u540D",title:"\u5019\u9009 = \u51ED\u636E\u5B58\u50A8\u91CC\u5DF2\u6709\u7684\u5F15\u7528\u540D + \u672C\u673A\u8FDE\u63A5\u7C3F\u91CC\u5728\u7528\u7684\u5F15\u7528\u540D",autoComplete:"off",spellCheck:!1,onFocus:()=>{Y(I),N("")},onBlur:le=>{le.currentTarget.parentElement.contains(le.relatedTarget)||Y("")},onChange:le=>{N(le.target.value),Y(I)}}),...G?[s("div",{className:"tt_envList",children:[...ae.length===0?[s("span",{className:"tt_envMore",children:"\u6CA1\u6709\u5339\u914D\u7684\u5F15\u7528"})]:ae.slice(0,30).map(le=>s("button",{type:"button",className:"tt_envItem","data-danger":x===le?"":void 0,onMouseDown:we=>we.preventDefault(),onClick:()=>Bc(I,le),children:x===le?le+"\uFF08\u518D\u70B9\u8986\u76D6\u5DF2\u586B\uFF09":le},le)),...ae.length>30?[s("span",{className:"tt_envMore",children:"\u8FD8\u6709 "+(ae.length-30)+" \u4E2A \u2014 \u7EE7\u7EED\u8F93\u5165\u7B5B\u9009"})]:[]]},"cred-list-"+I)]:[]]})},Pc=()=>{let V=fr(D?.password??"")!=="",G=br()===null;return o("div",{className:"tt_sshRow tt_credRow",children:[V?s("button",{type:"button",className:"tt_toolBtn tt_credClear",disabled:re!==!0,onClick:()=>{Dc()},children:"\u6E05\u9664\u5DF2\u5B58\u51ED\u636E"}):s("label",{className:"tt_credToggle",title:"\u52FE\u9009\u540E\uFF0C\u70B9\u300C\u5E94\u7528\u300D\u65F6\u628A\u5BC6\u7801\u5199\u8FDB\u5B98\u65B9\u51ED\u636E\u5B58\u50A8\uFF0C\u5B57\u6BB5\u91CC\u53EA\u7559 env: \u5F15\u7528\uFF08\u503C\u5728 ~/.dsh/.credentials.yaml\uFF0C\u4E0D\u8FDB\u73AF\u5883\u3001\u4E0D\u56DE\u4F20\u6D4F\u89C8\u5668\uFF1B\u6321\u4E0D\u4F4F\u540C\u7528\u6237\u8FDB\u7A0B\u4E0E agent\uFF09\u3002\u4E0D\u52FE\u9009\u5219\u6309\u73B0\u72B6\u660E\u6587\u5199\u8FDB\u8BBE\u7F6E\u6587\u4EF6\u3002\u80FD\u7528\u5BC6\u94A5 / agent \u5C31\u522B\u5B58\u5BC6\u7801\u3002",children:[s("input",{type:"checkbox",className:"tt_cardCheckbox",checked:$,disabled:G,onChange:te=>U(te.target.checked)}),s("span",{children:"\u5E94\u7528\u65F6\u5B58\u5165\u51ED\u636E\u5B58\u50A8"})]}),X.text===""?null:s("span",{className:"tt_credStatus","data-kind":X.kind,children:X.text}),G&&X.text===""?s("span",{className:"tt_credStatus","data-kind":"muted",children:"\u5BBF\u4E3B\u672A\u63D0\u4F9B\u51ED\u636E\u670D\u52A1\uFF08remote.credentials\uFF09\uFF0C\u53EA\u80FD\u660E\u6587\u4FDD\u5B58"}):null]})},Yn=()=>{let I=String(D?.host??"").trim(),V=String(D?.username??"").trim(),G=Number(D?.port);if((!Number.isInteger(G)||G<1||G>65535)&&(G=22),I===""||V==="")return k("\u4E3B\u673A\u4E0E\u7528\u6237\u540D\u5FC5\u586B"),null;let te=D?.auth,ae={host:I,port:G,username:V,auth:te};if(te==="key"){let le=String(D?.keyPath??"").trim();if(le==="")return k("auth=key \u9700\u8981\u79C1\u94A5\u8DEF\u5F84"),null;ae.keyPath=le,D?.passphrase!==""&&(ae.passphrase=D.passphrase)}if(te==="password"){let le=String(D?.password??"");if(le==="")return k("auth=password \u9700\u8981\u5BC6\u7801"),null;ae.password=le}return D?.agentForward===!0&&(ae.agentForward=!0),ae},Oc=()=>{k("");let I=Yn();I!==null&&(J({running:!0,ok:!1,text:"\u8FDE\u63A5\u6D4B\u8BD5\u4E2D\u2026"}),Ln(I,!1).then(V=>{if(V.result){let G=V.result.auth?.ok===!0;J({running:!1,ok:G,text:Mn(V.result)});return}J({running:!1,ok:!1,text:"\u274C \u8FDE\u63A5\u5931\u8D25\uFF1A"+String(V.error||"\u672A\u77E5\u9519\u8BEF")})}))},Ic=()=>{k("");let I=Yn();I!==null&&us(I)},Nc=()=>{if(D===null)return null;let I=(V,G,te,ae,le)=>o("label",{className:"tt_sshRow",children:[s("span",{className:"tt_cardLabel",children:V}),s("input",{className:"tt_cardInput",type:ae??"text",value:D[G]??"",placeholder:te??"",autoComplete:"off",spellCheck:!1,onChange:we=>{let ce=we.target.value;w(vt=>({...vt||{},[G]:ce}))},...le??{}})]});return o("div",{className:"tt_sshEdit",children:[s("div",{className:"tt_sshSection",children:"\u8FDE\u63A5"}),o("div",{className:"tt_sshGrid",children:[I("\u540D\u79F0","name","\u540C\u540D\u51B2\u7A81\u4F1A\u88AB\u62D2\u7EDD"),I("\u7AEF\u53E3","port","22")]}),I("\u4E3B\u673A","host","example.com \u6216 IP"),I("\u7528\u6237\u540D","username","root"),s("div",{className:"tt_sshSection",children:"\u8BA4\u8BC1"}),o("label",{className:"tt_sshRow",children:[s("span",{className:"tt_cardLabel",children:"\u8BA4\u8BC1\u65B9\u5F0F"}),o("select",{className:"tt_cardInput",value:D.auth,onChange:V=>w(G=>({...G||{},auth:V.target.value})),children:[s("option",{value:"agent",children:"agent \u2014 \u4F7F\u7528\u672C\u673A ssh-agent"}),s("option",{value:"key",children:"key \u2014 \u79C1\u94A5\u6587\u4EF6"}),s("option",{value:"password",children:"password \u2014 \u5BC6\u7801"})]})]}),...D.auth==="key"?[I("\u79C1\u94A5\u8DEF\u5F84","keyPath","~/.ssh/id_ed25519"),I("\u79C1\u94A5\u53E3\u4EE4\uFF08\u53EF\u7A7A\uFF09","passphrase","","password"),Gn("passphrase","\u8FD8\u6CA1\u6709\u522B\u7684\u8FDE\u63A5\u7528\u8FC7\u51ED\u636E\u5F15\u7528 \u2014 \u53EF\u5728\u79C1\u94A5\u53E3\u4EE4\u6846\u76F4\u63A5\u624B\u8F93 env:NAME")]:[],...D.auth==="password"?[I("\u5BC6\u7801","password","","password",{onBlur:()=>{ps(D.password)}}),Pc(),Gn("password","\u8FD8\u6CA1\u6709\u522B\u7684\u8FDE\u63A5\u7528\u8FC7\u51ED\u636E\u5F15\u7528 \u2014 \u52FE\u4E0A\u9762\u7684\u300C\u5E94\u7528\u65F6\u5B58\u5165\u51ED\u636E\u5B58\u50A8\u300D\u65B0\u5EFA\u4E00\u4E2A\uFF0C\u6216\u76F4\u63A5\u5728\u5BC6\u7801\u6846\u624B\u8F93 env:NAME")]:[],s("div",{className:"tt_sshSection",children:"\u9009\u9879"}),o("label",{className:"tt_cardRow",children:[s("input",{type:"checkbox",className:"tt_cardCheckbox",checked:D.agentForward===!0,onChange:V=>w(G=>({...G||{},agentForward:V.target.checked}))}),s("span",{className:"tt_cardLabel",children:"agent forwarding\uFF08\u8FDC\u7A0B\u53EF\u7528\u672C\u5730 ssh-agent \u94A5\u5319\uFF0C\u5982\u8FDC\u7A0B git clone\uFF09"})]}),Nt==="tmux"?o("label",{className:"tt_cardRow",children:[s("input",{type:"checkbox",className:"tt_cardCheckbox",checked:D.persist===!0,onChange:V=>w(G=>({...G||{},persist:V.target.checked}))}),s("span",{className:"tt_cardLabel",children:"\u6301\u4E45\u4F1A\u8BDD\uFF08tmux \u6258\u7BA1\uFF0C\u65AD\u7EBF/\u91CD\u542F\u540E\u6062\u590D\u73B0\u573A\uFF1B\u8FDC\u7A0B\u9700\u5B89\u88C5 tmux\uFF09"})]}):null,K.text!==""?s("div",{className:"tt_sshProbeResult"+(!K.running&&K.ok?" tt_sshProbeOk":"")+(!K.running&&!K.ok?" tt_sshProbeBad":""),children:K.text}):null,L!==""?s("span",{className:"tt_cardMessage tt_cardMessageError",children:L}):null,o("div",{className:"tt_sshActions",children:[o("div",{className:"tt_sshActionsGroup",children:[s("button",{type:"button",className:"tt_toolBtn",onClick:Kn,children:"\u53D6\u6D88"}),s("button",{type:"button",className:"tt_toolBtn",title:"\u4E0D\u52A8\u7EC8\u7AEF\uFF0C\u76F4\u63A5\u4EE5\u5F53\u524D\u586B\u5199\u7684\u4FE1\u606F\u6253\u5F00 SFTP \u6587\u4EF6\u6D4F\u89C8",onClick:Ic,children:"\u6587\u4EF6\u6D4F\u89C8"}),s("button",{type:"button",className:"tt_toolBtn",disabled:K.running,title:"\u6309\u5F53\u524D\u586B\u5199\u8BCA\u65AD\u8FDE\u63A5\uFF08TCP \u2192 \u4E3B\u673A\u5BC6\u94A5 \u2192 \u8BA4\u8BC1\uFF09\uFF1B\u4E0D\u4F1A\u65B0\u5EFA\u4F1A\u8BDD\uFF0C\u4E5F\u4E0D\u8BB0\u5F55\u4E3B\u673A\u6307\u7EB9",onClick:Oc,children:K.running?"\u8BD5\u8FDE\u4E2D\u2026":"\u8BD5\u8FDE"})]}),o("div",{className:"tt_sshActionsGroup",children:[s("button",{type:"button",className:"tt_cardSave",onClick:()=>{kc()},children:"\u5E94\u7528"}),s("span",{className:"tt_cardHint",children:"\u968F\u5361\u7247\u300C\u4FDD\u5B58\u300D\u5199\u5165\u914D\u7F6E"})]})]})]})},kr=(I,V,G,te)=>o("label",{className:"tt_cardField",children:[s("span",{className:"tt_cardLabel",children:I}),s("input",{className:"tt_cardInput",value:_[V]??"",placeholder:G??"",onChange:ae=>j(V,ae.target.value)}),te?s("span",{className:"tt_cardHint",children:te}):null]}),Er=(I,V)=>o("label",{className:"tt_cardField tt_cardRow",children:[s("input",{type:"checkbox",className:"tt_cardCheckbox",checked:_[V]===!0,onChange:G=>j(V,G.target.checked)}),s("span",{className:"tt_cardLabel",children:I})]}),Lr=_?.platform==="win32";return c==="summary"?"xterm \u7EC8\u7AEF\u9762\u677F\uFF1A\u591A\u6807\u7B7E\u9875\u3001\u65AD\u7EBF\u81EA\u52A8\u91CD\u8FDE\u3001cwd \u8DDF\u968F\u4F1A\u8BDD\u3001SSH \u8FDE\u63A5\u7C3F\u4E0E\u4E3B\u673A\u6307\u7EB9\u9489\u624E\u3001tmux \u4F1A\u8BDD\u6301\u4E45\u5316\u3002":o(p?"div":"li",{className:p?"tt_pageHost":g?"tt_card tt_cardOpen":"tt_card",children:[p?null:o("button",{type:"button",className:"tt_cardHeader","aria-expanded":g,onClick:()=>S(I=>!I),children:[o("span",{className:"tt_cardHeadText",children:[s("span",{className:"tt_cardName",children:"\u7EC8\u7AEF\u9762\u677F"}),s("span",{className:"tt_cardDescription",children:"xterm \u7EC8\u7AEF\u9762\u677F\uFF1A\u591A\u6807\u7B7E\u9875\u3001\u65AD\u7EBF\u81EA\u52A8\u91CD\u8FDE\u3001cwd \u8DDF\u968F\u4F1A\u8BDD\u3001SSH \u8FDE\u63A5\u7C3F\u4E0E\u4E3B\u673A\u6307\u7EB9\u9489\u624E\u3001tmux \u4F1A\u8BDD\u6301\u4E45\u5316\uFF1Bshell / TERM / \u5E76\u53D1\u4E0A\u9650\u7B49\u4FDD\u5B58\u5373\u70ED\u751F\u6548\u3002"})]}),s("span",{className:"dshkit_badge",children:"Kit"}),s("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:g?"tt_cardChevron tt_cardChevronOpen":"tt_cardChevron",children:s("path",{d:i,fill:"currentColor"})})]}),p||g?o("div",{className:"tt_cardBody",children:[_===null?s("div",{className:"tt_cardMessage",children:"\u52A0\u8F7D\u914D\u7F6E\u4E2D\u2026"}):o("div",{children:[B("\u57FA\u7840"),Er("\u542F\u7528\u63D2\u4EF6\uFF08\u4FDD\u5B58\u5373\u70ED\u751F\u6548\uFF1A\u5DE5\u5177\u4E0E\u9762\u677F\u5165\u53E3\u7ACB\u523B\u6536\u8D77\uFF0C\u4F1A\u8BDD\u8F6C\u4FDD\u6D3B\uFF09","enabled"),Er("\u5411 agent \u516C\u544A\u7EC8\u7AEF\u9762\u677F\u80FD\u529B","announceToAgent"),Lr?o("div",{className:"tt_cardField",children:[o("label",{className:"tt_cardRow",children:[s("input",{type:"checkbox",className:"tt_cardCheckbox",checked:!1,disabled:!0}),s("span",{className:"tt_cardLabel",children:"shell \u96C6\u6210\uFF08OSC 133/7 \u6CE8\u5165\uFF09"})]}),s("span",{className:"tt_cardHint",children:"Windows \u5BBF\u4E3B\u4E0A\u4E0D\u9002\u7528\uFF1A\u6CE8\u5165\u8D70\u7684\u662F POSIX \u7684 `-c` \u5305\u88C5\u5C42\u4E0E rc \u6869\uFF0Ccmd / PowerShell \u4E0A\u90FD\u4E0D\u6210\u7ACB\uFF08\u5B9E\u6D4B cmd \u5FFD\u7565 `-c` \u7A7A\u8DD1\u3001PowerShell \u62A5 export \u4E0D\u5B58\u5728\uFF09\u3002\u56E0\u6B64**\u672C\u5730**\u6807\u7B7E\u7684 cwd \u8DDF\u968F\u4E0E tty_capture{last} \u4E0D\u53EF\u7528\uFF1B\u8FDC\u7A0B Linux / macOS \u4E3B\u673A\u7167\u65E7\u652F\u6301\u3002"})]}):Er("shell \u96C6\u6210\uFF08OSC 133/7 \u6CE8\u5165\uFF0Ctty_capture{last} \u4E0E cwd \u8DDF\u968F\u4F9D\u8D56\u5B83\uFF09","shellIntegration"),B("SFTP \u6587\u4EF6\u4F20\u8F93"),o("div",{className:"tt_cardField",children:[s("span",{className:"tt_cardLabel",children:"SFTP \u6587\u4EF6\u6D4F\u89C8\u98CE\u683C"}),o("select",{className:"tt_cardInput",value:_.sftpStyle==="dual"?"dual":"dialog",onChange:I=>j("sftpStyle",I.target.value),children:[s("option",{value:"dialog",children:"\u5355\u7A97\u4F53 \u2014 \u8FDC\u7A0B\u76EE\u5F55 + \u4E0A\u4F20/\u4E0B\u8F7D/\u62D6\u62FD"}),s("option",{value:"dual",children:"\u53CC\u680F \u2014 \u5DE6\u672C\u673A / \u53F3\u8FDC\u7A0B\uFF0C\u9009\u4E2D\u76F4\u4F20"})]}),s("span",{className:"tt_cardHint",children:"\u53CC\u680F\u5728\u672C\u673A\u4E0E\u8FDC\u7A0B\u4E4B\u95F4\u5BF9\u62F7\u6587\u4EF6\uFF08\u76EE\u5F55\u9012\u5F52\u3001\u540C\u540D\u8986\u76D6\uFF09\uFF1B\u91CD\u65B0\u6253\u5F00 SFTP \u540E\u751F\u6548"})]}),o("div",{className:"tt_cardField",children:[s("span",{className:"tt_cardLabel",children:"SFTP \u4F20\u8F93\u9650\u5236\uFF080 = \u4E0D\u9650\uFF09"}),o("div",{className:"tt_limitGrid",children:[o("label",{className:"tt_sshRow",children:[s("span",{className:"tt_cardLabel",children:"\u4E0B\u8F7D\u4E0A\u9650 (MB)"}),s("input",{className:"tt_cardInput",type:"number",min:0,value:String(Number.isFinite(Number(_?.sftpLimits?.maxDownloadMb))?Number(_.sftpLimits.maxDownloadMb):1024),onChange:I=>A("maxDownloadMb",Number(I.target.value)||0)})]}),o("label",{className:"tt_sshRow",children:[s("span",{className:"tt_cardLabel",children:"\u4E0A\u4F20\u4E0A\u9650 (MB)"}),s("input",{className:"tt_cardInput",type:"number",min:0,value:String(Number.isFinite(Number(_?.sftpLimits?.maxUploadMb))?Number(_.sftpLimits.maxUploadMb):2048),onChange:I=>A("maxUploadMb",Number(I.target.value)||0)})]}),o("label",{className:"tt_sshRow",children:[s("span",{className:"tt_cardLabel",children:"\u6279\u91CF\u6587\u4EF6\u6570\u4E0A\u9650"}),s("input",{className:"tt_cardInput",type:"number",min:0,value:String(Number.isFinite(Number(_?.sftpLimits?.maxUploadFiles))?Number(_.sftpLimits.maxUploadFiles):1e3),onChange:I=>A("maxUploadFiles",Number(I.target.value)||0)})]})]}),s("span",{className:"tt_cardHint",children:"\u6D4F\u89C8\u5668\u4FA7\u4FDD\u62A4\uFF1A\u5355\u4E2A\u6587\u4EF6\u8D85\u8FC7\u4E0A\u9650\u65F6\u4E2D\u6B62\u4E0B\u8F7D/\u4E0A\u4F20\uFF08\u5927\u6587\u4EF6\u8BF7\u7528\u53CC\u680F \u21E8/\u21E6 \u76F4\u4F20\u6216\u7EC8\u7AEF scp/rsync\uFF0C\u4E0D\u5360\u6D4F\u89C8\u5668\u5185\u5B58\uFF09\uFF1B\u6587\u4EF6\u6570\u4E0A\u9650\u9488\u5BF9\u4E00\u6B21\u6279\u91CF/\u62D6\u62FD\u4E0A\u4F20\uFF1B\u4FDD\u5B58\u5373\u70ED\u751F\u6548"})]}),B("\u4F1A\u8BDD"),o("div",{className:"tt_cardField",children:[s("span",{className:"tt_cardLabel",children:"\u4F1A\u8BDD\u6301\u4E45\u5316\uFF08tmux\uFF09"}),o("select",{className:"tt_cardInput",value:_.persistence==="tmux"?"tmux":"off",onChange:I=>j("persistence",I.target.value),children:[s("option",{value:"off",children:"\u5173\u95ED \u2014 \u4F1A\u8BDD\u968F\u9762\u677F/\u5BBF\u4E3B\u7ED3\u675F\uFF08\u9ED8\u8BA4\uFF09"}),s("option",{value:"tmux",children:"tmux \u2014 \u65B0\u5F00\u7684\u7EC8\u7AEF/SSH \u6807\u7B7E\u9ED8\u8BA4\u6301\u4E45\u5316"})]}),s("span",{className:"tt_cardHint",children:"\u5F00\u542F\u540E\u6240\u6709\u65B0\u6807\u7B7E\uFF08\u672C\u5730/SSH \u8FDE\u63A5\u7C3F/SSH \u8FDE\u63A5\u5BF9\u8BDD\u6846\uFF09\u9ED8\u8BA4\u7531 tmux \u6258\u7BA1\u3001\u53EF\u8DE8\u5BBF\u4E3B\u91CD\u542F\u6062\u590D\uFF1B\u9700\u672C\u673A/\u8FDC\u7A0B\u5B89\u88C5 tmux\uFF1BSSH \u5BF9\u8BDD\u6846\u53EF\u5BF9\u5355\u6B21\u8FDE\u63A5\u53D6\u6D88\u52FE\u9009\uFF1B\u5DF2\u6709\u6807\u7B7E\u4E0D\u53D7\u5F71\u54CD"+(Lr?"\uFF1BWindows \u5BBF\u4E3B\u4E0A tmux \u4E0D\u53EF\u7528\uFF0C\u672C\u5730\u6807\u7B7E\u4F1A\u7167\u5E38\u6253\u5F00\u4F46\u4E0D\u53D7\u6258\u7BA1":"")}),Er("\u5173\u95ED\u9875\u9762\u540E\u7ED3\u675F\u6301\u4E45\u4F1A\u8BDD\uFF08\u4E0D\u4FDD\u6D3B\uFF09","endOnPageClose"),Er("\u670D\u52A1\u5668\u72B6\u6001\u6761\uFF08CPU / \u5185\u5B58 / \u78C1\u76D8 / \u5728\u7EBF / TCP / \u7F51\u901F\uFF1B\u91C7\u4E0D\u5230\u7684\u9879\u663E\u793A\u300C\u65E0\u300D\uFF09","statsEnabled"),s("span",{className:"tt_cardHint",children:"\u9ED8\u8BA4\u5173\u95ED\uFF1A\u6574\u4E2A\u9875\u9762\u5173\u95ED\u65F6\u6301\u4E45\u4F1A\u8BDD\u7559\u5B58\uFF08\u4FDD\u6D3B\u671F\u540E\u53EF\u518D\u6062\u590D\uFF09\uFF1B\u5F00\u542F\u5219\u9875\u9762\u65AD\u5F00\u4E14\u4FDD\u6D3B\u671F\u7ED3\u675F\u65F6\u8FDE tmux \u4F1A\u8BDD\u4E00\u8D77\u7ED3\u675F\u2014\u2014\u6CE8\u610F\u5237\u65B0\u9875\u9762\u5728\u4FDD\u6D3B\u671F\u5185\u4E0D\u53D7\u5F71\u54CD"})]}),kr("\u5E76\u53D1\u4F1A\u8BDD\u4E0A\u9650\uFF081~16\uFF09","maxSessions","4","\u8D85\u8FC7\u4E0A\u9650\u7684\u65B0\u6807\u7B7E\u4F1A\u88AB\u62D2\u7EDD\uFF1B\u4FDD\u5B58\u5373\u70ED\u751F\u6548"),o("div",{className:"tt_cardField",onBlur:I=>{I.currentTarget.contains(I.relatedTarget)||P(!1)},children:[s("span",{className:"tt_cardLabel",children:Lr?"Shell \u8DEF\u5F84\uFF08\u9ED8\u8BA4 %COMSPEC%\uFF09":"Shell \u8DEF\u5F84\uFF08\u9ED8\u8BA4 $SHELL\uFF09"}),s("input",{className:"tt_cardInput",value:_.shell??"",placeholder:Lr?"\u7559\u7A7A\u4F7F\u7528 %COMSPEC%\uFF08\u4E5F\u53EF\u586B powershell.exe / pwsh.exe \u5B8C\u6574\u8DEF\u5F84\uFF09":"\u7559\u7A7A\u4F7F\u7528 $SHELL",autoComplete:"off",spellCheck:!1,onFocus:()=>P(!0),onClick:()=>P(!0),onKeyDown:I=>{I.key==="Escape"&&P(!1)},onChange:I=>{j("shell",I.target.value),P(!0)}}),...E?[s("div",{className:"tt_envList tt_shellList",children:(()=>{let I=(_.shell??"").trim().toLowerCase(),V=I===""?C:C.filter(G=>G.toLowerCase().includes(I));return V.length===0?s("span",{className:"tt_envMore",children:"\u6CA1\u6709\u5339\u914D\u7684\u5019\u9009 \u2014 \u76F4\u63A5\u8F93\u5165\u4EFB\u610F\u8DEF\u5F84\u5373\u53EF"}):V.map(G=>s("button",{type:"button",className:"tt_envItem",onMouseDown:te=>te.preventDefault(),onClick:()=>{j("shell",G),P(!1)},children:G},G))})()},"shell-list")]:[],s("span",{className:"tt_cardHint",children:Lr?"Windows \u5BBF\u4E3B\uFF1A\u5019\u9009\u6765\u81EA %COMSPEC% \u4E0E\u5DF2\u5B89\u88C5\u7684 PowerShell\uFF08Windows PowerShell 5.1 / PowerShell 7\uFF09\uFF0C\u4E5F\u53EF\u76F4\u63A5\u8F93\u5165\u4EFB\u610F\u8DEF\u5F84\uFF1Bcmd / PowerShell \u6CA1\u6709 POSIX \u7684\u547D\u4EE4\u8FB9\u754C\u94A9\u5B50\uFF0C\u6240\u4EE5\u8FD9\u4E24\u8005\u4E0D\u652F\u6301 shell \u96C6\u6210":"\u53EF\u4E0B\u62C9\u9009\u62E9\u672C\u673A\u5DF2\u5B89\u88C5 shell\uFF08$SHELL \u4F18\u5148\uFF09\uFF0C\u4E5F\u53EF\u76F4\u63A5\u8F93\u5165\u4EFB\u610F\u8DEF\u5F84\uFF1Bzsh / bash \u652F\u6301 shell \u96C6\u6210"})]},"shell-field"),kr("TERM","term","xterm-256color","TUI \u7A0B\u5E8F\u4F9D\u8D56\u6B64\u503C"),kr("COLORTERM","colorTerm","truecolor",""),kr("\u515C\u5E95\u5DE5\u4F5C\u76EE\u5F55\uFF08\u5BA2\u6237\u7AEF\u5F53\u524D\u4F1A\u8BDD cwd \u4F18\u5148\uFF09","cwd","","\u7559\u7A7A\u4F7F\u7528\u5BBF\u4E3B\u8FDB\u7A0B\u542F\u52A8\u76EE\u5F55"),kr("\u65AD\u7EBF\u4FDD\u6D3B\uFF08\u79D2\uFF0C0 = \u7ACB\u5373\u7ED3\u675F\uFF09","reconnectGraceSec","120","\u5237\u65B0\u9875\u9762/\u7F51\u7EDC\u6296\u52A8\u540E\u4F1A\u8BDD\u4FDD\u6D3B\u7B49\u5F85\u91CD\u8FDE\uFF0C\u8D85\u65F6\u540E\u7ED3\u675F\uFF1B\u4FDD\u5B58\u5373\u70ED\u751F\u6548"),B("SSH \u8FDE\u63A5"),o("div",{className:"tt_cardField",children:[s("span",{className:"tt_cardLabel",children:"SSH \u8FDE\u63A5\u7C3F"}),...Array.isArray(_.sshHosts)&&_.sshHosts.length>0?[s("div",{className:"tt_hostList","data-editing":T!==null?"":void 0,children:_.sshHosts.map(I=>o("div",{children:[o("div",{className:"tt_sshHostRow",children:[s("div",{className:"tt_sshHostMeta",children:[s("span",{className:"tt_sshHostName",children:I?.name??""}),s("span",{className:"tt_sshHostTarget",children:En(I??{})})]}),s("button",{type:"button",className:"tt_toolBtn",disabled:oe[I?.name]?.running===!0,onClick:()=>{Lc(I)},title:"\u8BD5\u8FDE\u8BE5\u6761\u76EE\uFF1ATCP \u2192 \u4E3B\u673A\u5BC6\u94A5 \u2192 \u8BA4\u8BC1\u9010\u6BB5\u8BCA\u65AD",children:oe[I?.name]?.running===!0?"\u6D4B\u8BD5\u4E2D\u2026":"\u6D4B\u8BD5"}),s("button",{type:"button",className:"tt_toolBtn",onClick:()=>xc(I),children:"\u7F16\u8F91"}),s("button",{type:"button",className:"tt_toolBtn",onClick:()=>Ec(I?.name),children:"\u5220\u9664"})]}),oe[I?.name]&&oe[I?.name].text?s("div",{className:"tt_sshProbeResult"+(oe[I?.name].ok?" tt_sshProbeOk":" tt_sshProbeBad"),children:oe[I?.name].text}):null,T===I?.name?Nc():null]},String(I?.name??"")))})]:[s("span",{className:"tt_cardHint",children:"\u6682\u65E0\u6761\u76EE \u2014 \u7EC8\u7AEF\u9762\u677F\u300C+\u300D\u2192 SSH \u8FDE\u63A5\u2026 \u52FE\u9009\u300C\u4FDD\u5B58\u5230\u8FDE\u63A5\u7C3F\u300D\u5373\u53EF\u6DFB\u52A0"})],o("div",{className:"tt_cardRow",children:[s("button",{type:"button",className:"tt_toolBtn",onClick:()=>{Rc()},children:"\u4ECE ~/.ssh/config \u5BFC\u5165"}),s("span",{className:"tt_cardHint",children:"\u540C\u540D\u8DF3\u8FC7\uFF1B\u968F\u300C\u4FDD\u5B58\u300D\u5199\u5165\u914D\u7F6E"})]}),s("span",{className:"tt_cardHint",children:"\u968F\u300C\u4FDD\u5B58\u300D\u4E00\u5E76\u5199\u5165\u914D\u7F6E\uFF1B\u5BC6\u7801/\u53E3\u4EE4\u652F\u6301 env:VAR \u5F15\u7528\uFF0C\u907F\u514D\u660E\u6587\u5165\u5E93"})]}),o("div",{className:"tt_cardField",children:[o("div",{className:"tt_cardField",children:[s("span",{className:"tt_cardLabel",children:"\u7AEF\u53E3\u8F6C\u53D1"}),...Array.isArray(_.tunnels)&&_.tunnels.length>0?[s("div",{children:_.tunnels.map(I=>{let V=he.find(ae=>ae.name===I?.name),G=V?.state??"stopped",te=pe!==null&&String(I?.name??"")===pe;return o("div",{className:"tt_sshHostRow","data-editing":te?"":void 0,children:[s("span",{className:"tt_tunnelDot","data-state":G,title:G}),s("div",{className:"tt_sshHostMeta",children:[s("span",{className:"tt_sshHostName",children:(I?.name??"")+" \xB7 "+Jt(I??{})}),s("span",{className:"tt_sshHostTarget",children:(I?.bookName??"")+(V?.error?" \xB7 "+V.error:"")+(V?.lastForwardError?" \xB7 "+V.lastForwardError:"")})]}),s("input",{type:"checkbox",className:"tt_cardCheckbox",checked:I?.enabled!==!1,title:"\u542F\u7528",onChange:ae=>Cc(I?.name,ae.target.checked)}),s("button",{type:"button",className:"tt_toolBtn",onClick:()=>fs(I),children:"\u7F16\u8F91"}),s("button",{type:"button",className:"tt_toolBtn",onClick:()=>yc(I?.name),children:"\u5220\u9664"})]},String(I?.name??""))})})]:[s("span",{className:"tt_cardHint",children:"\u6682\u65E0\u96A7\u9053 \u2014 \u628A\u8FDC\u7A0B\u6570\u636E\u5E93/\u5185\u90E8\u670D\u52A1\u6620\u5C04\u5230\u672C\u5730\u7AEF\u53E3"})],o("div",{className:"tt_sshEdit",children:[o("div",{className:"tt_cardRow",children:[o("div",{className:"tt_segmented",role:"group","aria-label":"\u8F6C\u53D1\u65B9\u5411",children:[s("button",{type:"button",className:"tt_segmentedBtn","data-active":de.direction!=="remote"?"":void 0,title:"\u672C\u5730\u8F6C\u53D1 -L\uFF1A\u672C\u673A\u76D1\u542C\uFF0C\u8FDE\u5230 SSH \u670D\u52A1\u5668\u4FA7\u7684\u76EE\u6807",onClick:()=>Qe("direction","local"),children:"\u672C\u5730 -L"}),s("button",{type:"button",className:"tt_segmentedBtn","data-active":de.direction==="remote"?"":void 0,title:"\u8FDC\u7A0B\u8F6C\u53D1 -R\uFF1ASSH \u670D\u52A1\u5668\u4FA7\u76D1\u542C\uFF0C\u62E8\u56DE\u672C\u673A\u670D\u52A1",onClick:()=>Qe("direction","remote"),children:"\u8FDC\u7A0B -R"})]}),o("select",{className:"tt_cardInput",value:de.bookName,onChange:je("bookName"),children:[s("option",{value:"",children:"\u9009\u62E9\u8FDE\u63A5\u7C3F\u6761\u76EE"}),...Array.isArray(_?.sshHosts)?_.sshHosts.map(I=>s("option",{value:I?.name??"",children:I?.name??""})):[]]})]}),s("span",{className:"tt_cardHint",children:et!==void 0?"\u7ECF "+En(et)+" \u8FDE\u63A5 \u2014 \u96A7\u9053\u7684\u4E3B\u673A\u4E0E\u8BA4\u8BC1\u53D6\u81EA\u8BE5\u8FDE\u63A5\u7C3F\u6761\u76EE":"\u9009\u62E9\u8FD9\u6761\u96A7\u9053\u8981\u8D70\u54EA\u53F0 SSH \u8FDE\u63A5\uFF08\u4E3B\u673A\u4E0E\u8BA4\u8BC1\u53D6\u81EA\u8FDE\u63A5\u7C3F\uFF09"}),de.direction==="local"?o("div",{className:"tt_tunnelEndpoints",children:[o("div",{className:"tt_tunnelEndpoint",children:[s("span",{className:"tt_tunnelEndpointStatic",title:"\u672C\u673A\u76D1\u542C\u5730\u5740\u56FA\u5B9A 127.0.0.1\uFF08\u4E0D\u66B4\u9732\u5230\u5C40\u57DF\u7F51\uFF09",children:"127.0.0.1"}),s("span",{className:"tt_tunnelColon",children:":"}),s("input",{className:"tt_cardInput tt_tunnelPort",placeholder:"\u672C\u673A\u7AEF\u53E3",value:de.localPort,autoComplete:"off",inputMode:"numeric","aria-label":"\u672C\u673A\u76D1\u542C\u7AEF\u53E3",onChange:je("localPort")})]}),s("span",{className:"tt_tunnelArrow","data-direction":"local",title:"\u6570\u636E\u6D41\u5411\uFF1A\u672C\u673A \u2192 SSH \u670D\u52A1\u5668\u4FA7","aria-hidden":"true",children:"\u2192"}),o("div",{className:"tt_tunnelEndpoint",children:[s("input",{className:"tt_cardInput tt_tunnelHost",placeholder:"\u670D\u52A1\u5668\u4FA7\u4E3B\u673A\uFF08\u5982 db.internal\uFF09",value:de.remoteHost,autoComplete:"off","aria-label":"\u670D\u52A1\u5668\u4FA7\u76EE\u6807\u4E3B\u673A",onChange:je("remoteHost")}),s("span",{className:"tt_tunnelColon",children:":"}),s("input",{className:"tt_cardInput tt_tunnelPort",placeholder:"\u7AEF\u53E3",value:de.remotePort,autoComplete:"off",inputMode:"numeric","aria-label":"\u670D\u52A1\u5668\u4FA7\u76EE\u6807\u7AEF\u53E3",onChange:je("remotePort")})]})]}):o("div",{className:"tt_tunnelEndpoints",children:[o("div",{className:"tt_tunnelEndpoint",children:[s("input",{className:"tt_cardInput tt_tunnelHost",placeholder:"\u670D\u52A1\u5668\u4FA7\u76D1\u542C\u5730\u5740\uFF08\u7F3A\u7701 127.0.0.1\uFF09",value:de.remoteHost,autoComplete:"off","aria-label":"\u670D\u52A1\u5668\u4FA7\u76D1\u542C\u5730\u5740",onChange:je("remoteHost")}),s("span",{className:"tt_tunnelColon",children:":"}),s("input",{className:"tt_cardInput tt_tunnelPort",placeholder:"\u76D1\u542C\u7AEF\u53E3",value:de.remotePort,autoComplete:"off",inputMode:"numeric","aria-label":"\u670D\u52A1\u5668\u4FA7\u76D1\u542C\u7AEF\u53E3",onChange:je("remotePort")})]}),s("span",{className:"tt_tunnelArrow","data-direction":"remote",title:"\u6570\u636E\u6D41\u5411\uFF1A\u672C\u673A \u2190 SSH \u670D\u52A1\u5668\u4FA7","aria-hidden":"true",children:"\u2192"}),o("div",{className:"tt_tunnelEndpoint",children:[s("span",{className:"tt_tunnelEndpointStatic",title:"\u672C\u673A\u62E8\u53F7\u5730\u5740\u56FA\u5B9A 127.0.0.1",children:"127.0.0.1"}),s("span",{className:"tt_tunnelColon",children:":"}),s("input",{className:"tt_cardInput tt_tunnelPort",placeholder:"\u672C\u673A\u670D\u52A1\u7AEF\u53E3",value:de.localTargetPort,autoComplete:"off",inputMode:"numeric","aria-label":"\u672C\u673A\u76EE\u6807\u7AEF\u53E3",onChange:je("localTargetPort")})]})]}),s("div",{className:"tt_tunnelEndpoints",children:[s("span",{className:"tt_tunnelEndLabel",children:de.direction==="local"?"\u5DE6\uFF1A\u672C\u673A\u76D1\u542C\uFF08\u56FA\u5B9A 127.0.0.1\uFF09\u2192 \u53F3\uFF1A\u7531 SSH \u670D\u52A1\u5668\u4FA7\u8BBF\u95EE\u7684\u76EE\u6807":"\u5DE6\uFF1ASSH \u670D\u52A1\u5668\u4FA7\u76D1\u542C \u2192 \u53F3\uFF1A\u672C\u673A\u88AB\u8BBF\u95EE\u7684\u670D\u52A1\uFF08\u56FA\u5B9A 127.0.0.1\uFF09"})]}),s("div",{className:"tt_cardRow",children:[pe===null?s("button",{type:"button",className:"tt_cardSave",onClick:wc,children:"\u6DFB\u52A0\u96A7\u9053"}):s("button",{type:"button",className:"tt_cardSave",onClick:Sc,children:"\u4FDD\u5B58\u4FEE\u6539"}),pe===null?null:s("button",{type:"button",className:"tt_toolBtn",onClick:bc,children:"\u53D6\u6D88"}),s("span",{className:"tt_cardHint",children:pe===null?"\u6DFB\u52A0\u540E\u7ACB\u5373\u751F\u6548\uFF1B\u65AD\u7EBF\u81EA\u52A8\u91CD\u8FDE\uFF1B\u672C\u5730\u7AEF\u53E3\u5EFA\u8BAE 1024 \u4EE5\u4E0A\uFF1B\u8FDC\u7A0B\u4E3B\u673A\u7531 SSH \u670D\u52A1\u5668\u4FA7\u8BBF\u95EE\uFF08127.0.0.1 = \u670D\u52A1\u5668\u81EA\u8EAB\uFF09":`\u6B63\u5728\u7F16\u8F91\u300C${pe}\u300D\u2014\u2014\u6539\u7AEF\u53E3/\u6761\u76EE\u4F1A\u6309\u89C4\u5219\u751F\u6210\u65B0\u540D\u5B57\uFF1B\u4FDD\u5B58\u540E\u7ACB\u5373\u751F\u6548`})]})]})]}),o("div",{className:"tt_cardField",children:[s("span",{className:"tt_cardLabel",children:"SSH \u4E3B\u673A\u5BC6\u94A5\u8BB0\u5F55\uFF08TOFU\uFF09"}),s("button",{type:"button",className:"tt_toolBtn",onClick:()=>{Tc()},children:"\u4ECE known_hosts \u5BFC\u5165"})]}),...Array.isArray(_.hostKeys)&&_.hostKeys.length>0?[s("div",{className:"tt_hostList",children:_.hostKeys.map((I,V)=>o("div",{className:"tt_sshHostRow",children:[s("div",{className:"tt_sshHostMeta",children:[s("span",{className:"tt_sshHostName",children:String(I?.host??"")+":"+String(I?.port??22)}),s("span",{className:"tt_sshHostTarget",children:Vn(I).map(G=>"sha256:"+G).join(" / ")})]}),s("button",{type:"button",className:"tt_toolBtn",onClick:()=>{Mc(I)},children:"\u5220\u9664"})]},String(I?.host??"")+":"+String(I?.port??22)+"#"+String(V)))})]:[s("span",{className:"tt_cardHint",children:"\u6682\u65E0\u8BB0\u5F55 \u2014 \u9996\u6B21 SSH \u8FDE\u63A5\u6210\u529F\u540E\u81EA\u52A8\u8BB0\u5F55\u4E3B\u673A\u6307\u7EB9"})],s("span",{className:"tt_cardHint",children:"\u4E00\u673A\u591A\u628A\u94A5\u5319\uFF08\u5982 rsa + ed25519\uFF09\u5404\u8BB0\u4E00\u6761\u6307\u7EB9\uFF0C\u4EFB\u4E00\u5339\u914D\u5373\u653E\u884C\uFF1B\u6307\u7EB9\u53D8\u66F4\u65F6\u8FDE\u63A5\u4F1A\u88AB\u62D2\u7EDD\uFF08\u9632\u4E2D\u95F4\u4EBA\uFF09\uFF0C\u786E\u8BA4\u5B89\u5168\u540E\u5220\u9664\u5BF9\u5E94\u8BB0\u5F55\u5373\u53EF\u91CD\u8FDE"})]}),o("div",{className:"tt_cardField tt_cardRow",children:[s("button",{className:"tt_cardSave",disabled:u,onClick:()=>{Ac()},children:u?"\u4FDD\u5B58\u4E2D\u2026":"\u4FDD\u5B58"}),s("span",{className:"tt_cardMessage"+(y.kind==="ok"?" tt_cardMessageOk":y.kind==="error"?" tt_cardMessageError":""),children:y.text})]})]})]}):null]})}t.inject=["slots","sessions"];let a=["@hyzyn/dsh-tty#tty","@hyzyn/dsh-all#tty"];return t.apply=f=>{$l=f.sessions,f.inject(["remote","remote.credentials"],l=>(_t=l.remote?.credentials??l["remote.credentials"]??null,()=>{_t=null}));let c=!1,p=()=>{};rs={set(l){if(l!==c){if(c=l,l){p=x_();return}p(),p=()=>{},ii(),Kt()}}},rc(!0),jn();for(let l of a)f.slots.inject("plugins.row.config",()=>f.slots.register({name:"plugins.row.config",key:l},n));f.slots.inject("settings.kit.item",()=>f.slots.register({name:"settings.kit.item",id:"tty",order:80,label:()=>"\u7EC8\u7AEF\u9762\u677F"},n)),f.slots.inject("settings.plugin.item",()=>f.slots.register({name:"settings.plugin.item",key:"tty",order:100},n));let g=f.provide("ttyConnbar",{version:1,addAction:cs,requestRender(){Kt()}}),S=f.provide("ttyTerminal",{version:3,open(l){if(!Vt)return;let d=Vl(l),h=Gl(l,d),u=typeof l?.label=="string"&&l.label!==""?l.label:void 0;if(si(),l?.reuse!==!1){let v=Of(h);if(v!==null)return Bn(),Wt(v.sid),v}return Bn(),ei(h,u)},mount(l,d){return Vt?Uf(l,d):()=>{}}}),_=f.provide("ttyPanel",{version:2,isOpen(){return se!==null&&!Ae},mountPane(l){return Jl(l)},minimize(){return ns(),se!==null&&Ae}});return()=>{rs=null,Vt=!1,p(),_(),S(),g(),ii()}},t}});})();
2712
+ `+el,document.head.appendChild(Fi))}var as='<svg viewBox="0 0 16 16" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3 5l3.5 3L3 11"/><path d="M8.5 11H13"/></svg>',lf='<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" aria-hidden="true"><circle cx="7" cy="7" r="4.4"/><path d="M10.4 10.4L14 14"/></svg>',cf='<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2.5 4.5h11"/><path d="M6 4.5V3a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v1.5"/><path d="M4.5 4.5l.7 8.1a1 1 0 0 0 1 .9h3.6a1 1 0 0 0 1-.9l.7-8.1"/></svg>',hf='<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="5.5" y="5.5" width="8" height="8" rx="1.4"/><path d="M3.5 10.5h-1v-8h8v1"/></svg>',df='<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="3.5" y="3" width="9" height="11" rx="1.4"/><rect x="5.5" y="1.5" width="5" height="3" rx="1" fill="var(--dsw-alias-bg-base,#fff)"/></svg>',uf='<svg viewBox="0 0 16 16" width="13" height="13" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M13.5 8a5.5 5.5 0 1 1-1.6-3.9"/><path d="M13.7 1.8v2.7H11"/></svg>',ff='<svg viewBox="0 0 16 16" width="13" height="13" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M1.8 12.8V4.2a1 1 0 0 1 1-1h3l1.4 1.6h6a1 1 0 0 1 1 1v7a1 1 0 0 1-1 1H2.8a1 1 0 0 1-1-1z"/></svg>',Dl='<svg viewBox="0 0 16 16" width="13" height="13" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4.5 5.5L2 8l2.5 2.5"/><path d="M11.5 5.5L14 8l-2.5 2.5"/><path d="M2.8 8h10.4"/></svg>',_f='<svg viewBox="0 0 16 16" width="13" height="13" fill="currentColor" stroke="none" aria-hidden="true"><circle cx="3.4" cy="8" r="1.35"/><circle cx="8" cy="8" r="1.35"/><circle cx="12.6" cy="8" r="1.35"/></svg>',pf='<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" aria-hidden="true"><path d="M4 8h8"/></svg>',ls='<svg viewBox="0 0 16 16" width="13" height="13" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" aria-hidden="true"><path d="M4.5 4.5l7 7"/><path d="M11.5 4.5l-7 7"/></svg>',gf='<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" aria-hidden="true"><path d="M8 3.6v8.8"/><path d="M3.6 8h8.8"/></svg>',Jr='<svg viewBox="0 0 16 16" width="15" height="15" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2 12.4V3.9a.9.9 0 0 1 .9-.9h2.9l1.4 1.6h5.9a.9.9 0 0 1 .9.9v6.9a.9.9 0 0 1-.9.9H2.9a.9.9 0 0 1-.9-.9z"/></svg>',Bl='<svg viewBox="0 0 16 16" width="15" height="15" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4 2.6h4.4l3.6 3.6v7.2a.9.9 0 0 1-.9.9H4.9a.9.9 0 0 1-.9-.9V3.5a.9.9 0 0 1 .9-.9z"/><path d="M8.2 2.7v3.4h3.4"/></svg>',Pl='<svg viewBox="0 0 16 16" width="15" height="15" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M6.4 9.6l3.2-3.2"/><path d="M9.2 4.6l1-1a2.5 2.5 0 0 1 3.5 3.5l-1 1"/><path d="M6.8 11.4l-1 1a2.5 2.5 0 0 1-3.5-3.5l1-1"/></svg>',On='<svg viewBox="0 0 16 16" width="15" height="15" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M8 12.6V4.2"/><path d="M4.4 7.8L8 4.2l3.6 3.6"/></svg>',Ol='<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M8 3v7.2"/><path d="M5 7.4L8 10.4l3-3"/><path d="M3.4 12.8h9.2"/></svg>',vf='<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M8 10.4V3.2"/><path d="M5 6.2L8 3.2l3 3"/><path d="M3.4 12.8h9.2"/></svg>',In='<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M11.2 2.9l1.9 1.9-7.3 7.3-2.4.5.5-2.4z"/></svg>',_r='<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3 4.6h10"/><path d="M6.2 4.6V3.4a.8.8 0 0 1 .8-.8h2a.8.8 0 0 1 .8.8v1.2"/><path d="M4.6 4.6l.6 8a.9.9 0 0 0 .9.8h3.8a.9.9 0 0 0 .9-.8l.6-8"/></svg>',Nn='<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M13.2 8a5.2 5.2 0 1 1-1.5-3.7"/><path d="M13.4 2.2v2.6h-2.6"/></svg>',Il='<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2 12.4V3.9a.9.9 0 0 1 .9-.9h2.9l1.4 1.6h5.9a.9.9 0 0 1 .9.9v6.9a.9.9 0 0 1-.9.9H2.9a.9.9 0 0 1-.9-.9z"/><path d="M8 6.6v3.6"/><path d="M6.2 8.4h3.6"/></svg>',Nl='<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3.4 8h9"/><path d="M9.2 4.8L12.4 8l-3.2 3.2"/></svg>',Hl='<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12.6 8h-9"/><path d="M6.8 4.8L3.6 8l3.2 3.2"/></svg>',mf='<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M8 3.4v9"/><path d="M4.8 9.2L8 12.4l3.2-3.2"/></svg>',bf='<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="2.4" y="3.2" width="11.2" height="4" rx="1.2"/><rect x="2.4" y="8.8" width="11.2" height="4" rx="1.2"/><path d="M5 5.2h.01"/><path d="M5 10.8h.01"/></svg>',wf='<svg viewBox="0 0 16 16" width="15" height="15" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M8 2.6l5.8 10.4H2.2z"/><path d="M8 6.4v3.2"/><path d="M8 11.6h.01"/></svg>',Sf='<svg viewBox="0 0 16 16" width="15" height="15" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" aria-hidden="true"><circle cx="8" cy="8" r="5.6"/><path d="M8 7.2v3.6"/><path d="M8 5.1h.01"/></svg>',Fl='<svg viewBox="0 0 16 16" width="15" height="15" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="8" cy="8" r="5.6"/><path d="M6 6l4 4"/><path d="M10 6l-4 4"/></svg>',yf='<svg viewBox="0 0 16 16" width="15" height="15" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M8 2.8v5"/><path d="M11.6 4.6a5.2 5.2 0 1 1-7.2 0"/></svg>',Wl='<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="5.6" cy="6" r="2.8"/><path d="M7.8 7.9l5.4 5.4"/><path d="M10.6 10.7l1.2-1.2"/></svg>',$l=null,_e=null,se=null,Vi=null,Zr=null,_t=null,jt=null,Gt=null,ut=null,zr=null,Ur=null,Gi=null,Ye=null,jr=null,ze=null,Xe=null,Ne=null,pr=null,Qr=!1,qr=null,Ae=!1,Pe=null,Yi=null,wr=null,Yt=null,Xi=null,qt=null,Kr=1e3,Ji="dsh-tty:tabs",ne=new Map,ni=new Set,Hn=()=>ni.size>0,Sn=new Set,me=null,oi=0,Wi=!1,Je=null,gr=null,Lt=[],Zi=!0,rt=null,it=null,Vr=null,$r=null,yn=null,Cn=new Set;function cs(e){return Cn.add(e),()=>Cn.delete(e)}cs(({tab:e,addAction:t})=>{Vt&&e.exited&&t(uf,"\u91CD\u65B0\u6253\u5F00","\u4EE5\u539F\u8FDE\u63A5\u4FE1\u606F\u91CD\u5F00\u4F1A\u8BDD",()=>es(e.sid))});cs(({tab:e,addAction:t})=>{Vt&&t(ff,"SFTP","\u6253\u5F00\u8BE5\u8FDE\u63A5\u7684\u6587\u4EF6\u6D4F\u89C8\uFF08SFTP\uFF09",()=>us(e.spawnSpec,e.sid))});cs(({bookName:e,addAction:t})=>{if(!Vt)return;let r=e!==""?sc(e):0;if(r>0){t(Dl,"\u96A7\u9053 "+r,"\u67E5\u770B\u8BE5\u8FDE\u63A5\u7684\u7AEF\u53E3\u8F6C\u53D1\u96A7\u9053",s=>Ql(s.currentTarget,e));return}e!==""&&t(_f,"\u66F4\u591A","\u66F4\u591A\u64CD\u4F5C\uFF08\u7AEF\u53E3\u8F6C\u53D1\u2026\uFF09",s=>Jf(s.currentTarget,e))});function ai(e,t){if(jt===null)return;jt.textContent=e.split("\u2014\u2014")[0],jt.title=e,Gt.dataset.state=t,Vi!==null&&(Vi.style.display=t==="connected"?"none":""),wr!==null&&(wr.textContent=e),Yt!==null&&(Yt.dataset.state=t);let r=document.querySelector("[data-dsh-tty-entry] .tt_sidebarBadgeDot");r!==null&&(r.dataset.state=t)}function vn(e,t,r){let s=typeof e=="string"&&e!==""?e:null;if(s!==null){let o=ne.get(s);o!==void 0&&(o.statusText=t,o.statusState=r)}cl(s,me)&&(Zr=s,ai(t,r))}function $i(e,t){Zr=null,ai(e,t)}function Fn(){if(!hl(Zr,me))return;let e=me===null?void 0:ne.get(me);Zr=e===void 0?null:me;let t=ll(e);ai(t.text,t.state)}function be(e){_e!==null&&_e.readyState===WebSocket.OPEN&&_e.send(JSON.stringify(e))}function Cf(){let e=[],t=document.createDocumentFragment();for(let r of gn){let s=document.createElement("span");s.className="tt_statsItem";let o=document.createElement("span");o.className="tt_statsLabel",o.textContent=r.label,s.appendChild(o);let i=null,n=null;r.kind==="pct"&&(i=document.createElement("span"),i.className="tt_statsMeter",n=document.createElement("span"),n.className="tt_statsMeterFill",i.appendChild(n),s.appendChild(i));let a=document.createElement("span");a.className="tt_statsValue",s.appendChild(a),t.appendChild(s),e.push({item:s,value:a,meter:i,fill:n,slot:null})}return rt!==null&&rt.appendChild(t),e}function xf(e,t){let r=vl(t!==void 0?t.stats:null);for(let s=0;s<e.length;s+=1){let o=e[s],i=r[s];if(i!==void 0&&(o.slot!==i.slot&&(o.slot=i.slot,o.value.style.minWidth=i.slot>0?i.slot+"ch":""),o.value.textContent!==i.value&&(o.value.textContent=i.value),o.item.getAttribute("title")!==i.title&&o.item.setAttribute("title",i.title),o.fill!==null&&o.meter!==null)){let n=i.pct===null?"0%":Math.max(0,Math.min(100,i.pct)).toFixed(1)+"%";o.fill.style.width!==n&&(o.fill.style.width=n);let a=ul(i.pct);o.meter.dataset.level!==a&&(o.meter.dataset.level=a)}}}function hs(){$r=null,yn=null}function kf(){if(se===null||Ae||!Zi)return!1;let e=Ze();return e===void 0||e.embedded===!0||e.exited===!0||e.stats===null||e.stats===void 0?!1:pl(e.statsAt)}function ml(){if(Ae)return;let e=Ze();if(!(e===void 0||e.embedded===!0||e.fit===null)){try{e.fit.fit()}catch{return}try{e.spawned&&!e.exited&&Cr(e)}catch{}}}function Xt(){try{Ef()}catch(e){console.warn("[dsh-tty] \u72B6\u6001\u6761\u6E32\u67D3\u5931\u8D25\uFF08\u5DF2\u6536\u8D77\uFF09: "+(e instanceof Error?e.message:String(e)));try{rt!==null&&(rt.hidden=!0,rt.textContent=""),hs(),ze!==null&&delete ze.dataset.stats}catch{}}}function Ef(){if(ze===null||rt===null)return;let e=kf(),t=ze.dataset.stats!==void 0!==e;if(!e){t&&delete ze.dataset.stats,rt.hidden=!0,$r!==null&&(rt.textContent="",hs()),t&&ml();return}rt.hidden=!1,$r===null&&($r=Cf());let r=Ze(),s=r===void 0?"":r.sid+":"+String(r.statsAt||0);s!==yn&&(yn=s,xf($r,r)),t&&(ze.dataset.stats="",ml())}function zl(){Vr===null&&(Vr=setInterval(()=>Xt(),1e3))}function Ul(){Vr!==null&&(clearInterval(Vr),Vr=null)}function jl(){if(se===null||Ae||!Zi)return null;let e=Ze();return e===void 0||e.embedded===!0||e.exited===!0?null:e.sid}function li(){let e=jl();e!==it&&(it!==null&&be({t:"statsOff",sid:it}),it=e,e!==null&&be({t:"statsOn",sid:e}))}function Lf(e){if(e!==jl()){li();return}it!==null&&it!==e&&be({t:"statsOff",sid:it}),it=e,be({t:"statsOn",sid:e})}function Ze(){return me!==null?ne.get(me):void 0}function xn(){try{return al($l?.list?.getSnapshot?.())}catch{return}}function Mf(e){if(!(e.term===null||e.exited)){try{if(e.term.buffer.active.length<=e.term.rows)return}catch{return}e.term.reset(),be({t:"refresh",sid:e.sid})}}var zi=null;function ql(e){zi!==null&&clearTimeout(zi),zi=setTimeout(()=>{zi=null;let t=Ze();t!==void 0&&Mf(t)},e??200)}var Rf=["password","passphrase"];function bl(e){if(e===null||typeof e!="object"||e.t!=="ssh")return e;let t=e.credsStripped===!0,r={...e};for(let s of Rf){let o=r[s];typeof o=="string"&&o!==""&&!o.startsWith("env:")&&(delete r[s],t=!0)}return t&&(r.credsStripped=!0),r}var Kl=1;function Ft(){try{let e=[...ne.values()].filter(t=>!t.exited&&t.embedded!==!0).map(t=>({sid:t.sid,spawnSpec:bl(t.spawnSpec),label:t.label}));e.length===0||se===null?sessionStorage.removeItem(Ji):sessionStorage.setItem(Ji,JSON.stringify({v:Kl,tabs:e})),Tf([...ne.values()].filter(t=>t.embedded!==!0).map(t=>({spawnSpec:bl(t.spawnSpec),label:t.label})))}catch(e){console.warn("[dsh-tty] \u6807\u7B7E\u6301\u4E45\u5316\u5931\u8D25\uFF08\u672C\u6B21\u5237\u65B0\u540E\u6807\u7B7E\u5217\u8868\u53EF\u80FD\u4E22\u5931\uFF09: "+(e instanceof Error?e.message:String(e)))}}var kn="dsh-tty:persist-specs";function Tf(e){try{let t=e.filter(r=>ci(r.spawnSpec)).map(r=>({spawnSpec:r.spawnSpec,label:r.label}));t.length===0?localStorage.removeItem(kn):localStorage.setItem(kn,JSON.stringify(t))}catch{}}function Af(){try{let e=localStorage.getItem(kn);if(e===null)return[];let t=JSON.parse(e);return Array.isArray(t)?t.filter(r=>r!==null&&typeof r=="object"&&ci(r.spawnSpec)):[]}catch{return[]}}function Df(){try{let e=sessionStorage.getItem(Ji);if(e===null)return[];let t=JSON.parse(e);return Array.isArray(t)?t.filter(r=>r!==null&&typeof r=="object"&&typeof r.sid=="string"&&r.sid!==""&&r.spawnSpec!==null&&typeof r.spawnSpec=="object"):t!==null&&typeof t=="object"&&t.v===Kl&&Array.isArray(t.tabs)?t.tabs.filter(r=>r!==null&&typeof r=="object"&&typeof r.sid=="string"&&r.sid!==""&&r.spawnSpec!==null&&typeof r.spawnSpec=="object"):[]}catch{return[]}}function Qi(e,t){let r=_e;return new Promise(s=>{let o=null,i=n=>{let a;try{a=JSON.parse(n.data)}catch{return}a.t===e&&(o!==null&&clearTimeout(o),r.removeEventListener("message",i),s(r===_e?a:null))};o=setTimeout(()=>{r.removeEventListener("message",i),s(null)},t),r.addEventListener("message",i)})}function Cr(e){if(e===void 0||e.fit===void 0)return;let t=e.fit.proposeDimensions();t!==void 0&&be({t:"resize",sid:e.sid,cols:t.cols,rows:t.rows})}function Bf(e){if(e===void 0||e.fit===void 0)return;let t=e.term,r=t!==null&&t.buffer!==void 0?t.buffer.active:null,s=r==null?null:{atBottom:r.viewportY>=r.baseY,line:r.viewportY};try{e.fit.fit()}catch{return}if(s!==null)try{s.atBottom?t.scrollToBottom():t.scrollToLine(Math.min(s.line,t.buffer.active.baseY))}catch{}e.exited||Cr(e)}function hr(e,t,r,s){if(e.overlayEl===null||e.overlayEl===void 0)return;let o=e.overlayEl;if(t===""||t===void 0){o.textContent="";return}let i=s==="error"||s==="info"?s:"exited";o.innerHTML='<div class="tt_overlayCard" data-kind="'+i+'"><span class="tt_overlayIcon">'+(i==="error"?Fl:i==="info"?Nn:yf)+'</span><span class="tt_overlayText"><span class="tt_overlayMain"></span>'+(r===void 0||r===""?"":'<span class="tt_overlayHint"></span>')+"</span></div>",o.querySelector(".tt_overlayMain").textContent=t,r!==void 0&&r!==""&&(o.querySelector(".tt_overlayHint").textContent=r)}function Pf(e,t){try{let r=getComputedStyle(document.documentElement).getPropertyValue(e).trim();return r!==""?r:t}catch{return t}}function xr(e){let t=Pf("--dsw-alias-state-business-primary","#7c9cff"),r=new El.Terminal({cursorBlink:!0,cursorStyle:"bar",cursorInactiveStyle:"outline",fontSize:13,fontFamily:'"JetBrains Mono", "SF Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace',fontWeight:400,fontWeightBold:600,lineHeight:1.35,scrollback:5e3,convertEol:!1,allowProposedApi:!0,theme:{background:"#0b0e14",foreground:"#d7dce5",cursor:t,cursorAccent:"#0b0e14",selectionBackground:"rgba(124, 156, 255, .30)",black:"#1b2028",red:"#f07178",green:"#7ec699",yellow:"#e6b673",blue:"#7aa2f7",magenta:"#c792ea",cyan:"#7fdbca",white:"#c8d0dc",brightBlack:"#556070",brightRed:"#ff8b92",brightGreen:"#9fe0b4",brightYellow:"#f5cc8c",brightBlue:"#9ab8ff",brightMagenta:"#dbb3ff",brightCyan:"#a3f0e2",brightWhite:"#eef2f8"}}),s=new Ll.FitAddon,o=new To;r.loadAddon(s),r.loadAddon(o),r.loadAddon(new Ao);let i=document.createElement("div");i.className="tt_term";let n=document.createElement("div");n.className="tt_overlay",n.addEventListener("click",()=>{n.textContent="",es(e.sid)}),n.setAttribute("role","button"),n.setAttribute("aria-label","\u91CD\u65B0\u6253\u5F00\u4F1A\u8BDD"),n.tabIndex=0,n.addEventListener("keydown",a=>{(a.key==="Enter"||a.key===" "||a.key==="Spacebar")&&(a.preventDefault(),n.textContent="",es(e.sid))}),i.appendChild(n),r.open(i);try{s.fit()}catch{}try{let a=new Qa;a.onContextLoss(()=>{try{a.dispose()}catch{}}),r.loadAddon(a)}catch{}r.onData(a=>{be({t:"input",sid:e.sid,d:a})}),r.onResize(()=>{ci(e.spawnSpec)&&ql(200)}),r.attachCustomKeyEventHandler(a=>e.embedded===!0?!0:(a.ctrlKey||a.metaKey)&&a.key.toLowerCase()==="f"?(a.preventDefault(),_c(),!1):!0),e.term=r,e.fit=s,e.search=o,e.termEl=i,e.overlayEl=n}function wl(e){return e===null||typeof e!="object"?"":["t","name","host","port","username","command","cwd","persist","persistName"].map(r=>r+"="+String(e[r]??"")).join("\0")}function Of(e){let t=wl(e);if(t==="")return null;for(let r of ne.values())if(r.exited!==!0&&r.embedded!==!0&&wl(r.spawnSpec)===t)return r;return null}function ei(e,t){let r=os(),s={sid:r,term:null,fit:null,search:null,termEl:null,overlayEl:null,exited:!1,spawned:!1,spawnSpec:e??u_(),label:t};return xr(s),ne.set(r,s),oi+=1,Ue(),Wt(r),ds(s),Ft(),s}function If(e){if(Array.isArray(e))for(let t of e){if(t===null||typeof t!="object"||t.owner!=="agent")continue;let r=typeof t.sid=="string"?t.sid:"";if(r===""||ne.has(r))continue;let s={sid:r,term:null,fit:null,search:null,termEl:null,overlayEl:null,exited:!1,spawned:!1,agentOwned:!0,spawnSpec:{t:"spawn",cwd:typeof t.cwd=="string"?t.cwd:xn()},label:"agent"+(t.kind==="ssh"&&typeof t.target=="string"&&t.target!==""?" \xB7 "+t.target:"")};xr(s),ne.set(r,s),oi+=1,Ue(),Nf()&&s.termEl!==null&&ze!==null&&me===null&&Wt(r),be({t:"attach",sid:r}),Hf()}}function Nf(){return se!==null&&Ae!==!0}function Hf(){try{Ft()}catch{}}function Ff(e){if(If(e),!Array.isArray(e))return;let t=new Set(e.filter(r=>r!==null&&typeof r=="object"&&r.owner==="agent").map(r=>r.sid));for(let[r,s]of[...ne])s.agentOwned===!0&&(t.has(r)||s.exited!==!0&&s.live===!0&&(s.exited=!0,s.live=!1,Ue()))}function Wf(e){if(ne.has(e.sid))return ne.get(e.sid);let t={sid:e.sid,term:null,fit:null,search:null,termEl:null,overlayEl:null,exited:!1,spawned:!1,spawnSpec:e.spawnSpec,label:typeof e.label=="string"?e.label:void 0};xr(t),ne.set(t.sid,t),oi+=1,Ue(),Wt(t.sid),be({t:"attach",sid:t.sid})}function $f(e){if(!(e?.spawnSpec?.credsStripped!==!0||e.term===null))try{e.term.writeln("\x1B[2m[dsh-tty] \u51FA\u4E8E\u5B89\u5168\u8003\u8651\uFF0C\u660E\u6587\u5BC6\u7801/\u53E3\u4EE4\u4E0D\u968F\u6D4F\u89C8\u5668\u5B58\u50A8\u4FDD\u7559\uFF0C\u672C\u6B21\u8FDE\u63A5\u9700\u8981\u91CD\u65B0\u8F93\u5165\uFF1A\u91CD\u5F00\u6807\u7B7E\u65F6\u518D\u586B\u4E00\u6B21\uFF0C\u6216\u5728\u8BBE\u7F6E\u5361\u7247\u628A\u51ED\u636E\u6362\u6210 env: \u5F15\u7528\uFF08\u503C\u5B58\u5BBF\u4E3B\u51ED\u636E\u5B58\u50A8\uFF09\u3002\x1B[0m")}catch{}}function ds(e){$f(e);let t=e.fit!==null?e.fit.proposeDimensions():void 0,r={...e.spawnSpec,sid:e.sid,cols:t!==void 0?t.cols:80,rows:t!==void 0?t.rows:24};if(_e===null||_e.readyState!==WebSocket.OPEN){Sn.add({tab:e,frame:r});return}be(r)}function Sl(e){let t={sid:os(),term:null,fit:null,search:null,termEl:null,overlayEl:null,exited:!1,spawned:!1,spawnSpec:e.spawnSpec,label:typeof e.label=="string"?e.label:void 0};xr(t),ne.set(t.sid,t),oi+=1,Ue(),Wt(t.sid),ds(t)}function es(e){let t=ne.get(e);if(t===void 0)return;if(t.embedded===!0){Xl(t);return}let r=t.spawnSpec,s=t.label;if(t.exited||be({t:"kill",sid:e}),t.term!==null)try{t.term.dispose()}catch{}t.termEl!==null&&t.termEl.remove(),ne.delete(e);let o={sid:os(),term:null,fit:null,search:null,termEl:null,overlayEl:null,exited:!1,spawned:!1,spawnSpec:r,label:s};xr(o),ne.set(o.sid,o),Ue(),Wt(o.sid),ds(o),Ft()}function yl(e){let t=ne.get(e);if(t!==void 0){if(st!==null&&st.ownerKey===e&&Yr(!0),t.exited||be({t:"kill",sid:e}),ne.delete(e),ni.delete(e),t.term!==null)try{t.term.dispose()}catch{}if(t.termEl!==null&&t.termEl.remove(),me===e){me=null;let r=[...ne.entries()].filter(([,s])=>s.embedded!==!0).map(([s])=>s).pop()??null;r!==null&&Wt(r)}Ue(),Fn(),[...ne.values()].some(r=>r.embedded!==!0)?Ft():ii()}}function Vl(e){let t=typeof e?.command=="string"?e.command.trim():"";if(t==="")throw new Error("ttyTerminal \u9700\u8981 command");if(/[\r\n\0]/.test(t))throw new Error("command \u5FC5\u987B\u662F\u5355\u884C");return t}function Gl(e,t){return typeof e?.book=="string"&&e.book!==""?{t:"ssh",name:e.book,command:t}:e?.spec!==null&&typeof e?.spec=="object"?{t:"ssh",...e.spec,command:t}:{t:"spawn",...typeof e?.cwd=="string"&&e.cwd!==""?{cwd:e.cwd}:{},command:t}}function zf(e){let t=e.controller;t===void 0||t.observer!==null||(t.observer=new ResizeObserver(()=>{if(!(t.disposed||t.tab!==e||e.term===null)){try{e.fit.fit()}catch{return}e.spawned&&!e.exited&&Cr(e)}}),t.observer.observe(t.hostEl))}function Yl(e,t,r){let s={sid:os(),term:null,fit:null,search:null,termEl:null,overlayEl:null,exited:!1,spawned:!1,embedded:!0,controller:e,spawnSpec:t,label:r};return xr(s),ne.set(s.sid,s),ni.add(s.sid),e.hostEl.appendChild(s.termEl),zf(s),ds(s),s}function Xl(e){let t=e.controller;if(!(t===void 0||t.disposed)){e.exited||be({t:"kill",sid:e.sid});try{e.term?.dispose()}catch{}return e.termEl?.remove(),ne.delete(e.sid),ni.delete(e.sid),t.observer!==null&&(t.observer.disconnect(),t.observer=null),t.tab=Yl(t,e.spawnSpec,e.label),me===e.sid&&(me=t.tab.sid,Fn()),t.tab}}function Uf(e,t){if(!(e instanceof HTMLElement))throw new Error("ttyTerminal.mount \u9700\u8981 HTMLElement \u4F5C\u4E3A\u6302\u8F7D\u70B9");let r=Vl(t),s=Gl(t,r),o=typeof t?.label=="string"&&t.label!==""?t.label:void 0;si();let i={hostEl:e,tab:null,observer:null,disposed:!1};return i.tab=Yl(i,s,o),__(),()=>jf(i)}function jf(e){if(e.disposed)return;e.disposed=!0,e.observer!==null&&(e.observer.disconnect(),e.observer=null);let t=e.tab;if(t!==null){t.exited||be({t:"kill",sid:t.sid});try{t.term?.dispose()}catch{}t.termEl?.remove(),ne.delete(t.sid),ni.delete(t.sid),e.tab=null}if(se===null&&!Hn()&&_e!==null){Qr=!0;try{_e.close()}catch{}_e=null}}var qf=460,Kf=280,Vf=320,Gf=160,st=null,dr=qf,ur=Vf;function Wn(){let e=se!==null?se.querySelector(".tt_modal"):null,t=e!==null?e:se;return t!==null?t.getBoundingClientRect():null}var $n=e=>e==="bottom"?Gf:Kf;function Yf(e){let t=Wn();if(t===null)return 900;let r=e==="bottom"?t.height:t.width;return Math.max($n(e),Math.round(r*.72))}function Gr(e,t){return Math.min(Yf(e),Math.max($n(e),Math.round(t)))}function Ui(){let e=st;if(e!==null){if(e.collapsed){e.el.style.width="",e.el.style.height="",e.el.style.flexBasis="";return}if(e.side==="bottom"){ur=Gr("bottom",ur),e.el.style.width="",e.el.style.height=String(ur)+"px",e.el.style.flexBasis=String(ur)+"px";return}dr=Gr("right",dr),e.el.style.height="",e.el.style.width=String(dr)+"px",e.el.style.flexBasis=String(dr)+"px"}}function Yr(e){let t=st;if(t!==null){if(st=null,t.disposed=!0,e&&t.onClose!==null)try{t.onClose()}catch(r){console.warn("[dsh-tty] ttyPanel.onClose \u629B\u9519\uFF1A"+(r instanceof Error?r.message:String(r)))}try{t.el.remove()}catch{}Xe!==null&&delete Xe.dataset.side}}function Jl(e){if(Bn(),Xe===null)throw new Error("ttyPanel.mountPane\uFF1A\u7EC8\u7AEF\u9762\u677F\u672A\u5C31\u7EEA");st!==null&&Yr(!0),si();let t=cr(e?.ownerSid,me),r=e?.side==="bottom"?"bottom":"right",s=Math.max(r==="bottom"?120:200,Math.round(typeof e?.min=="number"&&Number.isFinite(e.min)?e.min:$n(r)));if(typeof e?.size=="number"&&Number.isFinite(e.size)){let l=Gr(r,e.size);r==="bottom"?ur=l:dr=l}let o=document.createElement("div");o.className="tt_dockPane",o.dataset.side=r,Xe.dataset.side=r,o.innerHTML='<div class="tt_dockPaneResize" title="'+(r==="bottom"?"\u62D6\u52A8\u8C03\u6574\u9AD8\u5EA6":"\u62D6\u52A8\u8C03\u6574\u5BBD\u5EA6")+'"></div><div class="tt_dockPaneHead"><span class="tt_dockPaneTitle"></span><span class="tt_dockPaneHint"></span><span class="tt_dockPaneSpacer"></span><button class="tt_dockPaneFold" type="button"></button><button class="tt_dockPaneClose" type="button" title="\u5173\u95ED\u4FA7\u680F">'+ls+'</button></div><div class="tt_dockPaneBody"></div>',Xe.appendChild(o);let i=o.querySelector(".tt_dockPaneTitle"),n=o.querySelector(".tt_dockPaneHint"),a=o.querySelector(".tt_dockPaneBody"),f=o.querySelector(".tt_dockPaneFold"),c=o.querySelector(".tt_dockPaneClose"),p=o.querySelector(".tt_dockPaneResize"),g={el:o,element:a,disposed:!1,collapsed:!1,side:r,minSize:s,ownerKey:t,onClose:typeof e?.onClose=="function"?e.onClose:null},S=()=>r==="bottom"?g.collapsed?On:mf:g.collapsed?Hl:Nl,_=l=>{g.collapsed=l===!0,g.collapsed?o.dataset.collapsed="1":delete o.dataset.collapsed,f.innerHTML=S(),f.title=g.collapsed?"\u5C55\u5F00\u4FA7\u680F":"\u6536\u8D77\u4FA7\u680F",f.setAttribute("aria-label",f.title),Ui()};return g.setTitle=l=>{i.textContent=typeof l=="string"?l:""},g.setHint=l=>{n.textContent=typeof l=="string"?l:""},g.isCollapsed=()=>g.collapsed===!0,g.collapse=()=>_(!0),g.expand=()=>_(!1),g.toggle=()=>_(!g.collapsed),g.dispose=()=>{g.disposed||st!==g||Yr(!1)},p.addEventListener("mousedown",l=>{if(l.button!==0||g.collapsed)return;l.preventDefault();let d=l.clientX,h=l.clientY,u=o.getBoundingClientRect(),v=b=>{r==="bottom"?ur=Gr("bottom",Math.max(s,u.height+(h-b.clientY))):dr=Gr("right",Math.max(s,u.width+(d-b.clientX))),Ui()},y=()=>{document.removeEventListener("mousemove",v),document.removeEventListener("mouseup",y),document.body.style.userSelect=""};document.body.style.userSelect="none",document.addEventListener("mousemove",v),document.addEventListener("mouseup",y)}),p.addEventListener("dblclick",()=>_(!g.collapsed)),f.addEventListener("click",()=>_(!g.collapsed)),c.addEventListener("click",()=>Yr(!0)),g.setTitle(typeof e?.title=="string"?e.title:""),g.setHint(typeof e?.hint=="string"?e.hint:""),_(e?.collapsed===!0),st=g,Ui(),Zl(),g}function Zl(){let e=st;if(e!==null){if(_n(e.ownerKey,me)){delete e.el.dataset.dockHidden,Xe!==null&&(Xe.dataset.side=e.side);return}e.el.dataset.dockHidden="1",Xe!==null&&delete Xe.dataset.side}}function Wt(e){let t=ne.get(e);if(t!==void 0&&t.embedded!==!0){me=e;for(let[r,s]of ne)s.embedded!==!0&&s.termEl!==null&&(s.termEl.style.display=r===e?"":"none");t.embedded!==!0&&ze!==null&&t.termEl!==null&&t.termEl.parentElement!==ze&&ze.appendChild(t.termEl),li(),Xt(),Ue(),Kt(),Zl();try{t.fit.fit()}catch{}t.spawned&&!t.exited&&Cr(t),hr(t,t.exited?"\u4F1A\u8BDD\u5DF2\u9000\u51FA":"",t.exited?"\u70B9\u51FB\u91CD\u65B0\u6253\u5F00":"","exited"),Fn()}}function mn(e){if(ut===null)return;let t=ne.get(e);if(t===void 0)return;let s=ut.querySelector(`[data-sid="${e}"]`)?.querySelector(".tt_tabDot");s!=null&&(s.dataset.state=t.exited?"exited":t.live===!0?"connected":t.errored===!0?"error":"connecting")}var bn=!1;function Ue(){if(ut===null)return;if(ut.querySelector(".tt_tabRename")!==null){bn||(bn=!0,setTimeout(()=>{bn=!1,Ue()},1e3));return}ut.textContent="";for(let[r,s]of ne){if(s.embedded===!0)continue;let o=document.createElement("button");o.className="tt_tab",o.dataset.sid=r,r===me&&(o.dataset.active="");let i=document.createElement("span");i.className="tt_tabDot",i.dataset.state=s.exited?"exited":s.live===!0?"connected":s.errored===!0?"error":"connecting",o.appendChild(i);let n=document.createElement("span");n.className="tt_tabLabel",n.textContent=s.label||"\u7EC8\u7AEF "+ec(r),n.addEventListener("dblclick",f=>{f.stopPropagation(),Zf(r,o)});let a=document.createElement("span");a.className="tt_tabClose",a.title="\u5173\u95ED",a.textContent="\u2715",a.setAttribute("role","button"),a.setAttribute("aria-label","\u5173\u95ED\u6807\u7B7E\uFF1A"+(s.label||"")),a.tabIndex=0,a.addEventListener("keydown",f=>{(f.key==="Enter"||f.key===" "||f.key==="Spacebar")&&(f.preventDefault(),f.stopPropagation(),yl(r))}),o.title=n.textContent,o.appendChild(n),o.appendChild(a),o.addEventListener("click",f=>{if(f.target.closest(".tt_tabClose")!==null){f.stopPropagation(),yl(r);return}Wt(r)}),ut.appendChild(o)}let e=ut.querySelector("[data-active]");e!==null&&typeof e.scrollIntoView=="function"&&e.scrollIntoView({block:"nearest",inline:"nearest"});let t=document.createElement("button");t.className="tt_tabAdd",t.title="\u65B0\u5EFA\uFF08\u672C\u5730 / SSH\uFF09",t.innerHTML=gf,t.addEventListener("click",()=>{r_(t)}),ut.appendChild(t)}function Xf(e){return e?.direction==="remote"?`\u8FDC\u7A0B:${e.remoteHost||"127.0.0.1"}:${String(e.remotePort??0)} \u2192 \u672C\u673A:${String(e.localTargetPort??0)}`:`\u672C\u673A:${String(e?.localPort??0)} \u2192 ${e?.remoteHost??"?"}:${String(e?.remotePort??0)}`}function Kt(){if(zr===null||Gi===null||jr===null||Ur===null)return;jr.textContent="";let e=Ze(),t=e?.spawnSpec??{};if(e===void 0||t.t!=="ssh"){zr.dataset.hidden="";return}delete zr.dataset.hidden;let r=Number(t.port);Gi.textContent=typeof e.target=="string"&&e.target!==""?e.target:typeof t.name=="string"&&t.name!==""?t.name:String(t.username??"")+"@"+String(t.host??"")+(Number.isInteger(r)&&r!==22?":"+r:""),Ye!==null&&(e.persistTmux===!0?(Ye.textContent="tmux",Ye.dataset.state="ok",Ye.title="\u5DF2\u7531 tmux \u6258\u7BA1 \u2014 \u65AD\u7EBF / \u5BBF\u4E3B\u91CD\u542F\u540E\u6309\u540D\u63A5\u56DE\u73B0\u573A"):t.persist===!0&&e.spawned===!0?(Ye.textContent="\u672A\u6301\u4E45\u5316",Ye.dataset.state="warn",Ye.title="\u8BF7\u6C42\u4E86\u6301\u4E45\u4F1A\u8BDD\uFF0C\u4F46 tmux \u4E0D\u53EF\u7528 \u2014 \u5F53\u524D\u4E3A\u666E\u901A\u4F1A\u8BDD"):(Ye.textContent="",delete Ye.dataset.state,Ye.removeAttribute("title")));let s=e.exited?"exited":e.live===!0?"connected":e.errored===!0?"error":"connecting";Ur.dataset.state=s,Ur.title=s==="connected"?"\u5DF2\u8FDE\u63A5":s==="connecting"?"\u8FDE\u63A5\u4E2D":s==="error"?"\u8FDE\u63A5\u51FA\u9519":"\u4F1A\u8BDD\u5DF2\u9000\u51FA";let o=(n,a,f,c)=>{let p=document.createElement("button");p.type="button",p.className="tt_toolBtn tt_connAct",p.title=f,p.innerHTML=n+"<span></span>",p.lastElementChild.textContent=a,p.addEventListener("click",c),jr.appendChild(p)};if(typeof t.command=="string"&&t.command!=="")return;let i=typeof t.name=="string"?t.name:"";for(let n of Cn)try{n({tab:e,spec:t,bookName:i,addAction:o})}catch(a){console.warn("[dsh-tty] connbar action failed: "+(a instanceof Error?a.message:String(a)))}}function Jf(e,t){if(vr!==null){ji();return}let r=document.createElement("div");r.className="tt_addMenu tt_connMore",vr=r,Rn(r,"\u7AEF\u53E3\u8F6C\u53D1","\u5728 \u8BBE\u7F6E \u2192 \u63D2\u4EF6 \u2192 \u7EC8\u7AEF\u9762\u677F \u91CC\u914D\u7F6E",()=>{ji(),Ql(e,t)},void 0,Dl),document.body.appendChild(r);let s=e.getBoundingClientRect(),o=r.offsetWidth,n=s.left+o>window.innerWidth-8?s.right-o:s.left;r.style.left=Math.max(8,Math.min(n,window.innerWidth-o-8))+"px",r.style.top=s.bottom+6+"px";let a=f=>{vr===r&&(r.contains(f.target)||e.contains(f.target)||ji())};Ki=a,setTimeout(()=>document.addEventListener("mousedown",a,!0),0)}function ji(){Ki!==null&&(document.removeEventListener("mousedown",Ki,!0),Ki=null),vr!==null&&(vr.remove(),vr=null)}var Ut=null,qi=null,vr=null,Ki=null;function ts(){qi!==null&&(document.removeEventListener("mousedown",qi,!0),qi=null),Ut!==null&&(Ut.remove(),Ut=null)}function Ql(e,t){if(Ut!==null){ts();return}let r=document.createElement("div");r.className="tt_tunnelPop";let s=document.createElement("div");s.className="tt_tunnelPopTitle",s.textContent="\u7AEF\u53E3\u8F6C\u53D1 \u2014 "+t,r.appendChild(s);let o=document.createElement("div");o.textContent="\u52A0\u8F7D\u4E2D\u2026",r.appendChild(o);let i=document.createElement("span");i.className="tt_cardHint",i.textContent="\u589E\u5220/\u542F\u505C\u5728 \u63D2\u4EF6\u914D\u7F6E \u2192 \u7EC8\u7AEF\u9762\u677F \u7684\u7AEF\u53E3\u8F6C\u53D1\u533A\u5757\u7EF4\u62A4",r.appendChild(i),document.body.appendChild(r),Ut=r;let n=e.getBoundingClientRect();r.style.top=String(n.bottom+6)+"px",r.style.left=String(Math.max(8,n.right-340))+"px";let a=f=>{Ut===r&&(r.contains(f.target)||e.contains(f.target)||ts())};qi=a,setTimeout(()=>document.addEventListener("mousedown",a,!0),0),(async()=>{let f=[];try{let g=await(await fetch("/api/dsh-tty/tunnels",{cache:"no-store"})).json();g.ok&&Array.isArray(g.tunnels)&&(f=g.tunnels)}catch{}if(Ut!==r)return;o.textContent="";let c=zn.filter(p=>p?.bookName===t&&p?.enabled!==!1);if(c.length===0){let p=document.createElement("span");p.className="tt_cardHint",p.textContent="\u8BE5\u8FDE\u63A5\u6682\u65E0\u542F\u7528\u7684\u96A7\u9053",o.appendChild(p);return}for(let p of c){let g=f.find(h=>h?.name===p?.name),S=g?.state??"stopped",_=document.createElement("div");_.className="tt_tunnelPopRow";let l=document.createElement("span");l.className="tt_connDot",l.dataset.state=S==="active"?"connected":S==="error"?"error":"connecting";let d=document.createElement("span");d.className="tt_connTarget",d.title=String(g?.error??g?.lastForwardError??""),d.textContent=Xf(p)+" \xB7 "+S,_.appendChild(l),_.appendChild(d),o.appendChild(_)}})()}function ec(e){let t=1;for(let r of ne.keys()){if(r===e)return String(t);t+=1}return String(t)}function Zf(e,t){let r=ne.get(e);if(r===void 0||t.querySelector(".tt_tabRename")!==null)return;let s=t.querySelector(".tt_tabLabel");if(s===null)return;let o=document.createElement("input");o.className="tt_tabRename",o.value=r.label||"\u7EC8\u7AEF "+ec(e),s.replaceWith(o),o.focus(),o.select();let i=!1,n=()=>{if(i)return;i=!0;let f=o.value.trim();r.label=f!==""?f:void 0,Ue(),Ft()},a=()=>{i||(i=!0,Ue())};o.addEventListener("keydown",f=>{f.stopPropagation(),f.key==="Enter"?n():f.key==="Escape"&&a()}),o.addEventListener("blur",n),o.addEventListener("click",f=>f.stopPropagation())}var zn=[],tc="dialog",Nt="off",Ht={maxDownloadMb:1024,maxUploadMb:2048,maxUploadFiles:1e3},mr=null,It=null,rs=null,Vt=!1;function rc(e){Vt=e,rs!==null&&rs.set(e)}function Qf(e){rc(!(e!==null&&typeof e=="object"&&e.enabled===!1)),e!==null&&typeof e=="object"&&typeof e.statsEnabled=="boolean"&&e.statsEnabled!==Zi&&(Zi=e.statsEnabled,li(),Xt())}function ti(e){Qf(e),e!==null&&typeof e=="object"&&Array.isArray(e.sshHosts)&&(Lt=e.sshHosts),e!==null&&typeof e=="object"&&Array.isArray(e.tunnels)&&(zn=e.tunnels),e!==null&&typeof e=="object"&&(e.sftpStyle==="dual"||e.sftpStyle==="dialog")&&(tc=e.sftpStyle),e!==null&&typeof e=="object"&&(e.persistence==="tmux"||e.persistence==="off")&&(Nt=e.persistence),e!==null&&typeof e=="object"&&typeof e.sftpLimits=="object"&&e.sftpLimits!==null&&(Ht={...Ht,...e.sftpLimits}),e!==null&&typeof e=="object"&&Number.isInteger(e.maxSessions)&&e.maxSessions>=1&&(mr=e.maxSessions)}function e_(e,t){let r=t==="error"||t==="info"?t:"warn",s=document.createElement("div");s.className="tt_toast",s.dataset.kind=r,s.innerHTML='<span class="tt_toastIcon">'+(r==="error"?Fl:r==="info"?Sf:wf)+'</span><span class="tt_toastText"></span>',s.lastElementChild.textContent=e,document.body.appendChild(s),setTimeout(()=>s.remove(),4e3)}async function ic(){try{be({t:"sessions"});let e=await Qi("sessions",3e3);if(e!==null&&Array.isArray(e.list))return It=e.list.length,It}catch{}return null}async function is(){if(await ic(),mr===null||It===null||It<mr)return null;let e=[...ne.values()].filter(s=>!s.exited).length,t=Math.max(0,It-e),r=`\u4F1A\u8BDD\u6570\u5DF2\u8FBE\u4E0A\u9650\uFF08\u5171 ${It} \u4E2A / \u4E0A\u9650 ${mr}\uFF1A\u672C\u7A97\u53E3 ${e} \u4E2A${t>0?" + \u5176\u4ED6\u7A97\u53E3 "+t+" \u4E2A":""}\uFF09\u2014\u2014\u5173\u95ED\u4E0D\u7528\u7684\u7A97\u53E3/\u6807\u7B7E\uFF0C\u6216\u5728\u8BBE\u7F6E\u5361\u7247\u8C03\u5927\u300C\u5E76\u53D1\u4F1A\u8BDD\u4E0A\u9650\u300D`;return e_(r),r}function t_(){return mr!==null&&It!==null&&It>=mr}function Un(){return Math.random().toString(36).slice(2,10)+Date.now().toString(36).slice(-4)}function sc(e){return zn.filter(t=>t?.bookName===e&&t?.enabled!==!1).length}function En(e){let t=Number(e?.port),r=Number.isInteger(t)&&t!==22?":"+t:"",s=e?.auth==="key"?"key":e?.auth==="password"?"password":"agent",o=e?.agentForward===!0?" \xB7 fwd":"";return String(e?.username??"")+"@"+String(e?.host??"")+r+" \xB7 "+s+o}async function Ln(e,t){let r=await fetch("/api/dsh-tty/probe",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({...e,bookRecord:t===!0})}),s=await r.json().catch(()=>({}));return s&&s.ok===!1&&s.error?{error:String(s.error)}:s&&s.result?{result:s.result}:{error:String(s&&s.error?s.error:"\u8FDE\u63A5\u6D4B\u8BD5\u5931\u8D25\uFF08HTTP "+r.status+"\uFF09")}}function Mn(e,t){if(!e)return"\u8FDE\u63A5\u6D4B\u8BD5\u2026";let r=e,s=typeof r.tcp?.ms=="number"?r.tcp.ms:null,o=typeof r.auth?.ms=="number"?r.auth.ms:null,i=[];r.tcp?.ok&&i.push("TCP "+(s!==null?s+"ms":"\u901A")),r.banner?.ok&&i.push("banner \u6B63\u5E38");let n=r.hostkey?.state;if(n==="matched"?i.push("\u4E3B\u673A\u5BC6\u94A5\u5339\u914D"):n==="recorded"?i.push("\u4E3B\u673A\u5BC6\u94A5\u5DF2\u8BB0\u5F55\uFF08TOFU\uFF09"):n==="mismatch"&&i.push("\u4E3B\u673A\u5BC6\u94A5\u4E0D\u5339\u914D\uFF01"),r.auth?.ok)return"\u2705 \u8FDE\u63A5\u6210\u529F\uFF1A"+(o!==null?"\u8BA4\u8BC1\u901A\u8FC7\uFF08"+o+"ms\uFF09":"\u8BA4\u8BC1\u901A\u8FC7")+(i.length?" \xB7 "+i.join(" \xB7 "):"");let a=r.auth?.error||r.tcp?.error||"\u672A\u77E5\u9519\u8BEF";return(t?.prefix||"\u274C \u8FDE\u63A5\u5931\u8D25\uFF1A")+a+(i.length?" \xB7 "+i.join(" \xB7 "):"")}async function jn(){try{let t=await(await fetch("/api/dsh-tty/config",{cache:"no-store"})).json();if(t.ok&&typeof t.config=="object"&&t.config!==null){let r=Lt;ti(t.config),Je!==null&&Lt!==r&&Tn(Je)}}catch{}}function nc(e){Je!==null&&(e.target instanceof Element&&(Je.contains(e.target)||e.target.closest(".tt_tabAdd")!==null)||ft())}function r_(e){if(Je!==null){ft();return}jn(),ic().then(()=>{Je!==null&&Tn(Je)});let t=document.createElement("div");t.className="tt_addMenu",Je=t,Tn(t),document.body.appendChild(t);let r=e.getBoundingClientRect(),s=t.offsetWidth,i=r.left+s>window.innerWidth-8?r.right-s:r.left;t.style.left=Math.max(8,Math.min(i,window.innerWidth-s-8))+"px",t.style.top=r.bottom+6+"px",document.addEventListener("mousedown",nc,!0)}function ft(){Je!==null&&(document.removeEventListener("mousedown",nc,!0),Je.remove(),Je=null)}function Rn(e,t,r,s,o,i){let n=document.createElement("button");if(n.type="button",n.className="tt_addMenuItem",o===!0&&(n.setAttribute("data-soldout",""),n.title="\u4F1A\u8BDD\u6570\u5DF2\u8FBE\u4E0A\u9650\u2014\u2014\u70B9\u51FB\u67E5\u770B\u600E\u4E48\u529E"),i!==void 0){let c=document.createElement("span");c.className="tt_addMenuIcon",c.innerHTML=i,n.appendChild(c)}let a=document.createElement("span");a.className="tt_addMenuText";let f=document.createElement("span");if(f.className="tt_addMenuMain",f.textContent=t,a.appendChild(f),r!==""){let c=document.createElement("span");c.className="tt_addMenuSub",c.textContent=r,a.appendChild(c)}n.appendChild(a),n.addEventListener("click",s),e.appendChild(n)}function Tn(e){e.textContent="";let t=t_();Rn(e,"\u672C\u5730\u7EC8\u7AEF",Nt==="tmux"?"tmux \u6258\u7BA1 \xB7 \u5BBF\u4E3B\u91CD\u542F\u540E\u53EF\u6062\u590D":"\u5728\u5F53\u524D\u4F1A\u8BDD\u5DE5\u4F5C\u76EE\u5F55\u6253\u5F00",async()=>{await is()||(ft(),ei())},t,as);let r=document.createElement("div");r.className="tt_addMenuSep",e.appendChild(r);let s=document.createElement("div");s.className="tt_addMenuTitle",s.textContent="SSH \u8FDE\u63A5\u7C3F",e.appendChild(s);for(let i of Lt){if(i===null||typeof i!="object"||typeof i.name!="string"||i.name==="")continue;let n=document.createElement("div");n.className="tt_addMenuRow";let a=document.createElement("button");a.type="button",a.className="tt_addMenuItem",t&&(a.setAttribute("data-soldout",""),a.title="\u4F1A\u8BDD\u6570\u5DF2\u8FBE\u4E0A\u9650\u2014\u2014\u70B9\u51FB\u67E5\u770B\u600E\u4E48\u529E");let f=document.createElement("span");f.className="tt_addMenuIcon",f.innerHTML=bf;let c=document.createElement("span");c.className="tt_addMenuText";let p=document.createElement("span");p.className="tt_addMenuMain",p.textContent=i.name;let g=document.createElement("span");g.className="tt_addMenuSub";let S=sc(i.name);g.textContent=En(i)+(S>0?" \xB7 \u21C4"+String(S):""),c.appendChild(p),c.appendChild(g),a.appendChild(f),a.appendChild(c),a.addEventListener("click",async()=>{if(await is())return;ft();let d=Nt==="tmux"&&i.persist!==!1?{persist:!0,persistName:Un()}:{};ei({t:"ssh",name:i.name,...d},i.name)});let _=document.createElement("button");_.type="button",_.className="tt_addMenuEdit",_.title="SFTP \u6587\u4EF6\u6D4F\u89C8",_.innerHTML=Jr,_.addEventListener("click",()=>{ft(),us({name:i.name})});let l=document.createElement("button");l.type="button",l.className="tt_addMenuEdit",l.title="\u7F16\u8F91\u8FDE\u63A5",l.innerHTML=In,l.addEventListener("click",()=>{ft(),Cl(i)}),n.appendChild(a),n.appendChild(_),n.appendChild(l),e.appendChild(n)}if(Lt.length===0){let i=document.createElement("div");i.className="tt_addMenuTitle",i.textContent="\uFF08\u7A7A \u2014 \u5728\u8BBE\u7F6E\u5361\u7247\u6216\u300CSSH \u8FDE\u63A5\u2026\u300D\u91CC\u4FDD\u5B58\uFF09",e.appendChild(i)}let o=document.createElement("div");o.className="tt_addMenuSep",e.appendChild(o),Rn(e,"SSH \u8FDE\u63A5\u2026","\u624B\u52A8\u586B\u5199\u4E3B\u673A / \u7528\u6237 / \u8BA4\u8BC1\u65B9\u5F0F",()=>{ft(),Cl()},!1,Wl)}function Cl(e){if(gr!==null)return;let t=e!==null&&typeof e=="object"?e:null,r=t!==null,s=document.createElement("div");s.className="tt_sshBackdrop";let o=document.createElement("div");o.className="tt_sshCard";let i=document.createElement("div");i.className="tt_sshTitle",i.innerHTML=Wl+"<span></span>",i.lastElementChild.textContent=r?"\u7F16\u8F91\u8FDE\u63A5 \xB7 "+String(t.name??""):"SSH \u8FDE\u63A5",o.appendChild(i);let n=N=>{let x=document.createElement("div");return x.className="tt_sshSection",x.textContent=N,x},a={},f=(N,x,O)=>{let H=document.createElement("label");H.className="tt_sshRow";let $=document.createElement("span");$.className="tt_cardLabel",$.textContent=x,H.appendChild($);let U;if(O?.select!==void 0){U=document.createElement("select");for(let X of O.select){let ee=document.createElement("option");ee.value=X.value,ee.textContent=X.label,U.appendChild(ee)}}else U=document.createElement("input"),U.type=O?.type??"text",U.placeholder=O?.placeholder??"";return U.className="tt_cardInput",U.autocomplete="off",U.spellcheck=!1,H.appendChild(U),a[N]=U,H};o.appendChild(n("\u8FDE\u63A5"));let c=document.createElement("div");c.className="tt_sshGrid",c.appendChild(f("host","\u4E3B\u673A",{placeholder:"example.com \u6216 IP"})),c.appendChild(f("port","\u7AEF\u53E3",{placeholder:"22"})),o.appendChild(c),o.appendChild(f("username","\u7528\u6237\u540D",{placeholder:"root"})),o.appendChild(n("\u8BA4\u8BC1")),o.appendChild(f("auth","\u8BA4\u8BC1\u65B9\u5F0F",{select:[{value:"agent",label:"agent \u2014 \u4F7F\u7528\u672C\u673A ssh-agent"},{value:"key",label:"key \u2014 \u79C1\u94A5\u6587\u4EF6"},{value:"password",label:"password \u2014 \u5BC6\u7801"}]}));let p=f("keyPath","\u79C1\u94A5\u8DEF\u5F84",{placeholder:"~/.ssh/id_ed25519"}),g=f("passphrase","\u79C1\u94A5\u53E3\u4EE4\uFF08\u53EF\u7A7A\uFF09",{type:"password"}),S=f("password","\u5BC6\u7801",{type:"password"}),_=(N,x)=>{let O=document.createElement("div");O.className="tt_sshRow tt_envRow";let H=document.createElement("input");H.type="text",H.className="tt_cardInput",H.placeholder="\u6216\uFF1A\u9009\u62E9\u51ED\u636E\u5B58\u50A8\u91CC\u7684\u5F15\u7528\u540D",H.title="\u5019\u9009 = \u51ED\u636E\u5B58\u50A8\u91CC\u5DF2\u6709\u7684\u5F15\u7528\u540D + \u672C\u673A\u8FDE\u63A5\u7C3F\u91CC\u5728\u7528\u7684\u5F15\u7528\u540D",H.autocomplete="off",H.spellcheck=!1;let $=document.createElement("span");$.className="tt_cardHint tt_envEmpty",$.textContent=x,$.hidden=!0,H.hidden=!0;let U=document.createElement("div");U.className="tt_envList",U.dataset.hidden="";let X=[],ee=()=>{if(U.textContent="",X.length===0){let K=document.createElement("span");K.className="tt_cardHint",K.textContent=x,U.appendChild(K);return}let re=H.value.trim().toUpperCase(),Q=re===""?X:X.filter(K=>K.toUpperCase().includes(re));for(let K of Q.slice(0,30)){let J=document.createElement("button");J.type="button",J.className="tt_envItem",J.textContent=K;let oe="env:"+K,ie=null,he=()=>{ie!==null&&(clearTimeout(ie),ie=null),J.textContent=K,delete J.dataset.danger};J.addEventListener("mousedown",Ce=>Ce.preventDefault()),J.addEventListener("click",()=>{let Ce=N.value;if(Ce===""||Ce.startsWith("env:")||ie!==null){he(),N.value=oe,N.focus(),N.dispatchEvent(new Event("change"));return}J.textContent=K+"\uFF08\u518D\u70B9\u8986\u76D6\u5DF2\u586B\uFF09",J.dataset.danger="",ie=setTimeout(he,4e3)}),U.appendChild(J)}if(Q.length>30){let K=document.createElement("span");K.className="tt_envMore",K.textContent="\u8FD8\u6709 "+(Q.length-30)+" \u4E2A \u2014 \u7EE7\u7EED\u8F93\u5165\u7B5B\u9009",U.appendChild(K)}else if(Q.length===0){let K=document.createElement("span");K.className="tt_envMore",K.textContent="\u6CA1\u6709\u5339\u914D\u7684\u5F15\u7528",U.appendChild(K)}};return H.addEventListener("input",ee),H.addEventListener("focus",()=>{X.length>0&&delete U.dataset.hidden}),H.addEventListener("blur",()=>{H.value.trim()===""&&(U.dataset.hidden="")}),O.appendChild(H),O.appendChild($),O.appendChild(U),{row:O,setNames(re){X=Array.isArray(re)?re:[];let Q=X.length>0;H.hidden=!Q,$.hidden=Q,ee()}}},l=(N,x)=>{let O=document.createElement("div");O.className="tt_sshRow tt_credRow";let H=document.createElement("label");H.className="tt_credToggle";let $=document.createElement("input");$.type="checkbox",$.className="tt_cardCheckbox";let U=document.createElement("span");U.textContent="\u4FDD\u5B58\u65F6\u5B58\u5165\u51ED\u636E\u5B58\u50A8",H.appendChild($),H.appendChild(U),$.checked=_t!==null,H.title="\u52FE\u9009\u540E\uFF0C\u70B9\u300C\u4FDD\u5B58\u4FEE\u6539\u300D\u6216\u300C\u8FDE\u63A5\uFF08\u5E76\u4FDD\u5B58\uFF09\u300D\u65F6\u628A\u5BC6\u7801\u5199\u8FDB\u5B98\u65B9\u51ED\u636E\u5B58\u50A8\uFF0C\u5B57\u6BB5\u91CC\u53EA\u7559 env: \u5F15\u7528\uFF08\u503C\u5728 ~/.dsh/.credentials.yaml\uFF0C\u4E0D\u8FDB\u73AF\u5883\u3001\u4E0D\u56DE\u4F20\u6D4F\u89C8\u5668\uFF1B\u6321\u4E0D\u4F4F\u540C\u7528\u6237\u8FDB\u7A0B\u4E0E agent\uFF09\u3002\u4E0D\u52FE\u9009\u5219\u6309\u73B0\u72B6\u660E\u6587\u5199\u8FDB\u8BBE\u7F6E\u6587\u4EF6\u3002\u80FD\u7528\u5BC6\u94A5 / agent \u5C31\u522B\u5B58\u5BC6\u7801\u3002";let X=document.createElement("button");X.type="button",X.className="tt_toolBtn tt_credClear",X.textContent="\u6E05\u9664\u5DF2\u5B58\u51ED\u636E",X.dataset.hidden="";let ee=document.createElement("span");ee.className="tt_credStatus",O.appendChild(H),O.appendChild(X),O.appendChild(ee);let re=(J,oe)=>{ee.textContent=J,ee.dataset.kind=oe},Q=async()=>{let J=fr(N.value),oe=J!=="";if(H.hidden=oe,X.hidden=!oe,ee.hidden=!1,br()===null){$.disabled=!0,$.checked=!1,X.disabled=!0,re(_t===null?"\u5BBF\u4E3B\u672A\u63D0\u4F9B\u51ED\u636E\u670D\u52A1\uFF08remote.credentials\uFF09\uFF0C\u53EA\u80FD\u660E\u6587\u4FDD\u5B58":"\u51ED\u636E\u670D\u52A1\u4E0D\u5B8C\u6574\uFF0C\u53EA\u80FD\u660E\u6587\u4FDD\u5B58","muted");return}if($.disabled=!1,!oe){ee.hidden=!0,re("","plain");return}let ie=await Rl(J);if(ie.unreported===!0){re("\u5F15\u7528 "+J+"\uFF1A\u5BBF\u4E3B\u672A\u62A5\u544A\u72B6\u6001","plain");return}if(ie.error!==void 0){re("\u8BFB\u53D6\u51ED\u636E\u72B6\u6001\u5931\u8D25\uFF1A"+ie.error,"error");return}let he=ie.view;re(he.configured?"\u5DF2\u5B58\u5165"+(he.source!==""?"\uFF08\u6765\u6E90 "+he.source+"\uFF09":"")+" \xB7 "+J:"\u5F15\u7528 "+J+"\uFF1A\u5B58\u50A8\u91CC\u8FD8\u6CA1\u6709\u8FD9\u4E2A\u503C",he.configured?"ok":"plain"),X.disabled=he.configured!==!0||he.writable!==!0};X.addEventListener("click",()=>{(async()=>{let J=fr(N.value);if(J==="")return;let oe=await Tl(J);if(oe.error!==void 0){re(oe.error,"error");return}N.value="",await Q()})()});let K=async()=>{let J=await Al($.checked===!0,N.value,a.host.value,a.port.value,a.username.value,x);return J.value!==void 0&&(N.value=J.value,await Q()),J};return N.addEventListener("change",()=>{Q()}),{row:O,refresh:Q,storeIfRequested:K}},d=_(a.passphrase,"\u8FD8\u6CA1\u6709\u522B\u7684\u8FDE\u63A5\u7528\u8FC7\u51ED\u636E\u5F15\u7528 \u2014 \u53EF\u5728\u79C1\u94A5\u53E3\u4EE4\u6846\u76F4\u63A5\u624B\u8F93 env:NAME"),h=_(a.password,"\u8FD8\u6CA1\u6709\u522B\u7684\u8FDE\u63A5\u7528\u8FC7\u51ED\u636E\u5F15\u7528 \u2014 \u52FE\u4E0A\u9762\u7684\u300C\u4FDD\u5B58\u65F6\u5B58\u5165\u51ED\u636E\u5B58\u50A8\u300D\u65B0\u5EFA\u4E00\u4E2A\uFF0C\u6216\u76F4\u63A5\u5728\u5BC6\u7801\u6846\u624B\u8F93 env:NAME"),u=l(a.password,"PASSWORD");(async()=>{let N=await Ml();d.setNames(N),h.setNames(N)})(),o.appendChild(p),o.appendChild(g),o.appendChild(d.row),o.appendChild(S),o.appendChild(u.row),o.appendChild(h.row),o.appendChild(n("\u9009\u9879"));let v=document.createElement("label");v.className="tt_cardRow";let y=document.createElement("input");y.type="checkbox",y.className="tt_cardCheckbox";let b=document.createElement("span");b.className="tt_cardLabel",b.textContent="agent forwarding\uFF08\u8FDC\u7A0B\u53EF\u7528\u672C\u5730 ssh-agent \u94A5\u5319\uFF0C\u5982\u8FDC\u7A0B git clone\uFF09",v.appendChild(y),v.appendChild(b),o.appendChild(v);let C=document.createElement("label");C.className="tt_cardRow";let m=document.createElement("input");m.type="checkbox",m.className="tt_cardCheckbox";let E=document.createElement("span");E.className="tt_cardLabel",E.textContent="\u6301\u4E45\u4F1A\u8BDD\uFF08tmux \u6258\u7BA1\uFF0C\u65AD\u7EBF/\u91CD\u542F\u540E\u6062\u590D\u73B0\u573A\uFF1B\u8FDC\u7A0B\u9700\u5B89\u88C5 tmux\uFF09",C.appendChild(m),C.appendChild(E),m.checked=Nt==="tmux",Nt==="tmux"&&o.appendChild(C);let P=document.createElement("label");P.className="tt_cardRow";let B=document.createElement("input");B.type="checkbox",B.className="tt_cardCheckbox";let F=document.createElement("span");F.className="tt_cardLabel",F.textContent="\u4FDD\u5B58\u5230\u8FDE\u63A5\u7C3F\uFF08\u540C\u540D\u8986\u76D6\uFF09",P.appendChild(B),P.appendChild(F),o.appendChild(P);let R=f("name","\u8FDE\u63A5\u7C3F\u540D\u79F0",{placeholder:"\u7559\u7A7A\u5219\u7528\u4E3B\u673A\u540D"});R.style.display="none",o.appendChild(R),B.addEventListener("change",()=>{R.style.display=B.checked?"":"none",B.checked&&a.name.value.trim()===""&&a.host.value.trim()!==""&&(a.name.value=a.host.value.trim()),B.checked&&a.name.focus()}),r&&(P.style.display="none",a.name.value=String(t.name??""),R.style.display="",a.host.value=String(t.host??""),a.port.value=String(t.port??22),a.username.value=String(t.username??""),a.auth.value=t.auth==="key"||t.auth==="password"?String(t.auth):"agent",a.keyPath.value=String(t.keyPath??""),a.passphrase.value=String(t.passphrase??""),a.password.value=String(t.password??""),y.checked=t.agentForward===!0,m.checked=Nt==="tmux");let j=document.createElement("div");j.className="tt_sshStatus";let A=document.createElement("div");A.className="tt_sshError";let T=document.createElement("div");T.className="tt_sshProbeResult",j.appendChild(A),j.appendChild(T),o.appendChild(j);let W=()=>{A.textContent="";let N=a.host.value.trim(),x=a.username.value.trim(),O=Number(a.port.value);if((!Number.isInteger(O)||O<1||O>65535)&&(O=22),N===""||x==="")return A.textContent="\u4E3B\u673A\u4E0E\u7528\u6237\u540D\u5FC5\u586B",null;let H=a.auth.value,$={host:N,port:O,username:x,auth:H};if(H==="key"){let U=a.keyPath.value.trim();if(U==="")return A.textContent="auth=key \u9700\u8981\u79C1\u94A5\u8DEF\u5F84",null;$.keyPath=U;let X=a.passphrase.value;X!==""&&($.passphrase=X)}if(H==="password"){let U=a.password.value;if(U==="")return A.textContent="auth=password \u9700\u8981\u5BC6\u7801",null;$.password=U}return y.checked&&($.agentForward=!0),$},D=document.createElement("div");D.className="tt_sshActions";let w=document.createElement("div");w.className="tt_sshActionsGroup";let L=document.createElement("div");L.className="tt_sshActionsGroup",D.appendChild(w),D.appendChild(L);let k=document.createElement("button");k.type="button",k.className="tt_toolBtn",k.textContent="\u53D6\u6D88";let M=document.createElement("button");M.type="button",M.className="tt_cardSave",M.textContent="\u8FDE\u63A5",w.appendChild(k);let z=document.createElement("button");z.type="button",z.className="tt_toolBtn",z.textContent="\u6587\u4EF6\u6D4F\u89C8",z.title="\u4E0D\u52A8\u7EC8\u7AEF\uFF0C\u76F4\u63A5\u4EE5\u5F53\u524D\u586B\u5199\u7684\u4FE1\u606F\u6253\u5F00 SFTP \u6587\u4EF6\u6D4F\u89C8",z.addEventListener("click",()=>{A.textContent="";let N=a.host.value.trim(),x=a.username.value.trim(),O=Number(a.port.value);if((!Number.isInteger(O)||O<1||O>65535)&&(O=22),N===""||x===""){A.textContent="\u4E3B\u673A\u4E0E\u7528\u6237\u540D\u5FC5\u586B";return}let H=a.auth.value,$={host:N,port:O,username:x,auth:H};if(H==="key"){let U=a.keyPath.value.trim();if(U===""){A.textContent="auth=key \u9700\u8981\u79C1\u94A5\u8DEF\u5F84";return}$.keyPath=U;let X=a.passphrase.value;X!==""&&($.passphrase=X)}if(H==="password"){let U=a.password.value;if(U===""){A.textContent="auth=password \u9700\u8981\u5BC6\u7801";return}$.password=U}y.checked&&($.agentForward=!0),Ot(),us($)}),w.appendChild(z);let q=null;r&&(q=document.createElement("button"),q.type="button",q.className="tt_toolBtn",q.textContent="\u4FDD\u5B58\u4FEE\u6539",q.addEventListener("click",()=>{A.textContent="";let N=a.host.value.trim(),x=a.username.value.trim();if(N===""||x===""){A.textContent="\u4E3B\u673A\u4E0E\u7528\u6237\u540D\u5FC5\u586B";return}let O=Number(a.port.value);(!Number.isInteger(O)||O<1||O>65535)&&(O=22);let H=a.auth.value,U={name:a.name.value.trim()||N,host:N,port:O,username:x,auth:H,keyPath:H==="key"?a.keyPath.value.trim():"",passphrase:a.passphrase.value,password:a.password.value,agentForward:y.checked,persist:m.checked};if(H==="key"&&U.keyPath===""){A.textContent="auth=key \u9700\u8981\u79C1\u94A5\u8DEF\u5F84";return}q!==null&&(q.disabled=!0),(async()=>{let X=await u.storeIfRequested();if(X.error!==void 0){A.textContent=X.error,q!==null&&(q.disabled=!1);return}X.value!==void 0&&(U.password=X.value);let ee=await s_(String(t.name??""),U);if(q!==null&&(q.disabled=!1),ee!==void 0){A.textContent="\u4FDD\u5B58\u5931\u8D25\uFF1A"+ee;return}Ot()})()}),w.appendChild(q));let Y=document.createElement("button");Y.type="button",Y.className="tt_toolBtn",Y.textContent="\u8BD5\u8FDE",Y.title="\u6309\u5F53\u524D\u586B\u5199\u8BCA\u65AD\u8FDE\u63A5\uFF08TCP \u2192 \u4E3B\u673A\u5BC6\u94A5 \u2192 \u8BA4\u8BC1\uFF09\uFF1B\u4E0D\u4F1A\u65B0\u5EFA\u4F1A\u8BDD\uFF0C\u4E5F\u4E0D\u8BB0\u5F55\u4E3B\u673A\u6307\u7EB9",Y.addEventListener("click",()=>{let N=W();N!==null&&(T.className="tt_sshProbeResult",T.textContent="\u8FDE\u63A5\u6D4B\u8BD5\u4E2D\u2026",Y.disabled=!0,Ln(N,!1).then(x=>{Y.disabled=!1,x.result?(T.className="tt_sshProbeResult"+(x.result.auth?.ok===!0?" tt_sshProbeOk":" tt_sshProbeBad"),T.textContent=Mn(x.result)):(T.className="tt_sshProbeResult tt_sshProbeBad",T.textContent="\u274C \u8FDE\u63A5\u5931\u8D25\uFF1A"+String(x.error||"\u672A\u77E5\u9519\u8BEF"))}))}),w.appendChild(Y),L.appendChild(M),o.appendChild(D);let Z=()=>{p.style.display=a.auth.value==="key"?"":"none",g.style.display=a.auth.value==="key"?"":"none",d.row.style.display=a.auth.value==="key"?"":"none",S.style.display=a.auth.value==="password"?"":"none",h.row.style.display=a.auth.value==="password"?"":"none",u.row.style.display=a.auth.value==="password"?"":"none"};a.auth.addEventListener("change",Z),Z(),u.refresh(),k.addEventListener("click",()=>Ot()),s.addEventListener("mousedown",N=>{N.target===s&&Ot()}),M.addEventListener("click",async()=>{A.textContent="";let N=await is();if(N!==null){A.textContent=N;return}let x=a.host.value.trim(),O=a.username.value.trim(),H=Number(a.port.value);if((!Number.isInteger(H)||H<1||H>65535)&&(H=22),x===""||O===""){A.textContent="\u4E3B\u673A\u4E0E\u7528\u6237\u540D\u5FC5\u586B";return}let $=a.auth.value,U={t:"ssh",host:x,port:H,username:O,auth:$};if($==="key"){let Q=a.keyPath.value.trim();Q!==""&&(U.keyPath=Q);let K=a.passphrase.value;K!==""&&(U.passphrase=K)}if($==="password"){let Q=a.password.value;Q!==""&&(U.password=Q)}y.checked&&(U.agentForward=!0),m.checked&&(U.persist=!0,U.persistName=Un());let X=H!==22?O+"@"+x+":"+H:O+"@"+x,ee=Q=>{Ot(),se!==null&&ei(U,Q!==""?Q:X)};if(!B.checked){ee("");return}let re=a.name.value.trim()||x;M.disabled=!0,(async()=>{let Q=await u.storeIfRequested();if(Q.error!==void 0){A.textContent=Q.error,M.disabled=!1;return}let K=Q.value??U.password??"",J=await i_({name:re,host:x,port:H,username:O,auth:$,keyPath:U.keyPath??"",passphrase:U.passphrase??"",password:K,agentForward:y.checked,persist:m.checked});if(M.disabled=!1,J!==void 0){A.textContent="\u4FDD\u5B58\u8FDE\u63A5\u7C3F\u5931\u8D25\uFF1A"+J;return}ee(re)})()}),s.appendChild(o),document.body.appendChild(s),gr=s,a.host.focus()}function Ot(){gr!==null&&(gr.remove(),gr=null)}async function i_(e){let t=[...Lt.filter(r=>r?.name!==e.name),e];try{let r=await fetch("/api/dsh-tty/config",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({sshHosts:t})}),s=await r.json().catch(()=>({}));if(!r.ok||!s.ok)return String(s.error||"HTTP "+r.status);ti(s.config);return}catch(r){return String(r&&r.message?r.message:r)}}async function s_(e,t){if(t.name!==e&&Lt.some(s=>s?.name===t.name))return"\u8FDE\u63A5\u7C3F\u91CC\u5DF2\u6709\u540C\u540D\u6761\u76EE: "+t.name;let r=Lt.map(s=>s?.name===e?t:s);try{let s=await fetch("/api/dsh-tty/config",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({sshHosts:r})}),o=await s.json().catch(()=>({}));if(!s.ok||!o.ok)return String(o.error||"HTTP "+s.status);ti(o.config);return}catch(s){return String(s&&s.message?s.message:s)}}function n_(e,t,r){let s=cr(r,me);if(ac(s))return;let o=document.createElement("div");o.className="tt_sftpDualCard";let i=document.createElement("div");i.className="tt_sftpTitleRow";let n=document.createElement("div");n.className="tt_sshTitle",n.innerHTML=Jr+"<span></span>",n.lastElementChild.textContent="SFTP \u53CC\u680F \xB7 "+t;let a=document.createElement("button");a.type="button",a.className="tt_close",a.title="\u5173\u95ED",a.innerHTML=ls,a.addEventListener("click",()=>yr(s)),i.appendChild(n),i.appendChild(a),o.appendChild(i);let f=document.createElement("div");f.className="tt_sftpStatus";let c=(w,L)=>{f.textContent=w,L===void 0?delete f.dataset.state:f.dataset.state=L},p=!1,g=(w,L)=>{if(!(p||_.local.busy||_.remote.busy)){p=!0;for(let k of[_.local,_.remote])k.setBusy(!0);c(w,"busy"),Promise.resolve().then(L).catch(k=>{(k===null||typeof k!="object"||k.name!=="TransferCanceledError")&&A.fail("\u5931\u8D25"),c(String(k&&k.message?k.message:k),"error")}).finally(()=>{p=!1;for(let k of[_.local,_.remote])k.setBusy(!1)})}},S=w=>{_[w].bar.after(d),d.style.display="",h.focus(),h.select()},_={},l=(w,L)=>{let k={kind:w,path:"",busy:!1},M=document.createElement("div");M.className="tt_sftpPane";let z=document.createElement("div");z.className="tt_sftpPaneHead";let q=document.createElement("span");q.textContent=L;let Y=document.createElement("span");Y.className="tt_sftpPaneMeta",z.appendChild(q),z.appendChild(Y),M.appendChild(z);let Z=document.createElement("div");Z.className="tt_sftpBar";let N=document.createElement("input");N.type="text",N.className="tt_sftpPath",N.placeholder=w==="local"?"\u672C\u673A\u8DEF\u5F84\uFF08\u56DE\u8F66\u8DF3\u8F6C\uFF09":"\u8FDC\u7A0B\u8DEF\u5F84\uFF08\u56DE\u8F66\u8DF3\u8F6C\uFF09",N.spellcheck=!1,N.autocomplete="off";let x=document.createElement("button");x.type="button",x.className="tt_toolBtn",x.innerHTML=Nn+"<span>\u5237\u65B0</span>";let O=document.createElement("button");O.type="button",O.className="tt_toolBtn",O.innerHTML=Il+"<span>\u65B0\u5EFA\u76EE\u5F55</span>",Z.appendChild(N),Z.appendChild(x),Z.appendChild(O),M.appendChild(Z);let H=document.createElement("div");H.className="tt_sftpList",M.appendChild(H),k.bar=Z;let $=K=>{k.busy=K;for(let J of[x,O])J.disabled=K;N.disabled=K},U=async(K,J)=>{let oe=w==="local"?"/api/dsh-tty/local-fs/":"/api/dsh-tty/sftp/",ie=w==="local"?J:{...e,...J},he=await fetch(oe+K,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(ie)}),Ce=await he.json().catch(()=>({}));if(!he.ok||Ce.ok!==!0)throw new Error(String(Ce.error||"HTTP "+he.status));return Ce},X=(K,J)=>{if(!(k.busy||p))return $(!0),c(K,"busy"),Promise.resolve().then(J).catch(oe=>c(String(oe&&oe.message?oe.message:oe),"error")).finally(()=>$(!1))},ee=(K,J)=>{if(K===void 0||K==="")throw new Error("\u76EE\u5F55\u5C1A\u672A\u5B9A\u4F4D\u5B8C\u6210");return K.endsWith("/")||K.endsWith("\\")?K+J:K+"/"+J},re=K=>{let J=ee(k.path,K.name),oe=[];K.isDir===!0?oe.push("\u76EE\u5F55"):oe.push($e(Number(K.size))||"\u2014");let ie=cc(Number(K.mtime));ie!==""&&oe.push(ie);let he=C(K.isDir?Jr:K.isSymlink?Pl:Bl,K.name,oe.join(" \xB7 "),K.isDir===!0?"dir":K.isSymlink===!0?"link":"file"),Ce=()=>k.loadDir(k.path),de=w==="local"?_.remote:_.local;return K.isDir===!0&&he.addEventListener("click",ve=>{ve.target instanceof Element&&ve.target.closest(".tt_sftpAct")!==null||k.loadDir(J)}),m(he,w==="local"?Nl:Hl,"\u4F20\u8F93\u5230"+(w==="local"?"\u8FDC\u7A0B":"\u672C\u673A")+"\uFF1A"+de.path,()=>{if(k.path===""||de.path===""){c("\u4E24\u4FA7\u76EE\u5F55\u5C1A\u672A\u5B9A\u4F4D\u5B8C\u6210\uFF0C\u7B49\u5217\u8868\u52A0\u8F7D\u540E\u518D\u4F20\u8F93","error");return}A.reset(),A.pulse(0),g("\u4F20\u8F93 "+K.name+"\u2026",async()=>{let ve=await fetch("/api/dsh-tty/local-fs/transfer",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({action:"start",direction:w==="local"?"up":"down",...e,localPath:w==="local"?J:ee(de.path,K.name),remotePath:w==="local"?ee(de.path,K.name):J})}),pe=await ve.json().catch(()=>({}));if(!ve.ok||pe.ok!==!0)throw A.fail("\u4F20\u8F93\u5931\u8D25"),new Error(String(pe.error||"HTTP "+ve.status));let Oe=pe.job?.id;if(typeof Oe!="string"||Oe==="")throw A.fail("\u4F20\u8F93\u5931\u8D25"),new Error("\u670D\u52A1\u7AEF\u672A\u8FD4\u56DE\u4EFB\u52A1 id");await T(Oe,K.name)==="canceled"?(A.reset(),c("\u5DF2\u53D6\u6D88\u4F20\u8F93 "+K.name)):(A.done("\u5B8C\u6210"),setTimeout(()=>A.reset(),1500),c("\u5DF2\u4F20\u8F93 "+K.name)),await de.loadDir(de.path)})}),w!=="local"&&K.isDir!==!0&&m(he,Ol,"\u4E0B\u8F7D "+K.name,()=>{P(K,J)}),m(he,In,"\u91CD\u547D\u540D "+K.name,()=>{h.placeholder="\u65B0\u540D\u79F0",h.value=K.name,S(w),y=async()=>{let ve=h.value.trim();ve===""||ve===K.name||(b(),await k.runTask("\u91CD\u547D\u540D "+K.name+"\u2026",async()=>{await U("rename",{from:J,to:ee(k.path,ve)}),await Ce()}))}}),E(he,()=>k.runTask("\u5220\u9664 "+K.name+"\u2026",async()=>{await U("remove",{path:J,recursive:K.isDir===!0}),await Ce(),c("\u5DF2\u5220\u9664 "+K.name)}),K),he},Q=K=>{if(H.textContent="",k.path!==""&&k.path!=="/"&&/^[A-Za-z]:[\\/]?$/.test(k.path)===!1){let ie=C(On,"..\uFF08\u4E0A\u7EA7\u76EE\u5F55\uFF09","","up");ie.addEventListener("click",()=>{let he=w==="local"?l_(k.path):hc(k.path);he!==null&&k.loadDir(he)}),H.appendChild(ie)}let J=Array.isArray(K)?K:[];if(J.length===0){let ie=document.createElement("div");ie.className="tt_addMenuTitle",ie.textContent="\uFF08\u7A7A\u76EE\u5F55\uFF09",H.appendChild(ie);return}let oe=500;for(let ie of J.slice(0,oe))ie===null||typeof ie!="object"||typeof ie.name!="string"||ie.name===""||H.appendChild(re(ie));if(J.length>oe){let ie=document.createElement("div");ie.className="tt_addMenuTitle",ie.textContent=`\u2026\u5176\u4F59 ${String(J.length-oe)} \u9879\u672A\u6E32\u67D3\uFF08\u5171 ${String(J.length)} \u9879\uFF09\u2014\u2014\u7528\u4E0A\u65B9\u8DEF\u5F84\u6846\u8DF3\u8F6C\u5230\u5B50\u76EE\u5F55\u5B9A\u4F4D`,H.appendChild(ie)}};return k.loadDir=async K=>{try{let J=await U("list",{path:K??k.path});k.path=typeof J.path=="string"&&J.path!==""?J.path:k.path,N.value=k.path;let oe=Array.isArray(J.entries)?J.entries.length:0;Q(J.entries),Y.textContent=String(oe)+" \u9879",c(k.path)}catch(J){c(String(J&&J.message?J.message:J),"error")}},k.runTask=X,k.setBusy=$,_[w]=k,x.addEventListener("click",()=>{k.runTask("\u52A0\u8F7D\u4E2D\u2026",()=>k.loadDir(k.path))}),O.addEventListener("click",()=>{k.busy||p||(h.placeholder="\u65B0\u76EE\u5F55\u540D\uFF08\u76F8\u5BF9\u5F53\u524D\u76EE\u5F55\uFF09",h.value="",S(w),y=async()=>{let K=h.value.trim();K!==""&&(b(),await k.runTask("\u521B\u5EFA\u76EE\u5F55 "+K+"\u2026",async()=>{await U("mkdir",{path:ee(k.path,K),parents:!0}),await k.loadDir(k.path)}))})}),N.addEventListener("keydown",K=>{if(K.key!=="Enter"||(K.preventDefault(),k.busy||p))return;let J=N.value.trim();J!==""&&k.runTask("\u52A0\u8F7D\u4E2D\u2026",()=>k.loadDir(J))}),M},d=document.createElement("div");d.className="tt_sftpEditor",d.style.display="none";let h=document.createElement("input");h.type="text",h.className="tt_cardInput",h.spellcheck=!1,h.autocomplete="off";let u=document.createElement("button");u.type="button",u.className="tt_toolBtn",u.textContent="\u786E\u5B9A";let v=document.createElement("button");v.type="button",v.className="tt_toolBtn",v.textContent="\u53D6\u6D88",d.appendChild(h),d.appendChild(u),d.appendChild(v);let y=null,b=()=>{d.style.display="none",h.value="",y=null};u.addEventListener("click",()=>{y?.()}),v.addEventListener("click",b),h.addEventListener("keydown",w=>{w.key==="Enter"?(w.preventDefault(),y?.()):w.key==="Escape"&&(w.stopPropagation(),b())});let C=(w,L,k,M)=>{let z=document.createElement("button");z.type="button",z.className="tt_sftpRow";let q=document.createElement("span");q.className="tt_sftpIcon",q.innerHTML=w,M!==void 0&&(q.dataset.kind=M);let Y=document.createElement("span");if(Y.className="tt_sftpName",Y.textContent=L,Y.title=L,z.appendChild(q),z.appendChild(Y),k!==""){let Z=document.createElement("span");Z.className="tt_sftpMeta",Z.textContent=k,z.appendChild(Z)}return z},m=(w,L,k,M)=>{let z=document.createElement("button");z.type="button",z.className="tt_sftpAct",z.innerHTML=L,z.title=k,z.addEventListener("click",q=>{q.stopPropagation(),M()}),w.appendChild(z)},E=(w,L,k)=>{let M=document.createElement("button");M.type="button",M.className="tt_sftpAct",M.innerHTML=_r,M.title="\u5220\u9664 "+k.name+(k.isDir?"\uFF08\u542B\u5185\u5BB9\uFF09":"");let z=null;M.addEventListener("click",q=>{if(q.stopPropagation(),z!==null){clearTimeout(z),z=null,M.innerHTML=_r,delete M.dataset.danger,L();return}M.textContent="\u786E\u8BA4?",M.dataset.danger="",z=setTimeout(()=>{z=null,M.innerHTML=_r,delete M.dataset.danger},4e3)}),w.appendChild(M)},P=(w,L)=>_.remote.runTask("\u4E0B\u8F7D "+w.name+"\u2026",async()=>{A.reset();let k;try{k=await uc("/api/dsh-tty/sftp/download",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({...e,path:L})},(M,z)=>{A.set(M,z)},Ht.maxDownloadMb,M=>A.setCancel(M))}catch(M){if(An(M)){A.reset(),c("\u5DF2\u53D6\u6D88\u4E0B\u8F7D "+w.name);return}throw A.fail("\u4E0B\u8F7D\u5931\u8D25"),M}A.done("\u5B8C\u6210"),fc(k,w.name),setTimeout(()=>A.reset(),1500),c("\u5DF2\u4E0B\u8F7D "+w.name+"\uFF08"+($e(k.size)||String(k.size)+" B")+"\uFF09")}),B=l("local","\u672C\u673A"),F=l("remote","\u8FDC\u7A0B");_.local.wrap=B,_.remote.wrap=F;let R=document.createElement("div");R.className="tt_sftpDual",R.appendChild(B),R.appendChild(F),o.appendChild(R),o.appendChild(d);let j=document.createElement("div");j.className="tt_sftpFoot";let A=dc();j.appendChild(A.el),j.appendChild(f),o.appendChild(j);let T=async(w,L)=>{let k=!1;A.setCancel(()=>{k||(k=!0,fetch("/api/dsh-tty/local-fs/transfer",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({action:"cancel",job:w})}).catch(()=>{}))});try{for(;;){await new Promise(Y=>setTimeout(Y,400));let M=await fetch("/api/dsh-tty/local-fs/transfer",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({action:"status",job:w})}),z=await M.json().catch(()=>({}));if(!M.ok||z.ok!==!0){if(k)return"canceled";throw new Error(String(z.error||"HTTP "+M.status))}let q=z.job;if(q===null||typeof q!="object")throw new Error("\u670D\u52A1\u7AEF\u8FD4\u56DE\u4E86\u975E\u6CD5\u7684\u4EFB\u52A1\u72B6\u6001");if(q.state==="running"){let Y=typeof q.current=="string"&&q.current!==""?q.current:L;c("\u4F20\u8F93 "+Y+"\u2026","busy"),Number.isFinite(q.total)&&q.total>0?A.set(Number(q.bytes)||0,q.total):A.pulse(Number(q.bytes)||0);continue}if(q.state==="canceled")return"canceled";if(q.state!=="done")throw new Error(String(q.error||"\u4F20\u8F93\u5931\u8D25"));return"done"}}finally{A.setCancel(null)}},W=Wn(),D=W===null?420:Math.round(W.height*.56);lc(o,"SFTP \u53CC\u680F \xB7 "+t,D,s),_.local.loadDir(""),_.remote.loadDir("")}var Mt=null,pt=null;function oc(){return pt!==null&&_n(pt.ownerKey,me)?pt.ownerKey:cr(void 0,me)}var ac=(e=oc())=>Mt!==null||pt!==null&&pt.ownerKey===e;function lc(e,t,r,s){let o=cr(s,me),i=st!==null&&st.ownerKey===o;if(se!==null&&!Ae&&Xe!==null&&!i)try{let a=Jl({title:t,side:"bottom",size:r,min:200,ownerSid:o,onClose:()=>yr(o)});a.element.appendChild(e),pt=a;return}catch(a){console.warn("[dsh-tty] SFTP \u6302\u5230\u7EC8\u7AEF\u6302\u8F7D\u4F4D\u5931\u8D25\uFF0C\u56DE\u9000\u5BF9\u8BDD\u6846\uFF1A"+(a instanceof Error?a.message:String(a)))}let n=document.createElement("div");n.className="tt_sshBackdrop",n.appendChild(e),n.addEventListener("mousedown",a=>{a.target===n&&yr()}),document.body.appendChild(n),Mt=n}var Xr=null;function o_(){let e=Xr;if(Xr=null,e!==null)try{e.click()}catch{}}function a_(e){let t=new TextEncoder().encode(e),r="";for(let s of t)r+=String.fromCharCode(s);return btoa(r).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function cc(e){let t=new Date(e);if(Number.isNaN(t.getTime()))return"";let r=s=>String(s).padStart(2,"0");return t.getFullYear()+"-"+r(t.getMonth()+1)+"-"+r(t.getDate())+" "+r(t.getHours())+":"+r(t.getMinutes())}function hc(e){let t=String(e).replace(/\/+$/,""),r=t.lastIndexOf("/");return r<=0?"/":t.slice(0,r)}function l_(e){let t=String(e).trim();if(t===""||(t=t.replace(/[\\/]+$/,""),t===""))return null;let r=t.match(/^([A-Za-z]:)(.*)$/);if(r!==null){let o=r[2];if(o==="")return null;let i=Math.max(o.lastIndexOf("\\"),o.lastIndexOf("/"));return i<=0?r[1]+"\\":r[1]+o.slice(0,i)}if(t.startsWith("\\\\")||t.startsWith("//")){let o=t.slice(2);if(o.split(/[\\/]/).filter(a=>a!=="").length<=2)return null;let n=Math.max(o.lastIndexOf("\\"),o.lastIndexOf("/"));return t.slice(0,2)+o.slice(0,n)}let s=t.lastIndexOf("/");return s<=0?s===0?"/":null:t.slice(0,s)}function Wr(e,t){return e.endsWith("/")?e+t:e+"/"+t}function dc(){let e=document.createElement("div");e.className="tt_sftpProgress";let t=document.createElement("div");t.className="tt_sftpTrack";let r=document.createElement("div");r.className="tt_sftpFill",t.appendChild(r);let s=document.createElement("span");s.className="tt_sftpPct",s.textContent="";let o=document.createElement("button");o.type="button",o.className="tt_sftpCancel",o.title="\u53D6\u6D88\u4F20\u8F93",o.textContent="\u2715",o.style.display="none";let i=null;o.addEventListener("click",_=>{_.stopPropagation();let l=i;l!==null&&(o.disabled=!0,l())}),e.appendChild(t),e.appendChild(s),e.appendChild(o);let n=_=>{s.textContent=_},a="",f=-1,c=_=>{_!==a&&(a=_,s.textContent=_)},p=_=>{let l=Math.round(_);l!==f&&(f=l,r.style.width=l+"%")},g=()=>{i=null,Xr===o&&(Xr=null),o.style.display="none",o.disabled=!1};return{el:e,reset(){delete e.dataset.active,delete e.dataset.state,a="",f=-1,this._last=void 0,this._lastAt=0,this._rate=void 0,r.style.width="0%",s.textContent="",g()},setCancel(_){if(_==null){g();return}i=_,Xr=o,o.disabled=!1,o.style.display=""},set(_,l){e.dataset.active="",delete e.dataset.state;let d=Date.now();if(this._last!==void 0&&d>this._lastAt){let h=(_-this._last)/((d-this._lastAt)/1e3);this._rate=this._rate===void 0?h:this._rate*.7+h*.3}if(this._last=_,this._lastAt=d,Number.isFinite(l)&&l>0){let h=Math.min(100,Math.max(0,_/l*100));p(h);let u=this._rate!==void 0&&this._rate>=0?Fr(this._rate):"";c(Math.round(h)+"%"+(u!==""?" \xB7 "+u:""))}else{r.style.width="";let h=this._rate!==void 0&&this._rate>=0?Fr(this._rate):"";c($e(_)+(h!==""?" \xB7 "+h:""))}},pulse(_){e.dataset.active="",delete e.dataset.state,r.style.width="45%",r.style.transition="none",setTimeout(()=>{r.style.transition="width .15s linear"},30);let l=Date.now();if(this._last!==void 0&&l>this._lastAt){let h=(_-this._last)/((l-this._lastAt)/1e3);this._rate=this._rate===void 0?h:this._rate*.7+h*.3}this._last=_,this._lastAt=l;let d=this._rate!==void 0&&this._rate>=0?Fr(this._rate):"";c((Number.isFinite(_)?$e(_):"\u2026")+(d!==""?" \xB7 "+d:""))},done(_){e.dataset.active="",e.dataset.state="done",r.style.width="100%",f=100,g(),c(_!==void 0&&_!==""?_:"\u5B8C\u6210")},fail(_){e.dataset.active="",e.dataset.state="error",g(),c(_!==void 0&&_!==""?_:"\u5931\u8D25")},text(_){delete e.dataset.state,_===void 0||_===""?(e.dataset.active="",a="",s.textContent=""):(e.dataset.active="",r.style.width="",f=-1,c(_))}}}async function uc(e,t,r,s=0,o=null){let i=s>0?s*1024*1024:0,n=typeof AbortController=="function"?new AbortController:null,a=!1;n!==null&&(t={...t,signal:n.signal},typeof o=="function"&&o(()=>{a=!0,n.abort()}));let f=await fetch(e,t);if(!f.ok){let d="HTTP "+f.status;try{let h=await f.json();h!==null&&typeof h=="object"&&typeof h.error=="string"&&(d=h.error)}catch{}throw new Error(d)}let c=Number(f.headers.get("content-length")),p=Number.isFinite(c)&&c>0;if(i>0&&p&&c>i){try{await f.body?.cancel()}catch{}throw new Error("\u6587\u4EF6\u8D85\u8FC7\u4E0B\u8F7D\u4E0A\u9650\uFF08"+$e(i)+"\uFF09\uFF1A\u8BF7\u7528\u53CC\u680F \u21E6 \u76F4\u4F20\u6216\u7EC8\u7AEF scp/rsync")}let g=f.body;if(g===null||typeof g.getReader!="function"){let d=await f.blob();if(i>0&&d.size>i)throw new Error("\u6587\u4EF6\u8D85\u8FC7\u4E0B\u8F7D\u4E0A\u9650\uFF08"+$e(i)+"\uFF09\uFF1A\u8BF7\u7528\u53CC\u680F \u21E6 \u76F4\u4F20\u6216\u7EC8\u7AEF scp/rsync");return p&&r(c,c),d}let S=g.getReader(),_=[],l=0;try{for(;;){let{done:d,value:h}=await S.read();if(d)break;if(h!==void 0&&h.byteLength>0){if(l+=h.byteLength,i>0&&l>i){try{await S.cancel()}catch{}throw new Error("\u6587\u4EF6\u8D85\u8FC7\u4E0B\u8F7D\u4E0A\u9650\uFF08"+$e(i)+"\uFF09\uFF1A\u8BF7\u7528\u53CC\u680F \u21E6 \u76F4\u4F20\u6216\u7EC8\u7AEF scp/rsync")}_.push(h),r(l,p?c:NaN)}}}catch(d){if(a||d!==null&&typeof d=="object"&&d.name==="AbortError"){try{await S.cancel()}catch{}throw new Sr}throw d}return new Blob(_,{type:"application/octet-stream"})}var Sr=class extends Error{constructor(){super("\u5DF2\u53D6\u6D88"),this.name="TransferCanceledError"}};function An(e){return e instanceof Sr}function fc(e,t){let r=URL.createObjectURL(e),s=document.createElement("a");s.href=r,s.download=t,s.click(),setTimeout(()=>URL.revokeObjectURL(r),3e4)}async function c_(e){if(e==null)return[];let t=typeof e.items<"u"?[...e.items]:[],r=[];for(let c of t){let p=typeof c.webkitGetAsEntry=="function"?c.webkitGetAsEntry():null;p!==null&&r.push(p)}if(r.length===0)return[...e.files??[]].map(c=>({relPath:c.name,file:c}));let s=[],o=Ht.maxUploadFiles,i=Ht.maxUploadMb>0?Ht.maxUploadMb*1024*1024:0,n=()=>o>0&&s.length>=o,a=0,f=(c,p)=>new Promise(g=>{if(n()){g();return}if(c.isFile===!0){c.file(l=>{i>0&&a+(l.size??0)>i?s._limitExceeded=!0:(s.push({relPath:p+c.name,file:l}),a+=l.size??0),g()},()=>g());return}if(c.isDirectory!==!0){g();return}let S=c.createReader(),_=()=>{S.readEntries(async l=>{if(l.length===0){g();return}for(let d of l){if(n())break;await f(d,p+c.name+"/")}if(n()){g();return}_()},()=>g())};_()});for(let c of r)await f(c,"");return s}function us(e,t){let r=cr(t,me);if(ac(r))return;let s=e!==null&&typeof e=="object"?e:{},o={};if(typeof s.name=="string"&&s.name!=="")o.name=s.name;else{for(let O of["host","username","auth","keyPath","passphrase","password"])typeof s[O]=="string"&&s[O]!==""&&(o[O]=s[O]);let x=Number(s.port);Number.isInteger(x)&&x>=1&&x<=65535&&(o.port=x),s.agentForward===!0&&(o.agentForward=!0)}let i=o.name??(o.username!==void 0?o.username+"@"+String(o.host??""):String(o.host??""));if(tc==="dual"){n_(o,i,r);return}let n=document.createElement("div");n.className="tt_sftpCard";let a=document.createElement("div");a.className="tt_sftpTitleRow";let f=document.createElement("div");f.className="tt_sshTitle",f.innerHTML=Jr+"<span></span>",f.lastElementChild.textContent="SFTP \xB7 "+i;let c=document.createElement("button");c.type="button",c.className="tt_close",c.title="\u5173\u95ED",c.innerHTML=ls,c.addEventListener("click",()=>yr(r)),a.appendChild(f),a.appendChild(c),n.appendChild(a);let p=document.createElement("div");p.className="tt_sftpBar";let g=document.createElement("input");g.type="text",g.className="tt_sftpPath",g.placeholder="\u8FDC\u7A0B\u8DEF\u5F84\uFF08\u56DE\u8F66\u8DF3\u8F6C\uFF09",g.spellcheck=!1,g.autocomplete="off";let S=document.createElement("button");S.type="button",S.className="tt_toolBtn",S.innerHTML=Nn+"<span>\u5237\u65B0</span>";let _=document.createElement("button");_.type="button",_.className="tt_toolBtn",_.innerHTML=Il+"<span>\u65B0\u5EFA\u76EE\u5F55</span>";let l=document.createElement("button");l.type="button",l.className="tt_toolBtn",l.innerHTML=vf+"<span>\u4E0A\u4F20</span>",l.title="\u9009\u62E9\u6587\u4EF6\u4E0A\u4F20\uFF1B\u4E5F\u53EF\u4EE5\u628A\u6587\u4EF6 / \u6587\u4EF6\u5939\u76F4\u63A5\u62D6\u8FDB\u5217\u8868";let d=document.createElement("input");d.type="file",d.multiple=!0,d.style.display="none",p.appendChild(g),p.appendChild(S),p.appendChild(_),p.appendChild(l),n.appendChild(p),n.appendChild(d);let h=document.createElement("div");h.className="tt_sftpEditor",h.style.display="none";let u=document.createElement("input");u.type="text",u.className="tt_cardInput",u.spellcheck=!1,u.autocomplete="off";let v=document.createElement("button");v.type="button",v.className="tt_toolBtn",v.textContent="\u786E\u5B9A";let y=document.createElement("button");y.type="button",y.className="tt_toolBtn",y.textContent="\u53D6\u6D88",h.appendChild(u),h.appendChild(v),h.appendChild(y),n.appendChild(h);let b=null,C=()=>{h.style.display="none",b=null};v.addEventListener("click",()=>{b?.()}),y.addEventListener("click",C),u.addEventListener("keydown",x=>{x.key==="Enter"?(x.preventDefault(),b?.()):x.key==="Escape"&&(x.stopPropagation(),C())});let m=document.createElement("div");m.className="tt_sftpList",n.appendChild(m);let E=document.createElement("div");E.className="tt_sftpFoot";let P=document.createElement("div");P.className="tt_sftpStatus";let B=dc();E.appendChild(B.el),E.appendChild(P),n.appendChild(E);let F={path:"",busy:!1},R=(x,O)=>{P.textContent=x,O===void 0?delete P.dataset.state:P.dataset.state=O},j=x=>{F.busy=x;for(let O of[S,_,l])O.disabled=x;g.disabled=x},A=async(x,O)=>{let H=await fetch("/api/dsh-tty/sftp/"+x,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({...o,...O})}),$=await H.json().catch(()=>({}));if(!H.ok||$.ok!==!0)throw new Error(String($.error||"HTTP "+H.status));return $},T=async(x,O)=>{if(!F.busy){j(!0),R(x,"busy");try{await O()}catch(H){R(String(H&&H.message?H.message:H),"error")}finally{j(!1)}}},W=(x,O,H,$)=>{let U=document.createElement("button");U.type="button",U.className="tt_sftpRow";let X=document.createElement("span");X.className="tt_sftpIcon",X.innerHTML=x,$!==void 0&&(X.dataset.kind=$);let ee=document.createElement("span");if(ee.className="tt_sftpName",ee.textContent=O,ee.title=O,U.appendChild(X),U.appendChild(ee),H!==""){let re=document.createElement("span");re.className="tt_sftpMeta",re.textContent=H,U.appendChild(re)}return U},D=(x,O,H,$)=>{let U=document.createElement("button");U.type="button",U.className="tt_sftpAct",U.innerHTML=O,U.title=H,U.addEventListener("click",X=>{X.stopPropagation(),$()}),x.appendChild(U)},w=(x,O,H)=>{let $=document.createElement("button");$.type="button",$.className="tt_sftpAct",$.innerHTML=_r,$.title="\u5220\u9664 "+O.name+(O.isDir?"\uFF08\u542B\u5185\u5BB9\uFF09":"");let U=null;$.addEventListener("click",X=>{if(X.stopPropagation(),!F.busy){if(U!==null){clearTimeout(U),U=null,$.innerHTML=_r,delete $.dataset.danger,T("\u5220\u9664 "+O.name+"\u2026",async()=>{await A("remove",{path:H,recursive:O.isDir===!0}),await k(F.path),R("\u5DF2\u5220\u9664 "+O.name)});return}$.textContent="\u786E\u8BA4?",$.dataset.danger="",U=setTimeout(()=>{U=null,$.innerHTML=_r,delete $.dataset.danger},4e3)}}),x.appendChild($)},L=x=>{if(m.textContent="",F.path!==""&&F.path!=="/"){let $=W(On,"..\uFF08\u4E0A\u7EA7\u76EE\u5F55\uFF09","","up");$.addEventListener("click",()=>{T("\u52A0\u8F7D\u4E2D\u2026",()=>k(hc(F.path)))}),m.appendChild($)}let O=Array.isArray(x)?x:[];if(O.length===0){let $=document.createElement("div");$.className="tt_addMenuTitle",$.textContent="\uFF08\u7A7A\u76EE\u5F55\uFF09",m.appendChild($);return}let H=500;for(let $ of O.slice(0,H)){if($===null||typeof $!="object"||typeof $.name!="string"||$.name==="")continue;let U=Wr(F.path,$.name),X=[];$.isDir===!0?X.push("\u76EE\u5F55"):X.push($e(Number($.size))||"\u2014");let ee=cc(Number($.mtime));ee!==""&&X.push(ee);let re=W($.isDir?Jr:$.isSymlink?Pl:Bl,$.name,X.join(" \xB7 "),$.isDir===!0?"dir":$.isSymlink===!0?"link":"file");$.isDir===!0?re.addEventListener("click",Q=>{Q.target instanceof Element&&Q.target.closest(".tt_sftpAct")!==null||T("\u52A0\u8F7D\u4E2D\u2026",()=>k(U))}):(re.addEventListener("click",Q=>{Q.target instanceof Element&&Q.target.closest(".tt_sftpAct")!==null||M($,U)}),D(re,Ol,"\u4E0B\u8F7D "+$.name,()=>{M($,U)})),D(re,In,"\u91CD\u547D\u540D "+$.name,()=>{u.placeholder="\u65B0\u540D\u79F0",u.value=$.name,h.style.display="",u.focus(),u.select(),b=async()=>{let Q=u.value.trim();Q===""||Q===$.name||(C(),await T("\u91CD\u547D\u540D "+$.name+"\u2026",async()=>{await A("rename",{from:U,to:Wr(F.path,Q)}),await k(F.path)}))}}),w(re,$,U),m.appendChild(re)}if(O.length>H){let $=document.createElement("div");$.className="tt_addMenuTitle",$.textContent=`\u2026\u5176\u4F59 ${String(O.length-H)} \u9879\u672A\u6E32\u67D3\uFF08\u5171 ${String(O.length)} \u9879\uFF09\u2014\u2014\u7528\u4E0A\u65B9\u8DEF\u5F84\u6846\u8DF3\u8F6C\u5230\u5B50\u76EE\u5F55\u5B9A\u4F4D`,m.appendChild($)}},k=async x=>{try{let O=await A("list",{path:x??F.path});F.path=typeof O.path=="string"&&O.path!==""?O.path:"/",g.value=F.path;let H=Array.isArray(O.entries)?O.entries.length:0;L(O.entries),R(F.path+" \u2014 "+String(H)+" \u9879")}catch(O){R(String(O&&O.message?O.message:O),"error")}},M=(x,O)=>T("\u4E0B\u8F7D "+x.name+"\u2026",async()=>{B.reset();let H;try{H=await uc("/api/dsh-tty/sftp/download",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({...o,path:O})},($,U)=>{B.set($,U)},Ht.maxDownloadMb,$=>B.setCancel($))}catch($){if(An($)){B.reset(),R("\u5DF2\u53D6\u6D88\u4E0B\u8F7D "+x.name);return}throw B.fail("\u4E0B\u8F7D\u5931\u8D25"),$}B.done("\u5B8C\u6210"),fc(H,x.name),setTimeout(()=>B.reset(),1500),R("\u5DF2\u4E0B\u8F7D "+x.name+"\uFF08"+($e(H.size)||String(H.size)+" B")+"\uFF09")}),z=(x,O,H,$,U)=>new Promise((X,ee)=>{let re=a_(JSON.stringify({...o,path:Wr(F.path,O)})),Q=new XMLHttpRequest;U.abort=()=>{U.stopped=!0,Q.abort()},Q.open("POST","/api/dsh-tty/sftp/upload"),Q.setRequestHeader("x-dsh-sftp-meta",re);let K=$>1?String(H)+"/"+String($)+" ":"";R("\u4E0A\u4F20 "+K+O,"busy"),Q.upload.addEventListener("progress",ie=>{ie.lengthComputable?B.set(ie.loaded,ie.total):B.pulse(0)});let J=!1,oe=ie=>{J||(J=!0,ie===null?X():ee(ie))};Q.addEventListener("load",()=>{if(Q.status===200){$===1&&B.done("\u4E0A\u4F20\u5B8C\u6210"),oe(null);return}if(U.stopped)return;B.fail("\u4E0A\u4F20\u5931\u8D25");let ie="HTTP "+Q.status;try{let he=JSON.parse(Q.responseText);he!==null&&typeof he=="object"&&typeof he.error=="string"&&(ie=he.error)}catch{}oe(new Error(ie))}),Q.addEventListener("error",()=>{if(U.stopped){oe(new Sr);return}B.fail("\u4E0A\u4F20\u5931\u8D25"),oe(new Error("\u7F51\u7EDC\u9519\u8BEF"))}),Q.addEventListener("abort",()=>{oe(new Sr)}),Q.send(x)}),q=async x=>T("\u4E0A\u4F20\u4E2D\u2026",async()=>{let O=Ht;if(O.maxUploadFiles>0&&x.length>O.maxUploadFiles){R("\u6587\u4EF6\u6570\u8D85\u8FC7\u4E0A\u9650\uFF08"+String(O.maxUploadFiles)+"\uFF09\uFF1A\u672C\u6B21 "+String(x.length)+" \u4E2A\uFF0C\u8BF7\u5206\u6279\u4E0A\u4F20","error"),B.fail("\u8D85\u9650");return}let H=O.maxUploadMb>0?O.maxUploadMb*1024*1024:0,$=x.find(Q=>H>0&&(Q.file?.size??0)>H);if($!==void 0){R("\u6587\u4EF6\u8D85\u8FC7\u4E0A\u4F20\u4E0A\u9650\uFF08"+$e(H)+"\uFF09\uFF1A"+String($.relPath??"")+"\uFF0C\u8BF7\u7528\u53CC\u680F \u21E8 \u76F4\u4F20\u6216\u7EC8\u7AEF scp/rsync","error"),B.fail("\u8D85\u9650");return}if(x._limitExceeded===!0){R("\u6587\u4EF6\u603B\u5927\u5C0F\u8D85\u8FC7\u4E0A\u4F20\u4E0A\u9650\uFF1A\u8BF7\u5206\u6279\u4E0A\u4F20\uFF08\u6216\u7528\u53CC\u680F \u21E8 \u76F4\u4F20\uFF09","error"),B.fail("\u8D85\u9650");return}let U=new Set;for(let Q of x){let K=Q.relPath.lastIndexOf("/");if(K<=0)continue;let J=Q.relPath.slice(0,K);U.has(J)||(U.add(J),await A("mkdir",{path:Wr(F.path,J),parents:!0}).catch(()=>{}))}B.reset();let X={stopped:!1,abort:null};B.setCancel(()=>X.abort?.());let ee=0,re=0;try{for(let Q of x){if(X.stopped)break;ee+=1,X.abort=null;try{await z(Q.file,Q.relPath,ee,x.length,X),re+=1}catch(K){if(An(K)||X.stopped)break;throw K}}}finally{B.setCancel(null)}if(X.stopped){B.reset(),R("\u5DF2\u53D6\u6D88\u4E0A\u4F20\uFF08\u5DF2\u4F20 "+String(re)+"/"+String(x.length)+" \u4E2A\uFF09"),await k(F.path);return}B.done("\u5168\u90E8\u5B8C\u6210"),setTimeout(()=>B.reset(),1500),R("\u4E0A\u4F20\u5B8C\u6210 "+String(x.length)+" \u4E2A\u6587\u4EF6"),await k(F.path)});S.addEventListener("click",()=>{T("\u52A0\u8F7D\u4E2D\u2026",()=>k(F.path))}),_.addEventListener("click",()=>{F.busy||(u.placeholder="\u65B0\u76EE\u5F55\u540D\uFF08\u76F8\u5BF9\u5F53\u524D\u76EE\u5F55\uFF09",u.value="",h.style.display="",u.focus(),b=async()=>{let x=u.value.trim();x!==""&&(C(),await T("\u521B\u5EFA\u76EE\u5F55 "+x+"\u2026",async()=>{await A("mkdir",{path:Wr(F.path,x)}),await k(F.path)}))})}),l.addEventListener("click",()=>{F.busy===!1&&d.click()}),d.addEventListener("change",()=>{let x=[...d.files??[]].map(O=>({relPath:O.name,file:O}));d.value="",x.length>0&&q(x)});let Y=0,Z=x=>{x?m.dataset.drag="":delete m.dataset.drag};n.addEventListener("dragenter",x=>{x.preventDefault(),Y+=1,Z(!0)}),n.addEventListener("dragover",x=>{x.preventDefault()}),n.addEventListener("dragleave",()=>{Y=Math.max(0,Y-1),Y===0&&Z(!1)}),n.addEventListener("drop",x=>{x.preventDefault(),Y=0,Z(!1),!F.busy&&c_(x.dataTransfer).then(O=>{(O.length>0||O._limitExceeded===!0)&&q(O)})}),g.addEventListener("keydown",x=>{if(x.key!=="Enter"||(x.preventDefault(),F.busy))return;let O=g.value.trim();O!==""&&T("\u52A0\u8F7D\u4E2D\u2026",()=>k(O))});let N=Wn();lc(n,"SFTP \xB7 "+i,N===null?340:Math.round(N.height*.46),r),T("\u8FDE\u63A5\u4E2D\u2026",()=>k(""))}function yr(e){let t=e===void 0?oc():e,r=Mt,s=pt!==null&&pt.ownerKey===t?pt:null;r===null&&s===null||(o_(),Mt=null,s!==null&&(pt=null),r!==null&&r.remove(),s!==null&&s.dispose())}function _c(){if(Ne===null)return;let e=Ne.style.display==="none"||Ne.style.display==="";Ne.style.display=e?"":"none";let t=se!==null?se.querySelector("[data-act=search]"):null;t!==null&&(e?t.dataset.on="":delete t.dataset.on),e&&Ne.focus()}var h_={matchBackground:"#3d2b00",matchBorder:"#8a5a00",activeMatchBackground:"#b06a00",activeMatchBorder:"#ffb84d",matchOverviewRuler:"#8a5a00",activeMatchColorOverviewRuler:"#ffb84d"};function d_(e){let t=Ze();if(t===void 0||t.search===void 0)return;let r=Ne.value;if(r==="")return;let s={decorations:h_};e?t.search.findPrevious(r,s):t.search.findNext(r,s)}function xl(){Qr||se===null&&!Hn()||qt!==null||(qt=setTimeout(()=>{qt=null,ss()},Kr),Kr=Math.min(Kr*2,5e3))}function ci(e){return e!==null&&typeof e=="object"&&e.persist===!0&&typeof e.persistName=="string"&&e.persistName!==""}function Dn(e){return ci(e)||e!==null&&typeof e=="object"&&typeof e.command=="string"&&e.command!==""}function u_(){return Nt==="tmux"?{t:"spawn",cwd:xn(),persist:!0,persistName:Un()}:{t:"spawn",cwd:xn()}}async function pc(){if(!wn){wn=!0;try{await f_()}finally{wn=!1}}}var wn=!1;async function f_(){if(await jn(),se===null){await p_();return}let e=Df(),t=Af();if(![...ne.values()].some(n=>n.embedded!==!0)){if(e.length>0||t.length>0){be({t:"sessions"});let n=await Qi("sessions",4e3),a=new Map;if(n!==null&&Array.isArray(n.list))for(let c of n.list)c!==null&&typeof c=="object"&&c.attachable===!0&&a.set(c.sid,c);let f=new Set;for(let c of e){if(a.has(c.sid))Wf(c);else if(Dn(c.spawnSpec))Sl(c);else continue;ci(c.spawnSpec)&&f.add(c.spawnSpec.persistName)}for(let c of t){let p=c.spawnSpec.persistName;f.has(p)||(Sl(c),f.add(p))}Ft()}if(![...ne.values()].some(n=>n.embedded!==!0)){if(await is())return;ei()}return}let r=[...ne.values()].filter(n=>!n.exited&&(n.embedded!==!0||n.spawned===!0)),s=r.filter(n=>Dn(n.spawnSpec)),o=null;if(s.length>0){be({t:"sessions"});let n=await Qi("sessions",4e3),a=new Set((n!==null&&Array.isArray(n.list)?n.list:[]).map(f=>f?.sid).filter(f=>typeof f=="string"));o=s.filter(f=>!a.has(f.sid));for(let f of o)es(f.sid)}let i=o!==null?new Set(o.map(n=>n.sid)):new Set;for(let n of r)i.has(n.sid)||be({t:"attach",sid:n.sid})}function __(){_e!==null&&(_e.readyState===WebSocket.OPEN||_e.readyState===WebSocket.CONNECTING)||ss()}async function p_(){let e=[...ne.values()].filter(s=>s.embedded===!0&&!s.exited);if(e.length===0)return;be({t:"sessions"});let t=await Qi("sessions",4e3),r=new Set((t!==null&&Array.isArray(t.list)?t.list:[]).map(s=>s?.sid).filter(s=>typeof s=="string"));for(let s of e)s.spawned===!0&&(r.has(s.sid)?be({t:"attach",sid:s.sid}):Dn(s.spawnSpec)?Xl(s):(s.exited=!0,s.live=!1,hr(s,"\u4F1A\u8BDD\u5DF2\u7ED3\u675F","\u70B9\u51FB\u91CD\u65B0\u6267\u884C","exited")))}function ss(){if(_e!==null){try{_e.close()}catch{}_e=null}Qr=!1,clearTimeout(qt),qt=null,Wi=!0,$i("\u8FDE\u63A5\u4E2D\u2026","");try{_e=new WebSocket(sf())}catch(e){Wi=!1,$i("\u8FDE\u63A5\u5931\u8D25\uFF1A"+e.message,"error"),xl();return}_e.onopen=()=>{Wi=!1,Kr=1e3,it=null,$i("\u5DF2\u8FDE\u63A5","connected");for(let e of[...Sn])Sn.delete(e),ne.has(e.tab.sid)&&be(e.frame);pc()},_e.onmessage=e=>{let t;try{t=JSON.parse(e.data)}catch{return}let r=t.sid;if(t.t==="ready"){let s=typeof t.target=="string"?t.target:"";vn(r,t.kind==="ssh"?"SSH "+(s!==""?s+" ":"")+"\u5DF2\u8FDE\u63A5":"\u5DF2\u8FDE\u63A5 pid="+t.pid,"connected");let o=ne.get(r);if(o!==void 0){if(o.exited=!1,o.spawned=!0,o.live=!0,o.errored=!1,o.target=s,o.persistTmux=t.persist===!0,t.kind==="ssh"&&s!==""&&!o.label&&(o.label=s,Ue()),Kt(),mn(r),hr(o,""),Cr(o),t.persist===!0){let i=document.fonts!==void 0&&document.fonts.ready!==void 0?document.fonts.ready:Promise.resolve();Promise.race([i,new Promise(n=>setTimeout(n,500))]).then(()=>ql(150))}ri(),Lf(r),Ft()}}else if(t.t==="sessions")Ff(t.list);else if(t.t==="data"){let s=ne.get(r);s!==void 0&&s.term!==null&&(s.term.write(String(t.d??"")),w_())}else if(t.t==="exit"){let s=ne.get(r);if(s!==void 0){s.exited=!0,s.live=!1,s.stats=null,r===me&&Xt();let o=t.code!==null&&t.code!==void 0?"code="+t.code:"",i=t.signal!==null&&t.signal!==void 0?"signal="+t.signal:"";vn(r,"\u5DF2\u9000\u51FA "+[o,i].filter(Boolean).join(" "),""),Kt(),mn(r),hr(s,"\u4F1A\u8BDD\u5DF2\u9000\u51FA","\u70B9\u51FB\u91CD\u65B0\u6253\u5F00","exited"),ri(),Ft()}}else if(t.t==="stats")try{let s=ne.get(r);if(s!==void 0){let o=t.stats;s.stats=_l(o)?o:null,s.statsAt=Date.now(),r===me&&Xt()}}catch(s){console.warn("[dsh-tty] stats \u5E27\u5904\u7406\u5931\u8D25\uFF08\u5DF2\u5FFD\u7565\uFF09: "+(s instanceof Error?s.message:String(s)))}else if(t.t==="error")if(vn(r,"\u9519\u8BEF\uFF1A"+String(t.m??""),"error"),typeof r=="string"){let s=ne.get(r);s!==void 0&&(s.live||(s.errored=!0),Kt(),mn(r),hr(s,"\u8FDE\u63A5\u51FA\u9519",String(t.m??"")+" \xB7 \u70B9\u51FB\u91CD\u8BD5","error"))}else g_("\u70B9\u51FB\u91CD\u8BD5")},_e.onclose=()=>{if(Wi=!1,!Qr){$i("\u8FDE\u63A5\u65AD\u5F00 \u2014 \u81EA\u52A8\u91CD\u8FDE\u4E2D","error");for(let e of ne.values())e.exited||hr(e,"\u8FDE\u63A5\u65AD\u5F00","\u81EA\u52A8\u91CD\u8FDE\u4E2D\u2026","info");xl()}},_e.onerror=()=>{}}function g_(e){pr!==null&&(pr.textContent=e)}function Bn(){(se===null||Ae)&&Pn()}function gc(){return typeof navigator<"u"&&navigator.clipboard!==void 0&&typeof navigator.clipboard.writeText=="function"}async function v_(e){if(gc())try{return await navigator.clipboard.writeText(e),!0}catch{}let t=document.createElement("textarea");t.value=e,t.style.position="fixed",t.style.opacity="0",document.body.appendChild(t),t.select();let r=!1;try{r=document.execCommand("copy")}catch{r=!1}return t.remove(),r||ai("\u590D\u5236\u5931\u8D25\uFF1A\u5F53\u524D\u73AF\u5883\u4E0D\u5141\u8BB8\u8BBF\u95EE\u526A\u8D34\u677F\uFF08http \u8BBF\u95EE\u65F6\u8BF7\u6539\u7528 localhost \u6216\u7EC8\u7AEF\u5185\u5FEB\u6377\u952E\uFF09","error"),r}async function m_(e){if(gc()&&typeof navigator.clipboard.readText=="function")try{let s=await navigator.clipboard.readText();return s!==""&&be({t:"input",sid:e.sid,d:s}),!0}catch{}let t=document.createElement("textarea");t.style.position="fixed",t.style.opacity="0",document.body.appendChild(t),t.focus();let r=!1;try{r=document.execCommand("paste");let s=r?t.value:"";s!==""&&be({t:"input",sid:e.sid,d:s})}catch{r=!1}return t.remove(),r||ai("\u6D4F\u89C8\u5668\u4E0D\u5141\u8BB8\u7F51\u9875\u8BFB\u53D6\u526A\u8D34\u677F\uFF08http \u8BBF\u95EE\u65F6\u5E38\u89C1\uFF09\uFF1A\u8BF7\u5728\u7EC8\u7AEF\u91CC\u6309 Ctrl+V / Cmd+V \u7C98\u8D34","error"),r}function Pn(){if(se!==null){Ae&&vc();return}si(),se=document.createElement("div"),se.className="tt_modalBackdrop",se.innerHTML='<div class="tt_modal"><div class="tt_header"><span class="tt_titleIcon">'+as+'</span><div class="tt_tabs"></div><div class="tt_status"><span class="tt_statusDot"></span><span class="tt_statusText">\u521D\u59CB\u5316\u2026</span></div><input class="tt_searchInput" style="display:none" placeholder="\u641C\u7D22 (Enter \u4E0B\u4E00\u4E2A, Shift+Enter \u4E0A\u4E00\u4E2A)" /><span class="tt_toolGroup"><button class="tt_toolBtn tt_iconBtn" data-act="search" title="\u641C\u7D22 (Ctrl+F)">'+lf+'</button><button class="tt_toolBtn tt_iconBtn" data-act="clear" title="\u6E05\u5C4F">'+cf+'</button><button class="tt_toolBtn tt_iconBtn" data-act="copy" title="\u590D\u5236\u9009\u4E2D\u5185\u5BB9">'+hf+'</button><button class="tt_toolBtn tt_iconBtn" data-act="paste" title="\u7C98\u8D34">'+df+'</button></span><span class="tt_winGroup"><button class="tt_min" title="\u6700\u5C0F\u5316\uFF08\u4F1A\u8BDD\u4FDD\u6301\u8FD0\u884C\uFF0C\u72B6\u6001\u5E76\u5165\u4FA7\u8FB9\u680F\u5165\u53E3\uFF09">'+pf+'</button><button class="tt_close" title="\u5173\u95ED\u9762\u677F\uFF08\u7ED3\u675F\u4F1A\u8BDD\uFF0C\u6807\u7B7E\u4FDD\u7559\uFF0C\u91CD\u5F00\u5373\u6062\u590D\u5217\u8868\uFF09">'+ls+'</button></span></div><div class="tt_connbar" data-hidden><div class="tt_connArea"><span class="tt_connDot"></span><span class="tt_connTarget">\u2014</span><span class="tt_connBadge"></span></div><div class="tt_connActions"></div></div><div class="tt_work"><div class="tt_body"><div class="tt_statsBar" hidden></div><div class="tt_overlay"></div></div></div></div>',document.body.appendChild(se),Vi=se.querySelector(".tt_status"),jt=se.querySelector(".tt_statusText"),Gt=se.querySelector(".tt_statusDot"),ut=se.querySelector(".tt_tabs"),zr=se.querySelector(".tt_connbar"),Ur=se.querySelector(".tt_connDot"),Gi=se.querySelector(".tt_connTarget"),Ye=se.querySelector(".tt_connBadge"),jr=se.querySelector(".tt_connActions"),Xe=se.querySelector(".tt_work"),ze=se.querySelector(".tt_body"),rt=se.querySelector(".tt_statsBar"),hs(),it=null,zl(),pr=se.querySelector(".tt_body > .tt_overlay"),Ne=se.querySelector(".tt_searchInput"),pr.addEventListener("click",()=>{pr.textContent="",ss()});let e=se.querySelector("[data-act=search]");e.addEventListener("click",()=>{_c(),Ne.style.display!=="none"&&Ne.focus()}),e.dataset.on="",Ne.addEventListener("keydown",t=>{t.key==="Enter"?(t.preventDefault(),d_(t.shiftKey)):t.key==="Escape"&&(t.stopPropagation(),Ne.style.display="none")}),se.querySelector("[data-act=clear]").addEventListener("click",()=>{let t=Ze();t!==void 0&&t.term!==null&&t.term.clear()}),se.querySelector("[data-act=copy]").addEventListener("click",()=>{let t=Ze();if(t===void 0||t.term===null)return;let r=t.term.getSelection();r!==""&&v_(r)}),se.querySelector("[data-act=paste]").addEventListener("click",()=>{let t=Ze();t!==void 0&&m_(t)}),se.querySelector(".tt_min").addEventListener("click",()=>{ns()}),se.querySelector(".tt_close").addEventListener("click",()=>{ii()}),se.addEventListener("mousedown",t=>{t.target===se&&ns()}),document.addEventListener("keydown",mc),qr=new ResizeObserver(()=>{Ae||(Ui(),Bf(Ze()))}),qr.observe(ze),Ue(),Kt(),_e!==null&&_e.readyState===WebSocket.OPEN?pc():ss()}function b_(){Pe=document.createElement("div"),Pe.className="tt_dock",Pe.title="\u70B9\u51FB\u6062\u590D\u7EC8\u7AEF\u7A97\u53E3",Pe.innerHTML='<span class="tt_dockTitle">'+as+'<span>\u7EC8\u7AEF</span><span class="tt_dockCount"></span></span><span class="tt_dockStatus"></span><span class="tt_dockDot"></span><button class="tt_dockClose" title="\u5173\u95ED\u9762\u677F\uFF08\u7ED3\u675F\u4F1A\u8BDD\uFF0C\u6807\u7B7E\u4FDD\u7559\uFF0C\u91CD\u5F00\u5373\u6062\u590D\u5217\u8868\uFF09">\u2715</button>',Yi=Pe.querySelector(".tt_dockCount"),wr=Pe.querySelector(".tt_dockStatus"),Yt=Pe.querySelector(".tt_dockDot");let e=[...ne.values()].filter(t=>!t.exited).length;Yi.textContent=ne.size>0?"\xB7 "+e+"/"+ne.size:"",jt!==null&&(wr.textContent=jt.textContent),Gt!==null&&(Yt.dataset.state=Gt.dataset.state??""),Pe.addEventListener("click",t=>{if(t.target.closest(".tt_dockClose")!==null){t.stopPropagation(),ii();return}vc()}),document.body.appendChild(Pe)}function ns(){se===null||Ae||(ft(),Ot(),Ae=!0,Mt!==null&&(Mt.style.display="none"),Ne!==null&&(Ne.style.display="none"),se.dataset.minimized="",Ul(),li(),Xt(),document.querySelector("[data-dsh-tty-entry]")!==null?ri():(b_(),Pe.classList.add("tt_dockCompact")))}function ri(){let e=document.querySelector("[data-dsh-tty-entry]");if(e===null)return;let t=e.querySelector(".tt_sidebarEntryBadge");if(!Ae){t!==null&&t.remove(),delete e.dataset.minimized,e.removeAttribute("title");return}t===null&&(t=document.createElement("span"),t.className="tt_sidebarEntryBadge",t.innerHTML='<span class="tt_sidebarBadgeDot"></span><span class="tt_sidebarBadgeCount"></span>',e.appendChild(t)),e.dataset.minimized="",e.title="\u7EC8\u7AEF\u5DF2\u6700\u5C0F\u5316 \u2014 \u70B9\u51FB\u6062\u590D";let r=[...ne.values()].filter(o=>!o.exited).length;t.querySelector(".tt_sidebarBadgeCount").textContent=r+"/"+ne.size;let s=t.querySelector(".tt_sidebarBadgeDot");s!==null&&Gt!==null&&(s.dataset.state=Gt.dataset.state??"")}function w_(){if(!Ae)return;let e=document.querySelector("[data-dsh-tty-entry] .tt_sidebarBadgeDot")??Yt;e!==null&&(e.dataset.active="",clearTimeout(Xi),Xi=setTimeout(()=>{delete e.dataset.active},900))}function vc(){if(se===null||!Ae)return;Ae=!1,delete se.dataset.minimized,Mt!==null&&(Mt.style.display=""),clearTimeout(Xi),Pe!==null&&(Pe.remove(),Pe=null),Yi=null,wr=null,Yt=null,ri(),zl(),li(),Xt();let e=Ze();if(e!==void 0&&e.fit!==void 0){try{e.fit.fit()}catch{}e.spawned&&!e.exited&&Cr(e)}e!==void 0&&e.term!==null&&e.term.focus()}function ii(){if(se===null)return;Yr(!0);let e=Hn();if(Qr=!e,Ae=!1,ft(),ji(),ts(),Ot(),yr(),clearTimeout(Xi),clearTimeout(qt),qt=null,Kr=1e3,Pe!==null&&(Pe.remove(),Pe=null),Yi=null,wr=null,Yt=null,ri(),_e!==null){for(let t of ne.values())!t.exited&&t.embedded!==!0&&be({t:"kill",sid:t.sid});if(!e){try{_e.close()}catch{}_e=null}}qr!==null&&(qr.disconnect(),qr=null);for(let[t,r]of[...ne])if(r.embedded!==!0){if(r.term!==null)try{r.term.dispose()}catch{}ne.delete(t)}me=null,Zr=null,document.removeEventListener("keydown",mc),se.remove(),se=null,Xe=null,Vi=null,jt=null,Gt=null,ut=null,zr=null,Ur=null,Gi=null,Ye=null,jr=null,ts(),Ul(),rt=null,hs(),it=null,ze=null,pr=null,Ne=null,oi=0;try{sessionStorage.removeItem(Ji)}catch{}}function mc(e){if(e.key==="Escape"&&se!==null){if(e.preventDefault(),Mt!==null){yr();return}if(gr!==null){Ot();return}if(Je!==null){ft();return}ns()}}function S_(){let e=document.querySelector('[data-pane="sidebar"], [class*="sidebarCol"]');if(e!==null)return e.querySelector('[class*="logoRow"]')?.parentElement??e.firstElementChild}function y_(e){let t=e.querySelector('button[class*="newSession"]');if(t!==null)return t;for(let r of e.children)if(r.tagName==="BUTTON")return r}function C_(){let e=document.createElement("div");return e.dataset.dshTtyEntry="",e.className="tt_sidebarEntry",e.setAttribute("role","button"),e.setAttribute("aria-label","\u7EC8\u7AEF"),e.tabIndex=0,e.innerHTML='<span class="tt_sidebarEntryIcon">'+as+'</span><span class="tt_sidebarEntryLabel">\u7EC8\u7AEF</span>',e.addEventListener("click",t=>{t.preventDefault(),Pn()}),e.addEventListener("keydown",t=>{(t.key==="Enter"||t.key===" "||t.key==="Spacebar")&&(t.preventDefault(),Pn())}),e}function kl(e,t){let r=y_(e);if(r===void 0)return!1;if(t.parentElement!==e){let s=r.closest('[class*="logoRow"]'),o=s!==null&&s.parentElement===e?s:r,i=Array.from(e.children).filter(n=>n instanceof HTMLElement&&n.matches("[data-dsh-global-search-entry], [data-dsh-rss-entry], [data-dsh-taskboard-entry], [data-dsh-ssh-entry], [data-dsh-tty-entry]"));if(i.length>0){let n=i[i.length-1];e.insertBefore(t,n.nextSibling)}else e.insertBefore(t,o.nextElementSibling)}return!0}function x_(){if(si(),typeof document<"u"&&document.querySelector("[data-dsh-tty-entry]")!==null)return()=>{};let e=C_(),t,r=!1,s=()=>{if(t!==void 0&&!t.isConnected&&(i.disconnect(),t=void 0,r=!1),r){if(document.body.contains(e))return;i.disconnect(),t=void 0,r=!1}t??(t=S_()),t!==void 0&&(r=kl(t,e),r&&i.observe(t,{childList:!0,subtree:!0}))},o=new MutationObserver(()=>{s()});o.observe(document.body,{childList:!0,subtree:!0});let i=new MutationObserver(()=>{if(t===void 0||!t.isConnected){r=!1,s();return}t.contains(e)||(r=kl(t,e))});return s(),()=>{o.disconnect(),i.disconnect(),e.remove()}}window.__ModuleLoader__.load({id:"@hyzyn/dsh-tty",factory:e=>{let t={},r=e("react"),{jsx:s,jsxs:o}=e("react/jsx-runtime"),i="M11.8486 5.5L11.4238 5.92383L8.69727 8.65137C8.44157 8.90706 8.21562 9.13382 8.01172 9.29785C7.79912 9.46883 7.55595 9.61756 7.25 9.66602C7.08435 9.69222 6.91565 9.69222 6.75 9.66602C6.44405 9.61756 6.20088 9.46883 5.98828 9.29785C5.78438 9.13382 5.55843 9.13382 5.30273 8.65137L2.57617 5.92383L2.15137 5.5L3 4.65137L3.42383 5.07617L6.15137 7.80273C6.42595 8.07732 6.59876 8.24849 6.74023 8.3623C6.87291 8.46904 6.92272 8.47813 6.9375 8.48047C6.97895 8.48703 7.02105 8.48703 7.0625 8.48047C7.07728 8.47813 7.12709 8.46904 7.25977 8.3623C7.40124 8.24849 7.57405 8.07732 7.84863 7.80273L10.5762 5.07617L11 4.65137L11.8486 5.5Z";function n(f){let c=f&&f.view,p=c==="page",[g,S]=r.useState(p),[_,l]=r.useState(null),[d,h]=r.useState(!1),[u,v]=r.useState(!1),[y,b]=r.useState({kind:"",text:""}),[C,m]=r.useState([]),[E,P]=r.useState(!1),B=I=>s("div",{className:"tt_cardSection",children:I}),F=async()=>{try{let V=await(await fetch("/api/dsh-tty/config",{cache:"no-store"})).json();V.ok&&typeof V.config=="object"&&V.config!==null?(l(V.config),ti(V.config)):b({kind:"error",text:String(V.error||"\u8BFB\u53D6\u914D\u7F6E\u5931\u8D25")})}catch(I){b({kind:"error",text:String(I&&I.message?I.message:I)})}},R=async()=>{try{let V=await(await fetch("/api/dsh-tty/shells",{cache:"no-store"})).json();V.ok&&Array.isArray(V.shells)&&m(V.shells)}catch{}};r.useEffect(()=>{g&&!d&&(h(!0),F(),R())},[g]);let j=(I,V)=>l(G=>({...G||{},[I]:V})),A=(I,V)=>l(G=>({...G||{},sftpLimits:{...G?.sftpLimits??{},[I]:V}})),[T,W]=r.useState(null),[D,w]=r.useState(null),[L,k]=r.useState(""),[M,z]=r.useState(null),[q,Y]=r.useState(""),[Z,N]=r.useState(""),[x,O]=r.useState(""),H=r.useRef(null),[$,U]=r.useState(!1),[X,ee]=r.useState({text:"",kind:""}),[re,Q]=r.useState(!1),[K,J]=r.useState({running:!1,ok:!1,text:""}),[oe,ie]=r.useState({}),[he,Ce]=r.useState([]),[de,ve]=r.useState({direction:"local",localPort:"",remoteHost:"",remotePort:"",localTargetPort:"",bookName:""}),[pe,Oe]=r.useState(null);r.useEffect(()=>{if(!g)return;let I=!0,V=async()=>{try{let ae=await(await fetch("/api/dsh-tty/tunnels",{cache:"no-store"})).json();I&&ae.ok&&Array.isArray(ae.tunnels)&&Ce(ae.tunnels)}catch{}};V();let G=setInterval(V,2e3);return()=>{I=!1,clearInterval(G)}},[g]);let je=I=>V=>ve(G=>({...G||{},[I]:V.target.value})),Qe=(I,V)=>ve(G=>({...G||{},[I]:V})),Jt=I=>I?.direction==="remote"?`\u8FDC\u7A0B:${I.remoteHost||"127.0.0.1"}:${String(I.remotePort??0)} \u2192 \u672C\u673A:${String(I.localTargetPort??0)}`:`\u672C\u673A:${String(I?.localPort??0)} \u2192 ${I?.remoteHost??"?"}:${String(I?.remotePort??0)}`,et=(_?.sshHosts??[]).find(I=>I?.name===de?.bookName),gt=async I=>{try{let V=await fetch("/api/dsh-tty/config",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({tunnels:I})}),G=await V.json().catch(()=>({}));return!V.ok||!G.ok?(b({kind:"error",text:String(G.error||"\u4FDD\u5B58\u96A7\u9053\u5931\u8D25")}),!1):!0}catch(V){return b({kind:"error",text:String(V&&V.message?V.message:V)}),!1}},ue=()=>sl(de,(Array.isArray(_?.sshHosts)?_.sshHosts:[]).map(I=>I?.name)),fs=I=>{b({kind:"",text:""}),Oe(String(I?.name??"")),ve({direction:I?.direction==="remote"?"remote":"local",bookName:String(I?.bookName??""),localPort:I?.localPort?String(I.localPort):"",remoteHost:String(I?.remoteHost??""),remotePort:I?.remotePort?String(I.remotePort):"",localTargetPort:I?.localTargetPort?String(I.localTargetPort):""})},bc=()=>{Oe(null),b({kind:"",text:""}),ve(I=>({...I||{},localPort:"",remoteHost:"",remotePort:"",localTargetPort:""}))},wc=()=>{b({kind:"",text:""});let I=ue();if(!I.ok){b({kind:"error",text:I.error});return}let V=I.tunnel,G=Array.isArray(_?.tunnels)?_.tunnels:[];if(nl(G,V.name)!==void 0){b({kind:"error",text:`\u5DF2\u5B58\u5728\u540C\u540D\u96A7\u9053\u300C${V.name}\u300D\u2014\u2014\u540C\u4E00\u300C\u8FDE\u63A5\u7C3F\u6761\u76EE + \u65B9\u5411 + \u7AEF\u53E3\u300D\u53EA\u80FD\u6709\u4E00\u6761\u3002\u6539\u7AEF\u53E3\u4F1A\u5F97\u5230\u65B0\u540D\u5B57\uFF0C\u6216\u5148\u5220\u6389\u65E7\u7684\u90A3\u6761\u3002`});return}let te=[...G,V];l(ae=>({...ae||{},tunnels:te})),ve(ae=>({...ae||{},localPort:"",remoteHost:"",remotePort:"",localTargetPort:""})),gt(te).then(ae=>{ae&&b({kind:"ok",text:`\u96A7\u9053\u300C${V.name}\u300D\u5DF2\u751F\u6548`})})},Sc=()=>{if(pe===null)return;b({kind:"",text:""});let I=ue();if(!I.ok){b({kind:"error",text:I.error});return}let V=Array.isArray(_?.tunnels)?_.tunnels:[],G=ol(V,pe,I.tunnel);if(!G.ok){G.error.includes("\u5DF2\u4E0D\u5B58\u5728")&&Oe(null),b({kind:"error",text:G.error});return}let te=G.tunnels;l(ae=>({...ae||{},tunnels:te})),gt(te).then(ae=>{if(ae!==!0){l(le=>({...le||{},tunnels:V}));return}Oe(null),ve(le=>({...le||{},localPort:"",remoteHost:"",remotePort:"",localTargetPort:""})),b({kind:"ok",text:`\u96A7\u9053\u300C${I.tunnel.name}\u300D\u5DF2\u66F4\u65B0`})})},qn=(I,V)=>{l(G=>({...G||{},tunnels:I})),gt(I).then(G=>{G!==!0&&l(te=>({...te||{},tunnels:V}))})},yc=I=>{let V=Array.isArray(_?.tunnels)?_.tunnels:[];pe!==null&&String(I??"")===pe&&(Oe(null),ve(G=>({...G||{},localPort:"",remoteHost:"",remotePort:"",localTargetPort:""}))),qn(V.filter(G=>G?.name!==I),V)},Cc=(I,V)=>{let G=Array.isArray(_?.tunnels)?_.tunnels:[];qn(G.map(te=>te?.name===I?{...te,enabled:V}:te),G)},xc=I=>{W(I?.name??null),k(""),J({running:!1,ok:!1,text:""}),Y(""),N(""),_s(),U(_t!==null),w({name:I?.name??"",host:I?.host??"",port:String(I?.port??22),username:I?.username??"",auth:I?.auth==="key"||I?.auth==="password"?I.auth:"agent",keyPath:I?.keyPath??"",passphrase:I?.passphrase??"",password:I?.password??"",agentForward:I?.agentForward===!0,persist:I?.persist!==!1}),Ml().then(V=>z(V)),ps(I?.password??"")},Kn=()=>{W(null),w(null),k(""),J({running:!1,ok:!1,text:""}),Y(""),N(""),_s()},kc=async()=>{if(D===null)return;let I=D.name.trim(),V=D.host.trim(),G=D.username.trim();if(I===""||V===""||G===""){k("\u540D\u79F0\u3001\u4E3B\u673A\u3001\u7528\u6237\u540D\u5FC5\u586B");return}let te=Number(D.port);if((!Number.isInteger(te)||te<1||te>65535)&&(te=22),(_?.sshHosts??[]).some(le=>le?.name===I&&I!==T)){k("\u8FDE\u63A5\u7C3F\u91CC\u5DF2\u6709\u540C\u540D\u6761\u76EE: "+I);return}if(D.auth==="key"&&D.keyPath.trim()===""){k("auth=key \u9700\u8981\u79C1\u94A5\u8DEF\u5F84");return}k("");let ae=D.password;if(D.auth==="password"){let le=await Al($,D.password,V,te,G,"PASSWORD");if(le.error!==void 0){k(le.error);return}le.value!==void 0&&(ae=le.value)}l(le=>({...le||{},sshHosts:(Array.isArray(le?.sshHosts)?le.sshHosts:[]).map(we=>we?.name===T?{name:I,host:V,port:te,username:G,auth:D.auth,keyPath:D.keyPath.trim(),passphrase:D.passphrase,password:ae,agentForward:D.agentForward,persist:D.persist===!0}:we)})),ie(le=>{let we={...le};return delete we[I],T!==I&&delete we[T],we}),W(null),w(null),J({running:!1,ok:!1,text:""}),b({kind:"ok",text:"\u5DF2\u4FEE\u6539\u6761\u76EE\u300C"+I+"\u300D\u2014 \u968F\u300C\u4FDD\u5B58\u300D\u5199\u5165\u914D\u7F6E"})},Ec=I=>{T===I&&Kn(),ie(V=>{let G={...V};return delete G[I],G}),l(V=>({...V||{},sshHosts:(Array.isArray(V?.sshHosts)?V.sshHosts:[]).filter(G=>G?.name!==I)}))},Lc=async I=>{let V=I?.name??"";if(V==="")return;let G={host:I?.host??"",port:Number(I?.port)||22,username:I?.username??"",auth:I?.auth==="key"||I?.auth==="password"?I.auth:"agent",keyPath:I?.keyPath??"",passphrase:I?.passphrase??"",password:I?.password??"",agentForward:I?.agentForward===!0};ie(ae=>({...ae,[V]:{running:!0,text:"\u8FDE\u63A5\u6D4B\u8BD5\u4E2D\u2026"}}));let te=await Ln(G,!0);ie(ae=>{let le=ae[V]||{};if(te.result){let we=te.result.auth?.ok===!0;return{...ae,[V]:{running:!1,ok:we,text:Mn(te.result)}}}return{...ae,[V]:{running:!1,ok:!1,text:"\u274C \u8FDE\u63A5\u5931\u8D25\uFF1A"+String(te.error||"\u672A\u77E5\u9519\u8BEF")}}})},Mc=async I=>{let V=(Array.isArray(_?.hostKeys)?_.hostKeys:[]).filter(G=>!(G?.host===I?.host&&Number(G?.port)===Number(I?.port)));l(G=>({...G||{},hostKeys:V}));try{let G=await fetch("/api/dsh-tty/config",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({hostKeys:V})}),te=await G.json().catch(()=>({}));!G.ok||!te.ok?b({kind:"error",text:String(te.error||"\u5220\u9664\u4E3B\u673A\u5BC6\u94A5\u8BB0\u5F55\u5931\u8D25")}):b({kind:"ok",text:"\u5DF2\u5220\u9664\u4E3B\u673A\u5BC6\u94A5\u8BB0\u5F55\uFF08\u4E0B\u6B21\u8FDE\u63A5\u91CD\u65B0\u8BB0\u5F55\u6307\u7EB9\uFF09"})}catch(G){b({kind:"error",text:String(G&&G.message?G.message:G)})}},Rc=async()=>{b({kind:"",text:""});try{let V=await(await fetch("/api/dsh-tty/ssh-config",{cache:"no-store"})).json();if(!V.ok){b({kind:"error",text:String(V.error||"\u8BFB\u53D6 ~/.ssh/config \u5931\u8D25")});return}let G=Array.isArray(V.entries)?V.entries:[],te=[...Array.isArray(_?.sshHosts)?_.sshHosts:[]],ae=new Set(te.map(ce=>ce?.name)),le=0,we=0;for(let ce of G)if(!(ce===null||typeof ce!="object"||typeof ce.name!="string")){if(ae.has(ce.name)){we+=1;continue}ae.add(ce.name),te.push({name:ce.name,host:String(ce.host??ce.name),port:Number(ce.port)||22,username:String(ce.username??""),auth:ce.auth==="key"?"key":"agent",keyPath:String(ce.keyPath??""),passphrase:"",password:"",agentForward:!1}),le+=1}l(ce=>({...ce||{},sshHosts:te})),b(le===0?{kind:"ok",text:we>0?`\u6CA1\u6709\u65B0\u6761\u76EE\uFF08${we} \u6761\u540C\u540D\u8DF3\u8FC7\uFF09`:"~/.ssh/config \u91CC\u6CA1\u6709\u53EF\u5BFC\u5165\u7684\u5177\u4F53\u4E3B\u673A"}:{kind:"ok",text:`\u5DF2\u5BFC\u5165 ${le} \u6761\uFF08\u540C\u540D\u8DF3\u8FC7 ${we} \u6761\uFF09\uFF0C\u968F\u300C\u4FDD\u5B58\u300D\u5199\u5165\u914D\u7F6E`})}catch(I){b({kind:"error",text:String(I&&I.message?I.message:I)})}},Vn=I=>I===null||typeof I!="object"?[]:Array.isArray(I.fingerprints)?I.fingerprints.filter(V=>typeof V=="string"&&V!==""):typeof I.fingerprint=="string"&&I.fingerprint!==""?[I.fingerprint]:[],Tc=async()=>{b({kind:"",text:""});try{let V=await(await fetch("/api/dsh-tty/known-hosts",{cache:"no-store"})).json();if(!V.ok){b({kind:"error",text:String(V.error||"\u8BFB\u53D6 ~/.ssh/known_hosts \u5931\u8D25")});return}let G=Array.isArray(V.entries)?V.entries:[],te=[...Array.isArray(_?.hostKeys)?_.hostKeys:[]],ae=new Map;for(let ce of te)ce===null||typeof ce!="object"||ae.set(String(ce.host??"")+":"+String(ce.port??22),{record:ce,fps:new Set(Vn(ce))});let le=0,we=0;for(let ce of G){if(ce===null||typeof ce!="object"||typeof ce.host!="string")continue;let vt=Array.isArray(ce.fingerprints)?ce.fingerprints.filter(Mr=>typeof Mr=="string"&&Mr!==""):[];if(typeof ce.fingerprint=="string"&&ce.fingerprint!==""&&vt.push(ce.fingerprint),vt.length===0)continue;let Xn=ce.host+":"+String(ce.port??22),$t=ae.get(Xn);if($t!==void 0){let Mr=!1;for(let Jn of vt)$t.fps.has(Jn)||$t.fps.size>=8||($t.fps.add(Jn),Mr=!0);if(!Mr){we+=1;continue}delete $t.record.fingerprint,$t.record.fingerprints=[...$t.fps],le+=1;continue}let gs={host:ce.host,port:Number(ce.port)||22,fingerprints:[...new Set(vt)].slice(0,8)};ae.set(Xn,{record:gs,fps:new Set(gs.fingerprints)}),te.push(gs),le+=1}if(le===0){b({kind:"ok",text:we>0?`\u6CA1\u6709\u65B0\u6307\u7EB9\uFF08${we} \u6761\u5DF2\u5B58\u5728\uFF09`:"known_hosts \u91CC\u6CA1\u6709\u53EF\u5BFC\u5165\u7684\u5177\u4F53\u4E3B\u673A"});return}l(ce=>({...ce||{},hostKeys:te}));try{let ce=await fetch("/api/dsh-tty/config",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({hostKeys:te})}),vt=await ce.json().catch(()=>({}));if(!ce.ok||!vt.ok){b({kind:"error",text:String(vt.error||"\u4FDD\u5B58 hostKeys \u5931\u8D25")});return}b({kind:"ok",text:`\u5DF2\u5BFC\u5165 ${le} \u6761\u4E3B\u673A\u7684\u6307\u7EB9\uFF08\u8DF3\u8FC7 ${we} \u6761\u5DF2\u5B58\u5728\uFF09`+(V.truncated===!0?"\uFF1B\u6CE8\u610F\uFF1Aknown_hosts \u8D85\u8FC7 500 \u6761\u4E3B\u673A\uFF0C\u672C\u6B21\u4EC5\u5BFC\u5165\u524D 500 \u6761":"")})}catch(ce){b({kind:"error",text:String(ce&&ce.message?ce.message:ce)})}}catch(I){b({kind:"error",text:String(I&&I.message?I.message:I)})}},Ac=async()=>{v(!0),b({kind:"",text:""});let I={};for(let V of["enabled","announceToAgent","maxSessions","shell","term","colorTerm","cwd","reconnectGraceSec","shellIntegration","sftpStyle","persistence","endOnPageClose","statsEnabled"]){let G=(_||{})[V];G!==void 0&&G!==""&&(I[V]=G)}I.sshHosts=Array.isArray(_?.sshHosts)?_.sshHosts:[],I.tunnels=Array.isArray(_?.tunnels)?_.tunnels:[],_?.sftpLimits&&typeof _.sftpLimits=="object"&&(I.sftpLimits={maxDownloadMb:Number(_.sftpLimits.maxDownloadMb)||0,maxUploadMb:Number(_.sftpLimits.maxUploadMb)||0,maxUploadFiles:Number(_.sftpLimits.maxUploadFiles)||0});try{let V=await fetch("/api/dsh-tty/config",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(I)}),G=await V.json();!V.ok||!G.ok?b({kind:"error",text:String(G.error||"\u4FDD\u5B58\u5931\u8D25")}):(b({kind:"ok",text:"\u5DF2\u4FDD\u5B58\u5E76\u70ED\u751F\u6548"}),G.config&&(l(G.config),ti(G.config)))}catch(V){b({kind:"error",text:String(V&&V.message?V.message:V)})}v(!1)},_s=()=>{H.current!==null&&(clearTimeout(H.current),H.current=null),O("")},ps=async I=>{let V=fr(I);if(br()===null){U(!1),Q(!1),ee({text:_t===null?"\u5BBF\u4E3B\u672A\u63D0\u4F9B\u51ED\u636E\u670D\u52A1\uFF08remote.credentials\uFF09\uFF0C\u53EA\u80FD\u660E\u6587\u4FDD\u5B58":"\u51ED\u636E\u670D\u52A1\u4E0D\u5B8C\u6574\uFF0C\u53EA\u80FD\u660E\u6587\u4FDD\u5B58",kind:"muted"});return}if(V===""){Q(!1),ee({text:"",kind:""});return}let G=await Rl(V);if(G.unreported===!0){Q(!1),ee({text:"\u5F15\u7528 "+V+"\uFF1A\u5BBF\u4E3B\u672A\u62A5\u544A\u72B6\u6001",kind:"plain"});return}if(G.error!==void 0){Q(!1),ee({text:"\u8BFB\u53D6\u51ED\u636E\u72B6\u6001\u5931\u8D25\uFF1A"+G.error,kind:"error"});return}let te=G.view;ee({text:te.configured?"\u5DF2\u5B58\u5165"+(te.source!==""?"\uFF08\u6765\u6E90 "+te.source+"\uFF09":"")+" \xB7 "+V:"\u5F15\u7528 "+V+"\uFF1A\u5B58\u50A8\u91CC\u8FD8\u6CA1\u6709\u8FD9\u4E2A\u503C",kind:te.configured?"ok":"plain"}),Q(te.configured===!0&&te.writable===!0)},Dc=async()=>{let I=fr(D?.password??"");if(I==="")return;let V=await Tl(I);if(V.error!==void 0){ee({text:V.error,kind:"error"});return}w(G=>({...G||{},password:""})),ee({text:"",kind:""}),Q(!1)},Bc=(I,V)=>{let G=String(D?.[I]??"");if(G===""||G.startsWith("env:")||x===V){_s(),w(te=>({...te||{},[I]:"env:"+V})),Y(""),I==="password"&&ps("env:"+V);return}O(V),H.current!==null&&clearTimeout(H.current),H.current=setTimeout(()=>{H.current=null,O("")},4e3)},Gn=(I,V)=>{if(M===null)return null;if(M.length===0)return s("span",{className:"tt_cardHint",children:V});let G=q===I,te=Z.trim().toUpperCase(),ae=te===""?M:M.filter(le=>le.toUpperCase().includes(te));return o("div",{className:"tt_credPicker",children:[s("input",{className:"tt_cardInput",value:G?Z:"",placeholder:"\u6216\uFF1A\u9009\u62E9\u51ED\u636E\u5B58\u50A8\u91CC\u7684\u5F15\u7528\u540D",title:"\u5019\u9009 = \u51ED\u636E\u5B58\u50A8\u91CC\u5DF2\u6709\u7684\u5F15\u7528\u540D + \u672C\u673A\u8FDE\u63A5\u7C3F\u91CC\u5728\u7528\u7684\u5F15\u7528\u540D",autoComplete:"off",spellCheck:!1,onFocus:()=>{Y(I),N("")},onBlur:le=>{le.currentTarget.parentElement.contains(le.relatedTarget)||Y("")},onChange:le=>{N(le.target.value),Y(I)}}),...G?[s("div",{className:"tt_envList",children:[...ae.length===0?[s("span",{className:"tt_envMore",children:"\u6CA1\u6709\u5339\u914D\u7684\u5F15\u7528"})]:ae.slice(0,30).map(le=>s("button",{type:"button",className:"tt_envItem","data-danger":x===le?"":void 0,onMouseDown:we=>we.preventDefault(),onClick:()=>Bc(I,le),children:x===le?le+"\uFF08\u518D\u70B9\u8986\u76D6\u5DF2\u586B\uFF09":le},le)),...ae.length>30?[s("span",{className:"tt_envMore",children:"\u8FD8\u6709 "+(ae.length-30)+" \u4E2A \u2014 \u7EE7\u7EED\u8F93\u5165\u7B5B\u9009"})]:[]]},"cred-list-"+I)]:[]]})},Pc=()=>{let V=fr(D?.password??"")!=="",G=br()===null;return o("div",{className:"tt_sshRow tt_credRow",children:[V?s("button",{type:"button",className:"tt_toolBtn tt_credClear",disabled:re!==!0,onClick:()=>{Dc()},children:"\u6E05\u9664\u5DF2\u5B58\u51ED\u636E"}):s("label",{className:"tt_credToggle",title:"\u52FE\u9009\u540E\uFF0C\u70B9\u300C\u5E94\u7528\u300D\u65F6\u628A\u5BC6\u7801\u5199\u8FDB\u5B98\u65B9\u51ED\u636E\u5B58\u50A8\uFF0C\u5B57\u6BB5\u91CC\u53EA\u7559 env: \u5F15\u7528\uFF08\u503C\u5728 ~/.dsh/.credentials.yaml\uFF0C\u4E0D\u8FDB\u73AF\u5883\u3001\u4E0D\u56DE\u4F20\u6D4F\u89C8\u5668\uFF1B\u6321\u4E0D\u4F4F\u540C\u7528\u6237\u8FDB\u7A0B\u4E0E agent\uFF09\u3002\u4E0D\u52FE\u9009\u5219\u6309\u73B0\u72B6\u660E\u6587\u5199\u8FDB\u8BBE\u7F6E\u6587\u4EF6\u3002\u80FD\u7528\u5BC6\u94A5 / agent \u5C31\u522B\u5B58\u5BC6\u7801\u3002",children:[s("input",{type:"checkbox",className:"tt_cardCheckbox",checked:$,disabled:G,onChange:te=>U(te.target.checked)}),s("span",{children:"\u5E94\u7528\u65F6\u5B58\u5165\u51ED\u636E\u5B58\u50A8"})]}),X.text===""?null:s("span",{className:"tt_credStatus","data-kind":X.kind,children:X.text}),G&&X.text===""?s("span",{className:"tt_credStatus","data-kind":"muted",children:"\u5BBF\u4E3B\u672A\u63D0\u4F9B\u51ED\u636E\u670D\u52A1\uFF08remote.credentials\uFF09\uFF0C\u53EA\u80FD\u660E\u6587\u4FDD\u5B58"}):null]})},Yn=()=>{let I=String(D?.host??"").trim(),V=String(D?.username??"").trim(),G=Number(D?.port);if((!Number.isInteger(G)||G<1||G>65535)&&(G=22),I===""||V==="")return k("\u4E3B\u673A\u4E0E\u7528\u6237\u540D\u5FC5\u586B"),null;let te=D?.auth,ae={host:I,port:G,username:V,auth:te};if(te==="key"){let le=String(D?.keyPath??"").trim();if(le==="")return k("auth=key \u9700\u8981\u79C1\u94A5\u8DEF\u5F84"),null;ae.keyPath=le,D?.passphrase!==""&&(ae.passphrase=D.passphrase)}if(te==="password"){let le=String(D?.password??"");if(le==="")return k("auth=password \u9700\u8981\u5BC6\u7801"),null;ae.password=le}return D?.agentForward===!0&&(ae.agentForward=!0),ae},Oc=()=>{k("");let I=Yn();I!==null&&(J({running:!0,ok:!1,text:"\u8FDE\u63A5\u6D4B\u8BD5\u4E2D\u2026"}),Ln(I,!1).then(V=>{if(V.result){let G=V.result.auth?.ok===!0;J({running:!1,ok:G,text:Mn(V.result)});return}J({running:!1,ok:!1,text:"\u274C \u8FDE\u63A5\u5931\u8D25\uFF1A"+String(V.error||"\u672A\u77E5\u9519\u8BEF")})}))},Ic=()=>{k("");let I=Yn();I!==null&&us(I)},Nc=()=>{if(D===null)return null;let I=(V,G,te,ae,le)=>o("label",{className:"tt_sshRow",children:[s("span",{className:"tt_cardLabel",children:V}),s("input",{className:"tt_cardInput",type:ae??"text",value:D[G]??"",placeholder:te??"",autoComplete:"off",spellCheck:!1,onChange:we=>{let ce=we.target.value;w(vt=>({...vt||{},[G]:ce}))},...le??{}})]});return o("div",{className:"tt_sshEdit",children:[s("div",{className:"tt_sshSection",children:"\u8FDE\u63A5"}),o("div",{className:"tt_sshGrid",children:[I("\u540D\u79F0","name","\u540C\u540D\u51B2\u7A81\u4F1A\u88AB\u62D2\u7EDD"),I("\u7AEF\u53E3","port","22")]}),I("\u4E3B\u673A","host","example.com \u6216 IP"),I("\u7528\u6237\u540D","username","root"),s("div",{className:"tt_sshSection",children:"\u8BA4\u8BC1"}),o("label",{className:"tt_sshRow",children:[s("span",{className:"tt_cardLabel",children:"\u8BA4\u8BC1\u65B9\u5F0F"}),o("select",{className:"tt_cardInput",value:D.auth,onChange:V=>w(G=>({...G||{},auth:V.target.value})),children:[s("option",{value:"agent",children:"agent \u2014 \u4F7F\u7528\u672C\u673A ssh-agent"}),s("option",{value:"key",children:"key \u2014 \u79C1\u94A5\u6587\u4EF6"}),s("option",{value:"password",children:"password \u2014 \u5BC6\u7801"})]})]}),...D.auth==="key"?[I("\u79C1\u94A5\u8DEF\u5F84","keyPath","~/.ssh/id_ed25519"),I("\u79C1\u94A5\u53E3\u4EE4\uFF08\u53EF\u7A7A\uFF09","passphrase","","password"),Gn("passphrase","\u8FD8\u6CA1\u6709\u522B\u7684\u8FDE\u63A5\u7528\u8FC7\u51ED\u636E\u5F15\u7528 \u2014 \u53EF\u5728\u79C1\u94A5\u53E3\u4EE4\u6846\u76F4\u63A5\u624B\u8F93 env:NAME")]:[],...D.auth==="password"?[I("\u5BC6\u7801","password","","password",{onBlur:()=>{ps(D.password)}}),Pc(),Gn("password","\u8FD8\u6CA1\u6709\u522B\u7684\u8FDE\u63A5\u7528\u8FC7\u51ED\u636E\u5F15\u7528 \u2014 \u52FE\u4E0A\u9762\u7684\u300C\u5E94\u7528\u65F6\u5B58\u5165\u51ED\u636E\u5B58\u50A8\u300D\u65B0\u5EFA\u4E00\u4E2A\uFF0C\u6216\u76F4\u63A5\u5728\u5BC6\u7801\u6846\u624B\u8F93 env:NAME")]:[],s("div",{className:"tt_sshSection",children:"\u9009\u9879"}),o("label",{className:"tt_cardRow",children:[s("input",{type:"checkbox",className:"tt_cardCheckbox",checked:D.agentForward===!0,onChange:V=>w(G=>({...G||{},agentForward:V.target.checked}))}),s("span",{className:"tt_cardLabel",children:"agent forwarding\uFF08\u8FDC\u7A0B\u53EF\u7528\u672C\u5730 ssh-agent \u94A5\u5319\uFF0C\u5982\u8FDC\u7A0B git clone\uFF09"})]}),Nt==="tmux"?o("label",{className:"tt_cardRow",children:[s("input",{type:"checkbox",className:"tt_cardCheckbox",checked:D.persist===!0,onChange:V=>w(G=>({...G||{},persist:V.target.checked}))}),s("span",{className:"tt_cardLabel",children:"\u6301\u4E45\u4F1A\u8BDD\uFF08tmux \u6258\u7BA1\uFF0C\u65AD\u7EBF/\u91CD\u542F\u540E\u6062\u590D\u73B0\u573A\uFF1B\u8FDC\u7A0B\u9700\u5B89\u88C5 tmux\uFF09"})]}):null,K.text!==""?s("div",{className:"tt_sshProbeResult"+(!K.running&&K.ok?" tt_sshProbeOk":"")+(!K.running&&!K.ok?" tt_sshProbeBad":""),children:K.text}):null,L!==""?s("span",{className:"tt_cardMessage tt_cardMessageError",children:L}):null,o("div",{className:"tt_sshActions",children:[o("div",{className:"tt_sshActionsGroup",children:[s("button",{type:"button",className:"tt_toolBtn",onClick:Kn,children:"\u53D6\u6D88"}),s("button",{type:"button",className:"tt_toolBtn",title:"\u4E0D\u52A8\u7EC8\u7AEF\uFF0C\u76F4\u63A5\u4EE5\u5F53\u524D\u586B\u5199\u7684\u4FE1\u606F\u6253\u5F00 SFTP \u6587\u4EF6\u6D4F\u89C8",onClick:Ic,children:"\u6587\u4EF6\u6D4F\u89C8"}),s("button",{type:"button",className:"tt_toolBtn",disabled:K.running,title:"\u6309\u5F53\u524D\u586B\u5199\u8BCA\u65AD\u8FDE\u63A5\uFF08TCP \u2192 \u4E3B\u673A\u5BC6\u94A5 \u2192 \u8BA4\u8BC1\uFF09\uFF1B\u4E0D\u4F1A\u65B0\u5EFA\u4F1A\u8BDD\uFF0C\u4E5F\u4E0D\u8BB0\u5F55\u4E3B\u673A\u6307\u7EB9",onClick:Oc,children:K.running?"\u8BD5\u8FDE\u4E2D\u2026":"\u8BD5\u8FDE"})]}),o("div",{className:"tt_sshActionsGroup",children:[s("button",{type:"button",className:"tt_cardSave",onClick:()=>{kc()},children:"\u5E94\u7528"}),s("span",{className:"tt_cardHint",children:"\u968F\u5361\u7247\u300C\u4FDD\u5B58\u300D\u5199\u5165\u914D\u7F6E"})]})]})]})},kr=(I,V,G,te)=>o("label",{className:"tt_cardField",children:[s("span",{className:"tt_cardLabel",children:I}),s("input",{className:"tt_cardInput",value:_[V]??"",placeholder:G??"",onChange:ae=>j(V,ae.target.value)}),te?s("span",{className:"tt_cardHint",children:te}):null]}),Er=(I,V)=>o("label",{className:"tt_cardField tt_cardRow",children:[s("input",{type:"checkbox",className:"tt_cardCheckbox",checked:_[V]===!0,onChange:G=>j(V,G.target.checked)}),s("span",{className:"tt_cardLabel",children:I})]}),Lr=_?.platform==="win32";return c==="summary"?"xterm \u7EC8\u7AEF\u9762\u677F\uFF1A\u591A\u6807\u7B7E\u9875\u3001\u65AD\u7EBF\u81EA\u52A8\u91CD\u8FDE\u3001cwd \u8DDF\u968F\u4F1A\u8BDD\u3001SSH \u8FDE\u63A5\u7C3F\u4E0E\u4E3B\u673A\u6307\u7EB9\u9489\u624E\u3001tmux \u4F1A\u8BDD\u6301\u4E45\u5316\u3002":o(p?"div":"li",{className:p?"tt_pageHost":g?"tt_card tt_cardOpen":"tt_card",children:[p?null:o("button",{type:"button",className:"tt_cardHeader","aria-expanded":g,onClick:()=>S(I=>!I),children:[o("span",{className:"tt_cardHeadText",children:[s("span",{className:"tt_cardName",children:"\u7EC8\u7AEF\u9762\u677F"}),s("span",{className:"tt_cardDescription",children:"xterm \u7EC8\u7AEF\u9762\u677F\uFF1A\u591A\u6807\u7B7E\u9875\u3001\u65AD\u7EBF\u81EA\u52A8\u91CD\u8FDE\u3001cwd \u8DDF\u968F\u4F1A\u8BDD\u3001SSH \u8FDE\u63A5\u7C3F\u4E0E\u4E3B\u673A\u6307\u7EB9\u9489\u624E\u3001tmux \u4F1A\u8BDD\u6301\u4E45\u5316\uFF1Bshell / TERM / \u5E76\u53D1\u4E0A\u9650\u7B49\u4FDD\u5B58\u5373\u70ED\u751F\u6548\u3002"})]}),s("span",{className:"dshkit_badge",children:"Kit"}),s("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:g?"tt_cardChevron tt_cardChevronOpen":"tt_cardChevron",children:s("path",{d:i,fill:"currentColor"})})]}),p||g?o("div",{className:"tt_cardBody",children:[_===null?s("div",{className:"tt_cardMessage",children:"\u52A0\u8F7D\u914D\u7F6E\u4E2D\u2026"}):o("div",{children:[B("\u57FA\u7840"),Er("\u542F\u7528\u63D2\u4EF6\uFF08\u4FDD\u5B58\u5373\u70ED\u751F\u6548\uFF1A\u5DE5\u5177\u4E0E\u9762\u677F\u5165\u53E3\u7ACB\u523B\u6536\u8D77\uFF0C\u4F1A\u8BDD\u8F6C\u4FDD\u6D3B\uFF09","enabled"),Er("\u5411 agent \u516C\u544A\u7EC8\u7AEF\u9762\u677F\u80FD\u529B","announceToAgent"),Lr?o("div",{className:"tt_cardField",children:[o("label",{className:"tt_cardRow",children:[s("input",{type:"checkbox",className:"tt_cardCheckbox",checked:!1,disabled:!0}),s("span",{className:"tt_cardLabel",children:"shell \u96C6\u6210\uFF08OSC 133/7 \u6CE8\u5165\uFF09"})]}),s("span",{className:"tt_cardHint",children:"Windows \u5BBF\u4E3B\u4E0A\u4E0D\u9002\u7528\uFF1A\u6CE8\u5165\u8D70\u7684\u662F POSIX \u7684 `-c` \u5305\u88C5\u5C42\u4E0E rc \u6869\uFF0Ccmd / PowerShell \u4E0A\u90FD\u4E0D\u6210\u7ACB\uFF08\u5B9E\u6D4B cmd \u5FFD\u7565 `-c` \u7A7A\u8DD1\u3001PowerShell \u62A5 export \u4E0D\u5B58\u5728\uFF09\u3002\u56E0\u6B64**\u672C\u5730**\u6807\u7B7E\u7684 cwd \u8DDF\u968F\u4E0E tty_capture{last} \u4E0D\u53EF\u7528\uFF1B\u8FDC\u7A0B Linux / macOS \u4E3B\u673A\u7167\u65E7\u652F\u6301\u3002"})]}):Er("shell \u96C6\u6210\uFF08OSC 133/7 \u6CE8\u5165\uFF0Ctty_capture{last} \u4E0E cwd \u8DDF\u968F\u4F9D\u8D56\u5B83\uFF09","shellIntegration"),B("SFTP \u6587\u4EF6\u4F20\u8F93"),o("div",{className:"tt_cardField",children:[s("span",{className:"tt_cardLabel",children:"SFTP \u6587\u4EF6\u6D4F\u89C8\u98CE\u683C"}),o("select",{className:"tt_cardInput",value:_.sftpStyle==="dual"?"dual":"dialog",onChange:I=>j("sftpStyle",I.target.value),children:[s("option",{value:"dialog",children:"\u5355\u7A97\u4F53 \u2014 \u8FDC\u7A0B\u76EE\u5F55 + \u4E0A\u4F20/\u4E0B\u8F7D/\u62D6\u62FD"}),s("option",{value:"dual",children:"\u53CC\u680F \u2014 \u5DE6\u672C\u673A / \u53F3\u8FDC\u7A0B\uFF0C\u9009\u4E2D\u76F4\u4F20"})]}),s("span",{className:"tt_cardHint",children:"\u53CC\u680F\u5728\u672C\u673A\u4E0E\u8FDC\u7A0B\u4E4B\u95F4\u5BF9\u62F7\u6587\u4EF6\uFF08\u76EE\u5F55\u9012\u5F52\u3001\u540C\u540D\u8986\u76D6\uFF09\uFF1B\u91CD\u65B0\u6253\u5F00 SFTP \u540E\u751F\u6548"})]}),o("div",{className:"tt_cardField",children:[s("span",{className:"tt_cardLabel",children:"SFTP \u4F20\u8F93\u9650\u5236\uFF080 = \u4E0D\u9650\uFF09"}),o("div",{className:"tt_limitGrid",children:[o("label",{className:"tt_sshRow",children:[s("span",{className:"tt_cardLabel",children:"\u4E0B\u8F7D\u4E0A\u9650 (MB)"}),s("input",{className:"tt_cardInput",type:"number",min:0,value:String(Number.isFinite(Number(_?.sftpLimits?.maxDownloadMb))?Number(_.sftpLimits.maxDownloadMb):1024),onChange:I=>A("maxDownloadMb",Number(I.target.value)||0)})]}),o("label",{className:"tt_sshRow",children:[s("span",{className:"tt_cardLabel",children:"\u4E0A\u4F20\u4E0A\u9650 (MB)"}),s("input",{className:"tt_cardInput",type:"number",min:0,value:String(Number.isFinite(Number(_?.sftpLimits?.maxUploadMb))?Number(_.sftpLimits.maxUploadMb):2048),onChange:I=>A("maxUploadMb",Number(I.target.value)||0)})]}),o("label",{className:"tt_sshRow",children:[s("span",{className:"tt_cardLabel",children:"\u6279\u91CF\u6587\u4EF6\u6570\u4E0A\u9650"}),s("input",{className:"tt_cardInput",type:"number",min:0,value:String(Number.isFinite(Number(_?.sftpLimits?.maxUploadFiles))?Number(_.sftpLimits.maxUploadFiles):1e3),onChange:I=>A("maxUploadFiles",Number(I.target.value)||0)})]})]}),s("span",{className:"tt_cardHint",children:"\u6D4F\u89C8\u5668\u4FA7\u4FDD\u62A4\uFF1A\u5355\u4E2A\u6587\u4EF6\u8D85\u8FC7\u4E0A\u9650\u65F6\u4E2D\u6B62\u4E0B\u8F7D/\u4E0A\u4F20\uFF08\u5927\u6587\u4EF6\u8BF7\u7528\u53CC\u680F \u21E8/\u21E6 \u76F4\u4F20\u6216\u7EC8\u7AEF scp/rsync\uFF0C\u4E0D\u5360\u6D4F\u89C8\u5668\u5185\u5B58\uFF09\uFF1B\u6587\u4EF6\u6570\u4E0A\u9650\u9488\u5BF9\u4E00\u6B21\u6279\u91CF/\u62D6\u62FD\u4E0A\u4F20\uFF1B\u4FDD\u5B58\u5373\u70ED\u751F\u6548"})]}),B("\u4F1A\u8BDD"),o("div",{className:"tt_cardField",children:[s("span",{className:"tt_cardLabel",children:"\u4F1A\u8BDD\u6301\u4E45\u5316\uFF08tmux\uFF09"}),o("select",{className:"tt_cardInput",value:_.persistence==="tmux"?"tmux":"off",onChange:I=>j("persistence",I.target.value),children:[s("option",{value:"off",children:"\u5173\u95ED \u2014 \u4F1A\u8BDD\u968F\u9762\u677F/\u5BBF\u4E3B\u7ED3\u675F\uFF08\u9ED8\u8BA4\uFF09"}),s("option",{value:"tmux",children:"tmux \u2014 \u65B0\u5F00\u7684\u7EC8\u7AEF/SSH \u6807\u7B7E\u9ED8\u8BA4\u6301\u4E45\u5316"})]}),s("span",{className:"tt_cardHint",children:"\u5F00\u542F\u540E\u6240\u6709\u65B0\u6807\u7B7E\uFF08\u672C\u5730/SSH \u8FDE\u63A5\u7C3F/SSH \u8FDE\u63A5\u5BF9\u8BDD\u6846\uFF09\u9ED8\u8BA4\u7531 tmux \u6258\u7BA1\u3001\u53EF\u8DE8\u5BBF\u4E3B\u91CD\u542F\u6062\u590D\uFF1B\u9700\u672C\u673A/\u8FDC\u7A0B\u5B89\u88C5 tmux\uFF1BSSH \u5BF9\u8BDD\u6846\u53EF\u5BF9\u5355\u6B21\u8FDE\u63A5\u53D6\u6D88\u52FE\u9009\uFF1B\u5DF2\u6709\u6807\u7B7E\u4E0D\u53D7\u5F71\u54CD"+(Lr?"\uFF1BWindows \u5BBF\u4E3B\u4E0A tmux \u4E0D\u53EF\u7528\uFF0C\u672C\u5730\u6807\u7B7E\u4F1A\u7167\u5E38\u6253\u5F00\u4F46\u4E0D\u53D7\u6258\u7BA1":"")}),Er("\u5173\u95ED\u9875\u9762\u540E\u7ED3\u675F\u6301\u4E45\u4F1A\u8BDD\uFF08\u4E0D\u4FDD\u6D3B\uFF09","endOnPageClose"),Er("\u670D\u52A1\u5668\u72B6\u6001\u6761\uFF08CPU / \u5185\u5B58 / \u78C1\u76D8 / \u5728\u7EBF / TCP / \u7F51\u901F\uFF1B\u91C7\u4E0D\u5230\u7684\u9879\u663E\u793A\u300C\u65E0\u300D\uFF09","statsEnabled"),s("span",{className:"tt_cardHint",children:"\u9ED8\u8BA4\u5173\u95ED\uFF1A\u6574\u4E2A\u9875\u9762\u5173\u95ED\u65F6\u6301\u4E45\u4F1A\u8BDD\u7559\u5B58\uFF08\u4FDD\u6D3B\u671F\u540E\u53EF\u518D\u6062\u590D\uFF09\uFF1B\u5F00\u542F\u5219\u9875\u9762\u65AD\u5F00\u4E14\u4FDD\u6D3B\u671F\u7ED3\u675F\u65F6\u8FDE tmux \u4F1A\u8BDD\u4E00\u8D77\u7ED3\u675F\u2014\u2014\u6CE8\u610F\u5237\u65B0\u9875\u9762\u5728\u4FDD\u6D3B\u671F\u5185\u4E0D\u53D7\u5F71\u54CD"})]}),kr("\u5E76\u53D1\u4F1A\u8BDD\u4E0A\u9650\uFF081~16\uFF09","maxSessions","4","\u8D85\u8FC7\u4E0A\u9650\u7684\u65B0\u6807\u7B7E\u4F1A\u88AB\u62D2\u7EDD\uFF1B\u4FDD\u5B58\u5373\u70ED\u751F\u6548"),o("div",{className:"tt_cardField",onBlur:I=>{I.currentTarget.contains(I.relatedTarget)||P(!1)},children:[s("span",{className:"tt_cardLabel",children:Lr?"Shell \u8DEF\u5F84\uFF08\u9ED8\u8BA4 %COMSPEC%\uFF09":"Shell \u8DEF\u5F84\uFF08\u9ED8\u8BA4 $SHELL\uFF09"}),s("input",{className:"tt_cardInput",value:_.shell??"",placeholder:Lr?"\u7559\u7A7A\u4F7F\u7528 %COMSPEC%\uFF08\u4E5F\u53EF\u586B powershell.exe / pwsh.exe \u5B8C\u6574\u8DEF\u5F84\uFF09":"\u7559\u7A7A\u4F7F\u7528 $SHELL",autoComplete:"off",spellCheck:!1,onFocus:()=>P(!0),onClick:()=>P(!0),onKeyDown:I=>{I.key==="Escape"&&P(!1)},onChange:I=>{j("shell",I.target.value),P(!0)}}),...E?[s("div",{className:"tt_envList tt_shellList",children:(()=>{let I=(_.shell??"").trim().toLowerCase(),V=I===""?C:C.filter(G=>G.toLowerCase().includes(I));return V.length===0?s("span",{className:"tt_envMore",children:"\u6CA1\u6709\u5339\u914D\u7684\u5019\u9009 \u2014 \u76F4\u63A5\u8F93\u5165\u4EFB\u610F\u8DEF\u5F84\u5373\u53EF"}):V.map(G=>s("button",{type:"button",className:"tt_envItem",onMouseDown:te=>te.preventDefault(),onClick:()=>{j("shell",G),P(!1)},children:G},G))})()},"shell-list")]:[],s("span",{className:"tt_cardHint",children:Lr?"Windows \u5BBF\u4E3B\uFF1A\u5019\u9009\u6765\u81EA %COMSPEC% \u4E0E\u5DF2\u5B89\u88C5\u7684 PowerShell\uFF08Windows PowerShell 5.1 / PowerShell 7\uFF09\uFF0C\u4E5F\u53EF\u76F4\u63A5\u8F93\u5165\u4EFB\u610F\u8DEF\u5F84\uFF1Bcmd / PowerShell \u6CA1\u6709 POSIX \u7684\u547D\u4EE4\u8FB9\u754C\u94A9\u5B50\uFF0C\u6240\u4EE5\u8FD9\u4E24\u8005\u4E0D\u652F\u6301 shell \u96C6\u6210":"\u53EF\u4E0B\u62C9\u9009\u62E9\u672C\u673A\u5DF2\u5B89\u88C5 shell\uFF08$SHELL \u4F18\u5148\uFF09\uFF0C\u4E5F\u53EF\u76F4\u63A5\u8F93\u5165\u4EFB\u610F\u8DEF\u5F84\uFF1Bzsh / bash \u652F\u6301 shell \u96C6\u6210"})]},"shell-field"),kr("TERM","term","xterm-256color","TUI \u7A0B\u5E8F\u4F9D\u8D56\u6B64\u503C"),kr("COLORTERM","colorTerm","truecolor",""),kr("\u515C\u5E95\u5DE5\u4F5C\u76EE\u5F55\uFF08\u5BA2\u6237\u7AEF\u5F53\u524D\u4F1A\u8BDD cwd \u4F18\u5148\uFF09","cwd","","\u7559\u7A7A\u4F7F\u7528\u5BBF\u4E3B\u8FDB\u7A0B\u542F\u52A8\u76EE\u5F55"),kr("\u65AD\u7EBF\u4FDD\u6D3B\uFF08\u79D2\uFF0C0 = \u7ACB\u5373\u7ED3\u675F\uFF09","reconnectGraceSec","120","\u5237\u65B0\u9875\u9762/\u7F51\u7EDC\u6296\u52A8\u540E\u4F1A\u8BDD\u4FDD\u6D3B\u7B49\u5F85\u91CD\u8FDE\uFF0C\u8D85\u65F6\u540E\u7ED3\u675F\uFF1B\u4FDD\u5B58\u5373\u70ED\u751F\u6548"),B("SSH \u8FDE\u63A5"),o("div",{className:"tt_cardField",children:[s("span",{className:"tt_cardLabel",children:"SSH \u8FDE\u63A5\u7C3F"}),...Array.isArray(_.sshHosts)&&_.sshHosts.length>0?[s("div",{className:"tt_hostList","data-editing":T!==null?"":void 0,children:_.sshHosts.map(I=>o("div",{children:[o("div",{className:"tt_sshHostRow",children:[s("div",{className:"tt_sshHostMeta",children:[s("span",{className:"tt_sshHostName",children:I?.name??""}),s("span",{className:"tt_sshHostTarget",children:En(I??{})})]}),s("button",{type:"button",className:"tt_toolBtn",disabled:oe[I?.name]?.running===!0,onClick:()=>{Lc(I)},title:"\u8BD5\u8FDE\u8BE5\u6761\u76EE\uFF1ATCP \u2192 \u4E3B\u673A\u5BC6\u94A5 \u2192 \u8BA4\u8BC1\u9010\u6BB5\u8BCA\u65AD",children:oe[I?.name]?.running===!0?"\u6D4B\u8BD5\u4E2D\u2026":"\u6D4B\u8BD5"}),s("button",{type:"button",className:"tt_toolBtn",onClick:()=>xc(I),children:"\u7F16\u8F91"}),s("button",{type:"button",className:"tt_toolBtn",onClick:()=>Ec(I?.name),children:"\u5220\u9664"})]}),oe[I?.name]&&oe[I?.name].text?s("div",{className:"tt_sshProbeResult"+(oe[I?.name].ok?" tt_sshProbeOk":" tt_sshProbeBad"),children:oe[I?.name].text}):null,T===I?.name?Nc():null]},String(I?.name??"")))})]:[s("span",{className:"tt_cardHint",children:"\u6682\u65E0\u6761\u76EE \u2014 \u7EC8\u7AEF\u9762\u677F\u300C+\u300D\u2192 SSH \u8FDE\u63A5\u2026 \u52FE\u9009\u300C\u4FDD\u5B58\u5230\u8FDE\u63A5\u7C3F\u300D\u5373\u53EF\u6DFB\u52A0"})],o("div",{className:"tt_cardRow",children:[s("button",{type:"button",className:"tt_toolBtn",onClick:()=>{Rc()},children:"\u4ECE ~/.ssh/config \u5BFC\u5165"}),s("span",{className:"tt_cardHint",children:"\u540C\u540D\u8DF3\u8FC7\uFF1B\u968F\u300C\u4FDD\u5B58\u300D\u5199\u5165\u914D\u7F6E"})]}),s("span",{className:"tt_cardHint",children:"\u968F\u300C\u4FDD\u5B58\u300D\u4E00\u5E76\u5199\u5165\u914D\u7F6E\uFF1B\u5BC6\u7801/\u53E3\u4EE4\u652F\u6301 env:VAR \u5F15\u7528\uFF0C\u907F\u514D\u660E\u6587\u5165\u5E93"})]}),o("div",{className:"tt_cardField",children:[o("div",{className:"tt_cardField",children:[s("span",{className:"tt_cardLabel",children:"\u7AEF\u53E3\u8F6C\u53D1"}),...Array.isArray(_.tunnels)&&_.tunnels.length>0?[s("div",{children:_.tunnels.map(I=>{let V=he.find(ae=>ae.name===I?.name),G=V?.state??"stopped",te=pe!==null&&String(I?.name??"")===pe;return o("div",{className:"tt_sshHostRow","data-editing":te?"":void 0,children:[s("span",{className:"tt_tunnelDot","data-state":G,title:G}),s("div",{className:"tt_sshHostMeta",children:[s("span",{className:"tt_sshHostName",children:(I?.name??"")+" \xB7 "+Jt(I??{})}),s("span",{className:"tt_sshHostTarget",children:(I?.bookName??"")+(V?.error?" \xB7 "+V.error:"")+(V?.lastForwardError?" \xB7 "+V.lastForwardError:"")})]}),s("input",{type:"checkbox",className:"tt_cardCheckbox",checked:I?.enabled!==!1,title:"\u542F\u7528",onChange:ae=>Cc(I?.name,ae.target.checked)}),s("button",{type:"button",className:"tt_toolBtn",onClick:()=>fs(I),children:"\u7F16\u8F91"}),s("button",{type:"button",className:"tt_toolBtn",onClick:()=>yc(I?.name),children:"\u5220\u9664"})]},String(I?.name??""))})})]:[s("span",{className:"tt_cardHint",children:"\u6682\u65E0\u96A7\u9053 \u2014 \u628A\u8FDC\u7A0B\u6570\u636E\u5E93/\u5185\u90E8\u670D\u52A1\u6620\u5C04\u5230\u672C\u5730\u7AEF\u53E3"})],o("div",{className:"tt_sshEdit",children:[o("div",{className:"tt_cardRow tt_tunnelHead",children:[o("div",{className:"tt_segmented",role:"group","aria-label":"\u8F6C\u53D1\u65B9\u5411",children:[s("button",{type:"button",className:"tt_segmentedBtn","data-active":de.direction!=="remote"?"":void 0,title:"\u672C\u5730\u8F6C\u53D1 -L\uFF1A\u672C\u673A\u76D1\u542C\uFF0C\u8FDE\u5230 SSH \u670D\u52A1\u5668\u4FA7\u7684\u76EE\u6807",onClick:()=>Qe("direction","local"),children:"\u672C\u5730 -L"}),s("button",{type:"button",className:"tt_segmentedBtn","data-active":de.direction==="remote"?"":void 0,title:"\u8FDC\u7A0B\u8F6C\u53D1 -R\uFF1ASSH \u670D\u52A1\u5668\u4FA7\u76D1\u542C\uFF0C\u62E8\u56DE\u672C\u673A\u670D\u52A1",onClick:()=>Qe("direction","remote"),children:"\u8FDC\u7A0B -R"})]}),o("select",{className:"tt_cardInput",value:de.bookName,onChange:je("bookName"),children:[s("option",{value:"",children:"\u9009\u62E9\u8FDE\u63A5\u7C3F\u6761\u76EE"}),...Array.isArray(_?.sshHosts)?_.sshHosts.map(I=>s("option",{value:I?.name??"",children:I?.name??""})):[]]})]}),s("span",{className:"tt_cardHint",children:et!==void 0?"\u7ECF "+En(et)+" \u8FDE\u63A5 \u2014 \u96A7\u9053\u7684\u4E3B\u673A\u4E0E\u8BA4\u8BC1\u53D6\u81EA\u8BE5\u8FDE\u63A5\u7C3F\u6761\u76EE":"\u9009\u62E9\u8FD9\u6761\u96A7\u9053\u8981\u8D70\u54EA\u53F0 SSH \u8FDE\u63A5\uFF08\u4E3B\u673A\u4E0E\u8BA4\u8BC1\u53D6\u81EA\u8FDE\u63A5\u7C3F\uFF09"}),de.direction==="local"?o("div",{className:"tt_tunnelEndpoints",children:[o("div",{className:"tt_tunnelHop",children:[o("div",{className:"tt_tunnelEndpoint",children:[s("span",{className:"tt_tunnelEndpointStatic",title:"\u672C\u673A\u76D1\u542C\u5730\u5740\u56FA\u5B9A 127.0.0.1\uFF08\u4E0D\u66B4\u9732\u5230\u5C40\u57DF\u7F51\uFF09",children:"127.0.0.1"}),s("span",{className:"tt_tunnelColon",children:":"}),s("input",{className:"tt_cardInput tt_tunnelPort",placeholder:"\u672C\u673A\u7AEF\u53E3",value:de.localPort,autoComplete:"off",inputMode:"numeric","aria-label":"\u672C\u673A\u76D1\u542C\u7AEF\u53E3",onChange:je("localPort")})]}),s("span",{className:"tt_tunnelArrow","data-direction":"local",title:"\u6570\u636E\u6D41\u5411\uFF1A\u672C\u673A \u2192 SSH \u670D\u52A1\u5668\u4FA7","aria-hidden":"true",children:"\u2192"})]}),o("div",{className:"tt_tunnelEndpoint",children:[s("input",{className:"tt_cardInput tt_tunnelHost",placeholder:"\u670D\u52A1\u5668\u4FA7\u4E3B\u673A",title:"\u76EE\u6807\u4E3B\u673A\u540D\u6216 IP\uFF08\u7531 SSH \u670D\u52A1\u5668\u4FA7\u8BBF\u95EE\uFF1B127.0.0.1 = \u670D\u52A1\u5668\u81EA\u8EAB\uFF09",value:de.remoteHost,autoComplete:"off","aria-label":"\u670D\u52A1\u5668\u4FA7\u76EE\u6807\u4E3B\u673A",onChange:je("remoteHost")}),s("span",{className:"tt_tunnelColon",children:":"}),s("input",{className:"tt_cardInput tt_tunnelPort",placeholder:"\u7AEF\u53E3",value:de.remotePort,autoComplete:"off",inputMode:"numeric","aria-label":"\u670D\u52A1\u5668\u4FA7\u76EE\u6807\u7AEF\u53E3",onChange:je("remotePort")})]})]}):o("div",{className:"tt_tunnelEndpoints",children:[o("div",{className:"tt_tunnelHop",children:[o("div",{className:"tt_tunnelEndpoint",children:[s("input",{className:"tt_cardInput tt_tunnelHost",placeholder:"\u670D\u52A1\u5668\u4FA7\u76D1\u542C\u5730\u5740",title:"\u670D\u52A1\u5668\u4FA7\u76D1\u542C\u5730\u5740\uFF08\u7F3A\u7701 127.0.0.1\uFF1B\u7559\u7A7A\u5373\u53EA\u8BA9\u670D\u52A1\u5668\u81EA\u5DF1\u8BBF\u95EE\uFF09",value:de.remoteHost,autoComplete:"off","aria-label":"\u670D\u52A1\u5668\u4FA7\u76D1\u542C\u5730\u5740",onChange:je("remoteHost")}),s("span",{className:"tt_tunnelColon",children:":"}),s("input",{className:"tt_cardInput tt_tunnelPort",placeholder:"\u76D1\u542C\u7AEF\u53E3",value:de.remotePort,autoComplete:"off",inputMode:"numeric","aria-label":"\u670D\u52A1\u5668\u4FA7\u76D1\u542C\u7AEF\u53E3",onChange:je("remotePort")})]}),s("span",{className:"tt_tunnelArrow","data-direction":"remote",title:"\u6570\u636E\u6D41\u5411\uFF1A\u672C\u673A \u2190 SSH \u670D\u52A1\u5668\u4FA7","aria-hidden":"true",children:"\u2192"})]}),o("div",{className:"tt_tunnelEndpoint",children:[s("span",{className:"tt_tunnelEndpointStatic",title:"\u672C\u673A\u62E8\u53F7\u5730\u5740\u56FA\u5B9A 127.0.0.1",children:"127.0.0.1"}),s("span",{className:"tt_tunnelColon",children:":"}),s("input",{className:"tt_cardInput tt_tunnelPort",placeholder:"\u672C\u673A\u670D\u52A1\u7AEF\u53E3",value:de.localTargetPort,autoComplete:"off",inputMode:"numeric","aria-label":"\u672C\u673A\u76EE\u6807\u7AEF\u53E3",onChange:je("localTargetPort")})]})]}),s("div",{className:"tt_tunnelEndpoints",children:[s("span",{className:"tt_tunnelEndLabel",children:de.direction==="local"?"\u5DE6\uFF1A\u672C\u673A\u76D1\u542C\uFF08\u56FA\u5B9A 127.0.0.1\uFF09\u2192 \u53F3\uFF1A\u7531 SSH \u670D\u52A1\u5668\u4FA7\u8BBF\u95EE\u7684\u76EE\u6807":"\u5DE6\uFF1ASSH \u670D\u52A1\u5668\u4FA7\u76D1\u542C \u2192 \u53F3\uFF1A\u672C\u673A\u88AB\u8BBF\u95EE\u7684\u670D\u52A1\uFF08\u56FA\u5B9A 127.0.0.1\uFF09"})]}),s("div",{className:"tt_cardRow tt_tunnelActions",children:[pe===null?s("button",{type:"button",className:"tt_cardSave",onClick:wc,children:"\u6DFB\u52A0\u96A7\u9053"}):s("button",{type:"button",className:"tt_cardSave",onClick:Sc,children:"\u4FDD\u5B58\u4FEE\u6539"}),pe===null?null:s("button",{type:"button",className:"tt_toolBtn",onClick:bc,children:"\u53D6\u6D88"}),s("span",{className:"tt_cardHint",children:pe===null?"\u6DFB\u52A0\u540E\u7ACB\u5373\u751F\u6548\uFF1B\u65AD\u7EBF\u81EA\u52A8\u91CD\u8FDE\uFF1B\u672C\u5730\u7AEF\u53E3\u5EFA\u8BAE 1024 \u4EE5\u4E0A\uFF1B\u8FDC\u7A0B\u4E3B\u673A\u7531 SSH \u670D\u52A1\u5668\u4FA7\u8BBF\u95EE\uFF08127.0.0.1 = \u670D\u52A1\u5668\u81EA\u8EAB\uFF09":`\u6B63\u5728\u7F16\u8F91\u300C${pe}\u300D\u2014\u2014\u6539\u7AEF\u53E3/\u6761\u76EE\u4F1A\u6309\u89C4\u5219\u751F\u6210\u65B0\u540D\u5B57\uFF1B\u4FDD\u5B58\u540E\u7ACB\u5373\u751F\u6548`})]})]})]}),o("div",{className:"tt_cardField",children:[s("span",{className:"tt_cardLabel",children:"SSH \u4E3B\u673A\u5BC6\u94A5\u8BB0\u5F55\uFF08TOFU\uFF09"}),s("button",{type:"button",className:"tt_toolBtn",onClick:()=>{Tc()},children:"\u4ECE known_hosts \u5BFC\u5165"})]}),...Array.isArray(_.hostKeys)&&_.hostKeys.length>0?[s("div",{className:"tt_hostList",children:_.hostKeys.map((I,V)=>o("div",{className:"tt_sshHostRow",children:[s("div",{className:"tt_sshHostMeta",children:[s("span",{className:"tt_sshHostName",children:String(I?.host??"")+":"+String(I?.port??22)}),s("span",{className:"tt_sshHostTarget",children:Vn(I).map(G=>"sha256:"+G).join(" / ")})]}),s("button",{type:"button",className:"tt_toolBtn",onClick:()=>{Mc(I)},children:"\u5220\u9664"})]},String(I?.host??"")+":"+String(I?.port??22)+"#"+String(V)))})]:[s("span",{className:"tt_cardHint",children:"\u6682\u65E0\u8BB0\u5F55 \u2014 \u9996\u6B21 SSH \u8FDE\u63A5\u6210\u529F\u540E\u81EA\u52A8\u8BB0\u5F55\u4E3B\u673A\u6307\u7EB9"})],s("span",{className:"tt_cardHint",children:"\u4E00\u673A\u591A\u628A\u94A5\u5319\uFF08\u5982 rsa + ed25519\uFF09\u5404\u8BB0\u4E00\u6761\u6307\u7EB9\uFF0C\u4EFB\u4E00\u5339\u914D\u5373\u653E\u884C\uFF1B\u6307\u7EB9\u53D8\u66F4\u65F6\u8FDE\u63A5\u4F1A\u88AB\u62D2\u7EDD\uFF08\u9632\u4E2D\u95F4\u4EBA\uFF09\uFF0C\u786E\u8BA4\u5B89\u5168\u540E\u5220\u9664\u5BF9\u5E94\u8BB0\u5F55\u5373\u53EF\u91CD\u8FDE"})]}),o("div",{className:"tt_cardField tt_cardRow",children:[s("button",{className:"tt_cardSave",disabled:u,onClick:()=>{Ac()},children:u?"\u4FDD\u5B58\u4E2D\u2026":"\u4FDD\u5B58"}),s("span",{className:"tt_cardMessage"+(y.kind==="ok"?" tt_cardMessageOk":y.kind==="error"?" tt_cardMessageError":""),children:y.text})]})]})]}):null]})}t.inject=["slots","sessions"];let a=["@hyzyn/dsh-tty#tty","@hyzyn/dsh-all#tty"];return t.apply=f=>{$l=f.sessions,f.inject(["remote","remote.credentials"],l=>(_t=l.remote?.credentials??l["remote.credentials"]??null,()=>{_t=null}));let c=!1,p=()=>{};rs={set(l){if(l!==c){if(c=l,l){p=x_();return}p(),p=()=>{},ii(),Kt()}}},rc(!0),jn();for(let l of a)f.slots.inject("plugins.row.config",()=>f.slots.register({name:"plugins.row.config",key:l},n));f.slots.inject("settings.kit.item",()=>f.slots.register({name:"settings.kit.item",id:"tty",order:80,label:()=>"\u7EC8\u7AEF\u9762\u677F"},n)),f.slots.inject("settings.plugin.item",()=>f.slots.register({name:"settings.plugin.item",key:"tty",order:100},n));let g=f.provide("ttyConnbar",{version:1,addAction:cs,requestRender(){Kt()}}),S=f.provide("ttyTerminal",{version:3,open(l){if(!Vt)return;let d=Vl(l),h=Gl(l,d),u=typeof l?.label=="string"&&l.label!==""?l.label:void 0;if(si(),l?.reuse!==!1){let v=Of(h);if(v!==null)return Bn(),Wt(v.sid),v}return Bn(),ei(h,u)},mount(l,d){return Vt?Uf(l,d):()=>{}}}),_=f.provide("ttyPanel",{version:2,isOpen(){return se!==null&&!Ae},mountPane(l){return Jl(l)},minimize(){return ns(),se!==null&&Ae}});return()=>{rs=null,Vt=!1,p(),_(),S(),g(),ii()}},t}});})();
2682
2713
  /*! Bundled license information:
2683
2714
 
2684
2715
  @xterm/addon-search/lib/addon-search.mjs: