MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / buildInitialAgentAccountModels

Function buildInitialAgentAccountModels

agent/app/service/agents_utils.go:1118–1151  ·  view source on GitHub ↗
(account *model.AgentAccount, requested []dto.AgentAccountModel)

Source from the content-addressed store, hash-verified

1116}
1117
1118func buildInitialAgentAccountModels(account *model.AgentAccount, requested []dto.AgentAccountModel) ([]dto.AgentAccountModel, error) {
1119 if account == nil {
1120 return nil, fmt.Errorf("account is required")
1121 }
1122 if requiresInitialAgentAccountModels(account.Provider) && len(requested) > 1 {
1123 return nil, buserr.New("ErrAgentAccountSingleInitialModel")
1124 }
1125 if len(requested) > 0 {
1126 models := make([]dto.AgentAccountModel, 0, len(requested))
1127 for _, item := range requested {
1128 models = append(models, cloneAgentAccountModel(item))
1129 }
1130 return models, nil
1131 }
1132 meta, ok := providercatalog.Get(account.Provider)
1133 if !ok || len(meta.Models) == 0 {
1134 if requiresInitialAgentAccountModels(account.Provider) {
1135 return nil, buserr.New("ErrAgentAccountModelsRequired")
1136 }
1137 return nil, nil
1138 }
1139 requested = make([]dto.AgentAccountModel, 0, len(meta.Models))
1140 for _, item := range meta.Models {
1141 requested = append(requested, dto.AgentAccountModel{
1142 ID: item.ID,
1143 Name: item.Name,
1144 ContextWindow: item.ContextWindow,
1145 MaxTokens: item.MaxTokens,
1146 Reasoning: item.Reasoning,
1147 Input: append([]string(nil), item.Input...),
1148 })
1149 }
1150 return requested, nil
1151}
1152
1153func compactPersistedAgentAccountModelSortOrder(accountID uint) error {
1154 rows, err := agentAccountModelRepo.List(repo.WithByAccountID(accountID), repo.WithOrderAsc("sort_order"), repo.WithOrderAsc("id"))

Callers 2

CreateAccountMethod · 0.85

Calls 3

cloneAgentAccountModelFunction · 0.85
GetMethod · 0.65

Tested by

no test coverage detected