EXPERIMENTAL: this endpoint is experimental and is subject to change.
(rw http.ResponseWriter, r *http.Request)
| 4684 | |
| 4685 | // EXPERIMENTAL: this endpoint is experimental and is subject to change. |
| 4686 | func (api *API) putChatPlanModeInstructions(rw http.ResponseWriter, r *http.Request) { |
| 4687 | ctx := r.Context() |
| 4688 | if !api.Authorize(r, policy.ActionUpdate, rbac.ResourceDeploymentConfig) { |
| 4689 | httpapi.Forbidden(rw) |
| 4690 | return |
| 4691 | } |
| 4692 | |
| 4693 | // Cap the raw request body to prevent excessive memory use from |
| 4694 | // payloads padded with invisible characters that sanitize away. |
| 4695 | r.Body = http.MaxBytesReader(rw, r.Body, int64(2*maxSystemPromptLenBytes)) |
| 4696 | |
| 4697 | var req codersdk.UpdateChatPlanModeInstructionsRequest |
| 4698 | if !httpapi.Read(ctx, rw, r, &req) { |
| 4699 | return |
| 4700 | } |
| 4701 | |
| 4702 | sanitizedInstructions := chatd.SanitizePromptText(req.PlanModeInstructions) |
| 4703 | if len(sanitizedInstructions) > maxSystemPromptLenBytes { |
| 4704 | httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{ |
| 4705 | Message: "Plan mode instructions exceed maximum length.", |
| 4706 | Detail: fmt.Sprintf("Maximum length is %d bytes, got %d.", maxSystemPromptLenBytes, len(sanitizedInstructions)), |
| 4707 | }) |
| 4708 | return |
| 4709 | } |
| 4710 | |
| 4711 | if err := api.Database.UpsertChatPlanModeInstructions(ctx, sanitizedInstructions); err != nil { |
| 4712 | httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ |
| 4713 | Message: "Internal error updating plan mode instructions.", |
| 4714 | Detail: err.Error(), |
| 4715 | }) |
| 4716 | return |
| 4717 | } |
| 4718 | |
| 4719 | rw.WriteHeader(http.StatusNoContent) |
| 4720 | } |
| 4721 | |
| 4722 | func readChatModelOverrideContext( |
| 4723 | rw http.ResponseWriter, |
nothing calls this directly
no test coverage detected