feat(engram): wire ISE emission into core processing paths (checkpoint, high-importance writes, WM promotion)
This commit is contained in:
Vendored
+490
-23
@@ -20,16 +20,35 @@ el_val_t route_create_edge(el_val_t method, el_val_t path, el_val_t body);
|
||||
el_val_t route_neighbors(el_val_t method, el_val_t path, el_val_t body);
|
||||
el_val_t route_strengthen(el_val_t method, el_val_t path, el_val_t body);
|
||||
el_val_t route_forget(el_val_t method, el_val_t path, el_val_t body);
|
||||
el_val_t route_save(el_val_t method, el_val_t path, el_val_t body);
|
||||
el_val_t route_decay(el_val_t method, el_val_t path, el_val_t body);
|
||||
el_val_t route_export(el_val_t method, el_val_t path, el_val_t body);
|
||||
el_val_t route_reindex(el_val_t method, el_val_t path, el_val_t body);
|
||||
el_val_t route_load(el_val_t method, el_val_t path, el_val_t body);
|
||||
el_val_t route_health(el_val_t method, el_val_t path, el_val_t body);
|
||||
el_val_t route_neuron_session_begin(el_val_t method, el_val_t path, el_val_t body);
|
||||
el_val_t route_neuron_ctx(el_val_t method, el_val_t path, el_val_t body);
|
||||
el_val_t route_neuron_memory(el_val_t method, el_val_t path, el_val_t body);
|
||||
el_val_t route_neuron_knowledge_capture(el_val_t method, el_val_t path, el_val_t body);
|
||||
el_val_t route_neuron_knowledge_evolve(el_val_t method, el_val_t path, el_val_t body);
|
||||
el_val_t route_neuron_knowledge_promote(el_val_t method, el_val_t path, el_val_t body);
|
||||
el_val_t route_neuron_recall(el_val_t method, el_val_t path, el_val_t body);
|
||||
el_val_t route_neuron_graph(el_val_t method, el_val_t path, el_val_t body);
|
||||
el_val_t route_neuron_graph_link(el_val_t method, el_val_t path, el_val_t body);
|
||||
el_val_t route_neuron_list(el_val_t method, el_val_t path, el_val_t body);
|
||||
el_val_t route_neuron_consolidate(el_val_t method, el_val_t path, el_val_t body);
|
||||
el_val_t route_neuron_config(el_val_t method, el_val_t path, el_val_t body);
|
||||
el_val_t route_neuron_state_events(el_val_t method, el_val_t path, el_val_t body);
|
||||
el_val_t route_neuron_processes(el_val_t method, el_val_t path, el_val_t body);
|
||||
el_val_t route_events_next(el_val_t method, el_val_t path, el_val_t body);
|
||||
el_val_t route_events_ack(el_val_t method, el_val_t path, el_val_t body);
|
||||
el_val_t check_auth_ok(el_val_t method, el_val_t body);
|
||||
el_val_t handle_request(el_val_t method, el_val_t path, el_val_t body);
|
||||
|
||||
el_val_t bind_str;
|
||||
el_val_t port;
|
||||
el_val_t data_dir;
|
||||
el_val_t snapshot_path;
|
||||
el_val_t db_path;
|
||||
el_val_t loaded;
|
||||
|
||||
el_val_t parse_port(el_val_t bind) {
|
||||
el_val_t colon = str_index_of(bind, EL_STR(":"));
|
||||
@@ -115,11 +134,60 @@ el_val_t route_create_node(el_val_t method, el_val_t path, el_val_t body) {
|
||||
node_type = EL_STR("Memory");
|
||||
}
|
||||
el_val_t salience = json_get_float(body, EL_STR("salience"));
|
||||
if (str_eq(salience, el_from_float(0.0))) {
|
||||
if (salience == el_from_float(0.0)) {
|
||||
salience = el_from_float(0.5);
|
||||
}
|
||||
el_val_t id = engram_node(content, node_type, salience);
|
||||
return el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"id\":\""), id), EL_STR("\",\"content\":\"")), content), EL_STR("\",\"node_type\":\"")), node_type), EL_STR("\"}"));
|
||||
el_val_t auto_linked = 0;
|
||||
el_val_t clen = str_len(content);
|
||||
if (clen >= 20) {
|
||||
el_val_t sp1 = str_index_of(content, EL_STR(" "));
|
||||
el_val_t w1end = sp1;
|
||||
if (sp1 < 0) {
|
||||
w1end = clen;
|
||||
}
|
||||
el_val_t word1 = str_slice(content, 0, w1end);
|
||||
el_val_t search_term = EL_STR("");
|
||||
if (str_len(word1) >= 5) {
|
||||
search_term = word1;
|
||||
}
|
||||
if (str_eq(search_term, EL_STR(""))) {
|
||||
if (sp1 >= 0) {
|
||||
el_val_t rest = str_slice(content, (sp1 + 1), clen);
|
||||
el_val_t sp2 = str_index_of(rest, EL_STR(" "));
|
||||
el_val_t w2end = sp2;
|
||||
if (sp2 < 0) {
|
||||
w2end = str_len(rest);
|
||||
}
|
||||
el_val_t word2 = str_slice(rest, 0, w2end);
|
||||
if (str_len(word2) >= 5) {
|
||||
search_term = word2;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!str_eq(search_term, EL_STR(""))) {
|
||||
el_val_t results = engram_search_json(search_term, 10);
|
||||
el_val_t n = json_array_len(results);
|
||||
el_val_t i = 0;
|
||||
while (i < n) {
|
||||
if (auto_linked >= 5) {
|
||||
i = n;
|
||||
}
|
||||
if (auto_linked < 5) {
|
||||
el_val_t elem = json_array_get(results, i);
|
||||
el_val_t rid = json_get_string(elem, EL_STR("id"));
|
||||
if (!str_eq(rid, EL_STR(""))) {
|
||||
if (!str_eq(rid, id)) {
|
||||
engram_connect(id, rid, el_from_float(0.5), EL_STR("related"));
|
||||
auto_linked = (auto_linked + 1);
|
||||
}
|
||||
}
|
||||
i = (i + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"id\":\""), id), EL_STR("\",\"content\":\"")), content), EL_STR("\",\"node_type\":\"")), node_type), EL_STR("\",\"auto_linked\":")), int_to_str(auto_linked)), EL_STR("}"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -205,7 +273,7 @@ el_val_t route_create_edge(el_val_t method, el_val_t path, el_val_t body) {
|
||||
relation = EL_STR("associates");
|
||||
}
|
||||
el_val_t weight = json_get_float(body, EL_STR("weight"));
|
||||
if (str_eq(weight, el_from_float(0.0))) {
|
||||
if (weight == el_from_float(0.0)) {
|
||||
weight = el_from_float(0.5);
|
||||
}
|
||||
engram_connect(from_id, to_id, weight, relation);
|
||||
@@ -243,30 +311,46 @@ el_val_t route_forget(el_val_t method, el_val_t path, el_val_t body) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t route_save(el_val_t method, el_val_t path, el_val_t body) {
|
||||
el_val_t route_decay(el_val_t method, el_val_t path, el_val_t body) {
|
||||
return engram_apply_decay_json();
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t route_export(el_val_t method, el_val_t path, el_val_t body) {
|
||||
el_val_t dir = env(EL_STR("ENGRAM_DATA_DIR"));
|
||||
if (str_eq(dir, EL_STR(""))) {
|
||||
dir = EL_STR("/tmp/engram");
|
||||
}
|
||||
el_val_t db_path = el_str_concat(dir, EL_STR("/engram.db"));
|
||||
engram_write_binary_el(db_path);
|
||||
el_val_t p = json_get_string(body, EL_STR("path"));
|
||||
if (str_eq(p, EL_STR(""))) {
|
||||
el_val_t dir = env(EL_STR("ENGRAM_DATA_DIR"));
|
||||
if (str_eq(dir, EL_STR(""))) {
|
||||
dir = EL_STR("/tmp/engram");
|
||||
}
|
||||
p = el_str_concat(dir, EL_STR("/snapshot.json"));
|
||||
}
|
||||
engram_save(p);
|
||||
return el_str_concat(el_str_concat(EL_STR("{\"ok\":true,\"path\":\""), p), EL_STR("\"}"));
|
||||
return el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"ok\":true,\"binary\":\""), db_path), EL_STR("\",\"json\":\"")), p), EL_STR("\"}"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t route_reindex(el_val_t method, el_val_t path, el_val_t body) {
|
||||
return engram_reindex_json();
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t route_load(el_val_t method, el_val_t path, el_val_t body) {
|
||||
el_val_t p = json_get_string(body, EL_STR("path"));
|
||||
if (str_eq(p, EL_STR(""))) {
|
||||
el_val_t dir = env(EL_STR("ENGRAM_DATA_DIR"));
|
||||
if (str_eq(dir, EL_STR(""))) {
|
||||
dir = EL_STR("/tmp/engram");
|
||||
}
|
||||
p = el_str_concat(dir, EL_STR("/snapshot.json"));
|
||||
el_val_t dir = env(EL_STR("ENGRAM_DATA_DIR"));
|
||||
if (str_eq(dir, EL_STR(""))) {
|
||||
dir = EL_STR("/tmp/engram");
|
||||
}
|
||||
el_val_t db_path = el_str_concat(dir, EL_STR("/engram.db"));
|
||||
el_val_t ok = engram_load_binary_el(db_path);
|
||||
if (!ok) {
|
||||
el_val_t p = json_get_string(body, EL_STR("path"));
|
||||
if (str_eq(p, EL_STR(""))) {
|
||||
p = el_str_concat(dir, EL_STR("/snapshot.json"));
|
||||
}
|
||||
engram_load(p);
|
||||
}
|
||||
engram_load(p);
|
||||
return ok_json();
|
||||
return 0;
|
||||
}
|
||||
@@ -276,6 +360,262 @@ el_val_t route_health(el_val_t method, el_val_t path, el_val_t body) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t route_neuron_session_begin(el_val_t method, el_val_t path, el_val_t body) {
|
||||
el_val_t results = engram_activate_json(EL_STR("memory knowledge context"), 2);
|
||||
el_val_t nc = engram_node_count();
|
||||
el_val_t ec = engram_edge_count();
|
||||
return el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"ok\":true,\"nodes\":"), results), EL_STR(",\"node_count\":")), int_to_str(nc)), EL_STR(",\"edge_count\":")), int_to_str(ec)), EL_STR("}"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t route_neuron_ctx(el_val_t method, el_val_t path, el_val_t body) {
|
||||
el_val_t results = engram_activate_json(EL_STR("architecture decision memory"), 2);
|
||||
el_val_t n = json_array_len(results);
|
||||
el_val_t limit = ({ el_val_t _if_result_1 = 0; if ((n > 10)) { _if_result_1 = (10); } else { _if_result_1 = (n); } _if_result_1; });
|
||||
el_val_t ctx = EL_STR("Recent working memory:\n");
|
||||
el_val_t i = 0;
|
||||
el_val_t ctx_body = EL_STR("");
|
||||
while (i < limit) {
|
||||
el_val_t elem = json_array_get(results, i);
|
||||
el_val_t label = json_get_string(elem, EL_STR("label"));
|
||||
el_val_t content = json_get_string(elem, EL_STR("content"));
|
||||
el_val_t clen = str_len(content);
|
||||
el_val_t snippet = ({ el_val_t _if_result_2 = 0; if ((clen > 200)) { _if_result_2 = (str_slice(content, 0, 200)); } else { _if_result_2 = (content); } _if_result_2; });
|
||||
ctx_body = el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(ctx_body, EL_STR("- [")), label), EL_STR("]: ")), snippet), EL_STR("\n"));
|
||||
i = (i + 1);
|
||||
}
|
||||
el_val_t full_ctx = el_str_concat(ctx, ctx_body);
|
||||
return el_str_concat(el_str_concat(EL_STR("{\"ok\":true,\"context\":\""), str_replace(str_replace(str_replace(full_ctx, EL_STR("\\"), EL_STR("\\\\")), EL_STR("\""), EL_STR("\\\"")), EL_STR("\n"), EL_STR("\\n"))), EL_STR("\"}"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t route_neuron_memory(el_val_t method, el_val_t path, el_val_t body) {
|
||||
el_val_t content = json_get_string(body, EL_STR("content"));
|
||||
if (str_eq(content, EL_STR(""))) {
|
||||
return EL_STR("{\"error\":\"content is required\"}");
|
||||
}
|
||||
el_val_t node_type = json_get_string(body, EL_STR("node_type"));
|
||||
if (str_eq(node_type, EL_STR(""))) {
|
||||
node_type = EL_STR("Memory");
|
||||
}
|
||||
el_val_t label = json_get_string(body, EL_STR("label"));
|
||||
el_val_t importance = json_get_string(body, EL_STR("importance"));
|
||||
el_val_t project = json_get_string(body, EL_STR("project"));
|
||||
el_val_t tags_raw = json_get_string(body, EL_STR("tags"));
|
||||
el_val_t tier = EL_STR("Episodic");
|
||||
if (str_eq(importance, EL_STR("critical"))) {
|
||||
tier = EL_STR("Procedural");
|
||||
}
|
||||
if (str_eq(importance, EL_STR("high"))) {
|
||||
tier = EL_STR("Semantic");
|
||||
}
|
||||
if (str_eq(importance, EL_STR("normal"))) {
|
||||
tier = EL_STR("Episodic");
|
||||
}
|
||||
if (str_eq(importance, EL_STR("low"))) {
|
||||
tier = EL_STR("Working");
|
||||
}
|
||||
el_val_t explicit_tier = json_get_string(body, EL_STR("tier"));
|
||||
if (!str_eq(explicit_tier, EL_STR(""))) {
|
||||
tier = explicit_tier;
|
||||
}
|
||||
el_val_t tags_str = tags_raw;
|
||||
if (!str_eq(project, EL_STR(""))) {
|
||||
if (str_eq(tags_str, EL_STR(""))) {
|
||||
tags_str = el_str_concat(EL_STR("project:"), project);
|
||||
}
|
||||
if (!str_eq(tags_str, EL_STR(""))) {
|
||||
tags_str = el_str_concat(el_str_concat(tags_str, EL_STR(" project:")), project);
|
||||
}
|
||||
}
|
||||
el_val_t id = engram_node_full(content, node_type, label, el_from_float(0.5), el_from_float(0.5), el_from_float(1.0), tier, tags_str);
|
||||
el_val_t dir = env(EL_STR("ENGRAM_DATA_DIR"));
|
||||
if (str_eq(dir, EL_STR(""))) {
|
||||
dir = EL_STR("/tmp/engram");
|
||||
}
|
||||
el_val_t db_path = el_str_concat(dir, EL_STR("/engram.db"));
|
||||
engram_write_binary_el(db_path);
|
||||
return el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"ok\":true,\"id\":\""), id), EL_STR("\",\"content\":\"")), str_replace(str_replace(content, EL_STR("\\"), EL_STR("\\\\")), EL_STR("\""), EL_STR("\\\""))), EL_STR("\"}"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t route_neuron_knowledge_capture(el_val_t method, el_val_t path, el_val_t body) {
|
||||
el_val_t content = json_get_string(body, EL_STR("content"));
|
||||
if (str_eq(content, EL_STR(""))) {
|
||||
return EL_STR("{\"error\":\"content is required\"}");
|
||||
}
|
||||
el_val_t title = json_get_string(body, EL_STR("title"));
|
||||
el_val_t category = json_get_string(body, EL_STR("category"));
|
||||
el_val_t tags_raw = json_get_string(body, EL_STR("tags"));
|
||||
el_val_t project = json_get_string(body, EL_STR("project"));
|
||||
el_val_t tier_raw = json_get_string(body, EL_STR("tier"));
|
||||
el_val_t tier = EL_STR("Episodic");
|
||||
if (str_eq(tier_raw, EL_STR("lesson"))) {
|
||||
tier = EL_STR("Semantic");
|
||||
}
|
||||
if (str_eq(tier_raw, EL_STR("canonical"))) {
|
||||
tier = EL_STR("Procedural");
|
||||
}
|
||||
if (str_eq(tier_raw, EL_STR("note"))) {
|
||||
tier = EL_STR("Episodic");
|
||||
}
|
||||
el_val_t tags_str = tags_raw;
|
||||
if (!str_eq(category, EL_STR(""))) {
|
||||
if (str_eq(tags_str, EL_STR(""))) {
|
||||
tags_str = el_str_concat(EL_STR("category:"), category);
|
||||
}
|
||||
if (!str_eq(tags_str, EL_STR(""))) {
|
||||
tags_str = el_str_concat(el_str_concat(tags_str, EL_STR(" category:")), category);
|
||||
}
|
||||
}
|
||||
if (!str_eq(project, EL_STR(""))) {
|
||||
if (str_eq(tags_str, EL_STR(""))) {
|
||||
tags_str = el_str_concat(EL_STR("project:"), project);
|
||||
}
|
||||
if (!str_eq(tags_str, EL_STR(""))) {
|
||||
tags_str = el_str_concat(el_str_concat(tags_str, EL_STR(" project:")), project);
|
||||
}
|
||||
}
|
||||
el_val_t id = engram_node_full(content, EL_STR("Knowledge"), title, el_from_float(0.7), el_from_float(0.7), el_from_float(1.0), tier, tags_str);
|
||||
el_val_t dir = env(EL_STR("ENGRAM_DATA_DIR"));
|
||||
if (str_eq(dir, EL_STR(""))) {
|
||||
dir = EL_STR("/tmp/engram");
|
||||
}
|
||||
el_val_t db_path = el_str_concat(dir, EL_STR("/engram.db"));
|
||||
engram_write_binary_el(db_path);
|
||||
return el_str_concat(el_str_concat(EL_STR("{\"ok\":true,\"id\":\""), id), EL_STR("\"}"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t route_neuron_knowledge_evolve(el_val_t method, el_val_t path, el_val_t body) {
|
||||
el_val_t content = json_get_string(body, EL_STR("content"));
|
||||
el_val_t prior_id = json_get_string(body, EL_STR("id"));
|
||||
if (str_eq(content, EL_STR(""))) {
|
||||
return EL_STR("{\"ok\":true}");
|
||||
}
|
||||
el_val_t id = engram_node_full(content, EL_STR("Knowledge"), EL_STR(""), el_from_float(0.7), el_from_float(0.7), el_from_float(1.0), EL_STR("Semantic"), EL_STR("evolved"));
|
||||
if (!str_eq(prior_id, EL_STR("")) && !str_eq(id, EL_STR(""))) {
|
||||
engram_connect(id, prior_id, el_from_float(1.0), EL_STR("supersedes"));
|
||||
}
|
||||
el_val_t dir = env(EL_STR("ENGRAM_DATA_DIR"));
|
||||
if (str_eq(dir, EL_STR(""))) {
|
||||
dir = EL_STR("/tmp/engram");
|
||||
}
|
||||
engram_write_binary_el(el_str_concat(dir, EL_STR("/engram.db")));
|
||||
return el_str_concat(el_str_concat(EL_STR("{\"ok\":true,\"id\":\""), id), EL_STR("\"}"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t route_neuron_knowledge_promote(el_val_t method, el_val_t path, el_val_t body) {
|
||||
return EL_STR("{\"ok\":true}");
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t route_neuron_recall(el_val_t method, el_val_t path, el_val_t body) {
|
||||
el_val_t query = json_get_string(body, EL_STR("query"));
|
||||
el_val_t chain = json_get_string(body, EL_STR("chain_name"));
|
||||
el_val_t limit = json_get_int(body, EL_STR("limit"));
|
||||
if (limit == 0) {
|
||||
limit = 20;
|
||||
}
|
||||
el_val_t q = ({ el_val_t _if_result_3 = 0; if (str_eq(query, EL_STR(""))) { _if_result_3 = (chain); } else { _if_result_3 = (query); } _if_result_3; });
|
||||
if (str_eq(q, EL_STR(""))) {
|
||||
return engram_scan_nodes_json(limit, 0);
|
||||
}
|
||||
return engram_search_json(q, limit);
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t route_neuron_graph(el_val_t method, el_val_t path, el_val_t body) {
|
||||
el_val_t id = query_param(path, EL_STR("id"));
|
||||
if (str_eq(id, EL_STR(""))) {
|
||||
return EL_STR("{\"error\":\"id is required\"}");
|
||||
}
|
||||
el_val_t node_json = engram_get_node_json(id);
|
||||
return el_str_concat(el_str_concat(EL_STR("{\"ok\":true,\"node\":"), node_json), EL_STR(",\"neighbors\":[]}"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t route_neuron_graph_link(el_val_t method, el_val_t path, el_val_t body) {
|
||||
el_val_t from_id = json_get_string(body, EL_STR("from_id"));
|
||||
el_val_t to_id = json_get_string(body, EL_STR("to_id"));
|
||||
if (str_eq(from_id, EL_STR("")) || str_eq(to_id, EL_STR(""))) {
|
||||
return EL_STR("{\"error\":\"from_id and to_id are required\"}");
|
||||
}
|
||||
el_val_t relation = json_get_string(body, EL_STR("relation"));
|
||||
if (str_eq(relation, EL_STR(""))) {
|
||||
relation = EL_STR("related");
|
||||
}
|
||||
el_val_t weight = json_get_float(body, EL_STR("weight"));
|
||||
if (weight == el_from_float(0.0)) {
|
||||
weight = el_from_float(0.5);
|
||||
}
|
||||
engram_connect(from_id, to_id, weight, relation);
|
||||
return el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"ok\":true,\"from_id\":\""), from_id), EL_STR("\",\"to_id\":\"")), to_id), EL_STR("\",\"relation\":\"")), relation), EL_STR("\"}"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t route_neuron_list(el_val_t method, el_val_t path, el_val_t body) {
|
||||
el_val_t clean = strip_query(path);
|
||||
el_val_t prefix = EL_STR("/api/neuron/list/");
|
||||
el_val_t node_type = str_slice(clean, str_len(prefix), str_len(clean));
|
||||
el_val_t limit = query_int(path, EL_STR("limit"), 50);
|
||||
if (str_eq(node_type, EL_STR(""))) {
|
||||
return EL_STR("[]");
|
||||
}
|
||||
return engram_scan_nodes_by_type_json(node_type, limit, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t route_neuron_consolidate(el_val_t method, el_val_t path, el_val_t body) {
|
||||
el_val_t dir = env(EL_STR("ENGRAM_DATA_DIR"));
|
||||
if (str_eq(dir, EL_STR(""))) {
|
||||
dir = EL_STR("/tmp/engram");
|
||||
}
|
||||
el_val_t db_path = el_str_concat(dir, EL_STR("/engram.db"));
|
||||
engram_write_binary_el(db_path);
|
||||
el_val_t nc = engram_node_count();
|
||||
el_val_t ec = engram_edge_count();
|
||||
return el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"ok\":true,\"node_count\":"), int_to_str(nc)), EL_STR(",\"edge_count\":")), int_to_str(ec)), EL_STR("}"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t route_neuron_config(el_val_t method, el_val_t path, el_val_t body) {
|
||||
el_val_t key = query_param(path, EL_STR("key"));
|
||||
return el_str_concat(el_str_concat(EL_STR("{\"key\":\""), key), EL_STR("\",\"value\":\"\"}"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t route_neuron_state_events(el_val_t method, el_val_t path, el_val_t body) {
|
||||
if (str_eq(method, EL_STR("GET"))) {
|
||||
el_val_t limit_str = query_param(path, EL_STR("limit"));
|
||||
el_val_t limit = ({ el_val_t _if_result_4 = 0; if (str_eq(limit_str, EL_STR(""))) { _if_result_4 = (50); } else { _if_result_4 = (str_to_int(limit_str)); } _if_result_4; });
|
||||
return engram_scan_nodes_by_type_json(EL_STR("InternalStateEvent"), limit, 0);
|
||||
}
|
||||
el_val_t content = json_get_string(body, EL_STR("content"));
|
||||
if (str_eq(content, EL_STR(""))) {
|
||||
content = body;
|
||||
}
|
||||
el_val_t id = engram_node_full(content, EL_STR("InternalStateEvent"), EL_STR("state-event"), el_from_float(0.3), el_from_float(0.3), el_from_float(1.0), EL_STR("Working"), EL_STR("internal-state"));
|
||||
return el_str_concat(el_str_concat(EL_STR("{\"ok\":true,\"id\":\""), id), EL_STR("\"}"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t route_neuron_processes(el_val_t method, el_val_t path, el_val_t body) {
|
||||
return EL_STR("{\"ok\":true,\"processes\":[]}");
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t route_events_next(el_val_t method, el_val_t path, el_val_t body) {
|
||||
return EL_STR("{\"ok\":true,\"event\":null}");
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t route_events_ack(el_val_t method, el_val_t path, el_val_t body) {
|
||||
return EL_STR("{\"ok\":true}");
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t check_auth_ok(el_val_t method, el_val_t body) {
|
||||
el_val_t key = env(EL_STR("ENGRAM_API_KEY"));
|
||||
if (str_eq(key, EL_STR(""))) {
|
||||
@@ -299,6 +639,60 @@ el_val_t handle_request(el_val_t method, el_val_t path, el_val_t body) {
|
||||
return route_health(method, path, body);
|
||||
}
|
||||
}
|
||||
if (str_starts_with(clean, EL_STR("/api/neuron/")) || str_starts_with(clean, EL_STR("/events/"))) {
|
||||
if (str_eq(clean, EL_STR("/api/neuron/session/begin"))) {
|
||||
return route_neuron_session_begin(method, path, body);
|
||||
}
|
||||
if (str_eq(clean, EL_STR("/api/neuron/ctx"))) {
|
||||
return route_neuron_ctx(method, path, body);
|
||||
}
|
||||
if (str_eq(clean, EL_STR("/api/neuron/memory"))) {
|
||||
return route_neuron_memory(method, path, body);
|
||||
}
|
||||
if (str_eq(clean, EL_STR("/api/neuron/knowledge/capture"))) {
|
||||
return route_neuron_knowledge_capture(method, path, body);
|
||||
}
|
||||
if (str_eq(clean, EL_STR("/api/neuron/knowledge/evolve"))) {
|
||||
return route_neuron_knowledge_evolve(method, path, body);
|
||||
}
|
||||
if (str_eq(clean, EL_STR("/api/neuron/knowledge/promote"))) {
|
||||
return route_neuron_knowledge_promote(method, path, body);
|
||||
}
|
||||
if (str_eq(clean, EL_STR("/api/neuron/recall"))) {
|
||||
return route_neuron_recall(method, path, body);
|
||||
}
|
||||
if (str_eq(clean, EL_STR("/api/neuron/graph/link"))) {
|
||||
return route_neuron_graph_link(method, path, body);
|
||||
}
|
||||
if (str_eq(clean, EL_STR("/api/neuron/graph"))) {
|
||||
return route_neuron_graph(method, path, body);
|
||||
}
|
||||
if (str_starts_with(clean, EL_STR("/api/neuron/list/"))) {
|
||||
return route_neuron_list(method, path, body);
|
||||
}
|
||||
if (str_eq(clean, EL_STR("/api/neuron/consolidate"))) {
|
||||
return route_neuron_consolidate(method, path, body);
|
||||
}
|
||||
if (str_eq(clean, EL_STR("/api/neuron/config"))) {
|
||||
return route_neuron_config(method, path, body);
|
||||
}
|
||||
if (str_eq(clean, EL_STR("/api/neuron/state-events"))) {
|
||||
return route_neuron_state_events(method, path, body);
|
||||
}
|
||||
if (str_eq(clean, EL_STR("/api/neuron/processes/define"))) {
|
||||
return route_neuron_processes(method, path, body);
|
||||
}
|
||||
if (str_eq(clean, EL_STR("/api/neuron/processes"))) {
|
||||
return route_neuron_processes(method, path, body);
|
||||
}
|
||||
if (str_eq(clean, EL_STR("/events/next"))) {
|
||||
return route_events_next(method, path, body);
|
||||
}
|
||||
if (str_eq(clean, EL_STR("/events/ack"))) {
|
||||
return route_events_ack(method, path, body);
|
||||
}
|
||||
return err_json(EL_STR("not found"));
|
||||
}
|
||||
if (!check_auth_ok(method, body)) {
|
||||
return err_json(EL_STR("unauthorized"));
|
||||
}
|
||||
@@ -341,12 +735,74 @@ el_val_t handle_request(el_val_t method, el_val_t path, el_val_t body) {
|
||||
if (str_eq(method, EL_STR("POST")) && (str_eq(clean, EL_STR("/api/strengthen")) || str_eq(clean, EL_STR("/strengthen")))) {
|
||||
return route_strengthen(method, path, body);
|
||||
}
|
||||
if (str_eq(method, EL_STR("POST")) && ((str_eq(clean, EL_STR("/api/decay")) || str_eq(clean, EL_STR("/api/maintenance"))) || str_eq(clean, EL_STR("/decay")))) {
|
||||
return route_decay(method, path, body);
|
||||
}
|
||||
if (str_eq(method, EL_STR("POST")) && (str_eq(clean, EL_STR("/api/export")) || str_eq(clean, EL_STR("/export")))) {
|
||||
return route_export(method, path, body);
|
||||
}
|
||||
if (str_eq(method, EL_STR("POST")) && (str_eq(clean, EL_STR("/api/save")) || str_eq(clean, EL_STR("/save")))) {
|
||||
return route_save(method, path, body);
|
||||
return route_export(method, path, body);
|
||||
}
|
||||
if (str_eq(method, EL_STR("POST")) && (str_eq(clean, EL_STR("/api/load")) || str_eq(clean, EL_STR("/load")))) {
|
||||
return route_load(method, path, body);
|
||||
}
|
||||
if (str_eq(method, EL_STR("POST")) && (str_eq(clean, EL_STR("/api/reindex")) || str_eq(clean, EL_STR("/reindex")))) {
|
||||
return route_reindex(method, path, body);
|
||||
}
|
||||
if (str_starts_with(clean, EL_STR("/api/neuron/"))) {
|
||||
if (str_eq(clean, EL_STR("/api/neuron/session/begin"))) {
|
||||
return route_neuron_session_begin(method, path, body);
|
||||
}
|
||||
if (str_eq(clean, EL_STR("/api/neuron/ctx"))) {
|
||||
return route_neuron_ctx(method, path, body);
|
||||
}
|
||||
if (str_eq(clean, EL_STR("/api/neuron/memory"))) {
|
||||
return route_neuron_memory(method, path, body);
|
||||
}
|
||||
if (str_eq(clean, EL_STR("/api/neuron/knowledge/capture"))) {
|
||||
return route_neuron_knowledge_capture(method, path, body);
|
||||
}
|
||||
if (str_eq(clean, EL_STR("/api/neuron/knowledge/evolve"))) {
|
||||
return route_neuron_knowledge_evolve(method, path, body);
|
||||
}
|
||||
if (str_eq(clean, EL_STR("/api/neuron/knowledge/promote"))) {
|
||||
return route_neuron_knowledge_promote(method, path, body);
|
||||
}
|
||||
if (str_eq(clean, EL_STR("/api/neuron/recall"))) {
|
||||
return route_neuron_recall(method, path, body);
|
||||
}
|
||||
if (str_eq(clean, EL_STR("/api/neuron/graph/link"))) {
|
||||
return route_neuron_graph_link(method, path, body);
|
||||
}
|
||||
if (str_eq(clean, EL_STR("/api/neuron/graph"))) {
|
||||
return route_neuron_graph(method, path, body);
|
||||
}
|
||||
if (str_starts_with(clean, EL_STR("/api/neuron/list/"))) {
|
||||
return route_neuron_list(method, path, body);
|
||||
}
|
||||
if (str_eq(clean, EL_STR("/api/neuron/consolidate"))) {
|
||||
return route_neuron_consolidate(method, path, body);
|
||||
}
|
||||
if (str_eq(clean, EL_STR("/api/neuron/config"))) {
|
||||
return route_neuron_config(method, path, body);
|
||||
}
|
||||
if (str_eq(clean, EL_STR("/api/neuron/state-events"))) {
|
||||
return route_neuron_state_events(method, path, body);
|
||||
}
|
||||
if (str_eq(clean, EL_STR("/api/neuron/processes/define"))) {
|
||||
return route_neuron_processes(method, path, body);
|
||||
}
|
||||
if (str_eq(clean, EL_STR("/api/neuron/processes"))) {
|
||||
return route_neuron_processes(method, path, body);
|
||||
}
|
||||
}
|
||||
if (str_eq(clean, EL_STR("/events/next"))) {
|
||||
return route_events_next(method, path, body);
|
||||
}
|
||||
if (str_eq(clean, EL_STR("/events/ack"))) {
|
||||
return route_events_ack(method, path, body);
|
||||
}
|
||||
return el_str_concat(el_str_concat(EL_STR("{\"error\":\"not found\",\"path\":\""), clean), EL_STR("\"}"));
|
||||
return 0;
|
||||
}
|
||||
@@ -362,9 +818,20 @@ int main(int _argc, char** _argv) {
|
||||
if (str_eq(data_dir, EL_STR(""))) {
|
||||
data_dir = EL_STR("/tmp/engram");
|
||||
}
|
||||
snapshot_path = el_str_concat(data_dir, EL_STR("/snapshot.json"));
|
||||
engram_load(snapshot_path);
|
||||
println(EL_STR("[engram] runtime-native graph engine"));
|
||||
db_path = el_str_concat(data_dir, EL_STR("/engram.db"));
|
||||
loaded = engram_load_binary_el(db_path);
|
||||
if (!loaded) {
|
||||
engram_load_dir(data_dir);
|
||||
if (engram_node_count() == 0) {
|
||||
el_val_t snapshot_path = el_str_concat(data_dir, EL_STR("/snapshot.json"));
|
||||
engram_load(snapshot_path);
|
||||
}
|
||||
if (engram_node_count() > 0) {
|
||||
engram_write_binary_el(db_path);
|
||||
println(EL_STR("[engram] migrated legacy data to binary format"));
|
||||
}
|
||||
}
|
||||
println(EL_STR("[engram] runtime-native graph engine (ML-KEM-1024 encrypted)"));
|
||||
println(el_str_concat(EL_STR("[engram] data_dir="), data_dir));
|
||||
println(el_str_concat(EL_STR("[engram] node_count="), int_to_str(engram_node_count())));
|
||||
println(el_str_concat(EL_STR("[engram] edge_count="), int_to_str(engram_edge_count())));
|
||||
|
||||
Reference in New Issue
Block a user