UNPKG

memofai

Version:

Official JavaScript/TypeScript SDK for Memory-of-Agents (MOA) - AI memory infrastructure for intelligent applications

121 lines 4.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.NetworkError = exports.RequestLimitError = exports.ServiceUnavailableError = exports.NotFoundError = exports.AuthorizationError = exports.AuthenticationError = exports.ValidationError = exports.ApiError = exports.ENVIRONMENTS = void 0; exports.ENVIRONMENTS = { dev: { baseURL: 'http://127.0.0.1:8000', description: 'Development environment for internal testing', }, alpha: { baseURL: 'https://alpha-api.memof.ai', description: 'Alpha environment for early testing', }, beta: { baseURL: 'https://beta-api.memof.ai', description: 'Beta environment for pre-production testing', }, sandbox: { baseURL: 'https://sandbox-api.memof.ai', description: 'Sandbox environment for development and testing', }, production: { baseURL: 'https://api.memof.ai', description: 'Production environment', }, }; class ApiError extends Error { constructor(message, status, statusText, response) { super(message); this.name = 'ApiError'; this.status = status; this.statusText = statusText; this.response = response; this.timestamp = new Date().toISOString(); Object.setPrototypeOf(this, ApiError.prototype); } isSubscriptionError() { return (this.response.error_type === 'subscription_required' || this.response.error_type === 'subscription_expired'); } getResourceType() { return this.response.resource_type; } getLimit() { return this.response.limit; } getCurrentUsage() { return this.response.current_usage; } } exports.ApiError = ApiError; class ValidationError extends ApiError { constructor(status, statusText, response) { super('Validation failed', status, statusText, response); Object.setPrototypeOf(this, ValidationError.prototype); this.name = 'ValidationError'; this.validationErrors = this.parseValidationErrors(response); } parseValidationErrors(response) { const errors = []; for (const [field, message] of Object.entries(response)) { if (Array.isArray(message)) { message.forEach(msg => errors.push({ field, message: msg })); } else if (typeof message === 'string') { errors.push({ field, message }); } } return errors; } } exports.ValidationError = ValidationError; class AuthenticationError extends ApiError { constructor(status, statusText, response) { super('Authentication required', status, statusText, response); this.name = 'AuthenticationError'; Object.setPrototypeOf(this, AuthenticationError.prototype); } } exports.AuthenticationError = AuthenticationError; class AuthorizationError extends ApiError { constructor(status, statusText, response) { super('Permission denied', status, statusText, response); this.name = 'AuthorizationError'; Object.setPrototypeOf(this, AuthorizationError.prototype); } } exports.AuthorizationError = AuthorizationError; class NotFoundError extends ApiError { constructor(status, statusText, response) { super('Resource not found', status, statusText, response); this.name = 'NotFoundError'; Object.setPrototypeOf(this, NotFoundError.prototype); } } exports.NotFoundError = NotFoundError; class ServiceUnavailableError extends ApiError { constructor(status, statusText, response) { super('Service temporarily unavailable', status, statusText, response); this.name = 'ServiceUnavailableError'; Object.setPrototypeOf(this, ServiceUnavailableError.prototype); } } exports.ServiceUnavailableError = ServiceUnavailableError; class RequestLimitError extends ApiError { constructor(status, statusText, response) { super('Monthly request limit exceeded', status, statusText, response); this.name = 'RequestLimitError'; Object.setPrototypeOf(this, RequestLimitError.prototype); } } exports.RequestLimitError = RequestLimitError; class NetworkError extends Error { constructor(message, originalError) { super(message); this.name = 'NetworkError'; this.originalError = originalError; Object.setPrototypeOf(this, NetworkError.prototype); } } exports.NetworkError = NetworkError; //# sourceMappingURL=types.js.map