CyberStrikeAI/web/static/app/assets/knowledge-management-BxQoJW...

1 line
6.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,g as n,t as r}from"./react-QV7DAAIx.js";import{B as ee,G as i,I as a,Lt as te,N as o,Pt as ne,R as s,U as re,ft as ie,i as c,lt as l,ot as u,ut as d,y as f}from"./semi-65W_4I1v.js";import{D as p,E as m,F as ae,I as h,P as g,_,a as v,b as y,c as b,d as x,f as S,l as oe,m as se,p as C,s as w,x as T,y as ce}from"./index-D_JyAVdp.js";var E=e(t(),1),D=e(r(),1),{Text:O}=i;function k(){let e=g(),t=n(),{hasPermission:r}=ae(),i=r(`knowledge:write`),k=r(`config:read`),[A,le]=(0,E.useState)(``),[j,M]=(0,E.useState)(``),[N,P]=(0,E.useState)(1),[F,I]=(0,E.useState)(20),[L,R]=(0,E.useState)(null),[z,B]=(0,E.useState)(null),[V,H]=(0,E.useState)(!1),[U,W]=(0,E.useState)(!1),[G,K]=(0,E.useState)(null),q=v(()=>h.get(`/knowledge/items`,{category:A||void 0,search:j||void 0,limit:F,offset:(N-1)*F}),[A,j,N,F]),J=v(()=>h.get(`/knowledge/stats`),[]),Y=v(()=>h.get(`/knowledge/categories`),[]),X=v(()=>h.get(`/knowledge/index-status`),[]),ue=Array.isArray(q.data?.items)?q.data.items:[],de=Number(q.data?.total||0),Z=q.data?.enabled===!1||X.data?.enabled===!1,fe=(Array.isArray(Y.data?.categories)?Y.data.categories:[]).map(e=>typeof e==`string`?{value:e,label:e}:{value:e.name||e.category,label:e.name||e.category}),Q=(0,E.useCallback)(()=>{q.reload(),J.reload(),X.reload()},[q,J,X]),pe=async()=>{let e=await L.form.validate();H(!0);try{let t={category:e.category.trim(),title:e.title.trim(),content:e.content};L.item?.id?await h.put(`/knowledge/items/${encodeURIComponent(L.item.id)}`,t):await h.post(`/knowledge/items`,t),T(L.item?.id?`知识项已更新`:`知识项已创建`),R(null),Q()}catch(e){y(e,`保存失败`)}finally{H(!1)}},me=e=>ce({title:`删除知识项「${e.title}」?`,content:`删除后需要重新索引,且不可恢复。`,onOk:async()=>{await h.del(`/knowledge/items/${encodeURIComponent(e.id)}`),T(`已删除`),Q()}}),$=async e=>{try{await h.post(`/knowledge/index`,e?{full:!0}:{}),T(`索引任务已提交`),X.reload()}catch(e){y(e,`构建索引失败`)}},he=async e=>{try{K(await h.post(`/knowledge/search`,{query:e,topK:5}))}catch(e){y(e,`检索失败`)}};return(0,D.jsxs)(`div`,{children:[(0,D.jsx)(C,{title:e(`knowledge.title`,null,`知识管理`),description:`知识条目会参与智能体检索;修改后需要重建索引才能生效。`,extra:(0,D.jsxs)(a,{wrap:!0,children:[k&&(0,D.jsx)(s,{icon:(0,D.jsx)(u,{}),onClick:()=>t(`/settings?section=knowledge`),children:`知识库设置`}),(0,D.jsx)(s,{icon:(0,D.jsx)(d,{}),onClick:Q,children:`刷新`}),i&&(0,D.jsx)(s,{disabled:Z,onClick:()=>$(!1),children:`构建索引`}),i&&(0,D.jsx)(s,{disabled:Z,onClick:()=>$(!0),children:`全量重建`}),i&&(0,D.jsx)(s,{theme:`solid`,type:`primary`,icon:(0,D.jsx)(ie,{}),disabled:Z,onClick:()=>R({item:null,form:{}}),children:`新增知识`})]})}),Z&&(0,D.jsx)(ee,{type:`warning`,bordered:!0,closeIcon:null,style:{marginBottom:16},description:(0,D.jsxs)(a,{wrap:!0,children:[(0,D.jsx)(`span`,{children:q.data?.message||X.data?.message||`知识库功能未启用,请先在系统设置中开启知识检索并配置嵌入模型。`}),k&&(0,D.jsx)(s,{size:`small`,theme:`solid`,type:`primary`,onClick:()=>t(`/settings?section=knowledge`),children:`前往启用知识库`})]})}),(0,D.jsx)(_,{columns:4,metrics:[{id:`items`,label:`知识条目`,value:p(J.data?.total_items||0),loading:J.loading},{id:`categories`,label:`分类数`,value:p(J.data?.total_categories||0),loading:J.loading},{id:`indexed`,label:`已索引`,value:p(X.data?.indexed_items??X.data?.total_indexed??0),loading:X.loading},{id:`pending`,label:`待索引`,value:p(X.data?.pending_items??0),loading:X.loading}]}),(0,D.jsxs)(se,{title:`知识条目`,children:[(0,D.jsx)(oe,{error:q.error,onRetry:()=>q.reload()}),(0,D.jsx)(w,{columns:[{title:`标题`,dataIndex:`title`,render:(e,t)=>(0,D.jsx)(O,{strong:!0,children:e||t.filePath})},{title:`分类`,dataIndex:`category`,width:160,render:e=>e?(0,D.jsx)(o,{size:`small`,children:e}):`—`},{title:`更新时间`,dataIndex:`updatedAt`,width:180,render:e=>m(e)},{title:`操作`,width:150,render:(e,t)=>(0,D.jsxs)(a,{children:[(0,D.jsx)(s,{size:`small`,theme:`borderless`,onClick:()=>B(t),children:`查看`}),i&&(0,D.jsx)(s,{size:`small`,theme:`borderless`,icon:(0,D.jsx)(ne,{}),onClick:()=>R({item:t,form:{}})}),i&&(0,D.jsx)(s,{size:`small`,theme:`borderless`,type:`danger`,icon:(0,D.jsx)(te,{}),onClick:()=>me(t)})]})}],dataSource:ue,rowKey:`id`,loading:q.loading,pagination:{currentPage:N,pageSize:F,total:de,onPageChange:P,onPageSizeChange:e=>{I(e),P(1)}},toolbar:(0,D.jsxs)(a,{children:[(0,D.jsx)(re,{prefix:(0,D.jsx)(l,{}),value:j,onChange:e=>{M(e),P(1)},placeholder:`搜索标题或内容`,style:{width:220}}),(0,D.jsx)(f,{value:A,onChange:e=>{le(e||``),P(1)},placeholder:`全部分类`,style:{width:180},showClear:!0,optionList:fe}),(0,D.jsx)(s,{onClick:()=>W(!0),children:`检索测试`})]})})]}),(0,D.jsx)(b,{title:L?.item?`编辑知识项`:`新增知识项`,visible:!!L,onCancel:()=>R(null),onOk:pe,confirmLoading:V,width:760,children:(0,D.jsxs)(c,{getFormApi:e=>R(t=>t&&{...t,form:e}),initValues:L?.item?{category:L.item.category,title:L.item.title,content:L.item.content}:{},children:[(0,D.jsx)(c.Input,{field:`category`,label:`分类`,rules:[{required:!0,message:`请输入分类`}],placeholder:`例如 sql_injection`}),(0,D.jsx)(c.Input,{field:`title`,label:`标题`,rules:[{required:!0,message:`请输入标题`}]}),(0,D.jsx)(c.TextArea,{field:`content`,label:`内容(Markdown)`,rules:[{required:!0,message:`请输入内容`}],autosize:{minRows:10,maxRows:24}})]})},L?.item?.id||`new`),(0,D.jsx)(b,{title:z?.title||`知识项`,visible:!!z,onCancel:()=>B(null),width:640,children:z&&(0,D.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:12},children:[(0,D.jsx)(x,{items:[{label:`分类`,value:z.category},{label:`文件路径`,value:z.filePath},{label:`创建时间`,value:m(z.createdAt)},{label:`更新时间`,value:m(z.updatedAt)}]}),(0,D.jsx)(S,{content:z.content||`(内容需要打开原文查看)`})]})}),(0,D.jsxs)(b,{title:`知识检索测试`,visible:U,onCancel:()=>{W(!1),K(null)},footer:null,width:720,children:[(0,D.jsxs)(c,{onSubmit:({query:e})=>he(e),children:[(0,D.jsx)(c.Input,{field:`query`,label:`检索语句`,rules:[{required:!0,message:`请输入检索语句`}]}),(0,D.jsx)(s,{htmlType:`submit`,theme:`solid`,type:`primary`,children:`检索`})]}),G&&(0,D.jsxs)(`div`,{style:{marginTop:16,display:`flex`,flexDirection:`column`,gap:8},children:[(G.results||[]).map((e,t)=>(0,D.jsxs)(`div`,{style:{border:`1px solid var(--semi-color-border)`,borderRadius:8,padding:12},children:[(0,D.jsxs)(a,{children:[(0,D.jsxs)(o,{color:`blue`,children:[`#`,t+1]}),(0,D.jsx)(O,{strong:!0,children:e.item?.title||e.title||e.id}),e.score!==void 0&&(0,D.jsxs)(O,{type:`tertiary`,children:[`相似度 `,Number(e.score).toFixed(3)]})]}),(0,D.jsx)(`div`,{style:{marginTop:8},children:(0,D.jsx)(S,{content:String(e.content||e.item?.content||``).slice(0,600)})})]},e.id||t)),(G.results||[]).length===0&&(0,D.jsx)(O,{type:`tertiary`,children:`没有命中结果`})]})]})]})}export{k as default};