@juspay/neurolink 7.7.0 → 7.8.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.
- package/CHANGELOG.md +20 -2
- package/README.md +33 -2
- package/dist/cli/commands/config.d.ts +3 -3
- package/dist/cli/commands/sagemaker.d.ts +11 -0
- package/dist/cli/commands/sagemaker.js +778 -0
- package/dist/cli/factories/commandFactory.js +1 -0
- package/dist/cli/index.js +3 -0
- package/dist/cli/utils/interactiveSetup.js +28 -0
- package/dist/core/baseProvider.d.ts +2 -2
- package/dist/core/types.d.ts +1 -0
- package/dist/core/types.js +1 -0
- package/dist/factories/providerRegistry.js +5 -0
- package/dist/lib/core/baseProvider.d.ts +2 -2
- package/dist/lib/core/types.d.ts +1 -0
- package/dist/lib/core/types.js +1 -0
- package/dist/lib/factories/providerRegistry.js +5 -0
- package/dist/lib/providers/amazonSagemaker.d.ts +67 -0
- package/dist/lib/providers/amazonSagemaker.js +149 -0
- package/dist/lib/providers/index.d.ts +4 -0
- package/dist/lib/providers/index.js +4 -0
- package/dist/lib/providers/sagemaker/adaptive-semaphore.d.ts +86 -0
- package/dist/lib/providers/sagemaker/adaptive-semaphore.js +212 -0
- package/dist/lib/providers/sagemaker/client.d.ts +156 -0
- package/dist/lib/providers/sagemaker/client.js +462 -0
- package/dist/lib/providers/sagemaker/config.d.ts +73 -0
- package/dist/lib/providers/sagemaker/config.js +308 -0
- package/dist/lib/providers/sagemaker/detection.d.ts +176 -0
- package/dist/lib/providers/sagemaker/detection.js +596 -0
- package/dist/lib/providers/sagemaker/diagnostics.d.ts +37 -0
- package/dist/lib/providers/sagemaker/diagnostics.js +137 -0
- package/dist/lib/providers/sagemaker/error-constants.d.ts +78 -0
- package/dist/lib/providers/sagemaker/error-constants.js +227 -0
- package/dist/lib/providers/sagemaker/errors.d.ts +83 -0
- package/dist/lib/providers/sagemaker/errors.js +216 -0
- package/dist/lib/providers/sagemaker/index.d.ts +35 -0
- package/dist/lib/providers/sagemaker/index.js +67 -0
- package/dist/lib/providers/sagemaker/language-model.d.ts +182 -0
- package/dist/lib/providers/sagemaker/language-model.js +755 -0
- package/dist/lib/providers/sagemaker/parsers.d.ts +136 -0
- package/dist/lib/providers/sagemaker/parsers.js +625 -0
- package/dist/lib/providers/sagemaker/streaming.d.ts +39 -0
- package/dist/lib/providers/sagemaker/streaming.js +320 -0
- package/dist/lib/providers/sagemaker/structured-parser.d.ts +117 -0
- package/dist/lib/providers/sagemaker/structured-parser.js +625 -0
- package/dist/lib/providers/sagemaker/types.d.ts +456 -0
- package/dist/lib/providers/sagemaker/types.js +7 -0
- package/dist/lib/types/cli.d.ts +36 -1
- package/dist/lib/utils/providerConfig.js +6 -2
- package/dist/lib/utils/providerHealth.js +45 -9
- package/dist/providers/amazonSagemaker.d.ts +67 -0
- package/dist/providers/amazonSagemaker.js +149 -0
- package/dist/providers/index.d.ts +4 -0
- package/dist/providers/index.js +4 -0
- package/dist/providers/sagemaker/adaptive-semaphore.d.ts +86 -0
- package/dist/providers/sagemaker/adaptive-semaphore.js +212 -0
- package/dist/providers/sagemaker/client.d.ts +156 -0
- package/dist/providers/sagemaker/client.js +462 -0
- package/dist/providers/sagemaker/config.d.ts +73 -0
- package/dist/providers/sagemaker/config.js +308 -0
- package/dist/providers/sagemaker/detection.d.ts +176 -0
- package/dist/providers/sagemaker/detection.js +596 -0
- package/dist/providers/sagemaker/diagnostics.d.ts +37 -0
- package/dist/providers/sagemaker/diagnostics.js +137 -0
- package/dist/providers/sagemaker/error-constants.d.ts +78 -0
- package/dist/providers/sagemaker/error-constants.js +227 -0
- package/dist/providers/sagemaker/errors.d.ts +83 -0
- package/dist/providers/sagemaker/errors.js +216 -0
- package/dist/providers/sagemaker/index.d.ts +35 -0
- package/dist/providers/sagemaker/index.js +67 -0
- package/dist/providers/sagemaker/language-model.d.ts +182 -0
- package/dist/providers/sagemaker/language-model.js +755 -0
- package/dist/providers/sagemaker/parsers.d.ts +136 -0
- package/dist/providers/sagemaker/parsers.js +625 -0
- package/dist/providers/sagemaker/streaming.d.ts +39 -0
- package/dist/providers/sagemaker/streaming.js +320 -0
- package/dist/providers/sagemaker/structured-parser.d.ts +117 -0
- package/dist/providers/sagemaker/structured-parser.js +625 -0
- package/dist/providers/sagemaker/types.d.ts +456 -0
- package/dist/providers/sagemaker/types.js +7 -0
- package/dist/types/cli.d.ts +36 -1
- package/dist/utils/providerConfig.js +6 -2
- package/dist/utils/providerHealth.js +45 -9
- package/package.json +4 -1
|
@@ -0,0 +1,216 @@
|
|
|
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 { ERROR_MESSAGE_TEMPLATES, ERROR_MESSAGE_PREFIXES, RETRY_DELAYS, RETRYABLE_ERROR_CONDITIONS, AWS_ERROR_MAPPINGS, ERROR_KEYWORDS, } from "./error-constants.js";
|
|
8
|
+
/**
|
|
9
|
+
* Custom error class for SageMaker-specific errors
|
|
10
|
+
*/
|
|
11
|
+
export class SageMakerError extends Error {
|
|
12
|
+
code;
|
|
13
|
+
statusCode;
|
|
14
|
+
cause;
|
|
15
|
+
endpoint;
|
|
16
|
+
requestId;
|
|
17
|
+
retryable;
|
|
18
|
+
constructor(message, code = "UNKNOWN_ERROR", statusCode, cause, endpoint, requestId, retryable = false) {
|
|
19
|
+
super(message);
|
|
20
|
+
this.name = "SageMakerError";
|
|
21
|
+
this.code = code;
|
|
22
|
+
this.statusCode = statusCode;
|
|
23
|
+
this.cause = cause;
|
|
24
|
+
this.endpoint = endpoint;
|
|
25
|
+
this.requestId = requestId;
|
|
26
|
+
this.retryable = retryable;
|
|
27
|
+
// Capture stack trace if available
|
|
28
|
+
if (Error.captureStackTrace) {
|
|
29
|
+
Error.captureStackTrace(this, SageMakerError);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Convert error to JSON for logging/serialization
|
|
34
|
+
*/
|
|
35
|
+
toJSON() {
|
|
36
|
+
return {
|
|
37
|
+
code: this.code,
|
|
38
|
+
message: this.message,
|
|
39
|
+
statusCode: this.statusCode,
|
|
40
|
+
cause: this.cause,
|
|
41
|
+
endpoint: this.endpoint,
|
|
42
|
+
requestId: this.requestId,
|
|
43
|
+
retryable: this.retryable,
|
|
44
|
+
stack: this.stack,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Get user-friendly error message with troubleshooting guidance
|
|
49
|
+
*/
|
|
50
|
+
getUserFriendlyMessage() {
|
|
51
|
+
return getSageMakerErrorGuidance(this.code, this.message, this.endpoint);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Check if this error type is retryable
|
|
55
|
+
*/
|
|
56
|
+
isRetryable() {
|
|
57
|
+
return this.retryable;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Get recommended retry delay in milliseconds
|
|
61
|
+
*/
|
|
62
|
+
getRetryDelay() {
|
|
63
|
+
return (RETRY_DELAYS[this.code] ||
|
|
64
|
+
RETRY_DELAYS.DEFAULT);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Main error handler for SageMaker operations
|
|
69
|
+
*
|
|
70
|
+
* @param error - Original error from AWS SDK or other operations
|
|
71
|
+
* @param endpoint - Endpoint name where error occurred (optional)
|
|
72
|
+
* @returns Categorized SageMakerError with user guidance
|
|
73
|
+
*/
|
|
74
|
+
export function handleSageMakerError(error, endpoint) {
|
|
75
|
+
// Handle cases where error is already a SageMakerError
|
|
76
|
+
if (error instanceof SageMakerError) {
|
|
77
|
+
return error;
|
|
78
|
+
}
|
|
79
|
+
// Handle standard Error objects
|
|
80
|
+
if (error instanceof Error) {
|
|
81
|
+
const errorName = error.name;
|
|
82
|
+
const errorMessage = error.message.toLowerCase();
|
|
83
|
+
// AWS SDK specific errors using centralized constants
|
|
84
|
+
if (errorName === "ValidationException" ||
|
|
85
|
+
ERROR_KEYWORDS.VALIDATION.some((keyword) => errorMessage.includes(keyword))) {
|
|
86
|
+
return new SageMakerError(`${ERROR_MESSAGE_PREFIXES.VALIDATION}: ${error.message}`, "VALIDATION_ERROR", 400, error, endpoint, extractRequestId(error), false);
|
|
87
|
+
}
|
|
88
|
+
if (errorName === "ModelError" ||
|
|
89
|
+
ERROR_KEYWORDS.MODEL.some((keyword) => errorMessage.includes(keyword))) {
|
|
90
|
+
return new SageMakerError(`${ERROR_MESSAGE_PREFIXES.MODEL}: ${error.message}`, "MODEL_ERROR", 500, error, endpoint, extractRequestId(error), false);
|
|
91
|
+
}
|
|
92
|
+
if (errorName === "InternalFailure" ||
|
|
93
|
+
ERROR_KEYWORDS.INTERNAL.some((keyword) => errorMessage.includes(keyword))) {
|
|
94
|
+
return new SageMakerError(`${ERROR_MESSAGE_PREFIXES.INTERNAL}: ${error.message}`, "INTERNAL_ERROR", 500, error, endpoint, extractRequestId(error), true);
|
|
95
|
+
}
|
|
96
|
+
if (errorName === "ServiceUnavailable" ||
|
|
97
|
+
ERROR_KEYWORDS.SERVICE_UNAVAILABLE.some((keyword) => errorMessage.includes(keyword))) {
|
|
98
|
+
return new SageMakerError(`${ERROR_MESSAGE_PREFIXES.SERVICE_UNAVAILABLE}: ${error.message}`, "SERVICE_UNAVAILABLE", 503, error, endpoint, extractRequestId(error), true);
|
|
99
|
+
}
|
|
100
|
+
if (errorName === "ThrottlingException" ||
|
|
101
|
+
ERROR_KEYWORDS.THROTTLING.some((keyword) => errorMessage.includes(keyword))) {
|
|
102
|
+
return new SageMakerError(`${ERROR_MESSAGE_PREFIXES.THROTTLING}: ${error.message}`, "THROTTLING_ERROR", 429, error, endpoint, extractRequestId(error), true);
|
|
103
|
+
}
|
|
104
|
+
if (errorName === "CredentialsError" ||
|
|
105
|
+
ERROR_KEYWORDS.CREDENTIALS.some((keyword) => errorMessage.includes(keyword))) {
|
|
106
|
+
return new SageMakerError(`${ERROR_MESSAGE_PREFIXES.CREDENTIALS}: ${error.message}`, "CREDENTIALS_ERROR", 401, error, endpoint, undefined, false);
|
|
107
|
+
}
|
|
108
|
+
if (errorName === "NetworkingError" ||
|
|
109
|
+
ERROR_KEYWORDS.NETWORK.some((keyword) => errorMessage.includes(keyword))) {
|
|
110
|
+
return new SageMakerError(`${ERROR_MESSAGE_PREFIXES.NETWORK}: ${error.message}`, "NETWORK_ERROR", 0, error, endpoint, undefined, true);
|
|
111
|
+
}
|
|
112
|
+
if (ERROR_KEYWORDS.ENDPOINT_NOT_FOUND.every((keyword) => errorMessage.includes(keyword))) {
|
|
113
|
+
return new SageMakerError(`${ERROR_MESSAGE_PREFIXES.ENDPOINT_NOT_FOUND}: ${error.message}`, "ENDPOINT_NOT_FOUND", 404, error, endpoint, extractRequestId(error), false);
|
|
114
|
+
}
|
|
115
|
+
// Generic error handling
|
|
116
|
+
return new SageMakerError(error.message, "UNKNOWN_ERROR", 500, error, endpoint, extractRequestId(error), false);
|
|
117
|
+
}
|
|
118
|
+
// Handle non-Error objects
|
|
119
|
+
const errorMessage = typeof error === "string" ? error : "Unknown error occurred";
|
|
120
|
+
return new SageMakerError(errorMessage, "UNKNOWN_ERROR", 500, undefined, endpoint, undefined, false);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Extract request ID from AWS SDK error for debugging
|
|
124
|
+
*
|
|
125
|
+
* @param error - Error object that might contain request ID
|
|
126
|
+
* @returns Request ID if found, undefined otherwise
|
|
127
|
+
*/
|
|
128
|
+
function extractRequestId(error) {
|
|
129
|
+
const errorAny = error;
|
|
130
|
+
return (errorAny.requestId ||
|
|
131
|
+
errorAny.RequestId ||
|
|
132
|
+
errorAny.$metadata?.requestId ||
|
|
133
|
+
undefined);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Get user-friendly error guidance based on error code
|
|
137
|
+
*
|
|
138
|
+
* @param code - SageMaker error code
|
|
139
|
+
* @param originalMessage - Original error message
|
|
140
|
+
* @param endpoint - Endpoint name (optional)
|
|
141
|
+
* @returns User-friendly error message with troubleshooting steps
|
|
142
|
+
*/
|
|
143
|
+
function getSageMakerErrorGuidance(code, originalMessage, endpoint) {
|
|
144
|
+
const endpointContext = endpoint ? ` (endpoint: ${endpoint})` : "";
|
|
145
|
+
// Get template for the error code, falling back to default
|
|
146
|
+
const template = ERROR_MESSAGE_TEMPLATES[code] || ERROR_MESSAGE_TEMPLATES.DEFAULT;
|
|
147
|
+
// Replace placeholders in the template
|
|
148
|
+
return template
|
|
149
|
+
.replace("{endpointContext}", endpointContext)
|
|
150
|
+
.replace("{originalMessage}", originalMessage);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Create a validation error for configuration issues
|
|
154
|
+
*
|
|
155
|
+
* @param message - Validation error message
|
|
156
|
+
* @param field - Configuration field that failed validation
|
|
157
|
+
* @returns SageMakerError with validation details
|
|
158
|
+
*/
|
|
159
|
+
export function createValidationError(message, field) {
|
|
160
|
+
const fullMessage = field
|
|
161
|
+
? `${ERROR_MESSAGE_PREFIXES.VALIDATION_FIELD} '${field}': ${message}`
|
|
162
|
+
: message;
|
|
163
|
+
return new SageMakerError(fullMessage, "VALIDATION_ERROR", 400);
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Create a credentials error with setup guidance
|
|
167
|
+
*
|
|
168
|
+
* @param message - Credentials error message
|
|
169
|
+
* @returns SageMakerError with credentials guidance
|
|
170
|
+
*/
|
|
171
|
+
export function createCredentialsError(message) {
|
|
172
|
+
return new SageMakerError(`${ERROR_MESSAGE_PREFIXES.CREDENTIALS_SETUP}: ${message}`, "CREDENTIALS_ERROR", 401, undefined, undefined, undefined, false);
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Create a network error with connectivity guidance
|
|
176
|
+
*
|
|
177
|
+
* @param message - Network error message
|
|
178
|
+
* @param endpoint - Endpoint that failed to connect
|
|
179
|
+
* @returns SageMakerError with network guidance
|
|
180
|
+
*/
|
|
181
|
+
export function createNetworkError(message, endpoint) {
|
|
182
|
+
return new SageMakerError(`${ERROR_MESSAGE_PREFIXES.NETWORK_CONNECTION}: ${message}`, "NETWORK_ERROR", 0, undefined, endpoint, undefined, true);
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Check if an error is retryable based on its characteristics
|
|
186
|
+
*
|
|
187
|
+
* @param error - Error to check
|
|
188
|
+
* @returns True if the error suggests a retry might succeed
|
|
189
|
+
*/
|
|
190
|
+
export function isRetryableError(error) {
|
|
191
|
+
if (error instanceof SageMakerError) {
|
|
192
|
+
return error.isRetryable();
|
|
193
|
+
}
|
|
194
|
+
if (error instanceof Error) {
|
|
195
|
+
const errorMessage = error.message.toLowerCase();
|
|
196
|
+
const errorName = error.name;
|
|
197
|
+
// Check against retryable error names and message keywords
|
|
198
|
+
return (RETRYABLE_ERROR_CONDITIONS.ERROR_NAMES.includes(errorName) ||
|
|
199
|
+
RETRYABLE_ERROR_CONDITIONS.ERROR_MESSAGE_KEYWORDS.some((keyword) => errorMessage.includes(keyword)));
|
|
200
|
+
}
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Get recommended retry delay for an error
|
|
205
|
+
*
|
|
206
|
+
* @param error - Error to get retry delay for
|
|
207
|
+
* @param attempt - Current retry attempt number (for exponential backoff)
|
|
208
|
+
* @returns Recommended delay in milliseconds
|
|
209
|
+
*/
|
|
210
|
+
export function getRetryDelay(error, attempt = 1) {
|
|
211
|
+
if (error instanceof SageMakerError) {
|
|
212
|
+
return error.getRetryDelay() * Math.pow(2, attempt - 1);
|
|
213
|
+
}
|
|
214
|
+
// Default exponential backoff
|
|
215
|
+
return 1000 * Math.pow(2, attempt - 1);
|
|
216
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Amazon SageMaker Provider - Main Export Module (Simplified)
|
|
3
|
+
*
|
|
4
|
+
* This module provides the main exports for SageMaker integration (Phase 1).
|
|
5
|
+
* Full implementation will be completed in subsequent phases.
|
|
6
|
+
*/
|
|
7
|
+
import { AmazonSageMakerProvider } from "../amazonSagemaker.js";
|
|
8
|
+
export { AmazonSageMakerProvider } from "../amazonSagemaker.js";
|
|
9
|
+
export { SageMakerRuntimeClient, createSageMakerRuntimeClient, testSageMakerConnectivity, } from "./client.js";
|
|
10
|
+
export { getSageMakerConfig, getSageMakerModelConfig, getDefaultSageMakerEndpoint, getSageMakerModel, validateAWSCredentials, getConfigurationSummary, clearConfigurationCache, loadConfigurationFromFile, checkSageMakerConfiguration, } from "./config.js";
|
|
11
|
+
export { SageMakerError, handleSageMakerError, createValidationError, createCredentialsError, createNetworkError, isRetryableError, getRetryDelay, } from "./errors.js";
|
|
12
|
+
export type { SageMakerConfig, SageMakerModelConfig, SageMakerEndpointInfo, SageMakerUsage, InvokeEndpointParams, InvokeEndpointResponse, SageMakerStreamChunk, SageMakerToolCall, SageMakerToolResult, SageMakerGenerationOptions, SageMakerGenerationResponse, SageMakerErrorCode, SageMakerErrorInfo, BatchInferenceConfig, ModelDeploymentConfig, EndpointMetrics, CostEstimate, } from "./types.js";
|
|
13
|
+
/**
|
|
14
|
+
* Factory function to create a SageMaker Provider
|
|
15
|
+
*
|
|
16
|
+
* @param modelName - Optional model name
|
|
17
|
+
* @param endpointName - Optional endpoint name
|
|
18
|
+
* @returns AmazonSageMakerProvider instance
|
|
19
|
+
*/
|
|
20
|
+
export declare function createSageMakerProvider(modelName?: string, endpointName?: string): AmazonSageMakerProvider;
|
|
21
|
+
/**
|
|
22
|
+
* Utility function to validate SageMaker setup (Simplified)
|
|
23
|
+
*
|
|
24
|
+
* @returns Setup validation result
|
|
25
|
+
*/
|
|
26
|
+
export declare function validateSageMakerSetup(): Promise<{
|
|
27
|
+
valid: boolean;
|
|
28
|
+
issues: string[];
|
|
29
|
+
recommendations: string[];
|
|
30
|
+
configSummary: Record<string, unknown>;
|
|
31
|
+
}>;
|
|
32
|
+
/**
|
|
33
|
+
* Default export for convenience
|
|
34
|
+
*/
|
|
35
|
+
export { AmazonSageMakerProvider as default };
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Amazon SageMaker Provider - Main Export Module (Simplified)
|
|
3
|
+
*
|
|
4
|
+
* This module provides the main exports for SageMaker integration (Phase 1).
|
|
5
|
+
* Full implementation will be completed in subsequent phases.
|
|
6
|
+
*/
|
|
7
|
+
// Import for internal use
|
|
8
|
+
import { AmazonSageMakerProvider } from "../amazonSagemaker.js";
|
|
9
|
+
import { checkSageMakerConfiguration } from "./config.js";
|
|
10
|
+
// Core provider exports
|
|
11
|
+
export { AmazonSageMakerProvider } from "../amazonSagemaker.js";
|
|
12
|
+
export { SageMakerRuntimeClient, createSageMakerRuntimeClient, testSageMakerConnectivity, } from "./client.js";
|
|
13
|
+
// Configuration exports
|
|
14
|
+
export { getSageMakerConfig, getSageMakerModelConfig, getDefaultSageMakerEndpoint, getSageMakerModel, validateAWSCredentials, getConfigurationSummary, clearConfigurationCache, loadConfigurationFromFile, checkSageMakerConfiguration, } from "./config.js";
|
|
15
|
+
// Error handling exports
|
|
16
|
+
export { SageMakerError, handleSageMakerError, createValidationError, createCredentialsError, createNetworkError, isRetryableError, getRetryDelay, } from "./errors.js";
|
|
17
|
+
/**
|
|
18
|
+
* Factory function to create a SageMaker Provider
|
|
19
|
+
*
|
|
20
|
+
* @param modelName - Optional model name
|
|
21
|
+
* @param endpointName - Optional endpoint name
|
|
22
|
+
* @returns AmazonSageMakerProvider instance
|
|
23
|
+
*/
|
|
24
|
+
export function createSageMakerProvider(modelName, endpointName) {
|
|
25
|
+
return new AmazonSageMakerProvider(modelName, endpointName);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Utility function to validate SageMaker setup (Simplified)
|
|
29
|
+
*
|
|
30
|
+
* @returns Setup validation result
|
|
31
|
+
*/
|
|
32
|
+
export async function validateSageMakerSetup() {
|
|
33
|
+
const issues = [];
|
|
34
|
+
const recommendations = [];
|
|
35
|
+
try {
|
|
36
|
+
// Check configuration
|
|
37
|
+
const configCheck = checkSageMakerConfiguration();
|
|
38
|
+
if (!configCheck.configured) {
|
|
39
|
+
issues.push(...configCheck.issues);
|
|
40
|
+
}
|
|
41
|
+
// Add general recommendations
|
|
42
|
+
if (issues.length === 0) {
|
|
43
|
+
recommendations.push("SageMaker basic configuration appears valid");
|
|
44
|
+
recommendations.push("Full functionality will be available in Phase 2");
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
valid: issues.length === 0,
|
|
48
|
+
issues,
|
|
49
|
+
recommendations,
|
|
50
|
+
configSummary: configCheck.summary,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
return {
|
|
55
|
+
valid: false,
|
|
56
|
+
issues: [
|
|
57
|
+
`Setup validation failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
58
|
+
],
|
|
59
|
+
recommendations: ["Check your SageMaker configuration and try again"],
|
|
60
|
+
configSummary: {},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Default export for convenience
|
|
66
|
+
*/
|
|
67
|
+
export { AmazonSageMakerProvider as default };
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SageMaker Language Model Implementation
|
|
3
|
+
*
|
|
4
|
+
* This module implements the LanguageModelV1 interface for Amazon SageMaker
|
|
5
|
+
* integration with the Vercel AI SDK.
|
|
6
|
+
*/
|
|
7
|
+
import type { LanguageModelV1, LanguageModelV1CallOptions, LanguageModelV1StreamPart } from "ai";
|
|
8
|
+
import type { SageMakerConfig, SageMakerModelConfig } from "./types.js";
|
|
9
|
+
/**
|
|
10
|
+
* SageMaker Language Model implementing LanguageModelV1 interface
|
|
11
|
+
*/
|
|
12
|
+
export declare class SageMakerLanguageModel implements LanguageModelV1 {
|
|
13
|
+
readonly specificationVersion = "v1";
|
|
14
|
+
readonly provider = "sagemaker";
|
|
15
|
+
readonly modelId: string;
|
|
16
|
+
readonly supportsStreaming = true;
|
|
17
|
+
readonly defaultObjectGenerationMode: "json";
|
|
18
|
+
private client;
|
|
19
|
+
private config;
|
|
20
|
+
private modelConfig;
|
|
21
|
+
constructor(modelId: string, config: SageMakerConfig, modelConfig: SageMakerModelConfig);
|
|
22
|
+
/**
|
|
23
|
+
* Generate text synchronously using SageMaker endpoint
|
|
24
|
+
*/
|
|
25
|
+
doGenerate(options: LanguageModelV1CallOptions): Promise<{
|
|
26
|
+
text?: string;
|
|
27
|
+
reasoning?: string | Array<{
|
|
28
|
+
type: "text";
|
|
29
|
+
text: string;
|
|
30
|
+
signature?: string;
|
|
31
|
+
} | {
|
|
32
|
+
type: "redacted";
|
|
33
|
+
data: string;
|
|
34
|
+
}>;
|
|
35
|
+
files?: Array<{
|
|
36
|
+
data: string | Uint8Array;
|
|
37
|
+
mimeType: string;
|
|
38
|
+
}>;
|
|
39
|
+
logprobs?: Array<{
|
|
40
|
+
token: string;
|
|
41
|
+
logprob: number;
|
|
42
|
+
topLogprobs: Array<{
|
|
43
|
+
token: string;
|
|
44
|
+
logprob: number;
|
|
45
|
+
}>;
|
|
46
|
+
}>;
|
|
47
|
+
usage: {
|
|
48
|
+
promptTokens: number;
|
|
49
|
+
completionTokens: number;
|
|
50
|
+
totalTokens?: number;
|
|
51
|
+
};
|
|
52
|
+
finishReason: "stop" | "length" | "content-filter" | "tool-calls" | "error" | "unknown";
|
|
53
|
+
warnings?: Array<{
|
|
54
|
+
type: "other";
|
|
55
|
+
message: string;
|
|
56
|
+
}>;
|
|
57
|
+
rawCall: {
|
|
58
|
+
rawPrompt: unknown;
|
|
59
|
+
rawSettings: Record<string, unknown>;
|
|
60
|
+
};
|
|
61
|
+
rawResponse?: {
|
|
62
|
+
headers?: Record<string, string>;
|
|
63
|
+
};
|
|
64
|
+
request?: {
|
|
65
|
+
body?: string;
|
|
66
|
+
};
|
|
67
|
+
}>;
|
|
68
|
+
/**
|
|
69
|
+
* Generate text with streaming using SageMaker endpoint
|
|
70
|
+
*/
|
|
71
|
+
doStream(options: LanguageModelV1CallOptions): Promise<{
|
|
72
|
+
stream: ReadableStream<LanguageModelV1StreamPart>;
|
|
73
|
+
rawCall: {
|
|
74
|
+
rawPrompt: unknown;
|
|
75
|
+
rawSettings: Record<string, unknown>;
|
|
76
|
+
};
|
|
77
|
+
rawResponse?: {
|
|
78
|
+
headers?: Record<string, string>;
|
|
79
|
+
};
|
|
80
|
+
request?: {
|
|
81
|
+
body?: string;
|
|
82
|
+
};
|
|
83
|
+
warnings?: Array<{
|
|
84
|
+
type: "other";
|
|
85
|
+
message: string;
|
|
86
|
+
}>;
|
|
87
|
+
}>;
|
|
88
|
+
/**
|
|
89
|
+
* Convert AI SDK options to SageMaker request format
|
|
90
|
+
*/
|
|
91
|
+
private convertToSageMakerRequest;
|
|
92
|
+
/**
|
|
93
|
+
* Convert Vercel AI SDK tools to SageMaker format
|
|
94
|
+
*/
|
|
95
|
+
private convertToolsToSageMakerFormat;
|
|
96
|
+
/**
|
|
97
|
+
* Convert Vercel AI SDK tool choice to SageMaker format
|
|
98
|
+
*/
|
|
99
|
+
private convertToolChoiceToSageMakerFormat;
|
|
100
|
+
/**
|
|
101
|
+
* Convert Vercel AI SDK response format to SageMaker format (Phase 4)
|
|
102
|
+
*/
|
|
103
|
+
private convertResponseFormatToSageMakerFormat;
|
|
104
|
+
/**
|
|
105
|
+
* Extract text content from AI SDK prompt format
|
|
106
|
+
*/
|
|
107
|
+
private extractPromptText;
|
|
108
|
+
/**
|
|
109
|
+
* Extract generated text from SageMaker response
|
|
110
|
+
*/
|
|
111
|
+
private extractTextFromResponse;
|
|
112
|
+
/**
|
|
113
|
+
* Extract tool calls from SageMaker response (Phase 4)
|
|
114
|
+
*/
|
|
115
|
+
private extractToolCallsFromResponse;
|
|
116
|
+
/**
|
|
117
|
+
* Map SageMaker finish reason to standardized format
|
|
118
|
+
*/
|
|
119
|
+
private mapSageMakerFinishReason;
|
|
120
|
+
/**
|
|
121
|
+
* Get model configuration summary for debugging
|
|
122
|
+
*/
|
|
123
|
+
getModelInfo(): {
|
|
124
|
+
modelId: string;
|
|
125
|
+
provider: string;
|
|
126
|
+
specificationVersion: string;
|
|
127
|
+
endpointName: string;
|
|
128
|
+
modelType: "huggingface" | "mistral" | "custom" | "claude" | "llama" | "jumpstart" | undefined;
|
|
129
|
+
region: string;
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* Test basic connectivity to the SageMaker endpoint
|
|
133
|
+
*/
|
|
134
|
+
testConnectivity(): Promise<{
|
|
135
|
+
success: boolean;
|
|
136
|
+
error?: string;
|
|
137
|
+
}>;
|
|
138
|
+
/**
|
|
139
|
+
* Batch inference support (Phase 4)
|
|
140
|
+
* Process multiple prompts in a single request for efficiency
|
|
141
|
+
*/
|
|
142
|
+
doBatchGenerate(prompts: string[], options?: {
|
|
143
|
+
maxTokens?: number;
|
|
144
|
+
temperature?: number;
|
|
145
|
+
topP?: number;
|
|
146
|
+
}): Promise<Array<{
|
|
147
|
+
text: string;
|
|
148
|
+
usage: {
|
|
149
|
+
promptTokens: number;
|
|
150
|
+
completionTokens: number;
|
|
151
|
+
totalTokens: number;
|
|
152
|
+
};
|
|
153
|
+
finishReason: "stop" | "length" | "content-filter" | "tool-calls" | "error" | "unknown";
|
|
154
|
+
}>>;
|
|
155
|
+
/**
|
|
156
|
+
* Process prompts in parallel with advanced concurrency control and error handling
|
|
157
|
+
*/
|
|
158
|
+
private processPromptsInParallel;
|
|
159
|
+
/**
|
|
160
|
+
* Enhanced model information with batch capabilities
|
|
161
|
+
*/
|
|
162
|
+
getModelCapabilities(): {
|
|
163
|
+
capabilities: {
|
|
164
|
+
streaming: boolean;
|
|
165
|
+
toolCalling: boolean;
|
|
166
|
+
structuredOutput: boolean;
|
|
167
|
+
batchInference: boolean;
|
|
168
|
+
supportedResponseFormats: string[];
|
|
169
|
+
supportedToolTypes: string[];
|
|
170
|
+
maxBatchSize: number;
|
|
171
|
+
adaptiveConcurrency: boolean;
|
|
172
|
+
errorRecovery: boolean;
|
|
173
|
+
};
|
|
174
|
+
modelId: string;
|
|
175
|
+
provider: string;
|
|
176
|
+
specificationVersion: string;
|
|
177
|
+
endpointName: string;
|
|
178
|
+
modelType: "huggingface" | "mistral" | "custom" | "claude" | "llama" | "jumpstart" | undefined;
|
|
179
|
+
region: string;
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
export default SageMakerLanguageModel;
|