MCPcopy Index your code
hub / github.com/coder/coder / putUserChatCompactionThreshold

Method putUserChatCompactionThreshold

coderd/exp_chats.go:5911–5981  ·  view source on GitHub ↗

@Summary Set user chat compaction threshold for a model config @x-apidocgen {"skip": true} EXPERIMENTAL: this endpoint is experimental and is subject to change.

(rw http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

5909// @x-apidocgen {"skip": true}
5910// EXPERIMENTAL: this endpoint is experimental and is subject to change.
5911func (api *API) putUserChatCompactionThreshold(rw http.ResponseWriter, r *http.Request) {
5912 var (
5913 ctx = r.Context()
5914 apiKey = httpmw.APIKey(r)
5915 )
5916
5917 modelConfigID, ok := parseChatModelConfigID(rw, r)
5918 if !ok {
5919 return
5920 }
5921
5922 var req codersdk.UpdateUserChatCompactionThresholdRequest
5923 if !httpapi.Read(ctx, rw, r, &req) {
5924 return
5925 }
5926 if req.ThresholdPercent < minChatContextCompressionThreshold ||
5927 req.ThresholdPercent > maxChatContextCompressionThreshold {
5928 httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
5929 Message: "threshold_percent is out of range.",
5930 Detail: fmt.Sprintf(
5931 "threshold_percent must be between %d and %d, got %d.",
5932 minChatContextCompressionThreshold,
5933 maxChatContextCompressionThreshold,
5934 req.ThresholdPercent,
5935 ),
5936 })
5937 return
5938 }
5939
5940 // Use system context because GetChatModelConfigByID requires
5941 // deployment-config read access, which non-admin users lack.
5942 // The user is only checking if the model exists and is enabled
5943 // before writing their own personal preference.
5944 //nolint:gocritic // Non-admin users need this lookup to save their own setting.
5945 modelConfig, err := api.Database.GetChatModelConfigByID(dbauthz.AsSystemRestricted(ctx), modelConfigID)
5946 if err != nil {
5947 if errors.Is(err, sql.ErrNoRows) || httpapi.Is404Error(err) {
5948 httpapi.ResourceNotFound(rw)
5949 return
5950 }
5951 httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
5952 Message: "Failed to get chat model config.",
5953 Detail: err.Error(),
5954 })
5955 return
5956 }
5957 if !modelConfig.Enabled {
5958 httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
5959 Message: "Model config is disabled.",
5960 })
5961 return
5962 }
5963
5964 _, err = api.Database.UpdateUserChatCompactionThreshold(ctx, database.UpdateUserChatCompactionThresholdParams{
5965 UserID: apiKey.UserID,
5966 Key: codersdk.CompactionThresholdKey(modelConfigID),
5967 ThresholdPercent: req.ThresholdPercent,
5968 })

Callers

nothing calls this directly

Calls 13

APIKeyFunction · 0.92
ReadFunction · 0.92
WriteFunction · 0.92
AsSystemRestrictedFunction · 0.92
Is404ErrorFunction · 0.92
ResourceNotFoundFunction · 0.92
CompactionThresholdKeyFunction · 0.92
parseChatModelConfigIDFunction · 0.85
ContextMethod · 0.65
IsMethod · 0.45

Tested by

no test coverage detected