Skip to content

Commit 7e19f8a

Browse files
committed
Check for api limit usage
1 parent 28dadae commit 7e19f8a

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

src/eca/features/chat.clj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,15 @@
165165
:content {:type :url
166166
:title (:title msg)
167167
:url (:url msg)}})
168+
:limit-reached (do
169+
(messenger/chat-content-received
170+
messenger
171+
{:chat-id chat-id
172+
:request-id request-id
173+
:role :system
174+
:content {:type :text
175+
:text (str "API limit reached. Tokens: " (:tokens msg))}})
176+
(finish-chat-prompt! chat-id :idle messenger db*))
168177
:finish (do
169178
(add-to-history! {:role "assistant" :content @received-msgs*})
170179
(finish-chat-prompt! chat-id :idle messenger db*))))

src/eca/features/tools.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
(mapv #(assoc % :source :mcp) mcp-tools))))
4141

4242
(defn call-tool! [^String name ^Map arguments db config]
43-
(logger/debug logger-tag (format "Calling tool '%s' with args '%s'" name arguments))
43+
(logger/info logger-tag (format "Calling tool '%s' with args '%s'" name arguments))
4444
(if-let [native-tool-handler (get-in (native-definitions db config) [name :handler])]
4545
(native-tool-handler arguments {:db db :config config})
4646
(f.mcp/call-tool! name arguments db)))

src/eca/features/tools/filesystem.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
(or (tools.util/invalid-arguments arguments [["path" (partial allowed-path? db) (str "Access denied - path $path outside allowed directories: " (tools.util/workspace-roots-strs db))]])
4949
(let [path (get arguments "path")
5050
content (get arguments "content")]
51-
(fs/create-dirs path)
51+
(fs/create-dirs (fs/parent (fs/path path)))
5252
(spit path content)
5353
(tools.util/single-text-content (format "Successfully wrote to %s" path)))))
5454

src/eca/llm_providers/anthropic.clj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@
154154
:on-response handle-response}))))
155155
"end_turn" (on-message-received {:type :finish
156156
:finish-reason (-> data :delta :stop_reason)})
157+
"max_tokens" (on-message-received {:type :limit-reached
158+
:tokens (:usage data)})
157159
nil)
158160
nil))]
159161
(base-request!

0 commit comments

Comments
 (0)