@juspay/neurolink 7.7.1 → 7.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/CHANGELOG.md +25 -2
  2. package/README.md +34 -2
  3. package/dist/cli/commands/config.d.ts +3 -3
  4. package/dist/cli/commands/sagemaker.d.ts +11 -0
  5. package/dist/cli/commands/sagemaker.js +778 -0
  6. package/dist/cli/factories/commandFactory.js +7 -2
  7. package/dist/cli/index.js +3 -0
  8. package/dist/cli/utils/interactiveSetup.js +28 -0
  9. package/dist/core/baseProvider.d.ts +2 -2
  10. package/dist/core/types.d.ts +16 -4
  11. package/dist/core/types.js +24 -3
  12. package/dist/factories/providerFactory.js +10 -1
  13. package/dist/factories/providerRegistry.js +6 -1
  14. package/dist/lib/core/baseProvider.d.ts +2 -2
  15. package/dist/lib/core/types.d.ts +16 -4
  16. package/dist/lib/core/types.js +24 -3
  17. package/dist/lib/factories/providerFactory.js +10 -1
  18. package/dist/lib/factories/providerRegistry.js +6 -1
  19. package/dist/lib/neurolink.d.ts +15 -0
  20. package/dist/lib/neurolink.js +73 -1
  21. package/dist/lib/providers/amazonSagemaker.d.ts +67 -0
  22. package/dist/lib/providers/amazonSagemaker.js +149 -0
  23. package/dist/lib/providers/googleVertex.d.ts +4 -0
  24. package/dist/lib/providers/googleVertex.js +44 -3
  25. package/dist/lib/providers/index.d.ts +4 -0
  26. package/dist/lib/providers/index.js +4 -0
  27. package/dist/lib/providers/sagemaker/adaptive-semaphore.d.ts +86 -0
  28. package/dist/lib/providers/sagemaker/adaptive-semaphore.js +212 -0
  29. package/dist/lib/providers/sagemaker/client.d.ts +156 -0
  30. package/dist/lib/providers/sagemaker/client.js +462 -0
  31. package/dist/lib/providers/sagemaker/config.d.ts +73 -0
  32. package/dist/lib/providers/sagemaker/config.js +308 -0
  33. package/dist/lib/providers/sagemaker/detection.d.ts +176 -0
  34. package/dist/lib/providers/sagemaker/detection.js +596 -0
  35. package/dist/lib/providers/sagemaker/diagnostics.d.ts +37 -0
  36. package/dist/lib/providers/sagemaker/diagnostics.js +137 -0
  37. package/dist/lib/providers/sagemaker/error-constants.d.ts +78 -0
  38. package/dist/lib/providers/sagemaker/error-constants.js +227 -0
  39. package/dist/lib/providers/sagemaker/errors.d.ts +83 -0
  40. package/dist/lib/providers/sagemaker/errors.js +216 -0
  41. package/dist/lib/providers/sagemaker/index.d.ts +35 -0
  42. package/dist/lib/providers/sagemaker/index.js +67 -0
  43. package/dist/lib/providers/sagemaker/language-model.d.ts +182 -0
  44. package/dist/lib/providers/sagemaker/language-model.js +755 -0
  45. package/dist/lib/providers/sagemaker/parsers.d.ts +136 -0
  46. package/dist/lib/providers/sagemaker/parsers.js +625 -0
  47. package/dist/lib/providers/sagemaker/streaming.d.ts +39 -0
  48. package/dist/lib/providers/sagemaker/streaming.js +320 -0
  49. package/dist/lib/providers/sagemaker/structured-parser.d.ts +117 -0
  50. package/dist/lib/providers/sagemaker/structured-parser.js +625 -0
  51. package/dist/lib/providers/sagemaker/types.d.ts +456 -0
  52. package/dist/lib/providers/sagemaker/types.js +7 -0
  53. package/dist/lib/sdk/toolRegistration.d.ts +1 -1
  54. package/dist/lib/sdk/toolRegistration.js +13 -5
  55. package/dist/lib/types/cli.d.ts +36 -1
  56. package/dist/lib/utils/providerHealth.js +19 -4
  57. package/dist/neurolink.d.ts +15 -0
  58. package/dist/neurolink.js +73 -1
  59. package/dist/providers/amazonSagemaker.d.ts +67 -0
  60. package/dist/providers/amazonSagemaker.js +149 -0
  61. package/dist/providers/googleVertex.d.ts +4 -0
  62. package/dist/providers/googleVertex.js +44 -3
  63. package/dist/providers/index.d.ts +4 -0
  64. package/dist/providers/index.js +4 -0
  65. package/dist/providers/sagemaker/adaptive-semaphore.d.ts +86 -0
  66. package/dist/providers/sagemaker/adaptive-semaphore.js +212 -0
  67. package/dist/providers/sagemaker/client.d.ts +156 -0
  68. package/dist/providers/sagemaker/client.js +462 -0
  69. package/dist/providers/sagemaker/config.d.ts +73 -0
  70. package/dist/providers/sagemaker/config.js +308 -0
  71. package/dist/providers/sagemaker/detection.d.ts +176 -0
  72. package/dist/providers/sagemaker/detection.js +596 -0
  73. package/dist/providers/sagemaker/diagnostics.d.ts +37 -0
  74. package/dist/providers/sagemaker/diagnostics.js +137 -0
  75. package/dist/providers/sagemaker/error-constants.d.ts +78 -0
  76. package/dist/providers/sagemaker/error-constants.js +227 -0
  77. package/dist/providers/sagemaker/errors.d.ts +83 -0
  78. package/dist/providers/sagemaker/errors.js +216 -0
  79. package/dist/providers/sagemaker/index.d.ts +35 -0
  80. package/dist/providers/sagemaker/index.js +67 -0
  81. package/dist/providers/sagemaker/language-model.d.ts +182 -0
  82. package/dist/providers/sagemaker/language-model.js +755 -0
  83. package/dist/providers/sagemaker/parsers.d.ts +136 -0
  84. package/dist/providers/sagemaker/parsers.js +625 -0
  85. package/dist/providers/sagemaker/streaming.d.ts +39 -0
  86. package/dist/providers/sagemaker/streaming.js +320 -0
  87. package/dist/providers/sagemaker/structured-parser.d.ts +117 -0
  88. package/dist/providers/sagemaker/structured-parser.js +625 -0
  89. package/dist/providers/sagemaker/types.d.ts +456 -0
  90. package/dist/providers/sagemaker/types.js +7 -0
  91. package/dist/sdk/toolRegistration.d.ts +1 -1
  92. package/dist/sdk/toolRegistration.js +13 -5
  93. package/dist/types/cli.d.ts +36 -1
  94. package/dist/utils/providerHealth.js +19 -4
  95. package/package.json +8 -2
@@ -0,0 +1,137 @@
1
+ /**
2
+ * SageMaker Simple Diagnostics Module
3
+ *
4
+ * Provides basic diagnostic functions for SageMaker configuration and connectivity.
5
+ */
6
+ import chalk from "chalk";
7
+ import { checkSageMakerConfiguration } from "./config.js";
8
+ import { createSageMakerProvider } from "./index.js";
9
+ /**
10
+ * Run quick diagnostics for SageMaker configuration
11
+ */
12
+ export async function runQuickDiagnostics(endpoint) {
13
+ const results = [];
14
+ // Test 1: Configuration check
15
+ try {
16
+ const configStatus = checkSageMakerConfiguration();
17
+ results.push({
18
+ name: "Configuration Validation",
19
+ category: "configuration",
20
+ status: configStatus.configured ? "pass" : "fail",
21
+ message: configStatus.configured
22
+ ? "SageMaker configuration is valid"
23
+ : "SageMaker configuration has issues",
24
+ details: configStatus.issues.join(", "),
25
+ recommendation: configStatus.configured
26
+ ? undefined
27
+ : "Run 'neurolink sagemaker setup' to configure",
28
+ });
29
+ }
30
+ catch (error) {
31
+ results.push({
32
+ name: "Configuration Validation",
33
+ category: "configuration",
34
+ status: "fail",
35
+ message: "Failed to validate configuration",
36
+ details: error instanceof Error ? error.message : String(error),
37
+ recommendation: "Check your AWS credentials and configuration",
38
+ });
39
+ }
40
+ // Test 2: Connectivity check (if endpoint provided)
41
+ if (endpoint) {
42
+ try {
43
+ const provider = createSageMakerProvider(undefined, endpoint);
44
+ const connectivityTest = await provider.testConnectivity();
45
+ results.push({
46
+ name: `Endpoint Connectivity (${endpoint})`,
47
+ category: "connectivity",
48
+ status: connectivityTest.success ? "pass" : "fail",
49
+ message: connectivityTest.success
50
+ ? "Endpoint is accessible"
51
+ : "Endpoint connectivity failed",
52
+ details: connectivityTest.error || "Connection successful",
53
+ recommendation: connectivityTest.success
54
+ ? undefined
55
+ : "Check endpoint name and AWS permissions",
56
+ });
57
+ }
58
+ catch (error) {
59
+ results.push({
60
+ name: `Endpoint Connectivity (${endpoint})`,
61
+ category: "connectivity",
62
+ status: "fail",
63
+ message: "Connectivity test failed",
64
+ details: error instanceof Error ? error.message : String(error),
65
+ recommendation: "Verify endpoint exists and you have access",
66
+ });
67
+ }
68
+ }
69
+ // Calculate summary
70
+ const passed = results.filter((r) => r.status === "pass").length;
71
+ const failed = results.filter((r) => r.status === "fail").length;
72
+ const warnings = results.filter((r) => r.status === "warning").length;
73
+ let overallStatus = "healthy";
74
+ if (failed > 0) {
75
+ overallStatus = failed >= results.length / 2 ? "critical" : "issues";
76
+ }
77
+ else if (warnings > 0) {
78
+ overallStatus = "issues";
79
+ }
80
+ return {
81
+ overallStatus,
82
+ results,
83
+ summary: {
84
+ total: results.length,
85
+ passed,
86
+ failed,
87
+ warnings,
88
+ },
89
+ };
90
+ }
91
+ /**
92
+ * Format diagnostic report for console output
93
+ */
94
+ export function formatDiagnosticReport(report) {
95
+ const lines = [];
96
+ lines.push(chalk.blue("🔍 SageMaker Diagnostic Results\n"));
97
+ // Summary
98
+ lines.push(`📊 Summary: ${report.summary.passed}/${report.summary.total} tests passed`);
99
+ if (report.summary.failed > 0) {
100
+ lines.push(chalk.red(` Failed: ${report.summary.failed}`));
101
+ }
102
+ if (report.summary.warnings > 0) {
103
+ lines.push(chalk.yellow(` Warnings: ${report.summary.warnings}`));
104
+ }
105
+ lines.push("");
106
+ // Individual results
107
+ report.results.forEach((result, index) => {
108
+ const icon = result.status === "pass" ? "✅" : result.status === "fail" ? "❌" : "⚠️";
109
+ const color = result.status === "pass"
110
+ ? chalk.green
111
+ : result.status === "fail"
112
+ ? chalk.red
113
+ : chalk.yellow;
114
+ lines.push(`${index + 1}. ${icon} ${color(result.name)}`);
115
+ lines.push(` ${result.message}`);
116
+ if (result.details) {
117
+ lines.push(` Details: ${result.details}`);
118
+ }
119
+ if (result.recommendation) {
120
+ lines.push(chalk.blue(` 💡 ${result.recommendation}`));
121
+ }
122
+ lines.push("");
123
+ });
124
+ // Overall status
125
+ const statusIcon = report.overallStatus === "healthy"
126
+ ? "✅"
127
+ : report.overallStatus === "issues"
128
+ ? "⚠️"
129
+ : "🚨";
130
+ const statusColor = report.overallStatus === "healthy"
131
+ ? chalk.green
132
+ : report.overallStatus === "issues"
133
+ ? chalk.yellow
134
+ : chalk.red;
135
+ lines.push(`${statusIcon} Overall Status: ${statusColor(report.overallStatus.toUpperCase())}`);
136
+ return lines.join("\n");
137
+ }
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Error message constants and templates for Amazon SageMaker Provider
3
+ *
4
+ * This module contains all error message templates, prefixes, and constants
5
+ * used throughout the SageMaker provider for consistent error handling.
6
+ */
7
+ /**
8
+ * Error message prefixes for different error types
9
+ */
10
+ export declare const ERROR_MESSAGE_PREFIXES: {
11
+ readonly VALIDATION: "Invalid request parameters";
12
+ readonly MODEL: "Model execution error";
13
+ readonly INTERNAL: "Internal server error";
14
+ readonly SERVICE_UNAVAILABLE: "SageMaker service is temporarily unavailable";
15
+ readonly THROTTLING: "Request rate limit exceeded";
16
+ readonly CREDENTIALS: "AWS credentials are invalid or missing";
17
+ readonly NETWORK: "Network error while connecting to SageMaker";
18
+ readonly ENDPOINT_NOT_FOUND: "SageMaker endpoint not found";
19
+ readonly VALIDATION_FIELD: "Validation failed for";
20
+ readonly CREDENTIALS_SETUP: "AWS credentials error";
21
+ readonly NETWORK_CONNECTION: "Network error";
22
+ };
23
+ /**
24
+ * Detailed error message templates for user guidance
25
+ */
26
+ export declare const ERROR_MESSAGE_TEMPLATES: {
27
+ readonly VALIDATION_ERROR: "❌ SageMaker Request Validation Error{endpointContext}\n\n{originalMessage}\n\n🔧 Common Solutions:\n1. Check your request parameters and format\n2. Verify the endpoint name is correct\n3. Ensure your request body matches the expected model format\n4. Validate that required parameters are included\n\n💡 Tips:\n- Double-check the endpoint name spelling\n- Ensure JSON format is valid if using JSON content type\n- Verify parameter types match model expectations";
28
+ readonly MODEL_ERROR: "❌ SageMaker Model Execution Error{endpointContext}\n\n{originalMessage}\n\n🔧 Common Solutions:\n1. Check if the model is properly deployed and in 'InService' status\n2. Verify your input format matches what the model expects\n3. Ensure input size is within model limits\n4. Check if the model container is healthy\n\n💡 Tips:\n- Try with a simpler input to test model health\n- Check CloudWatch logs for detailed model errors\n- Verify model dependencies are properly installed";
29
+ readonly INTERNAL_ERROR: "❌ SageMaker Internal Server Error{endpointContext}\n\n{originalMessage}\n\n🔧 Common Solutions:\n1. Retry the request after a short delay\n2. Check AWS Service Health Dashboard\n3. Verify your endpoint is still active and healthy\n4. Contact AWS support if issue persists\n\n💡 Tips:\n- This is usually a temporary issue\n- Implement exponential backoff for retries\n- Check if other endpoints are working";
30
+ readonly SERVICE_UNAVAILABLE: "❌ SageMaker Service Temporarily Unavailable{endpointContext}\n\n{originalMessage}\n\n🔧 Common Solutions:\n1. Wait and retry after a few seconds\n2. Check AWS region status\n3. Verify your endpoint hasn't been deleted\n4. Check if you've hit account limits\n\n💡 Tips:\n- Service issues are usually temporary\n- Implement retry logic with backoff\n- Monitor AWS Service Health Dashboard";
31
+ readonly CREDENTIALS_ERROR: "❌ AWS Credentials Error{endpointContext}\n\n{originalMessage}\n\n🔧 Required Steps:\n1. Verify AWS_ACCESS_KEY_ID is set correctly\n2. Verify AWS_SECRET_ACCESS_KEY is set correctly\n3. Check AWS_SESSION_TOKEN if using temporary credentials\n4. Ensure credentials have SageMaker permissions\n\n🔑 Required IAM Permissions:\n- sagemaker:InvokeEndpoint\n- sagemaker:InvokeEndpointWithResponseStream\n- sagemaker:DescribeEndpoint (optional, for debugging)\n\n💡 Setup Help:\n- Set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables\n- Check IAM user has necessary permissions\n- Verify credentials haven't expired";
32
+ readonly NETWORK_ERROR: "❌ Network Connection Error{endpointContext}\n\n{originalMessage}\n\n🔧 Common Solutions:\n1. Check your internet connection\n2. Verify firewall/proxy settings\n3. Try different DNS servers\n4. Check if SageMaker service is accessible from your network\n\n💡 Network Troubleshooting:\n- Test connectivity to other AWS services\n- Check for VPC/subnet restrictions if running in AWS\n- Verify security group rules allow outbound HTTPS";
33
+ readonly ENDPOINT_NOT_FOUND: "❌ SageMaker Endpoint Not Found{endpointContext}\n\n{originalMessage}\n\n🔧 Common Solutions:\n1. Verify the endpoint name is spelled correctly\n2. Check if the endpoint exists in the correct AWS region\n3. Ensure the endpoint is in 'InService' status\n4. Verify you have permissions to access the endpoint\n\n💡 Endpoint Management:\n- List endpoints: aws sagemaker list-endpoints\n- Check status: aws sagemaker describe-endpoint --endpoint-name <name>\n- Ensure endpoint is deployed in the same region";
34
+ readonly THROTTLING_ERROR: "❌ Request Rate Limit Exceeded{endpointContext}\n\n{originalMessage}\n\n🔧 Common Solutions:\n1. Implement exponential backoff retry logic\n2. Reduce request rate\n3. Consider using batch inference for large workloads\n4. Request higher limits from AWS support if needed\n\n💡 Rate Limiting Tips:\n- Space out requests over time\n- Use batch processing when possible\n- Monitor your request patterns\n- Consider auto-scaling your endpoint";
35
+ readonly UNKNOWN_ERROR: "❌ Unknown SageMaker Error{endpointContext}\n\n{originalMessage}\n\n🔧 General Troubleshooting:\n1. Check AWS credentials and permissions\n2. Verify endpoint name and status\n3. Check network connectivity\n4. Review request format and parameters\n\n💡 Additional Help:\n- Check CloudWatch logs for detailed errors\n- Verify SageMaker service health\n- Consult AWS SageMaker documentation\n- Contact AWS support for persistent issues";
36
+ readonly DEFAULT: "❌ SageMaker Error{endpointContext}\n\n{originalMessage}\n\n🔧 General Troubleshooting:\n1. Check AWS credentials and permissions\n2. Verify endpoint name and status\n3. Check network connectivity\n4. Review request format and parameters\n\n💡 Additional Help:\n- Check CloudWatch logs for detailed errors\n- Verify SageMaker service health\n- Consult AWS SageMaker documentation\n- Contact AWS support for persistent issues";
37
+ };
38
+ /**
39
+ * Retry delay constants for different error types (in milliseconds)
40
+ */
41
+ export declare const RETRY_DELAYS: {
42
+ readonly THROTTLING_ERROR: 5000;
43
+ readonly SERVICE_UNAVAILABLE: 2000;
44
+ readonly NETWORK_ERROR: 1000;
45
+ readonly DEFAULT: 1000;
46
+ };
47
+ /**
48
+ * List of retryable AWS SDK error names and conditions
49
+ */
50
+ export declare const RETRYABLE_ERROR_CONDITIONS: {
51
+ readonly ERROR_NAMES: readonly ["ServiceUnavailable", "InternalFailure", "ThrottlingException", "NetworkingError"];
52
+ readonly ERROR_MESSAGE_KEYWORDS: readonly ["timeout", "throttl", "unavailable", "internal", "network"];
53
+ };
54
+ /**
55
+ * AWS SDK error name mappings to SageMaker error codes
56
+ */
57
+ export declare const AWS_ERROR_MAPPINGS: {
58
+ readonly ValidationException: "VALIDATION_ERROR";
59
+ readonly ModelError: "MODEL_ERROR";
60
+ readonly InternalFailure: "INTERNAL_ERROR";
61
+ readonly ServiceUnavailable: "SERVICE_UNAVAILABLE";
62
+ readonly ThrottlingException: "THROTTLING_ERROR";
63
+ readonly CredentialsError: "CREDENTIALS_ERROR";
64
+ readonly NetworkingError: "NETWORK_ERROR";
65
+ };
66
+ /**
67
+ * Common error message keywords for pattern matching
68
+ */
69
+ export declare const ERROR_KEYWORDS: {
70
+ readonly VALIDATION: readonly ["validation"];
71
+ readonly MODEL: readonly ["model error"];
72
+ readonly INTERNAL: readonly ["internal"];
73
+ readonly SERVICE_UNAVAILABLE: readonly ["unavailable"];
74
+ readonly THROTTLING: readonly ["throttl"];
75
+ readonly CREDENTIALS: readonly ["credential"];
76
+ readonly NETWORK: readonly ["network"];
77
+ readonly ENDPOINT_NOT_FOUND: readonly ["endpoint", "not found"];
78
+ };
@@ -0,0 +1,227 @@
1
+ /**
2
+ * Error message constants and templates for Amazon SageMaker Provider
3
+ *
4
+ * This module contains all error message templates, prefixes, and constants
5
+ * used throughout the SageMaker provider for consistent error handling.
6
+ */
7
+ /**
8
+ * Error message prefixes for different error types
9
+ */
10
+ export const ERROR_MESSAGE_PREFIXES = {
11
+ VALIDATION: "Invalid request parameters",
12
+ MODEL: "Model execution error",
13
+ INTERNAL: "Internal server error",
14
+ SERVICE_UNAVAILABLE: "SageMaker service is temporarily unavailable",
15
+ THROTTLING: "Request rate limit exceeded",
16
+ CREDENTIALS: "AWS credentials are invalid or missing",
17
+ NETWORK: "Network error while connecting to SageMaker",
18
+ ENDPOINT_NOT_FOUND: "SageMaker endpoint not found",
19
+ VALIDATION_FIELD: "Validation failed for",
20
+ CREDENTIALS_SETUP: "AWS credentials error",
21
+ NETWORK_CONNECTION: "Network error",
22
+ };
23
+ /**
24
+ * Detailed error message templates for user guidance
25
+ */
26
+ export const ERROR_MESSAGE_TEMPLATES = {
27
+ VALIDATION_ERROR: `❌ SageMaker Request Validation Error{endpointContext}
28
+
29
+ {originalMessage}
30
+
31
+ 🔧 Common Solutions:
32
+ 1. Check your request parameters and format
33
+ 2. Verify the endpoint name is correct
34
+ 3. Ensure your request body matches the expected model format
35
+ 4. Validate that required parameters are included
36
+
37
+ 💡 Tips:
38
+ - Double-check the endpoint name spelling
39
+ - Ensure JSON format is valid if using JSON content type
40
+ - Verify parameter types match model expectations`,
41
+ MODEL_ERROR: `❌ SageMaker Model Execution Error{endpointContext}
42
+
43
+ {originalMessage}
44
+
45
+ 🔧 Common Solutions:
46
+ 1. Check if the model is properly deployed and in 'InService' status
47
+ 2. Verify your input format matches what the model expects
48
+ 3. Ensure input size is within model limits
49
+ 4. Check if the model container is healthy
50
+
51
+ 💡 Tips:
52
+ - Try with a simpler input to test model health
53
+ - Check CloudWatch logs for detailed model errors
54
+ - Verify model dependencies are properly installed`,
55
+ INTERNAL_ERROR: `❌ SageMaker Internal Server Error{endpointContext}
56
+
57
+ {originalMessage}
58
+
59
+ 🔧 Common Solutions:
60
+ 1. Retry the request after a short delay
61
+ 2. Check AWS Service Health Dashboard
62
+ 3. Verify your endpoint is still active and healthy
63
+ 4. Contact AWS support if issue persists
64
+
65
+ 💡 Tips:
66
+ - This is usually a temporary issue
67
+ - Implement exponential backoff for retries
68
+ - Check if other endpoints are working`,
69
+ SERVICE_UNAVAILABLE: `❌ SageMaker Service Temporarily Unavailable{endpointContext}
70
+
71
+ {originalMessage}
72
+
73
+ 🔧 Common Solutions:
74
+ 1. Wait and retry after a few seconds
75
+ 2. Check AWS region status
76
+ 3. Verify your endpoint hasn't been deleted
77
+ 4. Check if you've hit account limits
78
+
79
+ 💡 Tips:
80
+ - Service issues are usually temporary
81
+ - Implement retry logic with backoff
82
+ - Monitor AWS Service Health Dashboard`,
83
+ CREDENTIALS_ERROR: `❌ AWS Credentials Error{endpointContext}
84
+
85
+ {originalMessage}
86
+
87
+ 🔧 Required Steps:
88
+ 1. Verify AWS_ACCESS_KEY_ID is set correctly
89
+ 2. Verify AWS_SECRET_ACCESS_KEY is set correctly
90
+ 3. Check AWS_SESSION_TOKEN if using temporary credentials
91
+ 4. Ensure credentials have SageMaker permissions
92
+
93
+ 🔑 Required IAM Permissions:
94
+ - sagemaker:InvokeEndpoint
95
+ - sagemaker:InvokeEndpointWithResponseStream
96
+ - sagemaker:DescribeEndpoint (optional, for debugging)
97
+
98
+ 💡 Setup Help:
99
+ - Set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables
100
+ - Check IAM user has necessary permissions
101
+ - Verify credentials haven't expired`,
102
+ NETWORK_ERROR: `❌ Network Connection Error{endpointContext}
103
+
104
+ {originalMessage}
105
+
106
+ 🔧 Common Solutions:
107
+ 1. Check your internet connection
108
+ 2. Verify firewall/proxy settings
109
+ 3. Try different DNS servers
110
+ 4. Check if SageMaker service is accessible from your network
111
+
112
+ 💡 Network Troubleshooting:
113
+ - Test connectivity to other AWS services
114
+ - Check for VPC/subnet restrictions if running in AWS
115
+ - Verify security group rules allow outbound HTTPS`,
116
+ ENDPOINT_NOT_FOUND: `❌ SageMaker Endpoint Not Found{endpointContext}
117
+
118
+ {originalMessage}
119
+
120
+ 🔧 Common Solutions:
121
+ 1. Verify the endpoint name is spelled correctly
122
+ 2. Check if the endpoint exists in the correct AWS region
123
+ 3. Ensure the endpoint is in 'InService' status
124
+ 4. Verify you have permissions to access the endpoint
125
+
126
+ 💡 Endpoint Management:
127
+ - List endpoints: aws sagemaker list-endpoints
128
+ - Check status: aws sagemaker describe-endpoint --endpoint-name <name>
129
+ - Ensure endpoint is deployed in the same region`,
130
+ THROTTLING_ERROR: `❌ Request Rate Limit Exceeded{endpointContext}
131
+
132
+ {originalMessage}
133
+
134
+ 🔧 Common Solutions:
135
+ 1. Implement exponential backoff retry logic
136
+ 2. Reduce request rate
137
+ 3. Consider using batch inference for large workloads
138
+ 4. Request higher limits from AWS support if needed
139
+
140
+ 💡 Rate Limiting Tips:
141
+ - Space out requests over time
142
+ - Use batch processing when possible
143
+ - Monitor your request patterns
144
+ - Consider auto-scaling your endpoint`,
145
+ UNKNOWN_ERROR: `❌ Unknown SageMaker Error{endpointContext}
146
+
147
+ {originalMessage}
148
+
149
+ 🔧 General Troubleshooting:
150
+ 1. Check AWS credentials and permissions
151
+ 2. Verify endpoint name and status
152
+ 3. Check network connectivity
153
+ 4. Review request format and parameters
154
+
155
+ 💡 Additional Help:
156
+ - Check CloudWatch logs for detailed errors
157
+ - Verify SageMaker service health
158
+ - Consult AWS SageMaker documentation
159
+ - Contact AWS support for persistent issues`,
160
+ DEFAULT: `❌ SageMaker Error{endpointContext}
161
+
162
+ {originalMessage}
163
+
164
+ 🔧 General Troubleshooting:
165
+ 1. Check AWS credentials and permissions
166
+ 2. Verify endpoint name and status
167
+ 3. Check network connectivity
168
+ 4. Review request format and parameters
169
+
170
+ 💡 Additional Help:
171
+ - Check CloudWatch logs for detailed errors
172
+ - Verify SageMaker service health
173
+ - Consult AWS SageMaker documentation
174
+ - Contact AWS support for persistent issues`,
175
+ };
176
+ /**
177
+ * Retry delay constants for different error types (in milliseconds)
178
+ */
179
+ export const RETRY_DELAYS = {
180
+ THROTTLING_ERROR: 5000, // 5 seconds for throttling
181
+ SERVICE_UNAVAILABLE: 2000, // 2 seconds for service issues
182
+ NETWORK_ERROR: 1000, // 1 second for network issues
183
+ DEFAULT: 1000, // Default 1 second
184
+ };
185
+ /**
186
+ * List of retryable AWS SDK error names and conditions
187
+ */
188
+ export const RETRYABLE_ERROR_CONDITIONS = {
189
+ ERROR_NAMES: [
190
+ "ServiceUnavailable",
191
+ "InternalFailure",
192
+ "ThrottlingException",
193
+ "NetworkingError",
194
+ ],
195
+ ERROR_MESSAGE_KEYWORDS: [
196
+ "timeout",
197
+ "throttl",
198
+ "unavailable",
199
+ "internal",
200
+ "network",
201
+ ],
202
+ };
203
+ /**
204
+ * AWS SDK error name mappings to SageMaker error codes
205
+ */
206
+ export const AWS_ERROR_MAPPINGS = {
207
+ ValidationException: "VALIDATION_ERROR",
208
+ ModelError: "MODEL_ERROR",
209
+ InternalFailure: "INTERNAL_ERROR",
210
+ ServiceUnavailable: "SERVICE_UNAVAILABLE",
211
+ ThrottlingException: "THROTTLING_ERROR",
212
+ CredentialsError: "CREDENTIALS_ERROR",
213
+ NetworkingError: "NETWORK_ERROR",
214
+ };
215
+ /**
216
+ * Common error message keywords for pattern matching
217
+ */
218
+ export const ERROR_KEYWORDS = {
219
+ VALIDATION: ["validation"],
220
+ MODEL: ["model error"],
221
+ INTERNAL: ["internal"],
222
+ SERVICE_UNAVAILABLE: ["unavailable"],
223
+ THROTTLING: ["throttl"],
224
+ CREDENTIALS: ["credential"],
225
+ NETWORK: ["network"],
226
+ ENDPOINT_NOT_FOUND: ["endpoint", "not found"],
227
+ };
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Error handling system for Amazon SageMaker Provider
3
+ *
4
+ * This module provides comprehensive error handling, categorization,
5
+ * and user-friendly error messages for SageMaker operations.
6
+ */
7
+ import type { SageMakerErrorCode, SageMakerErrorInfo } from "./types.js";
8
+ /**
9
+ * Custom error class for SageMaker-specific errors
10
+ */
11
+ export declare class SageMakerError extends Error {
12
+ readonly code: SageMakerErrorCode;
13
+ readonly statusCode?: number;
14
+ readonly cause?: Error;
15
+ readonly endpoint?: string;
16
+ readonly requestId?: string;
17
+ readonly retryable: boolean;
18
+ constructor(message: string, code?: SageMakerErrorCode, statusCode?: number, cause?: Error, endpoint?: string, requestId?: string, retryable?: boolean);
19
+ /**
20
+ * Convert error to JSON for logging/serialization
21
+ */
22
+ toJSON(): SageMakerErrorInfo & {
23
+ stack?: string;
24
+ };
25
+ /**
26
+ * Get user-friendly error message with troubleshooting guidance
27
+ */
28
+ getUserFriendlyMessage(): string;
29
+ /**
30
+ * Check if this error type is retryable
31
+ */
32
+ isRetryable(): boolean;
33
+ /**
34
+ * Get recommended retry delay in milliseconds
35
+ */
36
+ getRetryDelay(): number;
37
+ }
38
+ /**
39
+ * Main error handler for SageMaker operations
40
+ *
41
+ * @param error - Original error from AWS SDK or other operations
42
+ * @param endpoint - Endpoint name where error occurred (optional)
43
+ * @returns Categorized SageMakerError with user guidance
44
+ */
45
+ export declare function handleSageMakerError(error: unknown, endpoint?: string): SageMakerError;
46
+ /**
47
+ * Create a validation error for configuration issues
48
+ *
49
+ * @param message - Validation error message
50
+ * @param field - Configuration field that failed validation
51
+ * @returns SageMakerError with validation details
52
+ */
53
+ export declare function createValidationError(message: string, field?: string): SageMakerError;
54
+ /**
55
+ * Create a credentials error with setup guidance
56
+ *
57
+ * @param message - Credentials error message
58
+ * @returns SageMakerError with credentials guidance
59
+ */
60
+ export declare function createCredentialsError(message: string): SageMakerError;
61
+ /**
62
+ * Create a network error with connectivity guidance
63
+ *
64
+ * @param message - Network error message
65
+ * @param endpoint - Endpoint that failed to connect
66
+ * @returns SageMakerError with network guidance
67
+ */
68
+ export declare function createNetworkError(message: string, endpoint?: string): SageMakerError;
69
+ /**
70
+ * Check if an error is retryable based on its characteristics
71
+ *
72
+ * @param error - Error to check
73
+ * @returns True if the error suggests a retry might succeed
74
+ */
75
+ export declare function isRetryableError(error: unknown): boolean;
76
+ /**
77
+ * Get recommended retry delay for an error
78
+ *
79
+ * @param error - Error to get retry delay for
80
+ * @param attempt - Current retry attempt number (for exponential backoff)
81
+ * @returns Recommended delay in milliseconds
82
+ */
83
+ export declare function getRetryDelay(error: unknown, attempt?: number): number;