File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33## Unreleased
44
5+ - Fix subagent spawning being rejected by reserved server-managed chat ids.
6+
57## 0.133.1
68
79- Support client-generated chat ids: clients may now create the ` chatId ` themselves and send it on the first ` chat/prompt ` . eca-emacs #231 .
Original file line number Diff line number Diff line change 12461246
12471247(def ^:private max-client-chat-id-length 256 )
12481248
1249+ (defn ^:private server-managed-subagent-chat-id?
1250+ [db chat-id]
1251+ (and (string? chat-id)
1252+ (string/starts-with? chat-id " subagent-" )
1253+ (some? (get-in db [:chats chat-id :subagent ]))))
1254+
12491255(defn validate-client-chat-id
12501256 " Validates a client-supplied chat id. Returns nil when valid, otherwise an
12511257 error message string.
12751281(defn prompt
12761282 [{:keys [message agent behavior chat-id contexts variant trust] :as params} db* messenger config metrics]
12771283 (let [provided-chat-id chat-id
1278- invalid-id-reason (when (some? provided-chat-id)
1284+ invalid-id-reason (when (and (some? provided-chat-id)
1285+ (not (server-managed-subagent-chat-id? @db* provided-chat-id)))
12791286 (validate-client-chat-id provided-chat-id))]
12801287 (if invalid-id-reason
12811288 (do (logger/warn logger-tag " Rejected chat/prompt with invalid chat-id"
Original file line number Diff line number Diff line change 14031403 (is (match? {:chat-id " subagent-foo" :status :error } resp))
14041404 (is (= {} (:chats (h/db ))))
14051405 (is (nil? (:chat-opened (h/messages ))))))
1406+ (testing " Server-managed subagent chat-id is accepted"
1407+ (h/reset-components! )
1408+ (let [chat-id " subagent-foo" ]
1409+ (swap! (h/db* ) assoc-in [:chats chat-id] {:id chat-id :subagent {:mode " subagent" }})
1410+ (is (= {:chat-id chat-id}
1411+ (prompt!
1412+ {:message " hi" :chat-id chat-id}
1413+ {:all-tools-mock (constantly [])
1414+ :api-mock
1415+ (fn [{:keys [on-first-response-received on-message-received]}]
1416+ (on-first-response-received {:type :text :text " ok" })
1417+ (on-message-received {:type :text :text " ok" })
1418+ (on-message-received {:type :finish }))})))))
14061419 (testing " Excessively long chat-id is rejected"
14071420 (h/reset-components! )
14081421 (let [too-long (apply str (repeat 257 " a" ))
You can’t perform that action at this time.
0 commit comments