Function: gptel--inspect-accept-tool-calls
gptel--inspect-accept-tool-calls is an interactive and natively
compiled function defined in gptel.el.
Signature
(gptel--inspect-accept-tool-calls &optional _)
Documentation
Run possibly edited tool-calls read from the tool call inspection buffer.
Key Bindings
gptel-tool-call-inspection-map C-c C-c
Source Code
;; Defined in /nix/store/q3r7g81pvghw7a523kjk2k2zih3pfk8z-emacs-packages-deps/share/emacs/site-lisp/elpa/gptel-20261002.545/gptel.el
(defun gptel--inspect-accept-tool-calls (&optional _)
"Run possibly edited tool-calls read from the tool call inspection buffer."
(interactive)
(let ((call) (index)
(read-error
(lambda () (user-error
"Cannot read modified arguments, please check modifications")))
(apply-error
(lambda () (message "Cannot apply argument modifications. \
This is a bug, please report it!"))))
(unless (gptel-fsm-p gptel--fsm-last) (funcall apply-error))
(cond
((buffer-modified-p)
(let* ((info (gptel-fsm-info gptel--fsm-last))
(backend (plist-get info :backend))
(tool-use (plist-get info :tool-use))
(tool-spec-args-cb) (name)
(tool-calls))
(dolist (o (cl-remove-if-not (lambda (ov) (overlay-get ov 'gptel-overlay))
(overlays-in (point-min) (point-max))))
(goto-char (overlay-start o))
(condition-case nil
(save-restriction
(narrow-to-region (point) (overlay-end o))
(skip-chars-forward "\n\r\ ")
(unless (eobp)
(setq call (read (current-buffer))
name (plist-get call :name))))
(error (funcall read-error)))
(unless (integerp (setq index (overlay-get o 'gptel-overlay)))
(funcall read-error))
;; Merge with or remove from messages array...
(gptel--inject-tool-call
backend (plist-get info :data) (nth index tool-use) call)
(if (not call)
;; Remove from tool-use
(plist-put info :tool-use
(append (cl-subseq tool-use 0 index)
(cl-subseq tool-use (1+ index))))
;; ...before modifying the tool use block
(gptel--merge-plists (nth index tool-use) call)
(setq tool-spec-args-cb (overlay-get o 'gptel-tool))
;; and modifying the arguments sent to the callback
(setf (nth 0 tool-spec-args-cb)
(or (cl-find name (plist-get info :tools)
:key #'gptel-tool-name :test #'string=)
(gptel-get-tool name)))
(setf (nth 1 tool-spec-args-cb) (plist-get call :args))
(push tool-spec-args-cb tool-calls)))
(gptel--accept-tool-calls ;include overlay to clean up if there is one
tool-calls (cadr (plist-get info :tool-display)))))
(t (let* ((tool-display (plist-get (gptel-fsm-info gptel--fsm-last)
:tool-display)))
(apply #'gptel--accept-tool-calls tool-display)))))
(quit-window t))