Browse Source

添加智能体新增功能

余思翰 1 week ago
parent
commit
84d183fecb

+ 34
- 2
llm-ui/src/api/llm/agent.js View File

1
 /*
1
 /*
2
  * @Author: wrh
2
  * @Author: wrh
3
  * @Date: 2025-07-17 18:06:24
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
 import request from '@/utils/request'
7
 import request from '@/utils/request'
8
 
8
 
48
     method: 'delete'
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 View File

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 View File

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 View File

2
  * @Author: ysh
2
  * @Author: ysh
3
  * @Date: 2025-07-17 18:16:50
3
  * @Date: 2025-07-17 18:16:50
4
  * @LastEditors: Please set LastEditors
4
  * @LastEditors: Please set LastEditors
5
- * @LastEditTime: 2025-07-22 10:01:21
5
+ * @LastEditTime: 2025-07-25 15:30:21
6
 -->
6
 -->
7
 <template>
7
 <template>
8
   <div class="agent-container">
8
   <div class="agent-container">
10
     <div class="agent-list">
10
     <div class="agent-list">
11
       <div class="list-header">
11
       <div class="list-header">
12
         <h3>智能体列表</h3>
12
         <h3>智能体列表</h3>
13
-        <el-button type="primary" size="small" @click="handleAdd">
13
+        <el-button type="primary" size="small" @click="openAddDialog">
14
           <el-icon>
14
           <el-icon>
15
             <Plus />
15
             <Plus />
16
           </el-icon>
16
           </el-icon>
61
         <!-- 空状态 -->
61
         <!-- 空状态 -->
62
         <div v-if="agentList.length === 0 && !loading" class="empty-state">
62
         <div v-if="agentList.length === 0 && !loading" class="empty-state">
63
           <el-empty description="暂无智能体数据">
63
           <el-empty description="暂无智能体数据">
64
-            <el-button type="primary" @click="handleAdd">创建智能体</el-button>
64
+            <el-button type="primary" @click="dialogVisible = true">创建智能体</el-button>
65
           </el-empty>
65
           </el-empty>
66
         </div>
66
         </div>
67
       </div>
67
       </div>
93
         </div>
93
         </div>
94
       </div>
94
       </div>
95
     </div>
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
   </div>
111
   </div>
97
 </template>
112
 </template>
98
 
113
 
99
 <script setup>
114
 <script setup>
100
 import { ref, reactive, onMounted } from 'vue'
115
 import { ref, reactive, onMounted } from 'vue'
101
 import { ElMessage, ElMessageBox } from 'element-plus'
116
 import { ElMessage, ElMessageBox } from 'element-plus'
102
-import { Plus, Search, More, Document, Select } from '@element-plus/icons-vue'
103
 import { listAgent, addAgent, updateAgent, delAgent } from '@/api/llm/agent'
117
 import { listAgent, addAgent, updateAgent, delAgent } from '@/api/llm/agent'
118
+import { opening } from '@/api/llm/mcp'
104
 
119
 
105
 // 响应式数据
120
 // 响应式数据
106
 const loading = ref(false)
121
 const loading = ref(false)
107
 const agentList = ref([])
122
 const agentList = ref([])
108
 const total = ref(0)
123
 const total = ref(0)
109
 const selectedAgentId = ref(null)
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
 const queryParams = reactive({
138
 const queryParams = reactive({
140
 const selectAgent = (agent) => {
166
 const selectAgent = (agent) => {
141
   selectedAgentId.value = agent.agentId
167
   selectedAgentId.value = agent.agentId
142
   console.log('选中智能体:', agent)
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
   const { action, agent } = command
210
   const { action, agent } = command
154
 
211
 
155
   if (action === 'edit') {
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
   } else if (action === 'delete') {
218
   } else if (action === 'delete') {
159
     try {
219
     try {
160
       await ElMessageBox.confirm(
220
       await ElMessageBox.confirm(

Loading…
Cancel
Save