CyberStrikeAI/web/static/app/assets/skills-management-CBXR8d2s.js

1 line
5.7 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,t as n}from"./react-QV7DAAIx.js";import{C as r,G as i,I as a,Lt as o,R as s,S as c,U as l,ft as u,i as d,lt as f,ut as p}from"./semi-65W_4I1v.js";import{E as m,F as h,I as g,L as _,T as v,a as y,b,c as x,d as S,f as C,l as w,m as T,n as E,p as D,s as O,x as k,y as A}from"./index-DNMXun-U.js";var j=e(t(),1),M=e(n(),1),{Text:N}=i;function P(){let e=h(),{hasPermission:t}=g(),n=t(`skills:write`),r=t(`skills:delete`),[i,c]=(0,j.useState)(``),S=E(i,300),[C,P]=(0,j.useState)(1),[I,L]=(0,j.useState)(20),[R,z]=(0,j.useState)(null),[B,V]=(0,j.useState)(null),[H,U]=(0,j.useState)(!1),W=y(()=>_.get(`/skills`,{search:S||void 0,limit:I,offset:(C-1)*I}),[S,C,I]),G=Array.isArray(W.data?.skills)?W.data.skills:[],K=Number(W.data?.total||0),q=async()=>{let e=await B.form.validate();U(!0);try{await _.post(`/skills`,{name:e.name.trim(),description:e.description.trim(),content:e.content}),k(`技能已创建`),V(null),W.reload()}catch(e){b(e,`创建技能失败`)}finally{U(!1)}},J=e=>A({title:`删除技能「${e.name}」?`,content:`该技能目录及其全部文件会被移除。`,onOk:async()=>{await _.del(`/skills/${encodeURIComponent(e.id||e.name)}`),k(`已删除`),W.reload()}});return(0,M.jsxs)(`div`,{children:[(0,M.jsx)(D,{title:e(`skills.managementTitle`,null,`技能管理`),description:`技能以目录形式存放在技能根目录,SKILL.md 描述触发条件与用法。`,extra:(0,M.jsxs)(a,{children:[(0,M.jsx)(s,{icon:(0,M.jsx)(p,{}),onClick:()=>W.reload(),loading:W.loading,children:`刷新`}),n&&(0,M.jsx)(s,{theme:`solid`,type:`primary`,icon:(0,M.jsx)(u,{}),onClick:()=>V({form:{}}),children:`新建技能`})]})}),(0,M.jsxs)(T,{title:`技能(${K})`,children:[(0,M.jsx)(w,{error:W.error,onRetry:()=>W.reload()}),(0,M.jsx)(O,{columns:[{title:`技能`,dataIndex:`name`,render:(e,t)=>(0,M.jsxs)(a,{vertical:!0,spacing:0,align:`start`,children:[(0,M.jsx)(N,{strong:!0,children:e||t.id}),(0,M.jsx)(N,{type:`tertiary`,ellipsis:{showTooltip:!0},style:{maxWidth:420},children:t.description})]})},{title:`版本`,dataIndex:`version`,width:100,render:e=>e||`—`},{title:`文件`,dataIndex:`file_count`,width:80,render:e=>String(e??`—`)},{title:`大小`,dataIndex:`file_size`,width:100,render:e=>v(e)},{title:`更新时间`,dataIndex:`mod_time`,width:170,render:e=>e?m(e):`—`},{title:`操作`,width:140,render:(e,t)=>(0,M.jsxs)(a,{children:[(0,M.jsx)(s,{size:`small`,theme:`borderless`,onClick:()=>z(t),children:`详情`}),r&&(0,M.jsx)(s,{size:`small`,theme:`borderless`,type:`danger`,icon:(0,M.jsx)(o,{}),onClick:()=>J(t)})]})}],dataSource:G,rowKey:e=>e.id||e.name,loading:W.loading,pagination:{currentPage:C,pageSize:I,total:K,onPageChange:P,onPageSizeChange:e=>{L(e),P(1)}},toolbar:(0,M.jsx)(l,{prefix:(0,M.jsx)(f,{}),value:i,onChange:e=>{c(e),P(1)},placeholder:`搜索技能名称或描述`,style:{width:280}})})]}),(0,M.jsx)(x,{title:`新建技能`,visible:!!B,onCancel:()=>V(null),onOk:q,confirmLoading:H,width:720,children:(0,M.jsxs)(d,{getFormApi:e=>V(t=>t&&{...t,form:e}),children:[(0,M.jsx)(d.Input,{field:`name`,label:`目录名`,placeholder:`小写字母、数字、连字符`,rules:[{required:!0,message:`请输入目录名`},{pattern:/^[a-z0-9-]+$/,message:`只允许小写字母、数字与连字符`}]}),(0,M.jsx)(d.Input,{field:`description`,label:`描述`,rules:[{required:!0,message:`请输入描述`}]}),(0,M.jsx)(d.TextArea,{field:`content`,label:`SKILL.md 正文`,rules:[{required:!0,message:`请输入正文`}],autosize:{minRows:10,maxRows:24}})]})},`new-skill`),(0,M.jsx)(F,{skill:R,onClose:()=>z(null),canWrite:n})]})}function F({skill:e,onClose:t,canWrite:n}){let[i,o]=(0,j.useState)([]),[l,u]=(0,j.useState)(``),[d,f]=(0,j.useState)(``),[p,m]=(0,j.useState)(!1),[h,g]=(0,j.useState)(!1);(0,j.useEffect)(()=>{e&&(o([]),u(``),f(``),_.get(`/skills/${encodeURIComponent(e.id||e.name)}/files`).then(e=>o(Array.isArray(e?.files)?e.files:[])).catch(()=>o([])))},[e]);let v=async t=>{m(!0);try{let n=await _.get(`/skills/${encodeURIComponent(e.id||e.name)}/file`,{path:t});u(t),f(n?.content||``)}catch(e){b(e,`读取文件失败`)}finally{m(!1)}},y=async()=>{g(!0);try{await _.put(`/skills/${encodeURIComponent(e.id||e.name)}/file`,{path:l,content:d}),k(`文件已保存`)}catch(e){b(e,`保存文件失败`)}finally{g(!1)}},w=i.map(e=>typeof e==`string`?e:e.path||e.name);return(0,M.jsx)(x,{title:e?.name||`技能详情`,visible:!!e,onCancel:t,width:860,children:e&&(0,M.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:12},children:[(0,M.jsx)(S,{items:[{label:`目录名`,value:e.id||e.dir_name},{label:`版本`,value:e.version||`—`},{label:`路径`,value:e.path},{label:`文件数`,value:e.file_count},{label:`触发词`,value:Array.isArray(e.triggers)?e.triggers.join(`、`):`—`},{label:`标签`,value:Array.isArray(e.tags)?e.tags.join(`、`):`—`}]}),(0,M.jsx)(N,{type:`tertiary`,children:e.description}),(0,M.jsxs)(`div`,{style:{display:`grid`,gridTemplateColumns:`220px minmax(0, 1fr)`,gap:12},children:[(0,M.jsx)(`div`,{style:{border:`1px solid var(--semi-color-border)`,borderRadius:8,maxHeight:420,overflow:`auto`},children:(0,M.jsx)(r,{dataSource:w,renderItem:e=>(0,M.jsx)(r.Item,{main:(0,M.jsx)(N,{size:`small`,ellipsis:{showTooltip:!0},children:e}),onClick:()=>v(e),style:{cursor:`pointer`,background:e===l?`var(--semi-color-primary-light-default)`:void 0}}),emptyContent:`暂无文件`})}),(0,M.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:8},children:[(0,M.jsxs)(a,{children:[(0,M.jsx)(N,{strong:!0,children:l||`选择左侧文件查看内容`}),n&&l&&(0,M.jsx)(s,{size:`small`,loading:h,onClick:y,children:`保存`})]}),l?(0,M.jsx)(c,{value:d,onChange:f,autosize:{minRows:20,maxRows:30},disabled:!n}):(0,M.jsx)(C,{content:e.description||`—`}),p&&(0,M.jsx)(N,{type:`tertiary`,children:`读取中…`})]})]})]})})}export{P as default};