resolveUserCompactionThreshold looks up the user's per-model compaction threshold override. Returns the override value and true if one exists and is valid, or 0 and false otherwise.
(ctx context.Context, userID uuid.UUID, modelConfigID uuid.UUID)
| 9155 | // compaction threshold override. Returns the override value and |
| 9156 | // true if one exists and is valid, or 0 and false otherwise. |
| 9157 | func (p *Server) resolveUserCompactionThreshold(ctx context.Context, userID uuid.UUID, modelConfigID uuid.UUID) (int32, bool) { |
| 9158 | raw, err := p.db.GetUserChatCompactionThreshold(ctx, database.GetUserChatCompactionThresholdParams{ |
| 9159 | UserID: userID, |
| 9160 | Key: codersdk.CompactionThresholdKey(modelConfigID), |
| 9161 | }) |
| 9162 | if errors.Is(err, sql.ErrNoRows) { |
| 9163 | return 0, false |
| 9164 | } |
| 9165 | if err != nil { |
| 9166 | p.logger.Warn(ctx, "failed to fetch compaction threshold override", |
| 9167 | slog.F("user_id", userID), |
| 9168 | slog.F("model_config_id", modelConfigID), |
| 9169 | slog.Error(err), |
| 9170 | ) |
| 9171 | return 0, false |
| 9172 | } |
| 9173 | // Range 0..100 must stay in sync with handler validation in |
| 9174 | // coderd/chats.go. |
| 9175 | val, err := strconv.ParseInt(raw, 10, 32) |
| 9176 | if err != nil || val < 0 || val > 100 { |
| 9177 | return 0, false |
| 9178 | } |
| 9179 | return int32(val), true |
| 9180 | } |
| 9181 | |
| 9182 | // resolveDeploymentSystemPrompt builds the deployment-level system |
| 9183 | // prompt from the built-in default and the admin-configured custom |