Function: eca-chat--rollback

eca-chat--rollback is a natively compiled function defined in eca-chat.el.

Signature

(eca-chat--rollback SESSION CONTENT-ID &optional TEXT)

Documentation

Rollback chat messages for SESSION to before CONTENT-ID.

TEXT is the rolled-back user message text; when the rollback removes messages, it is restored into the prompt field with any current draft appended, after the server clears the chat.

Source Code

;; Defined in /nix/store/jklqzw6pzz6j4jrbv8wy0iwgi7jlrbld-emacs-packages-deps/share/emacs/site-lisp/elpa/eca-20260928.1827/eca-chat.el
(defun eca-chat--rollback (session content-id &optional text)
  "Rollback chat messages for SESSION to before CONTENT-ID.
TEXT is the rolled-back user message text; when the rollback
removes messages, it is restored into the prompt field with any
current draft appended, after the server clears the chat."
  (unless eca-chat--chat-loading
    (eca-chat--stream-flush)
    (let ((rollback-messages-and-tools-str "1. Rollback messages and changes done by tool calls")
          (rollback-messages-str "2. Rollback only messages")
          (rollback-tools-str "3. Rollback only changes done by tool calls"))
      (when-let* ((rollback-type (completing-read "Select the rollback type:"
                                                  (lambda (s pred action)
                                                    (if (eq 'metadata action)
                                                        `(metadata (display-sort-function . ,#'identity))
                                                      (complete-with-action action
                                                                            (list rollback-messages-and-tools-str
                                                                                  rollback-messages-str
                                                                                  rollback-tools-str)
                                                                            s
                                                                            pred))) nil t)))
        (let ((include (cond
                        ((string= rollback-type rollback-messages-str) ["messages"])
                        ((string= rollback-type rollback-tools-str) ["tools"])
                        ((string= rollback-type rollback-messages-and-tools-str) ["messages" "tools"]))))
          (when (member "messages" (append include nil))
            (setq-local eca-chat--prompt-after-clear
                        (eca-chat--rollback-prompt-text text)))
          (unwind-protect
              (eca-api-request-sync session
                                    :method "chat/rollback"
                                    :params (list :chatId eca-chat--id
                                                  :contentId content-id
                                                  :include include))
            ;; `eca-chat-cleared' consumes the stash during the sync
            ;; wait; this reset only drops a leftover on request failure.
            (setq-local eca-chat--prompt-after-clear nil)))))))