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

Method interruptChat

coderd/exp_chats.go:3593–3627  ·  view source on GitHub ↗

EXPERIMENTAL: this endpoint is experimental and is subject to change. @Summary Interrupt chat @ID interrupt-chat @Security CoderSessionToken @Tags Chats @Param chat path string true "Chat ID" format(uuid) @Produce json @Success 200 {object} codersdk.Chat @Router /api/experimental/chats/{chat}/inter

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

Source from the content-addressed store, hash-verified

3591// @Router /api/experimental/chats/{chat}/interrupt [post]
3592// @Description Experimental: this endpoint is subject to change.
3593func (api *API) interruptChat(rw http.ResponseWriter, r *http.Request) {
3594 ctx := r.Context()
3595 chat := httpmw.ChatParam(r)
3596 chatID := chat.ID
3597 logger := api.Logger.Named("chat_interrupt").With(slog.F("chat_id", chatID))
3598
3599 if !api.Authorize(r, policy.ActionUpdate, chat.RBACObject()) {
3600 httpapi.ResourceNotFound(rw)
3601 return
3602 }
3603
3604 if api.chatDaemon != nil {
3605 chat = api.chatDaemon.InterruptChat(ctx, chat)
3606 } else {
3607 updatedChat, updateErr := api.Database.UpdateChatStatus(ctx, database.UpdateChatStatusParams{
3608 ID: chatID,
3609 Status: database.ChatStatusWaiting,
3610 WorkerID: uuid.NullUUID{},
3611 StartedAt: sql.NullTime{},
3612 HeartbeatAt: sql.NullTime{},
3613 LastError: pqtype.NullRawMessage{},
3614 })
3615 if updateErr != nil {
3616 logger.Error(ctx, "failed to mark chat as waiting", slog.Error(updateErr))
3617 httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
3618 Message: "Failed to interrupt chat.",
3619 Detail: updateErr.Error(),
3620 })
3621 return
3622 }
3623 chat = updatedChat
3624 }
3625
3626 httpapi.Write(ctx, rw, http.StatusOK, db2sdk.Chat(chat, nil, nil))
3627}
3628
3629// EXPERIMENTAL: this endpoint is experimental and is subject to change.
3630//

Callers 1

interruptChatFunction · 0.80

Calls 11

AuthorizeMethod · 0.95
ChatParamFunction · 0.92
ResourceNotFoundFunction · 0.92
WriteFunction · 0.92
ChatFunction · 0.92
NamedMethod · 0.80
ContextMethod · 0.65
RBACObjectMethod · 0.65
UpdateChatStatusMethod · 0.65
InterruptChatMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected