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

Method getChatUserPrompts

coderd/exp_chats.go:2190–2242  ·  view source on GitHub ↗

@Summary List chat user prompts @ID list-chat-user-prompts @Security CoderSessionToken @Tags Chats @Produce json @Param chat path string true "Chat ID" format(uuid) @Param limit query int false "Page size, 0 to 2000. 0 (the default) means the server-side default of 500." @Success 200 {object} coders

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

Source from the content-addressed store, hash-verified

2188//
2189//nolint:revive // HTTP handler writes to ResponseWriter.
2190func (api *API) getChatUserPrompts(rw http.ResponseWriter, r *http.Request) {
2191 ctx := r.Context()
2192 chat := httpmw.ChatParam(r)
2193 chatID := chat.ID
2194
2195 queryParams := r.URL.Query()
2196 parser := httpapi.NewQueryParamParser()
2197 // Default 0 sentinel; the SQL query treats 0 as "use the built-in
2198 // default of 500" via COALESCE(NULLIF(@limit_val, 0), 500). The
2199 // SDK guards opts.Limit > 0 so callers using the typed client only
2200 // reach here with an explicit value; raw HTTP callers can omit the
2201 // parameter (or pass 0) to opt into the default.
2202 limit := parser.PositiveInt32(queryParams, 0, "limit")
2203 if len(parser.Errors) > 0 {
2204 httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
2205 Message: "Query parameters have invalid values.",
2206 Validations: parser.Errors,
2207 })
2208 return
2209 }
2210 // PositiveInt32 already rejects negatives via parser.Errors above,
2211 // so we only need to cap the upper bound here.
2212 if limit > 2000 {
2213 httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
2214 Message: "Invalid limit parameter (0-2000).",
2215 })
2216 return
2217 }
2218
2219 rows, err := api.Database.GetChatUserPromptsByChatID(ctx, database.GetChatUserPromptsByChatIDParams{
2220 ChatID: chatID,
2221 LimitVal: limit,
2222 })
2223 if err != nil {
2224 httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
2225 Message: "Failed to get chat user prompts.",
2226 Detail: err.Error(),
2227 })
2228 return
2229 }
2230
2231 prompts := make([]codersdk.ChatPrompt, 0, len(rows))
2232 for _, row := range rows {
2233 prompts = append(prompts, codersdk.ChatPrompt{
2234 ID: row.ID,
2235 Text: row.Text,
2236 })
2237 }
2238
2239 httpapi.Write(ctx, rw, http.StatusOK, codersdk.ChatPromptsResponse{
2240 Prompts: prompts,
2241 })
2242}
2243
2244// authorizeChatWorkspaceExec enforces the workspace-level permissions
2245// shared by the chat stream endpoints that proxy a live websocket into

Callers

nothing calls this directly

Calls 7

PositiveInt32Method · 0.95
ChatParamFunction · 0.92
NewQueryParamParserFunction · 0.92
WriteFunction · 0.92
ContextMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected