memofai
Version:
Official JavaScript/TypeScript SDK for Memory-of-Agents (MOA) - AI memory infrastructure for intelligent applications
95 lines • 3.19 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MoaClient = void 0;
const http_client_1 = require("./http-client");
const endpoints_1 = require("./endpoints");
class WorkspaceNamespace {
constructor(request) {
this.request = request;
}
async list() {
return this.request('listWorkspaces');
}
async create(data) {
return this.request('createWorkspace', undefined, undefined, data);
}
async retrieve(workspaceId) {
return this.request('retrieveWorkspace', { workspace_id: workspaceId });
}
async update(workspaceId, data) {
return this.request('updateWorkspace', { workspace_id: workspaceId }, undefined, data);
}
async delete(workspaceId) {
return this.request('deleteWorkspace', { workspace_id: workspaceId });
}
}
class BotNamespace {
constructor(request) {
this.request = request;
}
async list() {
return this.request('listBots');
}
async create(data) {
return this.request('createBot', undefined, undefined, data);
}
async retrieve(botId) {
return this.request('retrieveBot', { bot_id: botId });
}
async update(botId, data) {
return this.request('updateBot', { bot_id: botId }, undefined, data);
}
async delete(botId) {
return this.request('deleteBot', { bot_id: botId });
}
}
class MemoryNamespace {
constructor(request) {
this.request = request;
}
async store(data) {
return this.request('storeMemory', undefined, undefined, data);
}
async list(botId, queryParams) {
return this.request('listMemory', { bot_id: botId }, queryParams);
}
async reprocess(memoryId) {
return this.request('reprocessMemory', { memory_id: memoryId });
}
async delete(memoryId) {
return this.request('deleteMemory', { memory_id: memoryId });
}
async search(data) {
return this.request('searchMemories', undefined, undefined, data);
}
}
class MoaClient {
constructor(config) {
this.httpClient = new http_client_1.HttpClient(config);
this.workspaces = new WorkspaceNamespace(this.request.bind(this));
this.bots = new BotNamespace(this.request.bind(this));
this.memories = new MemoryNamespace(this.request.bind(this));
}
async request(endpointName, pathParams, queryParams, body, headers) {
const endpoint = endpoints_1.API_ENDPOINTS[endpointName];
let path = endpoint.path;
if (pathParams) {
for (const [key, value] of Object.entries(pathParams)) {
path = path.replace(`:${key}`, value);
}
}
const cleanQueryParams = queryParams
? Object.fromEntries(Object.entries(queryParams).filter(([_, v]) => v !== undefined))
: undefined;
const response = await this.httpClient.request({
path,
method: endpoint.method,
queryParams: cleanQueryParams,
body,
headers,
});
return response.data;
}
}
exports.MoaClient = MoaClient;
//# sourceMappingURL=api-client.js.map