branch: externals/ellama
commit 14b2304fb45d3c5d64256f996e38cdca2b1fbc08
Author: Sergey Kostyaev <[email protected]>
Commit: Sergey Kostyaev <[email protected]>

    Add support for allowed tools list
    
    This commit introduces a new customization option `ellama-tools-allowed` 
that
    allows users to specify a list of allowed `ellama` tools. When a tool is in 
this
    list, it will execute without user confirmation. The execution logic is 
updated
    to check for the tool's presence in the allowed list in addition to existing
    confirmation mechanisms. The results of allowed tools are now properly 
encoded
    using `json-encode` if they are not already strings.
---
 ellama-tools.el | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/ellama-tools.el b/ellama-tools.el
index f7c547d52a..ac7cce0c0d 100644
--- a/ellama-tools.el
+++ b/ellama-tools.el
@@ -37,6 +37,12 @@ Dangerous.  Use at your own risk."
   :type 'boolean
   :group 'ellama)
 
+(defcustom ellama-tools-allowed nil
+  "List of allowed `ellama' tools.
+Tools from this list will work without user confirmation."
+  :type '(repeat function)
+  :group 'ellama)
+
 (defvar ellama-tools-available nil
   "Alist containing all registered tools.")
 
@@ -57,10 +63,14 @@ otherwise."
   (let ((confirmation (gethash function ellama-tools-confirm-allowed nil)))
     (cond
      ;; If user has approved all calls, just execute the function
-     ((when (or confirmation ellama-tools-allow-all)
-        (if args
-            (apply function args)
-          (funcall function))))
+     ((when (or confirmation ellama-tools-allow-all
+                (cl-find function ellama-tools-allowed))
+        (let ((result (if args
+                          (apply function args)
+                        (funcall function))))
+          (if (stringp result)
+              result
+            (json-encode result)))))
      ;; Otherwise, ask for confirmation
      (t
       (let* ((answer (read-char-choice

Reply via email to