@juspay/neurolink 6.0.0 → 6.2.0

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 (283) hide show
  1. package/CHANGELOG.md +14 -3
  2. package/dist/cli/commands/config.d.ts +13 -13
  3. package/dist/cli/index.js +3 -9
  4. package/dist/core/analytics.d.ts +11 -1
  5. package/dist/core/analytics.js +2 -2
  6. package/dist/core/base-provider.js +4 -18
  7. package/dist/core/dynamic-models.d.ts +8 -8
  8. package/dist/core/factory.js +3 -11
  9. package/dist/index.d.ts +2 -4
  10. package/dist/index.js +2 -11
  11. package/dist/lib/core/analytics.d.ts +11 -1
  12. package/dist/lib/core/analytics.js +2 -2
  13. package/dist/lib/core/base-provider.js +4 -18
  14. package/dist/lib/core/dynamic-models.d.ts +8 -8
  15. package/dist/lib/core/factory.js +3 -11
  16. package/dist/lib/index.d.ts +2 -4
  17. package/dist/lib/index.js +2 -11
  18. package/dist/lib/mcp/factory.d.ts +1 -1
  19. package/dist/lib/mcp/index.d.ts +7 -19
  20. package/dist/lib/mcp/index.js +15 -56
  21. package/dist/lib/neurolink.d.ts +1 -9
  22. package/dist/lib/neurolink.js +21 -70
  23. package/dist/lib/providers/amazon-bedrock.js +5 -16
  24. package/dist/lib/providers/anthropic-baseprovider.js +3 -21
  25. package/dist/lib/providers/anthropic.js +4 -7
  26. package/dist/lib/providers/azure-openai.js +4 -2
  27. package/dist/lib/providers/google-vertex.js +5 -9
  28. package/dist/lib/providers/huggingFace.js +5 -10
  29. package/dist/lib/providers/mistral.js +5 -8
  30. package/dist/lib/providers/openAI.js +4 -7
  31. package/dist/lib/utils/providerConfig.d.ts +117 -0
  32. package/dist/lib/utils/providerConfig.js +353 -0
  33. package/dist/lib/utils/providerUtils.d.ts +2 -1
  34. package/dist/lib/utils/providerUtils.js +53 -36
  35. package/dist/lib/utils/timeout.d.ts +72 -1
  36. package/dist/lib/utils/timeout.js +203 -2
  37. package/dist/mcp/factory.d.ts +1 -1
  38. package/dist/mcp/index.d.ts +7 -19
  39. package/dist/mcp/index.js +15 -56
  40. package/dist/neurolink.d.ts +1 -9
  41. package/dist/neurolink.js +21 -70
  42. package/dist/providers/amazon-bedrock.js +5 -16
  43. package/dist/providers/anthropic-baseprovider.js +3 -21
  44. package/dist/providers/anthropic.js +4 -7
  45. package/dist/providers/azure-openai.js +4 -2
  46. package/dist/providers/google-vertex.js +5 -9
  47. package/dist/providers/huggingFace.js +5 -10
  48. package/dist/providers/mistral.js +5 -8
  49. package/dist/providers/openAI.js +4 -7
  50. package/dist/utils/providerConfig.d.ts +117 -0
  51. package/dist/utils/providerConfig.js +353 -0
  52. package/dist/utils/providerUtils.d.ts +2 -1
  53. package/dist/utils/providerUtils.js +53 -36
  54. package/dist/utils/timeout.d.ts +72 -1
  55. package/dist/utils/timeout.js +203 -2
  56. package/package.json +2 -1
  57. package/dist/chat/client-utils.d.ts +0 -95
  58. package/dist/chat/client-utils.js +0 -315
  59. package/dist/chat/index.d.ts +0 -24
  60. package/dist/chat/index.js +0 -33
  61. package/dist/chat/session-storage.d.ts +0 -77
  62. package/dist/chat/session-storage.js +0 -233
  63. package/dist/chat/session.d.ts +0 -96
  64. package/dist/chat/session.js +0 -257
  65. package/dist/chat/sse-handler.d.ts +0 -49
  66. package/dist/chat/sse-handler.js +0 -259
  67. package/dist/chat/types.d.ts +0 -74
  68. package/dist/chat/types.js +0 -5
  69. package/dist/chat/websocket-chat-handler.d.ts +0 -37
  70. package/dist/chat/websocket-chat-handler.js +0 -262
  71. package/dist/cli/commands/mcp.d.ts +0 -20
  72. package/dist/cli/commands/mcp.js +0 -1272
  73. package/dist/core/defaults.d.ts +0 -19
  74. package/dist/core/defaults.js +0 -29
  75. package/dist/core/evaluation-config.d.ts +0 -29
  76. package/dist/core/evaluation-config.js +0 -144
  77. package/dist/factories/compatibility-factory.d.ts +0 -35
  78. package/dist/factories/compatibility-factory.js +0 -71
  79. package/dist/factories/provider-generate-factory.d.ts +0 -20
  80. package/dist/factories/provider-generate-factory.js +0 -93
  81. package/dist/lib/chat/client-utils.d.ts +0 -95
  82. package/dist/lib/chat/client-utils.js +0 -315
  83. package/dist/lib/chat/index.d.ts +0 -24
  84. package/dist/lib/chat/index.js +0 -33
  85. package/dist/lib/chat/session-storage.d.ts +0 -77
  86. package/dist/lib/chat/session-storage.js +0 -233
  87. package/dist/lib/chat/session.d.ts +0 -96
  88. package/dist/lib/chat/session.js +0 -257
  89. package/dist/lib/chat/sse-handler.d.ts +0 -49
  90. package/dist/lib/chat/sse-handler.js +0 -259
  91. package/dist/lib/chat/types.d.ts +0 -74
  92. package/dist/lib/chat/types.js +0 -5
  93. package/dist/lib/chat/websocket-chat-handler.d.ts +0 -37
  94. package/dist/lib/chat/websocket-chat-handler.js +0 -262
  95. package/dist/lib/core/defaults.d.ts +0 -19
  96. package/dist/lib/core/defaults.js +0 -29
  97. package/dist/lib/core/evaluation-config.d.ts +0 -29
  98. package/dist/lib/core/evaluation-config.js +0 -144
  99. package/dist/lib/factories/compatibility-factory.d.ts +0 -35
  100. package/dist/lib/factories/compatibility-factory.js +0 -71
  101. package/dist/lib/factories/provider-generate-factory.d.ts +0 -20
  102. package/dist/lib/factories/provider-generate-factory.js +0 -93
  103. package/dist/lib/mcp/adapters/plugin-bridge.d.ts +0 -40
  104. package/dist/lib/mcp/adapters/plugin-bridge.js +0 -89
  105. package/dist/lib/mcp/auto-discovery.d.ts +0 -62
  106. package/dist/lib/mcp/auto-discovery.js +0 -149
  107. package/dist/lib/mcp/client.d.ts +0 -68
  108. package/dist/lib/mcp/client.js +0 -248
  109. package/dist/lib/mcp/config.d.ts +0 -31
  110. package/dist/lib/mcp/config.js +0 -99
  111. package/dist/lib/mcp/context-manager.d.ts +0 -171
  112. package/dist/lib/mcp/context-manager.js +0 -362
  113. package/dist/lib/mcp/contracts/mcp-contract.d.ts +0 -169
  114. package/dist/lib/mcp/contracts/mcp-contract.js +0 -58
  115. package/dist/lib/mcp/core/plugin-manager.d.ts +0 -46
  116. package/dist/lib/mcp/core/plugin-manager.js +0 -110
  117. package/dist/lib/mcp/demo/plugin-demo.d.ts +0 -20
  118. package/dist/lib/mcp/demo/plugin-demo.js +0 -118
  119. package/dist/lib/mcp/dynamic-chain-executor.d.ts +0 -225
  120. package/dist/lib/mcp/dynamic-chain-executor.js +0 -489
  121. package/dist/lib/mcp/dynamic-orchestrator.d.ts +0 -115
  122. package/dist/lib/mcp/dynamic-orchestrator.js +0 -351
  123. package/dist/lib/mcp/ecosystem.d.ts +0 -75
  124. package/dist/lib/mcp/ecosystem.js +0 -161
  125. package/dist/lib/mcp/error-manager.d.ts +0 -254
  126. package/dist/lib/mcp/error-manager.js +0 -501
  127. package/dist/lib/mcp/error-recovery.d.ts +0 -159
  128. package/dist/lib/mcp/error-recovery.js +0 -405
  129. package/dist/lib/mcp/external-client.d.ts +0 -88
  130. package/dist/lib/mcp/external-client.js +0 -331
  131. package/dist/lib/mcp/external-manager.d.ts +0 -112
  132. package/dist/lib/mcp/external-manager.js +0 -308
  133. package/dist/lib/mcp/function-calling.d.ts +0 -65
  134. package/dist/lib/mcp/function-calling.js +0 -642
  135. package/dist/lib/mcp/health-monitor.d.ts +0 -257
  136. package/dist/lib/mcp/health-monitor.js +0 -630
  137. package/dist/lib/mcp/initialize-tools.d.ts +0 -29
  138. package/dist/lib/mcp/initialize-tools.js +0 -261
  139. package/dist/lib/mcp/initialize.d.ts +0 -18
  140. package/dist/lib/mcp/initialize.js +0 -62
  141. package/dist/lib/mcp/manager.d.ts +0 -68
  142. package/dist/lib/mcp/manager.js +0 -176
  143. package/dist/lib/mcp/neurolink-mcp-client.d.ts +0 -97
  144. package/dist/lib/mcp/neurolink-mcp-client.js +0 -462
  145. package/dist/lib/mcp/orchestrator.d.ts +0 -302
  146. package/dist/lib/mcp/orchestrator.js +0 -703
  147. package/dist/lib/mcp/plugin-manager.d.ts +0 -98
  148. package/dist/lib/mcp/plugin-manager.js +0 -296
  149. package/dist/lib/mcp/plugins/core/filesystem-mcp.d.ts +0 -36
  150. package/dist/lib/mcp/plugins/core/filesystem-mcp.js +0 -142
  151. package/dist/lib/mcp/plugins/filesystem-mcp.d.ts +0 -37
  152. package/dist/lib/mcp/plugins/filesystem-mcp.js +0 -54
  153. package/dist/lib/mcp/security-manager.d.ts +0 -87
  154. package/dist/lib/mcp/security-manager.js +0 -344
  155. package/dist/lib/mcp/semaphore-manager.d.ts +0 -137
  156. package/dist/lib/mcp/semaphore-manager.js +0 -329
  157. package/dist/lib/mcp/session-manager.d.ts +0 -187
  158. package/dist/lib/mcp/session-manager.js +0 -400
  159. package/dist/lib/mcp/session-persistence.d.ts +0 -93
  160. package/dist/lib/mcp/session-persistence.js +0 -301
  161. package/dist/lib/mcp/tool-integration.d.ts +0 -58
  162. package/dist/lib/mcp/tool-integration.js +0 -203
  163. package/dist/lib/mcp/transport-manager.d.ts +0 -154
  164. package/dist/lib/mcp/transport-manager.js +0 -334
  165. package/dist/lib/mcp/unified-mcp.d.ts +0 -133
  166. package/dist/lib/mcp/unified-mcp.js +0 -251
  167. package/dist/lib/mcp/unified-registry.d.ts +0 -165
  168. package/dist/lib/mcp/unified-registry.js +0 -538
  169. package/dist/lib/providers/analytics-helper.d.ts +0 -38
  170. package/dist/lib/providers/analytics-helper.js +0 -216
  171. package/dist/lib/providers/function-calling-provider.d.ts +0 -142
  172. package/dist/lib/providers/function-calling-provider.js +0 -630
  173. package/dist/lib/providers/mcp-provider.d.ts +0 -75
  174. package/dist/lib/providers/mcp-provider.js +0 -283
  175. package/dist/lib/providers/timeout-wrapper.d.ts +0 -40
  176. package/dist/lib/providers/timeout-wrapper.js +0 -100
  177. package/dist/lib/sdk/tool-extension.d.ts +0 -181
  178. package/dist/lib/sdk/tool-extension.js +0 -284
  179. package/dist/lib/services/streaming/streaming-manager.d.ts +0 -29
  180. package/dist/lib/services/streaming/streaming-manager.js +0 -245
  181. package/dist/lib/services/types.d.ts +0 -156
  182. package/dist/lib/services/types.js +0 -2
  183. package/dist/lib/services/websocket/websocket-server.d.ts +0 -34
  184. package/dist/lib/services/websocket/websocket-server.js +0 -305
  185. package/dist/lib/utils/provider-validation.d.ts +0 -36
  186. package/dist/lib/utils/provider-validation.js +0 -625
  187. package/dist/lib/utils/providerUtils-fixed.d.ts +0 -8
  188. package/dist/lib/utils/providerUtils-fixed.js +0 -94
  189. package/dist/lib/utils/streaming-utils.d.ts +0 -79
  190. package/dist/lib/utils/streaming-utils.js +0 -198
  191. package/dist/lib/utils/timeout-manager.d.ts +0 -75
  192. package/dist/lib/utils/timeout-manager.js +0 -244
  193. package/dist/mcp/adapters/plugin-bridge.d.ts +0 -40
  194. package/dist/mcp/adapters/plugin-bridge.js +0 -89
  195. package/dist/mcp/auto-discovery.d.ts +0 -62
  196. package/dist/mcp/auto-discovery.js +0 -149
  197. package/dist/mcp/client.d.ts +0 -68
  198. package/dist/mcp/client.js +0 -248
  199. package/dist/mcp/config.d.ts +0 -31
  200. package/dist/mcp/config.js +0 -99
  201. package/dist/mcp/context-manager.d.ts +0 -171
  202. package/dist/mcp/context-manager.js +0 -362
  203. package/dist/mcp/contracts/mcp-contract.d.ts +0 -169
  204. package/dist/mcp/contracts/mcp-contract.js +0 -58
  205. package/dist/mcp/core/plugin-manager.d.ts +0 -46
  206. package/dist/mcp/core/plugin-manager.js +0 -110
  207. package/dist/mcp/demo/plugin-demo.d.ts +0 -20
  208. package/dist/mcp/demo/plugin-demo.js +0 -118
  209. package/dist/mcp/dynamic-chain-executor.d.ts +0 -225
  210. package/dist/mcp/dynamic-chain-executor.js +0 -489
  211. package/dist/mcp/dynamic-orchestrator.d.ts +0 -115
  212. package/dist/mcp/dynamic-orchestrator.js +0 -351
  213. package/dist/mcp/ecosystem.d.ts +0 -75
  214. package/dist/mcp/ecosystem.js +0 -162
  215. package/dist/mcp/error-manager.d.ts +0 -254
  216. package/dist/mcp/error-manager.js +0 -501
  217. package/dist/mcp/error-recovery.d.ts +0 -159
  218. package/dist/mcp/error-recovery.js +0 -405
  219. package/dist/mcp/external-client.d.ts +0 -88
  220. package/dist/mcp/external-client.js +0 -331
  221. package/dist/mcp/external-manager.d.ts +0 -112
  222. package/dist/mcp/external-manager.js +0 -308
  223. package/dist/mcp/function-calling.d.ts +0 -65
  224. package/dist/mcp/function-calling.js +0 -642
  225. package/dist/mcp/health-monitor.d.ts +0 -257
  226. package/dist/mcp/health-monitor.js +0 -630
  227. package/dist/mcp/initialize-tools.d.ts +0 -29
  228. package/dist/mcp/initialize-tools.js +0 -262
  229. package/dist/mcp/initialize.d.ts +0 -18
  230. package/dist/mcp/initialize.js +0 -62
  231. package/dist/mcp/manager.d.ts +0 -68
  232. package/dist/mcp/manager.js +0 -176
  233. package/dist/mcp/neurolink-mcp-client.d.ts +0 -97
  234. package/dist/mcp/neurolink-mcp-client.js +0 -462
  235. package/dist/mcp/orchestrator.d.ts +0 -302
  236. package/dist/mcp/orchestrator.js +0 -703
  237. package/dist/mcp/plugin-manager.d.ts +0 -98
  238. package/dist/mcp/plugin-manager.js +0 -297
  239. package/dist/mcp/plugins/core/filesystem-mcp.d.ts +0 -36
  240. package/dist/mcp/plugins/core/filesystem-mcp.js +0 -142
  241. package/dist/mcp/plugins/core/neurolink-mcp.json +0 -17
  242. package/dist/mcp/plugins/filesystem-mcp.d.ts +0 -37
  243. package/dist/mcp/plugins/filesystem-mcp.js +0 -54
  244. package/dist/mcp/security-manager.d.ts +0 -87
  245. package/dist/mcp/security-manager.js +0 -344
  246. package/dist/mcp/semaphore-manager.d.ts +0 -137
  247. package/dist/mcp/semaphore-manager.js +0 -329
  248. package/dist/mcp/session-manager.d.ts +0 -187
  249. package/dist/mcp/session-manager.js +0 -400
  250. package/dist/mcp/session-persistence.d.ts +0 -93
  251. package/dist/mcp/session-persistence.js +0 -302
  252. package/dist/mcp/tool-integration.d.ts +0 -58
  253. package/dist/mcp/tool-integration.js +0 -203
  254. package/dist/mcp/transport-manager.d.ts +0 -154
  255. package/dist/mcp/transport-manager.js +0 -335
  256. package/dist/mcp/unified-mcp.d.ts +0 -133
  257. package/dist/mcp/unified-mcp.js +0 -251
  258. package/dist/mcp/unified-registry.d.ts +0 -165
  259. package/dist/mcp/unified-registry.js +0 -539
  260. package/dist/providers/analytics-helper.d.ts +0 -38
  261. package/dist/providers/analytics-helper.js +0 -216
  262. package/dist/providers/function-calling-provider.d.ts +0 -142
  263. package/dist/providers/function-calling-provider.js +0 -630
  264. package/dist/providers/mcp-provider.d.ts +0 -75
  265. package/dist/providers/mcp-provider.js +0 -283
  266. package/dist/providers/timeout-wrapper.d.ts +0 -40
  267. package/dist/providers/timeout-wrapper.js +0 -100
  268. package/dist/sdk/tool-extension.d.ts +0 -181
  269. package/dist/sdk/tool-extension.js +0 -284
  270. package/dist/services/streaming/streaming-manager.d.ts +0 -29
  271. package/dist/services/streaming/streaming-manager.js +0 -245
  272. package/dist/services/types.d.ts +0 -156
  273. package/dist/services/types.js +0 -2
  274. package/dist/services/websocket/websocket-server.d.ts +0 -34
  275. package/dist/services/websocket/websocket-server.js +0 -306
  276. package/dist/utils/provider-validation.d.ts +0 -36
  277. package/dist/utils/provider-validation.js +0 -625
  278. package/dist/utils/providerUtils-fixed.d.ts +0 -8
  279. package/dist/utils/providerUtils-fixed.js +0 -94
  280. package/dist/utils/streaming-utils.d.ts +0 -79
  281. package/dist/utils/streaming-utils.js +0 -198
  282. package/dist/utils/timeout-manager.d.ts +0 -75
  283. package/dist/utils/timeout-manager.js +0 -244
@@ -1,625 +0,0 @@
1
- /**
2
- * Enhanced Provider Validation Utilities
3
- *
4
- * Fixes false positives in provider status checking by implementing:
5
- * - API key format validation
6
- * - Lightweight authentication checks
7
- * - Proper error classification
8
- * - Rate-limit friendly validation
9
- */
10
- import { hasProviderEnvVars } from "./providerUtils.js";
11
- import { defaultTimeoutManager } from "./timeout-manager.js";
12
- /**
13
- * API key format validation rules for different providers
14
- */
15
- const API_KEY_FORMATS = {
16
- openai: /^sk-[A-Za-z0-9]{48,}$/,
17
- anthropic: /^sk-ant-[A-Za-z0-9\-_]{95,}$/,
18
- "google-ai": /^AIza[A-Za-z0-9\-_]{35}$/,
19
- huggingface: /^hf_[A-Za-z0-9]{37}$/,
20
- mistral: /^[A-Za-z0-9]{32}$/,
21
- // Azure and AWS have more complex validation patterns
22
- azure: /^[A-Za-z0-9]{32,}$/,
23
- aws: /^[A-Z0-9]{20}$/, // Access Key ID format
24
- };
25
- /**
26
- * Get API key for a provider from environment variables
27
- */
28
- function getProviderApiKey(provider) {
29
- switch (provider.toLowerCase()) {
30
- case "openai":
31
- return process.env.OPENAI_API_KEY || null;
32
- case "anthropic":
33
- return process.env.ANTHROPIC_API_KEY || null;
34
- case "google-ai":
35
- return (process.env.GOOGLE_AI_API_KEY ||
36
- process.env.GOOGLE_GENERATIVE_AI_API_KEY ||
37
- null);
38
- case "azure":
39
- return process.env.AZURE_OPENAI_API_KEY || null;
40
- case "huggingface":
41
- return process.env.HUGGINGFACE_API_KEY || process.env.HF_TOKEN || null;
42
- case "mistral":
43
- return process.env.MISTRAL_API_KEY || null;
44
- case "aws":
45
- case "bedrock":
46
- return process.env.AWS_ACCESS_KEY_ID || null;
47
- case "vertex":
48
- // Vertex uses service account JSON, not a simple API key
49
- return (process.env.GOOGLE_APPLICATION_CREDENTIALS ||
50
- process.env.GOOGLE_VERTEX_PROJECT ||
51
- null);
52
- default:
53
- return null;
54
- }
55
- }
56
- /**
57
- * Validate API key format for a specific provider
58
- */
59
- export function validateApiKeyFormat(provider, apiKey) {
60
- const format = API_KEY_FORMATS[provider.toLowerCase()];
61
- if (!format) {
62
- // No format validation available, assume valid if not empty
63
- return apiKey.length > 0;
64
- }
65
- return format.test(apiKey);
66
- }
67
- /**
68
- * Lightweight authentication check using minimal API calls
69
- */
70
- async function validateAuthentication(provider, apiKey) {
71
- const startTime = Date.now();
72
- try {
73
- const result = await defaultTimeoutManager.executeWithTimeout(async () => {
74
- switch (provider.toLowerCase()) {
75
- case "openai":
76
- return await validateOpenAIAuth(apiKey);
77
- case "anthropic":
78
- return await validateAnthropicAuth(apiKey);
79
- case "google-ai":
80
- return await validateGoogleAIAuth(apiKey);
81
- case "huggingface":
82
- return await validateHuggingFaceAuth(apiKey);
83
- case "mistral":
84
- return await validateMistralAuth(apiKey);
85
- case "azure":
86
- return await validateAzureAuth(apiKey);
87
- case "bedrock":
88
- case "aws":
89
- return await validateBedrockAuth(apiKey);
90
- case "vertex":
91
- return await validateVertexAuth(apiKey);
92
- default:
93
- return {
94
- success: false,
95
- error: "Validation not implemented for this provider",
96
- errorType: "unknown",
97
- };
98
- }
99
- }, {
100
- operation: `auth-check-${provider}`,
101
- timeout: 10000, // 10 second timeout for auth checks
102
- retryOnTimeout: false,
103
- });
104
- if (result.success && result.data) {
105
- return {
106
- ...result.data,
107
- responseTime: Date.now() - startTime,
108
- };
109
- }
110
- else {
111
- return {
112
- success: false,
113
- error: result.error?.message || "Authentication check failed",
114
- errorType: "network",
115
- responseTime: Date.now() - startTime,
116
- };
117
- }
118
- }
119
- catch (error) {
120
- return {
121
- success: false,
122
- error: error instanceof Error ? error.message : String(error),
123
- errorType: "unknown",
124
- responseTime: Date.now() - startTime,
125
- };
126
- }
127
- }
128
- /**
129
- * OpenAI authentication validation using models endpoint
130
- */
131
- async function validateOpenAIAuth(apiKey) {
132
- const response = await fetch("https://api.openai.com/v1/models", {
133
- method: "GET",
134
- headers: {
135
- Authorization: `Bearer ${apiKey}`,
136
- "User-Agent": "NeuroLink-CLI/4.1.1",
137
- },
138
- });
139
- if (response.ok) {
140
- return { success: true };
141
- }
142
- else if (response.status === 401) {
143
- return {
144
- success: false,
145
- error: "Invalid API key",
146
- errorType: "auth",
147
- };
148
- }
149
- else if (response.status === 429) {
150
- return {
151
- success: false,
152
- error: "Rate limit exceeded",
153
- errorType: "quota",
154
- };
155
- }
156
- else {
157
- const error = await response.text();
158
- return {
159
- success: false,
160
- error: `API error: ${response.status}`,
161
- errorType: "network",
162
- };
163
- }
164
- }
165
- /**
166
- * Anthropic authentication validation using messages endpoint (minimal)
167
- */
168
- async function validateAnthropicAuth(apiKey) {
169
- // Use a minimal message request to check auth
170
- const response = await fetch("https://api.anthropic.com/v1/messages", {
171
- method: "POST",
172
- headers: {
173
- "Content-Type": "application/json",
174
- "x-api-key": apiKey,
175
- "anthropic-version": "2023-06-01",
176
- "User-Agent": "NeuroLink-CLI/4.1.1",
177
- },
178
- body: JSON.stringify({
179
- model: "claude-3-haiku-20240307",
180
- max_tokens: 1,
181
- messages: [{ role: "user", content: "test" }],
182
- }),
183
- });
184
- if (response.ok) {
185
- return { success: true };
186
- }
187
- else if (response.status === 401) {
188
- return {
189
- success: false,
190
- error: "Invalid API key",
191
- errorType: "auth",
192
- };
193
- }
194
- else if (response.status === 429) {
195
- return {
196
- success: false,
197
- error: "Rate limit exceeded",
198
- errorType: "quota",
199
- };
200
- }
201
- else {
202
- return {
203
- success: false,
204
- error: `API error: ${response.status}`,
205
- errorType: "network",
206
- };
207
- }
208
- }
209
- /**
210
- * Google AI authentication validation
211
- */
212
- async function validateGoogleAIAuth(apiKey) {
213
- // Use the models endpoint for lightweight validation
214
- const response = await fetch(`https://generativelanguage.googleapis.com/v1beta/models?key=${apiKey}`, {
215
- method: "GET",
216
- headers: {
217
- "User-Agent": "NeuroLink-CLI/4.1.1",
218
- },
219
- });
220
- if (response.ok) {
221
- return { success: true };
222
- }
223
- else if (response.status === 400 || response.status === 401) {
224
- return {
225
- success: false,
226
- error: "Invalid API key",
227
- errorType: "auth",
228
- };
229
- }
230
- else if (response.status === 429) {
231
- return {
232
- success: false,
233
- error: "Rate limit exceeded",
234
- errorType: "quota",
235
- };
236
- }
237
- else {
238
- return {
239
- success: false,
240
- error: `API error: ${response.status}`,
241
- errorType: "network",
242
- };
243
- }
244
- }
245
- /**
246
- * HuggingFace authentication validation
247
- */
248
- async function validateHuggingFaceAuth(apiKey) {
249
- const response = await fetch("https://huggingface.co/api/whoami", {
250
- method: "GET",
251
- headers: {
252
- Authorization: `Bearer ${apiKey}`,
253
- "User-Agent": "NeuroLink-CLI/4.1.1",
254
- },
255
- });
256
- if (response.ok) {
257
- return { success: true };
258
- }
259
- else if (response.status === 401) {
260
- return {
261
- success: false,
262
- error: "Invalid API key",
263
- errorType: "auth",
264
- };
265
- }
266
- else {
267
- return {
268
- success: false,
269
- error: `API error: ${response.status}`,
270
- errorType: "network",
271
- };
272
- }
273
- }
274
- /**
275
- * Mistral authentication validation
276
- */
277
- async function validateMistralAuth(apiKey) {
278
- const response = await fetch("https://api.mistral.ai/v1/models", {
279
- method: "GET",
280
- headers: {
281
- Authorization: `Bearer ${apiKey}`,
282
- "User-Agent": "NeuroLink-CLI/4.1.1",
283
- },
284
- });
285
- if (response.ok) {
286
- return { success: true };
287
- }
288
- else if (response.status === 401) {
289
- return {
290
- success: false,
291
- error: "Invalid API key",
292
- errorType: "auth",
293
- };
294
- }
295
- else if (response.status === 429) {
296
- return {
297
- success: false,
298
- error: "Rate limit exceeded",
299
- errorType: "quota",
300
- };
301
- }
302
- else {
303
- return {
304
- success: false,
305
- error: `API error: ${response.status}`,
306
- errorType: "network",
307
- };
308
- }
309
- }
310
- /**
311
- * Azure OpenAI authentication validation
312
- */
313
- async function validateAzureAuth(apiKey) {
314
- // Azure validation is more complex as it requires endpoint URL
315
- // For now, we can only validate format and basic connectivity
316
- const endpoint = process.env.AZURE_OPENAI_ENDPOINT;
317
- if (!endpoint) {
318
- return {
319
- success: false,
320
- error: "AZURE_OPENAI_ENDPOINT not configured",
321
- errorType: "config",
322
- };
323
- }
324
- // Try to validate with a models call
325
- const response = await fetch(`${endpoint}/openai/models?api-version=2024-02-01`, {
326
- method: "GET",
327
- headers: {
328
- "api-key": apiKey,
329
- "User-Agent": "NeuroLink-CLI/4.1.1",
330
- },
331
- });
332
- if (response.ok) {
333
- return { success: true };
334
- }
335
- else if (response.status === 401) {
336
- return {
337
- success: false,
338
- error: "Invalid API key",
339
- errorType: "auth",
340
- };
341
- }
342
- else if (response.status === 429) {
343
- return {
344
- success: false,
345
- error: "Rate limit exceeded",
346
- errorType: "quota",
347
- };
348
- }
349
- else {
350
- return {
351
- success: false,
352
- error: `API error: ${response.status}`,
353
- errorType: "network",
354
- };
355
- }
356
- }
357
- /**
358
- * AWS Bedrock authentication validation
359
- */
360
- async function validateBedrockAuth(accessKeyId) {
361
- // Check if required AWS environment variables are present
362
- const secretKey = process.env.AWS_SECRET_ACCESS_KEY;
363
- const region = process.env.AWS_REGION || process.env.AWS_DEFAULT_REGION || "us-east-1";
364
- if (!secretKey) {
365
- return {
366
- success: false,
367
- error: "AWS_SECRET_ACCESS_KEY not configured",
368
- errorType: "config",
369
- };
370
- }
371
- // For Bedrock, we'll do a lightweight check using STS GetCallerIdentity
372
- // This validates AWS credentials without making actual model calls
373
- try {
374
- // This is a simplified check - in a real implementation, you'd use AWS SDK
375
- // For now, we'll just validate that the access key format is correct
376
- const accessKeyPattern = /^AKIA[0-9A-Z]{16}$|^ASIA[0-9A-Z]{16}$/;
377
- if (!accessKeyPattern.test(accessKeyId)) {
378
- return {
379
- success: false,
380
- error: "Invalid AWS Access Key ID format",
381
- errorType: "format",
382
- };
383
- }
384
- // Return success for format validation - actual AWS auth would require SDK
385
- return { success: true };
386
- }
387
- catch (error) {
388
- return {
389
- success: false,
390
- error: "AWS credentials validation failed",
391
- errorType: "auth",
392
- };
393
- }
394
- }
395
- /**
396
- * Google Vertex AI authentication validation
397
- */
398
- async function validateVertexAuth(credentialPath) {
399
- // Vertex AI uses service account JSON files or Application Default Credentials
400
- try {
401
- if (credentialPath && credentialPath.endsWith(".json")) {
402
- // Check if the service account file exists and is valid JSON
403
- const fs = await import("fs");
404
- if (!fs.existsSync(credentialPath)) {
405
- return {
406
- success: false,
407
- error: "Service account file not found",
408
- errorType: "config",
409
- };
410
- }
411
- try {
412
- const serviceAccount = JSON.parse(fs.readFileSync(credentialPath, "utf8"));
413
- if (!serviceAccount.type || serviceAccount.type !== "service_account") {
414
- return {
415
- success: false,
416
- error: "Invalid service account file format",
417
- errorType: "format",
418
- };
419
- }
420
- return { success: true };
421
- }
422
- catch {
423
- return {
424
- success: false,
425
- error: "Invalid service account JSON format",
426
- errorType: "format",
427
- };
428
- }
429
- }
430
- else if (process.env.GOOGLE_VERTEX_PROJECT) {
431
- // If project ID is configured, assume ADC is being used
432
- return { success: true };
433
- }
434
- else {
435
- return {
436
- success: false,
437
- error: "No valid Vertex AI credentials found",
438
- errorType: "config",
439
- };
440
- }
441
- }
442
- catch (error) {
443
- return {
444
- success: false,
445
- error: "Vertex AI credentials validation failed",
446
- errorType: "auth",
447
- };
448
- }
449
- }
450
- /**
451
- * Special validation for Ollama (local service)
452
- */
453
- async function validateOllamaAvailability() {
454
- try {
455
- const result = await defaultTimeoutManager.executeWithTimeout(async () => {
456
- const response = await fetch("http://localhost:11434/api/tags", {
457
- method: "GET",
458
- });
459
- if (!response.ok) {
460
- return { available: false, error: "Ollama service not responding" };
461
- }
462
- const data = await response.json();
463
- const models = data.models || [];
464
- return {
465
- available: true,
466
- models: models.map((m) => m.name),
467
- hasModels: models.length > 0,
468
- };
469
- }, {
470
- operation: "ollama-check",
471
- timeout: 5000,
472
- });
473
- if (result.success && result.data) {
474
- const { available, models, hasModels, error } = result.data;
475
- return {
476
- configured: true,
477
- formatValid: true,
478
- authenticated: available,
479
- available: available && (hasModels || false),
480
- error: !available
481
- ? error
482
- : !hasModels
483
- ? 'No models installed. Run "ollama pull <model-name>"'
484
- : undefined,
485
- errorType: !available ? "network" : !hasModels ? "config" : undefined,
486
- responseTime: result.executionTime,
487
- details: { models, modelCount: models?.length || 0 },
488
- };
489
- }
490
- else {
491
- return {
492
- configured: true,
493
- formatValid: true,
494
- authenticated: false,
495
- available: false,
496
- error: 'Ollama service not running. Start with "ollama serve"',
497
- errorType: "network",
498
- responseTime: result.executionTime,
499
- };
500
- }
501
- }
502
- catch (error) {
503
- return {
504
- configured: true,
505
- formatValid: true,
506
- authenticated: false,
507
- available: false,
508
- error: "Failed to check Ollama service",
509
- errorType: "network",
510
- };
511
- }
512
- }
513
- /**
514
- * Comprehensive provider validation that prevents false positives
515
- */
516
- export async function validateProvider(provider) {
517
- // Special case for Ollama (no API key required)
518
- if (provider.toLowerCase() === "ollama") {
519
- return await validateOllamaAvailability();
520
- }
521
- // Step 1: Check if provider environment variables are configured
522
- const configured = hasProviderEnvVars(provider);
523
- if (!configured) {
524
- return {
525
- configured: false,
526
- formatValid: false,
527
- authenticated: false,
528
- available: false,
529
- error: "Missing required environment variables",
530
- errorType: "config",
531
- };
532
- }
533
- // Step 2: Get and validate API key format
534
- const apiKey = getProviderApiKey(provider);
535
- if (!apiKey) {
536
- return {
537
- configured: false,
538
- formatValid: false,
539
- authenticated: false,
540
- available: false,
541
- error: "API key not found in environment",
542
- errorType: "config",
543
- };
544
- }
545
- const formatValid = validateApiKeyFormat(provider, apiKey);
546
- if (!formatValid) {
547
- return {
548
- configured: true,
549
- formatValid: false,
550
- authenticated: false,
551
- available: false,
552
- error: "API key format is invalid",
553
- errorType: "format",
554
- };
555
- }
556
- // Step 3: Perform lightweight authentication check
557
- const authResult = await validateAuthentication(provider, apiKey);
558
- return {
559
- configured: true,
560
- formatValid: true,
561
- authenticated: authResult.success,
562
- available: authResult.success,
563
- error: authResult.error,
564
- errorType: authResult.errorType,
565
- responseTime: authResult.responseTime,
566
- };
567
- }
568
- /**
569
- * Batch validate multiple providers efficiently
570
- */
571
- export async function validateProviders(providers) {
572
- const results = {};
573
- // 🔧 FIX: Add timeout handling for provider validation
574
- const validationPromises = providers.map(async (provider) => {
575
- const timeoutPromise = new Promise((_, reject) => setTimeout(() => reject(new Error("Timeout")), 5000));
576
- try {
577
- const result = await Promise.race([
578
- validateProvider(provider),
579
- timeoutPromise,
580
- ]);
581
- return { provider, result };
582
- }
583
- catch (error) {
584
- return {
585
- provider,
586
- result: {
587
- configured: false,
588
- formatValid: false,
589
- authenticated: false,
590
- available: false,
591
- error: error instanceof Error ? error.message : "Timeout",
592
- errorType: "network",
593
- },
594
- };
595
- }
596
- });
597
- const validationResults = await Promise.allSettled(validationPromises);
598
- validationResults.forEach((promiseResult, index) => {
599
- const provider = providers[index];
600
- if (promiseResult.status === "fulfilled") {
601
- results[provider] = promiseResult.value.result;
602
- }
603
- else {
604
- results[provider] = {
605
- configured: false,
606
- formatValid: false,
607
- authenticated: false,
608
- available: false,
609
- error: "Validation failed: " + promiseResult.reason,
610
- errorType: "unknown",
611
- };
612
- }
613
- });
614
- return results;
615
- }
616
- /**
617
- * Check if provider validation should be cached (to avoid rate limits)
618
- */
619
- export function shouldCacheValidation(result) {
620
- // Cache successful validations and format errors (don't change often)
621
- // Don't cache network errors or quota errors (can be temporary)
622
- return (result.available ||
623
- result.errorType === "format" ||
624
- result.errorType === "config");
625
- }
@@ -1,8 +0,0 @@
1
- /**
2
- * Asynchronously get the best available provider based on real-time checks.
3
- * This function performs actual authentication and availability tests.
4
- *
5
- * @param requestedProvider - Optional preferred provider name
6
- * @returns The best provider name to use
7
- */
8
- export declare function getBestProvider(requestedProvider?: string): Promise<string>;