From 3232de772aaea750aa203413d92791b34a6bd4f1 Mon Sep 17 00:00:00 2001 From: Bo Date: Wed, 18 Feb 2026 19:16:00 +0800 Subject: [PATCH] chore: simplify llm serial log. Signed-off-by: Bo --- main/llm/llm_proxy.c | 28 ++++++++++++++++------------ main/telegram/telegram_bot.c | 8 +++++++- main/tools/tool_cron.c | 9 +++++++++ main/tools/tool_registry.c | 4 ++-- 4 files changed, 34 insertions(+), 15 deletions(-) diff --git a/main/llm/llm_proxy.c b/main/llm/llm_proxy.c index b5b34b8..dba2961 100644 --- a/main/llm/llm_proxy.c +++ b/main/llm/llm_proxy.c @@ -48,20 +48,24 @@ static void llm_log_payload(const char *label, const char *payload) ESP_LOGI(TAG, "%s[%u]: %s", label, (unsigned)off, chunk); } #else - size_t shown = total > MIMI_LLM_LOG_PREVIEW_BYTES ? MIMI_LLM_LOG_PREVIEW_BYTES : total; - char preview[MIMI_LLM_LOG_PREVIEW_BYTES + 1]; - memcpy(preview, payload, shown); - preview[shown] = '\0'; - for (size_t i = 0; i < shown; i++) { - if (preview[i] == '\n' || preview[i] == '\r' || preview[i] == '\t') { - preview[i] = ' '; + if (MIMI_LLM_LOG_PREVIEW_BYTES > 0) { + size_t shown = total > MIMI_LLM_LOG_PREVIEW_BYTES ? MIMI_LLM_LOG_PREVIEW_BYTES : total; + char preview[MIMI_LLM_LOG_PREVIEW_BYTES + 1]; + memcpy(preview, payload, shown); + preview[shown] = '\0'; + for (size_t i = 0; i < shown; i++) { + if (preview[i] == '\n' || preview[i] == '\r' || preview[i] == '\t') { + preview[i] = ' '; + } } + ESP_LOGI(TAG, "%s (%u bytes): %s%s", + label, + (unsigned)total, + preview, + (shown < total) ? " ..." : ""); + } else { + ESP_LOGI(TAG, "%s (%u bytes)", label, (unsigned)total); } - ESP_LOGI(TAG, "%s (%u bytes): %s%s", - label, - (unsigned)total, - preview, - (shown < total) ? " ..." : ""); #endif } diff --git a/main/telegram/telegram_bot.c b/main/telegram/telegram_bot.c index 482b6a7..04eb760 100644 --- a/main/telegram/telegram_bot.c +++ b/main/telegram/telegram_bot.c @@ -392,11 +392,14 @@ esp_err_t telegram_send_message(const char *chat_id, const char *text) free(json_str); int sent_ok = 0; + bool markdown_failed = false; if (resp) { const char *desc = NULL; sent_ok = tg_response_is_ok(resp, &desc); if (!sent_ok) { - ESP_LOGW(TAG, "Markdown send failed: %s", desc ? desc : "unknown"); + markdown_failed = true; + ESP_LOGI(TAG, "Markdown rejected by Telegram for %s: %s", + chat_id, desc ? desc : "unknown"); } } @@ -435,6 +438,9 @@ esp_err_t telegram_send_message(const char *chat_id, const char *text) if (!sent_ok) { all_ok = 0; } else { + if (markdown_failed) { + ESP_LOGI(TAG, "Plain-text fallback succeeded for %s", chat_id); + } ESP_LOGI(TAG, "Telegram send success to %s (%d bytes)", chat_id, (int)chunk); } diff --git a/main/tools/tool_cron.c b/main/tools/tool_cron.c index b8b8e25..048e890 100644 --- a/main/tools/tool_cron.c +++ b/main/tools/tool_cron.c @@ -1,5 +1,6 @@ #include "tools/tool_cron.h" #include "cron/cron_service.h" +#include "bus/message_bus.h" #include #include @@ -45,6 +46,14 @@ esp_err_t tool_cron_add_execute(const char *input_json, char *output, size_t out if (channel) strncpy(job.channel, channel, sizeof(job.channel) - 1); if (chat_id) strncpy(job.chat_id, chat_id, sizeof(job.chat_id) - 1); + if (strcmp(job.channel, MIMI_CHAN_TELEGRAM) == 0 && + (job.chat_id[0] == '\0' || strcmp(job.chat_id, "cron") == 0)) { + snprintf(output, output_size, + "Error: cron_add with channel='telegram' requires a valid chat_id"); + cJSON_Delete(root); + return ESP_ERR_INVALID_ARG; + } + if (strcmp(schedule_type, "every") == 0) { job.kind = CRON_KIND_EVERY; cJSON *interval = cJSON_GetObjectItem(root, "interval_s"); diff --git a/main/tools/tool_registry.c b/main/tools/tool_registry.c index c277ed1..d4dde35 100644 --- a/main/tools/tool_registry.c +++ b/main/tools/tool_registry.c @@ -143,8 +143,8 @@ esp_err_t tool_registry_init(void) "\"interval_s\":{\"type\":\"integer\",\"description\":\"Interval in seconds (required for 'every')\"}," "\"at_epoch\":{\"type\":\"integer\",\"description\":\"Unix timestamp to fire at (required for 'at')\"}," "\"message\":{\"type\":\"string\",\"description\":\"Message to inject when the job fires, triggering an agent turn\"}," - "\"channel\":{\"type\":\"string\",\"description\":\"Optional reply channel (e.g. 'telegram'). Defaults to 'system'\"}," - "\"chat_id\":{\"type\":\"string\",\"description\":\"Optional reply chat_id. Defaults to 'cron'\"}" + "\"channel\":{\"type\":\"string\",\"description\":\"Optional reply channel (e.g. 'telegram'). If omitted, current turn channel is used when available\"}," + "\"chat_id\":{\"type\":\"string\",\"description\":\"Optional reply chat_id. Required when channel='telegram'. If omitted during a Telegram turn, current chat_id is used\"}" "}," "\"required\":[\"name\",\"schedule_type\",\"message\"]}", .execute = tool_cron_add_execute,