chore: simplify llm serial log.

Signed-off-by: Bo <boironic@gmail.com>
This commit is contained in:
Bo
2026-02-18 19:16:00 +08:00
parent 5d92917a0b
commit 3232de772a
4 changed files with 34 additions and 15 deletions

View File

@@ -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
}

View File

@@ -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);
}

View File

@@ -1,5 +1,6 @@
#include "tools/tool_cron.h"
#include "cron/cron_service.h"
#include "bus/message_bus.h"
#include <string.h>
#include <time.h>
@@ -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");

View File

@@ -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,