|
8 | 8 | (def ^:private logger-tag "[HOOK]") |
9 | 9 |
|
10 | 10 | (defn ^:private hook-matches? [type data hook] |
11 | | - (case type |
12 | | - (:preToolCall :postToolCall) |
13 | | - (re-matches (re-pattern (or (:matcher hook) ".*")) |
14 | | - (str (:server data) "__" (:tool-name data))) |
| 11 | + (let [hook-config-type (keyword (:type hook)) |
| 12 | + hook-config-type (cond ;; legacy values |
| 13 | + (= :prePrompt hook-config-type) :preRequest |
| 14 | + (= :postPrompt hook-config-type) :postRequest |
| 15 | + :else hook-config-type)] |
| 16 | + (cond |
| 17 | + (not= type hook-config-type) |
| 18 | + false |
15 | 19 |
|
16 | | - true)) |
| 20 | + (contains? #{:preToolCall :postToolCall} type) |
| 21 | + (re-matches (re-pattern (or (:matcher hook) ".*")) |
| 22 | + (str (:server data) "__" (:tool-name data))) |
| 23 | + |
| 24 | + :else |
| 25 | + true))) |
17 | 26 |
|
18 | 27 | (defn ^:private run-hook-action! [action name data db] |
19 | 28 | (case (:type action) |
|
39 | 48 | db |
40 | 49 | config] |
41 | 50 | (doseq [[name hook] (:hooks config)] |
42 | | - (when (= type (keyword (:type hook))) |
43 | | - (when (hook-matches? type data hook) |
44 | | - (vec |
45 | | - (map-indexed (fn [i action] |
46 | | - (let [id (str (random-uuid)) |
47 | | - type (:type action) |
48 | | - name (if (> 1 (count (:actions hook))) |
49 | | - (str name "-" (inc i)) |
50 | | - name)] |
51 | | - (on-before-action {:id id |
52 | | - :name name}) |
53 | | - (if-let [[status output error] (run-hook-action! action name data db)] |
54 | | - (on-after-action {:id id |
55 | | - :name name |
56 | | - :type type |
57 | | - :status status |
58 | | - :output output |
59 | | - :error error}) |
60 | | - (on-after-action {:id id |
61 | | - :name name |
62 | | - :type type |
63 | | - :status -1})))) |
64 | | - (:actions hook))))))) |
| 51 | + (when (hook-matches? type data hook) |
| 52 | + (vec |
| 53 | + (map-indexed (fn [i action] |
| 54 | + (let [id (str (random-uuid)) |
| 55 | + type (:type action) |
| 56 | + name (if (> 1 (count (:actions hook))) |
| 57 | + (str name "-" (inc i)) |
| 58 | + name)] |
| 59 | + (on-before-action {:id id |
| 60 | + :name name}) |
| 61 | + (if-let [[status output error] (run-hook-action! action name data db)] |
| 62 | + (on-after-action {:id id |
| 63 | + :name name |
| 64 | + :type type |
| 65 | + :status status |
| 66 | + :output output |
| 67 | + :error error}) |
| 68 | + (on-after-action {:id id |
| 69 | + :name name |
| 70 | + :type type |
| 71 | + :status -1})))) |
| 72 | + (:actions hook)))))) |
0 commit comments