|
1307 | 1307 | content)))) |
1308 | 1308 |
|
1309 | 1309 | (defn ^:private handle-command! [{:keys [command args]} chat-ctx] |
1310 | | - (let [{:keys [type on-finished-side-effect] :as result} (f.commands/handle-command! command args chat-ctx)] |
1311 | | - (case type |
1312 | | - :chat-messages (do |
1313 | | - (doseq [[chat-id {:keys [messages title]}] (:chats result)] |
1314 | | - (let [new-chat-ctx (assoc chat-ctx :chat-id chat-id)] |
1315 | | - (send-chat-contents! messages new-chat-ctx) |
1316 | | - (when title |
1317 | | - (send-content! new-chat-ctx :system (assoc-some |
1318 | | - {:type :metadata} |
1319 | | - :title title))))) |
1320 | | - (finish-chat-prompt! :idle chat-ctx)) |
1321 | | - :new-chat-status (finish-chat-prompt! (:status result) chat-ctx) |
1322 | | - :send-prompt (let [prompt-contents (:prompt result)] |
1323 | | - ;; Keep original slash command in :message for hooks (already in parent chat-ctx) |
1324 | | - (prompt-messages! [{:role "user" :content prompt-contents}] |
1325 | | - :eca-command |
1326 | | - (assoc chat-ctx :on-finished-side-effect on-finished-side-effect))) |
1327 | | - nil))) |
| 1310 | + (try |
| 1311 | + (let [{:keys [type on-finished-side-effect] :as result} (f.commands/handle-command! command args chat-ctx)] |
| 1312 | + (case type |
| 1313 | + :chat-messages (do |
| 1314 | + (doseq [[chat-id {:keys [messages title]}] (:chats result)] |
| 1315 | + (let [new-chat-ctx (assoc chat-ctx :chat-id chat-id)] |
| 1316 | + (send-chat-contents! messages new-chat-ctx) |
| 1317 | + (when title |
| 1318 | + (send-content! new-chat-ctx :system (assoc-some |
| 1319 | + {:type :metadata} |
| 1320 | + :title title))))) |
| 1321 | + (finish-chat-prompt! :idle chat-ctx)) |
| 1322 | + :new-chat-status (finish-chat-prompt! (:status result) chat-ctx) |
| 1323 | + :send-prompt (let [prompt-contents (:prompt result)] |
| 1324 | + ;; Keep original slash command in :message for hooks (already in parent chat-ctx) |
| 1325 | + (prompt-messages! [{:role "user" :content prompt-contents}] |
| 1326 | + :eca-command |
| 1327 | + (assoc chat-ctx :on-finished-side-effect on-finished-side-effect))) |
| 1328 | + nil)) |
| 1329 | + (catch Exception e |
| 1330 | + (logger/error e) |
| 1331 | + (send-content! chat-ctx :system {:type :text |
| 1332 | + :text (str "Error: " (ex-message e) "\n\nCheck ECA stderr for more details.")}) |
| 1333 | + (finish-chat-prompt! :idle (dissoc chat-ctx :on-finished-side-effect))))) |
1328 | 1334 |
|
1329 | 1335 | (defn ^:private prompt* |
1330 | 1336 | [{:keys [model]} |
|
0 commit comments