Function: eca-chat-content-received

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

Signature

(eca-chat-content-received SESSION PARAMS)

Documentation

Handle the content received notification with PARAMS for SESSION.

Source Code

;; Defined in /nix/store/jklqzw6pzz6j4jrbv8wy0iwgi7jlrbld-emacs-packages-deps/share/emacs/site-lisp/elpa/eca-20260928.1827/eca-chat.el
(defun eca-chat-content-received (session params)
  "Handle the content received notification with PARAMS for SESSION."
  (with-demoted-errors "eca-chat-content-received-functions: %S"
    (run-hook-with-args 'eca-chat-content-received-functions session params))
  (let* ((chat-id (plist-get params :chatId))
         (parent-chat-id (plist-get params :parentChatId))
         (role (plist-get params :role))
         (content (plist-get params :content))
         (roots (eca--session-workspace-folders session)))
    (if parent-chat-id
        ;; Subagent content → route to parent chat buffer, nested under tool call
        (when-let* ((parent-buffer (eca-get (eca--session-chats session) parent-chat-id))
                    ((buffer-live-p parent-buffer)))
          (eca-chat--with-current-buffer parent-buffer
            (when-let* ((tool-call-id (gethash chat-id eca-chat--subagent-chat-id->tool-call-id)))
              ;; Preserve the user's point: streaming must not move the cursor.
              (eca-chat--with-point-preserved
                (eca-chat--render-content session parent-buffer role content roots tool-call-id chat-id)
                (eca-chat--protect-non-prompt eca-chat--last-user-message-pos)
                (eca-chat--maybe-notify-status-changed session content)
                (eca-chat--maybe-revert-changed-file content)
                (eca-chat--maybe-run-tool-call-functions session content)))))
      ;; Normal content
      (when-let* ((chat-buffer (eca-chat--get-chat-buffer session chat-id))
                  ((buffer-live-p chat-buffer)))
        (eca-chat--with-current-buffer chat-buffer
          ;; Preserve the user's point: streaming must not move the cursor.
          (eca-chat--with-point-preserved
            (eca-chat--render-content session chat-buffer role content roots)
            (eca-chat--protect-non-prompt eca-chat--last-user-message-pos)
            (eca-chat--maybe-notify-status-changed session content)
            (eca-chat--maybe-revert-changed-file content)
            (eca-chat--maybe-run-tool-call-functions session content)))))))