(req dto.AgentAccountCreateReq)
| 1007 | } |
| 1008 | |
| 1009 | func (a AgentService) CreateAccount(req dto.AgentAccountCreateReq) error { |
| 1010 | provider := req.Provider |
| 1011 | if exist, _ := agentAccountRepo.GetFirst(repo.WithByProvider(provider), repo.WithByName(req.Name)); exist != nil && exist.ID > 0 { |
| 1012 | return buserr.New("ErrRecordExist") |
| 1013 | } |
| 1014 | resolvedInput, err := resolveAgentAccountInput(provider, req.APIKey, req.BaseURL) |
| 1015 | if err != nil { |
| 1016 | return err |
| 1017 | } |
| 1018 | account := &model.AgentAccount{ |
| 1019 | Provider: resolvedInput.Provider, |
| 1020 | Name: req.Name, |
| 1021 | APIKey: resolvedInput.APIKey, |
| 1022 | RememberAPIKey: req.RememberAPIKey, |
| 1023 | BaseURL: resolvedInput.BaseURL, |
| 1024 | APIType: req.APIType, |
| 1025 | Verified: true, |
| 1026 | Remark: req.Remark, |
| 1027 | } |
| 1028 | initialModels, err := buildInitialAgentAccountModels(account, req.Models) |
| 1029 | if err != nil { |
| 1030 | return err |
| 1031 | } |
| 1032 | if err := global.DB.Transaction(func(tx *gorm.DB) error { |
| 1033 | if err := tx.Create(account).Error; err != nil { |
| 1034 | return err |
| 1035 | } |
| 1036 | if len(initialModels) == 0 { |
| 1037 | return nil |
| 1038 | } |
| 1039 | return replacePersistedAgentAccountModelsWithTx(tx, account.ID, initialModels) |
| 1040 | }); err != nil { |
| 1041 | return err |
| 1042 | } |
| 1043 | asyncReportAIProviderInstall(provider) |
| 1044 | return nil |
| 1045 | } |
| 1046 | |
| 1047 | func (a AgentService) UpdateAccount(req dto.AgentAccountUpdateReq) error { |
| 1048 | account, err := agentAccountRepo.GetFirst(repo.WithByID(req.ID)) |
nothing calls this directly
no test coverage detected