diff options
| -rw-r--r-- | llm-tools.el | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/llm-tools.el b/llm-tools.el index 0b2474c..4fa4258 100644 --- a/llm-tools.el +++ b/llm-tools.el | |||
| @@ -442,4 +442,51 @@ If required, consider using the url as the input to the `Read` tool to get the c | |||
| 442 | :confirm nil | 442 | :confirm nil |
| 443 | :include t) | 443 | :include t) |
| 444 | 444 | ||
| 445 | ;;;; Preview Functions | ||
| 446 | (defun llm-tools--preview-teardown (ov) | ||
| 447 | "Delete region covered by overlay OV and remove the overlay." | ||
| 448 | (when (overlayp ov) | ||
| 449 | (with-current-buffer (overlay-buffer ov) | ||
| 450 | (let ((inhibit-read-only t)) | ||
| 451 | (delete-region (overlay-start ov) (overlay-end ov))) | ||
| 452 | (delete-overlay ov)))) | ||
| 453 | |||
| 454 | (defun llm-tools--make-preview-setup (formatter) | ||
| 455 | "Return a preview setup function that calls FORMATTER with ARG-VALUES. | ||
| 456 | FORMATTER is a function (ARG-VALUES) that inserts the preview text." | ||
| 457 | (lambda (arg-values _info) | ||
| 458 | (let ((from (point))) | ||
| 459 | (funcall formatter arg-values) | ||
| 460 | (make-overlay from (point))))) | ||
| 461 | |||
| 462 | (defun llm-tools--format-bash-preview (arg-values) | ||
| 463 | (let ((command (car arg-values))) | ||
| 464 | (insert "(" | ||
| 465 | (propertize "bash" 'font-lock-face 'font-lock-keyword-face) | ||
| 466 | " " command ")\n"))) | ||
| 467 | |||
| 468 | (defun llm-tools--format-edit-file-preview (arg-values) | ||
| 469 | (let ((patch (car arg-values))) | ||
| 470 | (insert "(" | ||
| 471 | (propertize "edit_file" 'font-lock-face 'font-lock-keyword-face) | ||
| 472 | ")\n" patch "\n"))) | ||
| 473 | |||
| 474 | (defun llm-tools--format-write-file-preview (arg-values) | ||
| 475 | (let ((file (car arg-values)) | ||
| 476 | (contents (cadr arg-values))) | ||
| 477 | (insert "(" | ||
| 478 | (propertize "write_file" 'font-lock-face 'font-lock-keyword-face) | ||
| 479 | " " (prin1-to-string file) ")\n" contents "\n"))) | ||
| 480 | |||
| 481 | (dolist (tool '(("bash" llm-tools--format-bash-preview) | ||
| 482 | ("edit_file" llm-tools--format-edit-file-preview) | ||
| 483 | ("write_file" llm-tools--format-write-file-preview))) | ||
| 484 | (setf (alist-get (car tool) | ||
| 485 | gptel--tool-preview-alist | ||
| 486 | nil | ||
| 487 | nil | ||
| 488 | #'equal) | ||
| 489 | (list (llm-tools--make-preview-setup (cadr tool)) | ||
| 490 | #'llm-tools--preview-teardown))) | ||
| 491 | |||
| 445 | (provide 'llm-tools) | 492 | (provide 'llm-tools) |
