UNPKG

ragatanga-mcp-sdk

Version:

SDK for integrating with the Ragatanga Management Control Plane (MCP) with Next.js 15, React 19, WebSocket and Arrow IPC support

274 lines (271 loc) 10 kB
var __defProp = Object.defineProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); // src/errors/ontology-errors.ts var _OntologyError = class _OntologyError extends MCPError { constructor(message, options) { super(message, options); this.name = "OntologyError"; } }; __name(_OntologyError, "OntologyError"); var OntologyError = _OntologyError; var _OntologyEntityNotFoundError = class _OntologyEntityNotFoundError extends OntologyError { constructor(entityUri, message, options) { super(message || `Entity not found: ${entityUri}`, options); this.name = "OntologyEntityNotFoundError"; this.entityUri = entityUri; } }; __name(_OntologyEntityNotFoundError, "OntologyEntityNotFoundError"); var OntologyEntityNotFoundError = _OntologyEntityNotFoundError; var _OntologySparqlError = class _OntologySparqlError extends OntologyError { constructor(query, message, options) { super(message || `Invalid SPARQL query: ${query}`, options); this.name = "OntologySparqlError"; this.query = query; } }; __name(_OntologySparqlError, "OntologySparqlError"); var OntologySparqlError = _OntologySparqlError; var _OntologyModificationError = class _OntologyModificationError extends OntologyError { constructor(operation, entityUri, message, options) { super( message || `Failed to ${operation}${entityUri ? ` entity: ${entityUri}` : ""}`, options ); this.name = "OntologyModificationError"; this.operation = operation; this.entityUri = entityUri; } }; __name(_OntologyModificationError, "OntologyModificationError"); var OntologyModificationError = _OntologyModificationError; var _OntologyPaginationError = class _OntologyPaginationError extends OntologyError { constructor(cursor, message, options) { super( message || `Invalid pagination${cursor ? ` cursor: ${cursor}` : ""}`, options ); this.name = "OntologyPaginationError"; this.cursor = cursor; } }; __name(_OntologyPaginationError, "OntologyPaginationError"); var OntologyPaginationError = _OntologyPaginationError; function parseOntologyError(error) { if (error instanceof OntologyError) { return error; } if (error instanceof HTTPError) { const errorData = error.data; const status = error.status; const message = errorData?.message || error.message; if (status === 404) { const entityUriMatch = message.match(/Entity not found: (.+)/); if (entityUriMatch) { return new OntologyEntityNotFoundError(entityUriMatch[1], message, { cause: error }); } } else if (status === 400) { if (message.includes("SPARQL") || message.includes("query")) { const queryMatch = message.match(/query: (.+)/); const query = queryMatch ? queryMatch[1] : "unknown query"; return new OntologySparqlError(query, message, { cause: error }); } if (message.includes("cursor") || message.includes("pagination")) { const cursorMatch = message.match(/cursor: (.+)/); const cursor = cursorMatch ? cursorMatch[1] : void 0; return new OntologyPaginationError(cursor, message, { cause: error }); } } if (message.includes("Failed to")) { const operationMatch = message.match(/Failed to (\w+)/); const entityUriMatch = message.match(/entity: (.+)/); if (operationMatch) { return new OntologyModificationError( operationMatch[1], entityUriMatch ? entityUriMatch[1] : void 0, message, { cause: error } ); } } } return new OntologyError(error.message, { cause: error }); } __name(parseOntologyError, "parseOntologyError"); // src/errors/index.ts var _MCPError = class _MCPError extends Error { constructor(message, options) { super(message); this.name = "MCPError"; this.status = options?.status; this.code = options?.code; this.cause = options?.cause; Object.setPrototypeOf(this, _MCPError.prototype); } /** * Creates a formatted error message with all available details */ toFormattedString() { const parts = [ `[${this.name}] ${this.message}`, this.code ? `Code: ${this.code}` : null, this.status ? `Status: ${this.status}` : null, this.cause ? `Cause: ${this.cause instanceof Error ? this.cause.message : String(this.cause)}` : null ].filter(Boolean); return parts.join(" | "); } }; __name(_MCPError, "MCPError"); var MCPError = _MCPError; var _NetworkError = class _NetworkError extends MCPError { constructor(message, options) { super(message, { status: 0, code: options?.code || "NETWORK_ERROR", cause: options?.cause }); this.name = "NetworkError"; Object.setPrototypeOf(this, _NetworkError.prototype); } }; __name(_NetworkError, "NetworkError"); var NetworkError = _NetworkError; var _TimeoutError = class _TimeoutError extends MCPError { constructor(message = "Request timed out", options) { super(message, { status: 0, code: options?.code || "TIMEOUT", cause: options?.cause }); this.name = "TimeoutError"; Object.setPrototypeOf(this, _TimeoutError.prototype); } }; __name(_TimeoutError, "TimeoutError"); var TimeoutError = _TimeoutError; var _HTTPError = class _HTTPError extends MCPError { constructor(message, response, options) { super(message, { status: response.status, code: options?.code || `HTTP_${response.status}`, cause: options?.cause }); this.name = "HTTPError"; this.response = response; Object.setPrototypeOf(this, _HTTPError.prototype); } }; __name(_HTTPError, "HTTPError"); var HTTPError = _HTTPError; var _AuthError = class _AuthError extends MCPError { constructor(message, options) { super(message, { status: options?.status || 401, code: options?.code || "AUTH_ERROR", cause: options?.cause }); this.name = "AuthError"; this.response = options?.response; Object.setPrototypeOf(this, _AuthError.prototype); } }; __name(_AuthError, "AuthError"); var AuthError = _AuthError; var _UnauthorizedError = class _UnauthorizedError extends AuthError { constructor(message, options) { super(message, { status: 401, code: options?.code || "UNAUTHORIZED", cause: options?.cause, response: options?.response }); this.name = "UnauthorizedError"; Object.setPrototypeOf(this, _UnauthorizedError.prototype); } }; __name(_UnauthorizedError, "UnauthorizedError"); var UnauthorizedError = _UnauthorizedError; var _TenantNotFoundError = class _TenantNotFoundError extends HTTPError { constructor(message, options) { const mockResponse = new Response(null, { status: 404 }); super(message, mockResponse, { code: options?.code || "TENANT_NOT_FOUND", cause: options?.cause }); this.name = "TenantNotFoundError"; Object.setPrototypeOf(this, _TenantNotFoundError.prototype); } }; __name(_TenantNotFoundError, "TenantNotFoundError"); var TenantNotFoundError = _TenantNotFoundError; var _WebSocketError = class _WebSocketError extends MCPError { constructor(message, options) { super(message, { code: options?.code || "WEBSOCKET_ERROR", cause: options?.cause }); this.name = "WebSocketError"; this.event = options?.event; Object.setPrototypeOf(this, _WebSocketError.prototype); } }; __name(_WebSocketError, "WebSocketError"); var WebSocketError = _WebSocketError; var _ParseError = class _ParseError extends MCPError { constructor(message, options) { super(message, { code: options?.code || "PARSE_ERROR", cause: options?.cause }); this.name = "ParseError"; this.data = options?.data; Object.setPrototypeOf(this, _ParseError.prototype); } }; __name(_ParseError, "ParseError"); var ParseError = _ParseError; var _ValidationError = class _ValidationError extends MCPError { constructor(message, options) { super(message, { code: options?.code || "VALIDATION_ERROR", cause: options?.cause }); this.name = "ValidationError"; this.errors = options?.errors; Object.setPrototypeOf(this, _ValidationError.prototype); } }; __name(_ValidationError, "ValidationError"); var ValidationError = _ValidationError; function createError(error) { if (error instanceof MCPError) { return error; } if (error instanceof Error) { return new MCPError(error.message, { cause: error }); } return new MCPError(String(error)); } __name(createError, "createError"); function createHttpError(response) { const status = response.status; let message = `HTTP Error ${status}`; let code = `HTTP_${status}`; if (status === 400) { message = "Bad Request: The request was invalid"; return new HTTPError(message, response); } else if (status === 401) { message = "Unauthorized: Authentication is required"; return new AuthError(message, { status, code, response }); } else if (status === 403) { message = "Forbidden: You don't have permission to access this resource"; return new AuthError(message, { status, code, response }); } else if (status === 404) { message = "Not Found: The requested resource does not exist"; return new HTTPError(message, response); } else if (status === 429) { message = "Too Many Requests: Rate limit exceeded"; return new HTTPError(message, response); } else if (status >= 500) { message = "Server Error: Something went wrong on the server"; return new HTTPError(message, response); } return new HTTPError(message, response); } __name(createHttpError, "createHttpError"); export { AuthError, HTTPError, MCPError, NetworkError, OntologyEntityNotFoundError, OntologyError, OntologyModificationError, OntologyPaginationError, OntologySparqlError, ParseError, TenantNotFoundError, TimeoutError, UnauthorizedError, ValidationError, WebSocketError, createError, createHttpError, parseOntologyError }; //# sourceMappingURL=index.mjs.map //# sourceMappingURL=index.mjs.map