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

    Fix result handling in tool execution wrapper
    
    Improved the logic for handling tool results by ensuring JSON encoding only
    occurs when a result exists, and the callback is called only when both 
callback
    and result are present. Also ensured proper fallback to 'done' string when 
no
    result or callback is available.
---
 ellama-tools.el | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/ellama-tools.el b/ellama-tools.el
index 3566a58fe7..eec9a0b952 100644
--- a/ellama-tools.el
+++ b/ellama-tools.el
@@ -205,14 +205,14 @@ approved, \"Forbidden by the user\" otherwise."
                   nil))))
           (let ((result-str (if (stringp result)
                                 result
-                              (if result
-                                  (json-encode result)
-                                "done")))
+                              (when result
+                                  (json-encode result))))
                 (cb (and args
                          (functionp (car args))
                          (car args))))
-            (if cb (funcall cb result-str)
-              result-str))))))))
+            (if (and cb result-str)
+                (funcall cb result-str)
+              (or result-str "done")))))))))
 
 (defun ellama-tools-wrap-with-confirm (tool-plist)
   "Wrap a tool's function with automatic confirmation.

Reply via email to