@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.
Files changed (234) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cli/commands/config.d.ts +86 -86
  3. package/dist/cli/commands/mcp.js +64 -9
  4. package/dist/cli/commands/models.js +25 -21
  5. package/dist/cli/commands/ollama.js +2 -2
  6. package/dist/cli/factories/commandFactory.d.ts +9 -0
  7. package/dist/cli/factories/commandFactory.js +177 -83
  8. package/dist/cli/factories/ollamaCommandFactory.js +3 -1
  9. package/dist/cli/factories/sagemakerCommandFactory.js +3 -2
  10. package/dist/cli/index.d.ts +1 -1
  11. package/dist/cli/index.js +19 -11
  12. package/dist/cli/utils/envManager.js +5 -5
  13. package/dist/cli/utils/ollamaUtils.d.ts +12 -0
  14. package/dist/cli/utils/ollamaUtils.js +58 -42
  15. package/dist/config/configManager.js +5 -2
  16. package/dist/core/analytics.d.ts +2 -24
  17. package/dist/core/analytics.js +12 -17
  18. package/dist/core/baseProvider.d.ts +30 -1
  19. package/dist/core/baseProvider.js +180 -198
  20. package/dist/core/dynamicModels.d.ts +4 -4
  21. package/dist/core/dynamicModels.js +7 -7
  22. package/dist/core/evaluation.d.ts +9 -9
  23. package/dist/core/evaluation.js +117 -65
  24. package/dist/core/evaluationProviders.d.ts +18 -2
  25. package/dist/core/evaluationProviders.js +15 -13
  26. package/dist/core/factory.js +77 -4
  27. package/dist/core/modelConfiguration.d.ts +63 -0
  28. package/dist/core/modelConfiguration.js +354 -290
  29. package/dist/core/streamAnalytics.d.ts +10 -5
  30. package/dist/core/streamAnalytics.js +10 -10
  31. package/dist/core/types.d.ts +19 -109
  32. package/dist/core/types.js +13 -0
  33. package/dist/factories/providerFactory.js +4 -1
  34. package/dist/factories/providerRegistry.js +2 -2
  35. package/dist/index.d.ts +2 -1
  36. package/dist/lib/config/configManager.js +5 -2
  37. package/dist/lib/core/analytics.d.ts +2 -24
  38. package/dist/lib/core/analytics.js +12 -17
  39. package/dist/lib/core/baseProvider.d.ts +30 -1
  40. package/dist/lib/core/baseProvider.js +180 -198
  41. package/dist/lib/core/dynamicModels.js +7 -7
  42. package/dist/lib/core/evaluation.d.ts +9 -9
  43. package/dist/lib/core/evaluation.js +117 -65
  44. package/dist/lib/core/evaluationProviders.d.ts +18 -2
  45. package/dist/lib/core/evaluationProviders.js +15 -13
  46. package/dist/lib/core/factory.js +77 -4
  47. package/dist/lib/core/modelConfiguration.d.ts +63 -0
  48. package/dist/lib/core/modelConfiguration.js +354 -290
  49. package/dist/lib/core/streamAnalytics.d.ts +10 -5
  50. package/dist/lib/core/streamAnalytics.js +10 -10
  51. package/dist/lib/core/types.d.ts +19 -109
  52. package/dist/lib/core/types.js +13 -0
  53. package/dist/lib/factories/providerFactory.js +4 -1
  54. package/dist/lib/factories/providerRegistry.js +2 -2
  55. package/dist/lib/index.d.ts +2 -1
  56. package/dist/lib/mcp/externalServerManager.js +14 -6
  57. package/dist/lib/mcp/factory.js +1 -1
  58. package/dist/lib/mcp/flexibleToolValidator.d.ts +50 -0
  59. package/dist/lib/mcp/flexibleToolValidator.js +161 -0
  60. package/dist/lib/mcp/index.d.ts +1 -1
  61. package/dist/lib/mcp/index.js +1 -1
  62. package/dist/lib/mcp/mcpCircuitBreaker.js +5 -1
  63. package/dist/lib/mcp/mcpClientFactory.js +3 -0
  64. package/dist/lib/mcp/registry.d.ts +3 -3
  65. package/dist/lib/mcp/registry.js +3 -3
  66. package/dist/lib/mcp/servers/aiProviders/aiAnalysisTools.js +5 -5
  67. package/dist/lib/mcp/servers/aiProviders/aiWorkflowTools.js +6 -6
  68. package/dist/lib/mcp/servers/utilities/utilityServer.js +1 -1
  69. package/dist/lib/mcp/toolDiscoveryService.js +8 -2
  70. package/dist/lib/mcp/toolRegistry.d.ts +2 -2
  71. package/dist/lib/mcp/toolRegistry.js +29 -54
  72. package/dist/lib/middleware/builtin/analytics.js +4 -4
  73. package/dist/lib/middleware/builtin/guardrails.js +2 -2
  74. package/dist/lib/middleware/registry.js +11 -2
  75. package/dist/lib/models/modelRegistry.d.ts +1 -1
  76. package/dist/lib/models/modelRegistry.js +3 -3
  77. package/dist/lib/models/modelResolver.d.ts +1 -1
  78. package/dist/lib/models/modelResolver.js +2 -2
  79. package/dist/lib/neurolink.d.ts +118 -0
  80. package/dist/lib/neurolink.js +814 -952
  81. package/dist/lib/providers/amazonBedrock.d.ts +47 -6
  82. package/dist/lib/providers/amazonBedrock.js +282 -23
  83. package/dist/lib/providers/amazonSagemaker.d.ts +1 -1
  84. package/dist/lib/providers/amazonSagemaker.js +12 -3
  85. package/dist/lib/providers/anthropic.d.ts +1 -1
  86. package/dist/lib/providers/anthropic.js +7 -6
  87. package/dist/lib/providers/anthropicBaseProvider.d.ts +1 -1
  88. package/dist/lib/providers/anthropicBaseProvider.js +4 -3
  89. package/dist/lib/providers/aws/credentialProvider.d.ts +58 -0
  90. package/dist/lib/providers/aws/credentialProvider.js +267 -0
  91. package/dist/lib/providers/aws/credentialTester.d.ts +49 -0
  92. package/dist/lib/providers/aws/credentialTester.js +394 -0
  93. package/dist/lib/providers/azureOpenai.d.ts +1 -1
  94. package/dist/lib/providers/azureOpenai.js +1 -1
  95. package/dist/lib/providers/googleAiStudio.d.ts +1 -1
  96. package/dist/lib/providers/googleAiStudio.js +2 -2
  97. package/dist/lib/providers/googleVertex.d.ts +40 -0
  98. package/dist/lib/providers/googleVertex.js +330 -274
  99. package/dist/lib/providers/huggingFace.js +1 -1
  100. package/dist/lib/providers/mistral.d.ts +1 -1
  101. package/dist/lib/providers/mistral.js +2 -2
  102. package/dist/lib/providers/ollama.d.ts +4 -0
  103. package/dist/lib/providers/ollama.js +38 -18
  104. package/dist/lib/providers/openAI.d.ts +1 -1
  105. package/dist/lib/providers/openAI.js +2 -2
  106. package/dist/lib/providers/sagemaker/adaptive-semaphore.js +7 -4
  107. package/dist/lib/providers/sagemaker/client.js +13 -3
  108. package/dist/lib/providers/sagemaker/config.js +5 -1
  109. package/dist/lib/providers/sagemaker/detection.js +19 -9
  110. package/dist/lib/providers/sagemaker/errors.d.ts +8 -1
  111. package/dist/lib/providers/sagemaker/errors.js +103 -20
  112. package/dist/lib/providers/sagemaker/language-model.d.ts +3 -3
  113. package/dist/lib/providers/sagemaker/language-model.js +4 -4
  114. package/dist/lib/providers/sagemaker/parsers.js +14 -6
  115. package/dist/lib/providers/sagemaker/streaming.js +14 -3
  116. package/dist/lib/providers/sagemaker/types.d.ts +1 -1
  117. package/dist/lib/proxy/awsProxyIntegration.d.ts +23 -0
  118. package/dist/lib/proxy/awsProxyIntegration.js +285 -0
  119. package/dist/lib/proxy/proxyFetch.d.ts +9 -5
  120. package/dist/lib/proxy/proxyFetch.js +232 -98
  121. package/dist/lib/proxy/utils/noProxyUtils.d.ts +39 -0
  122. package/dist/lib/proxy/utils/noProxyUtils.js +149 -0
  123. package/dist/lib/sdk/toolRegistration.d.ts +1 -1
  124. package/dist/lib/types/cli.d.ts +80 -8
  125. package/dist/lib/types/contextTypes.js +2 -2
  126. package/dist/lib/types/generateTypes.d.ts +4 -6
  127. package/dist/lib/types/providers.d.ts +124 -19
  128. package/dist/lib/types/providers.js +6 -6
  129. package/dist/lib/types/streamTypes.d.ts +4 -6
  130. package/dist/lib/types/typeAliases.d.ts +1 -1
  131. package/dist/lib/utils/analyticsUtils.d.ts +33 -0
  132. package/dist/lib/utils/analyticsUtils.js +76 -0
  133. package/dist/lib/utils/errorHandling.js +4 -1
  134. package/dist/lib/utils/evaluationUtils.d.ts +27 -0
  135. package/dist/lib/utils/evaluationUtils.js +131 -0
  136. package/dist/lib/utils/optionsUtils.js +10 -1
  137. package/dist/lib/utils/performance.d.ts +1 -1
  138. package/dist/lib/utils/performance.js +15 -3
  139. package/dist/lib/utils/providerConfig.d.ts +1 -0
  140. package/dist/lib/utils/providerConfig.js +2 -1
  141. package/dist/lib/utils/providerHealth.d.ts +48 -0
  142. package/dist/lib/utils/providerHealth.js +221 -158
  143. package/dist/lib/utils/providerUtils.js +2 -2
  144. package/dist/lib/utils/timeout.js +8 -3
  145. package/dist/mcp/externalServerManager.js +14 -6
  146. package/dist/mcp/factory.js +1 -1
  147. package/dist/mcp/flexibleToolValidator.d.ts +50 -0
  148. package/dist/mcp/flexibleToolValidator.js +161 -0
  149. package/dist/mcp/index.d.ts +1 -1
  150. package/dist/mcp/index.js +1 -1
  151. package/dist/mcp/mcpCircuitBreaker.js +5 -1
  152. package/dist/mcp/mcpClientFactory.js +3 -0
  153. package/dist/mcp/registry.d.ts +3 -3
  154. package/dist/mcp/registry.js +3 -3
  155. package/dist/mcp/servers/aiProviders/aiAnalysisTools.js +5 -5
  156. package/dist/mcp/servers/aiProviders/aiWorkflowTools.js +6 -6
  157. package/dist/mcp/servers/utilities/utilityServer.js +1 -1
  158. package/dist/mcp/toolDiscoveryService.js +8 -2
  159. package/dist/mcp/toolRegistry.d.ts +2 -2
  160. package/dist/mcp/toolRegistry.js +29 -54
  161. package/dist/middleware/builtin/analytics.js +4 -4
  162. package/dist/middleware/builtin/guardrails.js +2 -2
  163. package/dist/middleware/registry.js +11 -2
  164. package/dist/models/modelRegistry.d.ts +1 -1
  165. package/dist/models/modelRegistry.js +3 -3
  166. package/dist/models/modelResolver.d.ts +1 -1
  167. package/dist/models/modelResolver.js +2 -2
  168. package/dist/neurolink.d.ts +118 -0
  169. package/dist/neurolink.js +814 -952
  170. package/dist/providers/amazonBedrock.d.ts +47 -6
  171. package/dist/providers/amazonBedrock.js +282 -23
  172. package/dist/providers/amazonSagemaker.d.ts +1 -1
  173. package/dist/providers/amazonSagemaker.js +12 -3
  174. package/dist/providers/anthropic.d.ts +1 -1
  175. package/dist/providers/anthropic.js +7 -6
  176. package/dist/providers/anthropicBaseProvider.d.ts +1 -1
  177. package/dist/providers/anthropicBaseProvider.js +4 -3
  178. package/dist/providers/aws/credentialProvider.d.ts +58 -0
  179. package/dist/providers/aws/credentialProvider.js +267 -0
  180. package/dist/providers/aws/credentialTester.d.ts +49 -0
  181. package/dist/providers/aws/credentialTester.js +394 -0
  182. package/dist/providers/azureOpenai.d.ts +1 -1
  183. package/dist/providers/azureOpenai.js +1 -1
  184. package/dist/providers/googleAiStudio.d.ts +1 -1
  185. package/dist/providers/googleAiStudio.js +2 -2
  186. package/dist/providers/googleVertex.d.ts +40 -0
  187. package/dist/providers/googleVertex.js +330 -274
  188. package/dist/providers/huggingFace.js +1 -1
  189. package/dist/providers/mistral.d.ts +1 -1
  190. package/dist/providers/mistral.js +2 -2
  191. package/dist/providers/ollama.d.ts +4 -0
  192. package/dist/providers/ollama.js +38 -18
  193. package/dist/providers/openAI.d.ts +1 -1
  194. package/dist/providers/openAI.js +2 -2
  195. package/dist/providers/sagemaker/adaptive-semaphore.js +7 -4
  196. package/dist/providers/sagemaker/client.js +13 -3
  197. package/dist/providers/sagemaker/config.js +5 -1
  198. package/dist/providers/sagemaker/detection.js +19 -9
  199. package/dist/providers/sagemaker/errors.d.ts +8 -1
  200. package/dist/providers/sagemaker/errors.js +103 -20
  201. package/dist/providers/sagemaker/language-model.d.ts +3 -3
  202. package/dist/providers/sagemaker/language-model.js +4 -4
  203. package/dist/providers/sagemaker/parsers.js +14 -6
  204. package/dist/providers/sagemaker/streaming.js +14 -3
  205. package/dist/providers/sagemaker/types.d.ts +1 -1
  206. package/dist/proxy/awsProxyIntegration.d.ts +23 -0
  207. package/dist/proxy/awsProxyIntegration.js +285 -0
  208. package/dist/proxy/proxyFetch.d.ts +9 -5
  209. package/dist/proxy/proxyFetch.js +232 -98
  210. package/dist/proxy/utils/noProxyUtils.d.ts +39 -0
  211. package/dist/proxy/utils/noProxyUtils.js +149 -0
  212. package/dist/sdk/toolRegistration.d.ts +1 -1
  213. package/dist/types/cli.d.ts +80 -8
  214. package/dist/types/contextTypes.js +2 -2
  215. package/dist/types/generateTypes.d.ts +4 -6
  216. package/dist/types/providers.d.ts +124 -19
  217. package/dist/types/providers.js +6 -6
  218. package/dist/types/streamTypes.d.ts +4 -6
  219. package/dist/types/typeAliases.d.ts +1 -1
  220. package/dist/utils/analyticsUtils.d.ts +33 -0
  221. package/dist/utils/analyticsUtils.js +76 -0
  222. package/dist/utils/errorHandling.js +4 -1
  223. package/dist/utils/evaluationUtils.d.ts +27 -0
  224. package/dist/utils/evaluationUtils.js +131 -0
  225. package/dist/utils/optionsUtils.js +10 -1
  226. package/dist/utils/performance.d.ts +1 -1
  227. package/dist/utils/performance.js +15 -3
  228. package/dist/utils/providerConfig.d.ts +1 -0
  229. package/dist/utils/providerConfig.js +2 -1
  230. package/dist/utils/providerHealth.d.ts +48 -0
  231. package/dist/utils/providerHealth.js +221 -158
  232. package/dist/utils/providerUtils.js +2 -2
  233. package/dist/utils/timeout.js +8 -3
  234. package/package.json +5 -1
@@ -0,0 +1,394 @@
1
+ /**
2
+ * AWS Credential Testing Utilities for NeuroLink
3
+ *
4
+ * Provides comprehensive validation and debugging capabilities for AWS credentials
5
+ * to ensure compatibility with Bedrock-MCP-Connector authentication patterns.
6
+ */
7
+ import { BedrockClient, ListFoundationModelsCommand, } from "@aws-sdk/client-bedrock";
8
+ import { logger } from "../../utils/logger.js";
9
+ /**
10
+ * Helper function to safely extract comprehensive error information from AWS errors
11
+ * This centralizes error extraction and captures AWS SDK v3 name, statusCode, and requestId
12
+ * Enhanced to handle multiple AWS SDK error formats and edge cases
13
+ */
14
+ function extractAwsErrorInfo(error) {
15
+ const result = {};
16
+ if (typeof error === "object" && error !== null) {
17
+ const awsError = error; // Use AWSError interface to handle various error shapes
18
+ // Extract error code with comprehensive fallbacks
19
+ // AWS SDK v2: error.code, error.Code
20
+ // AWS SDK v3: error.name, error.Code, error.code
21
+ // Some services: error.errorCode, error.ErrorCode
22
+ result.code =
23
+ awsError.Code ||
24
+ awsError.code ||
25
+ awsError.errorCode ||
26
+ awsError.ErrorCode ||
27
+ awsError.name; // AWS SDK v3 often uses name as error code
28
+ // Extract error name with fallbacks
29
+ // AWS SDK v3: error.name is primary
30
+ // Some errors: error.errorType, error.ErrorType
31
+ // Fallback to constructor name
32
+ result.name =
33
+ awsError.name ||
34
+ awsError.errorType ||
35
+ awsError.ErrorType ||
36
+ awsError.constructor?.name;
37
+ // Extract error message with fallbacks
38
+ // Standard: error.message
39
+ // Some services: error.Message, error.errorMessage
40
+ result.message =
41
+ awsError.message ||
42
+ awsError.Message ||
43
+ awsError.errorMessage ||
44
+ String(error); // Last resort stringification
45
+ // Extract metadata with multiple patterns
46
+ // AWS SDK v3: error.$metadata
47
+ // Some services: error.metadata, error.$response
48
+ const metadata = awsError.$metadata || awsError.metadata || awsError.$response;
49
+ if (metadata && typeof metadata === "object") {
50
+ const metadataObj = metadata;
51
+ result.statusCode =
52
+ metadataObj.httpStatusCode ||
53
+ metadataObj.statusCode ||
54
+ metadataObj.status;
55
+ result.requestId =
56
+ metadataObj.requestId ||
57
+ metadataObj.RequestId ||
58
+ metadataObj.request_id ||
59
+ metadataObj["x-amzn-requestid"]; // Common response header
60
+ }
61
+ // Handle wrapped errors (common in AWS SDK v3)
62
+ // Sometimes the actual error is nested in error.cause or error.$fault
63
+ if (!result.code && (awsError.cause || awsError.$fault)) {
64
+ const nestedError = awsError.cause || awsError.$fault;
65
+ const nestedInfo = extractAwsErrorInfo(nestedError);
66
+ // Merge nested error info, preferring current level
67
+ result.code = result.code || nestedInfo.code;
68
+ result.name = result.name || nestedInfo.name;
69
+ result.message = result.message || nestedInfo.message;
70
+ result.statusCode = result.statusCode || nestedInfo.statusCode;
71
+ result.requestId = result.requestId || nestedInfo.requestId;
72
+ }
73
+ }
74
+ // Handle primitive error types (strings, etc.)
75
+ if (!result.message && error) {
76
+ result.message = String(error);
77
+ }
78
+ return result;
79
+ }
80
+ /**
81
+ * Credential testing and validation utility class
82
+ */
83
+ export class CredentialTester {
84
+ /**
85
+ * Validate AWS credentials and detect their source
86
+ */
87
+ static async validateCredentials(provider) {
88
+ const startTime = Date.now();
89
+ try {
90
+ // Get credentials from provider
91
+ const credentials = await provider.getCredentials();
92
+ const config = provider.getConfig();
93
+ // Detect credential source based on available information
94
+ const credentialSource = await this.detectCredentialSource(credentials, config);
95
+ const result = {
96
+ isValid: true,
97
+ credentialSource,
98
+ region: config.region,
99
+ hasExpiration: !!credentials.expiration,
100
+ expirationTime: credentials.expiration,
101
+ debugInfo: {
102
+ accessKeyId: credentials.accessKeyId.substring(0, 8) + "***",
103
+ hasSessionToken: !!credentials.sessionToken,
104
+ providerConfig: config,
105
+ },
106
+ };
107
+ logger.debug("Credential validation successful", {
108
+ source: credentialSource,
109
+ region: config.region,
110
+ validationTimeMs: Date.now() - startTime,
111
+ });
112
+ return result;
113
+ }
114
+ catch (error) {
115
+ const errorMessage = error instanceof Error ? error.message : String(error);
116
+ logger.error("Credential validation failed", {
117
+ error: errorMessage,
118
+ validationTimeMs: Date.now() - startTime,
119
+ });
120
+ return {
121
+ isValid: false,
122
+ credentialSource: "unknown",
123
+ region: provider.getConfig().region,
124
+ hasExpiration: false,
125
+ error: errorMessage,
126
+ debugInfo: {
127
+ accessKeyId: "unavailable",
128
+ hasSessionToken: false,
129
+ providerConfig: provider.getConfig(),
130
+ },
131
+ };
132
+ }
133
+ }
134
+ /**
135
+ * Test AWS Bedrock service connectivity
136
+ */
137
+ static async testBedrockConnectivity(provider, region) {
138
+ const startTime = Date.now();
139
+ const testRegion = region || provider.getConfig().region;
140
+ logger.debug("Starting Bedrock connectivity test", {
141
+ region: testRegion,
142
+ providerConfig: provider.getConfig(),
143
+ });
144
+ try {
145
+ // First, get credentials to see what we're working with
146
+ const credentials = await provider.getCredentials();
147
+ logger.debug("Got credentials for Bedrock test", {
148
+ accessKeyId: credentials.accessKeyId.substring(0, 8) + "***",
149
+ hasSessionToken: !!credentials.sessionToken,
150
+ hasExpiration: !!credentials.expiration,
151
+ expiration: credentials.expiration?.toISOString(),
152
+ credentialType: credentials.accessKeyId?.startsWith("ASIA")
153
+ ? "temporary"
154
+ : "long-term",
155
+ });
156
+ // Create Bedrock client with credential provider (use BedrockClient for listing models)
157
+ logger.debug("Creating BedrockClient", {
158
+ region: testRegion,
159
+ credentialProviderType: typeof provider.getCredentialProvider(),
160
+ });
161
+ const bedrockClient = new BedrockClient({
162
+ region: testRegion,
163
+ credentials: provider.getCredentialProvider(),
164
+ maxAttempts: provider.getConfig().maxAttempts || 3,
165
+ });
166
+ logger.debug("BedrockClient created, sending ListFoundationModelsCommand");
167
+ // Test connectivity by listing foundation models
168
+ const command = new ListFoundationModelsCommand({});
169
+ const ctrl = new AbortController();
170
+ const timeoutId = setTimeout(() => ctrl.abort(), provider.getConfig().timeout || 15000);
171
+ let response;
172
+ try {
173
+ response = await bedrockClient.send(command, {
174
+ abortSignal: ctrl.signal,
175
+ });
176
+ }
177
+ finally {
178
+ clearTimeout(timeoutId);
179
+ }
180
+ logger.debug("ListFoundationModelsCommand response received", {
181
+ hasModelSummaries: !!response.modelSummaries,
182
+ modelCount: response.modelSummaries?.length || 0,
183
+ responseMetadata: response.$metadata,
184
+ });
185
+ const models = response.modelSummaries || [];
186
+ const responseTime = Date.now() - startTime;
187
+ const result = {
188
+ bedrockAccessible: true,
189
+ availableModels: models.length,
190
+ responseTimeMs: responseTime,
191
+ sampleModels: models
192
+ .slice(0, 5)
193
+ .map((model) => model.modelId || "unknown"),
194
+ };
195
+ logger.debug("Bedrock connectivity test successful", {
196
+ region: testRegion,
197
+ modelsFound: models.length,
198
+ responseTimeMs: responseTime,
199
+ sampleModels: result.sampleModels,
200
+ });
201
+ return result;
202
+ }
203
+ catch (error) {
204
+ const errorMessage = error instanceof Error ? error.message : String(error);
205
+ const responseTime = Date.now() - startTime;
206
+ const { code, statusCode, requestId } = extractAwsErrorInfo(error);
207
+ logger.error("Bedrock connectivity test failed", {
208
+ region: testRegion,
209
+ error: errorMessage,
210
+ errorType: error instanceof Error ? error.constructor.name : "unknown",
211
+ errorCode: code,
212
+ statusCode,
213
+ requestId,
214
+ stack: error instanceof Error ? error.stack : "no stack trace",
215
+ responseTimeMs: responseTime,
216
+ });
217
+ return {
218
+ bedrockAccessible: false,
219
+ availableModels: 0,
220
+ responseTimeMs: responseTime,
221
+ error: errorMessage,
222
+ sampleModels: [],
223
+ };
224
+ }
225
+ }
226
+ /**
227
+ * Perform comprehensive credential and service testing
228
+ */
229
+ static async runComprehensiveTest(provider, testRegions = ["us-east-1", "us-west-2"]) {
230
+ logger.debug("Starting comprehensive AWS credential and connectivity test");
231
+ // Test credential validation
232
+ const credentialValidation = await this.validateCredentials(provider);
233
+ // Test connectivity across multiple regions (in parallel)
234
+ const connectivityTests = await Promise.all(testRegions.map(async (region) => {
235
+ try {
236
+ const result = await this.testBedrockConnectivity(provider, region);
237
+ return { region, result };
238
+ }
239
+ catch (error) {
240
+ const errorMessage = error instanceof Error ? error.message : String(error);
241
+ return {
242
+ region,
243
+ result: {
244
+ bedrockAccessible: false,
245
+ availableModels: 0,
246
+ responseTimeMs: 0,
247
+ error: errorMessage,
248
+ sampleModels: [],
249
+ },
250
+ };
251
+ }
252
+ }));
253
+ // Determine overall status
254
+ let overallStatus;
255
+ let summary;
256
+ if (!credentialValidation.isValid) {
257
+ overallStatus = "failed";
258
+ summary = `Credential validation failed: ${credentialValidation.error}`;
259
+ }
260
+ else {
261
+ const successfulConnections = connectivityTests.filter((test) => test.result.bedrockAccessible).length;
262
+ if (successfulConnections === testRegions.length) {
263
+ overallStatus = "success";
264
+ summary = `All tests passed. Credentials valid, Bedrock accessible in ${successfulConnections}/${testRegions.length} regions.`;
265
+ }
266
+ else if (successfulConnections > 0) {
267
+ overallStatus = "partial";
268
+ summary = `Partial success. Credentials valid, Bedrock accessible in ${successfulConnections}/${testRegions.length} regions.`;
269
+ }
270
+ else {
271
+ overallStatus = "failed";
272
+ summary = `Credentials valid but Bedrock inaccessible in all tested regions.`;
273
+ }
274
+ }
275
+ logger.info("Comprehensive test completed", {
276
+ overallStatus,
277
+ credentialSource: credentialValidation.credentialSource,
278
+ successfulConnections: connectivityTests.filter((test) => test.result.bedrockAccessible).length,
279
+ totalRegionsTested: testRegions.length,
280
+ });
281
+ return {
282
+ credentialValidation,
283
+ connectivityTests,
284
+ overallStatus,
285
+ summary,
286
+ };
287
+ }
288
+ /**
289
+ * Detect the source of AWS credentials based on credential properties and environment
290
+ */
291
+ static async detectCredentialSource(credentials, config) {
292
+ // Check for environment variables (static creds)
293
+ if (process.env.AWS_ACCESS_KEY_ID && process.env.AWS_SECRET_ACCESS_KEY) {
294
+ return credentials.sessionToken
295
+ ? "Environment Variables (with session token)"
296
+ : "Environment Variables";
297
+ }
298
+ // Explicit env‐based sources first
299
+ if (process.env.AWS_WEB_IDENTITY_TOKEN_FILE) {
300
+ return "Web Identity Token";
301
+ }
302
+ if (process.env.AWS_CREDENTIAL_PROCESS) {
303
+ return "Credential Process";
304
+ }
305
+ // Check for role‐based credentials (temporary credentials with session token)
306
+ if (credentials.sessionToken && credentials.expiration) {
307
+ // Prefer explicit hints first
308
+ if (config.roleArn) {
309
+ return "STS Assume Role";
310
+ }
311
+ // Enhanced container detection
312
+ if (process.env.AWS_CONTAINER_CREDENTIALS_RELATIVE_URI ||
313
+ process.env.AWS_CONTAINER_CREDENTIALS_FULL_URI) {
314
+ // Detect specific container environments
315
+ if (process.env.AWS_EXECUTION_ENV === "AWS_ECS_FARGATE") {
316
+ return "Container Credentials (ECS Fargate)";
317
+ }
318
+ if (process.env.AWS_EXECUTION_ENV === "AWS_ECS_EC2") {
319
+ return "Container Credentials (ECS)";
320
+ }
321
+ return "Container Credentials (ECS)";
322
+ }
323
+ // Enhanced Lambda detection
324
+ if (process.env.AWS_LAMBDA_FUNCTION_NAME) {
325
+ return "Lambda Execution Role";
326
+ }
327
+ // Enhanced EC2 detection
328
+ if (process.env.AWS_EXECUTION_ENV?.includes("EC2")) {
329
+ return "Instance Metadata (EC2)";
330
+ }
331
+ // Enhanced EKS detection
332
+ if (process.env.KUBERNETES_SERVICE_HOST) {
333
+ return "Service Account (EKS)";
334
+ }
335
+ return "Temporary Credentials (IAM Role)";
336
+ }
337
+ // SSO (env‐configured)
338
+ if (process.env.AWS_SSO_START_URL || process.env.AWS_SSO_REGION) {
339
+ return "AWS SSO";
340
+ }
341
+ // Check for profile‐based credentials
342
+ if (config.profile !== "default") {
343
+ return `AWS Profile (${config.profile})`;
344
+ }
345
+ if (process.env.AWS_PROFILE) {
346
+ return `AWS Profile (${process.env.AWS_PROFILE})`;
347
+ }
348
+ // Default fallback
349
+ return "AWS Credentials File";
350
+ }
351
+ /**
352
+ * Get credential source name for debugging
353
+ */
354
+ static async getCredentialSource(provider) {
355
+ try {
356
+ const credentials = await provider.getCredentials();
357
+ const config = provider.getConfig();
358
+ return await this.detectCredentialSource(credentials, config);
359
+ }
360
+ catch {
361
+ return "Unable to determine credential source";
362
+ }
363
+ }
364
+ /**
365
+ * Test credential refresh functionality
366
+ */
367
+ static async testCredentialRefresh(provider) {
368
+ const startTime = Date.now();
369
+ try {
370
+ await provider.refreshCredentials();
371
+ const refreshTime = Date.now() - startTime;
372
+ logger.debug("Credential refresh test successful", {
373
+ refreshTimeMs: refreshTime,
374
+ });
375
+ return {
376
+ refreshSuccessful: true,
377
+ refreshTimeMs: refreshTime,
378
+ };
379
+ }
380
+ catch (error) {
381
+ const errorMessage = error instanceof Error ? error.message : String(error);
382
+ const refreshTime = Date.now() - startTime;
383
+ logger.error("Credential refresh test failed", {
384
+ error: errorMessage,
385
+ refreshTimeMs: refreshTime,
386
+ });
387
+ return {
388
+ refreshSuccessful: false,
389
+ refreshTimeMs: refreshTime,
390
+ error: errorMessage,
391
+ };
392
+ }
393
+ }
394
+ }
@@ -16,6 +16,6 @@ export declare class AzureOpenAIProvider extends BaseProvider {
16
16
  */
17
17
  protected getAISDKModel(): LanguageModelV1;
18
18
  protected handleProviderError(error: unknown): Error;
19
- protected executeStream(options: StreamOptions, analysisSchema?: unknown): Promise<StreamResult>;
19
+ protected executeStream(options: StreamOptions, _analysisSchema?: unknown): Promise<StreamResult>;
20
20
  }
21
21
  export default AzureOpenAIProvider;
@@ -70,7 +70,7 @@ export class AzureOpenAIProvider extends BaseProvider {
70
70
  return new Error(`Azure OpenAI error: ${message}`);
71
71
  }
72
72
  // executeGenerate removed - BaseProvider handles all generation with tools
73
- async executeStream(options, analysisSchema) {
73
+ async executeStream(options, _analysisSchema) {
74
74
  try {
75
75
  // Build message array from options
76
76
  const messages = buildMessagesArray(options);
@@ -16,7 +16,7 @@ export declare class GoogleAIStudioProvider extends BaseProvider {
16
16
  */
17
17
  protected getAISDKModel(): LanguageModelV1;
18
18
  protected handleProviderError(error: unknown): Error;
19
- protected executeStream(options: StreamOptions, analysisSchema?: ZodUnknownSchema | Schema<unknown>): Promise<StreamResult>;
19
+ protected executeStream(options: StreamOptions, _analysisSchema?: ZodUnknownSchema | Schema<unknown>): Promise<StreamResult>;
20
20
  private getApiKey;
21
21
  }
22
22
  export default GoogleAIStudioProvider;
@@ -3,7 +3,7 @@ import { streamText } from "ai";
3
3
  import { GoogleAIModels } from "../core/types.js";
4
4
  import { BaseProvider } from "../core/baseProvider.js";
5
5
  import { logger } from "../utils/logger.js";
6
- import { createTimeoutController, TimeoutError, } from "../utils/timeout.js";
6
+ import { createTimeoutController, TimeoutError } from "../utils/timeout.js";
7
7
  import { AuthenticationError, NetworkError, ProviderError, RateLimitError, } from "../types/errors.js";
8
8
  import { DEFAULT_MAX_TOKENS, DEFAULT_MAX_STEPS } from "../core/constants.js";
9
9
  import { streamAnalyticsCollector } from "../core/streamAnalytics.js";
@@ -60,7 +60,7 @@ export class GoogleAIStudioProvider extends BaseProvider {
60
60
  throw new ProviderError(`Google AI error: ${message}`, this.providerName);
61
61
  }
62
62
  // executeGenerate removed - BaseProvider handles all generation with tools
63
- async executeStream(options, analysisSchema) {
63
+ async executeStream(options, _analysisSchema) {
64
64
  this.validateStreamOptions(options);
65
65
  const startTime = Date.now();
66
66
  const apiKey = this.getApiKey();
@@ -33,12 +33,52 @@ export declare class GoogleVertexProvider extends BaseProvider {
33
33
  * Creates fresh model instances for each request
34
34
  */
35
35
  protected getAISDKModel(): Promise<LanguageModel>;
36
+ /**
37
+ * Initialize model creation logging and tracking
38
+ */
39
+ private initializeModelCreationLogging;
40
+ /**
41
+ * Check if model is Anthropic-based and attempt creation
42
+ */
43
+ private attemptAnthropicModelCreation;
44
+ /**
45
+ * Create Google Vertex model with comprehensive logging and error handling
46
+ */
47
+ private createGoogleVertexModel;
48
+ /**
49
+ * Create Vertex AI instance and model with comprehensive logging
50
+ */
51
+ private createVertexInstance;
36
52
  /**
37
53
  * Gets the appropriate model instance (Google or Anthropic)
38
54
  * Uses dual provider architecture for proper model routing
39
55
  * Creates fresh instances for each request to ensure proper authentication
40
56
  */
41
57
  private getModel;
58
+ /**
59
+ * Log stream execution start with comprehensive analysis
60
+ */
61
+ private logStreamExecutionStart;
62
+ /**
63
+ * Log timeout setup process
64
+ */
65
+ private logTimeoutSetup;
66
+ /**
67
+ * Log successful timeout setup
68
+ */
69
+ private logTimeoutSetupSuccess;
70
+ /**
71
+ * Log and perform stream options validation
72
+ */
73
+ private logAndValidateStreamOptions;
74
+ /**
75
+ * Log start of message building process
76
+ */
77
+ private logMessageBuildStart;
78
+ /**
79
+ * Log successful message building
80
+ */
81
+ private logMessageBuildSuccess;
42
82
  protected executeStream(options: StreamOptions, analysisSchema?: ZodType<unknown, ZodTypeDef, unknown> | Schema<unknown>): Promise<StreamResult>;
43
83
  protected handleProviderError(error: unknown): Error;
44
84
  /**