@juspay/neurolink 7.29.0 → 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 (61) hide show
  1. package/CHANGELOG.md +12 -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 +299 -4
  19. package/dist/lib/neurolink.js +434 -73
  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/providers/googleVertex.js +13 -4
  27. package/dist/lib/proxy/awsProxyIntegration.d.ts +23 -0
  28. package/dist/lib/proxy/awsProxyIntegration.js +285 -0
  29. package/dist/lib/proxy/proxyFetch.d.ts +9 -5
  30. package/dist/lib/proxy/proxyFetch.js +232 -98
  31. package/dist/lib/proxy/utils/noProxyUtils.d.ts +39 -0
  32. package/dist/lib/proxy/utils/noProxyUtils.js +149 -0
  33. package/dist/lib/types/providers.d.ts +43 -0
  34. package/dist/lib/utils/providerConfig.d.ts +1 -0
  35. package/dist/lib/utils/providerConfig.js +2 -1
  36. package/dist/lib/utils/providerHealth.js +123 -5
  37. package/dist/mcp/externalServerManager.js +13 -14
  38. package/dist/mcp/flexibleToolValidator.d.ts +50 -0
  39. package/dist/mcp/flexibleToolValidator.js +161 -0
  40. package/dist/mcp/toolRegistry.d.ts +2 -2
  41. package/dist/mcp/toolRegistry.js +25 -50
  42. package/dist/neurolink.d.ts +299 -4
  43. package/dist/neurolink.js +434 -73
  44. package/dist/providers/amazonBedrock.d.ts +47 -6
  45. package/dist/providers/amazonBedrock.js +282 -23
  46. package/dist/providers/aws/credentialProvider.d.ts +58 -0
  47. package/dist/providers/aws/credentialProvider.js +267 -0
  48. package/dist/providers/aws/credentialTester.d.ts +49 -0
  49. package/dist/providers/aws/credentialTester.js +394 -0
  50. package/dist/providers/googleVertex.js +13 -4
  51. package/dist/proxy/awsProxyIntegration.d.ts +23 -0
  52. package/dist/proxy/awsProxyIntegration.js +285 -0
  53. package/dist/proxy/proxyFetch.d.ts +9 -5
  54. package/dist/proxy/proxyFetch.js +232 -98
  55. package/dist/proxy/utils/noProxyUtils.d.ts +39 -0
  56. package/dist/proxy/utils/noProxyUtils.js +149 -0
  57. package/dist/types/providers.d.ts +43 -0
  58. package/dist/utils/providerConfig.d.ts +1 -0
  59. package/dist/utils/providerConfig.js +2 -1
  60. package/dist/utils/providerHealth.js +123 -5
  61. package/package.json +5 -1
@@ -3,29 +3,70 @@ import { type LanguageModelV1 } from "ai";
3
3
  import type { AIProviderName } from "../core/types.js";
4
4
  import type { StreamOptions, StreamResult } from "../types/streamTypes.js";
5
5
  import { BaseProvider } from "../core/baseProvider.js";
6
+ import { AWSCredentialProvider } from "./aws/credentialProvider.js";
7
+ import { BedrockRuntimeClient } from "@aws-sdk/client-bedrock-runtime";
8
+ import type { AWSCredentialConfig } from "../types/providers.js";
9
+ import type { NeuroLink } from "../neurolink.js";
6
10
  /**
7
- * Amazon Bedrock Provider v2 - BaseProvider Implementation
11
+ * Amazon Bedrock Provider v3 - Enhanced Authentication Implementation
8
12
  *
9
- * PHASE 3.3: Simple BaseProvider wrap around existing @ai-sdk/amazon-bedrock implementation
13
+ * BEDROCK-MCP-CONNECTOR COMPATIBILITY: Complete AWS SDK credential chain support
10
14
  *
11
15
  * Features:
12
16
  * - Extends BaseProvider for shared functionality
13
- * - Preserves existing AWS credential configuration
14
- * - Maintains inference profile ARN support
15
- * - Uses pre-initialized Bedrock instance for efficiency
17
+ * - AWS SDK v3 defaultProvider credential chain (9 sources)
18
+ * - Dual access: AI SDK + Direct AWS SDK BedrockRuntimeClient
19
+ * - Full backward compatibility with existing configurations
16
20
  * - Enhanced error handling with setup guidance
21
+ * - Bedrock-MCP-Connector compatible authentication patterns
17
22
  */
18
23
  export declare class AmazonBedrockProvider extends BaseProvider {
24
+ private awsCredentialProvider;
25
+ private bedrockClient;
19
26
  private bedrock;
20
27
  private model;
21
- constructor(modelName?: string);
28
+ constructor(modelName?: string, credentialConfig?: AWSCredentialConfig, neurolink?: NeuroLink);
29
+ /**
30
+ * Legacy AWS configuration for backward compatibility
31
+ */
32
+ private createLegacyAWSConfig;
22
33
  protected getProviderName(): AIProviderName;
23
34
  protected getDefaultModel(): string;
24
35
  /**
25
36
  * Returns the Vercel AI SDK model instance for AWS Bedrock
26
37
  */
27
38
  protected getAISDKModel(): LanguageModelV1;
39
+ /**
40
+ * Get AWS SDK BedrockRuntimeClient for direct access (Bedrock-MCP-Connector compatibility)
41
+ * This provides the same direct AWS SDK access that Bedrock-MCP-Connector uses
42
+ */
43
+ getBedrockClient(): BedrockRuntimeClient;
44
+ /**
45
+ * Get AWS SDK BedrockRuntimeClient with proxy support ensured
46
+ * Use this method when proxy support is critical for the operation
47
+ */
48
+ getBedrockClientWithProxy(): Promise<BedrockRuntimeClient>;
49
+ /**
50
+ * Get AWS credential provider for advanced credential management
51
+ */
52
+ getCredentialProvider(): AWSCredentialProvider;
53
+ /**
54
+ * Ensure proxy support is configured for AWS SDK client if needed
55
+ */
56
+ private ensureProxySupport;
57
+ /**
58
+ * Test AWS credentials and Bedrock connectivity
59
+ * Useful for debugging authentication issues
60
+ */
61
+ testConnectivity(): Promise<{
62
+ credentialsValid: boolean;
63
+ bedrockAccessible: boolean;
64
+ credentialSource: string;
65
+ error?: string;
66
+ responseTime?: number;
67
+ }>;
28
68
  protected executeStream(options: StreamOptions, _analysisSchema?: ZodUnknownSchema): Promise<StreamResult>;
69
+ protected handleStreamError(error: unknown): Error;
29
70
  protected handleProviderError(error: unknown): Error;
30
71
  }
31
72
  export default AmazonBedrockProvider;
@@ -3,10 +3,12 @@ import { streamText } from "ai";
3
3
  import { BaseProvider } from "../core/baseProvider.js";
4
4
  import { logger } from "../utils/logger.js";
5
5
  import { createTimeoutController, TimeoutError } from "../utils/timeout.js";
6
- import { DEFAULT_MAX_TOKENS } from "../core/constants.js";
6
+ import { DEFAULT_MAX_TOKENS, DEFAULT_MAX_STEPS } from "../core/constants.js";
7
7
  import { validateApiKey, createAWSAccessKeyConfig, createAWSSecretConfig, getAWSRegion, getAWSSessionToken, } from "../utils/providerConfig.js";
8
8
  import { buildMessagesArray } from "../utils/messageBuilder.js";
9
9
  import { createProxyFetch } from "../proxy/proxyFetch.js";
10
+ import { AWSCredentialProvider } from "./aws/credentialProvider.js";
11
+ import { BedrockRuntimeClient } from "@aws-sdk/client-bedrock-runtime";
10
12
  // Configuration helpers
11
13
  const getBedrockModelId = () => {
12
14
  const model = process.env.BEDROCK_MODEL || process.env.BEDROCK_MODEL_ID;
@@ -27,23 +29,102 @@ const getAppEnvironment = () => {
27
29
  return process.env.PUBLIC_APP_ENVIRONMENT || "production";
28
30
  };
29
31
  /**
30
- * Amazon Bedrock Provider v2 - BaseProvider Implementation
32
+ * Amazon Bedrock Provider v3 - Enhanced Authentication Implementation
31
33
  *
32
- * PHASE 3.3: Simple BaseProvider wrap around existing @ai-sdk/amazon-bedrock implementation
34
+ * BEDROCK-MCP-CONNECTOR COMPATIBILITY: Complete AWS SDK credential chain support
33
35
  *
34
36
  * Features:
35
37
  * - Extends BaseProvider for shared functionality
36
- * - Preserves existing AWS credential configuration
37
- * - Maintains inference profile ARN support
38
- * - Uses pre-initialized Bedrock instance for efficiency
38
+ * - AWS SDK v3 defaultProvider credential chain (9 sources)
39
+ * - Dual access: AI SDK + Direct AWS SDK BedrockRuntimeClient
40
+ * - Full backward compatibility with existing configurations
39
41
  * - Enhanced error handling with setup guidance
42
+ * - Bedrock-MCP-Connector compatible authentication patterns
40
43
  */
41
44
  export class AmazonBedrockProvider extends BaseProvider {
45
+ awsCredentialProvider;
46
+ bedrockClient;
42
47
  bedrock;
43
48
  model;
44
- constructor(modelName) {
45
- super(modelName, "bedrock");
46
- // Initialize AWS configuration
49
+ constructor(modelName, credentialConfig, neurolink) {
50
+ super(modelName, "bedrock", neurolink);
51
+ // Debug: Bedrock initialization started
52
+ logger.debug("[Bedrock] Provider initialization started", {
53
+ requestedModel: modelName || "default",
54
+ environment: getAppEnvironment(),
55
+ });
56
+ // Initialize AWS credential provider with full credential chain support
57
+ const defaultCredentialConfig = {
58
+ region: getAWSRegion(),
59
+ enableDebugLogging: getAppEnvironment() === "dev",
60
+ ...credentialConfig,
61
+ };
62
+ // Debug: AWS configuration
63
+ logger.debug("[Bedrock] AWS configuration resolved", {
64
+ region: defaultCredentialConfig.region,
65
+ enableDebugLogging: defaultCredentialConfig.enableDebugLogging,
66
+ credentialConfigProvided: !!credentialConfig,
67
+ });
68
+ this.awsCredentialProvider = new AWSCredentialProvider(defaultCredentialConfig);
69
+ // Debug: AWS credential detection status
70
+ logger.debug("[Bedrock] AWS credential detection status", {
71
+ hasAccessKey: !!process.env.AWS_ACCESS_KEY_ID,
72
+ hasSecretKey: !!process.env.AWS_SECRET_ACCESS_KEY,
73
+ hasSessionToken: !!process.env.AWS_SESSION_TOKEN,
74
+ hasProfile: !!process.env.AWS_PROFILE,
75
+ credentialChainEnabled: true,
76
+ });
77
+ // Create AWS SDK v3 Bedrock client for direct access (Bedrock-MCP-Connector compatibility)
78
+ // Proxy support will be injected lazily when needed
79
+ this.bedrockClient = new BedrockRuntimeClient({
80
+ region: defaultCredentialConfig.region,
81
+ credentials: this.awsCredentialProvider.getCredentialProvider(),
82
+ });
83
+ // Debug: AWS region and service endpoint
84
+ logger.debug("[Bedrock] AWS service configuration", {
85
+ region: defaultCredentialConfig.region,
86
+ serviceEndpoint: `https://bedrock-runtime.${defaultCredentialConfig.region}.amazonaws.com`,
87
+ credentialProviderType: "AWS SDK v3 defaultProvider chain",
88
+ });
89
+ // For now, use legacy configuration as AI SDK may not support credential providers directly
90
+ // TODO: Update when @ai-sdk/amazon-bedrock supports credential providers
91
+ const legacyAwsConfig = this.createLegacyAWSConfig();
92
+ try {
93
+ this.bedrock = createAmazonBedrock(legacyAwsConfig);
94
+ }
95
+ catch (error) {
96
+ logger.error("Failed to create AI SDK provider", {
97
+ error: error instanceof Error ? error.message : String(error),
98
+ });
99
+ throw new Error(`Failed to initialize Amazon Bedrock AI SDK: ${error instanceof Error ? error.message : String(error)}`);
100
+ }
101
+ // Pre-initialize model for efficiency
102
+ const resolvedModelId = this.modelName || getBedrockModelId();
103
+ // Debug: Bedrock model validation process
104
+ logger.debug("[Bedrock] Model validation and ARN processing", {
105
+ requestedModel: this.modelName || "from environment",
106
+ resolvedModelId: resolvedModelId,
107
+ isInferenceProfile: resolvedModelId.includes(":inference-profile/"),
108
+ isFoundationModel: resolvedModelId.startsWith("anthropic.") ||
109
+ resolvedModelId.startsWith("amazon.") ||
110
+ resolvedModelId.startsWith("meta."),
111
+ modelARNValidation: resolvedModelId.includes("arn:aws:bedrock:")
112
+ ? "Full ARN provided"
113
+ : "Model ID provided",
114
+ });
115
+ this.model = this.bedrock(resolvedModelId);
116
+ logger.debug("Amazon Bedrock Provider v3 initialized", {
117
+ modelName: this.modelName,
118
+ region: defaultCredentialConfig.region,
119
+ credentialProvider: "AWS SDK v3 defaultProvider",
120
+ hasDualAccess: true,
121
+ provider: this.providerName,
122
+ });
123
+ }
124
+ /**
125
+ * Legacy AWS configuration for backward compatibility
126
+ */
127
+ createLegacyAWSConfig() {
47
128
  const awsConfig = {
48
129
  accessKeyId: getAWSAccessKeyId(),
49
130
  secretAccessKey: getAWSSecretAccessKey(),
@@ -57,16 +138,7 @@ export class AmazonBedrockProvider extends BaseProvider {
57
138
  awsConfig.sessionToken = sessionToken;
58
139
  }
59
140
  }
60
- // Create Bedrock provider instance
61
- this.bedrock = createAmazonBedrock(awsConfig);
62
- // Pre-initialize model for efficiency
63
- this.model = this.bedrock(this.modelName || getBedrockModelId());
64
- logger.debug("Amazon Bedrock BaseProvider v2 initialized", {
65
- modelName: this.modelName,
66
- region: awsConfig.region,
67
- hasSessionToken: !!awsConfig.sessionToken,
68
- provider: this.providerName,
69
- });
141
+ return awsConfig;
70
142
  }
71
143
  getProviderName() {
72
144
  return "bedrock";
@@ -80,27 +152,203 @@ export class AmazonBedrockProvider extends BaseProvider {
80
152
  getAISDKModel() {
81
153
  return this.model;
82
154
  }
155
+ /**
156
+ * Get AWS SDK BedrockRuntimeClient for direct access (Bedrock-MCP-Connector compatibility)
157
+ * This provides the same direct AWS SDK access that Bedrock-MCP-Connector uses
158
+ */
159
+ getBedrockClient() {
160
+ // Note: For synchronous access, proxy support is configured lazily
161
+ // If proxy support is critical, use getBedrockClientWithProxy() instead
162
+ return this.bedrockClient;
163
+ }
164
+ /**
165
+ * Get AWS SDK BedrockRuntimeClient with proxy support ensured
166
+ * Use this method when proxy support is critical for the operation
167
+ */
168
+ async getBedrockClientWithProxy() {
169
+ await this.ensureProxySupport();
170
+ return this.bedrockClient;
171
+ }
172
+ /**
173
+ * Get AWS credential provider for advanced credential management
174
+ */
175
+ getCredentialProvider() {
176
+ return this.awsCredentialProvider;
177
+ }
178
+ /**
179
+ * Ensure proxy support is configured for AWS SDK client if needed
180
+ */
181
+ async ensureProxySupport() {
182
+ try {
183
+ const { createAWSProxyHandler } = await import("../proxy/awsProxyIntegration.js");
184
+ const proxyHandler = await createAWSProxyHandler();
185
+ if (proxyHandler) {
186
+ logger.debug("[Bedrock] Reinitializing client with proxy support");
187
+ // Recreate the client with proxy handler
188
+ this.bedrockClient = new BedrockRuntimeClient({
189
+ region: this.awsCredentialProvider.getConfig().region,
190
+ credentials: this.awsCredentialProvider.getCredentialProvider(),
191
+ requestHandler: proxyHandler,
192
+ });
193
+ }
194
+ }
195
+ catch (error) {
196
+ logger.warn("[Bedrock] Failed to configure proxy support", { error });
197
+ // Continue without proxy support
198
+ }
199
+ }
200
+ /**
201
+ * Test AWS credentials and Bedrock connectivity
202
+ * Useful for debugging authentication issues
203
+ */
204
+ async testConnectivity() {
205
+ const startTime = Date.now();
206
+ try {
207
+ // Ensure proxy support is configured before testing
208
+ await this.ensureProxySupport();
209
+ const { CredentialTester } = await import("./aws/credentialTester.js");
210
+ // Add timeout protection using AbortController
211
+ const timeout = 15000; // 15 second timeout
212
+ const abortController = new AbortController();
213
+ const timeoutId = setTimeout(() => {
214
+ abortController.abort();
215
+ }, timeout);
216
+ try {
217
+ const [credentialResult, connectivityResult] = await Promise.race([
218
+ Promise.all([
219
+ CredentialTester.validateCredentials(this.awsCredentialProvider),
220
+ CredentialTester.testBedrockConnectivity(this.awsCredentialProvider),
221
+ ]),
222
+ new Promise((_, reject) => {
223
+ abortController.signal.addEventListener("abort", () => {
224
+ reject(new Error("Connectivity test timeout"));
225
+ });
226
+ }),
227
+ ]);
228
+ clearTimeout(timeoutId);
229
+ return {
230
+ credentialsValid: credentialResult.isValid,
231
+ bedrockAccessible: connectivityResult.bedrockAccessible,
232
+ credentialSource: credentialResult.credentialSource,
233
+ error: credentialResult.error || connectivityResult.error,
234
+ responseTime: Date.now() - startTime,
235
+ };
236
+ }
237
+ catch (timeoutError) {
238
+ clearTimeout(timeoutId);
239
+ throw timeoutError;
240
+ }
241
+ }
242
+ catch (error) {
243
+ const errorMessage = error instanceof Error ? error.message : String(error);
244
+ return {
245
+ credentialsValid: false,
246
+ bedrockAccessible: false,
247
+ credentialSource: "unknown",
248
+ error: errorMessage,
249
+ responseTime: Date.now() - startTime,
250
+ };
251
+ }
252
+ }
83
253
  // executeGenerate removed - BaseProvider handles all generation with tools
84
254
  async executeStream(options, _analysisSchema) {
85
255
  try {
86
256
  this.validateStreamOptions(options);
87
257
  const timeout = this.getTimeout(options);
88
258
  const timeoutController = createTimeoutController(timeout, this.providerName, "stream");
259
+ // Get tools consistently with generate method (now supports streaming with tools)
260
+ const shouldUseTools = !options.disableTools && this.supportsTools();
261
+ const tools = shouldUseTools ? await this.getAllTools() : {};
89
262
  // Build message array from options
90
263
  const messages = buildMessagesArray(options);
91
264
  const result = streamText({
92
265
  model: this.model,
93
266
  messages: messages,
267
+ tools,
268
+ maxSteps: options.maxSteps || DEFAULT_MAX_STEPS,
269
+ toolChoice: shouldUseTools ? "auto" : "none",
94
270
  maxTokens: options.maxTokens || DEFAULT_MAX_TOKENS,
95
271
  temperature: options.temperature,
96
272
  abortSignal: timeoutController?.controller.signal,
97
273
  });
98
274
  const streamResult = {
99
- stream: (async function* () {
100
- for await (const chunk of result.textStream) {
101
- yield { content: chunk };
275
+ stream: (async function* (self) {
276
+ let chunkCount = 0;
277
+ let streamStarted = false;
278
+ let timeoutId = null;
279
+ try {
280
+ // Create timeout promise for first chunk with proper cleanup
281
+ const timeoutPromise = new Promise((_, reject) => {
282
+ timeoutId = setTimeout(() => {
283
+ if (!streamStarted && chunkCount === 0) {
284
+ reject(new Error("❌ Amazon Bedrock Streaming Timeout\n\n" +
285
+ "Stream failed to produce any content within 5 seconds.\n\n" +
286
+ "🔧 Common Causes:\n" +
287
+ "1. Expired AWS credentials - run: aws sts get-caller-identity\n" +
288
+ "2. Missing Bedrock permissions - need: bedrock:InvokeModelWithResponseStream\n" +
289
+ "3. Model not available in your region\n" +
290
+ "4. Network connectivity issues\n\n" +
291
+ '💡 Try: neurolink generate "test" --provider bedrock\n' +
292
+ " (Generate mode provides more detailed error messages)"));
293
+ }
294
+ }, 5000);
295
+ });
296
+ // Process stream with timeout handling
297
+ const streamIterator = result.textStream[Symbol.asyncIterator]();
298
+ let timeoutActive = true;
299
+ while (true) {
300
+ let nextResult;
301
+ if (timeoutActive) {
302
+ // Race between next chunk and timeout for first chunk only
303
+ nextResult = await Promise.race([
304
+ streamIterator.next(),
305
+ timeoutPromise,
306
+ ]);
307
+ }
308
+ else {
309
+ // No timeout for subsequent chunks
310
+ nextResult = await streamIterator.next();
311
+ }
312
+ if (nextResult.done) {
313
+ break;
314
+ }
315
+ if (!streamStarted) {
316
+ streamStarted = true;
317
+ timeoutActive = false;
318
+ // Clear the timeout now that we have content
319
+ if (timeoutId) {
320
+ clearTimeout(timeoutId);
321
+ timeoutId = null;
322
+ }
323
+ }
324
+ chunkCount++;
325
+ yield { content: nextResult.value };
326
+ }
327
+ // If no chunks received, likely an authentication error
328
+ if (chunkCount === 0) {
329
+ throw new Error("❌ Amazon Bedrock Streaming Error\n\n" +
330
+ "Stream completed with no content.\n\n" +
331
+ "🔧 Most Likely Causes:\n" +
332
+ "1. AWS credentials are expired or invalid\n" +
333
+ "2. Insufficient Bedrock permissions\n" +
334
+ "3. Model access not enabled in AWS console\n" +
335
+ "4. Region mismatch\n\n" +
336
+ "🔍 Debug Steps:\n" +
337
+ "1. Check credentials: aws sts get-caller-identity\n" +
338
+ '2. Test generate mode: neurolink generate "test" --provider bedrock\n' +
339
+ '3. Verify region: AWS_REGION=us-east-1 neurolink stream "test" --provider bedrock');
340
+ }
341
+ }
342
+ catch (error) {
343
+ // Clean up timeout on error
344
+ if (timeoutId) {
345
+ clearTimeout(timeoutId);
346
+ }
347
+ throw self.handleStreamError
348
+ ? self.handleStreamError(error)
349
+ : error;
102
350
  }
103
- })(),
351
+ })(this),
104
352
  provider: this.providerName,
105
353
  model: this.modelName,
106
354
  };
@@ -111,6 +359,17 @@ export class AmazonBedrockProvider extends BaseProvider {
111
359
  throw this.handleProviderError(error);
112
360
  }
113
361
  }
362
+ handleStreamError(error) {
363
+ const errorMessage = error instanceof Error ? error.message : String(error);
364
+ // Stream-specific error handling
365
+ if (errorMessage.includes("no content") ||
366
+ errorMessage.includes("Streaming Timeout") ||
367
+ errorMessage.includes("Stream failed")) {
368
+ return new Error(errorMessage); // Already formatted in stream logic
369
+ }
370
+ // For other errors, use standard provider error handling
371
+ return this.handleProviderError(error);
372
+ }
114
373
  handleProviderError(error) {
115
374
  if (error instanceof Error && error.name === "TimeoutError") {
116
375
  return new TimeoutError(`Amazon Bedrock request timed out. Consider increasing timeout or using a lighter model.`, this.defaultTimeout);
@@ -0,0 +1,58 @@
1
+ /**
2
+ * AWS Credential Provider for NeuroLink
3
+ *
4
+ * Provides 100% compatibility with Bedrock-MCP-Connector authentication patterns
5
+ * by leveraging AWS SDK v3's official defaultProvider credential chain.
6
+ *
7
+ * Supports all 9 AWS credential sources:
8
+ * 1. Environment Variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)
9
+ * 2. AWS Credentials File (~/.aws/credentials)
10
+ * 3. AWS Config File (~/.aws/config)
11
+ * 4. IAM Roles (EC2/ECS/Lambda)
12
+ * 5. AWS SSO
13
+ * 6. STS Assume Role
14
+ * 7. Credential Process
15
+ * 8. Container Credentials
16
+ * 9. Instance Metadata Service (IMDS)
17
+ */
18
+ import type { AwsCredentialIdentity, Provider } from "@aws-sdk/types";
19
+ import type { AWSCredentialConfig } from "../../types/providers.js";
20
+ /**
21
+ * AWS Credential Provider class that wraps AWS SDK v3's defaultProvider
22
+ * to provide seamless compatibility with Bedrock-MCP-Connector authentication
23
+ */
24
+ export declare class AWSCredentialProvider {
25
+ private credentialProvider;
26
+ private config;
27
+ private isInitialized;
28
+ private lastCredentials;
29
+ private lastRefresh;
30
+ constructor(config?: AWSCredentialConfig);
31
+ /**
32
+ * Get AWS credentials using the default provider chain
33
+ * Implements caching to avoid unnecessary credential resolution calls
34
+ */
35
+ getCredentials(): Promise<AwsCredentialIdentity>;
36
+ /**
37
+ * Get the raw credential provider for direct use with AWS SDK clients
38
+ * This allows the credential provider to be passed directly to BedrockRuntimeClient
39
+ */
40
+ getCredentialProvider(): Provider<AwsCredentialIdentity>;
41
+ /**
42
+ * Force refresh of cached credentials
43
+ * Useful when credentials may have been updated externally
44
+ */
45
+ refreshCredentials(): Promise<AwsCredentialIdentity>;
46
+ /**
47
+ * Check if credentials are currently available without throwing errors
48
+ */
49
+ isCredentialsAvailable(): Promise<boolean>;
50
+ /**
51
+ * Get configuration information for debugging
52
+ */
53
+ getConfig(): Readonly<Required<AWSCredentialConfig>>;
54
+ /**
55
+ * Clean up resources and clear cached credentials
56
+ */
57
+ dispose(): void;
58
+ }