| 5891 | } |
| 5892 | |
| 5893 | static char *query_graph_tree_response_text(const cbm_cypher_result_t *result, int row_offset, |
| 5894 | int row_count, int visible_count, bool exact_total, |
| 5895 | bool allow_directory, |
| 5896 | const query_graph_cursor_context_t *cursor_context) { |
| 5897 | bool budget_hit = row_count < visible_count; |
| 5898 | bool materialized_more = row_offset + row_count < result->row_count; |
| 5899 | bool page_limit_hit = !budget_hit && materialized_more; |
| 5900 | bool truncated = budget_hit || materialized_more || result->truncated; |
| 5901 | |
| 5902 | char *rows_text = query_graph_tree_rows_text(result, row_offset, row_count, allow_directory); |
| 5903 | if (!rows_text) { |
| 5904 | return NULL; |
| 5905 | } |
| 5906 | cbm_sb_t sb; |
| 5907 | cbm_sb_init(&sb); |
| 5908 | cbm_sb_append(&sb, rows_text); |
| 5909 | free(rows_text); |
| 5910 | cbm_tree_scalar_int(&sb, "returned", row_count); |
| 5911 | cbm_tree_scalar_int(&sb, "total", result->row_count); |
| 5912 | cbm_tree_scalar_str(&sb, "total_relation", exact_total ? "eq" : "gte"); |
| 5913 | if (row_offset > 0) { |
| 5914 | cbm_tree_scalar_int(&sb, "offset", row_offset); |
| 5915 | } |
| 5916 | cbm_tree_scalar_bool(&sb, "has_more", truncated); |
| 5917 | cbm_tree_scalar_bool(&sb, "truncated", truncated); |
| 5918 | const char *reason = query_graph_truncation_reason(result, budget_hit, page_limit_hit); |
| 5919 | if (reason) { |
| 5920 | cbm_tree_scalar_str(&sb, "truncation_reason", reason); |
| 5921 | } |
| 5922 | if (row_count > 0 && materialized_more) { |
| 5923 | char next_cursor[QUERY_GRAPH_CURSOR_TOKEN_CAP]; |
| 5924 | if (query_graph_cursor_encode(cursor_context, row_offset + row_count, next_cursor)) { |
| 5925 | cbm_tree_scalar_str(&sb, "next_cursor", next_cursor); |
| 5926 | } |
| 5927 | cbm_tree_scalar_int(&sb, "next_offset", row_offset + row_count); |
| 5928 | } else if (budget_hit && row_count == 0) { |
| 5929 | cbm_tree_scalar_str(&sb, "hint", |
| 5930 | "First row exceeds output budget; raise max_output_tokens."); |
| 5931 | } |
| 5932 | if (result->warning) { |
| 5933 | cbm_tree_scalar_str(&sb, "warning", result->warning); |
| 5934 | } |
| 5935 | if (result->row_count == 0 && !result->truncated) { |
| 5936 | cbm_tree_scalar_str(&sb, "hint", |
| 5937 | "Query returned no results. Use get_graph_schema() to see " |
| 5938 | "available labels and edge types."); |
| 5939 | } |
| 5940 | return cbm_sb_finish(&sb); |
| 5941 | } |
| 5942 | |
| 5943 | static char *query_graph_json_response_text(const cbm_cypher_result_t *result, int row_offset, |
| 5944 | int row_count, int visible_count, bool exact_total, |
no test coverage detected