@juspay/neurolink 9.91.0 → 9.91.1
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 +6 -0
- package/dist/browser/neurolink.min.js +292 -291
- package/dist/lib/providers/sagemaker/client.d.ts +9 -0
- package/dist/lib/providers/sagemaker/client.js +75 -30
- package/dist/providers/sagemaker/client.d.ts +9 -0
- package/dist/providers/sagemaker/client.js +75 -30
- package/package.json +2 -2
|
@@ -10,9 +10,18 @@ import type { SageMakerConfig, InvokeEndpointParams, InvokeEndpointResponse, Con
|
|
|
10
10
|
*/
|
|
11
11
|
export declare class SageMakerRuntimeClient {
|
|
12
12
|
private client;
|
|
13
|
+
private sdkModule;
|
|
13
14
|
private config;
|
|
14
15
|
private isDisposed;
|
|
15
16
|
constructor(config: SageMakerConfig);
|
|
17
|
+
/**
|
|
18
|
+
* Lazily load (and cache) the `@aws-sdk/client-sagemaker-runtime` module.
|
|
19
|
+
*/
|
|
20
|
+
private getSdk;
|
|
21
|
+
/**
|
|
22
|
+
* Lazily construct (and cache) the underlying AWS SDK client.
|
|
23
|
+
*/
|
|
24
|
+
private getClient;
|
|
16
25
|
/**
|
|
17
26
|
* Invoke a SageMaker endpoint for synchronous inference
|
|
18
27
|
*
|
|
@@ -4,38 +4,41 @@
|
|
|
4
4
|
* This module provides a wrapper around the AWS SDK SageMaker Runtime client
|
|
5
5
|
* with enhanced error handling, retry logic, and NeuroLink-specific features.
|
|
6
6
|
*/
|
|
7
|
-
import { SageMakerRuntimeClient as AWSClient, InvokeEndpointCommand, InvokeEndpointWithResponseStreamCommand, } from "@aws-sdk/client-sagemaker-runtime";
|
|
8
7
|
import { handleSageMakerError, SageMakerError, isRetryableError, getRetryDelay, } from "./errors.js";
|
|
9
8
|
import { logger } from "../../utils/logger.js";
|
|
9
|
+
/**
|
|
10
|
+
* Lazily load `@aws-sdk/client-sagemaker-runtime`.
|
|
11
|
+
*
|
|
12
|
+
* The package is an optional dependency: importing it only happens here, on
|
|
13
|
+
* first actual endpoint invocation, so constructing a SageMakerRuntimeClient
|
|
14
|
+
* (e.g. while the CLI builds its command tree at startup) never requires the
|
|
15
|
+
* SDK to be installed. If it's missing, surface a comprehensible, actionable
|
|
16
|
+
* error instead of a raw resolution failure.
|
|
17
|
+
*/
|
|
18
|
+
async function loadSageMakerRuntime() {
|
|
19
|
+
try {
|
|
20
|
+
return await import(/* @vite-ignore */ "@aws-sdk/client-sagemaker-runtime");
|
|
21
|
+
}
|
|
22
|
+
catch (err) {
|
|
23
|
+
const e = err instanceof Error ? err : null;
|
|
24
|
+
if (e?.code === "ERR_MODULE_NOT_FOUND" &&
|
|
25
|
+
e.message.includes("client-sagemaker-runtime")) {
|
|
26
|
+
throw new Error('SageMaker inference requires "@aws-sdk/client-sagemaker-runtime". Install it with:\n pnpm add @aws-sdk/client-sagemaker-runtime', { cause: err });
|
|
27
|
+
}
|
|
28
|
+
throw err;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
10
31
|
/**
|
|
11
32
|
* Enhanced SageMaker Runtime client with retry logic and error handling
|
|
12
33
|
*/
|
|
13
34
|
export class SageMakerRuntimeClient {
|
|
14
|
-
client;
|
|
35
|
+
client = null;
|
|
36
|
+
sdkModule = null;
|
|
15
37
|
config;
|
|
16
38
|
isDisposed = false;
|
|
17
39
|
constructor(config) {
|
|
18
40
|
this.config = config;
|
|
19
|
-
|
|
20
|
-
this.client = new AWSClient({
|
|
21
|
-
region: config.region,
|
|
22
|
-
credentials: {
|
|
23
|
-
accessKeyId: config.accessKeyId,
|
|
24
|
-
secretAccessKey: config.secretAccessKey,
|
|
25
|
-
sessionToken: config.sessionToken,
|
|
26
|
-
},
|
|
27
|
-
maxAttempts: config.maxRetries || 3,
|
|
28
|
-
requestHandler: {
|
|
29
|
-
requestTimeout: config.timeout || 30000,
|
|
30
|
-
httpsAgent: {
|
|
31
|
-
// Keep connections alive for better performance
|
|
32
|
-
keepAlive: true,
|
|
33
|
-
maxSockets: 50,
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
...(config.endpoint && { endpoint: config.endpoint }),
|
|
37
|
-
});
|
|
38
|
-
logger.debug("SageMaker Runtime client initialized", {
|
|
41
|
+
logger.debug("SageMaker Runtime client configured", {
|
|
39
42
|
region: config.region,
|
|
40
43
|
timeout: config.timeout,
|
|
41
44
|
maxRetries: config.maxRetries,
|
|
@@ -43,6 +46,51 @@ export class SageMakerRuntimeClient {
|
|
|
43
46
|
customEndpoint: !!config.endpoint,
|
|
44
47
|
});
|
|
45
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Lazily load (and cache) the `@aws-sdk/client-sagemaker-runtime` module.
|
|
51
|
+
*/
|
|
52
|
+
async getSdk() {
|
|
53
|
+
if (!this.sdkModule) {
|
|
54
|
+
this.sdkModule = await loadSageMakerRuntime();
|
|
55
|
+
}
|
|
56
|
+
return this.sdkModule;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Lazily construct (and cache) the underlying AWS SDK client.
|
|
60
|
+
*/
|
|
61
|
+
async getClient() {
|
|
62
|
+
if (this.isDisposed) {
|
|
63
|
+
throw new SageMakerError("Cannot perform operation on disposed SageMaker client", {
|
|
64
|
+
code: "VALIDATION_ERROR",
|
|
65
|
+
statusCode: 400,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
if (!this.client) {
|
|
69
|
+
const { SageMakerRuntimeClient: AWSClientCtor } = await this.getSdk();
|
|
70
|
+
this.client = new AWSClientCtor({
|
|
71
|
+
region: this.config.region,
|
|
72
|
+
credentials: {
|
|
73
|
+
accessKeyId: this.config.accessKeyId,
|
|
74
|
+
secretAccessKey: this.config.secretAccessKey,
|
|
75
|
+
sessionToken: this.config.sessionToken,
|
|
76
|
+
},
|
|
77
|
+
maxAttempts: this.config.maxRetries || 3,
|
|
78
|
+
requestHandler: {
|
|
79
|
+
requestTimeout: this.config.timeout || 30000,
|
|
80
|
+
httpsAgent: {
|
|
81
|
+
// Keep connections alive for better performance
|
|
82
|
+
keepAlive: true,
|
|
83
|
+
maxSockets: 50,
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
...(this.config.endpoint && { endpoint: this.config.endpoint }),
|
|
87
|
+
});
|
|
88
|
+
logger.debug("SageMaker Runtime AWS SDK client initialized", {
|
|
89
|
+
region: this.config.region,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
return this.client;
|
|
93
|
+
}
|
|
46
94
|
/**
|
|
47
95
|
* Invoke a SageMaker endpoint for synchronous inference
|
|
48
96
|
*
|
|
@@ -61,6 +109,7 @@ export class SageMakerRuntimeClient {
|
|
|
61
109
|
? params.Body.length
|
|
62
110
|
: params.Body?.length || 0,
|
|
63
111
|
});
|
|
112
|
+
const { InvokeEndpointCommand } = await this.getSdk();
|
|
64
113
|
// Prepare the command input
|
|
65
114
|
const input = {
|
|
66
115
|
EndpointName: params.EndpointName,
|
|
@@ -73,10 +122,7 @@ export class SageMakerRuntimeClient {
|
|
|
73
122
|
InferenceId: params.InferenceId,
|
|
74
123
|
};
|
|
75
124
|
const command = new InvokeEndpointCommand(input);
|
|
76
|
-
const client = this.
|
|
77
|
-
if (!client) {
|
|
78
|
-
throw new Error("SageMaker client has been disposed");
|
|
79
|
-
}
|
|
125
|
+
const client = await this.getClient();
|
|
80
126
|
const response = (await this.executeWithRetry(() => client.send(command), params.EndpointName));
|
|
81
127
|
const duration = Date.now() - startTime;
|
|
82
128
|
logger.debug("SageMaker endpoint invocation successful", {
|
|
@@ -120,6 +166,7 @@ export class SageMakerRuntimeClient {
|
|
|
120
166
|
? params.Body.length
|
|
121
167
|
: params.Body?.length || 0,
|
|
122
168
|
});
|
|
169
|
+
const { InvokeEndpointWithResponseStreamCommand } = await this.getSdk();
|
|
123
170
|
// Prepare the command input for streaming
|
|
124
171
|
const input = {
|
|
125
172
|
EndpointName: params.EndpointName,
|
|
@@ -130,10 +177,7 @@ export class SageMakerRuntimeClient {
|
|
|
130
177
|
// Note: TargetModel, TargetVariant, InferenceId not available in streaming interface
|
|
131
178
|
};
|
|
132
179
|
const command = new InvokeEndpointWithResponseStreamCommand(input);
|
|
133
|
-
const client = this.
|
|
134
|
-
if (!client) {
|
|
135
|
-
throw new Error("SageMaker client has been disposed");
|
|
136
|
-
}
|
|
180
|
+
const client = await this.getClient();
|
|
137
181
|
const response = (await this.executeWithRetry(() => client.send(command), params.EndpointName));
|
|
138
182
|
logger.debug("SageMaker streaming invocation started", {
|
|
139
183
|
endpointName: params.EndpointName,
|
|
@@ -415,6 +459,7 @@ export class SageMakerRuntimeClient {
|
|
|
415
459
|
// Clear our client reference to enable garbage collection
|
|
416
460
|
// Note: AWS SDK v3 handles all internal resource cleanup automatically
|
|
417
461
|
this.client = null;
|
|
462
|
+
this.sdkModule = null;
|
|
418
463
|
logger.debug("SageMaker Runtime client disposed", {
|
|
419
464
|
note: "AWS SDK v3 handles internal resource cleanup automatically",
|
|
420
465
|
});
|
|
@@ -10,9 +10,18 @@ import type { SageMakerConfig, InvokeEndpointParams, InvokeEndpointResponse, Con
|
|
|
10
10
|
*/
|
|
11
11
|
export declare class SageMakerRuntimeClient {
|
|
12
12
|
private client;
|
|
13
|
+
private sdkModule;
|
|
13
14
|
private config;
|
|
14
15
|
private isDisposed;
|
|
15
16
|
constructor(config: SageMakerConfig);
|
|
17
|
+
/**
|
|
18
|
+
* Lazily load (and cache) the `@aws-sdk/client-sagemaker-runtime` module.
|
|
19
|
+
*/
|
|
20
|
+
private getSdk;
|
|
21
|
+
/**
|
|
22
|
+
* Lazily construct (and cache) the underlying AWS SDK client.
|
|
23
|
+
*/
|
|
24
|
+
private getClient;
|
|
16
25
|
/**
|
|
17
26
|
* Invoke a SageMaker endpoint for synchronous inference
|
|
18
27
|
*
|
|
@@ -4,38 +4,41 @@
|
|
|
4
4
|
* This module provides a wrapper around the AWS SDK SageMaker Runtime client
|
|
5
5
|
* with enhanced error handling, retry logic, and NeuroLink-specific features.
|
|
6
6
|
*/
|
|
7
|
-
import { SageMakerRuntimeClient as AWSClient, InvokeEndpointCommand, InvokeEndpointWithResponseStreamCommand, } from "@aws-sdk/client-sagemaker-runtime";
|
|
8
7
|
import { handleSageMakerError, SageMakerError, isRetryableError, getRetryDelay, } from "./errors.js";
|
|
9
8
|
import { logger } from "../../utils/logger.js";
|
|
9
|
+
/**
|
|
10
|
+
* Lazily load `@aws-sdk/client-sagemaker-runtime`.
|
|
11
|
+
*
|
|
12
|
+
* The package is an optional dependency: importing it only happens here, on
|
|
13
|
+
* first actual endpoint invocation, so constructing a SageMakerRuntimeClient
|
|
14
|
+
* (e.g. while the CLI builds its command tree at startup) never requires the
|
|
15
|
+
* SDK to be installed. If it's missing, surface a comprehensible, actionable
|
|
16
|
+
* error instead of a raw resolution failure.
|
|
17
|
+
*/
|
|
18
|
+
async function loadSageMakerRuntime() {
|
|
19
|
+
try {
|
|
20
|
+
return await import(/* @vite-ignore */ "@aws-sdk/client-sagemaker-runtime");
|
|
21
|
+
}
|
|
22
|
+
catch (err) {
|
|
23
|
+
const e = err instanceof Error ? err : null;
|
|
24
|
+
if (e?.code === "ERR_MODULE_NOT_FOUND" &&
|
|
25
|
+
e.message.includes("client-sagemaker-runtime")) {
|
|
26
|
+
throw new Error('SageMaker inference requires "@aws-sdk/client-sagemaker-runtime". Install it with:\n pnpm add @aws-sdk/client-sagemaker-runtime', { cause: err });
|
|
27
|
+
}
|
|
28
|
+
throw err;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
10
31
|
/**
|
|
11
32
|
* Enhanced SageMaker Runtime client with retry logic and error handling
|
|
12
33
|
*/
|
|
13
34
|
export class SageMakerRuntimeClient {
|
|
14
|
-
client;
|
|
35
|
+
client = null;
|
|
36
|
+
sdkModule = null;
|
|
15
37
|
config;
|
|
16
38
|
isDisposed = false;
|
|
17
39
|
constructor(config) {
|
|
18
40
|
this.config = config;
|
|
19
|
-
|
|
20
|
-
this.client = new AWSClient({
|
|
21
|
-
region: config.region,
|
|
22
|
-
credentials: {
|
|
23
|
-
accessKeyId: config.accessKeyId,
|
|
24
|
-
secretAccessKey: config.secretAccessKey,
|
|
25
|
-
sessionToken: config.sessionToken,
|
|
26
|
-
},
|
|
27
|
-
maxAttempts: config.maxRetries || 3,
|
|
28
|
-
requestHandler: {
|
|
29
|
-
requestTimeout: config.timeout || 30000,
|
|
30
|
-
httpsAgent: {
|
|
31
|
-
// Keep connections alive for better performance
|
|
32
|
-
keepAlive: true,
|
|
33
|
-
maxSockets: 50,
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
...(config.endpoint && { endpoint: config.endpoint }),
|
|
37
|
-
});
|
|
38
|
-
logger.debug("SageMaker Runtime client initialized", {
|
|
41
|
+
logger.debug("SageMaker Runtime client configured", {
|
|
39
42
|
region: config.region,
|
|
40
43
|
timeout: config.timeout,
|
|
41
44
|
maxRetries: config.maxRetries,
|
|
@@ -43,6 +46,51 @@ export class SageMakerRuntimeClient {
|
|
|
43
46
|
customEndpoint: !!config.endpoint,
|
|
44
47
|
});
|
|
45
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Lazily load (and cache) the `@aws-sdk/client-sagemaker-runtime` module.
|
|
51
|
+
*/
|
|
52
|
+
async getSdk() {
|
|
53
|
+
if (!this.sdkModule) {
|
|
54
|
+
this.sdkModule = await loadSageMakerRuntime();
|
|
55
|
+
}
|
|
56
|
+
return this.sdkModule;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Lazily construct (and cache) the underlying AWS SDK client.
|
|
60
|
+
*/
|
|
61
|
+
async getClient() {
|
|
62
|
+
if (this.isDisposed) {
|
|
63
|
+
throw new SageMakerError("Cannot perform operation on disposed SageMaker client", {
|
|
64
|
+
code: "VALIDATION_ERROR",
|
|
65
|
+
statusCode: 400,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
if (!this.client) {
|
|
69
|
+
const { SageMakerRuntimeClient: AWSClientCtor } = await this.getSdk();
|
|
70
|
+
this.client = new AWSClientCtor({
|
|
71
|
+
region: this.config.region,
|
|
72
|
+
credentials: {
|
|
73
|
+
accessKeyId: this.config.accessKeyId,
|
|
74
|
+
secretAccessKey: this.config.secretAccessKey,
|
|
75
|
+
sessionToken: this.config.sessionToken,
|
|
76
|
+
},
|
|
77
|
+
maxAttempts: this.config.maxRetries || 3,
|
|
78
|
+
requestHandler: {
|
|
79
|
+
requestTimeout: this.config.timeout || 30000,
|
|
80
|
+
httpsAgent: {
|
|
81
|
+
// Keep connections alive for better performance
|
|
82
|
+
keepAlive: true,
|
|
83
|
+
maxSockets: 50,
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
...(this.config.endpoint && { endpoint: this.config.endpoint }),
|
|
87
|
+
});
|
|
88
|
+
logger.debug("SageMaker Runtime AWS SDK client initialized", {
|
|
89
|
+
region: this.config.region,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
return this.client;
|
|
93
|
+
}
|
|
46
94
|
/**
|
|
47
95
|
* Invoke a SageMaker endpoint for synchronous inference
|
|
48
96
|
*
|
|
@@ -61,6 +109,7 @@ export class SageMakerRuntimeClient {
|
|
|
61
109
|
? params.Body.length
|
|
62
110
|
: params.Body?.length || 0,
|
|
63
111
|
});
|
|
112
|
+
const { InvokeEndpointCommand } = await this.getSdk();
|
|
64
113
|
// Prepare the command input
|
|
65
114
|
const input = {
|
|
66
115
|
EndpointName: params.EndpointName,
|
|
@@ -73,10 +122,7 @@ export class SageMakerRuntimeClient {
|
|
|
73
122
|
InferenceId: params.InferenceId,
|
|
74
123
|
};
|
|
75
124
|
const command = new InvokeEndpointCommand(input);
|
|
76
|
-
const client = this.
|
|
77
|
-
if (!client) {
|
|
78
|
-
throw new Error("SageMaker client has been disposed");
|
|
79
|
-
}
|
|
125
|
+
const client = await this.getClient();
|
|
80
126
|
const response = (await this.executeWithRetry(() => client.send(command), params.EndpointName));
|
|
81
127
|
const duration = Date.now() - startTime;
|
|
82
128
|
logger.debug("SageMaker endpoint invocation successful", {
|
|
@@ -120,6 +166,7 @@ export class SageMakerRuntimeClient {
|
|
|
120
166
|
? params.Body.length
|
|
121
167
|
: params.Body?.length || 0,
|
|
122
168
|
});
|
|
169
|
+
const { InvokeEndpointWithResponseStreamCommand } = await this.getSdk();
|
|
123
170
|
// Prepare the command input for streaming
|
|
124
171
|
const input = {
|
|
125
172
|
EndpointName: params.EndpointName,
|
|
@@ -130,10 +177,7 @@ export class SageMakerRuntimeClient {
|
|
|
130
177
|
// Note: TargetModel, TargetVariant, InferenceId not available in streaming interface
|
|
131
178
|
};
|
|
132
179
|
const command = new InvokeEndpointWithResponseStreamCommand(input);
|
|
133
|
-
const client = this.
|
|
134
|
-
if (!client) {
|
|
135
|
-
throw new Error("SageMaker client has been disposed");
|
|
136
|
-
}
|
|
180
|
+
const client = await this.getClient();
|
|
137
181
|
const response = (await this.executeWithRetry(() => client.send(command), params.EndpointName));
|
|
138
182
|
logger.debug("SageMaker streaming invocation started", {
|
|
139
183
|
endpointName: params.EndpointName,
|
|
@@ -415,6 +459,7 @@ export class SageMakerRuntimeClient {
|
|
|
415
459
|
// Clear our client reference to enable garbage collection
|
|
416
460
|
// Note: AWS SDK v3 handles all internal resource cleanup automatically
|
|
417
461
|
this.client = null;
|
|
462
|
+
this.sdkModule = null;
|
|
418
463
|
logger.debug("SageMaker Runtime client disposed", {
|
|
419
464
|
note: "AWS SDK v3 handles internal resource cleanup automatically",
|
|
420
465
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@juspay/neurolink",
|
|
3
|
-
"version": "9.91.
|
|
3
|
+
"version": "9.91.1",
|
|
4
4
|
"packageManager": "pnpm@10.15.1",
|
|
5
5
|
"description": "TypeScript AI SDK with 24+ LLM providers behind one consistent API. MCP-native (connect any MCP server), voice TTS/STT/realtime, RAG, agents, memory, context compaction. OpenAI · Anthropic · Gemini · Bedrock · Azure · Ollama · DeepSeek · NVIDIA NIM and more.",
|
|
6
6
|
"author": {
|
|
@@ -336,7 +336,6 @@
|
|
|
336
336
|
"@ai-sdk/provider": "^3.0.8",
|
|
337
337
|
"@anthropic-ai/sdk": "^0.102.0",
|
|
338
338
|
"@anthropic-ai/vertex-sdk": "^0.16.0",
|
|
339
|
-
"@aws-sdk/client-sagemaker-runtime": "^3.1000.0",
|
|
340
339
|
"@aws-sdk/types": "^3.862.0",
|
|
341
340
|
"@google/genai": "^1.43.0",
|
|
342
341
|
"@modelcontextprotocol/sdk": "^1.27.1",
|
|
@@ -400,6 +399,7 @@
|
|
|
400
399
|
"@aws-sdk/client-bedrock": "^3.1000.0",
|
|
401
400
|
"@aws-sdk/client-bedrock-runtime": "^3.1000.0",
|
|
402
401
|
"@aws-sdk/client-sagemaker": "^3.1000.0",
|
|
402
|
+
"@aws-sdk/client-sagemaker-runtime": "^3.1000.0",
|
|
403
403
|
"@aws-sdk/credential-provider-node": "^3.886.0",
|
|
404
404
|
"@fastify/cors": "^11.2.0",
|
|
405
405
|
"@fastify/rate-limit": "^10.3.0",
|