|
34 | 34 | :role role |
35 | 35 | :content content})) |
36 | 36 |
|
37 | | -(defn ^:private notify-before-hook! [chat-ctx {:keys [id name]}] |
| 37 | +(defn ^:private notify-before-hook-action! [chat-ctx {:keys [id name type]}] |
38 | 38 | (send-content! chat-ctx :system |
39 | | - {:type :hookStarted |
| 39 | + {:type :hookActionStarted |
| 40 | + :action-type type |
40 | 41 | :name name |
41 | 42 | :id id})) |
42 | 43 |
|
43 | | -(defn ^:private notify-after-hook! [chat-ctx {:keys [id name outputs status]}] |
| 44 | +(defn ^:private notify-after-hook-action! [chat-ctx {:keys [id name output error status type]}] |
44 | 45 | (send-content! chat-ctx :system |
45 | | - {:type :hookFinished |
| 46 | + {:type :hookActionFinished |
| 47 | + :action-type type |
46 | 48 | :id id |
47 | 49 | :name name |
48 | 50 | :status status |
49 | | - :outputs outputs})) |
| 51 | + :output output |
| 52 | + :error error})) |
50 | 53 |
|
51 | 54 | (defn finish-chat-prompt! [status {:keys [message chat-id db* metrics config on-finished-side-effect] :as chat-ctx}] |
52 | 55 | (swap! db* assoc-in [:chats chat-id :status] status) |
53 | 56 | (f.hooks/trigger-if-matches! :postPrompt |
54 | 57 | {:chat-id chat-id |
55 | 58 | :prompt message} |
56 | | - {:on-before-execute (partial notify-before-hook! chat-ctx) |
57 | | - :on-after-execute (partial notify-after-hook! chat-ctx)} |
| 59 | + {:on-before-action (partial notify-before-hook-action! chat-ctx) |
| 60 | + :on-after-action (partial notify-after-hook-action! chat-ctx)} |
58 | 61 | @db* |
59 | 62 | config) |
60 | 63 | (send-content! chat-ctx :system |
|
338 | 341 | :name (:name tool-call-state) |
339 | 342 | :server (:server tool-call-state) |
340 | 343 | :arguments (:arguments tool-call-state)} |
341 | | - {:on-before-execute (partial notify-before-hook! chat-ctx) |
342 | | - :on-after-execute (partial notify-after-hook! chat-ctx)} |
| 344 | + {:on-before-action (partial notify-before-hook-action! chat-ctx) |
| 345 | + :on-after-action (partial notify-after-hook-action! chat-ctx)} |
343 | 346 | @db* |
344 | 347 | (:config chat-ctx))) |
345 | 348 |
|
|
663 | 666 | :name name |
664 | 667 | :server server |
665 | 668 | :arguments arguments} |
666 | | - {:on-before-execute (partial notify-before-hook! chat-ctx) |
667 | | - :on-after-execute (fn [result] |
668 | | - (when (= 2 (:status result)) |
669 | | - (transition-tool-call! db* chat-ctx id :hook-rejected |
670 | | - {:reason {:code :hook-rejected |
671 | | - :text (str "Tool call rejected by hook: " (string/join "\n" (:outputs result)))}}) |
672 | | - (reset! hook-approved?* false)) |
673 | | - (notify-after-hook! chat-ctx result))} |
| 669 | + {:on-before-action (partial notify-before-hook-action! chat-ctx) |
| 670 | + :on-after-action (fn [result] |
| 671 | + (when (= 2 (:status result)) |
| 672 | + (transition-tool-call! db* chat-ctx id :hook-rejected |
| 673 | + {:reason {:code :hook-rejected |
| 674 | + :text (str "Tool call rejected by hook, output: " (:output result))}}) |
| 675 | + (reset! hook-approved?* false)) |
| 676 | + (notify-after-hook-action! chat-ctx result))} |
674 | 677 | db |
675 | 678 | config) |
676 | 679 | (if (and @approved?* @hook-approved?*) |
|
962 | 965 | _ (f.hooks/trigger-if-matches! :prePrompt |
963 | 966 | {:chat-id chat-id |
964 | 967 | :prompt message} |
965 | | - {:on-before-execute (partial notify-before-hook! chat-ctx) |
966 | | - :on-after-execute (fn [result] |
967 | | - (when (= 0 (:status result)) |
968 | | - (reset! hook-outputs* (:outputs result))) |
969 | | - (notify-after-hook! chat-ctx result))} |
| 968 | + {:on-before-action (partial notify-before-hook-action! chat-ctx) |
| 969 | + :on-after-action (fn [result] |
| 970 | + (when (= 0 (:status result)) |
| 971 | + (reset! hook-outputs* (:outputs result))) |
| 972 | + (notify-after-hook-action! chat-ctx result))} |
970 | 973 | db |
971 | 974 | config) |
972 | 975 | user-messages (if (seq @hook-outputs*) |
|
0 commit comments