Skip to content

Commit e1e2b97

Browse files
feat: Add an Agent Management Page (#11801)
1 parent 8e4e1dc commit e1e2b97

43 files changed

Lines changed: 2949 additions & 12 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

agent/app/api/v2/agents.go

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
package v2
2+
3+
import (
4+
"github.com/1Panel-dev/1Panel/agent/app/api/v2/helper"
5+
"github.com/1Panel-dev/1Panel/agent/app/dto"
6+
"github.com/gin-gonic/gin"
7+
)
8+
9+
// @Tags AI
10+
// @Summary Create Agent
11+
// @Accept json
12+
// @Param request body dto.AgentCreateReq true "request"
13+
// @Success 200 {object} dto.AgentItem
14+
// @Security ApiKeyAuth
15+
// @Security Timestamp
16+
// @Router /ai/agents [post]
17+
func (b *BaseApi) CreateAgent(c *gin.Context) {
18+
var req dto.AgentCreateReq
19+
if err := helper.CheckBindAndValidate(&req, c); err != nil {
20+
return
21+
}
22+
res, err := agentService.Create(req)
23+
if err != nil {
24+
helper.BadRequest(c, err)
25+
return
26+
}
27+
helper.SuccessWithData(c, res)
28+
}
29+
30+
// @Tags AI
31+
// @Summary Page Agents
32+
// @Accept json
33+
// @Param request body dto.SearchWithPage true "request"
34+
// @Success 200 {object} dto.PageResult
35+
// @Security ApiKeyAuth
36+
// @Security Timestamp
37+
// @Router /ai/agents/search [post]
38+
func (b *BaseApi) PageAgents(c *gin.Context) {
39+
var req dto.SearchWithPage
40+
if err := helper.CheckBindAndValidate(&req, c); err != nil {
41+
return
42+
}
43+
total, list, err := agentService.Page(req)
44+
if err != nil {
45+
helper.BadRequest(c, err)
46+
return
47+
}
48+
helper.SuccessWithData(c, dto.PageResult{
49+
Items: list,
50+
Total: total,
51+
})
52+
}
53+
54+
// @Tags AI
55+
// @Summary Delete Agent
56+
// @Accept json
57+
// @Param request body dto.AgentDeleteReq true "request"
58+
// @Success 200
59+
// @Security ApiKeyAuth
60+
// @Security Timestamp
61+
// @Router /ai/agents/delete [post]
62+
func (b *BaseApi) DeleteAgent(c *gin.Context) {
63+
var req dto.AgentDeleteReq
64+
if err := helper.CheckBindAndValidate(&req, c); err != nil {
65+
return
66+
}
67+
if err := agentService.Delete(req); err != nil {
68+
helper.BadRequest(c, err)
69+
return
70+
}
71+
helper.Success(c)
72+
}
73+
74+
// @Tags AI
75+
// @Summary Get Providers
76+
// @Success 200 {object} []dto.ProviderInfo
77+
// @Security ApiKeyAuth
78+
// @Security Timestamp
79+
// @Router /ai/agents/providers [get]
80+
func (b *BaseApi) GetAgentProviders(c *gin.Context) {
81+
list, err := agentService.GetProviders()
82+
if err != nil {
83+
helper.BadRequest(c, err)
84+
return
85+
}
86+
helper.SuccessWithData(c, list)
87+
}
88+
89+
// @Tags AI
90+
// @Summary Create Agent account
91+
// @Accept json
92+
// @Param request body dto.AgentAccountCreateReq true "request"
93+
// @Success 200
94+
// @Security ApiKeyAuth
95+
// @Security Timestamp
96+
// @Router /ai/agents/accounts [post]
97+
func (b *BaseApi) CreateAgentAccount(c *gin.Context) {
98+
var req dto.AgentAccountCreateReq
99+
if err := helper.CheckBindAndValidate(&req, c); err != nil {
100+
return
101+
}
102+
if err := agentService.CreateAccount(req); err != nil {
103+
helper.BadRequest(c, err)
104+
return
105+
}
106+
helper.Success(c)
107+
}
108+
109+
// @Tags AI
110+
// @Summary Update Agent account
111+
// @Accept json
112+
// @Param request body dto.AgentAccountUpdateReq true "request"
113+
// @Success 200
114+
// @Security ApiKeyAuth
115+
// @Security Timestamp
116+
// @Router /ai/agents/accounts/update [post]
117+
func (b *BaseApi) UpdateAgentAccount(c *gin.Context) {
118+
var req dto.AgentAccountUpdateReq
119+
if err := helper.CheckBindAndValidate(&req, c); err != nil {
120+
return
121+
}
122+
if err := agentService.UpdateAccount(req); err != nil {
123+
helper.BadRequest(c, err)
124+
return
125+
}
126+
helper.Success(c)
127+
}
128+
129+
// @Tags AI
130+
// @Summary Page Agent accounts
131+
// @Accept json
132+
// @Param request body dto.AgentAccountSearch true "request"
133+
// @Success 200 {object} dto.PageResult
134+
// @Security ApiKeyAuth
135+
// @Security Timestamp
136+
// @Router /ai/agents/accounts/search [post]
137+
func (b *BaseApi) PageAgentAccounts(c *gin.Context) {
138+
var req dto.AgentAccountSearch
139+
if err := helper.CheckBindAndValidate(&req, c); err != nil {
140+
return
141+
}
142+
total, list, err := agentService.PageAccounts(req)
143+
if err != nil {
144+
helper.BadRequest(c, err)
145+
return
146+
}
147+
helper.SuccessWithData(c, dto.PageResult{
148+
Items: list,
149+
Total: total,
150+
})
151+
}
152+
153+
// @Tags AI
154+
// @Summary Verify Agent account
155+
// @Accept json
156+
// @Param request body dto.AgentAccountVerifyReq true "request"
157+
// @Success 200
158+
// @Security ApiKeyAuth
159+
// @Security Timestamp
160+
// @Router /ai/agents/accounts/verify [post]
161+
func (b *BaseApi) VerifyAgentAccount(c *gin.Context) {
162+
var req dto.AgentAccountVerifyReq
163+
if err := helper.CheckBindAndValidate(&req, c); err != nil {
164+
return
165+
}
166+
if err := agentService.VerifyAccount(req); err != nil {
167+
helper.BadRequest(c, err)
168+
return
169+
}
170+
helper.Success(c)
171+
}
172+
173+
// @Tags AI
174+
// @Summary Delete Agent account
175+
// @Accept json
176+
// @Param request body dto.AgentAccountDeleteReq true "request"
177+
// @Success 200
178+
// @Security ApiKeyAuth
179+
// @Security Timestamp
180+
// @Router /ai/agents/accounts/delete [post]
181+
func (b *BaseApi) DeleteAgentAccount(c *gin.Context) {
182+
var req dto.AgentAccountDeleteReq
183+
if err := helper.CheckBindAndValidate(&req, c); err != nil {
184+
return
185+
}
186+
if err := agentService.DeleteAccount(req); err != nil {
187+
helper.BadRequest(c, err)
188+
return
189+
}
190+
helper.Success(c)
191+
}

agent/app/api/v2/app.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func (b *BaseApi) InstallApp(c *gin.Context) {
164164
if err := helper.CheckBindAndValidate(&req, c); err != nil {
165165
return
166166
}
167-
install, err := appService.Install(req)
167+
install, err := appService.Install(req, true)
168168
if err != nil {
169169
helper.InternalServer(c, err)
170170
return

agent/app/api/v2/entry.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ var (
2020
aiToolService = service.NewIAIToolService()
2121
mcpServerService = service.NewIMcpServerService()
2222
tensorrtLLMService = service.NewITensorRTLLMService()
23+
agentService = service.NewIAgentService()
2324

2425
containerService = service.NewIContainerService()
2526
composeTemplateService = service.NewIComposeTemplateService()

agent/app/dto/agents.go

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
package dto
2+
3+
import "time"
4+
5+
type AgentCreateReq struct {
6+
Name string `json:"name" validate:"required"`
7+
AppVersion string `json:"appVersion" validate:"required"`
8+
WebUIPort int `json:"webUIPort" validate:"required"`
9+
BridgePort int `json:"bridgePort" validate:"required"`
10+
Provider string `json:"provider" validate:"required"`
11+
Model string `json:"model" validate:"required"`
12+
AccountID uint `json:"accountId"`
13+
APIKey string `json:"apiKey"`
14+
BaseURL string `json:"baseURL"`
15+
Token string `json:"token"`
16+
TaskID string `json:"taskID"`
17+
Advanced bool `json:"advanced"`
18+
ContainerName string `json:"containerName"`
19+
AllowPort bool `json:"allowPort"`
20+
SpecifyIP string `json:"specifyIP"`
21+
RestartPolicy string `json:"restartPolicy"`
22+
CpuQuota float64 `json:"cpuQuota"`
23+
MemoryLimit float64 `json:"memoryLimit"`
24+
MemoryUnit string `json:"memoryUnit"`
25+
PullImage bool `json:"pullImage"`
26+
EditCompose bool `json:"editCompose"`
27+
DockerCompose string `json:"dockerCompose"`
28+
}
29+
30+
type AgentItem struct {
31+
ID uint `json:"id"`
32+
Name string `json:"name"`
33+
Provider string `json:"provider"`
34+
Model string `json:"model"`
35+
BaseURL string `json:"baseUrl"`
36+
APIKey string `json:"apiKey"`
37+
Token string `json:"token"`
38+
Status string `json:"status"`
39+
Message string `json:"message"`
40+
AppInstallID uint `json:"appInstallId"`
41+
AppVersion string `json:"appVersion"`
42+
Container string `json:"containerName"`
43+
WebUIPort int `json:"webUIPort"`
44+
BridgePort int `json:"bridgePort"`
45+
Path string `json:"path"`
46+
ConfigPath string `json:"configPath"`
47+
CreatedAt time.Time `json:"createdAt"`
48+
}
49+
50+
type AgentDeleteReq struct {
51+
ID uint `json:"id" validate:"required"`
52+
TaskID string `json:"taskID"`
53+
ForceDelete bool `json:"forceDelete"`
54+
}
55+
56+
type AgentAccountCreateReq struct {
57+
Provider string `json:"provider" validate:"required"`
58+
Name string `json:"name" validate:"required"`
59+
APIKey string `json:"apiKey" validate:"required"`
60+
BaseURL string `json:"baseURL"`
61+
Remark string `json:"remark"`
62+
}
63+
64+
type AgentAccountUpdateReq struct {
65+
ID uint `json:"id" validate:"required"`
66+
Name string `json:"name" validate:"required"`
67+
APIKey string `json:"apiKey" validate:"required"`
68+
BaseURL string `json:"baseURL"`
69+
Remark string `json:"remark"`
70+
SyncAgents bool `json:"syncAgents"`
71+
}
72+
73+
type AgentAccountVerifyReq struct {
74+
Provider string `json:"provider" validate:"required"`
75+
APIKey string `json:"apiKey" validate:"required"`
76+
BaseURL string `json:"baseURL"`
77+
}
78+
79+
type AgentAccountDeleteReq struct {
80+
ID uint `json:"id" validate:"required"`
81+
}
82+
83+
type AgentAccountSearch struct {
84+
PageInfo
85+
Provider string `json:"provider"`
86+
Name string `json:"name"`
87+
}
88+
89+
type AgentAccountInfo struct {
90+
ID uint `json:"id"`
91+
Provider string `json:"provider"`
92+
Name string `json:"name"`
93+
APIKey string `json:"apiKey"`
94+
BaseURL string `json:"baseUrl"`
95+
Verified bool `json:"verified"`
96+
Remark string `json:"remark"`
97+
CreatedAt time.Time `json:"createdAt"`
98+
}
99+
100+
type ProviderModelInfo struct {
101+
ID string `json:"id"`
102+
Name string `json:"name"`
103+
}
104+
105+
type ProviderInfo struct {
106+
Provider string `json:"provider"`
107+
BaseURL string `json:"baseUrl"`
108+
Models []ProviderModelInfo `json:"models"`
109+
}

agent/app/model/agent.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package model
2+
3+
type Agent struct {
4+
BaseModel
5+
Name string `json:"name" gorm:"not null;unique"`
6+
Provider string `json:"provider"`
7+
Model string `json:"model"`
8+
BaseURL string `json:"baseUrl"`
9+
APIKey string `json:"apiKey"`
10+
Token string `json:"token"`
11+
Status string `json:"status"`
12+
Message string `json:"message"`
13+
AppInstallID uint `json:"appInstallId"`
14+
AccountID uint `json:"accountId"`
15+
ConfigPath string `json:"configPath"`
16+
}

agent/app/model/agent_account.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package model
2+
3+
type AgentAccount struct {
4+
BaseModel
5+
Provider string `json:"provider"`
6+
Name string `json:"name"`
7+
APIKey string `json:"apiKey"`
8+
BaseURL string `json:"baseUrl"`
9+
Verified bool `json:"verified"`
10+
Remark string `json:"remark"`
11+
}
12+
13+
func (AgentAccount) TableName() string {
14+
return "agent_provider_accounts"
15+
}

0 commit comments

Comments
 (0)