@juspay/neurolink 7.29.1 → 7.29.2

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 (59) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/cli/commands/config.d.ts +3 -3
  3. package/dist/cli/commands/mcp.js +25 -0
  4. package/dist/cli/factories/commandFactory.d.ts +1 -0
  5. package/dist/cli/factories/commandFactory.js +115 -21
  6. package/dist/cli/index.js +8 -0
  7. package/dist/core/factory.js +77 -4
  8. package/dist/factories/providerFactory.js +3 -0
  9. package/dist/factories/providerRegistry.js +2 -2
  10. package/dist/lib/core/factory.js +77 -4
  11. package/dist/lib/factories/providerFactory.js +3 -0
  12. package/dist/lib/factories/providerRegistry.js +2 -2
  13. package/dist/lib/mcp/externalServerManager.js +13 -14
  14. package/dist/lib/mcp/flexibleToolValidator.d.ts +50 -0
  15. package/dist/lib/mcp/flexibleToolValidator.js +161 -0
  16. package/dist/lib/mcp/toolRegistry.d.ts +2 -2
  17. package/dist/lib/mcp/toolRegistry.js +25 -50
  18. package/dist/lib/neurolink.d.ts +2 -0
  19. package/dist/lib/neurolink.js +137 -69
  20. package/dist/lib/providers/amazonBedrock.d.ts +47 -6
  21. package/dist/lib/providers/amazonBedrock.js +282 -23
  22. package/dist/lib/providers/aws/credentialProvider.d.ts +58 -0
  23. package/dist/lib/providers/aws/credentialProvider.js +267 -0
  24. package/dist/lib/providers/aws/credentialTester.d.ts +49 -0
  25. package/dist/lib/providers/aws/credentialTester.js +394 -0
  26. package/dist/lib/proxy/awsProxyIntegration.d.ts +23 -0
  27. package/dist/lib/proxy/awsProxyIntegration.js +285 -0
  28. package/dist/lib/proxy/proxyFetch.d.ts +9 -5
  29. package/dist/lib/proxy/proxyFetch.js +232 -98
  30. package/dist/lib/proxy/utils/noProxyUtils.d.ts +39 -0
  31. package/dist/lib/proxy/utils/noProxyUtils.js +149 -0
  32. package/dist/lib/types/providers.d.ts +43 -0
  33. package/dist/lib/utils/providerConfig.d.ts +1 -0
  34. package/dist/lib/utils/providerConfig.js +2 -1
  35. package/dist/lib/utils/providerHealth.js +123 -5
  36. package/dist/mcp/externalServerManager.js +13 -14
  37. package/dist/mcp/flexibleToolValidator.d.ts +50 -0
  38. package/dist/mcp/flexibleToolValidator.js +161 -0
  39. package/dist/mcp/toolRegistry.d.ts +2 -2
  40. package/dist/mcp/toolRegistry.js +25 -50
  41. package/dist/neurolink.d.ts +2 -0
  42. package/dist/neurolink.js +137 -69
  43. package/dist/providers/amazonBedrock.d.ts +47 -6
  44. package/dist/providers/amazonBedrock.js +282 -23
  45. package/dist/providers/aws/credentialProvider.d.ts +58 -0
  46. package/dist/providers/aws/credentialProvider.js +267 -0
  47. package/dist/providers/aws/credentialTester.d.ts +49 -0
  48. package/dist/providers/aws/credentialTester.js +394 -0
  49. package/dist/proxy/awsProxyIntegration.d.ts +23 -0
  50. package/dist/proxy/awsProxyIntegration.js +285 -0
  51. package/dist/proxy/proxyFetch.d.ts +9 -5
  52. package/dist/proxy/proxyFetch.js +232 -98
  53. package/dist/proxy/utils/noProxyUtils.d.ts +39 -0
  54. package/dist/proxy/utils/noProxyUtils.js +149 -0
  55. package/dist/types/providers.d.ts +43 -0
  56. package/dist/utils/providerConfig.d.ts +1 -0
  57. package/dist/utils/providerConfig.js +2 -1
  58. package/dist/utils/providerHealth.js +123 -5
  59. package/package.json +5 -1
@@ -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
- * Proxy-aware fetch implementation for AI SDK providers
3
- * Implements the proven Vercel AI SDK proxy pattern using undici
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
- * This implements the community-validated approach for Vercel AI SDK
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
  };