| 178 | } |
| 179 | |
| 180 | func providerPatchFromDTO(input ProviderInput) appapi.ProviderPatch { |
| 181 | patch := appapi.ProviderPatch{ |
| 182 | Enabled: input.Enabled, |
| 183 | } |
| 184 | if input.Endpoint != "" { |
| 185 | patch.Endpoint = &input.Endpoint |
| 186 | } |
| 187 | if input.APIKey != "" { |
| 188 | patch.APIKey = &input.APIKey |
| 189 | } |
| 190 | if input.APIKeyEnv != "" { |
| 191 | patch.APIKeyEnv = &input.APIKeyEnv |
| 192 | } |
| 193 | if input.SupportedClient != "" { |
| 194 | patch.SupportedClient = &input.SupportedClient |
| 195 | } else if len(input.Clients) > 0 { |
| 196 | patch.Clients = &providers.ListPatch{Op: providers.ListOpReplace, Items: input.Clients} |
| 197 | } |
| 198 | if input.Models != nil { |
| 199 | patch.Models = &providers.ListPatch{Op: providers.ListOpReplace, Items: input.Models} |
| 200 | } |
| 201 | if input.ListModelsCmd != "" { |
| 202 | patch.ListModelsCmd = &input.ListModelsCmd |
| 203 | } |
| 204 | if input.KeepProxyConfig { |
| 205 | patch.KeepProxyConfig = &input.KeepProxyConfig |
| 206 | } |
| 207 | if input.UseProxy { |
| 208 | patch.UseProxy = &input.UseProxy |
| 209 | } |
| 210 | if input.Description != "" { |
| 211 | patch.Description = &input.Description |
| 212 | } |
| 213 | return patch |
| 214 | } |
| 215 | |
| 216 | func wrapProviderError(code string, err error, name string) error { |
| 217 | if err == nil { |