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

Method regenerateChatTitle

coderd/exp_chats.go:3642–3693  ·  view source on GitHub ↗

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

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

Source from the content-addressed store, hash-verified

3640//
3641//nolint:revive // HTTP handler writes to ResponseWriter.
3642func (api *API) regenerateChatTitle(rw http.ResponseWriter, r *http.Request) {
3643 ctx := r.Context()
3644 apiKey := httpmw.APIKey(r)
3645 chat := httpmw.ChatParam(r)
3646
3647 if !api.Authorize(r, policy.ActionUpdate, chat.RBACObject()) {
3648 httpapi.ResourceNotFound(rw)
3649 return
3650 }
3651
3652 // Only the chat owner may regenerate titles. See
3653 // postChatMessages for the security rationale.
3654 if apiKey.UserID != chat.OwnerID {
3655 httpapi.Write(ctx, rw, http.StatusForbidden, codersdk.Response{
3656 Message: "Only the chat owner may regenerate the title.",
3657 })
3658 return
3659 }
3660
3661 if api.chatDaemon == nil {
3662 httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
3663 Message: "Chat processor is unavailable.",
3664 Detail: "Chat processor is not configured.",
3665 })
3666 return
3667 }
3668
3669 ctx = aibridge.WithDelegatedAPIKeyID(ctx, apiKey.ID)
3670 updatedChat, err := api.chatDaemon.RegenerateChatTitle(ctx, chat)
3671 if err != nil {
3672 if errors.Is(err, chatd.ErrManualTitleRegenerationInProgress) {
3673 httpapi.Write(ctx, rw, http.StatusConflict, codersdk.Response{
3674 Message: "Title regeneration already in progress for this chat.",
3675 })
3676 return
3677 }
3678 if maybeWriteLimitErr(ctx, rw, err) {
3679 return
3680 }
3681 if httpapi.Is404Error(err) {
3682 httpapi.ResourceNotFound(rw)
3683 return
3684 }
3685 httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
3686 Message: "Failed to regenerate chat title.",
3687 Detail: err.Error(),
3688 })
3689 return
3690 }
3691
3692 httpapi.Write(ctx, rw, http.StatusOK, db2sdk.Chat(updatedChat, nil, nil))
3693}
3694
3695//nolint:revive // HTTP handler writes to ResponseWriter.
3696func (api *API) proposeChatTitle(rw http.ResponseWriter, r *http.Request) {

Callers 1

regenerateChatTitleFunction · 0.80

Calls 14

AuthorizeMethod · 0.95
APIKeyFunction · 0.92
ChatParamFunction · 0.92
ResourceNotFoundFunction · 0.92
WriteFunction · 0.92
WithDelegatedAPIKeyIDFunction · 0.92
Is404ErrorFunction · 0.92
ChatFunction · 0.92
maybeWriteLimitErrFunction · 0.85
ContextMethod · 0.65
RBACObjectMethod · 0.65
RegenerateChatTitleMethod · 0.45

Tested by

no test coverage detected