Added orchestration layer

This commit is contained in:
Storme-bit
2026-04-05 05:27:04 -07:00
parent 4b3f6455f9
commit eccda21992
5 changed files with 161 additions and 8 deletions

View File

@@ -0,0 +1,18 @@
const fetch = require('node-fetch');
const { getEnv } = require('@nexusai/shared');
const BASE_URL = getEnv('INFERENCE_SERVICE_URL', 'http://localhost:3001');
async function complete(prompt, options ={}) {
const res = await fetch(`${BASE_URL}/complete`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ prompt, ...options })
})
if (!res.ok) throw new Error(`Inference service error: ${res.status} ${res.statusText}`);
return res.json();
}
module.exports = {
complete
}

View File

@@ -0,0 +1,48 @@
const fetch = require('node-fetch');
const { getEnv } = require('@nexusai/shared');
const BASE_URL = getEnv('MEMORY_SERVICE_URL', 'http://localhost:3002');
//function to get session by external id, returns null if not found, throws error for other issues
async function getSessionByExternalId(externalId) {
const res = await fetch(`${BASE_URL}/sessions/by-external/${externalId}`);
if (!res.status === 400) return null; // Not found or bad request
if (!res.ok) throw new Error(`Memory service error: ${res.status} ${res.statusText}`); // Other errors
return res.json();
}
// create a new session with an external ID, returns the created session
async function createSession(externalId) {
const res = await fetch(`${BASE_URL}/sessions`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ externalId })
});
if (!res.ok) throw new Error(`Failed to create sessions: ${res.status} ${res.statusText}`);
return res.json();
}
async function getRecentEpisodes(sessionId, limit = 10) {
const res = await fetch(`${BASE_URL}/sessions/${sessionId}/episodes/recent?limit=${limit}`);
if (!res.ok) throw new Error(`Failed to fetch episodes: ${res.status} ${res.statusText}`);
return res.json();
}
async function createEpisode(sessionId, userMessage, aiResponse, tokenCount) {
const res = await fetch(`${BASE_URL}/episodes`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ sessionId, userMessage, aiResponse, tokenCount })
});
if (!res.ok) throw new Error(`Failed to create episode: ${res.status} ${res.statusText}`);
return res.json();
}
module.exports = {
getSessionByExternalId,
createSession,
getRecentEpisodes,
createEpisode
}