Files
mimiclaw/main/memory/session_mgr.h
crispyberry 3365db45b9 feat: add memory store and session manager
MEMORY.md for long-term memory, daily YYYY-MM-DD.md notes.
JSONL session files per chat_id with ring buffer history
(max 20 messages). All persisted on SPIFFS.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-05 18:55:44 +08:00

40 lines
1.0 KiB
C

#pragma once
#include "esp_err.h"
#include <stddef.h>
/**
* Initialize session manager.
*/
esp_err_t session_mgr_init(void);
/**
* Append a message to a session file (JSONL format).
* @param chat_id Session identifier (e.g., "12345")
* @param role "user" or "assistant"
* @param content Message text
*/
esp_err_t session_append(const char *chat_id, const char *role, const char *content);
/**
* Load session history as a JSON array string suitable for LLM messages.
* Returns the last max_msgs messages as:
* [{"role":"user","content":"..."},{"role":"assistant","content":"..."},...]
*
* @param chat_id Session identifier
* @param buf Output buffer (caller allocates)
* @param size Buffer size
* @param max_msgs Maximum number of messages to return
*/
esp_err_t session_get_history_json(const char *chat_id, char *buf, size_t size, int max_msgs);
/**
* Clear a session (delete the file).
*/
esp_err_t session_clear(const char *chat_id);
/**
* List all session files (prints to log).
*/
void session_list(void);