feat(architecture): enforce lifecycle orchestration and layered component boundaries

This commit is contained in:
admin
2026-02-26 10:18:19 +08:00
parent 64c2c7d8c2
commit cf1fecb004
32 changed files with 1701 additions and 180 deletions

View File

@@ -11,6 +11,8 @@
#include "esp_http_client.h"
#include "esp_log.h"
#include "esp_timer.h"
#include "runtime_diagnostics.h"
#include "runtime_policy.h"
#include "freertos/FreeRTOS.h"
#include "freertos/semphr.h"
#include "freertos/task.h"
@@ -881,8 +883,11 @@ esp_err_t image_generation_generate_png(const image_generation_request_t *req,
image_generation_result_t *out_result,
char *err,
size_t err_len) {
runtime_diag_counter_add(RUNTIME_DIAG_COUNTER_IMAGE_GENERATE_ATTEMPT, 1);
if (req == NULL || out_result == NULL || req->prompt == NULL || req->prompt[0] == '\0') {
image_generation_fill_err(err, err_len, "prompt is required");
runtime_diag_counter_add(RUNTIME_DIAG_COUNTER_IMAGE_GENERATE_FAILED, 1);
return ESP_ERR_INVALID_ARG;
}
@@ -890,10 +895,10 @@ esp_err_t image_generation_generate_png(const image_generation_request_t *req,
image_generation_request_t actual = *req;
if (actual.generation_timeout_ms == 0) {
actual.generation_timeout_ms = CONFIG_TQ_Z_IMAGE_TIMEOUT_MS;
actual.generation_timeout_ms = runtime_policy_image_generation_timeout_default_ms();
}
if (actual.download_timeout_ms == 0) {
actual.download_timeout_ms = CONFIG_TQ_Z_IMAGE_DOWNLOAD_TIMEOUT_MS;
actual.download_timeout_ms = runtime_policy_image_download_timeout_default_ms();
}
ESP_LOGI(TAG,
@@ -912,6 +917,12 @@ esp_err_t image_generation_generate_png(const image_generation_request_t *req,
"image generate stage failed, rc=0x%x, msg=%s",
(unsigned)gen_rc,
(err != NULL && err[0] != '\0') ? err : "model invoke failed");
if (gen_rc == ESP_ERR_TIMEOUT) {
runtime_diag_counter_add(RUNTIME_DIAG_COUNTER_IMAGE_GENERATE_TIMEOUT, 1);
} else {
runtime_diag_counter_add(RUNTIME_DIAG_COUNTER_IMAGE_GENERATE_FAILED, 1);
}
runtime_diag_record_error("image_generate", gen_rc, err != NULL ? err : "model invoke failed");
image_generation_result_free(out_result);
return gen_rc;
}
@@ -927,6 +938,12 @@ esp_err_t image_generation_generate_png(const image_generation_request_t *req,
"image download stage failed, rc=0x%x, msg=%s",
(unsigned)dl_rc,
(err != NULL && err[0] != '\0') ? err : "download failed");
if (dl_rc == ESP_ERR_TIMEOUT) {
runtime_diag_counter_add(RUNTIME_DIAG_COUNTER_IMAGE_GENERATE_TIMEOUT, 1);
} else {
runtime_diag_counter_add(RUNTIME_DIAG_COUNTER_IMAGE_GENERATE_FAILED, 1);
}
runtime_diag_record_error("image_download", dl_rc, err != NULL ? err : "download failed");
image_generation_result_free(out_result);
return dl_rc;
}
@@ -940,6 +957,7 @@ esp_err_t image_generation_generate_png(const image_generation_request_t *req,
(long long)(t_gen_done_ms - t0_ms),
(long long)(t_dl_done_ms - t_gen_done_ms),
(long long)(t_dl_done_ms - t0_ms));
runtime_diag_counter_add(RUNTIME_DIAG_COUNTER_IMAGE_GENERATE_SUCCESS, 1);
return ESP_OK;
}