// retoor #include #include #include // Placeholder for LLM API call // In a real implementation, this function would call the LLM API to get the summary. static char* call_llm_to_summarize(const char* messages_concatenated) { // For demonstration, just return a dummy summary. return strdup("This is a summary of the oldest 20 messages."); } char* summarize_oldest_messages(const char** messages, size_t message_count) { // Concatenate the oldest 20 messages size_t total_length = 0; size_t start_index = 0; if (message_count > 20) { start_index = message_count - 20; } for (size_t i = start_index; i < message_count; ++i) { total_length += strlen(messages[i]) + 1; // +1 for separator } char* concatenated = malloc(total_length + 1); if (!concatenated) { return NULL; } size_t write_offset = 0; for (size_t i = start_index; i < message_count; ++i) { size_t msg_len = strlen(messages[i]); memcpy(concatenated + write_offset, messages[i], msg_len); write_offset += msg_len; if (i < message_count - 1) { concatenated[write_offset++] = ' '; } } concatenated[write_offset] = '\0'; // Call the LLM API to get the summary char* summary = call_llm_to_summarize(concatenated); free(concatenated); return summary; }