- 新增 log_datasource.go / log_proxy.go / user_api_token.go 后端控制器 - 新增 log_datasource.go model - 新增 monitor/log-center.ts API 模块 - 新增 LogCenter 前端组件及页面 - 重构 deployment 相关组件 (HPDA/UpdateImageModal/bundle-yaml 等) - 新增 ResetPasswordDialog / code-snippet-block / copy-button 等 UI 组件 - 重构多个 k8s 相关组件 (TopologyView/ResourceVisualEditor/PodFileBrowser 等) - 更新多个 API 和工具函数 (auth.ts/monitor/index.ts/request.ts 等) - 更新静态资源 (index.html + 新 JS/CSS bundle) - 删除废弃静态资源文件
20 lines
30 KiB
JavaScript
20 lines
30 KiB
JavaScript
import{r as x,j as s,b as _s}from"./vendor-codemirror-B1SGo4xl.js";import{C as D,b as T,c as Y,a as q}from"./card-CdN7vcLa.js";import{aa as ks,a1 as Es,Z as H,m as ds,B as N,q as Ls,D as Rs,a as Ms,b as Ps,c as Ds,d as Ts,e as qs,t as w}from"./index-lgmWPQDG.js";import{I as C}from"./input-DBDfXZx0.js";import{B as k}from"./badge-Ca5YHtna.js";import{L as y}from"./label-Bzhjv1tR.js";import{S as ss,a as ts,b as es,c as as,d as ns}from"./select-Bv_WioDg.js";import{S as Us}from"./switch-BGnej0rz.js";import{d as U}from"./dashboard-CdCPPiIv.js";import{a as Bs}from"./alert-CifuiQtF.js";import{a as Fs}from"./agent-DtywswSX.js";import{a as $}from"./ai-DlszA9HX.js";import{aA as zs,C as Hs,p as os,l as ms,A as xs,F as hs,aa as Vs,L as E,r as Ks,b6 as cs,am as Gs,ap as Ws,U as Qs,b7 as Zs,ay as Js,aR as Xs}from"./vendor-icons-BlY7QrxS.js";import"./index-5FEebgvX.js";function Ys(e,n=[]){let i=[];function r(a,d){const m=x.createContext(d);m.displayName=a+"Context";const l=i.length;i=[...i,d];const g=h=>{const{scope:u,children:c,...p}=h,A=u?.[e]?.[l]||m,j=x.useMemo(()=>p,Object.values(p));return s.jsx(A.Provider,{value:j,children:c})};g.displayName=a+"Provider";function v(h,u){const c=u?.[e]?.[l]||m,p=x.useContext(c);if(p)return p;if(d!==void 0)return d;throw new Error(`\`${h}\` must be used within \`${a}\``)}return[g,v]}const o=()=>{const a=i.map(d=>x.createContext(d));return function(m){const l=m?.[e]||a;return x.useMemo(()=>({[`__scope${e}`]:{...m,[e]:l}}),[m,l])}};return o.scopeName=e,[r,st(o,...n)]}function st(...e){const n=e[0];if(e.length===1)return n;const i=()=>{const r=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(a){const d=r.reduce((m,{useScope:l,scopeName:g})=>{const h=l(a)[`__scope${g}`];return{...m,...h}},{});return x.useMemo(()=>({[`__scope${n.scopeName}`]:d}),[d])}};return i.scopeName=n.scopeName,i}var tt=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],V=tt.reduce((e,n)=>{const i=ks(`Primitive.${n}`),r=x.forwardRef((o,a)=>{const{asChild:d,...m}=o,l=d?i:n;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),s.jsx(l,{...m,ref:a})});return r.displayName=`Primitive.${n}`,{...e,[n]:r}},{}),B={exports:{}},F={};var rs;function et(){if(rs)return F;rs=1;var e=_s();function n(h,u){return h===u&&(h!==0||1/h===1/u)||h!==h&&u!==u}var i=typeof Object.is=="function"?Object.is:n,r=e.useState,o=e.useEffect,a=e.useLayoutEffect,d=e.useDebugValue;function m(h,u){var c=u(),p=r({inst:{value:c,getSnapshot:u}}),A=p[0].inst,j=p[1];return a(function(){A.value=c,A.getSnapshot=u,l(A)&&j({inst:A})},[h,c,u]),o(function(){return l(A)&&j({inst:A}),h(function(){l(A)&&j({inst:A})})},[h]),d(c),c}function l(h){var u=h.getSnapshot;h=h.value;try{var c=u();return!i(h,c)}catch{return!0}}function g(h,u){return u()}var v=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?g:m;return F.useSyncExternalStore=e.useSyncExternalStore!==void 0?e.useSyncExternalStore:v,F}var is;function at(){return is||(is=1,B.exports=et()),B.exports}var nt=at();function ot(){return nt.useSyncExternalStore(ct,()=>!0,()=>!1)}function ct(){return()=>{}}var K="Avatar",[rt]=Ys(K),[it,us]=rt(K),As=x.forwardRef((e,n)=>{const{__scopeAvatar:i,...r}=e,[o,a]=x.useState("idle");return s.jsx(it,{scope:i,imageLoadingStatus:o,onImageLoadingStatusChange:a,children:s.jsx(V.span,{...r,ref:n})})});As.displayName=K;var fs="AvatarImage",pt=x.forwardRef((e,n)=>{const{__scopeAvatar:i,src:r,onLoadingStatusChange:o=()=>{},...a}=e,d=us(fs,i),m=lt(r,a),l=Es(g=>{o(g),d.onImageLoadingStatusChange(g)});return H(()=>{m!=="idle"&&l(m)},[m,l]),m==="loaded"?s.jsx(V.img,{...a,ref:n,src:r}):null});pt.displayName=fs;var gs="AvatarFallback",Is=x.forwardRef((e,n)=>{const{__scopeAvatar:i,delayMs:r,...o}=e,a=us(gs,i),[d,m]=x.useState(r===void 0);return x.useEffect(()=>{if(r!==void 0){const l=window.setTimeout(()=>m(!0),r);return()=>window.clearTimeout(l)}},[r]),d&&a.imageLoadingStatus!=="loaded"?s.jsx(V.span,{...o,ref:n}):null});Is.displayName=gs;function ps(e,n){return e?n?(e.src!==n&&(e.src=n),e.complete&&e.naturalWidth>0?"loaded":"loading"):"error":"idle"}function lt(e,{referrerPolicy:n,crossOrigin:i}){const r=ot(),o=x.useRef(null),a=r?(o.current||(o.current=new window.Image),o.current):null,[d,m]=x.useState(()=>ps(a,e));return H(()=>{m(ps(a,e))},[a,e]),H(()=>{const l=h=>()=>{m(h)};if(!a)return;const g=l("loaded"),v=l("error");return a.addEventListener("load",g),a.addEventListener("error",v),n&&(a.referrerPolicy=n),typeof i=="string"&&(a.crossOrigin=i),()=>{a.removeEventListener("load",g),a.removeEventListener("error",v)}},[a,i,n]),d}var dt=As,mt=Is;function xt({className:e,...n}){return s.jsx(dt,{"code-path":"src/components/ui/avatar.tsx:11:5","data-slot":"avatar",className:ds("relative flex size-8 shrink-0 overflow-hidden rounded-full",e),...n})}function ht({className:e,...n}){return s.jsx(mt,{"code-path":"src/components/ui/avatar.tsx:40:5","data-slot":"avatar-fallback",className:ds("bg-muted flex size-full items-center justify-center rounded-full",e),...n})}const z=[{id:"openai",name:"OpenAI",defaultEndpoint:"https://api.openai.com/v1",models:["gpt-4o-mini","gpt-4o","gpt-4-turbo"]},{id:"deepseek",name:"DeepSeek",defaultEndpoint:"https://api.deepseek.com/v1",models:["deepseek-chat","deepseek-reasoner"]},{id:"qwen",name:"通义千问 (DashScope)",defaultEndpoint:"https://dashscope.aliyuncs.com/compatible-mode/v1",models:["qwen-plus","qwen-turbo","qwen-max"]},{id:"moonshot",name:"Moonshot 月之暗面",defaultEndpoint:"https://api.moonshot.cn/v1",models:["moonshot-v1-8k","moonshot-v1-32k"]},{id:"ollama",name:"Ollama 本地",defaultEndpoint:"http://localhost:11434/v1",models:["qwen2.5:7b","llama3.2","deepseek-r1:7b"]},{id:"custom",name:"自定义 (OpenAI 兼容)",defaultEndpoint:"",models:[]}],ut={provider:"openai",model:"gpt-4o-mini",api_key:"",endpoint:"https://api.openai.com/v1",temperature:.7,max_tokens:2e3,system_prompt:"",enabled:!1};async function At(){const n=(await Bs.getAlerts({page:1,page_size:20}))?.list||[];if(!n.length)return"(当前无告警事件)";const i=n.slice(0,15).map((o,a)=>`${a+1}. [${o.severity||"未知"}|${o.status||"-"}] ${o.rule_name||"告警"} → 目标:${o.target||"-"} 值:${o.value??"-"} 时间:${(o.started_at||"").slice(0,16)}`),r=n.filter(o=>o.status==="firing").length;return`共 ${n.length} 条告警(firing ${r} 条),前 ${Math.min(15,n.length)} 条:
|
|
${i.join(`
|
|
`)}`}async function ls(){const e=await Fs.getLatest(),n=Array.isArray(e)?e:e?.list||[];if(!n.length)return"(当前无 Agent 上报数据,可能未部署监控 Agent)";const i=n.slice(0,20).map((a,d)=>{const m=a.cpu_usage??"-",l=a.mem_usage??"-";return`${d+1}. ${a.hostname||"-"} | CPU:${m}% | 内存:${l}% (${a.mem_used??"-"}/${a.mem_total??"-"}GB) | 核数:${a.cpu_cores??"-"} | 上报:${(a.report_time||"").slice(0,16)}`}),r=n.filter(a=>(a.cpu_usage??0)>=80||(a.mem_usage??0)>=80),o=r.length?`
|
|
⚠️ 高负载主机 ${r.length} 台:${r.map(a=>`${a.hostname}(CPU${a.cpu_usage}%/MEM${a.mem_usage}%)`).join("、")}`:"";return`Agent 监控的 ${n.length} 台主机实时指标:
|
|
${i.join(`
|
|
`)}${o}`}async function ft(){const[e,n,i]=await Promise.all([U.getStats().catch(()=>null),U.getAlerts(10).catch(()=>null),U.getReleases(10).catch(()=>null)]),r=e||{},o=r.server_stats||{},a=r.kubernetes_stats||{},d=r.alert_stats||{},m=r.pipeline_stats||{},l=r.cost_stats||{},g=`服务器:${o.total??0}(运行${o.running??0}) | Kubernetes集群:${a.total??0} 节点:${a.total_nodes??0} Pod:${a.total_pods??0} | 告警:${d.total??0}(firing ${d.firing??0}) | 流水线:${m.total??0}(成功率${m.success_rate??0}%) | 本月成本:¥${l.month_cost??0}`,v=Array.isArray(n)?n:n?.list||[],h=Array.isArray(i)?i:i?.list||[],u=v.slice(0,10).map((p,A)=>`${A+1}.[${p.severity||"?"}|${p.status||"?"}] ${p.rule_name||"-"} → ${p.target||"-"}`),c=h.slice(0,10).map((p,A)=>`${A+1}.${p.app_name||"-"} ${p.version||""} [${p.environment||"-"}/${p.status||"-"}] by ${p.author||"-"}`);return`平台概览:${g}
|
|
|
|
最近告警:
|
|
${u.join(`
|
|
`)||"(无)"}
|
|
|
|
最近发布:
|
|
${c.join(`
|
|
`)||"(无)"}`}const gt=[{id:"alerts",name:"分析今日告警",icon:ms,prompt:"帮我分析以下最近的告警事件,给出根因分析和处置建议(按严重程度排序,给出具体处置步骤)",contextLoader:At},{id:"performance",name:"性能瓶颈分析",icon:xs,prompt:"分析以下主机实时指标,找出 CPU/内存使用率最高的主机并给出性能优化建议",contextLoader:ls},{id:"report",name:"生成运维报告",icon:hs,prompt:"基于以下平台实时数据,生成一份简洁的今日运维报告,包括资源概览、告警情况和发布状态,用 Markdown 格式输出",contextLoader:ft},{id:"optimize",name:"资源优化建议",icon:Vs,prompt:"根据以下主机资源使用数据,提供成本优化和容量规划建议(识别闲置/过载主机,给出缩容/扩容建议)",contextLoader:ls}];function It(e){return new Date(e).toLocaleTimeString("zh-CN",{hour:"2-digit",minute:"2-digit"})}function Rt(){const[e,n]=x.useState([]),[i,r]=x.useState(""),[o,a]=x.useState(!1),d=x.useRef(null);x.useEffect(()=>()=>d.current?.abort(),[]);const[m,l]=x.useState(!1),[g,v]=x.useState(!1),[h,u]=x.useState(!1),[c,p]=x.useState(ut),[A,j]=x.useState(!1),[L,G]=x.useState(null),W=()=>{try{return crypto.randomUUID()}catch{}return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{const I=Math.random()*16|0;return(t==="x"?I:I&3|8).toString(16)})},[Q,vs]=x.useState(()=>W()),Z=x.useRef(null),js=()=>Z.current?.scrollIntoView({behavior:"smooth"});x.useEffect(()=>{js()},[e]);const Os=async()=>{try{const t=await $.getConfig();p(t),j(!!(t.enabled&&t.configured))}catch{j(!1)}},bs=async()=>{try{const I=(await $.getHistory(Q))?.list||[];n(I.map(f=>({id:String(f.id),role:f.role,content:f.content,timestamp:f.created_at})))}catch{}};x.useEffect(()=>{Os(),bs()},[]);const Ns=t=>{const I=z.find(f=>f.id===t);p(f=>({...f,provider:t,endpoint:I?.defaultEndpoint||f.endpoint,model:I?.models[0]||f.model}))},Ss=async()=>{if(c.enabled&&!c.api_key&&c.provider!=="ollama"){w.error("请填写 API Key");return}v(!0);try{const t=await $.saveConfig(c);p(t),j(!!(t.enabled&&t.configured)),w.success("配置已保存"),l(!1)}catch(t){w.error(t instanceof Error?t.message:"保存失败")}finally{v(!1)}},ys=async()=>{u(!0);try{await $.testConnection(),w.success("LLM 服务连接成功")}catch(t){w.error(t instanceof Error?t.message:"连接失败")}finally{u(!1)}},J=async t=>{const I={id:Date.now().toString(),role:"user",content:t,timestamp:new Date().toISOString()},f=(Date.now()+1).toString(),$s=[...e,I,{id:f,role:"assistant",content:"",timestamp:new Date().toISOString()}];n($s),a(!0);const M=new AbortController;d.current=M;let P=!1;try{const _=[...e,I].slice(-10).map(O=>({role:O.role,content:O.content}));await $.chatStream(_,O=>{P=!0,n(S=>S.map(b=>b.id===f?{...b,content:b.content+O}:b))},M.signal,Q)}catch(_){if(M.signal.aborted)n(O=>O.map(S=>S.id===f?{...S,content:S.content||"(已停止生成)",isStopped:!0}:S));else{const O=_ instanceof Error?_.message:"对话失败";n(S=>S.map(b=>b.id===f?{...b,content:P?b.content+`
|
|
|
|
⚠️ ${O}`:`⚠️ ${O}`,isError:!P}:b))}}finally{a(!1),d.current=null}},X=async()=>{const t=i.trim();!t||o||(r(""),await J(t))},ws=async t=>{if(o||L)return;if(!A||!t.contextLoader){r(t.prompt);return}G(t.id);let I="";try{I=await t.contextLoader()}catch{I="(平台数据加载失败,请稍后重试或检查后端服务)"}finally{G(null)}const f=`${t.prompt}
|
|
|
|
【平台实时数据】
|
|
${I}`;await J(f)},Cs=async()=>{try{await $.clearHistory()}catch{}const t=W();vs(t),n([]),r(""),w.success("已开始新对话")},R=z.find(t=>t.id===c.provider);return s.jsxs("div",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:370:5",className:"space-y-6",children:[s.jsxs("div",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:372:7",className:"flex items-center justify-between",children:[s.jsxs("div",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:373:9",className:"flex items-center gap-3",children:[s.jsx("div",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:374:11",className:"w-10 h-10 rounded-lg bg-gradient-to-br from-purple-500 to-pink-500 flex items-center justify-center",children:s.jsx(zs,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:375:13",className:"h-5 w-5 text-white"})}),s.jsxs("div",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:377:11",children:[s.jsx("h1",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:378:13",className:"text-2xl font-bold text-slate-100",children:"AIOps 智能助手"}),s.jsx("p",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:379:13",className:"text-sm text-slate-500",children:"AI 驱动的智能运维助手"})]})]}),s.jsxs("div",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:382:9",className:"flex items-center gap-3",children:[A?s.jsxs(k,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:384:13",variant:"outline",className:"border-emerald-500/30 text-emerald-400 bg-emerald-500/10",children:[s.jsx(Hs,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:385:15",className:"h-3 w-3 mr-1"}),c.model]}):s.jsx(k,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:389:13",variant:"outline",className:"border-amber-500/30 text-amber-400 bg-amber-500/10",children:"未配置"}),s.jsxs(N,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:393:11",variant:"outline",className:"border-slate-700 text-slate-300",onClick:()=>l(!0),children:[s.jsx(os,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:394:13",className:"h-4 w-4 mr-2"}),"模型配置"]})]})]}),s.jsxs("div",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:400:7",className:"grid grid-cols-4 gap-6 h-[calc(100vh-200px)]",children:[s.jsxs("div",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:402:9",className:"col-span-1 space-y-4",children:[s.jsxs(D,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:403:11",className:"bg-slate-800 border-slate-700",children:[s.jsx(T,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:404:13",className:"pb-3",children:s.jsx(Y,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:405:15",className:"text-sm text-slate-300",children:"快速操作"})}),s.jsx(q,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:407:13",className:"space-y-2",children:gt.map(t=>s.jsxs(N,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:409:17",variant:"ghost",className:"w-full justify-start text-slate-300 hover:text-slate-100 hover:bg-slate-700",disabled:o||L!==null,onClick:()=>ws(t),children:[L===t.id?s.jsx(E,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:417:21",className:"h-4 w-4 mr-2 shrink-0 animate-spin"}):s.jsx(t.icon,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:419:21",className:"h-4 w-4 mr-2 shrink-0"}),s.jsx("span",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:421:19",className:"text-sm",children:t.name}),A&&t.contextLoader&&s.jsx("span",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:423:21",className:"ml-auto text-[10px] text-emerald-400/60 shrink-0",children:"实时"})]},t.id))})]}),s.jsxs(D,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:430:11",className:"bg-slate-800 border-slate-700",children:[s.jsx(T,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:431:13",className:"pb-3",children:s.jsx(Y,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:432:15",className:"text-sm text-slate-300",children:"能力展示"})}),s.jsxs(q,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:434:13",className:"space-y-3",children:[s.jsxs("div",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:435:15",className:"flex items-center gap-2 text-sm text-slate-400",children:[s.jsx(ms,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:436:17",className:"h-4 w-4 text-amber-400"}),s.jsx("span",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:437:17",children:"智能告警分析"})]}),s.jsxs("div",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:439:15",className:"flex items-center gap-2 text-sm text-slate-400",children:[s.jsx(xs,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:440:17",className:"h-4 w-4 text-blue-400"}),s.jsx("span",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:441:17",children:"性能瓶颈识别"})]}),s.jsxs("div",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:443:15",className:"flex items-center gap-2 text-sm text-slate-400",children:[s.jsx(hs,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:444:17",className:"h-4 w-4 text-emerald-400"}),s.jsx("span",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:445:17",children:"自动报告生成"})]}),s.jsxs("div",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:447:15",className:"flex items-center gap-2 text-sm text-slate-400",children:[s.jsx(Ks,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:448:17",className:"h-4 w-4 text-purple-400"}),s.jsx("span",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:449:17",children:"脚本自动生成"})]})]})]})]}),s.jsxs(D,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:456:9",className:"col-span-3 bg-slate-800 border-slate-700 flex flex-col",children:[s.jsx(T,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:457:11",className:"border-b border-slate-700 pb-3",children:s.jsxs("div",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:458:13",className:"flex items-center justify-between",children:[s.jsxs("div",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:459:15",className:"flex items-center gap-2",children:[s.jsx(cs,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:460:17",className:"h-5 w-5 text-purple-400"}),s.jsx("span",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:461:17",className:"font-medium text-slate-100",children:"AI 助手"}),A?s.jsxs(k,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:463:19",variant:"outline",className:"border-emerald-500/30 text-emerald-400 bg-emerald-500/10 text-xs",children:[s.jsx("span",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:464:21",className:"w-2 h-2 rounded-full bg-emerald-400 mr-1 animate-pulse"}),"在线"]}):s.jsx(k,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:468:19",variant:"outline",className:"border-slate-600 text-slate-400 text-xs",children:"离线"})]}),s.jsxs(N,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:471:15",variant:"ghost",size:"sm",className:"text-slate-400",onClick:Cs,disabled:e.length===0,children:[s.jsx(Gs,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:472:17",className:"h-4 w-4 mr-1"}),"新对话"]})]})}),s.jsx(Ls,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:478:11",className:"flex-1 p-4",children:s.jsxs("div",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:479:13",className:"space-y-4",children:[e.length===0&&!o&&s.jsxs("div",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:481:17",className:"flex flex-col items-center justify-center py-16 text-slate-500",children:[s.jsx(Ws,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:482:19",className:"h-10 w-10 mb-3 opacity-30"}),s.jsx("p",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:483:19",children:A?"暂无对话记录,输入问题开始与 AI 助手对话":"AI 助手尚未配置大模型"}),!A&&s.jsxs(N,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:485:21",variant:"outline",size:"sm",className:"mt-4 border-slate-600 text-slate-300",onClick:()=>l(!0),children:[s.jsx(os,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:486:23",className:"h-4 w-4 mr-1"}),"前往配置"]})]}),e.map(t=>{const I=o&&t.role==="assistant"&&t.content==="";return s.jsxs("div",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:496:17",className:`flex gap-3 ${t.role==="user"?"flex-row-reverse":""}`,children:[s.jsx(xt,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:497:19",className:t.role==="assistant"?"bg-purple-500":"bg-blue-500",children:s.jsx(ht,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:498:21",children:t.role==="assistant"?s.jsx(cs,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:499:55",className:"h-4 w-4"}):s.jsx(Qs,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:499:85",className:"h-4 w-4"})})}),s.jsxs("div",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:502:19",className:`max-w-[80%] ${t.role==="user"?"text-right":""}`,children:[s.jsxs("div",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:503:21",className:`inline-block rounded-lg p-3 text-left whitespace-pre-wrap break-words ${t.isError?"bg-red-900/30 border border-red-500/30 text-red-300":t.role==="assistant"?"bg-slate-700 text-slate-100":"bg-blue-600 text-white"}`,children:[I?s.jsxs("div",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:513:25",className:"flex items-center gap-2 text-slate-400",children:[s.jsx(E,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:514:27",className:"h-4 w-4 animate-spin"}),s.jsx("span",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:515:27",className:"text-sm",children:"思考中..."})]}):t.content,o&&t.role==="assistant"&&!I&&t.content&&s.jsx("span",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:522:25",className:"inline-block w-2 h-4 ml-0.5 bg-purple-400 animate-pulse align-middle"})]}),s.jsxs("div",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:525:21",className:"text-xs text-slate-500 mt-1",children:[It(t.timestamp),t.isStopped&&s.jsx("span",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:527:45",className:"ml-2 text-slate-600",children:"(已停止)"})]})]})]},t.id)}),s.jsx("div",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:534:15",ref:Z})]})}),s.jsx(q,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:538:11",className:"border-t border-slate-700 pt-4",children:s.jsxs("div",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:539:13",className:"flex gap-2",children:[s.jsx(C,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:540:15",value:i,onChange:t=>r(t.target.value),onKeyDown:t=>t.key==="Enter"&&X(),placeholder:A?"输入运维问题,或选择左侧快速操作...":"请先配置大模型...",className:"flex-1 bg-slate-900 border-slate-700 text-slate-100",disabled:o}),s.jsx(N,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:548:15",className:"bg-purple-600 hover:bg-purple-700",onClick:X,disabled:o||!i.trim(),children:s.jsx(Zs,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:549:17",className:"h-4 w-4"})}),o&&s.jsx(N,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:553:17",variant:"outline",className:"border-red-500/40 text-red-400 hover:bg-red-500/10",onClick:()=>d.current?.abort(),title:"停止生成",children:s.jsx(Js,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:559:19",className:"h-4 w-4"})})]})})]})]}),s.jsx(Rs,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:568:7",open:m,onOpenChange:l,children:s.jsxs(Ms,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:569:9",className:"max-w-2xl bg-slate-900 border-slate-700 text-slate-100",children:[s.jsxs(Ps,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:570:11",children:[s.jsx(Ds,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:571:13",children:"大模型配置"}),s.jsx(Ts,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:572:13",className:"text-slate-500",children:"配置 AI 助手使用的大语言模型(支持 OpenAI 兼容接口)"})]}),s.jsxs("div",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:576:11",className:"space-y-4 py-4 max-h-[60vh] overflow-y-auto pr-1",children:[s.jsxs("div",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:578:13",className:"flex items-center justify-between rounded-lg border border-slate-700 p-3",children:[s.jsxs("div",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:579:15",children:[s.jsx("p",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:580:17",className:"text-sm font-medium text-slate-200",children:"启用 AI 助手"}),s.jsx("p",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:581:17",className:"text-xs text-slate-500",children:"关闭后将无法进行对话"})]}),s.jsx(Us,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:583:15",checked:c.enabled,onCheckedChange:t=>p({...c,enabled:t})})]}),s.jsxs("div",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:586:13",className:"grid grid-cols-2 gap-4",children:[s.jsxs("div",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:587:15",children:[s.jsx(y,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:588:17",className:"text-slate-300",children:"提供商"}),s.jsxs(ss,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:589:17",value:c.provider,onValueChange:Ns,children:[s.jsx(ts,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:590:19",className:"bg-slate-800 border-slate-700 text-slate-100 mt-1",children:s.jsx(es,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:591:21"})}),s.jsx(as,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:593:19",className:"bg-slate-800 border-slate-700",children:z.map(t=>s.jsx(ns,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:595:23",value:t.id,className:"text-slate-100",children:t.name},t.id))})]})]}),s.jsxs("div",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:600:15",children:[s.jsx(y,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:601:17",className:"text-slate-300",children:"模型"}),R&&R.models.length>0?s.jsxs(ss,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:603:19",value:c.model,onValueChange:t=>p({...c,model:t}),children:[s.jsx(ts,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:604:21",className:"bg-slate-800 border-slate-700 text-slate-100 mt-1",children:s.jsx(es,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:605:23"})}),s.jsx(as,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:607:21",className:"bg-slate-800 border-slate-700",children:R.models.map(t=>s.jsx(ns,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:609:25",value:t,className:"text-slate-100",children:t},t))})]}):s.jsx(C,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:614:19",value:c.model,onChange:t=>p({...c,model:t.target.value}),placeholder:"输入模型名称",className:"bg-slate-800 border-slate-700 text-slate-100 mt-1"})]})]}),s.jsxs("div",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:623:13",children:[s.jsxs(y,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:624:15",className:"text-slate-300",children:["API Key ",c.provider==="ollama"&&s.jsx("span",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:624:90",className:"text-xs text-slate-500",children:"(本地 Ollama 通常无需)"})]}),s.jsx(C,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:625:15",type:"password",value:c.api_key,onChange:t=>p({...c,api_key:t.target.value}),placeholder:"sk-...",className:"bg-slate-800 border-slate-700 text-slate-100 mt-1"})]}),s.jsxs("div",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:633:13",children:[s.jsx(y,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:634:15",className:"text-slate-300",children:"API Endpoint"}),s.jsx(C,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:635:15",value:c.endpoint,onChange:t=>p({...c,endpoint:t.target.value}),placeholder:"https://api.openai.com/v1",className:"bg-slate-800 border-slate-700 text-slate-100 mt-1 font-mono text-sm"}),s.jsx("p",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:641:15",className:"text-xs text-slate-500 mt-1",children:"基础地址(不含 /chat/completions),OpenAI 兼容格式"})]}),s.jsxs("div",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:643:13",children:[s.jsx(y,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:644:15",className:"text-slate-300",children:"系统提示词(可选)"}),s.jsx("textarea",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:645:15",value:c.system_prompt,onChange:t=>p({...c,system_prompt:t.target.value}),placeholder:"留空则使用内置 AIOps 运维助手角色提示词",className:"w-full bg-slate-800 border border-slate-700 text-slate-100 mt-1 rounded-md p-2 text-sm min-h-[70px] resize-y"})]}),s.jsxs("div",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:652:13",className:"grid grid-cols-2 gap-4",children:[s.jsxs("div",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:653:15",children:[s.jsx(y,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:654:17",className:"text-slate-300",children:"Temperature"}),s.jsx(C,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:655:17",type:"number",min:0,max:2,step:.1,value:Math.round(c.temperature*10)/10,onChange:t=>p({...c,temperature:parseFloat(t.target.value)||0}),className:"bg-slate-800 border-slate-700 text-slate-100 mt-1"}),s.jsx("p",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:664:17",className:"text-xs text-slate-500 mt-1",children:"值越高回答越创造性"})]}),s.jsxs("div",{"code-path":"src/components/aiops/AIOpsAssistant.tsx:666:15",children:[s.jsx(y,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:667:17",className:"text-slate-300",children:"Max Tokens"}),s.jsx(C,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:668:17",type:"number",value:c.max_tokens,onChange:t=>p({...c,max_tokens:parseInt(t.target.value)||2e3}),className:"bg-slate-800 border-slate-700 text-slate-100 mt-1"})]})]})]}),s.jsxs(qs,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:677:11",className:"gap-2",children:[s.jsxs(N,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:678:13",variant:"outline",onClick:ys,disabled:h,className:"border-slate-700 text-slate-300",children:[h?s.jsx(E,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:679:26",className:"h-4 w-4 mr-2 animate-spin"}):s.jsx(Xs,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:679:78",className:"h-4 w-4 mr-2"}),"测试连接"]}),s.jsx(N,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:682:13",variant:"outline",onClick:()=>l(!1),className:"border-slate-700 text-slate-300",children:"取消"}),s.jsxs(N,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:685:13",className:"bg-purple-600 hover:bg-purple-700",onClick:Ss,disabled:g,children:[g?s.jsx(E,{"code-path":"src/components/aiops/AIOpsAssistant.tsx:686:25",className:"h-4 w-4 mr-2 animate-spin"}):null,"保存配置"]})]})]})})]})}export{Rt as AIOpsAssistant};
|