refactor: remove NVS/CLI config, use mimi_secrets.h as sole configuration method

All configuration is now done exclusively through mimi_secrets.h at build time.
Removed NVS read/write logic, CLI config commands (wifi_set, set_tg_token,
set_api_key, set_model, set_proxy, clear_proxy, set_search_key), and setter
functions from all modules. CLI retains debug/maintenance commands only.
Updated all documentation to reflect the change.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
crispyberry
2026-02-07 23:04:24 +08:00
parent 43ded65713
commit 82f93b617b
18 changed files with 63 additions and 547 deletions

View File

@@ -8,7 +8,6 @@
#include "esp_http_client.h"
#include "esp_crt_bundle.h"
#include "esp_heap_caps.h"
#include "nvs.h"
#include "cJSON.h"
static const char *TAG = "llm";
@@ -71,7 +70,6 @@ static esp_err_t http_event_handler(esp_http_client_event_t *evt)
esp_err_t llm_proxy_init(void)
{
/* Build-time secrets take highest priority */
if (MIMI_SECRET_API_KEY[0] != '\0') {
strncpy(s_api_key, MIMI_SECRET_API_KEY, sizeof(s_api_key) - 1);
}
@@ -79,27 +77,10 @@ esp_err_t llm_proxy_init(void)
strncpy(s_model, MIMI_SECRET_MODEL, sizeof(s_model) - 1);
}
/* Fall back to NVS for values not set at build time */
if (s_api_key[0] == '\0' || s_model[0] == '\0') {
nvs_handle_t nvs;
esp_err_t err = nvs_open(MIMI_NVS_LLM, NVS_READONLY, &nvs);
if (err == ESP_OK) {
if (s_api_key[0] == '\0') {
size_t len = sizeof(s_api_key);
nvs_get_str(nvs, MIMI_NVS_KEY_API_KEY, s_api_key, &len);
}
if (strcmp(s_model, MIMI_LLM_DEFAULT_MODEL) == 0) {
size_t len = sizeof(s_model);
nvs_get_str(nvs, MIMI_NVS_KEY_MODEL, s_model, &len);
}
nvs_close(nvs);
}
}
if (s_api_key[0]) {
ESP_LOGI(TAG, "LLM proxy initialized (model: %s)", s_model);
} else {
ESP_LOGW(TAG, "No API key. Use CLI: set_api_key <KEY>");
ESP_LOGW(TAG, "No API key. Set MIMI_SECRET_API_KEY in mimi_secrets.h");
}
return ESP_OK;
}
@@ -467,30 +448,3 @@ esp_err_t llm_chat_tools(const char *system_prompt,
return ESP_OK;
}
/* ── NVS helpers ──────────────────────────────────────────────── */
esp_err_t llm_set_api_key(const char *api_key)
{
nvs_handle_t nvs;
ESP_ERROR_CHECK(nvs_open(MIMI_NVS_LLM, NVS_READWRITE, &nvs));
ESP_ERROR_CHECK(nvs_set_str(nvs, MIMI_NVS_KEY_API_KEY, api_key));
ESP_ERROR_CHECK(nvs_commit(nvs));
nvs_close(nvs);
strncpy(s_api_key, api_key, sizeof(s_api_key) - 1);
ESP_LOGI(TAG, "API key saved");
return ESP_OK;
}
esp_err_t llm_set_model(const char *model)
{
nvs_handle_t nvs;
ESP_ERROR_CHECK(nvs_open(MIMI_NVS_LLM, NVS_READWRITE, &nvs));
ESP_ERROR_CHECK(nvs_set_str(nvs, MIMI_NVS_KEY_MODEL, model));
ESP_ERROR_CHECK(nvs_commit(nvs));
nvs_close(nvs);
strncpy(s_model, model, sizeof(s_model) - 1);
ESP_LOGI(TAG, "Model set to: %s", s_model);
return ESP_OK;
}

View File

@@ -8,7 +8,7 @@
#include "mimi_config.h"
/**
* Initialize the LLM proxy. Reads API key and model from NVS.
* Initialize the LLM proxy.
*/
esp_err_t llm_proxy_init(void);
@@ -24,16 +24,6 @@ esp_err_t llm_proxy_init(void);
esp_err_t llm_chat(const char *system_prompt, const char *messages_json,
char *response_buf, size_t buf_size);
/**
* Save the Anthropic API key to NVS.
*/
esp_err_t llm_set_api_key(const char *api_key);
/**
* Save the model identifier to NVS.
*/
esp_err_t llm_set_model(const char *model);
/* ── Tool Use Support ──────────────────────────────────────────── */
typedef struct {