Updated semantic, and added entities/relationship implementation
This commit is contained in:
@@ -4,6 +4,7 @@ const {getEnv} = require('@nexusai/shared');
|
||||
const { getDB } = require('./db');
|
||||
const episodic = require('./episodic');
|
||||
const semantic = require('./semantic');
|
||||
const entities = require('./entities');
|
||||
|
||||
const app = express();
|
||||
app.use(express.json());
|
||||
@@ -94,6 +95,68 @@ app.delete('/episodes/:id', (req, res) => {
|
||||
res.status(204).send();
|
||||
});
|
||||
|
||||
/*********************************** */
|
||||
/********** Entity Routes ********** */
|
||||
/*********************************** */
|
||||
//Upsert an entity, creates or updates if already exists
|
||||
app.post('/entities', (req, res) => {
|
||||
const {name, type, notes, metadata} = req.body;
|
||||
if (!name || !type) {
|
||||
return res.status(400).json({ error: 'name and type are required' });
|
||||
}
|
||||
const entity = entities.upsertEntity(name, type, notes, metadata);
|
||||
res.status(201).json(entity);
|
||||
});
|
||||
|
||||
// Get an entity by ID
|
||||
app.get('/entities/:id', (req, res) => {
|
||||
const entity = entities.getEntity(req.params.id);
|
||||
if (!entity) return res.status(404).json({ error: 'Entity not found' });
|
||||
res.json(entity);
|
||||
});
|
||||
|
||||
// Get all entities of a given type
|
||||
app.get('/entities/by-type/:type', (req, res) => {
|
||||
res.json(entities.getEntitiesByType(req.params.type));
|
||||
});
|
||||
|
||||
// Delete an entity by ID
|
||||
app.delete('/entities/:id', (req, res) => {
|
||||
entities.deleteEntity(req.params.id);
|
||||
res.status(204).send();
|
||||
});
|
||||
|
||||
/***************************************** */
|
||||
/********** Relationship Routes ********** */
|
||||
/***************************************** */
|
||||
|
||||
// Upsert a relationship between two entities
|
||||
app.post('/relationships', (req, res) => {
|
||||
const {fromId, toId, label, metadata } = req.body;
|
||||
if (!fromId || !toId || !label) {
|
||||
return res.status(400).json({ error: 'fromId, toId and label are required' });
|
||||
}
|
||||
const relationship = entities.upsertRelationship(fromId, toId, label, metadata);
|
||||
res.status(201).json(relationship);
|
||||
});
|
||||
|
||||
// Get all relationships for a given entity ID
|
||||
app.get('/entities/:id/relationships', (req, res) => {
|
||||
res.json(entities.getRelationshipsByEntity(req.params.id));
|
||||
});
|
||||
|
||||
// Delete a specific relationship
|
||||
app.delete('/relationships', (req, res) => {
|
||||
const {fromId, toId, label} = req.body;
|
||||
if (!fromId || !toId || !label) {
|
||||
return res.status(400).json({ error: 'fromId, toId and label are required' });
|
||||
}
|
||||
entities.deleteRelationship(fromId, toId, label);
|
||||
res.status(204).send();
|
||||
})
|
||||
|
||||
|
||||
|
||||
/********************************** */
|
||||
/********** Start Server ********** */
|
||||
/********************************** */
|
||||
|
||||
Reference in New Issue
Block a user