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

Method putChatPlanModeInstructions

coderd/exp_chats.go:4686–4720  ·  view source on GitHub ↗

EXPERIMENTAL: this endpoint is experimental and is subject to change.

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

Source from the content-addressed store, hash-verified

4684
4685// EXPERIMENTAL: this endpoint is experimental and is subject to change.
4686func (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
4722func readChatModelOverrideContext(
4723 rw http.ResponseWriter,

Callers

nothing calls this directly

Calls 9

AuthorizeMethod · 0.95
ForbiddenFunction · 0.92
ReadFunction · 0.92
SanitizePromptTextFunction · 0.92
WriteFunction · 0.92
ContextMethod · 0.65
ErrorMethod · 0.45
WriteHeaderMethod · 0.45

Tested by

no test coverage detected