UNPKG

recallrai

Version:

Official Node.js SDK for RecallrAI - Revolutionary contextual memory system that enables AI assistants to form meaningful connections between conversations, just like human memory.

88 lines (87 loc) 3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RecallrAI = void 0; const http_client_1 = require("./utils/http-client"); const user_1 = require("./user"); const user_2 = require("./models/user"); const errors_1 = require("./errors"); class RecallrAI { /** * Initialize the RecallrAI client. * * @param options Configuration options for the client */ constructor(options) { const { apiKey, projectId, baseUrl = 'https://api.recallrai.com', timeout = 30000 } = options; if (!apiKey.startsWith('rai_')) { throw new Error('API key must start with "rai_"'); } this.apiKey = apiKey; this.projectId = projectId; this.baseUrl = baseUrl; this.http = new http_client_1.HTTPClient({ apiKey: this.apiKey, projectId: this.projectId, baseUrl: this.baseUrl, timeout }); } /** * Create a new user. * * @param userId Unique identifier for the user * @param metadata Optional metadata to associate with the user * @returns The created user object * @throws {UserAlreadyExistsError} If a user with the same ID already exists */ async createUser(userId, metadata = {}) { try { const response = await this.http.post('/api/v1/users', { user_id: userId, metadata }); const userData = user_2.UserModel.fromApiResponse(response.data); return new user_1.User(this.http, userData); } catch (error) { if (error.status === 409) { throw new errors_1.UserAlreadyExistsError(userId); } throw error; } } /** * Get a user by ID. * * @param userId Unique identifier of the user * @returns A User object representing the user * @throws {UserNotFoundError} If the user is not found */ async getUser(userId) { try { const response = await this.http.get(`/api/v1/users/${userId}`); const userData = user_2.UserModel.fromApiResponse(response.data); return new user_1.User(this.http, userData); } catch (error) { if (error.status === 404) { throw new errors_1.UserNotFoundError(userId); } throw error; } } /** * List users with pagination. * * @param offset Number of records to skip * @param limit Maximum number of records to return * @returns List of users with pagination info */ async listUsers(offset = 0, limit = 10) { try { const response = await this.http.get('/api/v1/users', { params: { offset, limit } }); return user_2.UserList.fromApiResponse(response.data); } catch (error) { throw new errors_1.RecallrAIError('Failed to list users', undefined, error.status); } } } exports.RecallrAI = RecallrAI;