(req dto.AgentCreateReq)
| 134 | ) |
| 135 | |
| 136 | func (a AgentService) Create(req dto.AgentCreateReq) (*dto.AgentItem, error) { |
| 137 | agentType := req.AgentType |
| 138 | if err := checkPortExist(req.WebUIPort); err != nil { |
| 139 | return nil, err |
| 140 | } |
| 141 | if exist, _ := agentRepo.GetFirst(repo.WithByLowerName(req.Name)); exist != nil && exist.ID > 0 { |
| 142 | return nil, buserr.New("ErrNameIsExist") |
| 143 | } |
| 144 | if installs, _ := appInstallRepo.ListBy(context.Background(), repo.WithByLowerName(req.Name)); len(installs) > 0 { |
| 145 | return nil, buserr.New("ErrNameIsExist") |
| 146 | } |
| 147 | if !xpack.MultiNodeProvider.IsXpack() { |
| 148 | count, _, err := agentRepo.Page(1, 1) |
| 149 | if err != nil { |
| 150 | return nil, err |
| 151 | } |
| 152 | if count >= maxCommunityAIAgents { |
| 153 | return nil, buserr.WithMap("ErrAgentLimitReached", map[string]interface{}{"max": maxCommunityAIAgents}, nil) |
| 154 | } |
| 155 | } |
| 156 | app, err := appRepo.GetFirst(appRepo.WithKey(agentType)) |
| 157 | if err != nil || app.ID == 0 { |
| 158 | return nil, buserr.New("ErrRecordNotFound") |
| 159 | } |
| 160 | detail, err := appDetailRepo.GetFirst(appDetailRepo.WithAppId(app.ID), appDetailRepo.WithVersion(req.AppVersion)) |
| 161 | if err != nil || detail.ID == 0 { |
| 162 | return nil, buserr.New("ErrRecordNotFound") |
| 163 | } |
| 164 | |
| 165 | provider := "" |
| 166 | baseURL := "" |
| 167 | apiType := "" |
| 168 | maxTokens := 0 |
| 169 | contextWindow := 0 |
| 170 | apiKey := "" |
| 171 | runtimeModel := "" |
| 172 | accountID := uint(0) |
| 173 | token := "" |
| 174 | configPath := "" |
| 175 | storedModel := "" |
| 176 | var allowedOrigins []string |
| 177 | var account *model.AgentAccount |
| 178 | var installHooks *appInstallHooks |
| 179 | |
| 180 | if agentType == constant.AppOpenclaw || agentType == constant.AppHermesAgent { |
| 181 | if req.AccountID == 0 { |
| 182 | return nil, buserr.New("ErrAgentAccountRequired") |
| 183 | } |
| 184 | account, err = agentAccountRepo.GetFirst(repo.WithByID(req.AccountID)) |
| 185 | if err != nil { |
| 186 | return nil, err |
| 187 | } |
| 188 | if !account.Verified { |
| 189 | return nil, buserr.New("ErrAgentAccountNotVerified") |
| 190 | } |
| 191 | provider = account.Provider |
| 192 | baseURL = account.BaseURL |
| 193 | resolvedRuntime, err := resolveOpenclawAccountModelRuntimeByID(account, req.Model) |
no test coverage detected