瀏覽代碼

添加智能体新增功能

余思翰 1 周之前
父節點
當前提交
84d183fecb
共有 4 個檔案被更改,包括 120 行新增56 行删除
  1. 34
    2
      llm-ui/src/api/llm/agent.js
  2. 16
    0
      llm-ui/src/api/llm/mcp.js
  3. 0
    44
      llm-ui/src/api/llm/tool.js
  4. 70
    10
      llm-ui/src/views/llm/agent/index.vue

+ 34
- 2
llm-ui/src/api/llm/agent.js 查看文件

@@ -1,8 +1,8 @@
1 1
 /*
2 2
  * @Author: wrh
3 3
  * @Date: 2025-07-17 18:06:24
4
- * @LastEditors: wrh
5
- * @LastEditTime: 2025-07-17 18:07:30
4
+ * @LastEditors: Please set LastEditors
5
+ * @LastEditTime: 2025-07-25 14:51:40
6 6
  */
7 7
 import request from '@/utils/request'
8 8
 
@@ -48,3 +48,35 @@ export function delAgent(agentId) {
48 48
     method: 'delete'
49 49
   })
50 50
 }
51
+
52
+// 上传单文件
53
+export function uploadFile(file, agentName) {
54
+  const formData = new FormData()
55
+  formData.append('file', file)
56
+  formData.append('agentName', agentName)
57
+  return request({
58
+    url: '/llm/agent/upload',
59
+    method: 'post',
60
+    data: formData,
61
+    headers: {
62
+      'Content-Type': 'multipart/form-data'
63
+    }
64
+  })
65
+}
66
+
67
+// 上传多文件
68
+export function uploadFileList(fileList, agentName) {
69
+  const formData = new FormData()
70
+  for (let f of fileList) {
71
+    formData.append('fileList', f)
72
+  }
73
+  formData.append('agentName', agentName)
74
+  return request({
75
+    url: '/llm/agent/uploadList',
76
+    method: 'post',
77
+    data: formData,
78
+    headers: {
79
+      'Content-Type': 'multipart/form-data'
80
+    }
81
+  })
82
+}

+ 16
- 0
llm-ui/src/api/llm/mcp.js 查看文件

@@ -0,0 +1,16 @@
1
+/*
2
+ * @Author: ysh
3
+ * @Date: 2025-07-25 14:52:22
4
+ * @LastEditors: 
5
+ * @LastEditTime: 2025-07-25 14:53:25
6
+ */
7
+import request from '@/utils/request'
8
+
9
+//获取开场白, agentName:智能体名称
10
+export function opening(agentName) {
11
+  return request({
12
+    url: '/llm/mcp/opening',
13
+    method: 'get',
14
+    params: { agentName }
15
+  })
16
+}

+ 0
- 44
llm-ui/src/api/llm/tool.js 查看文件

@@ -1,44 +0,0 @@
1
-import request from '@/utils/request'
2
-
3
-// 查询智能体工具列表
4
-export function listTool(query) {
5
-  return request({
6
-    url: '/llm/tool/list',
7
-    method: 'get',
8
-    params: query
9
-  })
10
-}
11
-
12
-// 查询智能体工具详细
13
-export function getTool(agentToolId) {
14
-  return request({
15
-    url: '/llm/tool/' + agentToolId,
16
-    method: 'get'
17
-  })
18
-}
19
-
20
-// 新增智能体工具
21
-export function addTool(data) {
22
-  return request({
23
-    url: '/llm/tool',
24
-    method: 'post',
25
-    data: data
26
-  })
27
-}
28
-
29
-// 修改智能体工具
30
-export function updateTool(data) {
31
-  return request({
32
-    url: '/llm/tool',
33
-    method: 'put',
34
-    data: data
35
-  })
36
-}
37
-
38
-// 删除智能体工具
39
-export function delTool(agentToolId) {
40
-  return request({
41
-    url: '/llm/tool/' + agentToolId,
42
-    method: 'delete'
43
-  })
44
-}

+ 70
- 10
llm-ui/src/views/llm/agent/index.vue 查看文件

@@ -2,7 +2,7 @@
2 2
  * @Author: ysh
3 3
  * @Date: 2025-07-17 18:16:50
4 4
  * @LastEditors: Please set LastEditors
5
- * @LastEditTime: 2025-07-22 10:01:21
5
+ * @LastEditTime: 2025-07-25 15:30:21
6 6
 -->
7 7
 <template>
8 8
   <div class="agent-container">
@@ -10,7 +10,7 @@
10 10
     <div class="agent-list">
11 11
       <div class="list-header">
12 12
         <h3>智能体列表</h3>
13
-        <el-button type="primary" size="small" @click="handleAdd">
13
+        <el-button type="primary" size="small" @click="openAddDialog">
14 14
           <el-icon>
15 15
             <Plus />
16 16
           </el-icon>
@@ -61,7 +61,7 @@
61 61
         <!-- 空状态 -->
62 62
         <div v-if="agentList.length === 0 && !loading" class="empty-state">
63 63
           <el-empty description="暂无智能体数据">
64
-            <el-button type="primary" @click="handleAdd">创建智能体</el-button>
64
+            <el-button type="primary" @click="dialogVisible = true">创建智能体</el-button>
65 65
           </el-empty>
66 66
         </div>
67 67
       </div>
@@ -93,20 +93,46 @@
93 93
         </div>
94 94
       </div>
95 95
     </div>
96
+
97
+    <el-dialog v-model="dialogVisible" :title="isEdit ? '编辑智能体' : '新增智能体'" width="30%" @close="resetForm">
98
+      <el-form :model="form" :rules="rules" label-width="120px">
99
+        <el-form-item label="智能体名称" prop="agentName">
100
+          <el-input v-model="form.agentName" placeholder="请输入智能体名称" />
101
+        </el-form-item>
102
+        <el-form-item label="智能体描述" prop="description">
103
+          <el-input type="textarea" v-model="form.description" placeholder="请输入智能体描述" />
104
+        </el-form-item>
105
+      </el-form>
106
+      <template #footer>
107
+        <el-button @click="() => { dialogVisible = false; resetForm(); }">取消</el-button>
108
+        <el-button type="primary" @click="handleSubmit">{{ isEdit ? '保存' : '确定' }}</el-button>
109
+      </template>
110
+    </el-dialog>
96 111
   </div>
97 112
 </template>
98 113
 
99 114
 <script setup>
100 115
 import { ref, reactive, onMounted } from 'vue'
101 116
 import { ElMessage, ElMessageBox } from 'element-plus'
102
-import { Plus, Search, More, Document, Select } from '@element-plus/icons-vue'
103 117
 import { listAgent, addAgent, updateAgent, delAgent } from '@/api/llm/agent'
118
+import { opening } from '@/api/llm/mcp'
104 119
 
105 120
 // 响应式数据
106 121
 const loading = ref(false)
107 122
 const agentList = ref([])
108 123
 const total = ref(0)
109 124
 const selectedAgentId = ref(null)
125
+const dialogVisible = ref(false)
126
+const form = reactive({
127
+  agentName: '',
128
+  description: ''
129
+})
130
+const rules = reactive({
131
+  agentName: [{ required: true, message: '请输入智能体名称', trigger: 'blur' }],
132
+  description: [{ required: true, message: '请输入智能体描述', trigger: 'blur' }]
133
+})
134
+const isEdit = ref(false)
135
+const editAgentId = ref(null)
110 136
 
111 137
 // 查询参数
112 138
 const queryParams = reactive({
@@ -140,12 +166,43 @@ const handleQuery = () => {
140 166
 const selectAgent = (agent) => {
141 167
   selectedAgentId.value = agent.agentId
142 168
   console.log('选中智能体:', agent)
169
+  opening(agent.agentName).then(res => {
170
+    console.log('开场白:', res.resultContent)
171
+  })
172
+}
173
+
174
+const resetForm = () => {
175
+  isEdit.value = false
176
+  editAgentId.value = null
177
+  form.agentName = ''
178
+  form.description = ''
143 179
 }
144 180
 
145
-// 新增智能体
146
-const handleAdd = () => {
147
-  ElMessage.info('新增智能体功能待实现')
148
-  // TODO: 打开新增对话框
181
+const openAddDialog = () => {
182
+  resetForm()
183
+  dialogVisible.value = true
184
+}
185
+
186
+const handleSubmit = () => {
187
+  if (isEdit.value) {
188
+    updateAgent({ agentId: editAgentId.value, ...form }).then(res => {
189
+      if (res.code === 200) {
190
+        ElMessage.success('编辑成功')
191
+        dialogVisible.value = false
192
+        isEdit.value = false
193
+        editAgentId.value = null
194
+        getList()
195
+      }
196
+    })
197
+  } else {
198
+    addAgent(form).then(res => {
199
+      if (res.code === 200) {
200
+        ElMessage.success('新增成功')
201
+        dialogVisible.value = false
202
+        getList()
203
+      }
204
+    })
205
+  }
149 206
 }
150 207
 
151 208
 // 操作菜单处理
@@ -153,8 +210,11 @@ const handleCommand = async (command) => {
153 210
   const { action, agent } = command
154 211
 
155 212
   if (action === 'edit') {
156
-    ElMessage.info('编辑智能体功能待实现')
157
-    // TODO: 打开编辑对话框
213
+    isEdit.value = true
214
+    editAgentId.value = agent.agentId
215
+    form.agentName = agent.agentName
216
+    form.description = agent.description
217
+    dialogVisible.value = true
158 218
   } else if (action === 'delete') {
159 219
     try {
160 220
       await ElMessageBox.confirm(

Loading…
取消
儲存