@@ -43,20 +43,20 @@ func NewIAgentService() IAgentService {
4343func (a AgentService ) Create (req dto.AgentCreateReq ) (* dto.AgentItem , error ) {
4444 provider := strings .ToLower (strings .TrimSpace (req .Provider ))
4545 if ! isSupportedAgentProvider (provider ) {
46- return nil , buserr .WithDetail ( "ErrInvalidParams" , "provider" , nil )
46+ return nil , buserr .New ( "ErrAgentProviderNotSupported" )
4747 }
4848 if req .AccountID == 0 {
49- return nil , buserr .WithDetail ( "ErrInvalidParams" , "accountId" , nil )
49+ return nil , buserr .New ( "ErrAgentAccountRequired" )
5050 }
5151 account , err := agentAccountRepo .GetFirst (repo .WithByID (req .AccountID ))
5252 if err != nil {
5353 return nil , err
5454 }
5555 if ! account .Verified {
56- return nil , buserr .WithDetail ( "ErrInvalidParams" , "account" , nil )
56+ return nil , buserr .New ( "ErrAgentAccountNotVerified" )
5757 }
5858 if account .Provider != "" && provider != "" && account .Provider != provider {
59- return nil , buserr .WithDetail ( "ErrInvalidParams" , "provider" , nil )
59+ return nil , buserr .New ( "ErrAgentProviderMismatch" )
6060 }
6161 provider = strings .ToLower (strings .TrimSpace (account .Provider ))
6262 baseURL := strings .TrimSpace (account .BaseURL )
@@ -66,10 +66,10 @@ func (a AgentService) Create(req dto.AgentCreateReq) (*dto.AgentItem, error) {
6666 }
6767 }
6868 if provider == "ollama" && baseURL == "" {
69- return nil , buserr .WithDetail ( "ErrInvalidParams" , "baseURL" , nil )
69+ return nil , buserr .New ( "ErrAgentBaseURLRequired" )
7070 }
7171 if provider != "ollama" && strings .TrimSpace (account .APIKey ) == "" {
72- return nil , buserr .WithDetail ( "ErrInvalidParams" , "apiKey" , nil )
72+ return nil , buserr .New ( "ErrAgentApiKeyRequired" )
7373 }
7474 if err := checkPortExist (req .WebUIPort ); err != nil {
7575 return nil , err
@@ -110,7 +110,7 @@ func (a AgentService) Create(req dto.AgentCreateReq) (*dto.AgentItem, error) {
110110 }
111111
112112 if req .EditCompose && strings .TrimSpace (req .DockerCompose ) == "" {
113- return nil , buserr .WithDetail ( "ErrInvalidParams" , "dockerCompose" , nil )
113+ return nil , buserr .New ( "ErrAgentComposeRequired" )
114114 }
115115 installReq := request.AppInstallCreate {
116116 AppDetailId : detail .ID ,
@@ -178,7 +178,7 @@ func (a AgentService) Page(req dto.SearchWithPage) (int64, []dto.AgentItem, erro
178178
179179func (a AgentService ) Delete (req dto.AgentDeleteReq ) error {
180180 if req .ID == 0 {
181- return buserr .WithDetail ( "ErrInvalidParams" , "id" , nil )
181+ return buserr .New ( "ErrAgentIDRequired" )
182182 }
183183 agent , err := agentRepo .GetFirst (repo .WithByID (req .ID ))
184184 if err != nil {
@@ -216,11 +216,11 @@ func (a AgentService) GetProviders() ([]dto.ProviderInfo, error) {
216216func (a AgentService ) CreateAccount (req dto.AgentAccountCreateReq ) error {
217217 provider := strings .ToLower (strings .TrimSpace (req .Provider ))
218218 if ! isSupportedAgentProvider (provider ) {
219- return buserr .WithDetail ( "ErrInvalidParams" , "provider" , nil )
219+ return buserr .New ( "ErrAgentProviderNotSupported" )
220220 }
221221 apiKey := strings .TrimSpace (req .APIKey )
222222 if apiKey == "" {
223- return buserr .WithDetail ( "ErrInvalidParams" , "apiKey" , nil )
223+ return buserr .New ( "ErrAgentApiKeyRequired" )
224224 }
225225 baseURL := strings .TrimSpace (req .BaseURL )
226226 if provider != "ollama" {
@@ -229,7 +229,7 @@ func (a AgentService) CreateAccount(req dto.AgentAccountCreateReq) error {
229229 }
230230 }
231231 if provider == "ollama" && baseURL == "" {
232- return buserr .WithDetail ( "ErrInvalidParams" , "baseURL" , nil )
232+ return buserr .New ( "ErrAgentBaseURLRequired" )
233233 }
234234 if exist , _ := agentAccountRepo .GetFirst (repo .WithByProvider (provider ), repo .WithByName (req .Name )); exist != nil && exist .ID > 0 {
235235 return buserr .New ("ErrRecordExist" )
@@ -261,7 +261,7 @@ func (a AgentService) UpdateAccount(req dto.AgentAccountUpdateReq) error {
261261 }
262262 }
263263 if provider == "ollama" && baseURL == "" {
264- return buserr .WithDetail ( "ErrInvalidParams" , "baseURL" , nil )
264+ return buserr .New ( "ErrAgentBaseURLRequired" )
265265 }
266266 if err := a .VerifyAccount (dto.AgentAccountVerifyReq {Provider : provider , BaseURL : baseURL , APIKey : req .APIKey }); err != nil {
267267 return err
@@ -313,11 +313,11 @@ func (a AgentService) PageAccounts(req dto.AgentAccountSearch) (int64, []dto.Age
313313func (a AgentService ) VerifyAccount (req dto.AgentAccountVerifyReq ) error {
314314 provider := strings .ToLower (strings .TrimSpace (req .Provider ))
315315 if ! isSupportedAgentProvider (provider ) {
316- return buserr .WithDetail ( "ErrInvalidParams" , "provider" , nil )
316+ return buserr .New ( "ErrAgentProviderNotSupported" )
317317 }
318318 apiKey := strings .TrimSpace (req .APIKey )
319319 if apiKey == "" {
320- return buserr .WithDetail ( "ErrInvalidParams" , "apiKey" , nil )
320+ return buserr .New ( "ErrAgentApiKeyRequired" )
321321 }
322322 baseURL := strings .TrimSpace (req .BaseURL )
323323 if baseURL == "" {
@@ -326,7 +326,7 @@ func (a AgentService) VerifyAccount(req dto.AgentAccountVerifyReq) error {
326326 }
327327 }
328328 if provider == "ollama" && baseURL == "" {
329- return buserr .WithDetail ( "ErrInvalidParams" , "baseURL" , nil )
329+ return buserr .New ( "ErrAgentBaseURLRequired" )
330330 }
331331 if provider == "ollama" {
332332 return nil
@@ -336,10 +336,10 @@ func (a AgentService) VerifyAccount(req dto.AgentAccountVerifyReq) error {
336336
337337func (a AgentService ) DeleteAccount (req dto.AgentAccountDeleteReq ) error {
338338 if req .ID == 0 {
339- return buserr .WithDetail ( "ErrInvalidParams" , "id" , nil )
339+ return buserr .New ( "ErrAgentAccountIDRequired" )
340340 }
341341 if exists , _ := agentRepo .GetFirst (repo .WithByAccountID (req .ID )); exists != nil && exists .ID > 0 {
342- return buserr .New ("ErrRecordExist " )
342+ return buserr .New ("ErrAgentAccountBound " )
343343 }
344344 return agentAccountRepo .DeleteByID (req .ID )
345345}
@@ -391,11 +391,11 @@ func verifyProvider(provider, baseURL, apiKey string) error {
391391 }
392392 resp , err := client .Do (request )
393393 if err != nil {
394- return err
394+ return buserr . WithErr ( "ErrAgentAccountUnavailable" , err )
395395 }
396396 defer resp .Body .Close ()
397397 if resp .StatusCode >= 400 {
398- return buserr .WithDetail ( "ErrInvalidParams " , fmt .Sprintf ("verify failed: %d " , resp .StatusCode ), nil )
398+ return buserr .WithErr ( "ErrAgentAccountUnavailable " , fmt .Errorf ("verify failed: %s " , resp .Status ) )
399399 }
400400 return nil
401401}
0 commit comments