@snowlocked/dsh-k8s-console 0.1.0
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/README.md +21 -0
- package/cordis.patch.yml +4 -0
- package/lib/client.js +828 -0
- package/lib/index.js +25 -0
- package/package.json +52 -0
package/README.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# dsh-k8s-console
|
|
2
|
+
|
|
3
|
+
DSH(DeepSeek Harness)**K8s 控制台**插件:kubeconfig 管理 + 集群会话工作区。
|
|
4
|
+
|
|
5
|
+
- ➕ 添加 kubeconfig(粘贴内容 / 导入本机文件路径),列表展示 context / API server
|
|
6
|
+
- 点击列表项即**新建会话 Tab**(重复点击同一集群会再开一个独立会话,不定位旧 Tab)
|
|
7
|
+
- 每个会话 2 个子页:
|
|
8
|
+
- ⌨️ **命令控制台**:所选 context/namespace 下执行 kubectl,SSE 流式输出,可中止/超时
|
|
9
|
+
- 💬 **AI 对话**:多轮对话生成命令 / 解释输出,回复内命令可一键发到控制台执行;
|
|
10
|
+
AI 模型复用 DSH 自身配置(界面按需选模型,无需重复填 Key)
|
|
11
|
+
|
|
12
|
+
构建与安装见仓库根 README;本目录为可发布/可链接安装形态:
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
# 开发/自用(先 build 生成 lib/)
|
|
16
|
+
dsh plugin --profile web add "link:D:\path\to\dsh-plugin-k8s\plugins\dsh-plugin-k8s"
|
|
17
|
+
# 或发布后
|
|
18
|
+
dsh plugin --profile web add @snowlocked/dsh-k8s-console
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
安装后重启 `dsh web`,左侧栏底部出现「K8s」入口。
|
package/cordis.patch.yml
ADDED
package/lib/client.js
ADDED
|
@@ -0,0 +1,828 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: "@snowlocked/dsh-k8s-console",
|
|
3
|
+
factory: (require) => {
|
|
4
|
+
"use strict";
|
|
5
|
+
var __dsh_k8s_internal = { exports: {} };
|
|
6
|
+
var __dsh_k8s_exports = __dsh_k8s_internal.exports;
|
|
7
|
+
Object.defineProperty(__dsh_k8s_exports, Symbol.toStringTag, { value: "Module" });
|
|
8
|
+
"use strict";var __dsh_k8s_module__=(()=>{var pe=Object.defineProperty;var Ue=Object.getOwnPropertyDescriptor;var Ge=Object.getOwnPropertyNames;var Qe=Object.prototype.hasOwnProperty;var E=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,n)=>(typeof require<"u"?require:t)[n]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var Ze=(e,t)=>{for(var n in t)pe(e,n,{get:t[n],enumerable:!0})},et=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Ge(t))!Qe.call(e,s)&&s!==n&&pe(e,s,{get:()=>t[s],enumerable:!(o=Ue(t,s))||o.enumerable});return e};var tt=e=>et(pe({},"__esModule",{value:!0}),e);var kt={};Ze(kt,{apply:()=>ut,inject:()=>dt});var ae=E("react");var oe=E("react");var Pe=E("react");var Ce="dsh-k8s-console.persist.v1";function ue(){try{let e=window.localStorage.getItem(Ce);if(!e)return{};let t=JSON.parse(e);return t&&typeof t=="object"?t:{}}catch{return{}}}function Se(e){try{let t={...ue(),...e};window.localStorage.setItem(Ce,JSON.stringify(t))}catch{}}var Y=ue().panelOpen===!0,fe=new Set,ke=()=>{for(let e of fe)e()},me=Object.freeze({panelOpen:!0}),ge=Object.freeze({panelOpen:!1}),ne=Y?me:ge,be=()=>{try{Se({panelOpen:Y})}catch{}},W={open(){Y||(Y=!0,ne=me,be(),ke())},close(){Y&&(Y=!1,ne=ge,be(),ke())},toggle(){Y=!Y,ne=Y?me:ge,be(),ke()},getSnapshot:()=>ne,subscribe(e){return fe.add(e),()=>fe.delete(e)}};function Ee(){return(0,Pe.useSyncExternalStore)(W.subscribe,W.getSnapshot,W.getSnapshot)}var V=E("react/jsx-runtime"),nt=(0,V.jsxs)("svg",{viewBox:"0 0 16 16",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:1.4,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,V.jsx)("circle",{cx:"8",cy:"8",r:"1.4",fill:"currentColor",stroke:"none"}),(0,V.jsx)("circle",{cx:"8",cy:"2.6",r:"1.05",fill:"currentColor",stroke:"none"}),(0,V.jsx)("circle",{cx:"8",cy:"13.4",r:"1.05",fill:"currentColor",stroke:"none"}),(0,V.jsx)("circle",{cx:"2.6",cy:"8",r:"1.05",fill:"currentColor",stroke:"none"}),(0,V.jsx)("circle",{cx:"13.4",cy:"8",r:"1.05",fill:"currentColor",stroke:"none"}),(0,V.jsx)("path",{d:"M8 4v2.6M8 9.4V12M4.6 6.6l2.2 1.4M9.2 8l2.2 1.4M4.6 9.4l2.2-1.4M9.2 8l2.2-1.4"})]});function $e(e={}){let{wide:t=!0,t:n=(c=>c)}=e,o=n,s=(0,oe.useSyncExternalStore)(W.subscribe,W.getSnapshot,W.getSnapshot),m=(0,oe.useCallback)(()=>{W.toggle()},[]);return(0,V.jsxs)("button",{type:"button","data-d-sh-plugin":"k8s-console","data-active":s.panelOpen||void 0,"aria-label":o("sidebar.aria"),title:o("sidebar.title"),onClick:m,className:"kc-sidebar-entry",children:[(0,V.jsx)("span",{className:"kc-sidebar-entry-icon","aria-hidden":"true",children:nt}),t?(0,V.jsx)("span",{className:"kc-sidebar-entry-label",children:o("sidebar.label")}):null]})}var re=E("react");var M=E("react");var Te="/api/dsh-plugin-k8s",G=class extends Error{status;code;constructor(t,n,o){super(t),this.status=n,this.code=o}};async function X(e){return e instanceof G||e instanceof Error?e.message:typeof e=="string"?e:JSON.stringify(e)}function Ke(e){return{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(e??{})}}async function Z(e,t){let n;try{n=await fetch(`${Te}${e}`,Ke(t))}catch(s){throw new G(`\u7F51\u7EDC\u8BF7\u6C42\u5931\u8D25\uFF1A${s instanceof Error?s.message:String(s)}`,0)}let o=null;try{o=await n.json()}catch{o=null}if(!n.ok){let s=o&&typeof o=="object"?o:{};throw new G(String(s.error??`HTTP ${n.status}`),n.status,String(s.code??""))}return o}async function Ae(e,t,n,o){let s;try{s=await fetch(`${Te}${e}`,{...Ke(t),...o?{signal:o}:{}})}catch(b){throw o?.aborted?b:new G(`\u7F51\u7EDC\u8BF7\u6C42\u5931\u8D25\uFF1A${b instanceof Error?b.message:String(b)}`,0)}if(!s.ok||!s.body){let b=`HTTP ${s.status}`;try{let k=await s.json();k?.error&&(b=k.error)}catch{}throw new G(b,s.status)}let m=s.body.getReader(),c=new TextDecoder("utf-8"),P="";for(;;){let b;try{b=await m.read()}catch(h){throw o?.aborted?h:new G(`\u8BFB\u53D6\u6D41\u5931\u8D25\uFF1A${h instanceof Error?h.message:String(h)}`,0)}if(b.done)break;P+=c.decode(b.value,{stream:!0});let k;for(;(k=P.indexOf(`
|
|
9
|
+
|
|
10
|
+
`))>=0;){let h=P.slice(0,k);if(P=P.slice(k+2),h.startsWith("data: ")){let T=h.slice(6).trim();if(!T)continue;try{n(JSON.parse(T))}catch{}}}}if(P.startsWith("data: ")){let b=P.slice(6).trim();if(b)try{n(JSON.parse(b))}catch{}}}var B={state:e=>Z("/state",e?{refresh:!0}:{}),kubeconfigs:()=>Z("/kubeconfigs/list"),save:e=>Z("/kubeconfigs/save",e),remove:e=>Z("/kubeconfig/remove",{id:e}),raw:e=>Z("/kubeconfig/raw",{id:e}),check:e=>Z("/kubeconfigs/check",{id:e}),aiModels:()=>Z("/ai/models"),run:(e,t,n)=>Ae("/run",e,t,n),chat:(e,t,n)=>Ae("/ai/chat",e,t,n)};function ze(e){let t=[];for(let n of e.providers)if(n.models.length===0)t.push({key:`p:${n.provider}`,provider:n.provider,label:n.label??n.provider});else for(let o of n.models)t.push({key:`m:${n.provider}/${o.id}`,provider:n.provider,model:o.id,label:o.label??`${n.provider} \xB7 ${o.id}`});return t}function Me(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function xe(e){if(!e)return"\u2014";let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString("zh-CN",{hour12:!1})}var H=E("react");var p=E("react/jsx-runtime"),ve={open:!1,name:"",mode:"paste",content:"",filePath:"",busy:!1,error:null};function Re(e){let{kubeconfigs:t,busyList:n,refresh:o,onOpenSession:s,onFlash:m}=e,[c,P]=(0,H.useState)(ve),[b,k]=(0,H.useState)(null),h=e.stateInfo?.kubectl,T=(0,H.useRef)(null);(0,H.useEffect)(()=>{c.open&&c.mode==="paste"&&T.current?.focus()},[c.open,c.mode]);let g=(0,H.useCallback)(a=>{P(w=>({...w,...a}))},[]),K=(0,H.useCallback)(()=>{P(ve)},[]),z=(0,H.useCallback)(async()=>{if(c.busy)return;let a=c.name.trim();if(!a){g({error:"\u8BF7\u586B\u5199 kubeconfig \u540D\u79F0\uFF08\u663E\u793A\u7528\uFF09"});return}if(c.mode==="paste"&&c.content.trim()===""){g({error:"\u8BF7\u7C98\u8D34 kubeconfig \u5185\u5BB9\uFF0C\u6216\u6539\u7528\u201C\u672C\u673A\u6587\u4EF6\u5BFC\u5165\u201D"});return}if(c.mode==="path"&&c.filePath.trim()===""){g({error:"\u8BF7\u586B\u5199\u672C\u673A kubeconfig \u6587\u4EF6\u8DEF\u5F84\uFF08\u5982 D:\\path\\dev.yaml\uFF09"});return}g({busy:!0,error:null});try{await B.save({name:a,content:c.mode==="paste"?c.content:void 0,filePath:c.mode==="path"?c.filePath:void 0}),K(),m("ok",`\u5DF2\u4FDD\u5B58 kubeconfig\u300C${a}\u300D`),o()}catch(w){g({error:await X(w)})}finally{g({busy:!1})}},[c,g,K,m,o]),R=(0,H.useCallback)(async a=>{if(window.confirm(`\u5220\u9664 kubeconfig\u300C${a.name}\u300D\uFF1F
|
|
11
|
+
|
|
12
|
+
\u8BE5\u64CD\u4F5C\u4F1A\u79FB\u9664\u672C\u5730\u4FDD\u5B58\u7684\u6587\u4EF6\u526F\u672C\uFF08\u542B\u8BBF\u95EE\u51ED\u636E\uFF09\uFF0C\u5E76\u5173\u95ED\u5B83\u7684\u6240\u6709\u4F1A\u8BDD Tab\u3002`)){k(`rm:${a.id}`);try{let{ok:O}=await B.remove(a.id);O?(m("info",`\u5DF2\u5220\u9664\u300C${a.name}\u300D`),o()):m("error","\u5220\u9664\u5931\u8D25\uFF1A\u670D\u52A1\u7AEF\u672A\u786E\u8BA4")}catch(O){m("error",`\u5220\u9664\u5931\u8D25\uFF1A${await X(O)}`)}finally{k(null)}}},[m,o]),j=(0,H.useCallback)(async a=>{k(`check:${a.id}`);try{let w=await B.check(a.id);m(w.ok?"ok":"error",`\u300C${a.name}\u300D${w.ok?"\u2705 \u96C6\u7FA4\u53EF\u8FBE":"\u274C \u4E0D\u53EF\u8FBE"}\uFF1A${w.message}`)}catch(w){m("error",`\u300C${a.name}\u300D\u68C0\u67E5\u5931\u8D25\uFF1A${await X(w)}`)}finally{k(null),o()}},[m,o]),I=(0,H.useCallback)(async a=>{k(`copy:${a.id}`);try{let{content:w}=await B.raw(a.id);await navigator.clipboard.writeText(w),m("ok",`\u5DF2\u590D\u5236\u300C${a.name}\u300D\u5B8C\u6574 kubeconfig \u5230\u526A\u8D34\u677F\uFF08\u542B\u51ED\u636E\uFF0C\u6CE8\u610F\u4FDD\u7BA1\uFF09`)}catch(w){m("error",`\u590D\u5236\u5931\u8D25\uFF1A${await X(w)}`)}finally{k(null)}},[m]);return(0,p.jsxs)("div",{className:"kc-nav",children:[(0,p.jsxs)("div",{className:"kc-nav-head",children:[(0,p.jsx)("span",{className:"kc-nav-title",children:"kubeconfig"}),(0,p.jsx)("span",{className:"kc-nav-count",children:t.length}),(0,p.jsx)("span",{className:"kc-grow"}),(0,p.jsx)("button",{className:"kc-btn-sm",onClick:()=>{g({...ve,open:!0})},title:"\u6DFB\u52A0 kubeconfig\uFF08\u7C98\u8D34\u5185\u5BB9\u6216\u5BFC\u5165\u672C\u673A\u6587\u4EF6\uFF09",children:"\u2795 \u6DFB\u52A0"}),(0,p.jsx)("button",{className:"kc-btn-sm",onClick:()=>void o(),disabled:n,title:"\u5237\u65B0\u5217\u8868",children:"\u21BB"})]}),h&&!h.present?(0,p.jsxs)("div",{className:"kc-warnbox",title:h.missingReason,children:[(0,p.jsx)("div",{className:"kc-warnbox-title",children:"\u26A0\uFE0F kubectl \u4E0D\u53EF\u7528"}),(0,p.jsx)("div",{className:"kc-warnbox-text",children:h.missingReason})]}):null,(0,p.jsxs)("div",{className:"kc-nav-list",children:[t.length===0?(0,p.jsx)("div",{className:"kc-nav-empty",children:n?"\u52A0\u8F7D\u4E2D\u2026":`\u8FD8\u6CA1\u6709 kubeconfig\u3002
|
|
13
|
+
\u70B9\u53F3\u4E0A\u89D2 \u2795 \u6DFB\u52A0\uFF08\u7C98\u8D34\u5185\u5BB9\u6216\u5BFC\u5165\u672C\u673A\u6587\u4EF6\uFF09\u3002`}):null,t.map(a=>{let w=b===`rm:${a.id}`||b===`check:${a.id}`||b===`copy:${a.id}`;return(0,p.jsxs)("div",{className:"kc-conn",title:"\u70B9\u51FB\u65B0\u5EFA\u4F1A\u8BDD\uFF08\u540C\u4E00\u96C6\u7FA4\u53EF\u5F00\u591A\u4E2A\uFF09",children:[(0,p.jsxs)("button",{type:"button",className:"kc-conn-main",onClick:()=>s(a),disabled:n,children:[(0,p.jsx)("span",{className:"kc-conn-name",children:a.name}),(0,p.jsxs)("span",{className:"kc-conn-sub",children:[a.currentContext??a.contextNames[0]??"\uFF08\u65E0 context\uFF09",a.contextNames.length>1?`\uFF08\u5171 ${a.contextNames.length} \u4E2A context\uFF09`:""]}),(0,p.jsx)("span",{className:"kc-conn-server",title:"API server",children:a.server??""}),a.lastCheckError?(0,p.jsx)("span",{className:"kc-conn-state kc-conn-state-bad",title:`\u4E0A\u6B21\u68C0\u67E5\u5931\u8D25\uFF1A${a.lastCheckError}`,children:"\u2715"}):a.lastCheckedAt?(0,p.jsx)("span",{className:"kc-conn-state kc-conn-state-ok",title:`\u4E0A\u6B21\u68C0\u67E5 ${xe(a.lastCheckedAt)}`,children:"\u2713"}):null]}),(0,p.jsxs)("span",{className:"kc-conn-actions",children:[(0,p.jsx)("button",{className:"kc-icon-btn",title:"\u6D4B\u8BD5\u8FDE\u901A\uFF08kubectl get --raw=/version\uFF09",disabled:w,onClick:()=>void j(a),children:w&&b===`check:${a.id}`?"\u2026":"\u6D4B"}),(0,p.jsx)("button",{className:"kc-icon-btn",title:"\u590D\u5236\u5B8C\u6574 kubeconfig\uFF08\u542B\u51ED\u636E\uFF09",disabled:w,onClick:()=>void I(a),children:w&&b===`copy:${a.id}`?"\u2026":"\u29C9"}),(0,p.jsx)("button",{className:"kc-icon-btn kc-icon-btn-danger",title:`\u5220\u9664\uFF08${Me(a.size)}\uFF0C\u66F4\u65B0\u4E8E ${xe(a.updatedAt)}\uFF09`,disabled:w,onClick:()=>void R(a),children:"\u2715"})]})]},a.id)})]}),(0,p.jsx)("div",{className:"kc-nav-foot",children:(0,p.jsxs)("div",{className:"kc-muted",style:{fontSize:11,lineHeight:1.6},children:["\u6570\u636E\u76EE\u5F55\uFF1A",e.stateInfo?.dataDir??"\u2026",h?.present&&h.version?(0,p.jsxs)("div",{children:["kubectl ",h.version]}):null]})}),c.open?(0,p.jsx)("div",{className:"kc-modal-mask",onMouseDown:a=>{a.target===a.currentTarget&&K()},children:(0,p.jsxs)("div",{className:"kc-modal",children:[(0,p.jsx)("div",{className:"kc-modal-title",children:"\u2795 \u6DFB\u52A0 kubeconfig"}),(0,p.jsxs)("div",{className:"kc-field",children:[(0,p.jsx)("label",{children:"\u540D\u79F0\uFF08\u663E\u793A\u7528\uFF09"}),(0,p.jsx)("input",{value:c.name,onChange:a=>g({name:a.target.value,error:null}),placeholder:"\u4F8B\u5982\uFF1Adevelopment / dev",autoFocus:!0})]}),(0,p.jsxs)("div",{className:"kc-seg",role:"tablist",children:[(0,p.jsx)("button",{type:"button",role:"tab","aria-selected":c.mode==="paste",className:c.mode==="paste"?"kc-seg-active":"",onClick:()=>g({mode:"paste"}),children:"\u{1F4CB} \u7C98\u8D34\u5185\u5BB9"}),(0,p.jsx)("button",{type:"button",role:"tab","aria-selected":c.mode==="path",className:c.mode==="path"?"kc-seg-active":"",onClick:()=>g({mode:"path"}),children:"\u{1F4C1} \u5BFC\u5165\u672C\u673A\u6587\u4EF6"})]}),c.mode==="paste"?(0,p.jsxs)("div",{className:"kc-field",children:[(0,p.jsx)("label",{children:"kubeconfig \u5185\u5BB9\uFF08YAML\uFF09"}),(0,p.jsx)("textarea",{ref:T,className:"kc-code-input",rows:10,value:c.content,onChange:a=>g({content:a.target.value,error:null}),placeholder:`apiVersion: v1
|
|
14
|
+
kind: Config
|
|
15
|
+
clusters:
|
|
16
|
+
- name: "dev"
|
|
17
|
+
cluster:
|
|
18
|
+
server: "https://\u2026"
|
|
19
|
+
\u2026`,spellCheck:!1})]}):(0,p.jsxs)("div",{className:"kc-field",children:[(0,p.jsx)("label",{children:"\u672C\u673A\u6587\u4EF6\u8DEF\u5F84"}),(0,p.jsx)("input",{value:c.filePath,onChange:a=>g({filePath:a.target.value,error:null}),placeholder:"D:\\Users\\wuzan\\.kube\\configs\\dev.yaml",spellCheck:!1}),(0,p.jsx)("div",{className:"kc-muted",style:{fontSize:11,marginTop:4},children:"\u8BFB\u53D6\u8BE5\u8DEF\u5F84\u7684\u5185\u5BB9\u5E76\u4FDD\u5B58\u526F\u672C\u5230\u63D2\u4EF6\u6570\u636E\u76EE\u5F55\uFF08\u652F\u6301 .yaml/.yml/.config\uFF09\u3002\u4FEE\u6539\u539F\u6587\u4EF6\u4E0D\u4F1A\u540C\u6B65 \u2014\u2014 \u60F3\u7528\u65B0\u7248\u8BF7\u5220\u9664\u540E\u91CD\u65B0\u5BFC\u5165\u3002"})]}),c.error?(0,p.jsx)("div",{className:"kc-form-error",children:c.error}):null,(0,p.jsxs)("div",{className:"kc-modal-actions",children:[(0,p.jsx)("button",{onClick:K,disabled:c.busy,children:"\u53D6\u6D88"}),(0,p.jsx)("button",{className:"kc-btn-primary",onClick:()=>void z(),disabled:c.busy,children:c.busy?"\u4FDD\u5B58\u5E76\u89E3\u6790\u2026":"\u4FDD\u5B58"})]})]})}):null]})}var Q=E("react");var N=E("react");var y=E("react/jsx-runtime"),Oe=800,ot=["get pods -A","get nodes -o wide","get all -n default","logs deploy/xxx -n <ns> --tail=100","describe pod <name> -n <ns>","get events -n <ns> --sort-by=.lastTimestamp"];function rt(e){switch(e){case"timeout":return"\u5DF2\u8D85\u65F6\u88AB\u7EC8\u6B62";case"bytes":return"\u8F93\u51FA\u8D85\u8FC7\u4E0A\u9650\u5DF2\u88AB\u622A\u65AD";case"aborted":return"\u5DF2\u624B\u52A8\u4E2D\u6B62";default:return""}}var Ie=(0,N.forwardRef)(function({kube:t},n){let[o,s]=(0,N.useState)(""),[m,c]=(0,N.useState)(""),[P,b]=(0,N.useState)(""),[k,h]=(0,N.useState)(!1),[T,g]=(0,N.useState)([]),[K,z]=(0,N.useState)(null),[R,j]=(0,N.useState)([]),[I,a]=(0,N.useState)(-1),[w,O]=(0,N.useState)(null),F=(0,N.useRef)(null),u=(0,N.useRef)(null),f=(0,N.useRef)(null),A=(0,N.useRef)(()=>{}),$=(0,N.useCallback)(r=>{g(l=>{let x=[...l,r];return x.length>Oe?x.slice(x.length-Oe):x})},[]);(0,N.useEffect)(()=>{let r=u.current;r&&(r.scrollTop=r.scrollHeight)},[T,k,K]);let J=(0,N.useCallback)(()=>{F.current?.abort()},[]),_=(0,N.useCallback)(async r=>{let l=r.trim();if(!l||k)return;let x=l.split(`
|
|
20
|
+
`).filter(C=>C.trim()!==""&&!C.trim().startsWith("#")).join(`
|
|
21
|
+
`).trim();if(!x)return;F.current=new AbortController;let L=F.current.signal;h(!0),z(null),a(-1),$({kind:"cmd",text:x}),j(C=>[...C.slice(-99),x]);let qe=C=>{if(C.type==="start")$({kind:"sys",text:`\u25B6 ${String(C.command??`kubectl ${x}`)}`}),O(`\u6B63\u5728\u6267\u884C ${String(C.command??"")} \u2026\uFF08\u53EF\u968F\u65F6\u4E2D\u6B62\uFF09`);else if(C.type==="out"){let ce=C.channel==="stderr"?"stderr":"stdout",te=typeof C.text=="string"?C.text:"";te&&$({kind:"out",channel:ce,text:te})}else if(C.type==="exit"){let ce=typeof C.code=="number"?C.code:null,te=typeof C.signal=="string"?C.signal:null,Ye=typeof C.durationMs=="number"?C.durationMs:0,Ne=C.truncated===!0,le=typeof C.reason=="string"?C.reason:void 0;z({code:ce,signal:te,durationMs:Ye,truncated:Ne,reason:le});let de=rt(le);Ne&&!de&&$({kind:"sys",text:"\u8F93\u51FA\u8D85\u8FC7\u4E0A\u9650\u5DF2\u622A\u65AD",tone:"err"}),de&&$({kind:"sys",text:de,tone:le==="aborted"?"muted":"err"}),O(null)}else C.type==="error"&&($({kind:"err",text:String(C.message??"\u672A\u77E5\u9519\u8BEF")}),O(null))};try{await B.run({id:t.id,command:x,context:m,namespace:P},qe,L),L.aborted&&($({kind:"sys",text:"\u5DF2\u4E2D\u6B62",tone:"muted"}),z(C=>C??{code:null,signal:null,durationMs:0,truncated:!1,reason:"aborted"}))}catch(C){L.aborted?$({kind:"sys",text:"\u5DF2\u4E2D\u6B62",tone:"muted"}):$({kind:"err",text:await X(C)}),O(null)}finally{h(!1),F.current=null}},[t.id,k,m,P,$]);A.current=_,(0,N.useImperativeHandle)(n,()=>({runText(r){s(r),f.current?.focus(),window.setTimeout(()=>{let l=A.current;l&&l(r)},0)}}),[]);let U=(0,N.useCallback)(()=>{_(o)},[_,o]),q=(0,N.useCallback)(r=>{if(r.key==="Enter"&&!r.shiftKey&&!r.nativeEvent.isComposing){r.preventDefault(),U();return}if(r.key==="ArrowUp"&&R.length>0){let l=I<0?R.length-1:Math.max(0,I-1);a(l),s(R[l]??""),r.preventDefault()}else if(r.key==="ArrowDown"&&I>=0){if(I>=R.length-1)a(-1),s("");else{let l=I+1;a(l),s(R[l]??"")}r.preventDefault()}},[R,I,U]),se=(0,N.useCallback)(()=>{g([]),z(null)},[]),ie=(0,N.useCallback)(async()=>{let r=T.filter(l=>l.kind==="cmd"||l.kind==="out").map(l=>l.kind==="cmd"?`$ ${l.text}`:l.text).join("");try{await navigator.clipboard.writeText(r),O("\u5DF2\u590D\u5236\u8F93\u51FA"),window.setTimeout(()=>O(null),1500)}catch(l){O(`\u590D\u5236\u5931\u8D25\uFF1A${l instanceof Error?l.message:String(l)}`)}},[T]),i=r=>{let l=[];return r.reason==="aborted"?l.push("\u5DF2\u4E2D\u6B62"):r.code===0?l.push("\u6210\u529F"):r.code!==null&&l.push(`\u9000\u51FA\u7801 ${r.code}`),r.signal&&l.push(`signal ${r.signal}`),l.push(`${(r.durationMs/1e3).toFixed(2)}s`),l.join(" \xB7 ")};return(0,y.jsxs)("div",{className:"kc-console",children:[(0,y.jsxs)("div",{className:"kc-console-toolbar",children:[(0,y.jsxs)("div",{className:"kc-console-env",children:[(0,y.jsxs)("label",{title:"\u5728\u8BE5 kubeconfig \u7684\u54EA\u4E9B context \u4E0A\u6267\u884C\uFF08\u7A7A = \u4F7F\u7528\u6587\u4EF6\u5F53\u524D\u4E0A\u4E0B\u6587\uFF09",children:["context",(0,y.jsxs)("select",{value:m,onChange:r=>c(r.target.value),disabled:k,children:[(0,y.jsx)("option",{value:"",children:t.currentContext?`${t.currentContext}\uFF08\u9ED8\u8BA4\uFF09`:"\uFF08\u9ED8\u8BA4\uFF09"}),t.contextNames.filter(r=>r!==t.currentContext).map(r=>(0,y.jsx)("option",{value:r,children:r},r))]})]}),(0,y.jsxs)("label",{title:"\u7ED9\u547D\u4EE4\u9644\u52A0 -n <namespace>\uFF08\u547D\u4EE4\u91CC\u81EA\u5E26 -n \u65F6\u4EE5\u547D\u4EE4\u91CC\u7684\u4E3A\u51C6\uFF09",children:["namespace",(0,y.jsx)("input",{value:P,onChange:r=>b(r.target.value),placeholder:"default",disabled:k,spellCheck:!1})]})]}),(0,y.jsx)("div",{className:"kc-grow"}),(0,y.jsx)("button",{className:"kc-btn-sm",onClick:se,title:"\u6E05\u7A7A\u8F93\u51FA",children:"\u6E05\u7A7A"}),(0,y.jsx)("button",{className:"kc-btn-sm",onClick:()=>void ie(),title:"\u590D\u5236\u5168\u90E8\u547D\u4EE4\u4E0E\u8F93\u51FA",children:"\u590D\u5236\u8F93\u51FA"}),(0,y.jsx)("button",{className:"kc-btn-sm",onClick:()=>{s(ot.join(`
|
|
22
|
+
`)),f.current?.focus()},title:"\u586B\u5165\u5E38\u7528\u793A\u4F8B",children:"\u793A\u4F8B"})]}),(0,y.jsxs)("div",{className:"kc-console-input-row",children:[(0,y.jsx)("textarea",{ref:f,className:"kc-code-input kc-command-input",value:o,onChange:r=>s(r.target.value),onKeyDown:q,placeholder:`kubectl \u547D\u4EE4\uFF08\u53EF\u7701\u7565\u524D\u7F00 kubectl\uFF09
|
|
23
|
+
\u4F8B\u5982\uFF1Aget pods -A
|
|
24
|
+
|
|
25
|
+
Enter \u6267\u884C \xB7 Shift+Enter \u6362\u884C \xB7 \u2191/\u2193 \u5386\u53F2 \xB7 \u975E\u4EA4\u4E92\uFF08logs -f \u7B49\u957F\u547D\u4EE4\u8BF7\u7528\u4E2D\u6B62\u6309\u94AE\uFF09`,spellCheck:!1,rows:3}),k?(0,y.jsx)("button",{className:"kc-btn-primary kc-btn-stop",onClick:J,title:"\u4E2D\u6B62\u5F53\u524D\u547D\u4EE4",children:"\u25A0 \u4E2D\u6B62"}):(0,y.jsx)("button",{className:"kc-btn-primary",onClick:U,disabled:o.trim()==="",title:"\u6267\u884C\uFF08Ctrl+Enter \u4EA6\u53EF\uFF09",children:"\u25B6 \u6267\u884C"})]}),w?(0,y.jsx)("div",{className:"kc-console-status",children:w}):null,(0,y.jsx)("div",{className:"kc-output",ref:u,children:T.length===0?(0,y.jsx)("div",{className:"kc-output-empty",children:(0,y.jsxs)("div",{className:"kc-muted",children:["\u8F93\u5165\u547D\u4EE4\u5F00\u59CB\uFF08",t.name,m?` \xB7 --context ${m}`:"",P?` \xB7 -n ${P}`:"","\uFF09\u3002",(0,y.jsx)("br",{}),"\u53EA\u8BFB\u5EFA\u8BAE\uFF1Aget / describe / logs / top / explain\u3002\u7834\u574F\u6027\u547D\u4EE4\u8BF7\u81EA\u884C\u786E\u8BA4\u5F71\u54CD\u3002"]})}):T.map((r,l)=>r.kind==="cmd"?(0,y.jsxs)("div",{className:"kc-out-line kc-out-cmd",children:[(0,y.jsx)("span",{className:"kc-out-prompt",children:"$"})," ",r.text]},l):r.kind==="out"?(0,y.jsx)("pre",{className:`kc-out-line kc-out-${r.channel}${r.text.endsWith(`
|
|
26
|
+
`),""}`,children:r.text},l):r.kind==="err"?(0,y.jsxs)("div",{className:"kc-out-line kc-out-err",children:["\u2715 ",r.text]},l):(0,y.jsx)("div",{className:`kc-out-line kc-out-sys${r.tone==="err"?" kc-out-err":""}${r.tone==="muted"?" kc-out-muted":""}`,children:r.text},l))}),K?(0,y.jsxs)("div",{className:`kc-exitbar${K.reason==="aborted"?" kc-exitbar-muted":K.code===0?"":" kc-exitbar-err"}`,children:[K.reason==="aborted"?"\u23F9 ":K.code===0?"\u2713 ":"\u2715 ",i(K),K.truncated?" \xB7 \u26A0\uFE0F \u8F93\u51FA\u88AB\u622A\u65AD":"",k?" \xB7 \u8FD0\u884C\u4E2D":""]}):null]})});var S=E("react");var d=E("react/jsx-runtime"),De=0,at=()=>(De+=1,De);function st(e){let t=/```(?:bash|sh|shell|kubectl|console)?\s*\n([\s\S]*?)```/g,n;for(;(n=t.exec(e))!==null;){let o=n[1]??"",s=he(o);if(s)return s}return he(e)}function he(e){for(let t of e.split(`
|
|
27
|
+
`)){let n=t.replace(/^\s*[$>]\s*/,"").trim();if(!(!n||n.startsWith("#"))&&/^kubectl\b/u.test(n))return n}return null}function it(e){let t=[],n=/```([\w+-]*)\s*\n([\s\S]*?)```/g,o=0,s;for(;(s=n.exec(e))!==null;)s.index>o&&t.push({kind:"text",text:e.slice(o,s.index)}),t.push({kind:"code",lang:s[1]||void 0,text:s[2]??""}),o=n.lastIndex;return o<e.length&&t.push({kind:"text",text:e.slice(o)}),t}function He({kube:e,onRunCommand:t}){let[n,o]=(0,S.useState)([]),[s,m]=(0,S.useState)(""),[c,P]=(0,S.useState)(!1),[b,k]=(0,S.useState)(null),[h,T]=(0,S.useState)(!1),[g,K]=(0,S.useState)(""),[z,R]=(0,S.useState)(null),j=(0,S.useRef)(null),I=(0,S.useRef)(null),a=(0,S.useRef)(null),w=(0,S.useCallback)(async()=>{T(!0);try{k(await B.aiModels())}catch(i){k(null),R(`\u6A21\u578B\u679A\u4E3E\u5931\u8D25\uFF1A${await X(i)}`)}finally{T(!1)}},[]);(0,S.useEffect)(()=>{w()},[w]);let O=(0,S.useMemo)(()=>b?ze(b):[],[b]),F=(0,S.useMemo)(()=>O.find(i=>i.key===g),[O,g]);(0,S.useEffect)(()=>{let i=I.current;i&&(i.scrollTop=i.scrollHeight)},[n]);let u=(0,S.useCallback)(i=>{o(r=>[...r,{...i,key:at()}])},[]),f=(0,S.useCallback)(i=>{o(r=>{if(r.length===0)return r;let l=r[r.length-1];if(l.role!=="assistant")return r;let x={...l,...i};i.content&&typeof i.content=="string"&&(x.content=l.content+i.content);let L=[...r];return L[L.length-1]=x,L})},[]),A=(0,S.useCallback)(()=>{j.current?.abort()},[]),$=(0,S.useCallback)(async()=>{let i=s.trim();if(!i||c)return;m(""),R(null);let r=n.filter(x=>x.role==="user"||x.state==="done").map(x=>({role:x.role,content:x.content}));r.push({role:"user",content:i}),u({role:"user",content:i}),u({role:"assistant",content:"",state:"streaming"}),P(!0),j.current=new AbortController;let l=j.current.signal;try{await B.chat({id:e.id,provider:F?.provider,model:F?.model,history:r.slice(-40)},x=>{x.type==="delta"&&typeof x.text=="string"?f({content:x.text}):x.type==="done"?f({state:"done",meta:{...typeof x.provider=="string"?{provider:x.provider}:{},...typeof x.model=="string"?{model:x.model}:{}}}):x.type==="aborted"?f({state:"done"}):x.type==="error"&&f({state:"error",content:`\u26A0\uFE0F ${String(x.message??"AI \u51FA\u9519")}`})},l)}catch(x){if(l.aborted)f({state:"done"});else{let L=await X(x);f({state:"error",content:`\u26A0\uFE0F ${L}`})}}finally{P(!1),j.current=null}},[s,c,n,F,e.id,u,f]),J=(0,S.useCallback)(i=>{i.key==="Enter"&&!i.shiftKey&&!i.nativeEvent.isComposing&&(i.preventDefault(),$())},[$]),_=(0,S.useCallback)(()=>{c&&A(),o([]),R(null)},[c,A]),U=[...n].reverse().find(i=>i.role==="assistant"&&i.state==="done"),q=U?st(U.content):null,se=(0,S.useCallback)(async i=>{try{await navigator.clipboard.writeText(i)}catch{}},[]),ie=i=>{if(i.role==="user")return(0,d.jsx)("div",{className:"kc-chat-user-text",children:i.content});if(i.state==="error")return(0,d.jsx)("div",{className:"kc-chat-error-text",children:i.content});let r=it(i.content);return(0,d.jsxs)("div",{className:"kc-chat-ai-text",children:[r.length===0?i.state==="streaming"?(0,d.jsx)("span",{className:"kc-chat-cursor",children:"\u258D"}):(0,d.jsx)("span",{className:"kc-muted",children:"\uFF08\u7A7A\u56DE\u590D\uFF09"}):r.map((l,x)=>{if(l.kind==="text")return(0,d.jsx)("span",{className:"kc-chat-text-span",children:l.text},x);let L=l.lang===void 0||/^(bash|sh|shell|kubectl|console)$/u.test(l.lang)?he(l.text):null;return(0,d.jsxs)("div",{className:"kc-codebox",children:[(0,d.jsxs)("div",{className:"kc-codebox-head",children:[(0,d.jsx)("span",{className:"kc-codebox-lang",children:l.lang||"code"}),(0,d.jsx)("span",{className:"kc-grow"}),(0,d.jsx)("button",{className:"kc-btn-sm",onClick:()=>void se(l.text),children:"\u590D\u5236"}),L?(0,d.jsx)("button",{className:"kc-btn-sm",onClick:()=>t(L),title:`\u53D1\u9001\u5230\u547D\u4EE4\u63A7\u5236\u53F0\u6267\u884C\uFF1A${L}`,children:"\u25B6 \u8FD0\u884C"}):null]}),(0,d.jsx)("pre",{className:"kc-codebox-body",children:l.text})]},x)}),i.state==="streaming"&&r.length>0?(0,d.jsx)("span",{className:"kc-chat-cursor",children:"\u258D"}):null]})};return(0,d.jsxs)("div",{className:"kc-chat",children:[(0,d.jsxs)("div",{className:"kc-chat-toolbar",children:[(0,d.jsxs)("label",{title:"\u590D\u7528 DSH \u5DF2\u914D\u7F6E\u7684\u6A21\u578B\uFF1B\u7A7A = \u8BA9 DSH \u81EA\u52A8\u9009\u62E9",children:["AI \u6A21\u578B",(0,d.jsxs)("select",{value:g,onChange:i=>K(i.target.value),disabled:c||h,children:[(0,d.jsx)("option",{value:"",children:"\u81EA\u52A8\uFF08\u7531 DSH \u9009\u62E9\uFF09"}),O.map(i=>(0,d.jsx)("option",{value:i.key,children:i.label??i.key},i.key))]})]}),(0,d.jsx)("button",{className:"kc-btn-sm",onClick:()=>void w(),disabled:h,title:"\u91CD\u65B0\u679A\u4E3E DSH \u6A21\u578B",children:"\u21BB \u6A21\u578B"}),(0,d.jsx)("button",{className:"kc-btn-sm",onClick:_,disabled:n.length===0&&!c,title:"\u6E05\u7A7A\u672C\u4F1A\u8BDD\u5BF9\u8BDD",children:"\u6E05\u7A7A\u5BF9\u8BDD"}),(0,d.jsx)("span",{className:"kc-grow"}),(0,d.jsxs)("span",{className:"kc-chat-cluster",title:"AI \u7CFB\u7EDF\u63D0\u793A\u4E2D\u4F1A\u643A\u5E26\u8BE5\u96C6\u7FA4\u4FE1\u606F",children:["\u2388 ",e.name," \xB7 ",e.currentContext??"",e.server?` \xB7 ${e.server.replace(/^https?:\/\//u,"")}`:""]})]}),b&&!b.ok?(0,d.jsxs)("div",{className:"kc-chat-warn",children:["\u26A0\uFE0F ",b.message??"\u6CA1\u6709\u53EF\u7528\u6A21\u578B","\uFF08\u914D\u7F6E\u597D\u540E\u70B9\u201C\u21BB \u6A21\u578B\u201D\u5237\u65B0\uFF09"]}):null,z?(0,d.jsxs)("div",{className:"kc-chat-warn",children:["\u26A0\uFE0F ",z]}):null,(0,d.jsxs)("div",{className:"kc-chat-scroll",ref:I,children:[n.length===0?(0,d.jsx)("div",{className:"kc-chat-empty",children:(0,d.jsxs)("div",{className:"kc-muted",style:{maxWidth:460},children:["\u9488\u5BF9\u5F53\u524D\u96C6\u7FA4\uFF08",e.name,"\uFF09\u63D0\u95EE\uFF0C\u4F8B\u5982\uFF1A",(0,d.jsx)("br",{}),"\xB7 \u201C\u67E5\u770B default \u547D\u540D\u7A7A\u95F4\u4E0B\u6240\u6709 deployment \u53CA\u5176\u72B6\u6001\u201D",(0,d.jsx)("br",{}),"\xB7 \u201C\u627E\u51FA ImagePullBackOff \u7684 pod\uFF0C\u5E76\u89E3\u91CA\u600E\u4E48\u6392\u67E5\u201D",(0,d.jsx)("br",{}),"\xB7 \u201C\u751F\u6210\u628A myapp \u7F29\u5230 2 \u526F\u672C\u7684\u547D\u4EE4\u201D",(0,d.jsx)("br",{}),"\xB7 \u201C\u7C98\u8D34\u4E00\u6761 kubectl \u62A5\u9519\uFF0C\u5E2E\u6211\u89E3\u91CA\u539F\u56E0\u201D",(0,d.jsx)("br",{}),(0,d.jsx)("br",{}),"AI \u751F\u6210\u7684\u53EF\u6267\u884C\u547D\u4EE4\u4F1A\u5728\u4EE3\u7801\u5757\u4E0B\u65B9\u63D0\u4F9B ",(0,d.jsx)("b",{children:"\u25B6 \u8FD0\u884C"}),"\uFF0C\u70B9\u51FB\u540E\u5207\u5230\u547D\u4EE4\u63A7\u5236\u53F0\u76F4\u63A5\u6267\u884C\u3002"]})}):n.map(i=>(0,d.jsxs)("div",{className:`kc-chat-row kc-chat-${i.role}`,children:[(0,d.jsx)("div",{className:"kc-chat-avatar",children:i.role==="user"?"\u{1F9D1}":"\u{1F916}"}),(0,d.jsxs)("div",{className:"kc-chat-bubble",children:[ie(i),i.state==="done"&&i.meta&&(i.meta.provider||i.meta.model)?(0,d.jsxs)("div",{className:"kc-chat-meta",children:[i.meta.provider,"/",i.meta.model]}):null]})]},i.key)),q&&!c?(0,d.jsxs)("div",{className:"kc-chat-quickrun",children:["\u{1F4A1} \u53EF\u7528\u547D\u4EE4\uFF1A",(0,d.jsx)("code",{children:q}),(0,d.jsx)("button",{className:"kc-btn-sm",onClick:()=>t(q),children:"\u25B6 \u53D1\u9001\u5230\u63A7\u5236\u53F0\u6267\u884C"})]}):null]}),(0,d.jsxs)("div",{className:"kc-chat-input-row",children:[(0,d.jsx)("textarea",{ref:a,className:"kc-code-input kc-chat-input",value:s,onChange:i=>m(i.target.value),onKeyDown:J,placeholder:"\u95EE AI\uFF1A\u751F\u6210 kubectl \u547D\u4EE4 / \u89E3\u91CA\u8F93\u51FA / \u6392\u67E5\u62A5\u9519\u2026\uFF08Enter \u53D1\u9001\uFF0CShift+Enter \u6362\u884C\uFF09",spellCheck:!1,rows:2}),c?(0,d.jsx)("button",{className:"kc-btn-primary kc-btn-stop",onClick:A,children:"\u25A0 \u505C\u6B62"}):(0,d.jsx)("button",{className:"kc-btn-primary",onClick:()=>void $(),disabled:s.trim()==="",children:"\u53D1\u9001"})]})]})}var D=E("react/jsx-runtime");function Le({kube:e}){let[t,n]=(0,Q.useState)("console"),[o,s]=(0,Q.useState)({console:!0,chat:!1}),m=(0,Q.useRef)(null),c=(0,Q.useCallback)(k=>{n(k),s(h=>h[k]?h:{...h,[k]:!0})},[]),P=(0,Q.useCallback)(k=>{c("console"),window.setTimeout(()=>{m.current?.runText(k)},0)},[c]),b=(k,h,T)=>(0,D.jsx)("button",{type:"button",role:"tab","aria-selected":t===k,title:T,className:t===k?"kc-seg-active":"",onClick:()=>c(k),children:h});return(0,D.jsxs)("div",{className:"kc-workspace",children:[(0,D.jsxs)("div",{className:"kc-ws-meta",children:[(0,D.jsxs)("span",{className:"kc-ws-meta-name",title:`kubeconfig \u6587\u4EF6\uFF1A${e.fileName}`,children:["\u2388 ",e.name]}),(0,D.jsx)("span",{className:"kc-ws-meta-chip",title:"\u5F53\u524D\u4E0A\u4E0B\u6587",children:e.currentContext??e.contextNames.join(", ")??"\uFF08\u65E0\uFF09"}),e.server?(0,D.jsx)("span",{className:"kc-ws-meta-chip kc-ws-meta-server",title:"API server",children:e.server}):null,(0,D.jsx)("span",{className:"kc-grow"}),(0,D.jsxs)("div",{className:"kc-seg",role:"tablist","aria-label":"\u4F1A\u8BDD\u5B50\u9875",children:[b("console","\u2328\uFE0F \u547D\u4EE4\u63A7\u5236\u53F0","\u76F4\u63A5\u6267\u884C kubectl \u547D\u4EE4\uFF08\u4F7F\u7528\u672C\u4F1A\u8BDD\u9009\u62E9\u7684 context / namespace\uFF09"),b("chat","\u{1F4AC} AI \u5BF9\u8BDD","\u591A\u8F6E\u5BF9\u8BDD\uFF1A\u751F\u6210 kubectl \u547D\u4EE4 / \u89E3\u91CA\u8F93\u51FA\u7ED3\u679C\uFF1B\u6A21\u578B\u8DDF\u968F DSH \u914D\u7F6E")]})]}),(0,D.jsxs)("div",{className:"kc-ws-body",children:[o.console?(0,D.jsx)("div",{className:"kc-ws-pane","data-active":t==="console"?"true":void 0,style:t==="console"?void 0:{display:"none"},children:(0,D.jsx)(Ie,{ref:m,kube:e})}):null,o.chat?(0,D.jsx)("div",{className:"kc-ws-pane","data-active":t==="chat"?"true":void 0,style:t==="chat"?void 0:{display:"none"},children:(0,D.jsx)(He,{kube:e,onRunCommand:P})}):null]})]})}var v=E("react/jsx-runtime"),Be=0;function ct(){return Be+=1,`session_${Date.now().toString(36)}_${Be}`}function ye(e={}){let[t,n]=(0,M.useState)([]),[o,s]=(0,M.useState)(null),[m,c]=(0,M.useState)(!1),[P,b]=(0,M.useState)(null),[k,h]=(0,M.useState)(null),T=(0,M.useRef)(!0),[g,K]=(0,M.useState)([]),[z,R]=(0,M.useState)(null),j=(0,M.useCallback)((u,f)=>{h({kind:u,text:f}),window.setTimeout(()=>h(A=>A?.text===f?null:A),u==="error"?6e3:2600)},[]),I=(0,M.useCallback)(async()=>{c(!0);try{let[u,{kubeconfigs:f}]=await Promise.all([B.state(!0),B.kubeconfigs()]);s(u),n(f),b(null)}catch(u){let f=await X(u);b(`\u65E0\u6CD5\u8FDE\u63A5\u63D2\u4EF6\u670D\u52A1\uFF1A${f}\u3002\u8BF7\u786E\u8BA4\u5DF2\u5728 DSH \u4E2D\u5B89\u88C5\u5E76\u542F\u7528 dsh-plugin-k8s\uFF08\u91CD\u542F dsh web \u540E\u751F\u6548\uFF09\u3002`),j("error",`\u52A0\u8F7D\u5931\u8D25\uFF1A${f}`)}finally{c(!1)}},[j]);(0,M.useEffect)(()=>{T.current&&(T.current=!1,I())},[I]),(0,M.useEffect)(()=>{let u=new Set(t.map(f=>f.id));K(f=>{let A=f.filter($=>u.has($.kube.id));return A.length===f.length?f:A})},[t]),(0,M.useEffect)(()=>{z!==null&&!g.some(u=>u.key===z)&&R(g.length>0?g[g.length-1].key:null)},[g,z]);let a=(0,M.useCallback)(u=>{let f={key:ct(),kube:u};K(A=>[...A,f]),R(f.key)},[]),w=(0,M.useCallback)(u=>{let f=g.findIndex(J=>J.key===u);if(K(J=>J.filter(_=>_.key!==u)),z!==u)return;let A=f>=0?g[f+1]:void 0,$=f>=0?g[f-1]:void 0;R((A??$)?.key??null)},[g,z]),O=(u,f)=>{let A=g.slice(0,f+1).filter(q=>q.kube.id===u.kube.id).length,$=g.filter(q=>q.kube.id===u.kube.id).length,J=u.kube.name,_=$>1?`${J} #${A}`:J,U=u.kube.currentContext?` \xB7 ${u.kube.currentContext}`:"";return{title:_,sub:`${u.kube.name}${U} \u2014 \u4F1A\u8BDD ${A}`}},F=u=>(0,v.jsx)(Le,{kube:u.kube},u.key);return(0,v.jsxs)("div",{className:"kc-app",children:[(0,v.jsxs)("div",{className:"kc-topbar",children:[(0,v.jsxs)("div",{className:"kc-title",children:[(0,v.jsx)("span",{className:"kc-logo",children:"K8s"})," K8s \u63A7\u5236\u53F0",(0,v.jsx)("span",{className:"kc-badge",children:"dsh-plugin-k8s"}),o?.kubectl.version?(0,v.jsxs)("span",{className:"kc-badge kc-badge-ok",children:["kubectl ",o.kubectl.version]}):null,o&&!o.kubectl.present?(0,v.jsx)("span",{className:"kc-badge kc-badge-bad",title:o.kubectl.missingReason,children:"kubectl \u672A\u627E\u5230"}):null]}),(0,v.jsx)("div",{className:"kc-grow"}),k?(0,v.jsx)("span",{className:`kc-notice kc-notice-${k.kind}`,title:k.text,children:k.text}):null,m?(0,v.jsx)("span",{className:"kc-muted",children:"\u2026"}):null,e.onClose?(0,v.jsx)("button",{onClick:e.onClose,title:"\u5173\u95ED\u9762\u677F\uFF0C\u56DE\u5230\u5BF9\u8BDD",children:e.standalone?"\u2715 \u5173\u95ED":"\u2715 \u56DE\u5230\u5BF9\u8BDD"}):null]}),P?(0,v.jsx)("div",{className:"kc-fatal",children:(0,v.jsxs)("div",{className:"kc-fatal-box",children:[(0,v.jsx)("div",{className:"kc-fatal-title",children:"\u26A0\uFE0F K8s \u63A7\u5236\u53F0\u6682\u65F6\u4E0D\u53EF\u7528"}),(0,v.jsx)("div",{className:"kc-fatal-text",children:P}),(0,v.jsx)("button",{onClick:()=>{b(null),I()},children:"\u91CD\u8BD5"})]})}):(0,v.jsxs)("div",{className:"kc-app-body",children:[(0,v.jsx)(Re,{kubeconfigs:t,busyList:m,refresh:I,onOpenSession:a,onFlash:j,stateInfo:o}),(0,v.jsxs)("div",{className:"kc-main",children:[(0,v.jsxs)("div",{className:"kc-tabbar",role:"tablist","aria-label":"\u5DF2\u6253\u5F00\u7684\u96C6\u7FA4\u4F1A\u8BDD",children:[g.length===0?(0,v.jsx)("span",{className:"kc-muted",style:{padding:"0 10px",whiteSpace:"nowrap"},children:"\u70B9\u51FB\u5DE6\u4FA7 kubeconfig \u65B0\u5EFA\u4F1A\u8BDD\uFF08\u540C\u4E00\u96C6\u7FA4\u53EF\u5F00\u591A\u4E2A\u72EC\u7ACB\u4F1A\u8BDD\uFF09\u3002"}):null,g.map((u,f)=>{let{title:A,sub:$}=O(u,f);return(0,v.jsxs)("div",{role:"tab","aria-selected":u.key===z,className:`kc-tab${u.key===z?" kc-tab-active":""}`,title:`${$} \u2014\u2014 \u70B9\u51FB\u5207\u6362\uFF0C\u2715 \u5173\u95ED`,onClick:()=>R(u.key),children:[(0,v.jsx)("span",{className:"kc-tab-icon",children:"\u2388"}),(0,v.jsx)("span",{className:"kc-tab-label",children:A}),(0,v.jsx)("span",{className:"kc-tab-close",title:"\u5173\u95ED",onClick:J=>{J.stopPropagation(),w(u.key)},children:"\u2715"})]},u.key)})]}),(0,v.jsx)("div",{className:"kc-tabpanes",children:g.length===0?(0,v.jsxs)("div",{className:"kc-empty",style:{flex:1},children:[(0,v.jsx)("div",{style:{fontSize:30,opacity:.5},children:"\u2388"}),(0,v.jsx)("div",{children:"\u8FD8\u6CA1\u6709\u6253\u5F00\u4EFB\u4F55\u96C6\u7FA4\u4F1A\u8BDD\u3002"}),(0,v.jsxs)("div",{style:{marginTop:6,fontSize:12},className:"kc-muted",children:["\u5DE6\u4FA7\u70B9\u51FB kubeconfig \u5373\u53EF\u65B0\u5EFA\u4F1A\u8BDD Tab\uFF08\u91CD\u590D\u70B9\u51FB\u540C\u4E00\u96C6\u7FA4\u4F1A\u518D\u5F00\u4E00\u4E2A\u72EC\u7ACB\u4F1A\u8BDD\uFF09\uFF1B",(0,v.jsx)("br",{}),"\u6BCF\u4E2A\u4F1A\u8BDD\u5185\u542B\u300C\u2328\uFE0F \u547D\u4EE4\u63A7\u5236\u53F0\u300D\u4E0E\u300C\u{1F4AC} AI \u5BF9\u8BDD\u300D\u4E24\u4E2A\u5B50\u9875\uFF0C\u5404\u81EA\u72EC\u7ACB\u4FDD\u6301\u72B6\u6001\u3002"]})]}):g.map(u=>(0,v.jsx)("div",{role:"tabpanel",className:"kc-pane","data-active":u.key===z?"true":void 0,style:u.key===z?void 0:{display:"none"},children:F(u)},u.key))})]})]})]})}var we=E("react/jsx-runtime"),je=280;function Je(e){let[t,n]=(0,re.useState)({left:je,right:0});return(0,re.useEffect)(()=>{if(typeof document>"u")return;let o=document.querySelector('[class*="sidebarCol"]'),s=document.querySelector('[class*="detailsCol"]');if(o===null&&s===null)return;let m=()=>{n({left:o!==null?o.getBoundingClientRect().width:je,right:s!==null?s.getBoundingClientRect().width:0})};m();let c=new ResizeObserver(m);return o!==null&&c.observe(o),s!==null&&c.observe(s),()=>c.disconnect()},[]),(0,we.jsx)("div",{id:"dsh-k8s-console","data-hidden":e.hidden?"true":void 0,style:{position:"absolute",left:Math.max(0,Math.round(t.left)),top:0,right:Math.max(0,Math.round(t.right)),bottom:0,background:"var(--kc-bg)",display:e.hidden?"none":"flex",flexDirection:"column",overflow:"hidden",zIndex:1},children:(0,we.jsx)(ye,{onClose:e.onClose,standalone:e.standalone})})}var Ve=`/* dsh-plugin-k8s \u5BA2\u6237\u7AEF\u6837\u5F0F\uFF08\u6697\u8272\u4E3B\u9898\uFF0C\u96F6\u5916\u90E8\u4F9D\u8D56\uFF0C\u5168\u90E8\u9650\u5B9A\u5728 #dsh-k8s-console\uFF09 */
|
|
28
|
+
:root {
|
|
29
|
+
--kc-bg: #0d1117;
|
|
30
|
+
--kc-panel: #141a23;
|
|
31
|
+
--kc-panel-2: #1b2230;
|
|
32
|
+
--kc-border: #2a3345;
|
|
33
|
+
--kc-border-strong: #3a4660;
|
|
34
|
+
--kc-text: #e6e9ef;
|
|
35
|
+
--kc-muted: #8b93a3;
|
|
36
|
+
--kc-accent: #3fa7f7;
|
|
37
|
+
--kc-accent-weak: rgba(63, 167, 247, 0.14);
|
|
38
|
+
--kc-ok: #37c978;
|
|
39
|
+
--kc-warn: #e0b341;
|
|
40
|
+
--kc-err: #ff5f56;
|
|
41
|
+
--kc-radius: 8px;
|
|
42
|
+
--kc-mono: "Cascadia Code", "JetBrains Mono", Consolas, "Courier New", monospace;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/* ---------- \u4FA7\u8FB9\u680F\u5165\u53E3\uFF08\u4F4D\u4E8E DSH \u4FA7\u680F\uFF0C\u4E0D\u5728\u9762\u677F\u5185\uFF0C\u9700\u5168\u5C40\u53EF\u89C1\uFF09 ---------- */
|
|
46
|
+
button.kc-sidebar-entry {
|
|
47
|
+
display: flex;
|
|
48
|
+
align-items: center;
|
|
49
|
+
gap: 8px;
|
|
50
|
+
width: 100%;
|
|
51
|
+
min-width: 0;
|
|
52
|
+
padding: 6px 10px;
|
|
53
|
+
color: var(--kc-muted);
|
|
54
|
+
background: transparent;
|
|
55
|
+
border: 0;
|
|
56
|
+
border-radius: 8px;
|
|
57
|
+
cursor: pointer;
|
|
58
|
+
font: inherit;
|
|
59
|
+
font-size: 13px;
|
|
60
|
+
text-align: left;
|
|
61
|
+
transition: background 0.12s, color 0.12s;
|
|
62
|
+
}
|
|
63
|
+
button.kc-sidebar-entry:hover {
|
|
64
|
+
background: var(--kc-accent-weak);
|
|
65
|
+
color: var(--kc-text);
|
|
66
|
+
}
|
|
67
|
+
button.kc-sidebar-entry[data-active='true'],
|
|
68
|
+
button.kc-sidebar-entry[data-active='true']:hover {
|
|
69
|
+
background: var(--kc-accent-weak);
|
|
70
|
+
color: var(--kc-accent);
|
|
71
|
+
}
|
|
72
|
+
.kc-sidebar-entry-icon {
|
|
73
|
+
display: inline-flex;
|
|
74
|
+
flex: 0 0 auto;
|
|
75
|
+
}
|
|
76
|
+
.kc-sidebar-entry-icon svg {
|
|
77
|
+
display: block;
|
|
78
|
+
}
|
|
79
|
+
.kc-sidebar-entry-label {
|
|
80
|
+
overflow: hidden;
|
|
81
|
+
text-overflow: ellipsis;
|
|
82
|
+
white-space: nowrap;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/* ---------- \u9762\u677F\u6839 ---------- */
|
|
86
|
+
#dsh-k8s-console {
|
|
87
|
+
color: var(--kc-text);
|
|
88
|
+
font-size: 13px;
|
|
89
|
+
line-height: 1.5;
|
|
90
|
+
box-sizing: border-box;
|
|
91
|
+
}
|
|
92
|
+
#dsh-k8s-console *,
|
|
93
|
+
#dsh-k8s-console *::before,
|
|
94
|
+
#dsh-k8s-console *::after {
|
|
95
|
+
box-sizing: border-box;
|
|
96
|
+
}
|
|
97
|
+
#dsh-k8s-console input,
|
|
98
|
+
#dsh-k8s-console select,
|
|
99
|
+
#dsh-k8s-console textarea,
|
|
100
|
+
#dsh-k8s-console button {
|
|
101
|
+
font: inherit;
|
|
102
|
+
color: var(--kc-text);
|
|
103
|
+
background: var(--kc-panel-2);
|
|
104
|
+
border: 1px solid var(--kc-border);
|
|
105
|
+
border-radius: 6px;
|
|
106
|
+
}
|
|
107
|
+
#dsh-k8s-console button {
|
|
108
|
+
padding: 5px 11px;
|
|
109
|
+
cursor: pointer;
|
|
110
|
+
transition: background 0.12s, border-color 0.12s;
|
|
111
|
+
}
|
|
112
|
+
#dsh-k8s-console button:hover:not(:disabled) {
|
|
113
|
+
border-color: var(--kc-accent);
|
|
114
|
+
background: var(--kc-accent-weak);
|
|
115
|
+
}
|
|
116
|
+
#dsh-k8s-console button:disabled {
|
|
117
|
+
opacity: 0.45;
|
|
118
|
+
cursor: not-allowed;
|
|
119
|
+
}
|
|
120
|
+
#dsh-k8s-console button.kc-btn-primary {
|
|
121
|
+
background: var(--kc-accent);
|
|
122
|
+
border-color: var(--kc-accent);
|
|
123
|
+
color: #fff;
|
|
124
|
+
}
|
|
125
|
+
#dsh-k8s-console button.kc-btn-primary:hover:not(:disabled) {
|
|
126
|
+
background: #63b8ff;
|
|
127
|
+
border-color: #63b8ff;
|
|
128
|
+
}
|
|
129
|
+
#dsh-k8s-console button.kc-btn-stop {
|
|
130
|
+
background: #c0392b;
|
|
131
|
+
border-color: #c0392b;
|
|
132
|
+
}
|
|
133
|
+
#dsh-k8s-console button.kc-btn-stop:hover:not(:disabled) {
|
|
134
|
+
background: #d9534a;
|
|
135
|
+
border-color: #d9534a;
|
|
136
|
+
}
|
|
137
|
+
#dsh-k8s-console button.kc-btn-sm {
|
|
138
|
+
padding: 2px 8px;
|
|
139
|
+
font-size: 12px;
|
|
140
|
+
border-radius: 5px;
|
|
141
|
+
}
|
|
142
|
+
#dsh-k8s-console input,
|
|
143
|
+
#dsh-k8s-console select,
|
|
144
|
+
#dsh-k8s-console textarea {
|
|
145
|
+
padding: 5px 9px;
|
|
146
|
+
}
|
|
147
|
+
#dsh-k8s-console input:focus,
|
|
148
|
+
#dsh-k8s-console select:focus,
|
|
149
|
+
#dsh-k8s-console textarea:focus {
|
|
150
|
+
outline: none;
|
|
151
|
+
border-color: var(--kc-accent);
|
|
152
|
+
}
|
|
153
|
+
#dsh-k8s-console input::placeholder,
|
|
154
|
+
#dsh-k8s-console textarea::placeholder {
|
|
155
|
+
color: #5b6475;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
.kc-grow { flex: 1 1 auto; }
|
|
159
|
+
.kc-muted { color: var(--kc-muted); }
|
|
160
|
+
.kc-app {
|
|
161
|
+
display: flex;
|
|
162
|
+
flex-direction: column;
|
|
163
|
+
height: 100%;
|
|
164
|
+
overflow: hidden;
|
|
165
|
+
background: var(--kc-bg);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/* ---------- \u9876\u680F ---------- */
|
|
169
|
+
.kc-topbar {
|
|
170
|
+
display: flex;
|
|
171
|
+
align-items: center;
|
|
172
|
+
gap: 10px;
|
|
173
|
+
padding: 10px 14px;
|
|
174
|
+
background: linear-gradient(180deg, #182130, #121825);
|
|
175
|
+
border: 1px solid var(--kc-border);
|
|
176
|
+
border-radius: var(--kc-radius);
|
|
177
|
+
margin: 10px 10px 0;
|
|
178
|
+
}
|
|
179
|
+
.kc-title {
|
|
180
|
+
font-size: 14px;
|
|
181
|
+
font-weight: 600;
|
|
182
|
+
display: flex;
|
|
183
|
+
align-items: center;
|
|
184
|
+
gap: 8px;
|
|
185
|
+
min-width: 0;
|
|
186
|
+
}
|
|
187
|
+
.kc-logo {
|
|
188
|
+
width: 24px;
|
|
189
|
+
height: 24px;
|
|
190
|
+
border-radius: 6px;
|
|
191
|
+
background: linear-gradient(135deg, #3fa7f7, #7b61ff);
|
|
192
|
+
display: inline-flex;
|
|
193
|
+
align-items: center;
|
|
194
|
+
justify-content: center;
|
|
195
|
+
font-size: 11px;
|
|
196
|
+
font-weight: 800;
|
|
197
|
+
color: #fff;
|
|
198
|
+
letter-spacing: -0.5px;
|
|
199
|
+
}
|
|
200
|
+
.kc-badge {
|
|
201
|
+
font-size: 11px;
|
|
202
|
+
font-weight: 400;
|
|
203
|
+
color: var(--kc-muted);
|
|
204
|
+
border: 1px solid var(--kc-border);
|
|
205
|
+
border-radius: 999px;
|
|
206
|
+
padding: 1px 8px;
|
|
207
|
+
white-space: nowrap;
|
|
208
|
+
}
|
|
209
|
+
.kc-badge-ok { color: var(--kc-ok); border-color: rgba(55, 201, 120, 0.4); }
|
|
210
|
+
.kc-badge-bad { color: var(--kc-err); border-color: rgba(255, 95, 86, 0.4); }
|
|
211
|
+
.kc-notice {
|
|
212
|
+
font-size: 12px;
|
|
213
|
+
padding: 2px 10px;
|
|
214
|
+
border-radius: 999px;
|
|
215
|
+
white-space: nowrap;
|
|
216
|
+
overflow: hidden;
|
|
217
|
+
text-overflow: ellipsis;
|
|
218
|
+
max-width: 46%;
|
|
219
|
+
}
|
|
220
|
+
.kc-notice-ok { color: var(--kc-ok); background: rgba(55, 201, 120, 0.12); }
|
|
221
|
+
.kc-notice-error { color: var(--kc-err); background: rgba(255, 95, 86, 0.12); }
|
|
222
|
+
.kc-notice-info { color: var(--kc-accent); background: var(--kc-accent-weak); }
|
|
223
|
+
|
|
224
|
+
.kc-fatal {
|
|
225
|
+
flex: 1;
|
|
226
|
+
display: flex;
|
|
227
|
+
align-items: center;
|
|
228
|
+
justify-content: center;
|
|
229
|
+
padding: 24px;
|
|
230
|
+
}
|
|
231
|
+
.kc-fatal-box {
|
|
232
|
+
max-width: 560px;
|
|
233
|
+
background: var(--kc-panel);
|
|
234
|
+
border: 1px solid var(--kc-border-strong);
|
|
235
|
+
border-radius: 10px;
|
|
236
|
+
padding: 20px 22px;
|
|
237
|
+
}
|
|
238
|
+
.kc-fatal-title { font-weight: 600; margin-bottom: 8px; color: var(--kc-err); }
|
|
239
|
+
.kc-fatal-text { color: var(--kc-muted); margin-bottom: 14px; white-space: pre-wrap; }
|
|
240
|
+
|
|
241
|
+
/* ---------- \u4E3B\u4F53\u5E03\u5C40 ---------- */
|
|
242
|
+
.kc-app-body {
|
|
243
|
+
display: flex;
|
|
244
|
+
gap: 10px;
|
|
245
|
+
padding: 10px;
|
|
246
|
+
flex: 1;
|
|
247
|
+
min-height: 0;
|
|
248
|
+
}
|
|
249
|
+
.kc-nav {
|
|
250
|
+
width: 292px;
|
|
251
|
+
flex: 0 0 auto;
|
|
252
|
+
display: flex;
|
|
253
|
+
flex-direction: column;
|
|
254
|
+
min-height: 0;
|
|
255
|
+
background: var(--kc-panel);
|
|
256
|
+
border: 1px solid var(--kc-border);
|
|
257
|
+
border-radius: var(--kc-radius);
|
|
258
|
+
overflow: hidden;
|
|
259
|
+
}
|
|
260
|
+
.kc-main {
|
|
261
|
+
flex: 1;
|
|
262
|
+
min-width: 0;
|
|
263
|
+
display: flex;
|
|
264
|
+
flex-direction: column;
|
|
265
|
+
background: var(--kc-panel);
|
|
266
|
+
border: 1px solid var(--kc-border);
|
|
267
|
+
border-radius: var(--kc-radius);
|
|
268
|
+
overflow: hidden;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/* ---------- TabBar\uFF08\u4F1A\u8BDD\uFF09 ---------- */
|
|
272
|
+
.kc-tabbar {
|
|
273
|
+
display: flex;
|
|
274
|
+
align-items: center;
|
|
275
|
+
gap: 4px;
|
|
276
|
+
padding: 8px 10px 0;
|
|
277
|
+
overflow-x: auto;
|
|
278
|
+
scrollbar-width: thin;
|
|
279
|
+
border-bottom: 1px solid var(--kc-border);
|
|
280
|
+
background: linear-gradient(180deg, #1a2230, #151b28);
|
|
281
|
+
flex: 0 0 auto;
|
|
282
|
+
}
|
|
283
|
+
.kc-tab {
|
|
284
|
+
display: inline-flex;
|
|
285
|
+
align-items: center;
|
|
286
|
+
gap: 6px;
|
|
287
|
+
flex: 0 0 auto;
|
|
288
|
+
max-width: 240px;
|
|
289
|
+
padding: 5px 10px;
|
|
290
|
+
background: var(--kc-panel-2);
|
|
291
|
+
border: 1px solid var(--kc-border);
|
|
292
|
+
border-bottom: 0;
|
|
293
|
+
border-radius: 8px 8px 0 0;
|
|
294
|
+
color: var(--kc-muted);
|
|
295
|
+
cursor: pointer;
|
|
296
|
+
font-size: 12px;
|
|
297
|
+
user-select: none;
|
|
298
|
+
}
|
|
299
|
+
.kc-tab:hover { color: var(--kc-text); }
|
|
300
|
+
.kc-tab-active {
|
|
301
|
+
background: var(--kc-panel);
|
|
302
|
+
border-color: var(--kc-border-strong);
|
|
303
|
+
border-bottom-color: var(--kc-panel);
|
|
304
|
+
color: var(--kc-text);
|
|
305
|
+
margin-bottom: -1px;
|
|
306
|
+
}
|
|
307
|
+
.kc-tab-icon { opacity: 0.8; }
|
|
308
|
+
.kc-tab-label {
|
|
309
|
+
overflow: hidden;
|
|
310
|
+
text-overflow: ellipsis;
|
|
311
|
+
white-space: nowrap;
|
|
312
|
+
}
|
|
313
|
+
.kc-tab-close {
|
|
314
|
+
padding: 0 3px;
|
|
315
|
+
border-radius: 4px;
|
|
316
|
+
color: var(--kc-muted);
|
|
317
|
+
font-size: 11px;
|
|
318
|
+
}
|
|
319
|
+
.kc-tab-close:hover { color: var(--kc-err); background: rgba(255, 95, 86, 0.12); }
|
|
320
|
+
.kc-tabpanes { flex: 1; min-height: 0; position: relative; }
|
|
321
|
+
.kc-pane {
|
|
322
|
+
position: absolute;
|
|
323
|
+
inset: 0;
|
|
324
|
+
overflow: hidden;
|
|
325
|
+
display: flex;
|
|
326
|
+
flex-direction: column;
|
|
327
|
+
}
|
|
328
|
+
.kc-empty {
|
|
329
|
+
display: flex;
|
|
330
|
+
flex-direction: column;
|
|
331
|
+
align-items: center;
|
|
332
|
+
justify-content: center;
|
|
333
|
+
gap: 8px;
|
|
334
|
+
color: var(--kc-muted);
|
|
335
|
+
text-align: center;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/* ---------- \u5DE6\u4FA7 kubeconfig \u7BA1\u7406 ---------- */
|
|
339
|
+
.kc-nav-head {
|
|
340
|
+
display: flex;
|
|
341
|
+
align-items: center;
|
|
342
|
+
gap: 8px;
|
|
343
|
+
padding: 10px 10px 8px;
|
|
344
|
+
}
|
|
345
|
+
.kc-nav-title { font-weight: 600; font-size: 13px; }
|
|
346
|
+
.kc-nav-count {
|
|
347
|
+
font-size: 11px;
|
|
348
|
+
color: var(--kc-muted);
|
|
349
|
+
border: 1px solid var(--kc-border);
|
|
350
|
+
border-radius: 999px;
|
|
351
|
+
padding: 0 7px;
|
|
352
|
+
}
|
|
353
|
+
.kc-warnbox {
|
|
354
|
+
margin: 0 10px 8px;
|
|
355
|
+
padding: 8px 10px;
|
|
356
|
+
border: 1px solid rgba(224, 179, 65, 0.4);
|
|
357
|
+
background: rgba(224, 179, 65, 0.08);
|
|
358
|
+
border-radius: 6px;
|
|
359
|
+
font-size: 12px;
|
|
360
|
+
}
|
|
361
|
+
.kc-warnbox-title { color: var(--kc-warn); font-weight: 600; margin-bottom: 2px; }
|
|
362
|
+
.kc-warnbox-text { color: var(--kc-muted); white-space: pre-wrap; }
|
|
363
|
+
.kc-nav-list {
|
|
364
|
+
flex: 1;
|
|
365
|
+
min-height: 0;
|
|
366
|
+
overflow-y: auto;
|
|
367
|
+
padding: 0 6px 6px;
|
|
368
|
+
display: flex;
|
|
369
|
+
flex-direction: column;
|
|
370
|
+
gap: 4px;
|
|
371
|
+
}
|
|
372
|
+
.kc-nav-empty {
|
|
373
|
+
color: var(--kc-muted);
|
|
374
|
+
font-size: 12px;
|
|
375
|
+
white-space: pre-wrap;
|
|
376
|
+
padding: 14px 10px;
|
|
377
|
+
}
|
|
378
|
+
.kc-conn {
|
|
379
|
+
border: 1px solid var(--kc-border);
|
|
380
|
+
border-radius: 8px;
|
|
381
|
+
overflow: hidden;
|
|
382
|
+
display: flex;
|
|
383
|
+
align-items: stretch;
|
|
384
|
+
}
|
|
385
|
+
.kc-conn:hover { border-color: var(--kc-border-strong); }
|
|
386
|
+
.kc-conn-main {
|
|
387
|
+
flex: 1;
|
|
388
|
+
min-width: 0;
|
|
389
|
+
display: flex;
|
|
390
|
+
flex-direction: column;
|
|
391
|
+
align-items: stretch;
|
|
392
|
+
gap: 2px;
|
|
393
|
+
padding: 7px 10px;
|
|
394
|
+
text-align: left;
|
|
395
|
+
background: var(--kc-panel-2);
|
|
396
|
+
border: 0;
|
|
397
|
+
border-radius: 0;
|
|
398
|
+
}
|
|
399
|
+
.kc-conn-main:hover { background: var(--kc-accent-weak); border-color: transparent; }
|
|
400
|
+
.kc-conn-name {
|
|
401
|
+
font-weight: 600;
|
|
402
|
+
color: var(--kc-text);
|
|
403
|
+
overflow: hidden;
|
|
404
|
+
text-overflow: ellipsis;
|
|
405
|
+
white-space: nowrap;
|
|
406
|
+
}
|
|
407
|
+
.kc-conn-sub {
|
|
408
|
+
font-size: 11px;
|
|
409
|
+
color: var(--kc-muted);
|
|
410
|
+
overflow: hidden;
|
|
411
|
+
text-overflow: ellipsis;
|
|
412
|
+
white-space: nowrap;
|
|
413
|
+
}
|
|
414
|
+
.kc-conn-server {
|
|
415
|
+
font-size: 10px;
|
|
416
|
+
color: #5b6475;
|
|
417
|
+
font-family: var(--kc-mono);
|
|
418
|
+
overflow: hidden;
|
|
419
|
+
text-overflow: ellipsis;
|
|
420
|
+
white-space: nowrap;
|
|
421
|
+
direction: rtl;
|
|
422
|
+
text-align: left;
|
|
423
|
+
}
|
|
424
|
+
.kc-conn-state { font-size: 11px; }
|
|
425
|
+
.kc-conn-state-ok { color: var(--kc-ok); }
|
|
426
|
+
.kc-conn-state-bad { color: var(--kc-err); }
|
|
427
|
+
.kc-conn-actions {
|
|
428
|
+
display: flex;
|
|
429
|
+
flex-direction: column;
|
|
430
|
+
align-items: center;
|
|
431
|
+
justify-content: center;
|
|
432
|
+
gap: 4px;
|
|
433
|
+
padding: 4px 6px;
|
|
434
|
+
background: var(--kc-panel-2);
|
|
435
|
+
border-left: 1px solid var(--kc-border);
|
|
436
|
+
}
|
|
437
|
+
.kc-icon-btn {
|
|
438
|
+
width: 26px;
|
|
439
|
+
height: 22px;
|
|
440
|
+
padding: 0;
|
|
441
|
+
display: inline-flex;
|
|
442
|
+
align-items: center;
|
|
443
|
+
justify-content: center;
|
|
444
|
+
font-size: 12px;
|
|
445
|
+
border-radius: 5px;
|
|
446
|
+
}
|
|
447
|
+
.kc-icon-btn-danger:hover:not(:disabled) { color: var(--kc-err); border-color: var(--kc-err); }
|
|
448
|
+
.kc-nav-foot {
|
|
449
|
+
padding: 8px 10px;
|
|
450
|
+
border-top: 1px solid var(--kc-border);
|
|
451
|
+
color: var(--kc-muted);
|
|
452
|
+
font-size: 11px;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
/* ---------- \u6A21\u6001\u6846\uFF08\u6DFB\u52A0 kubeconfig\uFF09 ---------- */
|
|
456
|
+
.kc-modal-mask {
|
|
457
|
+
position: absolute;
|
|
458
|
+
inset: 0;
|
|
459
|
+
z-index: 300;
|
|
460
|
+
display: flex;
|
|
461
|
+
align-items: center;
|
|
462
|
+
justify-content: center;
|
|
463
|
+
background: rgba(4, 8, 14, 0.6);
|
|
464
|
+
backdrop-filter: blur(2px);
|
|
465
|
+
}
|
|
466
|
+
.kc-modal {
|
|
467
|
+
width: min(620px, 90%);
|
|
468
|
+
max-height: 88%;
|
|
469
|
+
overflow-y: auto;
|
|
470
|
+
background: var(--kc-panel);
|
|
471
|
+
border: 1px solid var(--kc-border-strong);
|
|
472
|
+
border-radius: 12px;
|
|
473
|
+
padding: 16px 18px;
|
|
474
|
+
box-shadow: 0 18px 48px rgba(0, 0, 0, 0.5);
|
|
475
|
+
display: flex;
|
|
476
|
+
flex-direction: column;
|
|
477
|
+
gap: 12px;
|
|
478
|
+
}
|
|
479
|
+
.kc-modal-title { font-weight: 700; font-size: 15px; }
|
|
480
|
+
.kc-field { display: flex; flex-direction: column; gap: 5px; }
|
|
481
|
+
.kc-field label { font-size: 12px; color: var(--kc-muted); }
|
|
482
|
+
.kc-form-error {
|
|
483
|
+
color: var(--kc-err);
|
|
484
|
+
background: rgba(255, 95, 86, 0.1);
|
|
485
|
+
border: 1px solid rgba(255, 95, 86, 0.3);
|
|
486
|
+
border-radius: 6px;
|
|
487
|
+
padding: 6px 9px;
|
|
488
|
+
font-size: 12px;
|
|
489
|
+
white-space: pre-wrap;
|
|
490
|
+
}
|
|
491
|
+
.kc-modal-actions {
|
|
492
|
+
display: flex;
|
|
493
|
+
justify-content: flex-end;
|
|
494
|
+
gap: 8px;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
/* ---------- \u5206\u6BB5\u63A7\u4EF6\uFF08\u4F1A\u8BDD\u5B50\u9875 / \u8868\u5355 tab\uFF09 ---------- */
|
|
498
|
+
.kc-seg {
|
|
499
|
+
display: inline-flex;
|
|
500
|
+
align-items: center;
|
|
501
|
+
gap: 2px;
|
|
502
|
+
background: var(--kc-panel-2);
|
|
503
|
+
border: 1px solid var(--kc-border);
|
|
504
|
+
border-radius: 7px;
|
|
505
|
+
padding: 2px;
|
|
506
|
+
}
|
|
507
|
+
.kc-seg button {
|
|
508
|
+
padding: 4px 12px;
|
|
509
|
+
font-size: 12px;
|
|
510
|
+
border: 0;
|
|
511
|
+
border-radius: 5px;
|
|
512
|
+
background: transparent;
|
|
513
|
+
color: var(--kc-muted);
|
|
514
|
+
white-space: nowrap;
|
|
515
|
+
}
|
|
516
|
+
.kc-seg button:hover:not(:disabled) { color: var(--kc-text); background: rgba(255, 255, 255, 0.05); border: 0; }
|
|
517
|
+
.kc-seg button.kc-seg-active {
|
|
518
|
+
background: var(--kc-accent);
|
|
519
|
+
color: #fff;
|
|
520
|
+
}
|
|
521
|
+
.kc-seg button.kc-seg-active:hover:not(:disabled) { background: #63b8ff; color: #fff; }
|
|
522
|
+
|
|
523
|
+
/* ---------- \u4EE3\u7801\u8F93\u5165/\u8F93\u51FA ---------- */
|
|
524
|
+
.kc-code-input {
|
|
525
|
+
font-family: var(--kc-mono);
|
|
526
|
+
font-size: 12px;
|
|
527
|
+
line-height: 1.55;
|
|
528
|
+
background: #0b0f16;
|
|
529
|
+
resize: vertical;
|
|
530
|
+
tab-size: 2;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
/* ---------- \u4F1A\u8BDD\u5DE5\u4F5C\u533A ---------- */
|
|
534
|
+
.kc-workspace { flex: 1; display: flex; flex-direction: column; min-height: 0; }
|
|
535
|
+
.kc-ws-meta {
|
|
536
|
+
display: flex;
|
|
537
|
+
align-items: center;
|
|
538
|
+
gap: 8px;
|
|
539
|
+
padding: 8px 12px;
|
|
540
|
+
border-bottom: 1px solid var(--kc-border);
|
|
541
|
+
background: #121825;
|
|
542
|
+
flex: 0 0 auto;
|
|
543
|
+
}
|
|
544
|
+
.kc-ws-meta-name { font-weight: 600; font-size: 13px; }
|
|
545
|
+
.kc-ws-meta-chip {
|
|
546
|
+
font-size: 11px;
|
|
547
|
+
color: var(--kc-muted);
|
|
548
|
+
border: 1px solid var(--kc-border);
|
|
549
|
+
border-radius: 999px;
|
|
550
|
+
padding: 1px 8px;
|
|
551
|
+
max-width: 320px;
|
|
552
|
+
overflow: hidden;
|
|
553
|
+
text-overflow: ellipsis;
|
|
554
|
+
white-space: nowrap;
|
|
555
|
+
}
|
|
556
|
+
.kc-ws-meta-server { font-family: var(--kc-mono); }
|
|
557
|
+
.kc-ws-body { flex: 1; min-height: 0; position: relative; }
|
|
558
|
+
.kc-ws-pane {
|
|
559
|
+
position: absolute;
|
|
560
|
+
inset: 0;
|
|
561
|
+
display: flex;
|
|
562
|
+
flex-direction: column;
|
|
563
|
+
min-height: 0;
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
/* ---------- \u547D\u4EE4\u63A7\u5236\u53F0 ---------- */
|
|
567
|
+
.kc-console {
|
|
568
|
+
flex: 1;
|
|
569
|
+
display: flex;
|
|
570
|
+
flex-direction: column;
|
|
571
|
+
min-height: 0;
|
|
572
|
+
padding: 10px 12px;
|
|
573
|
+
gap: 8px;
|
|
574
|
+
}
|
|
575
|
+
.kc-console-toolbar {
|
|
576
|
+
display: flex;
|
|
577
|
+
align-items: center;
|
|
578
|
+
gap: 8px;
|
|
579
|
+
flex-wrap: wrap;
|
|
580
|
+
}
|
|
581
|
+
.kc-console-env { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
|
|
582
|
+
.kc-console-env label {
|
|
583
|
+
display: inline-flex;
|
|
584
|
+
align-items: center;
|
|
585
|
+
gap: 5px;
|
|
586
|
+
font-size: 11px;
|
|
587
|
+
color: var(--kc-muted);
|
|
588
|
+
}
|
|
589
|
+
.kc-console-env select,
|
|
590
|
+
.kc-console-env input {
|
|
591
|
+
font-size: 12px;
|
|
592
|
+
min-width: 90px;
|
|
593
|
+
padding: 3px 7px;
|
|
594
|
+
}
|
|
595
|
+
.kc-console-input-row {
|
|
596
|
+
display: flex;
|
|
597
|
+
gap: 8px;
|
|
598
|
+
align-items: stretch;
|
|
599
|
+
}
|
|
600
|
+
.kc-console-input-row .kc-code-input { flex: 1; }
|
|
601
|
+
.kc-console-input-row button { white-space: nowrap; }
|
|
602
|
+
.kc-console-status {
|
|
603
|
+
font-size: 12px;
|
|
604
|
+
color: var(--kc-accent);
|
|
605
|
+
padding: 0 2px;
|
|
606
|
+
}
|
|
607
|
+
.kc-output {
|
|
608
|
+
flex: 1;
|
|
609
|
+
min-height: 0;
|
|
610
|
+
overflow-y: auto;
|
|
611
|
+
background: #0a0e15;
|
|
612
|
+
border: 1px solid var(--kc-border);
|
|
613
|
+
border-radius: 8px;
|
|
614
|
+
padding: 8px 0;
|
|
615
|
+
font-family: var(--kc-mono);
|
|
616
|
+
font-size: 12px;
|
|
617
|
+
line-height: 1.5;
|
|
618
|
+
}
|
|
619
|
+
.kc-output-empty {
|
|
620
|
+
padding: 10px 14px;
|
|
621
|
+
color: var(--kc-muted);
|
|
622
|
+
font-family: inherit;
|
|
623
|
+
}
|
|
624
|
+
.kc-out-line {
|
|
625
|
+
margin: 0;
|
|
626
|
+
padding: 0 12px;
|
|
627
|
+
white-space: pre-wrap;
|
|
628
|
+
word-break: break-word;
|
|
629
|
+
font-family: var(--kc-mono);
|
|
630
|
+
}
|
|
631
|
+
.kc-out-cmd {
|
|
632
|
+
color: #9ccbff;
|
|
633
|
+
background: rgba(63, 167, 247, 0.07);
|
|
634
|
+
border-left: 2px solid var(--kc-accent);
|
|
635
|
+
padding-top: 2px;
|
|
636
|
+
padding-bottom: 2px;
|
|
637
|
+
}
|
|
638
|
+
.kc-out-prompt { color: var(--kc-accent); user-select: none; }
|
|
639
|
+
.kc-out-stdout { color: #d6dde8; }
|
|
640
|
+
.kc-out-stderr { color: #ffb3a8; }
|
|
641
|
+
.kc-out-err { color: var(--kc-err); }
|
|
642
|
+
.kc-out-sys { color: var(--kc-muted); font-size: 11px; }
|
|
643
|
+
.kc-out-muted { color: #6b7484; }
|
|
644
|
+
.kc-exitbar {
|
|
645
|
+
flex: 0 0 auto;
|
|
646
|
+
font-size: 12px;
|
|
647
|
+
color: var(--kc-ok);
|
|
648
|
+
border-top: 1px solid var(--kc-border);
|
|
649
|
+
padding: 5px 4px 0;
|
|
650
|
+
}
|
|
651
|
+
.kc-exitbar-err { color: var(--kc-err); }
|
|
652
|
+
.kc-exitbar-muted { color: var(--kc-muted); }
|
|
653
|
+
|
|
654
|
+
/* ---------- AI \u5BF9\u8BDD ---------- */
|
|
655
|
+
.kc-chat {
|
|
656
|
+
flex: 1;
|
|
657
|
+
display: flex;
|
|
658
|
+
flex-direction: column;
|
|
659
|
+
min-height: 0;
|
|
660
|
+
padding: 10px 12px;
|
|
661
|
+
gap: 8px;
|
|
662
|
+
}
|
|
663
|
+
.kc-chat-toolbar {
|
|
664
|
+
display: flex;
|
|
665
|
+
align-items: center;
|
|
666
|
+
gap: 8px;
|
|
667
|
+
flex-wrap: wrap;
|
|
668
|
+
}
|
|
669
|
+
.kc-chat-toolbar label {
|
|
670
|
+
display: inline-flex;
|
|
671
|
+
align-items: center;
|
|
672
|
+
gap: 5px;
|
|
673
|
+
font-size: 11px;
|
|
674
|
+
color: var(--kc-muted);
|
|
675
|
+
}
|
|
676
|
+
.kc-chat-toolbar select { font-size: 12px; min-width: 150px; padding: 3px 7px; }
|
|
677
|
+
.kc-chat-cluster {
|
|
678
|
+
font-size: 11px;
|
|
679
|
+
color: var(--kc-muted);
|
|
680
|
+
font-family: var(--kc-mono);
|
|
681
|
+
overflow: hidden;
|
|
682
|
+
text-overflow: ellipsis;
|
|
683
|
+
white-space: nowrap;
|
|
684
|
+
max-width: 40%;
|
|
685
|
+
}
|
|
686
|
+
.kc-chat-warn {
|
|
687
|
+
font-size: 12px;
|
|
688
|
+
color: var(--kc-warn);
|
|
689
|
+
background: rgba(224, 179, 65, 0.1);
|
|
690
|
+
border: 1px solid rgba(224, 179, 65, 0.35);
|
|
691
|
+
border-radius: 6px;
|
|
692
|
+
padding: 6px 9px;
|
|
693
|
+
white-space: pre-wrap;
|
|
694
|
+
}
|
|
695
|
+
.kc-chat-scroll {
|
|
696
|
+
flex: 1;
|
|
697
|
+
min-height: 0;
|
|
698
|
+
overflow-y: auto;
|
|
699
|
+
display: flex;
|
|
700
|
+
flex-direction: column;
|
|
701
|
+
gap: 10px;
|
|
702
|
+
padding: 4px 2px;
|
|
703
|
+
}
|
|
704
|
+
.kc-chat-empty {
|
|
705
|
+
flex: 1;
|
|
706
|
+
display: flex;
|
|
707
|
+
align-items: center;
|
|
708
|
+
justify-content: center;
|
|
709
|
+
color: var(--kc-muted);
|
|
710
|
+
font-size: 12px;
|
|
711
|
+
}
|
|
712
|
+
.kc-chat-row { display: flex; gap: 8px; align-items: flex-start; }
|
|
713
|
+
.kc-chat-assistant { flex-direction: row; }
|
|
714
|
+
.kc-chat-user { flex-direction: row-reverse; }
|
|
715
|
+
.kc-chat-avatar {
|
|
716
|
+
flex: 0 0 auto;
|
|
717
|
+
width: 28px;
|
|
718
|
+
height: 28px;
|
|
719
|
+
display: flex;
|
|
720
|
+
align-items: center;
|
|
721
|
+
justify-content: center;
|
|
722
|
+
border-radius: 50%;
|
|
723
|
+
background: var(--kc-panel-2);
|
|
724
|
+
border: 1px solid var(--kc-border);
|
|
725
|
+
font-size: 14px;
|
|
726
|
+
user-select: none;
|
|
727
|
+
}
|
|
728
|
+
.kc-chat-bubble {
|
|
729
|
+
max-width: min(760px, 82%);
|
|
730
|
+
padding: 8px 12px;
|
|
731
|
+
border-radius: 10px;
|
|
732
|
+
font-size: 13px;
|
|
733
|
+
overflow-wrap: break-word;
|
|
734
|
+
}
|
|
735
|
+
.kc-chat-user .kc-chat-bubble {
|
|
736
|
+
background: var(--kc-accent-weak);
|
|
737
|
+
border: 1px solid rgba(63, 167, 247, 0.25);
|
|
738
|
+
}
|
|
739
|
+
.kc-chat-assistant .kc-chat-bubble {
|
|
740
|
+
background: var(--kc-panel-2);
|
|
741
|
+
border: 1px solid var(--kc-border);
|
|
742
|
+
}
|
|
743
|
+
.kc-chat-user-text { white-space: pre-wrap; }
|
|
744
|
+
.kc-chat-ai-text { white-space: normal; }
|
|
745
|
+
.kc-chat-text-span { white-space: pre-wrap; }
|
|
746
|
+
.kc-chat-cursor {
|
|
747
|
+
display: inline-block;
|
|
748
|
+
width: 7px;
|
|
749
|
+
color: var(--kc-accent);
|
|
750
|
+
animation: kc-blink 1s steps(2, start) infinite;
|
|
751
|
+
}
|
|
752
|
+
@keyframes kc-blink { to { visibility: hidden; } }
|
|
753
|
+
.kc-chat-error-text {
|
|
754
|
+
color: var(--kc-err);
|
|
755
|
+
white-space: pre-wrap;
|
|
756
|
+
}
|
|
757
|
+
.kc-chat-meta {
|
|
758
|
+
margin-top: 6px;
|
|
759
|
+
font-size: 10px;
|
|
760
|
+
color: #5b6475;
|
|
761
|
+
text-align: right;
|
|
762
|
+
}
|
|
763
|
+
.kc-chat-quickrun {
|
|
764
|
+
display: flex;
|
|
765
|
+
align-items: center;
|
|
766
|
+
gap: 8px;
|
|
767
|
+
padding: 6px 10px;
|
|
768
|
+
border: 1px dashed var(--kc-border-strong);
|
|
769
|
+
border-radius: 8px;
|
|
770
|
+
font-size: 12px;
|
|
771
|
+
color: var(--kc-muted);
|
|
772
|
+
background: #101623;
|
|
773
|
+
}
|
|
774
|
+
.kc-chat-quickrun code {
|
|
775
|
+
font-family: var(--kc-mono);
|
|
776
|
+
font-size: 11px;
|
|
777
|
+
color: #9ccbff;
|
|
778
|
+
overflow: hidden;
|
|
779
|
+
text-overflow: ellipsis;
|
|
780
|
+
white-space: nowrap;
|
|
781
|
+
flex: 1;
|
|
782
|
+
}
|
|
783
|
+
.kc-chat-input-row { display: flex; gap: 8px; align-items: stretch; }
|
|
784
|
+
.kc-chat-input-row .kc-code-input { flex: 1; }
|
|
785
|
+
.kc-chat-input-row button { white-space: nowrap; }
|
|
786
|
+
|
|
787
|
+
/* ---------- \u4EE3\u7801\u5757\uFF08AI \u56DE\u590D\u5185\uFF09 ---------- */
|
|
788
|
+
.kc-codebox {
|
|
789
|
+
margin: 6px 0;
|
|
790
|
+
border: 1px solid var(--kc-border);
|
|
791
|
+
border-radius: 8px;
|
|
792
|
+
overflow: hidden;
|
|
793
|
+
background: #0a0e15;
|
|
794
|
+
}
|
|
795
|
+
.kc-codebox-head {
|
|
796
|
+
display: flex;
|
|
797
|
+
align-items: center;
|
|
798
|
+
gap: 6px;
|
|
799
|
+
padding: 3px 6px 3px 10px;
|
|
800
|
+
background: #111827;
|
|
801
|
+
border-bottom: 1px solid var(--kc-border);
|
|
802
|
+
}
|
|
803
|
+
.kc-codebox-lang {
|
|
804
|
+
font-size: 11px;
|
|
805
|
+
color: var(--kc-muted);
|
|
806
|
+
font-family: var(--kc-mono);
|
|
807
|
+
}
|
|
808
|
+
.kc-codebox-body {
|
|
809
|
+
margin: 0;
|
|
810
|
+
padding: 8px 12px;
|
|
811
|
+
font-family: var(--kc-mono);
|
|
812
|
+
font-size: 12px;
|
|
813
|
+
line-height: 1.55;
|
|
814
|
+
white-space: pre-wrap;
|
|
815
|
+
word-break: break-word;
|
|
816
|
+
color: #d6dde8;
|
|
817
|
+
max-height: 320px;
|
|
818
|
+
overflow-y: auto;
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
/* ---------- \u6EDA\u52A8\u6761 ---------- */
|
|
822
|
+
#dsh-k8s-console *::-webkit-scrollbar { width: 8px; height: 8px; }
|
|
823
|
+
#dsh-k8s-console *::-webkit-scrollbar-thumb { background: #2f3a4e; border-radius: 4px; }
|
|
824
|
+
#dsh-k8s-console *::-webkit-scrollbar-track { background: transparent; }
|
|
825
|
+
`;var Xe="dsh-k8s-console-style";function Fe(){if(typeof document>"u")return()=>{};let e=document.getElementById(Xe);if(e!==null&&e.isConnected)return()=>{};let t=document.createElement("style");return t.id=Xe,t.setAttribute("data-plugin","dsh-plugin-k8s"),t.textContent=Ve,document.head.appendChild(t),()=>{t.isConnected&&t.remove()}}var We={"sidebar.label":"K8s","sidebar.aria":"K8s \u63A7\u5236\u53F0","sidebar.title":"\u6253\u5F00 K8s \u63A7\u5236\u53F0","overlay.close":"\u56DE\u5230\u5BF9\u8BDD"},_e={"sidebar.label":"K8s","sidebar.aria":"K8s console","sidebar.title":"Open K8s console","overlay.close":"Back to conversation"};var dt=["slots","locale"];function pt({renderSlot:e,standalone:t=!1}){let n=Ee(),o=(0,ae.useRef)(!1);if((0,ae.useEffect)(()=>{n.panelOpen&&(o.current=!0)},[n.panelOpen]),!n.panelOpen&&!t&&!o.current)return null;let s=n.panelOpen||t;return e("k8s.console",{onClose:()=>W.close(),standalone:t,hidden:!s})}function ut(e){let t=e?.slots,n=e?.locale;if(!t||!n)return;let o=n.bind("k8s"),s=n.register("k8s",{zh:We,en:_e}),m=Fe(),c=t.inject("sidebar.footer.action",()=>t.register({name:"sidebar.footer.action",id:"k8s-console",order:-9,locale:"k8s",label:()=>o("sidebar.label")},$e)),P=t.inject("k8s.console",()=>t.register({name:"k8s.console",id:"dsh",order:0,locale:"k8s",label:()=>o("sidebar.aria")},Je)),b=t.inject("shell.overlay",()=>t.register({name:"shell.overlay",id:"k8s.console",order:70,locale:"k8s",label:()=>o("sidebar.aria"),children:{"k8s.console":{kind:"single",scope:"root"}}},pt));e?.effect&&e.effect(()=>()=>{s(),c(),P(),b(),m()},"dsh-plugin-k8s: plugin teardown")}return tt(kt);})();
|
|
826
|
+
return __dsh_k8s_module__;
|
|
827
|
+
},
|
|
828
|
+
});
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import{resolve as Be}from"node:path";import{randomBytes as Se}from"node:crypto";import{existsSync as _,mkdirSync as Z,readFileSync as U,readdirSync as Ce,renameSync as V,statSync as Ee,writeFileSync as W,chmodSync as Q}from"node:fs";import{join as K,basename as Re}from"node:path";var h=class extends Error{code;status;details;constructor(o,n="ERR_K8S",s=400,r){super(o),this.name="K8sConsoleError",this.code=n,this.status=s,r!==void 0&&(this.details=r)}};function X(e){return e instanceof Error?e:new Error(typeof e=="string"?e:JSON.stringify(e))}function T(e){let o=[],n=[],s,r=null,u=-1,t=null,c=()=>{!t||!r||(r==="contexts"?o.push({name:t.name,...t.cluster?{cluster:t.cluster}:{},...t.user?{user:t.user}:{},...t.namespace?{namespace:t.namespace}:{}}):r==="clusters"&&n.push({name:t.name,...t.server?{server:t.server}:{}}),t=null)},d=e.split(`
|
|
2
|
+
`);for(let f of d){let i=f.replace(/\t/gu," ");if(i.trim()===""||i.trimStart().startsWith("#"))continue;let l=i.length-i.trimStart().length,a=i.trim(),g=/^current-context\s*:\s*("([^"]*)"|'([^']*)'|([^\s#]+))/.exec(a);if(g){let y=g[2]??g[3]??g[4]??"";y&&(s=y);continue}let m=/^([a-zA-Z][\w.-]*)\s*:\s*$/.exec(a);if(m&&l<=(r===null?0:u)){let y=m[1];if(y==="contexts"||y==="clusters"){c(),r=y,u=l,t=null;continue}if(y==="users"||y==="preferences"){c(),r=null,t=null;continue}}if(!r)continue;let b=/^-\s*name\s*:\s*("([^"]*)"|'([^']*)'|([^\s#]+))/.exec(a);if(b){c(),t={indent:l,bucket:null,bucketIndent:-1,name:b[2]??b[3]??b[4]??""};continue}if(!t)continue;if(a.startsWith("-")||l<=t.indent){c(),r=null,t=null;continue}let v=/^([a-zA-Z][\w.-]*)\s*:\s*$/.exec(a);if(v&&l>t.indent){t.bucket=v[1],t.bucketIndent=l;continue}if(!t.bucket)continue;if(l<=t.bucketIndent){t.bucket=null,t.bucketIndent=-1;continue}let p=/^([a-zA-Z][\w.-]*)\s*:\s*("([^"]*)"|'([^']*)'|([^\s#]+)?)/.exec(a);if(!p)continue;let x=p[1],w=p[3]??p[4]??p[5]??"";t.bucket==="cluster"&&x==="server"&&w?t.server=w:t.bucket==="context"&&x==="cluster"&&w?t.cluster=w:t.bucket==="context"&&x==="user"&&w?t.user=w:t.bucket==="context"&&x==="namespace"&&w&&(t.namespace=w)}return c(),{contexts:o,clusters:n,...s?{currentContext:s}:{}}}function D(e){return e.contexts.length===0?null:!e.currentContext&&e.contexts.length===1?{...e,currentContext:e.contexts[0].name}:e}function Y(e,o,n){let s=D(n)??{contexts:[],clusters:n.clusters},r=s.currentContext,u=s.contexts.find(c=>c.name===r),t=u?.cluster?s.clusters.find(c=>c.name===u.cluster)?.server:void 0;return{...e,contextNames:s.contexts.map(c=>c.name),...s.currentContext?{currentContext:s.currentContext}:{},...t||s.clusters[0]?.server?{server:t??s.clusters[0].server}:{},size:Buffer.byteLength(o,"utf8"),parse:"fallback"}}var ee="dsh-k8s",te=120,Ae=1024*1024,Me=/^[A-Za-z0-9_-]{6,64}$/u,Ke=/^[A-Za-z0-9._-]+\.(yaml|yml|config)$/u,Ie=/(^|\n)\s*(apiVersion\s*:\s*["']?v1|kind\s*:\s*["']?Config|current-context\s*:)/u;function I(e){return Me.test(e)}function Ne(){return`k8s_${Se(5).toString("hex")}`}function ne(e){return`${e}.yaml`}function Te(e){return e.replace(/\r\n?/gu,`
|
|
3
|
+
`).trimEnd()+`
|
|
4
|
+
`}function Pe(e,o){let n=e?.trim();if(!n)throw new h("kubeconfig \u540D\u79F0\u4E0D\u80FD\u4E3A\u7A7A","INVALID_NAME");if(n.length>te)throw new h(`\u540D\u79F0\u8FC7\u957F\uFF08\u6700\u591A ${te} \u5B57\u7B26\uFF09`,"INVALID_NAME");let s=Te(o),r=Buffer.byteLength(s,"utf8");if(r<=0)throw new h("kubeconfig \u5185\u5BB9\u4E3A\u7A7A","EMPTY_CONTENT");if(r>Ae)throw new h("kubeconfig \u5185\u5BB9\u8FC7\u5927\uFF08\u4E0A\u9650 1MB\uFF09","CONTENT_TOO_LARGE");if(!Ie.test(s))throw new h("\u5185\u5BB9\u770B\u8D77\u6765\u4E0D\u662F kubeconfig\uFF08\u672A\u627E\u5230 apiVersion/kind: Config/current-context \u7B49\u5B57\u6BB5\uFF09\u3002\u8BF7\u7C98\u8D34\u5B8C\u6574\u7684 kubeconfig YAML \u5185\u5BB9\u3002","NOT_KUBECONFIG");return{name:n,content:s}}function re(e,o){let n=K(e,"kubeconfigs"),s=K(e,"kubeconfigs.json"),r=()=>{_(e)||Z(e,{recursive:!0}),_(n)||Z(n,{recursive:!0})},u=()=>{if(r(),!_(s))return[];try{let i=JSON.parse(U(s,"utf8"));return Array.isArray(i.items)?i.items:[]}catch(i){return o?.(`[dsh-k8s-console] \u7D22\u5F15\u8BFB\u53D6\u5931\u8D25\uFF1A${i instanceof Error?i.message:String(i)}`),[]}},t=i=>{r();let l=`${s}.tmp-${process.pid}`;W(l,JSON.stringify({version:1,items:i},null,2),"utf8");try{Q(l,384)}catch{}V(l,s)},c=()=>{r();let i=u(),l=new Set;for(let g of Ce(n)){let m=/^([A-Za-z0-9_-]{6,64})\.(yaml|yml|config)$/u.exec(g);m&&l.add(m[1])}let a=i.filter(g=>l.has(g.id));return a.length!==i.length&&t(a),a},d=i=>{let l=c().find(g=>g.id===i);if(!l)return;let a=K(n,l.fileName);if(_(a))try{return U(a,"utf8")}catch{return}},f=(i,l)=>{let a=T(l);return Y(i,l,a)};return{dataDir:e,kubeDir:n,list(){return r(),c().map(l=>{let a=d(l.id);return a===void 0?null:f(l,a)}).filter(l=>l!==null).sort((l,a)=>l.name.localeCompare(a.name,"zh-CN"))},get(i){return c().find(l=>l.id===i)},requireContent(i){let l=c().find(g=>g.id===i);if(!l)throw new h(`kubeconfig \u4E0D\u5B58\u5728\uFF1A${i}`,"NOT_FOUND",404);let a=d(i);if(a===void 0)throw new h(`kubeconfig \u6587\u4EF6\u4E22\u5931\uFF1A${l.fileName}`,"FILE_MISSING",404);return{record:l,content:a}},save(i){let l,a;if(typeof i.filePath=="string"&&i.filePath.trim()!==""){let E=i.filePath.trim(),G;try{G=U(E,"utf8")}catch(F){let xe=F instanceof Error?F.message:String(F);throw new h(`\u65E0\u6CD5\u8BFB\u53D6\u6587\u4EF6\uFF1A${xe}`,"FILE_READ_FAILED",400)}let q=Ee(E,{throwIfNoEntry:!1});if(q!==void 0&&!q.isFile())throw new h("\u5BFC\u5165\u8DEF\u5F84\u4E0D\u662F\u6587\u4EF6","FILE_READ_FAILED",400);l=G,a=Re(E).replace(/\.(yaml|yml|config)$/iu,"")}else if(typeof i.content=="string")l=i.content;else throw new h("\u9700\u8981\u63D0\u4F9B kubeconfig \u5185\u5BB9\uFF08\u7C98\u8D34 content \u6216\u586B\u5199\u672C\u673A filePath\uFF09","BAD_INPUT");let g=i.name?.trim()||a?.trim()||"",{name:m,content:b}=Pe(g,l);r();let v=u(),p=i.id&&I(i.id)?v.find(E=>E.id===i.id):void 0,x=v.find(E=>E.id!==(p?.id??i.id)&&E.name.trim().toLowerCase()===m.toLowerCase());if(x)throw new h(`\u5DF2\u5B58\u5728\u540C\u540D kubeconfig\u300C${x.name}\u300D\u3002\u5982\u9700\u8986\u76D6\u8BF7\u4F7F\u7528\u8BE5\u6761\u76EE\u7684\u7F16\u8F91\u529F\u80FD\u3002`,"DUPLICATE_NAME");let w=new Date().toISOString(),y=p?.id??Ne(),k={id:y,name:m,fileName:p?.fileName??ne(y),createdAt:p?.createdAt??w,updatedAt:w,...p?.lastCheckedAt?{lastCheckedAt:p.lastCheckedAt}:{},...p?.lastCheckError?{lastCheckError:p.lastCheckError}:{}};Ke.test(k.fileName)||(k.fileName=ne(y));let S=K(n,k.fileName),P=`${S}.tmp-${process.pid}`;W(P,b,"utf8");try{Q(P,384)}catch{}V(P,S);let L=v.findIndex(E=>E.id===y);return L>=0?v[L]=k:v.push(k),t(v),o?.(`[dsh-k8s-console] \u5DF2\u4FDD\u5B58 kubeconfig\u300C${k.name}\u300D(${k.id})`),f(k,b)},remove(i){if(!I(i))return!1;r();let l=u(),a=l.findIndex(m=>m.id===i);if(a<0)return!1;let[g]=l.splice(a,1);try{let m=K(n,g.fileName);_(m)&&V(m,`${m}.trash-${process.pid}`)}catch{}return t(l),o?.(`[dsh-k8s-console] \u5DF2\u5220\u9664 kubeconfig ${i}`),!0},noteCheckResult(i,l,a){let g=u(),m=g.find(b=>b.id===i);m&&(m.lastCheckedAt=new Date().toISOString(),l?delete m.lastCheckError:m.lastCheckError=a,t(g))}}}function oe(){let e=process.env.DSH_HOME&&process.env.DSH_HOME.length>0?process.env.DSH_HOME:null;if(e)return K(e,ee);let o=process.env.HOME||process.env.USERPROFILE||".";return K(o,".dsh",ee)}import{join as j}from"node:path";import{spawn as se,spawnSync as ie}from"node:child_process";function $(e){if(e.configured&&e.configured.trim()!=="")return e.configured.trim();let o=process.env.KUBECTL_BIN?.trim();return o||"kubectl"}var O=null;function B(e={}){let o=$(e);if(O?.key===o)return O.probe;let n={present:!1};try{let s=ie(o,["version","--client","-o","json"],{encoding:"utf8",timeout:1e4,windowsHide:!0});if(s.error){let r=s.error,u=r.code;n.missingReason=u==="ENOENT"?`\u672A\u627E\u5230\u53EF\u6267\u884C\u7684\u300C${o}\u300D\u3002\u8BF7\u5B89\u88C5 kubectl \u5E76\u52A0\u5165 PATH\uFF0C\u6216\u5B89\u88C5\u540E\u5728\u63D2\u4EF6\u914D\u7F6E\u4E2D\u8BBE\u7F6E kubectlBin \u8DEF\u5F84\u3002`:`\u542F\u52A8 kubectl \u5931\u8D25\uFF1A${r.message}`}else if(s.status===0){n.present=!0,n.path=o;try{let r=JSON.parse(s.stdout||"{}");n.version=r.clientVersion?.gitVersion}catch{n.version=(s.stdout??"").split(`
|
|
5
|
+
`)[0]?.trim()||void 0}}else n.missingReason=`kubectl version --client \u9000\u51FA\u7801 ${s.status}\uFF1A${(s.stderr??s.stdout??"").slice(0,200)}`}catch(s){n.missingReason=`\u63A2\u6D4B kubectl \u5F02\u5E38\uFF1A${s instanceof Error?s.message:String(s)}`}return O={key:o,probe:n},n}function ce(){O=null}function ue(e){let o=[],n="",s=null,r=!1,u=0,t=e??"";for(;u<t.length;){let c=t[u];if(s!==null){if(c===s)s=null,r=!0;else if(c==="\\"&&s==='"'){let d=t[u+1];d==='"'||d==="\\"||d==="$"||d==="`"?(n+=d,u+=1):n+=c}else n+=c;u+=1;continue}if(c==="'"||c==='"'){s=c,r=!0,u+=1;continue}if(c==="\\"){let d=t[u+1];if(d!==void 0){n+=d,r=!0,u+=2;continue}n+=c,r=!0,u+=1;continue}if(c===" "||c===" "||c===`
|
|
6
|
+
`||c==="\r"){(n.length>0||r)&&(o.push(n),n="",r=!1),u+=1;continue}n+=c,r=!0,u+=1}return(n.length>0||r)&&o.push(n),o}function ae(e){let o=e.map(n=>n.trim()).filter(n=>n.length>0);return o.length>0&&o[0].toLowerCase()==="kubectl"&&o.shift(),o}async function le(e,o){let{bin:n,kubeFile:s,argv:r,cwd:u}=e,t=Date.now(),c={...process.env,...e.env??{},KUBECONFIG:s},d=se(n,r,{cwd:u,env:c,windowsHide:!0,stdio:["ignore","pipe","pipe"],shell:!1}),f=e.maxBytes??4*1024*1024,i=e.timeoutMs??0,l=0,a=!1,g,m=()=>{if(!(d.exitCode!==null||d.signalCode!==null))try{d.kill("SIGTERM")}catch{}},b=i>0?setTimeout(()=>{g="timeout",m()},i):null,v=(x,w)=>{if(l+=w.length,l>f){a||(a=!0,g="bytes",m());return}o(x,w.toString("utf8"))},p=()=>{g="aborted",m()};return e.signal&&(e.signal.aborted?p():e.signal.addEventListener("abort",p,{once:!0})),await new Promise((x,w)=>{d.stdout?.on("data",y=>v("stdout",y)),d.stderr?.on("data",y=>v("stderr",y)),d.on("error",y=>{b&&clearTimeout(b),e.signal?.removeEventListener("abort",p);let k=y.code;w(new h(k==="ENOENT"?`\u65E0\u6CD5\u542F\u52A8 kubectl\u300C${n}\u300D\uFF1A\u547D\u4EE4\u4E0D\u5B58\u5728\u3002\u8BF7\u5B89\u88C5 kubectl\uFF08\u6216\u8BBE\u7F6E\u73AF\u5883\u53D8\u91CF KUBECTL_BIN / \u63D2\u4EF6\u914D\u7F6E kubectlBin\uFF09`:`\u65E0\u6CD5\u542F\u52A8 kubectl\uFF1A${y.message}`,k==="ENOENT"?"KUBECTL_MISSING":"SPAWN_FAILED",502))}),d.on("close",(y,k)=>{b&&clearTimeout(b),e.signal?.removeEventListener("abort",p);let S=Date.now()-t;x({code:y,signal:k??null,durationMs:S,truncated:a,...g?{reason:g}:{}})})})}function _e(e,o,n,s=15e3){let r=Date.now(),u={...process.env};o&&(u.KUBECONFIG=o);try{let t=ie(e,n,{encoding:"utf8",timeout:s,env:u,windowsHide:!0});return{ok:t.status===0,code:t.status,stdout:t.stdout??"",stderr:t.stderr??"",durationMs:Date.now()-r}}catch(t){return{ok:!1,code:null,stdout:"",stderr:X(t).message,durationMs:Date.now()-r}}}function de(e,o,n,s,r=15e3,u){let t={...process.env,KUBECONFIG:o};return new Promise(c=>{let d=Date.now(),f=se(e,n,{cwd:s,env:t,windowsHide:!0,stdio:["ignore","pipe","pipe"],shell:!1}),i="",l="",a=!1,g=setTimeout(()=>{try{f.kill("SIGTERM")}catch{}},r),m=()=>{a||(a=!0,clearTimeout(g),c({ok:f.exitCode===0,code:f.exitCode,stdout:i,stderr:l,durationMs:Date.now()-d}))};if(f.stdout?.on("data",b=>{i=(i+b.toString("utf8")).slice(0,512*1024)}),f.stderr?.on("data",b=>{l=(l+b.toString("utf8")).slice(0,128*1024)}),f.on("error",()=>m()),f.on("close",m),u)if(u.aborted)try{f.kill("SIGTERM")}catch{}else u.addEventListener("abort",()=>{try{f.kill("SIGTERM")}catch{}},{once:!0})})}function fe(e,o){let n=_e(e,o,["config","view","--kubeconfig",o,"-o","json"]);if(!n.ok){let t=(n.stderr||n.stdout).trim()||`\u9000\u51FA\u7801 ${n.code??"?"}`;throw new h(`kubectl config view \u89E3\u6790\u5931\u8D25\uFF1A${t.slice(0,300)}`,"BAD_KUBECONFIG",400)}let s;try{s=JSON.parse(n.stdout)}catch{throw new h("kubectl config view \u8F93\u51FA\u4E0D\u662F\u5408\u6CD5 JSON","BAD_KUBECONFIG",400)}let r=(s.clusters??[]).filter(t=>typeof t.name=="string").map(t=>({name:t.name,...t.cluster?.server?{server:t.cluster.server}:{}}));return{meta:{contexts:(s.contexts??[]).filter(t=>typeof t.name=="string").map(t=>({name:t.name,...t.context?.cluster?{cluster:t.context.cluster}:{},...t.context?.user?{user:t.context.user}:{},...t.context?.namespace?{namespace:t.context.namespace}:{}})),clusters:r,...typeof s["current-context"]=="string"?{currentContext:s["current-context"]}:{}},method:"kubectl"}}function me(e,o){return{meta:T(o),method:"fallback"}}var $e=24,ge=6e3;async function be(e){let o=[];if(e&&typeof e.listProviders=="function")try{let n=await e.listProviders()??[];for(let s of n){let r=s,u=String(r.id??r.name??r.provider??"");if(!u)continue;let t=[];if(typeof e.listModels=="function")try{for(let c of await e.listModels(u)??[]){let d=String(c.id??c.name??"");d&&t.push({id:d,...typeof c.label=="string"?{label:c.label}:{}})}}catch{}o.push({provider:u,...typeof r.label=="string"?{label:r.label}:{},models:t})}}catch{}return{ok:o.length>0,providers:o,...o.length===0?{message:"\u5F53\u524D DSH \u6CA1\u6709\u53EF\u7528\u7684\u6A21\u578B provider\uFF0C\u8BF7\u5148\u5728 DSH \u7684 AI/\u6A21\u578B\u8BBE\u7F6E\u4E2D\u5B8C\u6210\u914D\u7F6E\uFF08\u672C\u63D2\u4EF6\u76F4\u63A5\u590D\u7528 DSH \u6A21\u578B\uFF09"}:{}}}async function Le(e,o){let n=[];try{n=e.listProviders?await e.listProviders():[]}catch{return null}let s=(n??[]).map(c=>{let d=c;return String(d.id??d.name??d.provider??"")}).filter(Boolean),r=o.provider?.trim(),u=r&&s.includes(r)?r:s.includes("deepseek")?"deepseek":s[0];if(!u)return null;let t;if(e.listModels)try{let d=(await e.listModels(u)).map(i=>String(i.id??i.name??"")).filter(Boolean),f=o.model?.trim();t=f&&d.includes(f)?f:d.find(i=>i==="deepseek-chat")??d.find(i=>i.toLowerCase().includes("chat")&&!i.toLowerCase().includes("reason"))??d[0]}catch{t=o.model?.trim()||void 0}else t=o.model?.trim()||void 0;return{provider:u,...t?{model:t}:{}}}async function pe(e){let{llm:o}=e;if(!o||typeof o.stream!="function")throw new h("\u65E0\u6CD5\u8C03\u7528 AI\uFF1A\u5F53\u524D DSH \u6CA1\u6709\u53EF\u7528\u7684\u6A21\u578B\u670D\u52A1\u3002\u8BF7\u5728 DSH \u7684 AI/\u6A21\u578B\u8BBE\u7F6E\u4E2D\u5B8C\u6210\u914D\u7F6E\u540E\u91CD\u8BD5\u3002","AI_NO_ROUTE",502);let n=await Le(o,{provider:e.preferred?.provider?.trim()||void 0,model:e.preferred?.model?.trim()||void 0});if(!n?.provider||!n.model)throw new h("\u6CA1\u6709\u627E\u5230\u53EF\u7528\u7684\u6A21\u578B\u8DEF\u7531\uFF0C\u8BF7\u68C0\u67E5 DSH \u6A21\u578B\u914D\u7F6E\u6216\u6539\u9009\u5176\u5B83\u6A21\u578B","AI_NO_ROUTE",502);let s=e.turns.slice(-$e).map(a=>({...a,content:a.content.length>ge?`${a.content.slice(0,ge)}\u2026\uFF08\u8FC7\u957F\u5DF2\u622A\u65AD\uFF09`:a.content})),r=s[s.length-1],u=s.slice(0,-1).map(a=>`${a.role==="user"?"\u7528\u6237":"\u52A9\u624B"}\uFF1A
|
|
7
|
+
${a.content}`).join(`
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
`),t=[u?`\u4EE5\u4E0B\u662F\u6B64\u524D\u5BF9\u8BDD\u7684\u8BB0\u5F55\uFF1A
|
|
12
|
+
|
|
13
|
+
${u}
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
\u8BF7\u7EE7\u7EED\u5B8C\u6210\u4E0B\u9762\u7684\u6700\u65B0\u8BF7\u6C42\u3002`:"\u8BF7\u56DE\u7B54\u4E0B\u9762\u7684\u8BF7\u6C42\u3002","",`${r?.role==="user"?"\u7528\u6237":"\u52A9\u624B"}\uFF1A${r?.content??""}`].join(`
|
|
18
|
+
`),c=Date.now(),d="",f=null,i=!1,l=()=>{i=!0};e.signal?.addEventListener("abort",l,{once:!0});try{let a=o.stream({provider:n.provider,model:n.model,messages:[{role:"user",content:[{type:"text",text:t}]}],system:e.system,maxTokens:e.maxTokens??1800,temperature:e.temperature??.3,...e.signal?{signal:e.signal}:{}});for await(let g of a){if(i)break;g.type==="text-delta"&&typeof g.text=="string"&&(d+=g.text,e.onDelta(g.text)),g.type==="finish"&&(f=g.reason??null)}}catch(a){if(i||e.signal?.aborted)return{provider:n.provider,model:n.model,finishReason:"aborted"};throw new h(`\u8C03\u7528 DSH \u6A21\u578B\u5931\u8D25\uFF1A${a instanceof Error?a.message:String(a)}`,"AI_LLM",502)}finally{e.signal?.removeEventListener("abort",l)}if(i||e.signal?.aborted)return{provider:n.provider,model:n.model,finishReason:"aborted"};if(Date.now()-c>18e4)throw new h("AI \u751F\u6210\u8D85\u65F6\uFF08>180s\uFF09","AI_TIMEOUT",504);if(!d.trim()||f==="error"||f==="aborted")throw new h("AI \u672A\u751F\u6210\u5185\u5BB9\uFF08\u751F\u6210\u88AB\u4E2D\u65AD\u6216\u5931\u8D25\uFF09","AI_EMPTY",502);return{provider:n.provider,model:n.model,finishReason:f}}function he(e){return["\u4F60\u662F\u5D4C\u5165\u5728 DeepSeek Harness\u300CK8s \u63A7\u5236\u53F0\u300D\u63D2\u4EF6\u91CC\u7684 Kubernetes \u8FD0\u7EF4\u52A9\u624B\u3002","\u4F60\u7684\u5DE5\u4F5C\uFF1A\u6839\u636E\u7528\u6237\u7684\u4E2D\u6587/\u81EA\u7136\u8BED\u8A00\u9700\u6C42\u751F\u6210\u53EF\u6267\u884C\u7684 kubectl \u547D\u4EE4\uFF0C\u6216\u89E3\u91CA\u547D\u4EE4\u3001\u62A5\u9519\u4E0E\u8F93\u51FA\u7ED3\u679C\u3002","\u8F93\u51FA\u7EA6\u5B9A\uFF1A","1. \u5F53\u56DE\u7B54\u5305\u542B\u53EF\u6267\u884C\u547D\u4EE4\u65F6\uFF0C\u628A\u547D\u4EE4\u653E\u5728\u5355\u4E2A ```bash \u56F4\u680F\u4EE3\u7801\u5757\u4E2D\uFF08\u6BCF\u884C\u4E00\u6761\uFF0C\u547D\u4EE4\u4EE5 kubectl \u5F00\u5934\uFF09\u3002","2. \u53EA\u8BFB\u4F18\u5148\uFF1A\u4F18\u5148 kubectl get/describe/logs/explain/top \u7B49\u53EA\u8BFB\u547D\u4EE4\uFF1B\u9700\u8981 delete/apply/scale/exec/port-forward \u7B49\u6709\u526F\u4F5C\u7528\u7684\u64CD\u4F5C\u65F6\uFF0C\u5148\u8BF4\u660E\u5F71\u54CD\u518D\u7ED9\u547D\u4EE4\u3002","3. \u62FF\u4E0D\u51C6\u8D44\u6E90/\u547D\u540D\u7A7A\u95F4\u65F6\uFF0C\u5148\u7ED9 kubectl get \u7C7B\u63A2\u67E5\u547D\u4EE4\uFF0C\u4E0D\u8981\u51ED\u7A7A\u634F\u9020\u8D44\u6E90\u540D\u3002","4. \u4E0D\u786E\u5B9A\u7684\u8BED\u6CD5\u6807\u6CE8\u5728\u4EE3\u7801\u5757\u5916\u8BF4\u660E\uFF0C\u4E0D\u8981\u7F16\u9020 kubectl \u4E0D\u5B58\u5728\u7684 flag\u3002","5. \u89E3\u91CA\u5C3D\u91CF\u7B80\u6D01\uFF1B\u56DE\u7B54\u4F7F\u7528\u4E2D\u6587\u3002",e?`\u5F53\u524D\u76EE\u6807\u96C6\u7FA4\uFF08\u6765\u81EA\u6240\u9009 kubeconfig\uFF09\uFF1A
|
|
19
|
+
${e}
|
|
20
|
+
|
|
21
|
+
\u6CE8\u610F\uFF1A\u547D\u4EE4\u6267\u884C\u65F6 kubectl \u5DF2\u81EA\u52A8\u4F7F\u7528\u8BE5 kubeconfig\uFF0C\u9664\u975E\u786E\u6709\u9700\u8981\u5426\u5219\u4E0D\u5FC5\u91CD\u590D --kubeconfig\u3002`:"","\u5982\u679C\u7528\u6237\u7684\u95EE\u9898\u4E0E Kubernetes/kubectl \u65E0\u5173\uFF0C\u793C\u8C8C\u8BF4\u660E\u4F60\u53EA\u64C5\u957F Kubernetes \u8FD0\u7EF4\u5E76\u5F15\u5BFC\u56DE\u6B63\u9898\u3002"].filter(Boolean).join(`
|
|
22
|
+
`)}var A="/api/dsh-plugin-k8s",De=6*1024*1024;function R(e,o,n){e.statusCode=o,e.setHeader("content-type","application/json; charset=utf-8"),e.setHeader("cache-control","no-store"),e.end(JSON.stringify(n))}async function N(e){let o=[],n=0;try{for await(let s of e){let r=Buffer.isBuffer(s)?s:Buffer.from(s);if(n+=r.length,n>De)return;o.push(r)}}catch{return}try{let s=JSON.parse(Buffer.concat(o).toString("utf8"));if(s&&typeof s=="object"&&!Array.isArray(s))return s}catch{}}function M(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}function C(e,o){for(let n of o){let s=e[n];if(typeof s=="string")return s}}function H(e){let o=C(e,["id"])??"";if(!I(o))throw new h("\u7F3A\u5C11\u6216\u975E\u6CD5\u7684 kubeconfig id","BAD_ID",400);return o}function Oe(e,o,n,s){let r=typeof e=="number"?e:Number(e);return Number.isFinite(r)?Math.min(s,Math.max(n,Math.trunc(r))):o}var ke={"content-type":"text/event-stream; charset=utf-8","cache-control":"no-store","x-accel-buffering":"no"};function ye(e){let o=!1,n=()=>{if(!o){if(o=!0,typeof e.writeHead=="function")e.writeHead(200,ke);else{e.statusCode=200;for(let[s,r]of Object.entries(ke))e.setHeader(s,r)}typeof e.flushHeaders=="function"&&e.flushHeaders()}};return{started:()=>o,push(s){n(),typeof e.write=="function"?e.write(`data: ${JSON.stringify(s)}
|
|
23
|
+
|
|
24
|
+
`):(e.setHeader("content-type","application/json; charset=utf-8"),e.end(JSON.stringify(s)))},end(){n(),e.end()}}}function J(e){let o=new AbortController,n=()=>{try{o.abort()}catch{}};return typeof e.on=="function"&&e.on("close",n),{signal:o.signal,dispose:()=>{typeof e.on=="function"&&e.off?.("close",n)}}}function z(e,o,n="ERR_K8S"){e.push({type:"error",message:o,code:n}),e.end()}function we(e){let o=[],n=(r,u,t)=>{o.push({kind:"exact",path:u,method:r,handler:async(c,d)=>{if(c.method&&c.method.toUpperCase()!==r){R(d,405,{error:"Method not allowed"});return}try{await t(c,d)}catch(f){let i=f instanceof h?f:new h(f instanceof Error?f.message:String(f),"ERR_INTERNAL",500);i.status>=500&&e.log("error",`[api] ${r} ${u} \u5931\u8D25\uFF1A${i.message}`),R(d,i.status,{error:i.message,code:i.code})}}})},s=()=>{let r=B(e.locator);if(!r.present)throw new h(r.missingReason??"kubectl \u4E0D\u53EF\u7528","KUBECTL_MISSING",502);return $(e.locator)};return n("POST",`${A}/state`,async(r,u)=>{M(await N(r)).refresh===!0&&ce();let c=B(e.locator),d=e.store.list();R(u,200,{ok:!0,name:"dsh-plugin-k8s",version:"0.1.0",dataDir:e.store.dataDir,kubeconfigCount:d.length,kubectl:c,kubectlCommand:$(e.locator)})}),n("POST",`${A}/kubeconfigs/list`,async(r,u)=>{R(u,200,{kubeconfigs:e.store.list()})}),n("POST",`${A}/kubeconfigs/save`,async(r,u)=>{let t=M(await N(r)),c=C(t,["name"])??"",d=C(t,["content"]),f=C(t,["filePath"]),i=e.store.save({id:C(t,["id"]),name:c,content:d,filePath:f}),l=B(e.locator),{record:a,content:g}=e.store.requireContent(i.id),m=j(e.store.kubeDir,a.fileName),b;if(l.present)try{b=fe($(e.locator),m)}catch(p){throw e.store.remove(i.id),p}else b=me("",g);if(!D(b.meta))throw e.store.remove(i.id),new h("kubeconfig \u91CC\u6CA1\u6709\u4EFB\u4F55 context\uFF08contexts \u5217\u8868\u4E3A\u7A7A\uFF09\uFF0C\u770B\u8D77\u6765\u4E0D\u662F\u53EF\u7528\u7684 kubeconfig","NO_CONTEXT",400);e.log("info",`kubeconfig \u4FDD\u5B58\u5E76\u901A\u8FC7\u89E3\u6790\uFF08${b.method}\uFF09\uFF1A${i.name}`);let v=e.store.list().find(p=>p.id===i.id)??i;R(u,200,{ok:!0,kubeconfig:v,parse:b.method})}),n("POST",`${A}/kubeconfig/remove`,async(r,u)=>{let t=M(await N(r)),c=e.store.remove(H(t));R(u,200,{ok:c})}),n("POST",`${A}/kubeconfig/raw`,async(r,u)=>{let t=M(await N(r)),{content:c}=e.store.requireContent(H(t));R(u,200,{ok:!0,content:c})}),n("POST",`${A}/kubeconfigs/check`,async(r,u)=>{let t=M(await N(r)),c=H(t),{record:d}=e.store.requireContent(c),f=s(),i=j(e.store.kubeDir,d.fileName),l=J(r);try{let a=await de(f,i,["--request-timeout","8s","get","--raw=/version"],e.store.kubeDir,15e3,l.signal);if(a.ok){let m=/"gitVersion"\s*:\s*"([^"]+)"/u.exec(a.stdout)?.[1];e.store.noteCheckResult(c,!0),R(u,200,{ok:!0,latencyMs:a.durationMs,serverVersion:m,message:m?`\u96C6\u7FA4\u53EF\u8FBE\uFF08server ${m}\uFF09`:"\u96C6\u7FA4\u53EF\u8FBE"})}else{let g=(a.stderr||a.stdout).trim();e.store.noteCheckResult(c,!1,g.slice(0,500)),R(u,200,{ok:!1,latencyMs:a.durationMs,message:g.slice(0,500)||`kubectl \u9000\u51FA\u7801 ${a.code??"?"}`})}}finally{l.dispose()}}),n("POST",`${A}/run`,async(r,u)=>{let t=M(await N(r)),c=H(t),{record:d}=e.store.requireContent(c),f=ye(u),i=J(r),l=e.store.kubeDir,a=j(l,d.fileName),g=C(t,["command"])??"",m=C(t,["context"])??"",b=C(t,["namespace"])??"",v=Oe(t.timeoutMs,e.runtime.runTimeoutMs,1e3,900*1e3),p;try{p=ae(ue(g))}catch{p=[]}if(p.length===0){z(f,"\u8BF7\u8F93\u5165\u8981\u6267\u884C\u7684\u547D\u4EE4\uFF08\u4F8B\u5982\uFF1Aget pods -A\uFF09","EMPTY_COMMAND"),i.dispose();return}let x=p.reduce((k,S)=>k+S.length,0);if(p.length>200||x>32*1024||p.some(k=>k.length>4096)){z(f,"\u547D\u4EE4\u8FC7\u957F\u6216\u53C2\u6570\u8FC7\u591A","COMMAND_TOO_LONG"),i.dispose();return}let w=[];m.trim()!==""&&w.push("--context",m.trim()),b.trim()!==""&&w.push("-n",b.trim()),w.push(...p),f.push({type:"start",command:`kubectl ${w.join(" ")}`,argv:w,kubeconfig:d.name,timeoutMs:v});let y=!1;try{let k=s(),S=await le({bin:k,kubeFile:a,argv:w,cwd:l,timeoutMs:v,maxBytes:e.runtime.outputBytes,signal:i.signal},(P,L)=>f.push({type:"out",channel:P,text:L}));y=!0,f.push({type:"exit",code:S.code,signal:S.signal,reason:S.reason,truncated:S.truncated,durationMs:S.durationMs}),f.end()}catch(k){let S=k instanceof h?k:new h(k instanceof Error?k.message:String(k),"ERR_INTERNAL",500);f.push({type:"error",message:S.message,code:S.code}),f.end()}finally{y||f.end(),i.dispose()}}),n("POST",`${A}/ai/models`,async(r,u)=>{let t=e.getLlm(),c=await be(t);R(u,200,c)}),n("POST",`${A}/ai/chat`,async(r,u)=>{let t=M(await N(r)),c=C(t,["id"])??"",d=ye(u),f=J(r),i;if(c&&I(c)){let m=e.store.get(c);if(m){let{content:b}=e.store.requireContent(c),v=T(b),p=D(v),x=p?.currentContext,w=p?.contexts.find(k=>k.name===x),y=w?.cluster?p?.clusters.find(k=>k.name===w.cluster)?.server:void 0;i=[`kubeconfig \u540D\u79F0\uFF1A${m.name}`,y?`API server\uFF1A${y}`:"",x?`\u5F53\u524D context\uFF1A${x}`:`\u53EF\u7528 context\uFF1A${p?.contexts.map(k=>k.name).join("\u3001")??""}`].filter(Boolean).join(`
|
|
25
|
+
`)}}let a=(Array.isArray(t.history)?t.history:[]).map(m=>{let b=M(m),v=C(b,["role"]),p=C(b,["content"])??"";return(v==="user"||v==="assistant")&&p.trim()!==""?{role:v,content:p.slice(0,24e3)}:null}).filter(m=>m!==null).slice(-40);if(a.length===0||a[a.length-1].role!=="user"){z(d,"\u7F3A\u5C11\u8981\u63D0\u95EE\u7684\u5185\u5BB9","AI_INPUT"),f.dispose();return}let g=e.getLlm();try{let m=await pe({llm:g,preferred:{provider:C(t,["provider"])??void 0,model:C(t,["model"])??void 0},system:he(i),turns:a,signal:f.signal,onDelta:b=>d.push({type:"delta",text:b})});m.finishReason==="aborted"?d.push({type:"aborted"}):d.push({type:"done",provider:m.provider,model:m.model}),d.end()}catch(m){let b=m instanceof h?m:new h(m instanceof Error?m.message:String(m),"AI_INTERNAL",500);b.status>=500&&e.log("error",`[ai/chat] \u5931\u8D25\uFF1A${b.message}`),d.push({type:"error",message:b.message,code:b.code}),d.end()}finally{f.dispose()}}),o}var lt="dsh-plugin-k8s",dt=["webServer"];function ve(e,o,n,s){let r=typeof e=="number"?e:Number(e);return Number.isFinite(r)?Math.min(s,Math.max(n,Math.trunc(r))):o}function ft(e,o={}){let n=(c,d)=>{try{e.logger?.[c](`[dsh-plugin-k8s] ${d}`)}catch{}},s=Be(o.dataDir&&o.dataDir.length>0?o.dataDir:oe()),r=re(s,c=>n("info",c)),u={configured:o.kubectlBin?.trim()||void 0},t={runTimeoutMs:ve(o.runTimeoutMs,12e4,1e3,900*1e3),outputBytes:ve(o.outputBytes,4*1024*1024,256*1024,32*1024*1024)};e.inject(["webServer"],c=>{c.effect(()=>{let d=we({store:r,locator:u,runtime:t,log:n,getLlm:()=>e.get("llm")??void 0}),f=c.webServer;if(!f){n("error","webServer \u670D\u52A1\u4E0D\u53EF\u7528\uFF0C\u63D2\u4EF6 HTTP API \u672A\u6CE8\u518C");return}let i=d.map(l=>f.register(l));return()=>{for(let l of i)l()}},"dsh-plugin-k8s: http api")}),n("info",`\u63D2\u4EF6\u5DF2\u52A0\u8F7D\uFF1A\u6570\u636E\u76EE\u5F55=${s}\uFF0C\u547D\u4EE4\u8D85\u65F6=${t.runTimeoutMs}ms\uFF0C\u8F93\u51FA\u4E0A\u9650=${Math.round(t.outputBytes/1024)}KB`)}function mt(e){return I(e)}export{ft as apply,dt as inject,mt as isKubeIdValid,lt as name};
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@snowlocked/dsh-k8s-console",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "DSH K8s 控制台插件:管理 kubeconfig,点击即开会话 Tab(同一集群可开多个),每个会话含「kubectl 命令控制台」与「AI 对话」两个子页;AI 复用 DSH 自身模型配置。",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./lib/index.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./lib/index.js",
|
|
10
|
+
"./client": "./lib/client.js",
|
|
11
|
+
"./package.json": "./package.json"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"lib",
|
|
15
|
+
"cordis.patch.yml",
|
|
16
|
+
"README.md"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"prepack": "node ../../build.mjs",
|
|
20
|
+
"build": "node ../../build.mjs"
|
|
21
|
+
},
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public"
|
|
24
|
+
},
|
|
25
|
+
"dsh": {
|
|
26
|
+
"bundle": {
|
|
27
|
+
"patch": "./cordis.patch.yml"
|
|
28
|
+
},
|
|
29
|
+
"client": {
|
|
30
|
+
"inject": [
|
|
31
|
+
"slots",
|
|
32
|
+
"locale"
|
|
33
|
+
],
|
|
34
|
+
"platform": "web"
|
|
35
|
+
},
|
|
36
|
+
"engines": {
|
|
37
|
+
"dsh": ">=0.1.1-rc.1"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": "^22.19.0 || >=24.0.0"
|
|
42
|
+
},
|
|
43
|
+
"keywords": [
|
|
44
|
+
"dsh-plugin",
|
|
45
|
+
"deepseek-harness",
|
|
46
|
+
"kubernetes",
|
|
47
|
+
"k8s",
|
|
48
|
+
"kubectl",
|
|
49
|
+
"kubeconfig",
|
|
50
|
+
"ai"
|
|
51
|
+
]
|
|
52
|
+
}
|