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:
@@ -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 = "web_search";
|
||||
@@ -44,40 +43,18 @@ static esp_err_t http_event_handler(esp_http_client_event_t *evt)
|
||||
|
||||
esp_err_t tool_web_search_init(void)
|
||||
{
|
||||
/* Build-time secret takes highest priority */
|
||||
if (MIMI_SECRET_SEARCH_KEY[0] != '\0') {
|
||||
strncpy(s_search_key, MIMI_SECRET_SEARCH_KEY, sizeof(s_search_key) - 1);
|
||||
} else {
|
||||
nvs_handle_t nvs;
|
||||
esp_err_t err = nvs_open(MIMI_NVS_SEARCH, NVS_READONLY, &nvs);
|
||||
if (err == ESP_OK) {
|
||||
size_t len = sizeof(s_search_key);
|
||||
nvs_get_str(nvs, MIMI_NVS_KEY_API_KEY, s_search_key, &len);
|
||||
nvs_close(nvs);
|
||||
}
|
||||
}
|
||||
|
||||
if (s_search_key[0]) {
|
||||
ESP_LOGI(TAG, "Web search initialized (key configured)");
|
||||
} else {
|
||||
ESP_LOGW(TAG, "No search API key. Use CLI: set_search_key <KEY>");
|
||||
ESP_LOGW(TAG, "No search API key. Set MIMI_SECRET_SEARCH_KEY in mimi_secrets.h");
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t tool_web_search_set_key(const char *api_key)
|
||||
{
|
||||
nvs_handle_t nvs;
|
||||
ESP_ERROR_CHECK(nvs_open(MIMI_NVS_SEARCH, 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_search_key, api_key, sizeof(s_search_key) - 1);
|
||||
ESP_LOGI(TAG, "Search API key saved");
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
/* ── URL-encode a query string ────────────────────────────────── */
|
||||
|
||||
static size_t url_encode(const char *src, char *dst, size_t dst_size)
|
||||
@@ -237,7 +214,7 @@ static esp_err_t search_via_proxy(const char *path, search_buf_t *sb)
|
||||
esp_err_t tool_web_search_execute(const char *input_json, char *output, size_t output_size)
|
||||
{
|
||||
if (s_search_key[0] == '\0') {
|
||||
snprintf(output, output_size, "Error: No search API key configured. Use set_search_key command.");
|
||||
snprintf(output, output_size, "Error: No search API key configured. Set MIMI_SECRET_SEARCH_KEY in mimi_secrets.h");
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <stddef.h>
|
||||
|
||||
/**
|
||||
* Initialize web search tool — loads API key from NVS.
|
||||
* Initialize web search tool.
|
||||
*/
|
||||
esp_err_t tool_web_search_init(void);
|
||||
|
||||
@@ -18,7 +18,3 @@ esp_err_t tool_web_search_init(void);
|
||||
*/
|
||||
esp_err_t tool_web_search_execute(const char *input_json, char *output, size_t output_size);
|
||||
|
||||
/**
|
||||
* Save Brave Search API key to NVS.
|
||||
*/
|
||||
esp_err_t tool_web_search_set_key(const char *api_key);
|
||||
|
||||
Reference in New Issue
Block a user