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cAAA,CAAA;AAsCT,SAAS,gBAAmB,MAA4C,EAAA;AAC7E,EAAA,OAAO,CAAC,IAAA,KAAkB,QAAS,CAAA,MAAA,EAAQ,IAAI,CAAA;AACjD;AAFgB,MAAA,CAAA,eAAA,EAAA,iBAAA,CAAA;AAOT,SAAS,oBAAuB,MAIrC,EAAA;AACA,EAAA,OAAO,CAAC,IAAA,KAAkB,YAAa,CAAA,MAAA,EAAQ,IAAI,CAAA;AACrD;AANgB,MAAA,CAAA,mBAAA,EAAA,qBAAA,CAAA;AAWT,SAAS,aAAA,CAAiB,QAAsB,IAAoB,EAAA;AACzE,EAAM,MAAA,WAAA,GAAcA,CAAE,CAAA,KAAA,CAAM,MAAM,CAAA;AAClC,EAAO,OAAA,QAAA,CAAS,aAAa,IAAI,CAAA;AACnC;AAHgB,MAAA,CAAA,aAAA,EAAA,eAAA,CAAA;AAQT,SAAS,gBAAA,CAAoB,QAAsB,IAAkB,EAAA;AAE1E,EAAA,MAAM,aAAaA,CAAE,CAAA,MAAA,CAAO,EAAE,EAAE,QAAS,EAAA;AACzC,EAAA,UAAA,CAAW,MAAM,IAAI,CAAA;AAGrB,EAAO,OAAA,QAAA,CAAS,QAAQ,IAAI,CAAA;AAC9B;AAPgB,MAAA,CAAA,gBAAA,EAAA,kBAAA,CAAA","file":"index.mjs","sourcesContent":["import { z } from 'zod';\n\n// Base schemas\n\n/**\n * Base schema for timestamps\n */\nexport const timestampSchema = z.string().regex(/^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$/);\n\n/**\n * Base schema for UUIDs\n */\nexport const uuidSchema = z.string().uuid();\n\n// API response schemas\n\n/**\n * Schema for OntologySummary\n */\nexport const ontologySummarySchema = z.object({\n  id: uuidSchema,\n  name: z.string().min(1),\n  createdAt: timestampSchema,\n  format: z.string().optional(),\n});\n\nexport type OntologySummarySchema = z.infer<typeof ontologySummarySchema>;\n\n/**\n * Schema for OntologyMetadata\n */\nexport const ontologyMetadataSchema = ontologySummarySchema.extend({\n  size: z.number().nonnegative().optional(),\n  updatedAt: timestampSchema.optional(),\n  entityCount: z.number().nonnegative().optional(),\n  owner: z.string().optional(),\n});\n\nexport type OntologyMetadataSchema = z.infer<typeof ontologyMetadataSchema>;\n\n/**\n * Schema for authentication information\n */\nexport const authSchema = z.object({\n  token: z.string(),\n  refreshToken: z.string().optional(),\n  expiresAt: timestampSchema.optional(),\n  userId: z.string().optional(),\n  permissions: z.array(z.string()).optional(),\n});\n\nexport type AuthSchema = z.infer<typeof authSchema>;\n\n/**\n * Schema for MCPContextSpec\n */\nexport const contextSpecSchema = z.object({\n  id: z.string(),\n  parameters: z.record(z.unknown()),\n});\n\nexport type ContextSpecSchema = z.infer<typeof contextSpecSchema>;\n\n/**\n * Schema for MCPContextRequest\n */\nexport const contextRequestSchema = z.object({\n  request_id: z.string(),\n  current_query: z.string(),\n  context_specs: z.array(contextSpecSchema),\n});\n\nexport type ContextRequestSchema = z.infer<typeof contextRequestSchema>;\n\n/**\n * Schema for MCPContextResponse\n */\nexport const contextResponseSchema = z.object({\n  responses: z.array(\n    z.object({\n      id: z.string(),\n      content: z.object({\n        type: z.string(),\n        value: z.string(),\n      }),\n      metadata: z.object({\n        confidence: z.number(),\n        source: z.string(),\n        timestamp: timestampSchema,\n      }).catchall(z.unknown()),\n    })\n  ),\n});\n\nexport type ContextResponseSchema = z.infer<typeof contextResponseSchema>;\n\n/**\n * Schema for error responses\n */\nexport const errorResponseSchema = z.object({\n  error: z.string(),\n  message: z.string(),\n  statusCode: z.number().optional(),\n  code: z.string().optional(),\n});\n\nexport type ErrorResponseSchema = z.infer<typeof errorResponseSchema>;\n\n/**\n * Schema for pagination metadata\n */\nexport const paginationSchema = z.object({\n  total: z.number().nonnegative(),\n  page: z.number().nonnegative(),\n  pageSize: z.number().positive(),\n  totalPages: z.number().nonnegative(),\n  hasMore: z.boolean(),\n});\n\nexport type PaginationSchema = z.infer<typeof paginationSchema>;\n\n/**\n * Generic paginated response schema\n */\nexport function createPaginatedSchema<T extends z.ZodTypeAny>(itemSchema: T) {\n  return z.object({\n    data: z.array(itemSchema),\n    pagination: paginationSchema,\n  });\n}\n\n/**\n * Schema for API limits/usage\n */\nexport const apiLimitsSchema = z.object({\n  limit: z.number().positive(),\n  remaining: z.number().nonnegative(),\n  reset: timestampSchema,\n});\n\nexport type ApiLimitsSchema = z.infer<typeof apiLimitsSchema>;\n","/**\n * Base error class for all MCP SDK errors\n */\nexport class MCPError extends Error {\n  status?: number;\n  code?: string;\n  cause?: unknown;\n\n  constructor(message: string, options?: { status?: number; code?: string; cause?: unknown }) {\n    super(message);\n    this.name = 'MCPError';\n    this.status = options?.status;\n    this.code = options?.code;\n    this.cause = options?.cause;\n\n    // Ensures proper prototype chain for instanceof checks\n    Object.setPrototypeOf(this, MCPError.prototype);\n  }\n\n  /**\n   * Creates a formatted error message with all available details\n   */\n  toFormattedString(): string {\n    const parts = [\n      `[${this.name}] ${this.message}`,\n      this.code ? `Code: ${this.code}` : null,\n      this.status ? `Status: ${this.status}` : null,\n      this.cause ? `Cause: ${this.cause instanceof Error ? this.cause.message : String(this.cause)}` : null,\n    ].filter(Boolean);\n\n    return parts.join(' | ');\n  }\n}\n\n/**\n * Error thrown when there's a network-related issue\n */\nexport class NetworkError extends MCPError {\n  constructor(message: string, options?: { code?: string; cause?: unknown }) {\n    super(message, { status: 0, code: options?.code || 'NETWORK_ERROR', cause: options?.cause });\n    this.name = 'NetworkError';\n\n    Object.setPrototypeOf(this, NetworkError.prototype);\n  }\n}\n\n/**\n * Error thrown when a request times out\n */\nexport class TimeoutError extends MCPError {\n  constructor(message = 'Request timed out', options?: { code?: string; cause?: unknown }) {\n    super(message, { status: 0, code: options?.code || 'TIMEOUT', cause: options?.cause });\n    this.name = 'TimeoutError';\n\n    Object.setPrototypeOf(this, TimeoutError.prototype);\n  }\n}\n\n/**\n * Error thrown when a request receives a 4xx or 5xx response\n */\nexport class HTTPError extends MCPError {\n  response: Response;\n\n  constructor(message: string, response: Response, options?: { code?: string; cause?: unknown }) {\n    super(message, {\n      status: response.status,\n      code: options?.code || `HTTP_${response.status}`,\n      cause: options?.cause\n    });\n    this.name = 'HTTPError';\n    this.response = response;\n\n    Object.setPrototypeOf(this, HTTPError.prototype);\n  }\n}\n\n/**\n * Error thrown when there's an authentication or authorization issue\n */\nexport class AuthError extends MCPError {\n  response?: Response;\n\n  constructor(message: string, options?: { status?: number; code?: string; cause?: unknown; response?: Response }) {\n    super(message, {\n      status: options?.status || 401,\n      code: options?.code || 'AUTH_ERROR',\n      cause: options?.cause\n    });\n    this.name = 'AuthError';\n    this.response = options?.response;\n\n    Object.setPrototypeOf(this, AuthError.prototype);\n  }\n}\n\n/**\n * Error thrown when user is unauthorized to access a resource\n */\nexport class UnauthorizedError extends AuthError {\n  constructor(message: string, options?: { code?: string; cause?: unknown; response?: Response }) {\n    super(message, {\n      status: 401,\n      code: options?.code || 'UNAUTHORIZED',\n      cause: options?.cause,\n      response: options?.response\n    });\n    this.name = 'UnauthorizedError';\n\n    Object.setPrototypeOf(this, UnauthorizedError.prototype);\n  }\n}\n\n/**\n * Error thrown when a tenant is not found\n */\nexport class TenantNotFoundError extends HTTPError {\n  constructor(message: string, options?: { code?: string; cause?: unknown }) {\n    // Create a mock Response object since we don't have the actual one\n    const mockResponse = new Response(null, { status: 404 });\n    \n    super(message, mockResponse, {\n      code: options?.code || 'TENANT_NOT_FOUND',\n      cause: options?.cause\n    });\n    this.name = 'TenantNotFoundError';\n\n    Object.setPrototypeOf(this, TenantNotFoundError.prototype);\n  }\n}\n\n/**\n * Error thrown when there's an issue with WebSocket connection\n */\nexport class WebSocketError extends MCPError {\n  event?: Event;\n\n  constructor(message: string, options?: { event?: Event; code?: string; cause?: unknown }) {\n    super(message, {\n      code: options?.code || 'WEBSOCKET_ERROR',\n      cause: options?.cause\n    });\n    this.name = 'WebSocketError';\n    this.event = options?.event;\n\n    Object.setPrototypeOf(this, WebSocketError.prototype);\n  }\n}\n\n/**\n * Error thrown when there's an issue with parsing a response\n */\nexport class ParseError extends MCPError {\n  data?: unknown;\n\n  constructor(message: string, options?: { data?: unknown; code?: string; cause?: unknown }) {\n    super(message, {\n      code: options?.code || 'PARSE_ERROR',\n      cause: options?.cause\n    });\n    this.name = 'ParseError';\n    this.data = options?.data;\n\n    Object.setPrototypeOf(this, ParseError.prototype);\n  }\n}\n\n/**\n * Error thrown when validation fails (e.g., with zod or other validators)\n */\nexport class ValidationError extends MCPError {\n  errors?: unknown;\n\n  constructor(message: string, options?: { errors?: unknown; code?: string; cause?: unknown }) {\n    super(message, {\n      code: options?.code || 'VALIDATION_ERROR',\n      cause: options?.cause\n    });\n    this.name = 'ValidationError';\n    this.errors = options?.errors;\n\n    Object.setPrototypeOf(this, ValidationError.prototype);\n  }\n}\n\n/**\n * Create appropriate error instance from an unknown error\n */\nexport function createError(error: unknown): MCPError {\n  if (error instanceof MCPError) {\n    return error;\n  }\n\n  if (error instanceof Error) {\n    return new MCPError(error.message, { cause: error });\n  }\n\n  return new MCPError(String(error));\n}\n\n// Export ontology error classes\nexport {\n  OntologyError,\n  OntologyEntityNotFoundError,\n  OntologySparqlError,\n  OntologyModificationError,\n  OntologyPaginationError,\n  parseOntologyError\n} from './ontology-errors';\n\n/**\n * Create appropriate HTTP error based on response status\n */\nexport function createHttpError(response: Response): MCPError {\n  const status = response.status;\n  let message = `HTTP Error ${status}`;\n  let code = `HTTP_${status}`;\n\n  // Add specific error messages for common HTTP status codes\n  if (status === 400) {\n    message = 'Bad Request: The request was invalid';\n    return new HTTPError(message, response);\n  } else if (status === 401) {\n    message = 'Unauthorized: Authentication is required';\n    return new AuthError(message, { status, code, response });\n  } else if (status === 403) {\n    message = 'Forbidden: You don\\'t have permission to access this resource';\n    return new AuthError(message, { status, code, response });\n  } else if (status === 404) {\n    message = 'Not Found: The requested resource does not exist';\n    return new HTTPError(message, response);\n  } else if (status === 429) {\n    message = 'Too Many Requests: Rate limit exceeded';\n    return new HTTPError(message, response);\n  } else if (status >= 500) {\n    message = 'Server Error: Something went wrong on the server';\n    return new HTTPError(message, response);\n  }\n\n  return new HTTPError(message, response);\n}\n","import { z } from 'zod';\nimport { ValidationError } from '../errors';\n\n/**\n * Validates data against a Zod schema and returns the validated data\n * @param schema - Zod schema to validate against\n * @param data - Data to validate\n * @returns Validated and typed data\n * @throws ValidationError if validation fails\n */\nexport function validate<T>(schema: z.ZodType<T>, data: unknown): T {\n  try {\n    return schema.parse(data);\n  } catch (error) {\n    if (error instanceof z.ZodError) {\n      throw new ValidationError(\n        `Validation failed: ${error.errors.map((e) => e.message).join(', ')}`,\n        { errors: error.format() }\n      );\n    }\n    throw error;\n  }\n}\n\n/**\n * Similar to validate, but returns a Result object with success/error state\n * instead of throwing an exception.\n */\nexport function validateSafe<T>(schema: z.ZodType<T>, data: unknown): {\n  success: boolean;\n  data?: T;\n  error?: ValidationError;\n} {\n  try {\n    return {\n      success: true,\n      data: schema.parse(data)\n    };\n  } catch (error) {\n    if (error instanceof z.ZodError) {\n      return {\n        success: false,\n        error: new ValidationError(\n          `Validation failed: ${error.errors.map((e) => e.message).join(', ')}`,\n          { errors: error.format() }\n        )\n      };\n    }\n    if (error instanceof Error) {\n      return {\n        success: false,\n        error: new ValidationError(error.message, { cause: error })\n      };\n    }\n    return {\n      success: false,\n      error: new ValidationError(`Unknown validation error: ${String(error)}`)\n    };\n  }\n}\n\n/**\n * Returns a function that will validate data against the given schema\n * @param schema - Zod schema to validate against\n * @returns Function that validates data against the schema\n */\nexport function createValidator<T>(schema: z.ZodType<T>): (data: unknown) => T {\n  return (data: unknown) => validate(schema, data);\n}\n\n/**\n * Creates a safe validator that doesn't throw exceptions\n */\nexport function createSafeValidator<T>(schema: z.ZodType<T>): (data: unknown) => {\n  success: boolean;\n  data?: T;\n  error?: ValidationError;\n} {\n  return (data: unknown) => validateSafe(schema, data);\n}\n\n/**\n * Validates an array of items against a schema\n */\nexport function validateArray<T>(schema: z.ZodType<T>, data: unknown): T[] {\n  const arraySchema = z.array(schema);\n  return validate(arraySchema, data);\n}\n\n/**\n * Validates that the response is a non-null object before further validation\n */\nexport function validateResponse<T>(schema: z.ZodType<T>, data: unknown): T {\n  // First ensure we have a non-null object\n  const baseSchema = z.object({}).required();\n  baseSchema.parse(data);\n\n  // Then validate the actual schema\n  return validate(schema, data);\n}\n"]}