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

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