Function: eca-chat-opened
eca-chat-opened is a natively compiled function defined in
eca-chat.el.
Signature
(eca-chat-opened SESSION PARAMS)
Documentation
Handle chat/opened notification for SESSION with PARAMS.
Idempotent: if the chat-id is already known on the client side
(e.g. a client-initiated chat where the client minted the id and
the server is just announcing the new chat to other observers),
update the title and return without creating a duplicate buffer.
Otherwise, creates a new chat buffer for a server-initiated chat
(e.g. /fork or replay via chat/open) and registers it under the
real chat-id so subsequent chat/contentReceived notifications
render into it.
A registered buffer marked eca-chat--closed (left behind by
eca-chat-exit on restart) is treated as stale, not reused, so a
resumed chat gets a fresh writable buffer.
Source Code
;; Defined in /nix/store/jklqzw6pzz6j4jrbv8wy0iwgi7jlrbld-emacs-packages-deps/share/emacs/site-lisp/elpa/eca-20260928.1827/eca-chat.el
(defun eca-chat-opened (session params)
"Handle chat/opened notification for SESSION with PARAMS.
Idempotent: if the chat-id is already known on the client side
\(e.g. a client-initiated chat where the client minted the id and
the server is just announcing the new chat to other observers\),
update the title and return without creating a duplicate buffer.
Otherwise, creates a new chat buffer for a server-initiated chat
\(e.g. /fork or replay via chat/open\) and registers it under the
real chat-id so subsequent `chat/contentReceived' notifications
render into it.
A registered buffer marked `eca-chat--closed' (left behind by
`eca-chat-exit' on restart) is treated as stale, not reused, so a
resumed chat gets a fresh writable buffer."
(let* ((chat-id (plist-get params :chatId))
(title (plist-get params :title))
(existing (eca-get (eca--session-chats session) chat-id)))
(cond
((and existing (buffer-live-p existing)
(not (buffer-local-value 'eca-chat--closed existing)))
;; Already known: propagate title (if any) but do not duplicate.
(when title
(with-current-buffer existing
(setq-local eca-chat--title title)))
(eca-chat--invalidate-tab-line-cache session)
(eca-chat--force-tab-line-update)
(eca-chat--notify-status-changed session))
(t
;; Any live buffer reaching here is a stale closed one; kill it so
;; it doesn't linger as an orphan `:closed' buffer.
(when (and existing (buffer-live-p existing))
(kill-buffer existing))
(cl-incf eca-chat--new-chat-id)
(let ((new-buffer (eca-chat--create-buffer session)))
(with-current-buffer new-buffer
(let ((eca--chat-init-session session)
(eca--chat-init-skip-welcome t))
(eca-chat-mode))
(setq-local eca-chat--id chat-id)
(setq-local eca-chat--title title)
(eca-chat--initialize-selection-state session))
(setf (eca--session-chats session)
(eca-assoc (eca--session-chats session) chat-id new-buffer))
(eca-chat--invalidate-tab-line-cache session)
(eca-chat--force-tab-line-update)
(eca-chat--notify-status-changed session))))))