UNPKG

@juspay/neurolink

Version:

Universal AI Development Platform with working MCP integration, multi-provider support, and professional CLI. Built-in tools operational, 58+ external MCP servers discoverable. Connect to filesystem, GitHub, database operations, and more. Build, test, and

154 lines (153 loc) 6 kB
/** * AWS SageMaker Runtime Client Wrapper * * This module provides a wrapper around the AWS SDK SageMaker Runtime client * with enhanced error handling, retry logic, and NeuroLink-specific features. */ import type { SageMakerConfig, InvokeEndpointParams, InvokeEndpointResponse } from "./types.js"; import type { ConnectionResult } from "../../types/typeAliases.js"; /** * Enhanced SageMaker Runtime client with retry logic and error handling */ export declare class SageMakerRuntimeClient { private client; private config; private isDisposed; constructor(config: SageMakerConfig); /** * Invoke a SageMaker endpoint for synchronous inference * * @param params - Endpoint invocation parameters * @returns Promise resolving to the inference response * @throws {SageMakerError} When the request fails */ invokeEndpoint(params: InvokeEndpointParams): Promise<InvokeEndpointResponse>; /** * Invoke a SageMaker endpoint with streaming response * * @param params - Endpoint invocation parameters for streaming * @returns Promise resolving to async iterable of response chunks * @throws {SageMakerError} When the request fails */ invokeEndpointWithStreaming(params: InvokeEndpointParams): Promise<{ Body: AsyncIterable<Uint8Array>; ContentType?: string; InvokedProductionVariant?: string; }>; /** * Execute a request with automatic retry logic * * @param operation - Function that executes the AWS SDK command * @param endpointName - Endpoint name for error context * @param attempt - Current attempt number (for recursive retries) * @returns Promise resolving to the operation result */ private executeWithRetry; /** * Validate endpoint connectivity and permissions * * @param endpointName - Name of the endpoint to validate * @returns Promise resolving to validation result */ validateEndpoint(endpointName: string): Promise<{ isValid: boolean; status?: string; error?: string; }>; /** * Get client configuration summary for debugging * * @returns Configuration summary (with sensitive data masked) */ getConfigSummary(): Record<string, unknown>; /** * Check if the client is properly configured * * @returns True if client appears to be properly configured */ isConfigured(): boolean; /** * Convert AWS SDK async iterable stream with payload structure */ private convertAsyncIterableStream; /** * Convert Node.js readable stream with reader interface */ private convertReadableStream; /** * Convert non-stream data to single Uint8Array chunk as fallback */ private convertFallbackData; /** * Convert AWS response stream to async iterable of Uint8Array chunks * Refactored into smaller focused methods for different stream types */ private convertAWSStreamToIterable; /** * Check if the client has been disposed */ get disposed(): boolean; /** * Dispose of the client and clean up resources using explicit disposed state pattern * * AWS SDK v3 Automatic Resource Management: * ======================================== * * The AWS SDK v3 uses automatic resource cleanup and doesn't require explicit disposal * of client instances in most cases. Here's how it works: * * 1. **HTTP Connection Pools**: AWS SDK v3 uses Node.js's built-in HTTP agent with * connection pooling. These connections are automatically managed and will be * closed when the Node.js process exits or becomes idle. * * 2. **Memory Management**: SDK clients don't hold significant resources that require * manual cleanup. The JavaScript garbage collector handles memory deallocation * when client references are removed. * * 3. **Background Timers**: Any internal timers (for retries, timeouts) are automatically * cleared when operations complete or the client goes out of scope. * * 4. **Keep-Alive Connections**: HTTP keep-alive connections are managed by the * underlying HTTP agent and will timeout automatically based on the configured * keep-alive timeout (typically 15 seconds). * * Why We Still Implement dispose(): * ================================= * * 1. **Explicit State Management**: Provides clear lifecycle control and prevents * accidental usage of disposed clients. * * 2. **Resource Tracking**: Allows our application to track when clients are no * longer needed, which is useful for debugging and monitoring. * * 3. **Defensive Programming**: Ensures we don't rely on automatic cleanup in * environments where it might not work as expected. * * 4. **Future Compatibility**: If future SDK versions require explicit cleanup, * we already have the infrastructure in place. * * For more information, see: * - https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/ * - https://aws.amazon.com/blogs/developer/node-js-configuring-maxsockets-in-sdk-for-javascript/ */ dispose(): void; /** * Ensure client is not disposed before operations */ private ensureNotDisposed; } /** * Factory function to create a SageMaker Runtime client * * @param config - SageMaker configuration * @returns Configured SageMakerRuntimeClient instance */ export declare function createSageMakerRuntimeClient(config: SageMakerConfig): SageMakerRuntimeClient; /** * Utility function to test SageMaker connectivity * * @param config - SageMaker configuration * @param endpointName - Endpoint to test * @returns Promise resolving to connectivity test result */ export declare function testSageMakerConnectivity(config: SageMakerConfig, endpointName: string): Promise<ConnectionResult>;