mirror of
https://gitee.com/fit2cloud-feizhiyun/1Panel.git
synced 2026-11-20 07:49:30 +08:00
feat: add agent website check for delete (#12433)
This commit is contained in:
@@ -51,6 +51,27 @@ func (b *BaseApi) PageAgents(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
// @Tags AI
|
||||
// @Summary Delete check Agent
|
||||
// @Accept json
|
||||
// @Param request body dto.AgentIDReq true "request"
|
||||
// @Success 200 {array} dto.AppResource
|
||||
// @Security ApiKeyAuth
|
||||
// @Security Timestamp
|
||||
// @Router /ai/agents/delete/check [post]
|
||||
func (b *BaseApi) DeleteCheckAgent(c *gin.Context) {
|
||||
var req dto.AgentIDReq
|
||||
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
||||
return
|
||||
}
|
||||
checkData, err := agentService.DeleteCheck(req)
|
||||
if err != nil {
|
||||
helper.BadRequest(c, err)
|
||||
return
|
||||
}
|
||||
helper.SuccessWithData(c, checkData)
|
||||
}
|
||||
|
||||
// @Tags AI
|
||||
// @Summary Delete Agent
|
||||
// @Accept json
|
||||
|
||||
@@ -28,6 +28,7 @@ import (
|
||||
type IAgentService interface {
|
||||
Create(req dto.AgentCreateReq) (*dto.AgentItem, error)
|
||||
Page(req dto.SearchWithPage) (int64, []dto.AgentItem, error)
|
||||
DeleteCheck(req dto.AgentIDReq) ([]dto.AppResource, error)
|
||||
Delete(req dto.AgentDeleteReq) error
|
||||
ResetToken(req dto.AgentTokenResetReq) error
|
||||
UpdateRemark(req dto.AgentRemarkUpdateReq) error
|
||||
@@ -301,6 +302,13 @@ func (a AgentService) Delete(req dto.AgentDeleteReq) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
resources, err := a.deleteCheckByAgent(agent)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(resources) > 0 {
|
||||
return buserr.New("ErrAgentWebsiteBound")
|
||||
}
|
||||
if agent.AppInstallID == 0 {
|
||||
return agentRepo.DeleteByID(agent.ID)
|
||||
}
|
||||
@@ -316,6 +324,32 @@ func (a AgentService) Delete(req dto.AgentDeleteReq) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a AgentService) DeleteCheck(req dto.AgentIDReq) ([]dto.AppResource, error) {
|
||||
agent, err := agentRepo.GetFirst(repo.WithByID(req.AgentID))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return a.deleteCheckByAgent(agent)
|
||||
}
|
||||
|
||||
func (a AgentService) deleteCheckByAgent(agent *model.Agent) ([]dto.AppResource, error) {
|
||||
if agent == nil || agent.WebsiteID == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
website, err := websiteRepo.GetFirst(repo.WithByID(agent.WebsiteID))
|
||||
if err != nil {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
websiteName, err := loadAgentWebsiteResourceName(website)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return []dto.AppResource{{Type: "website", Name: websiteName}}, nil
|
||||
}
|
||||
|
||||
func (a AgentService) ResetToken(req dto.AgentTokenResetReq) error {
|
||||
agent, err := loadOpenclawAgentByID(req.ID)
|
||||
if err != nil {
|
||||
|
||||
@@ -103,6 +103,20 @@ func loadAgentWebsiteDomainMapByWebsiteID(items []dto.AgentItem) (map[uint][]mod
|
||||
return websiteDomainMap, nil
|
||||
}
|
||||
|
||||
func loadAgentWebsiteResourceName(website model.Website) (string, error) {
|
||||
websiteDomains, err := websiteDomainRepo.GetBy(websiteDomainRepo.WithWebsiteId(website.ID), repo.WithOrderAsc("id"))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if len(websiteDomains) > 0 {
|
||||
return websiteDomains[0].Domain, nil
|
||||
}
|
||||
if website.PrimaryDomain != "" {
|
||||
return website.PrimaryDomain, nil
|
||||
}
|
||||
return fmt.Sprintf("%d", website.ID), nil
|
||||
}
|
||||
|
||||
func fillAgentWebsiteItems(items []dto.AgentItem, explicitWebsiteMap map[uint]model.Website, websiteDomainMap map[uint][]model.WebsiteDomain) {
|
||||
for index := range items {
|
||||
if items[index].WebsiteID == 0 {
|
||||
|
||||
@@ -42,6 +42,7 @@ func (a *AIToolsRouter) InitRouter(Router *gin.RouterGroup) {
|
||||
|
||||
aiToolsRouter.POST("/agents", baseApi.CreateAgent)
|
||||
aiToolsRouter.POST("/agents/search", baseApi.PageAgents)
|
||||
aiToolsRouter.POST("/agents/delete/check", baseApi.DeleteCheckAgent)
|
||||
aiToolsRouter.POST("/agents/delete", baseApi.DeleteAgent)
|
||||
aiToolsRouter.POST("/agents/token/reset", baseApi.ResetAgentToken)
|
||||
aiToolsRouter.POST("/agents/remark", baseApi.UpdateAgentRemark)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { AI } from '@/api/interface/ai';
|
||||
import { App } from '@/api/interface/app';
|
||||
import http from '@/api';
|
||||
import { ResPage, SearchWithPage } from '../interface';
|
||||
import { TimeoutEnum } from '@/enums/http-enum';
|
||||
@@ -101,6 +102,10 @@ export const pageAgents = (req: SearchWithPage) => {
|
||||
return http.post<ResPage<AI.AgentItem>>(`/ai/agents/search`, req);
|
||||
};
|
||||
|
||||
export const deleteAgentCheck = (req: AI.AgentIDReq) => {
|
||||
return http.post<App.AppInstallResource[]>(`/ai/agents/delete/check`, req);
|
||||
};
|
||||
|
||||
export const deleteAgent = (req: AI.AgentDeleteReq) => {
|
||||
return http.post(`/ai/agents/delete`, req);
|
||||
};
|
||||
|
||||
@@ -190,6 +190,7 @@
|
||||
<AddDialog ref="addRef" @search="search" @task="openTaskLog" />
|
||||
<TaskLog ref="taskLogRef" @close="search" />
|
||||
<DeleteDialog ref="deleteRef" @close="search" />
|
||||
<AppResources ref="checkRef" @close="search" />
|
||||
<ConfigDrawer ref="configRef" @updated="search" />
|
||||
<OverviewDrawer ref="overviewRef" />
|
||||
<BindWebsiteDialog ref="bindWebsiteRef" @success="search" />
|
||||
@@ -203,7 +204,7 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, reactive, ref } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { pageAgents, resetAgentToken, updateAgentRemark } from '@/api/modules/ai';
|
||||
import { deleteAgentCheck, pageAgents, resetAgentToken, updateAgentRemark } from '@/api/modules/ai';
|
||||
import { checkAppInstalled, installedOp, searchApp, searchAppInstalled } from '@/api/modules/app';
|
||||
import { AI } from '@/api/interface/ai';
|
||||
import { App } from '@/api/interface/app';
|
||||
@@ -214,6 +215,7 @@ import { MsgSuccess } from '@/utils/message';
|
||||
|
||||
import AddDialog from '@/views/ai/agents/agent/add/index.vue';
|
||||
import DeleteDialog from '@/views/ai/agents/agent/delete/index.vue';
|
||||
import AppResources from '@/views/app-store/installed/check/index.vue';
|
||||
import ConfigDrawer from '@/views/ai/agents/agent/config/index.vue';
|
||||
import OverviewDrawer from '@/views/ai/agents/agent/components/overview.vue';
|
||||
import BindWebsiteDialog from '@/views/ai/agents/agent/website/index.vue';
|
||||
@@ -236,6 +238,7 @@ const loading = ref(false);
|
||||
const addRef = ref();
|
||||
const taskLogRef = ref();
|
||||
const deleteRef = ref();
|
||||
const checkRef = ref();
|
||||
const configRef = ref();
|
||||
const overviewRef = ref();
|
||||
const bindWebsiteRef = ref();
|
||||
@@ -442,7 +445,16 @@ const jumpWebUI = (row: AI.AgentItem) => {
|
||||
}
|
||||
};
|
||||
|
||||
const onDelete = (row: AI.AgentItem) => {
|
||||
const onDelete = async (row: AI.AgentItem) => {
|
||||
const res = await deleteAgentCheck({ agentId: row.id });
|
||||
if ((res.data || []).length > 0) {
|
||||
checkRef.value?.acceptParams({
|
||||
items: res.data,
|
||||
installID: row.appInstallId,
|
||||
key: row.agentType,
|
||||
});
|
||||
return;
|
||||
}
|
||||
deleteRef.value?.acceptParams(row.id, row.name);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user