about summary refs log tree commit diff
diff options
context:
space:
mode:
authorArun Isaac2026-04-09 18:13:34 +0100
committerArun Isaac2026-04-09 18:13:34 +0100
commit699b75bebd75717817ab9b0d589a3304317867ef (patch)
tree1c0b71bcea874c68c340c9ec81ebc60b8ae1e519
parent9a60e760e4a5ad6d274f887d91b43ee9db436779 (diff)
downloadkaagum-699b75bebd75717817ab9b0d589a3304317867ef.tar.gz
kaagum-699b75bebd75717817ab9b0d589a3304317867ef.tar.lz
kaagum-699b75bebd75717817ab9b0d589a3304317867ef.zip
Abstract out construction of agent_message_chunk notifications.
-rw-r--r--kaakaa/tea.scm57
1 files changed, 24 insertions, 33 deletions
diff --git a/kaakaa/tea.scm b/kaakaa/tea.scm
index e9c00c9..0de845a 100644
--- a/kaakaa/tea.scm
+++ b/kaakaa/tea.scm
@@ -86,23 +86,28 @@
   `(("name" . ,name)
     ("description" . ,(command-description command))))
 
+(define (agent-message-chunk session-id text)
+  "Return an @samp{agent_message_chunk} @samp{session/update} ACP message for
+@var{session-id} with @var{text}."
+  (acp-message `(("jsonrpc" . "2.0")
+                 ("method" . "session/update")
+                 ("params"
+                  ("sessionId" . ,session-id)
+                  ("update"
+                   ("sessionUpdate" . "agent_message_chunk")
+                   ("content"
+                    ("type" . "text")
+                    ("text" . ,text)))))))
+
 (define %cwd-command
   (command "Print current working directory of the session"
            (lambda (state session-id _)
              (values state
-                     (list (acp-message
-                            `(("jsonrpc" . "2.0")
-                              ("method" . "session/update")
-                              ("params"
-                               ("sessionId" . ,session-id)
-                               ("update"
-                                ("sessionUpdate" . "agent_message_chunk")
-                                ("content"
-                                 ("type" . "text")
-                                 ("text" . ,(focus (compose session-cwd
-                                                            (key-ref session-id)
-                                                            state-sessions)
-                                                   state))))))))))))
+                     (list (agent-message-chunk session-id
+                                                (focus (compose session-cwd
+                                                                (key-ref session-id)
+                                                                state-sessions)
+                                                       state)))))))
 
 (define %commands
   `(("cwd" . ,%cwd-command)))
@@ -171,15 +176,8 @@ effects."
    ;; command not found
    (else
     (values state
-            (list (acp-message `(("jsonrpc" . "2.0")
-                                 ("method" . "session/update")
-                                 ("params"
-                                  ("sessionId" . ,session-id)
-                                  ("update"
-                                   ("sessionUpdate" . "agent_message_chunk")
-                                   ("content"
-                                    ("type" . "text")
-                                    ("text" . "Error: Unknown command")))))))))))
+            (list (agent-message-chunk session-id
+                                       "Error: Unknown command"))))))
 
 (define (next-state-client-request state request)
   "Given current @var{state} and a new ACP @var{request}, return the next state and
@@ -437,17 +435,10 @@ and a list of effects.
                                    <>))
                          '())))
       (values state
-              (cons (acp-message `( ;; Send LLM's text response.
-                                   ("jsonrpc" . "2.0")
-                                   ("method" . "session/update")
-                                   ("params"
-                                    ("sessionId" . ,session-id)
-                                    ("update"
-                                     ("sessionUpdate" . "agent_message_chunk")
-                                     ("content"
-                                      ("type" . "text")
-                                      ("text" . ,(focus (key-ref "content")
-                                                        llm-reply)))))))
+              (cons (agent-message-chunk session-id
+                                         ;; Send LLM's text response.
+                                         (focus (key-ref "content")
+                                                llm-reply))
                     (append tool-call-effects
                             ;; End prompt turn if there are no further tool
                             ;; calls and a cancellation is not in progress.