(rw http.ResponseWriter, r *http.Request)
| 6737 | } |
| 6738 | |
| 6739 | func (api *API) listChatModelConfigs(rw http.ResponseWriter, r *http.Request) { |
| 6740 | ctx := r.Context() |
| 6741 | |
| 6742 | // Admin users can see all model configs (including disabled ones) |
| 6743 | // for management purposes. Non-admin users see only enabled |
| 6744 | // configs, which is sufficient for using the chat feature. |
| 6745 | isAdmin := api.Authorize(r, policy.ActionRead, rbac.ResourceDeploymentConfig) |
| 6746 | |
| 6747 | var configs []database.ChatModelConfig |
| 6748 | var err error |
| 6749 | if isAdmin { |
| 6750 | configs, err = api.Database.GetChatModelConfigs(ctx) |
| 6751 | } else { |
| 6752 | //nolint:gocritic // All authenticated users need to read enabled model configs to use the chat feature. |
| 6753 | configs, err = api.Database.GetEnabledChatModelConfigs(dbauthz.AsChatd(ctx)) |
| 6754 | } |
| 6755 | if err != nil { |
| 6756 | httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ |
| 6757 | Message: "Failed to list chat model configs.", |
| 6758 | Detail: err.Error(), |
| 6759 | }) |
| 6760 | return |
| 6761 | } |
| 6762 | |
| 6763 | resp := make([]codersdk.ChatModelConfig, 0, len(configs)) |
| 6764 | for _, config := range configs { |
| 6765 | resp = append(resp, convertChatModelConfig(config)) |
| 6766 | } |
| 6767 | |
| 6768 | httpapi.Write(ctx, rw, http.StatusOK, resp) |
| 6769 | } |
| 6770 | |
| 6771 | type chatModelConfigProviderModelError struct { |
| 6772 | Response codersdk.Response |
nothing calls this directly
no test coverage detected