| 2223 | goto bad; |
| 2224 | } |
| 2225 | chat_msg_add_tool_call_id(msg, id); |
| 2226 | buf b = {0}; |
| 2227 | buf_puts(&b, msg->content ? msg->content : ""); |
| 2228 | const size_t begin = b.len; |
| 2229 | buf_puts(&b, "<tool_result>"); |
| 2230 | append_tool_result_text(&b, nested.content); |
| 2231 | buf_puts(&b, "</tool_result>"); |
| 2232 | /* Preserve parsed boundaries, not just markup which ordinary user |
| 2233 | * text can also contain. V4.1 orders and separates these blocks. */ |
| 2234 | msg->tool_results = xrealloc(msg->tool_results, |
| 2235 | (size_t)(msg->tool_results_len + 1) * sizeof(msg->tool_results[0])); |
| 2236 | msg->tool_results[msg->tool_results_len++] = (tool_result_span){ |
| 2237 | .begin = begin, .end = b.len, .id = id ? xstrdup(id) : NULL, |
| 2238 | .content = nested.content}; |
| 2239 | nested.content = NULL; |
| 2240 | free(msg->content); |
| 2241 | msg->content = buf_take(&b); |
| 2242 | if (nested.images.len) { |
| 2243 | size_t total = msg->images.len + nested.images.len; |
no test coverage detected