Function: eca-rewrite-content-received

eca-rewrite-content-received is a natively compiled function defined in eca-rewrite.el.

Signature

(eca-rewrite-content-received SESSION PARAMS)

Documentation

Handle content update for a rewrite operation from LLM.

SESSION is the ECA session. PARAMS is a plist containing:
  :rewriteId -- the identifier of the rewrite overlay,
  :content -- a plist with at least a :type and optionally :text.

Update the corresponding overlay with content (partial or finished), accepts, shows menu, or diffs according to eca-rewrite-finished-action,
 or prompts user if not set.

Source Code

;; Defined in /nix/store/jklqzw6pzz6j4jrbv8wy0iwgi7jlrbld-emacs-packages-deps/share/emacs/site-lisp/elpa/eca-20260928.1827/eca-rewrite.el
;; Public

(defun eca-rewrite-content-received (_session params)
  "Handle content update for a rewrite operation from LLM.
SESSION is the ECA session.
PARAMS is a plist containing:
  :rewriteId -- the identifier of the rewrite overlay,
  :content   -- a plist with at least a :type and optionally :text.

Update the corresponding overlay with content (partial or finished),
accepts, shows menu, or diffs according to `eca-rewrite-finished-action',
 or prompts user if not set."
  (let* ((id (plist-get params :rewriteId))
         (content (plist-get params :content))
         (buffer (eca-rewrite--get-buffer id)))
    (when (buffer-live-p buffer)
      (with-current-buffer buffer
        (when-let ((ov (eca-rewrite--overlay-from-id id)))
          (pcase (plist-get content :type)
            ("reasoning" (eca-rewrite--refresh-overlay-actions ov 'reasoning))
            ("text" (eca-rewrite--add-text ov (plist-get content :text)))
            ("error" (progn
                       (eca-rewrite--reject (list ov))
                       (eca-error "Rewrite error: %s" (plist-get content :message))))
            ("replace" (progn
                         (overlay-put ov 'eca-rewrite--new-text-acc "")
                         (eca-rewrite--add-text ov (plist-get content :text))))
            ("finished" (progn
                          (overlay-put ov 'eca-rewrite--total-time-ms (plist-get content :totalTimeMs))
                          (pcase eca-rewrite-finished-action
                            ('accept (eca-rewrite--accept ov))
                            ('diff (eca-rewrite--diff ov))
                            ('merge (eca-rewrite--merge ov))
                            ('show-overlay-actions (progn
                                                     (eca-rewrite--refresh-overlay-actions ov 'finished)
                                                     (pulse-momentary-highlight-region (overlay-start ov) (overlay-end ov))
                                                     (kill-buffer (overlay-get ov 'eca-rewrite--temp-buffer))))
                            (_ (user-error (format "Uknown rewrite action '%s' for eca-rewrite-finished-action" eca-rewrite-finished-action))))
                          (with-demoted-errors "eca-rewrite-on-finished-hook: %S"
                            (run-hook-with-args 'eca-rewrite-on-finished-hook ov))))))))))