Skip to content

Commit f358412

Browse files
committed
Merge branch 'master' into improve-approval
2 parents a9d53f7 + e60b5e4 commit f358412

File tree

10 files changed

+71
-40
lines changed

10 files changed

+71
-40
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22

33
## Unreleased
44

5+
## 0.39.0
6+
7+
- Fix session-tokens in usage notifications.
8+
- Support context limit on usage notifications.
9+
- Fix session/message tokens calculation.
10+
11+
## 0.38.3
12+
13+
- Fix anthropic token renew.
14+
15+
## 0.38.2
16+
517
- Fix command prompts to allow args with spaces between quotes.
618
- Fix anthropic token renew when expires.
719
- Considerably improve toolCall approval / permissions config.

docs/models.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -232,25 +232,25 @@ Only set this when your provider uses a different path or expects query paramete
232232

233233
=== "Same model with different settings"
234234

235-
For now, you can create different providers with same model names to achieve that:
235+
For now, you can create different providers with same model names to achieve that:
236236

237-
```javascript
238-
{
239-
"providers": {
240-
"openai": {
241-
"api": "openai-responses",
242-
"models": { "gpt-5": {} }
243-
},
244-
"openai-high": {
245-
"api": "openai-responses",
246-
"url": "https://api.openai.com",
247-
"keyEnv": "OPENAI_API_KEY",
248-
"models": {
249-
"gpt-5": {
250-
"extraPayload": { "reasoning": { "effort": "high" } }
251-
}
252-
}
253-
}
237+
```javascript
238+
{
239+
"providers": {
240+
"openai": {
241+
"api": "openai-responses",
242+
"models": { "gpt-5": {} }
243+
},
244+
"openai-high": {
245+
"api": "openai-responses",
246+
"url": "https://api.openai.com",
247+
"keyEnv": "OPENAI_API_KEY",
248+
"models": {
249+
"gpt-5": {
250+
"extraPayload": { "reasoning": { "effort": "high" } }
251+
}
252+
}
253+
}
254+
}
254255
}
255-
}
256-
```
256+
```

docs/protocol.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,20 @@ interface UsageContent {
543543
* The cost of the whole chat session so far.
544544
*/
545545
sessionCost?: string;
546+
547+
/**
548+
* Informations about limits.
549+
*/
550+
limit: {
551+
/**
552+
* The context limit for this chat.
553+
*/
554+
context: number;
555+
/**
556+
* The output limit for this chat.
557+
*/
558+
output: number;
559+
}
546560
}
547561

548562
/**

resources/ECA_VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.38.1
1+
0.39.0

src/eca/features/chat.clj

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,15 @@
6868
total-input-tokens (get-in db [:chats chat-id :total-input-tokens] 0)
6969
total-input-cache-creation-tokens (get-in db [:chats chat-id :total-input-cache-creation-tokens] nil)
7070
total-input-cache-read-tokens (get-in db [:chats chat-id :total-input-cache-read-tokens] nil)
71-
total-input-cache-tokens (or total-input-cache-creation-tokens 0)
72-
total-output-tokens (get-in db [:chats chat-id :total-output-tokens] 0)]
71+
total-input-cache-tokens (or total-input-cache-read-tokens 0)
72+
total-output-tokens (get-in db [:chats chat-id :total-output-tokens] 0)
73+
model-capabilities (get-in db [:models full-model])]
7374
(assoc-some {:message-output-tokens output-tokens
7475
:message-input-tokens (+ input-tokens message-input-cache-tokens)
7576
:session-tokens (+ total-input-tokens total-input-cache-tokens total-output-tokens)}
76-
:message-cost (shared/tokens->cost input-tokens input-cache-creation-tokens input-cache-read-tokens output-tokens full-model db)
77-
:session-cost (shared/tokens->cost total-input-tokens total-input-cache-creation-tokens total-input-cache-read-tokens total-output-tokens full-model db)))))
77+
:limit (:limit model-capabilities)
78+
:message-cost (shared/tokens->cost input-tokens input-cache-creation-tokens input-cache-read-tokens output-tokens model-capabilities)
79+
:session-cost (shared/tokens->cost total-input-tokens total-input-cache-creation-tokens total-input-cache-read-tokens total-output-tokens model-capabilities)))))
7880

7981
(defn ^:private tokenize-args [^String s]
8082
(if (string/blank? s)

src/eca/features/commands.clj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,14 @@
183183
total-input-cache-creation-tokens (get-in db [:chats chat-id :total-input-cache-creation-tokens] nil)
184184
total-input-cache-read-tokens (get-in db [:chats chat-id :total-input-cache-read-tokens] nil)
185185
total-output-tokens (get-in db [:chats chat-id :total-output-tokens] 0)
186+
model-capabilities (get-in db [:models full-model])
186187
text (multi-str (str "Total input tokens: " total-input-tokens)
187188
(when total-input-cache-creation-tokens
188189
(str "Total input cache creation tokens: " total-input-cache-creation-tokens))
189190
(when total-input-cache-read-tokens
190191
(str "Total input cache read tokens: " total-input-cache-read-tokens))
191192
(str "Total output tokens: " total-output-tokens)
192-
(str "Total cost: $" (shared/tokens->cost total-input-tokens total-input-cache-creation-tokens total-input-cache-read-tokens total-output-tokens full-model db)))]
193+
(str "Total cost: $" (shared/tokens->cost total-input-tokens total-input-cache-creation-tokens total-input-cache-read-tokens total-output-tokens model-capabilities)))]
193194
{:type :chat-messages
194195
:chats {chat-id [{:role "system" :content [{:type :text :text text}]}]}})
195196
"config" {:type :chat-messages

src/eca/features/login.clj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,5 @@
5454
(login-step
5555
{:provider provider
5656
:step :login/renew-token
57-
:db* db*}))
57+
:db* db*})
58+
(db/update-global-cache! @db*))

src/eca/models.clj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
:web-search (contains? models-with-web-search-support (name model))
4848
:tools (get model-config "tool_call")
4949
:max-output-tokens (get-in model-config ["limit" "output"])}
50+
:limit {:context (get-in model-config ["limit" "context"])
51+
:output (get-in model-config ["limit" "output"])}
5052
:input-token-cost (some-> (get-in model-config ["cost" "input"]) float (/ one-million))
5153
:output-token-cost (some-> (get-in model-config ["cost" "output"]) float (/ one-million))
5254
:input-cache-creation-token-cost (some-> (get-in model-config ["cost" "cache_write"]) float (/ one-million))

src/eca/shared.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@
7373

7474
(defn multi-str [& strings] (string/join "\n" (remove nil? strings)))
7575

76-
(defn tokens->cost [input-tokens input-cache-creation-tokens input-cache-read-tokens output-tokens full-model db]
76+
(defn tokens->cost [input-tokens input-cache-creation-tokens input-cache-read-tokens output-tokens model-capabilities]
7777
(when-let [{:keys [input-token-cost output-token-cost
78-
input-cache-creation-token-cost input-cache-read-token-cost]} (get-in db [:models full-model])]
78+
input-cache-creation-token-cost input-cache-read-token-cost]} model-capabilities]
7979
(when (and input-token-cost output-token-cost)
8080
(let [input-cost (* input-tokens input-token-cost)
8181
input-cost (if (and input-cache-creation-tokens input-cache-creation-token-cost)

test/eca/shared_test.clj

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,19 @@
3232
(shared/assoc-some {} :a 1 :b)))))
3333

3434
(deftest tokens->cost-test
35-
(let [db {:models {"provider/my-model" {:input-token-cost 0.01
36-
:output-token-cost 0.02
37-
:input-cache-creation-token-cost 0.005
38-
:input-cache-read-token-cost 0.001}}}]
35+
(let [model-capabilities {:input-token-cost 0.01
36+
:output-token-cost 0.02
37+
:input-cache-creation-token-cost 0.005
38+
:input-cache-read-token-cost 0.001}]
3939
(testing "basic input/output cost"
40-
(is (= "0.70" (shared/tokens->cost 30 nil nil 20 "provider/my-model" db))))
40+
(is (= "0.70" (shared/tokens->cost 30 nil nil 20 model-capabilities))))
4141
(testing "with cache creation tokens"
42-
(is (= "0.75" (shared/tokens->cost 30 10 nil 20 "provider/my-model" db))))
42+
(is (= "0.75" (shared/tokens->cost 30 10 nil 20 model-capabilities))))
4343
(testing "with cache read tokens"
44-
(is (= "0.73" (shared/tokens->cost 30 nil 30 20 "provider/my-model" db))))
44+
(is (= "0.73" (shared/tokens->cost 30 nil 30 20 model-capabilities))))
4545
(testing "with both cache creation and read tokens"
46-
(is (= "0.78" (shared/tokens->cost 30 10 30 20 "provider/my-model" db))))
46+
(is (= "0.78" (shared/tokens->cost 30 10 30 20 model-capabilities))))
4747
(testing "returns nil when model is missing from db"
48-
(is (nil? (shared/tokens->cost 30 nil nil 20 "unknown" db))))
48+
(is (nil? (shared/tokens->cost 30 nil nil 20 {}))))
4949
(testing "returns nil when mandatory costs are missing"
50-
(is (nil? (shared/tokens->cost 30 nil nil 20 "my-model-missing"
51-
{:models {"my-model-missing" {:input-token-cost 0.01}}}))))))
50+
(is (nil? (shared/tokens->cost 30 nil nil 20 {:input-token-cost 0.01}))))))

0 commit comments

Comments
 (0)