|
76 | 76 | :message-cost (shared/tokens->cost input-tokens input-cache-creation-tokens input-cache-read-tokens output-tokens full-model db) |
77 | 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))))) |
78 | 78 |
|
79 | | -(defn ^:private message->decision [message] |
80 | | - (let [slash? (string/starts-with? message "/") |
81 | | - mcp-prompt? (string/includes? (first (string/split message #" ")) ":")] |
82 | | - (cond |
83 | | - (and slash? mcp-prompt?) |
84 | | - (let [command (subs message 1) |
85 | | - parts (string/split command #" ") |
86 | | - [server] (string/split command #":")] |
87 | | - {:type :mcp-prompt |
88 | | - :server server |
89 | | - :prompt (second (string/split (first parts) #":")) |
90 | | - :args (vec (rest parts))}) |
| 79 | +(defn ^:private tokenize-args [^String s] |
| 80 | + (if (string/blank? s) |
| 81 | + [] |
| 82 | + (->> (re-seq #"\s*\"([^\"]*)\"|\s*([^\s]+)" s) |
| 83 | + (map (fn [[_ quoted unquoted]] (or quoted unquoted))) |
| 84 | + (vec)))) |
91 | 85 |
|
92 | | - slash? |
| 86 | +(defn ^:private message->decision [message] |
| 87 | + (let [slash? (string/starts-with? message "/")] |
| 88 | + (if slash? |
93 | 89 | (let [command (subs message 1) |
94 | | - parts (string/split command #" ")] |
95 | | - {:type :eca-command |
96 | | - :command (first parts) |
97 | | - :args (vec (rest parts))}) |
98 | | - |
99 | | - :else |
| 90 | + tokens (let [toks (tokenize-args command)] (if (seq toks) toks [""])) |
| 91 | + first-token (first tokens) |
| 92 | + args (vec (rest tokens))] |
| 93 | + (if (and first-token (string/includes? first-token ":")) |
| 94 | + (let [[server prompt] (string/split first-token #":" 2)] |
| 95 | + {:type :mcp-prompt |
| 96 | + :server server |
| 97 | + :prompt prompt |
| 98 | + :args args}) |
| 99 | + {:type :eca-command |
| 100 | + :command first-token |
| 101 | + :args args})) |
100 | 102 | {:type :prompt-message |
101 | 103 | :message message}))) |
102 | 104 |
|
|
230 | 232 | :origin origin)}) |
231 | 233 | (send-content! chat-ctx :assistant |
232 | 234 | (assoc-some |
233 | | - {:type :toolCalled |
234 | | - :origin origin |
235 | | - :name name |
236 | | - :arguments arguments |
237 | | - :error (:error result) |
238 | | - :id id |
239 | | - :outputs (:contents result)} |
240 | | - :details details |
241 | | - :summary summary)))) |
| 235 | + {:type :toolCalled |
| 236 | + :origin origin |
| 237 | + :name name |
| 238 | + :arguments arguments |
| 239 | + :error (:error result) |
| 240 | + :id id |
| 241 | + :outputs (:contents result)} |
| 242 | + :details details |
| 243 | + :summary summary)))) |
242 | 244 | (do |
243 | 245 | (add-to-history! {:role "tool_call" :content tool-call}) |
244 | 246 | (add-to-history! {:role "tool_call_output" |
|
0 commit comments