Expose node/create endpoint and respect label field in memory writes
This commit is contained in:
+31
-1
@@ -27871,7 +27871,9 @@ el_val_t handle_api_remember(el_val_t body) {
|
||||
el_val_t sal = ({ el_val_t _if_result_305 = 0; if (str_eq(sal_str, EL_STR("0.95"))) { _if_result_305 = (el_from_float(0.95)); } else { _if_result_305 = (({ el_val_t _if_result_306 = 0; if (str_eq(sal_str, EL_STR("0.75"))) { _if_result_306 = (el_from_float(0.75)); } else { _if_result_306 = (({ el_val_t _if_result_307 = 0; if (str_eq(sal_str, EL_STR("0.25"))) { _if_result_307 = (el_from_float(0.25)); } else { _if_result_307 = (el_from_float(0.5)); } _if_result_307; })); } _if_result_306; })); } _if_result_305; });
|
||||
el_val_t base_tags = ({ el_val_t _if_result_308 = 0; if (str_eq(tags_raw, EL_STR(""))) { _if_result_308 = (EL_STR("[\"Memory\"]")); } else { _if_result_308 = (tags_raw); } _if_result_308; });
|
||||
el_val_t final_tags = ({ el_val_t _if_result_309 = 0; if (str_eq(project, EL_STR(""))) { _if_result_309 = (base_tags); } else { el_val_t inner = str_slice(base_tags, 1, (str_len(base_tags) - 1)); _if_result_309 = (el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("["), inner), EL_STR(",\"project:")), project), EL_STR("\"]"))); } _if_result_309; });
|
||||
el_val_t id = engram_node_full(content, EL_STR("Memory"), EL_STR("memory:remembered"), el_from_float(sal), el_from_float(sal), el_from_float(el_from_float(0.9)), EL_STR("Episodic"), final_tags);
|
||||
el_val_t req_label = json_get(body, EL_STR("label"));
|
||||
el_val_t eff_label = (str_eq(req_label, EL_STR("")) ? EL_STR("memory:remembered") : req_label);
|
||||
el_val_t id = engram_node_full(content, EL_STR("Memory"), eff_label, el_from_float(sal), el_from_float(sal), el_from_float(el_from_float(0.9)), EL_STR("Episodic"), final_tags);
|
||||
if (str_eq(id, EL_STR(""))) {
|
||||
return EL_STR("{\"ok\":false,\"error\":\"write_not_persisted\",\"id\":\"\"}");
|
||||
}
|
||||
@@ -27884,6 +27886,31 @@ el_val_t handle_api_remember(el_val_t body) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t handle_api_node_create(el_val_t body) {
|
||||
el_val_t content = json_get(body, EL_STR("content"));
|
||||
if (str_eq(content, EL_STR(""))) {
|
||||
return api_err(EL_STR("content is required"));
|
||||
}
|
||||
el_val_t label = json_get(body, EL_STR("label"));
|
||||
el_val_t eff_label = (str_eq(label, EL_STR("")) ? EL_STR("memory:remembered") : label);
|
||||
el_val_t node_type = json_get(body, EL_STR("node_type"));
|
||||
el_val_t eff_type = (str_eq(node_type, EL_STR("")) ? EL_STR("Episodic") : node_type);
|
||||
el_val_t tags_raw = json_get(body, EL_STR("tags"));
|
||||
el_val_t eff_tags = (str_eq(tags_raw, EL_STR("")) ? EL_STR("[\"Memory\"]") : tags_raw);
|
||||
el_val_t importance = json_get(body, EL_STR("importance"));
|
||||
el_val_t sal = (str_eq(importance, EL_STR("critical")) ? el_from_float(0.95) : (str_eq(importance, EL_STR("high")) ? el_from_float(0.75) : (str_eq(importance, EL_STR("low")) ? el_from_float(0.25) : el_from_float(0.7))));
|
||||
el_val_t id = engram_node_full(content, EL_STR("Memory"), eff_label, sal, sal, el_from_float(0.9), eff_type, eff_tags);
|
||||
if (str_eq(id, EL_STR(""))) {
|
||||
return EL_STR("{\"ok\":false,\"error\":\"write_not_persisted\",\"id\":\"\"}");
|
||||
}
|
||||
el_val_t readback = engram_get_node_json(id);
|
||||
if (str_eq(readback, EL_STR("")) || str_eq(readback, EL_STR("{}"))) {
|
||||
return el_str_concat(el_str_concat(EL_STR("{\"ok\":false,\"error\":\"write_not_persisted\",\"id\":\""), id), EL_STR("\"}"));
|
||||
}
|
||||
return el_str_concat(el_str_concat(EL_STR("{\"id\":\""), id), EL_STR("\",\"ok\":true}"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t handle_api_recall(el_val_t method, el_val_t path, el_val_t body) {
|
||||
el_val_t q = ({ el_val_t _if_result_310 = 0; if (str_eq(method, EL_STR("GET"))) { _if_result_310 = (api_query_param(path, EL_STR("query"))); } else { _if_result_310 = (json_get(body, EL_STR("query"))); } _if_result_310; });
|
||||
el_val_t chain = json_get(body, EL_STR("chain_name"));
|
||||
@@ -29074,6 +29101,9 @@ el_val_t handle_request(el_val_t method, el_val_t path, el_val_t body) {
|
||||
if (str_eq(clean, EL_STR("/api/neuron/graph/link"))) {
|
||||
return handle_api_link_entities(body);
|
||||
}
|
||||
if (str_eq(clean, EL_STR("/api/neuron/node/create"))) {
|
||||
return handle_api_node_create(body);
|
||||
}
|
||||
if (str_eq(clean, EL_STR("/api/neuron/memory"))) {
|
||||
return handle_api_remember(body);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user