Entropic 2.3.8
Local-first agentic inference engine
Loading...
Searching...
No Matches
c_interface.cpp File Reference

C boundary implementation for i_storage_backend.h. More...

#include <entropic/interfaces/i_storage_backend.h>
#include <entropic/storage/backend.h>
#include <entropic/types/logging.h>
#include <cstring>
#include <new>
#include <optional>
#include <string>
Include dependency graph for c_interface.cpp:

Go to the source code of this file.

Classes

struct  entropic_storage_backend
 

Functions

static char * dup_string (const std::string &s)
 Duplicate a std::string to a malloc'd C string.
 
static std::optional< std::string > opt_str (const char *s)
 Convert optional C string to std::optional<std::string>.
 
entropic_storage_backend_t entropic_storage_create (const char *db_path)
 Create a storage backend.
 
entropic_error_t entropic_storage_initialize (entropic_storage_backend_t storage)
 Initialize storage.
 
void entropic_storage_destroy (entropic_storage_backend_t storage)
 Destroy storage.
 
char * entropic_storage_create_conversation (entropic_storage_backend_t storage, const char *title, const char *project_path, const char *model_id)
 Create a conversation.
 
entropic_error_t entropic_storage_save_conversation (entropic_storage_backend_t storage, const char *conversation_id, const char *messages_json)
 Save messages to a conversation.
 
entropic_error_t entropic_storage_load_conversation (entropic_storage_backend_t storage, const char *conversation_id, char **result_json)
 Load a conversation.
 
entropic_error_t entropic_storage_list_conversations (entropic_storage_backend_t storage, int limit, int offset, char **result_json)
 List conversations.
 
entropic_error_t entropic_storage_search_conversations (entropic_storage_backend_t storage, const char *query, int limit, char **result_json)
 Search conversations.
 
entropic_error_t entropic_storage_delete_conversation (entropic_storage_backend_t storage, const char *conversation_id)
 Delete a conversation.
 
entropic_error_t entropic_storage_create_delegation (entropic_storage_backend_t storage, const char *parent_conversation_id, const char *delegating_tier, const char *target_tier, const char *task, int max_turns, char **result_json)
 Create a delegation.
 
entropic_error_t entropic_storage_complete_delegation (entropic_storage_backend_t storage, const char *delegation_id, const char *status, const char *result_summary)
 Complete a delegation.
 
entropic_error_t entropic_storage_get_delegations (entropic_storage_backend_t storage, const char *conversation_id, char **result_json)
 Get delegations for a conversation.
 
entropic_error_t entropic_storage_save_snapshot (entropic_storage_backend_t storage, const char *conversation_id, const char *messages_json)
 Save a compaction snapshot.
 
entropic_error_t entropic_storage_get_stats (entropic_storage_backend_t storage, char **result_json)
 Get statistics.
 

Detailed Description

C boundary implementation for i_storage_backend.h.

Wraps SqliteStorageBackend in opaque handles, catches all exceptions at the .so boundary, and converts to entropic_error_t codes.

Version
1.8.8

Definition in file c_interface.cpp.

Function Documentation

◆ dup_string()

static char * dup_string ( const std::string &  s)
static

Duplicate a std::string to a malloc'd C string.

Parameters
sSource string.
Returns
Heap-allocated copy (caller must free with entropic_free).

Definition at line 53 of file c_interface.cpp.

◆ entropic_storage_complete_delegation()

entropic_error_t entropic_storage_complete_delegation ( entropic_storage_backend_t  storage,
const char *  delegation_id,
const char *  status,
const char *  result_summary 
)

Complete a delegation.

Mark a delegation as completed or failed.

Parameters
storageHandle.
delegation_idDelegation ID.
statusStatus string.
result_summaryOptional summary.
Returns
Error code.

Definition at line 333 of file c_interface.cpp.

◆ entropic_storage_create()

entropic_storage_backend_t entropic_storage_create ( const char *  db_path)

Create a storage backend.

Create a storage backend with SQLite at the given path.

Parameters
db_pathDatabase file path.
Returns
Handle or NULL.

Definition at line 80 of file c_interface.cpp.

◆ entropic_storage_create_conversation()

char * entropic_storage_create_conversation ( entropic_storage_backend_t  storage,
const char *  title,
const char *  project_path,
const char *  model_id 
)

Create a conversation.

Create a new conversation.

Parameters
storageHandle.
titleTitle.
project_pathOptional project path.
model_idOptional model ID.
Returns
Conversation ID (caller frees) or NULL.

Definition at line 131 of file c_interface.cpp.

◆ entropic_storage_create_delegation()

entropic_error_t entropic_storage_create_delegation ( entropic_storage_backend_t  storage,
const char *  parent_conversation_id,
const char *  delegating_tier,
const char *  target_tier,
const char *  task,
int  max_turns,
char **  result_json 
)

Create a delegation.

Create a delegation record with a child conversation.

Parameters
storageHandle.
parent_conversation_idParent conversation.
delegating_tierSource tier.
target_tierTarget tier.
taskTask description.
max_turnsTurn limit.
result_jsonOutput JSON.
Returns
Error code.

Definition at line 294 of file c_interface.cpp.

◆ entropic_storage_delete_conversation()

entropic_error_t entropic_storage_delete_conversation ( entropic_storage_backend_t  storage,
const char *  conversation_id 
)

Delete a conversation.

Delete a conversation and all associated records.

Parameters
storageHandle.
conversation_idConversation ID.
Returns
Error code.

Definition at line 264 of file c_interface.cpp.

◆ entropic_storage_destroy()

void entropic_storage_destroy ( entropic_storage_backend_t  storage)

Destroy storage.

Destroy storage and close connections.

Parameters
storageHandle (NULL-safe).

Definition at line 115 of file c_interface.cpp.

◆ entropic_storage_get_delegations()

entropic_error_t entropic_storage_get_delegations ( entropic_storage_backend_t  storage,
const char *  conversation_id,
char **  result_json 
)

Get delegations for a conversation.

Get delegations for a parent conversation.

Parameters
storageHandle.
conversation_idParent conversation.
result_jsonOutput JSON.
Returns
Error code.

Definition at line 360 of file c_interface.cpp.

◆ entropic_storage_get_stats()

entropic_error_t entropic_storage_get_stats ( entropic_storage_backend_t  storage,
char **  result_json 
)

Get statistics.

Get storage statistics.

Parameters
storageHandle.
result_jsonOutput JSON.
Returns
Error code.

Definition at line 415 of file c_interface.cpp.

◆ entropic_storage_initialize()

entropic_error_t entropic_storage_initialize ( entropic_storage_backend_t  storage)

Initialize storage.

Initialize storage (run migrations, create tables).

Parameters
storageHandle.
Returns
Error code.

Definition at line 98 of file c_interface.cpp.

◆ entropic_storage_list_conversations()

entropic_error_t entropic_storage_list_conversations ( entropic_storage_backend_t  storage,
int  limit,
int  offset,
char **  result_json 
)

List conversations.

List conversations with pagination.

Parameters
storageHandle.
limitMax results.
offsetOffset.
result_jsonOutput JSON.
Returns
Error code.

Definition at line 210 of file c_interface.cpp.

◆ entropic_storage_load_conversation()

entropic_error_t entropic_storage_load_conversation ( entropic_storage_backend_t  storage,
const char *  conversation_id,
char **  result_json 
)

Load a conversation.

Load a conversation with messages.

Parameters
storageHandle.
conversation_idConversation ID.
result_jsonOutput JSON.
Returns
Error code.

Definition at line 181 of file c_interface.cpp.

◆ entropic_storage_save_conversation()

entropic_error_t entropic_storage_save_conversation ( entropic_storage_backend_t  storage,
const char *  conversation_id,
const char *  messages_json 
)

Save messages to a conversation.

Parameters
storageHandle.
conversation_idConversation ID.
messages_jsonJSON array.
Returns
Error code.

Definition at line 156 of file c_interface.cpp.

◆ entropic_storage_save_snapshot()

entropic_error_t entropic_storage_save_snapshot ( entropic_storage_backend_t  storage,
const char *  conversation_id,
const char *  messages_json 
)

Save a compaction snapshot.

Save a pre-compaction snapshot of full conversation history.

Parameters
storageHandle.
conversation_idConversation ID.
messages_jsonJSON messages.
Returns
Error code.

Definition at line 389 of file c_interface.cpp.

◆ entropic_storage_search_conversations()

entropic_error_t entropic_storage_search_conversations ( entropic_storage_backend_t  storage,
const char *  query,
int  limit,
char **  result_json 
)

Search conversations.

Full-text search across conversations.

Parameters
storageHandle.
queryFTS5 query.
limitMax results.
result_jsonOutput JSON.
Returns
Error code.

Definition at line 238 of file c_interface.cpp.

◆ opt_str()

static std::optional< std::string > opt_str ( const char *  s)
static

Convert optional C string to std::optional<std::string>.

Parameters
sC string or NULL.
Returns
Optional string.

Definition at line 66 of file c_interface.cpp.