The first content text of a tool result, bounded for a status summary. */
| 756 | |
| 757 | /* The first content text of a tool result, bounded for a status summary. */ |
| 758 | static char *application_tool_result_summary(const char *response) { |
| 759 | yyjson_doc *doc = response ? yyjson_read(response, strlen(response), 0) : NULL; |
| 760 | yyjson_val *root = doc ? yyjson_doc_get_root(doc) : NULL; |
| 761 | yyjson_val *content = root && yyjson_is_obj(root) ? yyjson_obj_get(root, "content") : NULL; |
| 762 | yyjson_val *first = content && yyjson_is_arr(content) ? yyjson_arr_get_first(content) : NULL; |
| 763 | yyjson_val *text = first && yyjson_is_obj(first) ? yyjson_obj_get(first, "text") : NULL; |
| 764 | char *summary = NULL; |
| 765 | if (text && yyjson_is_str(text)) { |
| 766 | const char *value = yyjson_get_str(text); |
| 767 | size_t length = strlen(value); |
| 768 | if (length >= APPLICATION_RECORD_ERROR_CAP) { |
| 769 | length = APPLICATION_RECORD_ERROR_CAP - 1U; |
| 770 | /* Never split a UTF-8 sequence. */ |
| 771 | while (length > 0 && ((unsigned char)value[length] & 0xC0U) == 0x80U) { |
| 772 | length--; |
| 773 | } |
| 774 | } |
| 775 | summary = cbm_alloc(CBM_MEM_CLASS_OTHER, length + 1U); |
| 776 | if (summary) { |
| 777 | memcpy(summary, value, length); |
| 778 | summary[length] = '\0'; |
| 779 | } |
| 780 | } |
| 781 | yyjson_doc_free(doc); |
| 782 | return summary; |
| 783 | } |
| 784 | |
| 785 | static void application_index_record_finish_locked(cbm_daemon_application_job_t *job) { |
| 786 | cbm_daemon_application_index_record_t *record = |
no test coverage detected