@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
150 lines (149 loc) • 5.49 kB
JavaScript
/**
* Amazon SageMaker Provider Implementation (Simplified)
*
* This module provides a simplified SageMaker provider that extends BaseProvider
* and integrates with the NeuroLink ecosystem using existing patterns.
*/
import { BaseProvider } from "../core/baseProvider.js";
import { logger } from "../utils/logger.js";
// SageMaker-specific imports
import { getSageMakerConfig, getSageMakerModelConfig, getDefaultSageMakerEndpoint, getSageMakerModel, } from "./sagemaker/config.js";
import { handleSageMakerError, SageMakerError } from "./sagemaker/errors.js";
import { SageMakerLanguageModel } from "./sagemaker/language-model.js";
/**
* Amazon SageMaker Provider extending BaseProvider
*/
export class AmazonSageMakerProvider extends BaseProvider {
sagemakerModel;
sagemakerConfig;
modelConfig;
constructor(modelName, endpointName) {
super(modelName, "sagemaker");
try {
// Load and validate configuration
this.sagemakerConfig = getSageMakerConfig();
this.modelConfig = getSageMakerModelConfig(endpointName || getDefaultSageMakerEndpoint());
// Create the proper LanguageModel (v2) implementation
this.sagemakerModel = new SageMakerLanguageModel(this.modelName, this.sagemakerConfig, this.modelConfig);
logger.debug("Amazon SageMaker Provider initialized", {
modelName: this.modelName,
endpointName: this.modelConfig.endpointName,
region: this.sagemakerConfig.region,
provider: this.providerName,
});
}
catch (error) {
logger.error("Failed to initialize SageMaker provider", {
error: error instanceof Error ? error.message : String(error),
modelName,
endpointName,
});
throw handleSageMakerError(error);
}
}
getProviderName() {
return "sagemaker";
}
getDefaultModel() {
return getSageMakerModel();
}
getAISDKModel() {
return this.sagemakerModel;
}
async executeStream(options, analysisSchema) {
try {
// For now, throw an error indicating this is not yet implemented
throw new SageMakerError("SageMaker streaming not yet fully implemented. Coming in next phase.", "MODEL_ERROR", 501, undefined, this.modelConfig.endpointName);
}
catch (error) {
throw this.handleProviderError(error);
}
}
handleProviderError(error) {
if (error instanceof SageMakerError) {
return error;
}
if (error instanceof Error && error.name === "TimeoutError") {
return new SageMakerError(`SageMaker request timed out. Consider increasing timeout.`, "NETWORK_ERROR", 408, error, this.modelConfig.endpointName);
}
return handleSageMakerError(error, this.modelConfig.endpointName);
}
/**
* Get SageMaker-specific provider information
*/
getSageMakerInfo() {
return {
endpointName: this.modelConfig.endpointName,
modelType: this.modelConfig.modelType || "custom",
region: this.sagemakerConfig.region,
configured: !!(this.sagemakerConfig.accessKeyId && this.sagemakerConfig.secretAccessKey),
};
}
/**
* Test basic configuration
*/
async testConnection() {
try {
// Basic validation test
if (!this.sagemakerConfig.accessKeyId ||
!this.sagemakerConfig.secretAccessKey) {
return {
connected: false,
error: "AWS credentials not configured",
};
}
if (!this.modelConfig.endpointName ||
this.modelConfig.endpointName === "default-endpoint") {
return {
connected: false,
error: "SageMaker endpoint not configured",
};
}
// For now, just return that configuration looks valid
return {
connected: true,
};
}
catch (error) {
return {
connected: false,
error: error instanceof Error ? error.message : String(error),
};
}
}
/**
* Public method to get the AI SDK model for CLI and external usage
*/
async getModel() {
return this.getAISDKModel();
}
/**
* Test connectivity to the SageMaker endpoint
*/
async testConnectivity() {
const model = this.sagemakerModel;
return model.testConnectivity
? await model.testConnectivity()
: { success: false, error: "Test method not available" };
}
/**
* Get model capabilities and information
*/
getModelCapabilities() {
const model = this.sagemakerModel;
return model.getModelCapabilities
? model.getModelCapabilities()
: {
capabilities: {
streaming: true,
toolCalling: true,
structuredOutput: true,
batchInference: true,
supportedResponseFormats: ["text", "json_object"],
supportedToolTypes: ["function"],
maxBatchSize: 10,
},
};
}
}
export default AmazonSageMakerProvider;