@juspay/neurolink 7.29.1 → 7.29.3
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 +12 -0
- package/dist/cli/commands/config.d.ts +86 -86
- package/dist/cli/commands/mcp.js +64 -9
- package/dist/cli/commands/models.js +25 -21
- package/dist/cli/commands/ollama.js +2 -2
- package/dist/cli/factories/commandFactory.d.ts +9 -0
- package/dist/cli/factories/commandFactory.js +177 -83
- package/dist/cli/factories/ollamaCommandFactory.js +3 -1
- package/dist/cli/factories/sagemakerCommandFactory.js +3 -2
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.js +19 -11
- package/dist/cli/utils/envManager.js +5 -5
- package/dist/cli/utils/ollamaUtils.d.ts +12 -0
- package/dist/cli/utils/ollamaUtils.js +58 -42
- package/dist/config/configManager.js +5 -2
- package/dist/core/analytics.d.ts +2 -24
- package/dist/core/analytics.js +12 -17
- package/dist/core/baseProvider.d.ts +30 -1
- package/dist/core/baseProvider.js +180 -198
- package/dist/core/dynamicModels.d.ts +4 -4
- package/dist/core/dynamicModels.js +7 -7
- package/dist/core/evaluation.d.ts +9 -9
- package/dist/core/evaluation.js +117 -65
- package/dist/core/evaluationProviders.d.ts +18 -2
- package/dist/core/evaluationProviders.js +15 -13
- package/dist/core/factory.js +77 -4
- package/dist/core/modelConfiguration.d.ts +63 -0
- package/dist/core/modelConfiguration.js +354 -290
- package/dist/core/streamAnalytics.d.ts +10 -5
- package/dist/core/streamAnalytics.js +10 -10
- package/dist/core/types.d.ts +19 -109
- package/dist/core/types.js +13 -0
- package/dist/factories/providerFactory.js +4 -1
- package/dist/factories/providerRegistry.js +2 -2
- package/dist/index.d.ts +2 -1
- package/dist/lib/config/configManager.js +5 -2
- package/dist/lib/core/analytics.d.ts +2 -24
- package/dist/lib/core/analytics.js +12 -17
- package/dist/lib/core/baseProvider.d.ts +30 -1
- package/dist/lib/core/baseProvider.js +180 -198
- package/dist/lib/core/dynamicModels.js +7 -7
- package/dist/lib/core/evaluation.d.ts +9 -9
- package/dist/lib/core/evaluation.js +117 -65
- package/dist/lib/core/evaluationProviders.d.ts +18 -2
- package/dist/lib/core/evaluationProviders.js +15 -13
- package/dist/lib/core/factory.js +77 -4
- package/dist/lib/core/modelConfiguration.d.ts +63 -0
- package/dist/lib/core/modelConfiguration.js +354 -290
- package/dist/lib/core/streamAnalytics.d.ts +10 -5
- package/dist/lib/core/streamAnalytics.js +10 -10
- package/dist/lib/core/types.d.ts +19 -109
- package/dist/lib/core/types.js +13 -0
- package/dist/lib/factories/providerFactory.js +4 -1
- package/dist/lib/factories/providerRegistry.js +2 -2
- package/dist/lib/index.d.ts +2 -1
- package/dist/lib/mcp/externalServerManager.js +14 -6
- package/dist/lib/mcp/factory.js +1 -1
- package/dist/lib/mcp/flexibleToolValidator.d.ts +50 -0
- package/dist/lib/mcp/flexibleToolValidator.js +161 -0
- package/dist/lib/mcp/index.d.ts +1 -1
- package/dist/lib/mcp/index.js +1 -1
- package/dist/lib/mcp/mcpCircuitBreaker.js +5 -1
- package/dist/lib/mcp/mcpClientFactory.js +3 -0
- package/dist/lib/mcp/registry.d.ts +3 -3
- package/dist/lib/mcp/registry.js +3 -3
- package/dist/lib/mcp/servers/aiProviders/aiAnalysisTools.js +5 -5
- package/dist/lib/mcp/servers/aiProviders/aiWorkflowTools.js +6 -6
- package/dist/lib/mcp/servers/utilities/utilityServer.js +1 -1
- package/dist/lib/mcp/toolDiscoveryService.js +8 -2
- package/dist/lib/mcp/toolRegistry.d.ts +2 -2
- package/dist/lib/mcp/toolRegistry.js +29 -54
- package/dist/lib/middleware/builtin/analytics.js +4 -4
- package/dist/lib/middleware/builtin/guardrails.js +2 -2
- package/dist/lib/middleware/registry.js +11 -2
- package/dist/lib/models/modelRegistry.d.ts +1 -1
- package/dist/lib/models/modelRegistry.js +3 -3
- package/dist/lib/models/modelResolver.d.ts +1 -1
- package/dist/lib/models/modelResolver.js +2 -2
- package/dist/lib/neurolink.d.ts +118 -0
- package/dist/lib/neurolink.js +814 -952
- package/dist/lib/providers/amazonBedrock.d.ts +47 -6
- package/dist/lib/providers/amazonBedrock.js +282 -23
- package/dist/lib/providers/amazonSagemaker.d.ts +1 -1
- package/dist/lib/providers/amazonSagemaker.js +12 -3
- package/dist/lib/providers/anthropic.d.ts +1 -1
- package/dist/lib/providers/anthropic.js +7 -6
- package/dist/lib/providers/anthropicBaseProvider.d.ts +1 -1
- package/dist/lib/providers/anthropicBaseProvider.js +4 -3
- package/dist/lib/providers/aws/credentialProvider.d.ts +58 -0
- package/dist/lib/providers/aws/credentialProvider.js +267 -0
- package/dist/lib/providers/aws/credentialTester.d.ts +49 -0
- package/dist/lib/providers/aws/credentialTester.js +394 -0
- package/dist/lib/providers/azureOpenai.d.ts +1 -1
- package/dist/lib/providers/azureOpenai.js +1 -1
- package/dist/lib/providers/googleAiStudio.d.ts +1 -1
- package/dist/lib/providers/googleAiStudio.js +2 -2
- package/dist/lib/providers/googleVertex.d.ts +40 -0
- package/dist/lib/providers/googleVertex.js +330 -274
- package/dist/lib/providers/huggingFace.js +1 -1
- package/dist/lib/providers/mistral.d.ts +1 -1
- package/dist/lib/providers/mistral.js +2 -2
- package/dist/lib/providers/ollama.d.ts +4 -0
- package/dist/lib/providers/ollama.js +38 -18
- package/dist/lib/providers/openAI.d.ts +1 -1
- package/dist/lib/providers/openAI.js +2 -2
- package/dist/lib/providers/sagemaker/adaptive-semaphore.js +7 -4
- package/dist/lib/providers/sagemaker/client.js +13 -3
- package/dist/lib/providers/sagemaker/config.js +5 -1
- package/dist/lib/providers/sagemaker/detection.js +19 -9
- package/dist/lib/providers/sagemaker/errors.d.ts +8 -1
- package/dist/lib/providers/sagemaker/errors.js +103 -20
- package/dist/lib/providers/sagemaker/language-model.d.ts +3 -3
- package/dist/lib/providers/sagemaker/language-model.js +4 -4
- package/dist/lib/providers/sagemaker/parsers.js +14 -6
- package/dist/lib/providers/sagemaker/streaming.js +14 -3
- package/dist/lib/providers/sagemaker/types.d.ts +1 -1
- package/dist/lib/proxy/awsProxyIntegration.d.ts +23 -0
- package/dist/lib/proxy/awsProxyIntegration.js +285 -0
- package/dist/lib/proxy/proxyFetch.d.ts +9 -5
- package/dist/lib/proxy/proxyFetch.js +232 -98
- package/dist/lib/proxy/utils/noProxyUtils.d.ts +39 -0
- package/dist/lib/proxy/utils/noProxyUtils.js +149 -0
- package/dist/lib/sdk/toolRegistration.d.ts +1 -1
- package/dist/lib/types/cli.d.ts +80 -8
- package/dist/lib/types/contextTypes.js +2 -2
- package/dist/lib/types/generateTypes.d.ts +4 -6
- package/dist/lib/types/providers.d.ts +124 -19
- package/dist/lib/types/providers.js +6 -6
- package/dist/lib/types/streamTypes.d.ts +4 -6
- package/dist/lib/types/typeAliases.d.ts +1 -1
- package/dist/lib/utils/analyticsUtils.d.ts +33 -0
- package/dist/lib/utils/analyticsUtils.js +76 -0
- package/dist/lib/utils/errorHandling.js +4 -1
- package/dist/lib/utils/evaluationUtils.d.ts +27 -0
- package/dist/lib/utils/evaluationUtils.js +131 -0
- package/dist/lib/utils/optionsUtils.js +10 -1
- package/dist/lib/utils/performance.d.ts +1 -1
- package/dist/lib/utils/performance.js +15 -3
- package/dist/lib/utils/providerConfig.d.ts +1 -0
- package/dist/lib/utils/providerConfig.js +2 -1
- package/dist/lib/utils/providerHealth.d.ts +48 -0
- package/dist/lib/utils/providerHealth.js +221 -158
- package/dist/lib/utils/providerUtils.js +2 -2
- package/dist/lib/utils/timeout.js +8 -3
- package/dist/mcp/externalServerManager.js +14 -6
- package/dist/mcp/factory.js +1 -1
- package/dist/mcp/flexibleToolValidator.d.ts +50 -0
- package/dist/mcp/flexibleToolValidator.js +161 -0
- package/dist/mcp/index.d.ts +1 -1
- package/dist/mcp/index.js +1 -1
- package/dist/mcp/mcpCircuitBreaker.js +5 -1
- package/dist/mcp/mcpClientFactory.js +3 -0
- package/dist/mcp/registry.d.ts +3 -3
- package/dist/mcp/registry.js +3 -3
- package/dist/mcp/servers/aiProviders/aiAnalysisTools.js +5 -5
- package/dist/mcp/servers/aiProviders/aiWorkflowTools.js +6 -6
- package/dist/mcp/servers/utilities/utilityServer.js +1 -1
- package/dist/mcp/toolDiscoveryService.js +8 -2
- package/dist/mcp/toolRegistry.d.ts +2 -2
- package/dist/mcp/toolRegistry.js +29 -54
- package/dist/middleware/builtin/analytics.js +4 -4
- package/dist/middleware/builtin/guardrails.js +2 -2
- package/dist/middleware/registry.js +11 -2
- package/dist/models/modelRegistry.d.ts +1 -1
- package/dist/models/modelRegistry.js +3 -3
- package/dist/models/modelResolver.d.ts +1 -1
- package/dist/models/modelResolver.js +2 -2
- package/dist/neurolink.d.ts +118 -0
- package/dist/neurolink.js +814 -952
- package/dist/providers/amazonBedrock.d.ts +47 -6
- package/dist/providers/amazonBedrock.js +282 -23
- package/dist/providers/amazonSagemaker.d.ts +1 -1
- package/dist/providers/amazonSagemaker.js +12 -3
- package/dist/providers/anthropic.d.ts +1 -1
- package/dist/providers/anthropic.js +7 -6
- package/dist/providers/anthropicBaseProvider.d.ts +1 -1
- package/dist/providers/anthropicBaseProvider.js +4 -3
- package/dist/providers/aws/credentialProvider.d.ts +58 -0
- package/dist/providers/aws/credentialProvider.js +267 -0
- package/dist/providers/aws/credentialTester.d.ts +49 -0
- package/dist/providers/aws/credentialTester.js +394 -0
- package/dist/providers/azureOpenai.d.ts +1 -1
- package/dist/providers/azureOpenai.js +1 -1
- package/dist/providers/googleAiStudio.d.ts +1 -1
- package/dist/providers/googleAiStudio.js +2 -2
- package/dist/providers/googleVertex.d.ts +40 -0
- package/dist/providers/googleVertex.js +330 -274
- package/dist/providers/huggingFace.js +1 -1
- package/dist/providers/mistral.d.ts +1 -1
- package/dist/providers/mistral.js +2 -2
- package/dist/providers/ollama.d.ts +4 -0
- package/dist/providers/ollama.js +38 -18
- package/dist/providers/openAI.d.ts +1 -1
- package/dist/providers/openAI.js +2 -2
- package/dist/providers/sagemaker/adaptive-semaphore.js +7 -4
- package/dist/providers/sagemaker/client.js +13 -3
- package/dist/providers/sagemaker/config.js +5 -1
- package/dist/providers/sagemaker/detection.js +19 -9
- package/dist/providers/sagemaker/errors.d.ts +8 -1
- package/dist/providers/sagemaker/errors.js +103 -20
- package/dist/providers/sagemaker/language-model.d.ts +3 -3
- package/dist/providers/sagemaker/language-model.js +4 -4
- package/dist/providers/sagemaker/parsers.js +14 -6
- package/dist/providers/sagemaker/streaming.js +14 -3
- package/dist/providers/sagemaker/types.d.ts +1 -1
- package/dist/proxy/awsProxyIntegration.d.ts +23 -0
- package/dist/proxy/awsProxyIntegration.js +285 -0
- package/dist/proxy/proxyFetch.d.ts +9 -5
- package/dist/proxy/proxyFetch.js +232 -98
- package/dist/proxy/utils/noProxyUtils.d.ts +39 -0
- package/dist/proxy/utils/noProxyUtils.js +149 -0
- package/dist/sdk/toolRegistration.d.ts +1 -1
- package/dist/types/cli.d.ts +80 -8
- package/dist/types/contextTypes.js +2 -2
- package/dist/types/generateTypes.d.ts +4 -6
- package/dist/types/providers.d.ts +124 -19
- package/dist/types/providers.js +6 -6
- package/dist/types/streamTypes.d.ts +4 -6
- package/dist/types/typeAliases.d.ts +1 -1
- package/dist/utils/analyticsUtils.d.ts +33 -0
- package/dist/utils/analyticsUtils.js +76 -0
- package/dist/utils/errorHandling.js +4 -1
- package/dist/utils/evaluationUtils.d.ts +27 -0
- package/dist/utils/evaluationUtils.js +131 -0
- package/dist/utils/optionsUtils.js +10 -1
- package/dist/utils/performance.d.ts +1 -1
- package/dist/utils/performance.js +15 -3
- package/dist/utils/providerConfig.d.ts +1 -0
- package/dist/utils/providerConfig.js +2 -1
- package/dist/utils/providerHealth.d.ts +48 -0
- package/dist/utils/providerHealth.js +221 -158
- package/dist/utils/providerUtils.js +2 -2
- package/dist/utils/timeout.js +8 -3
- package/package.json +5 -1
|
@@ -262,7 +262,11 @@ export class HuggingFaceStreamParser extends BaseStreamingParser {
|
|
|
262
262
|
// Error format
|
|
263
263
|
if (data.error) {
|
|
264
264
|
const errorMessage = extractApiErrorMessage(data.error);
|
|
265
|
-
throw new SageMakerError(`HuggingFace streaming error: ${errorMessage}`,
|
|
265
|
+
throw new SageMakerError(`HuggingFace streaming error: ${errorMessage}`, {
|
|
266
|
+
code: "MODEL_ERROR",
|
|
267
|
+
statusCode: 500,
|
|
268
|
+
retryable: false,
|
|
269
|
+
});
|
|
266
270
|
}
|
|
267
271
|
return null;
|
|
268
272
|
}
|
|
@@ -274,7 +278,7 @@ export class HuggingFaceStreamParser extends BaseStreamingParser {
|
|
|
274
278
|
return {
|
|
275
279
|
promptTokens: Number(tokens.input) || 0,
|
|
276
280
|
completionTokens: Number(tokens.generated) || 0,
|
|
277
|
-
|
|
281
|
+
total: Number(tokens.total) || 0,
|
|
278
282
|
};
|
|
279
283
|
}
|
|
280
284
|
mapFinishReason(reason) {
|
|
@@ -379,7 +383,11 @@ export class LlamaStreamParser extends BaseStreamingParser {
|
|
|
379
383
|
if (data.error) {
|
|
380
384
|
const errorData = data.error;
|
|
381
385
|
const errorMessage = extractApiErrorMessage(errorData);
|
|
382
|
-
throw new SageMakerError(`LLaMA streaming error: ${errorMessage}`,
|
|
386
|
+
throw new SageMakerError(`LLaMA streaming error: ${errorMessage}`, {
|
|
387
|
+
code: "MODEL_ERROR",
|
|
388
|
+
statusCode: 500,
|
|
389
|
+
retryable: false,
|
|
390
|
+
});
|
|
383
391
|
}
|
|
384
392
|
return null;
|
|
385
393
|
}
|
|
@@ -441,7 +449,7 @@ export class LlamaStreamParser extends BaseStreamingParser {
|
|
|
441
449
|
return {
|
|
442
450
|
promptTokens: Number(usage.prompt_tokens) || 0,
|
|
443
451
|
completionTokens: Number(usage.completion_tokens) || 0,
|
|
444
|
-
|
|
452
|
+
total: Number(usage.total_tokens) || 0,
|
|
445
453
|
};
|
|
446
454
|
}
|
|
447
455
|
mapFinishReason(reason) {
|
|
@@ -563,7 +571,7 @@ export class CustomStreamParser extends BaseStreamingParser {
|
|
|
563
571
|
return {
|
|
564
572
|
promptTokens: Number(usage.prompt_tokens || usage.input_tokens) || 0,
|
|
565
573
|
completionTokens: Number(usage.completion_tokens || usage.output_tokens) || 0,
|
|
566
|
-
|
|
574
|
+
total: Number(usage.total_tokens) || 0,
|
|
567
575
|
};
|
|
568
576
|
}
|
|
569
577
|
}
|
|
@@ -621,6 +629,6 @@ export function estimateTokenUsage(prompt, completion) {
|
|
|
621
629
|
return {
|
|
622
630
|
promptTokens,
|
|
623
631
|
completionTokens,
|
|
624
|
-
|
|
632
|
+
total: promptTokens + completionTokens,
|
|
625
633
|
};
|
|
626
634
|
}
|
|
@@ -69,7 +69,18 @@ async function createProtocolSpecificStream(responseStream, parser, capability,
|
|
|
69
69
|
while (true) {
|
|
70
70
|
// Check for abort signal
|
|
71
71
|
if (options.abortSignal?.aborted) {
|
|
72
|
-
|
|
72
|
+
// Clean up upstream iterator before throwing
|
|
73
|
+
try {
|
|
74
|
+
await reader.return?.();
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
// Ignore cleanup errors, still propagate original abort
|
|
78
|
+
}
|
|
79
|
+
throw new SageMakerError("Stream aborted by user", {
|
|
80
|
+
code: "NETWORK_ERROR",
|
|
81
|
+
statusCode: 499,
|
|
82
|
+
retryable: false,
|
|
83
|
+
});
|
|
73
84
|
}
|
|
74
85
|
const { done, value } = await reader.next();
|
|
75
86
|
if (done) {
|
|
@@ -86,7 +97,7 @@ async function createProtocolSpecificStream(responseStream, parser, capability,
|
|
|
86
97
|
options.onComplete?.(finalUsage || {
|
|
87
98
|
promptTokens: 0,
|
|
88
99
|
completionTokens: 0,
|
|
89
|
-
|
|
100
|
+
total: 0,
|
|
90
101
|
});
|
|
91
102
|
controller.close();
|
|
92
103
|
break;
|
|
@@ -315,6 +326,6 @@ export function estimateTokenUsage(prompt, completion) {
|
|
|
315
326
|
return {
|
|
316
327
|
promptTokens,
|
|
317
328
|
completionTokens,
|
|
318
|
-
|
|
329
|
+
total: promptTokens + completionTokens,
|
|
319
330
|
};
|
|
320
331
|
}
|
|
@@ -96,7 +96,7 @@ export interface SageMakerUsage {
|
|
|
96
96
|
/** Number of completion tokens */
|
|
97
97
|
completionTokens: number;
|
|
98
98
|
/** Total tokens used */
|
|
99
|
-
|
|
99
|
+
total: number;
|
|
100
100
|
/** Request processing time in milliseconds */
|
|
101
101
|
requestTime?: number;
|
|
102
102
|
/** Model inference time in milliseconds */
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AWS SDK Global Agent Configuration for Proxy Support
|
|
3
|
+
* Configures Node.js global HTTP/HTTPS agents to work with AWS SDK
|
|
4
|
+
* Ensures BedrockRuntimeClient and other AWS services respect proxy settings
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Configure global Node.js agents for AWS SDK proxy support
|
|
8
|
+
* This ensures BedrockRuntimeClient and other AWS SDK clients respect proxy settings
|
|
9
|
+
*/
|
|
10
|
+
export declare function configureAWSProxySupport(): Promise<void>;
|
|
11
|
+
/**
|
|
12
|
+
* Create a proxy-aware HTTP handler for AWS SDK clients
|
|
13
|
+
* This is the proper way to inject proxy support into AWS SDK v3 clients
|
|
14
|
+
*/
|
|
15
|
+
export declare function createAWSProxyHandler(targetUrl?: string): Promise<unknown | null>;
|
|
16
|
+
/**
|
|
17
|
+
* Clean up global agents (for testing or shutdown)
|
|
18
|
+
*/
|
|
19
|
+
export declare function cleanupAWSProxySupport(): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Test AWS endpoint connectivity through proxy
|
|
22
|
+
*/
|
|
23
|
+
export declare function testAWSProxyConnectivity(): Promise<boolean>;
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AWS SDK Global Agent Configuration for Proxy Support
|
|
3
|
+
* Configures Node.js global HTTP/HTTPS agents to work with AWS SDK
|
|
4
|
+
* Ensures BedrockRuntimeClient and other AWS services respect proxy settings
|
|
5
|
+
*/
|
|
6
|
+
import { logger } from "../utils/logger.js";
|
|
7
|
+
/**
|
|
8
|
+
* Configure global Node.js agents for AWS SDK proxy support
|
|
9
|
+
* This ensures BedrockRuntimeClient and other AWS SDK clients respect proxy settings
|
|
10
|
+
*/
|
|
11
|
+
export async function configureAWSProxySupport() {
|
|
12
|
+
try {
|
|
13
|
+
// Check if proxy is needed for AWS endpoints
|
|
14
|
+
const testUrl = "https://bedrock-runtime.us-east-1.amazonaws.com";
|
|
15
|
+
const proxyUrl = await getProxyUrlForTarget(testUrl);
|
|
16
|
+
if (!proxyUrl) {
|
|
17
|
+
logger.debug("[AWS Proxy] No proxy configuration needed for AWS SDK");
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
logger.debug("[AWS Proxy] Configuring global agents for AWS SDK", {
|
|
21
|
+
proxyUrl: proxyUrl.replace(/\/\/[^:]+:[^@]+@/, "//*****:*****@"),
|
|
22
|
+
targetEndpoint: testUrl,
|
|
23
|
+
});
|
|
24
|
+
// Configure global agents
|
|
25
|
+
await configureGlobalAgents(proxyUrl);
|
|
26
|
+
logger.info("[AWS Proxy] AWS SDK proxy support configured successfully");
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
logger.error("[AWS Proxy] Failed to configure AWS SDK proxy support", {
|
|
30
|
+
error,
|
|
31
|
+
});
|
|
32
|
+
// Don't throw - allow AWS SDK to work without proxy
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Configure Node.js global HTTP/HTTPS agents
|
|
37
|
+
*/
|
|
38
|
+
async function configureGlobalAgents(proxyUrl) {
|
|
39
|
+
try {
|
|
40
|
+
const parsed = new URL(proxyUrl);
|
|
41
|
+
logger.debug("[AWS Proxy] Configuring global agents", {
|
|
42
|
+
protocol: parsed.protocol,
|
|
43
|
+
hostname: parsed.hostname,
|
|
44
|
+
port: parsed.port || getDefaultPort(parsed.protocol),
|
|
45
|
+
});
|
|
46
|
+
// For HTTP/HTTPS proxies, we need to set global agents
|
|
47
|
+
if (parsed.protocol === "http:" || parsed.protocol === "https:") {
|
|
48
|
+
await configureHttpAgents(proxyUrl);
|
|
49
|
+
}
|
|
50
|
+
else if (parsed.protocol === "socks4:" || parsed.protocol === "socks5:") {
|
|
51
|
+
await configureSocksAgents(proxyUrl);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
throw new Error(`Unsupported proxy protocol for AWS SDK: ${parsed.protocol}`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
logger.error("[AWS Proxy] Failed to configure global agents", {
|
|
59
|
+
proxyUrl,
|
|
60
|
+
error,
|
|
61
|
+
});
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Configure HTTP/HTTPS proxy agents using existing proxy infrastructure
|
|
67
|
+
*/
|
|
68
|
+
async function configureHttpAgents(proxyUrl) {
|
|
69
|
+
// No-op here. Prefer explicit handler injection at client construction time.
|
|
70
|
+
logger.debug("[AWS Proxy] Skipping global env/agent mutation; use injected HttpHandler instead", {
|
|
71
|
+
proxyUrl: proxyUrl.replace(/\/\/[^:]+:[^@]+@/, "//*****:*****@"),
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Configure SOCKS proxy agents - simplified approach
|
|
76
|
+
*/
|
|
77
|
+
async function configureSocksAgents(proxyUrl) {
|
|
78
|
+
// SOCKS via HTTP(S)_PROXY won't work; avoid setting to socks://
|
|
79
|
+
// Setting HTTP_PROXY/HTTPS_PROXY to a socks:// URL is not respected by Node's https module nor by AWS SDK handlers
|
|
80
|
+
logger.warn("[AWS Proxy] SOCKS proxy configuration not supported for AWS SDK", {
|
|
81
|
+
proxyUrl: proxyUrl.replace(/\/\/[^:]+:[^@]+@/, "//*****:*****@"),
|
|
82
|
+
reason: "AWS SDK v3 does not support SOCKS proxies via environment variables",
|
|
83
|
+
});
|
|
84
|
+
throw new Error(`SOCKS proxy configuration not supported for AWS SDK. Consider using HTTP/HTTPS proxy instead. ` +
|
|
85
|
+
`For SOCKS support, use a proxy-aware agent injected into AWS clients.`);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Minimal HTTP agent configuration (fallback)
|
|
89
|
+
*/
|
|
90
|
+
async function _configureMinimalHttpAgents(_proxyUrl) {
|
|
91
|
+
// Remove broken fallback. Use explicit proxy-aware HttpHandler instead.
|
|
92
|
+
logger.warn("[AWS Proxy] Minimal agent fallback removed; a proper proxy agent is required.");
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Create a proxy-aware HTTP handler for AWS SDK clients
|
|
96
|
+
* This is the proper way to inject proxy support into AWS SDK v3 clients
|
|
97
|
+
*/
|
|
98
|
+
export async function createAWSProxyHandler(targetUrl) {
|
|
99
|
+
try {
|
|
100
|
+
const testUrl = targetUrl || "https://bedrock-runtime.us-east-1.amazonaws.com";
|
|
101
|
+
const proxyUrl = await getProxyUrlForTarget(testUrl);
|
|
102
|
+
if (!proxyUrl) {
|
|
103
|
+
logger.debug("[AWS Proxy] No proxy configured, using default HTTP handler");
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
logger.debug("[AWS Proxy] Creating proxy-aware HTTP handler for AWS SDK", {
|
|
107
|
+
proxyUrl: proxyUrl.replace(/\/\/[^:]+:[^@]+@/, "//*****:*****@"),
|
|
108
|
+
});
|
|
109
|
+
// Dynamically import proxy agent modules
|
|
110
|
+
const parsed = new URL(proxyUrl);
|
|
111
|
+
if (parsed.protocol === "http:" || parsed.protocol === "https:") {
|
|
112
|
+
try {
|
|
113
|
+
// Use undici ProxyAgent for HTTP/HTTPS proxies
|
|
114
|
+
const { ProxyAgent } = await import("undici");
|
|
115
|
+
const proxyAgent = new ProxyAgent(proxyUrl);
|
|
116
|
+
// Create a custom dispatcher wrapper for AWS SDK
|
|
117
|
+
return {
|
|
118
|
+
async handle(request) {
|
|
119
|
+
const { fetch } = await import("undici");
|
|
120
|
+
const req = request;
|
|
121
|
+
return fetch(req.url, {
|
|
122
|
+
method: req.method,
|
|
123
|
+
headers: req.headers,
|
|
124
|
+
body: req.body,
|
|
125
|
+
dispatcher: proxyAgent,
|
|
126
|
+
});
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
catch (undiciError) {
|
|
131
|
+
logger.warn("[AWS Proxy] No suitable proxy agent available", {
|
|
132
|
+
undiciError: undiciError instanceof Error
|
|
133
|
+
? undiciError.message
|
|
134
|
+
: String(undiciError),
|
|
135
|
+
});
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
logger.warn("[AWS Proxy] Unsupported proxy protocol for AWS SDK", {
|
|
141
|
+
protocol: parsed.protocol,
|
|
142
|
+
});
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
logger.error("[AWS Proxy] Failed to create proxy-aware HTTP handler", {
|
|
148
|
+
error,
|
|
149
|
+
});
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Get default port for protocol
|
|
155
|
+
*/
|
|
156
|
+
function getDefaultPort(protocol) {
|
|
157
|
+
switch (protocol) {
|
|
158
|
+
case "http:":
|
|
159
|
+
return 8080;
|
|
160
|
+
case "https:":
|
|
161
|
+
return 8080;
|
|
162
|
+
case "socks4:":
|
|
163
|
+
return 1080;
|
|
164
|
+
case "socks5:":
|
|
165
|
+
return 1080;
|
|
166
|
+
default:
|
|
167
|
+
return 8080;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
// Import shared NO_PROXY utility
|
|
171
|
+
import { shouldBypassProxySimple } from "./utils/noProxyUtils.js";
|
|
172
|
+
/**
|
|
173
|
+
* Get proxy URL for specific target (reuse existing logic)
|
|
174
|
+
*/
|
|
175
|
+
async function getProxyUrlForTarget(targetUrl) {
|
|
176
|
+
try {
|
|
177
|
+
// Simple fallback proxy detection using environment variables
|
|
178
|
+
// This is more reliable than trying to import internal functions
|
|
179
|
+
const httpProxy = process.env.HTTP_PROXY || process.env.http_proxy;
|
|
180
|
+
const httpsProxy = process.env.HTTPS_PROXY || process.env.https_proxy;
|
|
181
|
+
const allProxy = process.env.ALL_PROXY || process.env.all_proxy;
|
|
182
|
+
const noProxy = process.env.NO_PROXY || process.env.no_proxy;
|
|
183
|
+
// Check if target should bypass proxy using shared utility
|
|
184
|
+
if (noProxy && shouldBypassProxySimple(targetUrl, noProxy)) {
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
// Use HTTPS proxy for HTTPS URLs, HTTP proxy for HTTP URLs
|
|
188
|
+
const url = new URL(targetUrl);
|
|
189
|
+
if (url.protocol === "https:" && (httpsProxy || allProxy)) {
|
|
190
|
+
return httpsProxy || allProxy || null;
|
|
191
|
+
}
|
|
192
|
+
else if (url.protocol === "http:" && httpProxy) {
|
|
193
|
+
return httpProxy;
|
|
194
|
+
}
|
|
195
|
+
else if (httpProxy) {
|
|
196
|
+
// Fallback to HTTP proxy for any protocol
|
|
197
|
+
return httpProxy;
|
|
198
|
+
}
|
|
199
|
+
else if (allProxy) {
|
|
200
|
+
return allProxy;
|
|
201
|
+
}
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
catch (error) {
|
|
205
|
+
// Fallback to simple environment variable check
|
|
206
|
+
// (Ensure any logged URLs here are masked before emitting.)
|
|
207
|
+
logger.warn("[AWS Proxy] Error in proxy detection, using simple fallback", {
|
|
208
|
+
error: error instanceof Error ? error.message : String(error),
|
|
209
|
+
});
|
|
210
|
+
// Check NO_PROXY bypass first in fallback path too
|
|
211
|
+
const noProxy = process.env.NO_PROXY || process.env.no_proxy;
|
|
212
|
+
if (noProxy && shouldBypassProxySimple(targetUrl, noProxy)) {
|
|
213
|
+
return null;
|
|
214
|
+
}
|
|
215
|
+
const url = new URL(targetUrl);
|
|
216
|
+
const httpsProxy = process.env.HTTPS_PROXY || process.env.https_proxy;
|
|
217
|
+
const httpProxy = process.env.HTTP_PROXY || process.env.http_proxy;
|
|
218
|
+
const allProxy = process.env.ALL_PROXY || process.env.all_proxy;
|
|
219
|
+
if (url.protocol === "https:" && httpsProxy) {
|
|
220
|
+
return httpsProxy;
|
|
221
|
+
}
|
|
222
|
+
if (url.protocol === "http:" && httpProxy) {
|
|
223
|
+
return httpProxy;
|
|
224
|
+
}
|
|
225
|
+
if (allProxy) {
|
|
226
|
+
return allProxy;
|
|
227
|
+
}
|
|
228
|
+
return null;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Clean up global agents (for testing or shutdown)
|
|
233
|
+
*/
|
|
234
|
+
export async function cleanupAWSProxySupport() {
|
|
235
|
+
try {
|
|
236
|
+
const http = await import("http");
|
|
237
|
+
const https = await import("https");
|
|
238
|
+
// Reset to default agents
|
|
239
|
+
https.globalAgent = new https.Agent();
|
|
240
|
+
http.globalAgent = new http.Agent();
|
|
241
|
+
logger.debug("[AWS Proxy] Global agents reset to defaults");
|
|
242
|
+
}
|
|
243
|
+
catch (error) {
|
|
244
|
+
logger.warn("[AWS Proxy] Failed to cleanup global agents", { error });
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Test AWS endpoint connectivity through proxy
|
|
249
|
+
*/
|
|
250
|
+
export async function testAWSProxyConnectivity() {
|
|
251
|
+
try {
|
|
252
|
+
const testUrl = "https://bedrock-runtime.us-east-1.amazonaws.com";
|
|
253
|
+
const proxyUrl = await getProxyUrlForTarget(testUrl);
|
|
254
|
+
if (!proxyUrl) {
|
|
255
|
+
logger.debug("[AWS Proxy] No proxy configured, direct connection test");
|
|
256
|
+
return true; // No proxy needed
|
|
257
|
+
}
|
|
258
|
+
logger.debug("[AWS Proxy] Testing proxy connectivity to AWS", {
|
|
259
|
+
testUrl,
|
|
260
|
+
proxyUrl: proxyUrl.replace(/\/\/[^:]+:[^@]+@/, "//*****:*****@"),
|
|
261
|
+
});
|
|
262
|
+
// Simple connectivity test using fetch with AbortController for timeout
|
|
263
|
+
const controller = new AbortController();
|
|
264
|
+
const timeoutId = setTimeout(() => controller.abort(), 5000); // 5 second timeout
|
|
265
|
+
// Use proxy-aware fetch instead of raw fetch
|
|
266
|
+
const { createProxyFetch } = await import("./proxyFetch.js");
|
|
267
|
+
const proxyAwareFetch = createProxyFetch();
|
|
268
|
+
const response = await proxyAwareFetch(testUrl, {
|
|
269
|
+
method: "HEAD",
|
|
270
|
+
signal: controller.signal,
|
|
271
|
+
});
|
|
272
|
+
clearTimeout(timeoutId);
|
|
273
|
+
const success = response.status < 500; // Accept any non-5xx response
|
|
274
|
+
logger.debug("[AWS Proxy] AWS proxy connectivity test", {
|
|
275
|
+
success,
|
|
276
|
+
status: response.status,
|
|
277
|
+
statusText: response.statusText,
|
|
278
|
+
});
|
|
279
|
+
return success;
|
|
280
|
+
}
|
|
281
|
+
catch (error) {
|
|
282
|
+
logger.warn("[AWS Proxy] AWS proxy connectivity test failed", { error });
|
|
283
|
+
return false;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* Enhanced proxy-aware fetch implementation for AI SDK providers
|
|
3
|
+
* Supports HTTP/HTTPS, SOCKS4/5, authentication, and NO_PROXY bypass
|
|
4
|
+
* Lightweight implementation extracted from research of major proxy packages
|
|
4
5
|
*/
|
|
5
6
|
/**
|
|
6
|
-
* Create a proxy-aware fetch function
|
|
7
|
-
*
|
|
7
|
+
* Create a proxy-aware fetch function with enhanced capabilities
|
|
8
|
+
* Supports HTTP/HTTPS, SOCKS4/5, authentication, and NO_PROXY bypass
|
|
8
9
|
*/
|
|
9
10
|
export declare function createProxyFetch(): typeof fetch;
|
|
10
11
|
/**
|
|
11
|
-
* Get proxy status information
|
|
12
|
+
* Get enhanced proxy status information
|
|
12
13
|
*/
|
|
13
14
|
export declare function getProxyStatus(): {
|
|
14
15
|
enabled: boolean;
|
|
15
16
|
httpProxy: string | null;
|
|
16
17
|
httpsProxy: string | null;
|
|
18
|
+
allProxy: string | null;
|
|
19
|
+
socksProxy: string | null;
|
|
17
20
|
noProxy: string | null;
|
|
18
21
|
method: string;
|
|
22
|
+
capabilities: string[];
|
|
19
23
|
};
|