|
| 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 | +} |
0 commit comments