@juspay/neurolink 7.33.1 → 7.33.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/constants/index.d.ts +192 -0
- package/dist/constants/index.js +195 -0
- package/dist/constants/performance.d.ts +366 -0
- package/dist/constants/performance.js +389 -0
- package/dist/constants/retry.d.ts +224 -0
- package/dist/constants/retry.js +266 -0
- package/dist/constants/timeouts.d.ts +225 -0
- package/dist/constants/timeouts.js +182 -0
- package/dist/constants/tokens.d.ts +234 -0
- package/dist/constants/tokens.js +314 -0
- package/dist/core/types.d.ts +268 -0
- package/dist/core/types.js +153 -0
- package/dist/lib/constants/index.d.ts +192 -0
- package/dist/lib/constants/index.js +195 -0
- package/dist/lib/constants/performance.d.ts +366 -0
- package/dist/lib/constants/performance.js +389 -0
- package/dist/lib/constants/retry.d.ts +224 -0
- package/dist/lib/constants/retry.js +266 -0
- package/dist/lib/constants/timeouts.d.ts +225 -0
- package/dist/lib/constants/timeouts.js +182 -0
- package/dist/lib/constants/tokens.d.ts +234 -0
- package/dist/lib/constants/tokens.js +314 -0
- package/dist/lib/core/types.d.ts +268 -0
- package/dist/lib/core/types.js +153 -0
- package/dist/lib/mcp/externalServerManager.d.ts +18 -3
- package/dist/lib/mcp/externalServerManager.js +125 -3
- package/dist/lib/models/modelRegistry.d.ts +1 -1
- package/dist/lib/models/modelRegistry.js +63 -37
- package/dist/lib/neurolink.d.ts +1 -1
- package/dist/lib/neurolink.js +38 -36
- package/dist/lib/providers/azureOpenai.d.ts +1 -1
- package/dist/lib/providers/azureOpenai.js +2 -1
- package/dist/lib/utils/providerConfig.d.ts +25 -0
- package/dist/lib/utils/providerConfig.js +24 -3
- package/dist/lib/utils/providerHealth.d.ts +1 -1
- package/dist/lib/utils/providerHealth.js +40 -33
- package/dist/lib/utils/providerSetupMessages.js +7 -6
- package/dist/lib/utils/providerUtils.js +16 -24
- package/dist/mcp/externalServerManager.d.ts +18 -3
- package/dist/mcp/externalServerManager.js +125 -3
- package/dist/models/modelRegistry.d.ts +1 -1
- package/dist/models/modelRegistry.js +63 -37
- package/dist/neurolink.d.ts +1 -1
- package/dist/neurolink.js +38 -36
- package/dist/providers/azureOpenai.d.ts +1 -1
- package/dist/providers/azureOpenai.js +2 -1
- package/dist/utils/providerConfig.d.ts +25 -0
- package/dist/utils/providerConfig.js +24 -3
- package/dist/utils/providerHealth.d.ts +1 -1
- package/dist/utils/providerHealth.js +40 -33
- package/dist/utils/providerSetupMessages.js +7 -6
- package/dist/utils/providerUtils.js +16 -24
- package/package.json +1 -1
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
* Provides centralized model data for models command system
|
|
4
4
|
* Part of Phase 4.1 - Models Command System
|
|
5
5
|
*/
|
|
6
|
-
import { AIProviderName } from "../types
|
|
6
|
+
import { AIProviderName, OpenAIModels, GoogleAIModels, AnthropicModels, DEFAULT_MODEL_ALIASES, } from "../core/types.js";
|
|
7
7
|
/**
|
|
8
8
|
* Comprehensive model registry
|
|
9
9
|
*/
|
|
10
10
|
export const MODEL_REGISTRY = {
|
|
11
11
|
// OpenAI Models
|
|
12
|
-
|
|
13
|
-
id:
|
|
12
|
+
[OpenAIModels.GPT_4O]: {
|
|
13
|
+
id: OpenAIModels.GPT_4O,
|
|
14
14
|
name: "GPT-4 Omni",
|
|
15
15
|
provider: AIProviderName.OPENAI,
|
|
16
16
|
description: "Most capable OpenAI model with vision and advanced reasoning",
|
|
@@ -53,8 +53,8 @@ export const MODEL_REGISTRY = {
|
|
|
53
53
|
releaseDate: "2024-05-13",
|
|
54
54
|
category: "general",
|
|
55
55
|
},
|
|
56
|
-
|
|
57
|
-
id:
|
|
56
|
+
[OpenAIModels.GPT_4O_MINI]: {
|
|
57
|
+
id: OpenAIModels.GPT_4O_MINI,
|
|
58
58
|
name: "GPT-4 Omni Mini",
|
|
59
59
|
provider: AIProviderName.OPENAI,
|
|
60
60
|
description: "Fast and cost-effective model with strong performance",
|
|
@@ -98,8 +98,8 @@ export const MODEL_REGISTRY = {
|
|
|
98
98
|
category: "general",
|
|
99
99
|
},
|
|
100
100
|
// Google AI Studio Models
|
|
101
|
-
|
|
102
|
-
id:
|
|
101
|
+
[GoogleAIModels.GEMINI_2_5_PRO]: {
|
|
102
|
+
id: GoogleAIModels.GEMINI_2_5_PRO,
|
|
103
103
|
name: "Gemini 2.5 Pro",
|
|
104
104
|
provider: AIProviderName.GOOGLE_AI,
|
|
105
105
|
description: "Google's most capable multimodal model with large context window",
|
|
@@ -142,8 +142,8 @@ export const MODEL_REGISTRY = {
|
|
|
142
142
|
releaseDate: "2024-12-11",
|
|
143
143
|
category: "reasoning",
|
|
144
144
|
},
|
|
145
|
-
|
|
146
|
-
id:
|
|
145
|
+
[GoogleAIModels.GEMINI_2_5_FLASH]: {
|
|
146
|
+
id: GoogleAIModels.GEMINI_2_5_FLASH,
|
|
147
147
|
name: "Gemini 2.5 Flash",
|
|
148
148
|
provider: AIProviderName.GOOGLE_AI,
|
|
149
149
|
description: "Fast and efficient multimodal model with large context",
|
|
@@ -187,8 +187,8 @@ export const MODEL_REGISTRY = {
|
|
|
187
187
|
category: "general",
|
|
188
188
|
},
|
|
189
189
|
// Anthropic Models
|
|
190
|
-
|
|
191
|
-
id:
|
|
190
|
+
[AnthropicModels.CLAUDE_3_5_SONNET]: {
|
|
191
|
+
id: AnthropicModels.CLAUDE_3_5_SONNET,
|
|
192
192
|
name: "Claude 3.5 Sonnet",
|
|
193
193
|
provider: AIProviderName.ANTHROPIC,
|
|
194
194
|
description: "Anthropic's most capable model with excellent reasoning and coding",
|
|
@@ -236,8 +236,8 @@ export const MODEL_REGISTRY = {
|
|
|
236
236
|
releaseDate: "2024-10-22",
|
|
237
237
|
category: "coding",
|
|
238
238
|
},
|
|
239
|
-
|
|
240
|
-
id:
|
|
239
|
+
[AnthropicModels.CLAUDE_3_5_HAIKU]: {
|
|
240
|
+
id: AnthropicModels.CLAUDE_3_5_HAIKU,
|
|
241
241
|
name: "Claude 3.5 Haiku",
|
|
242
242
|
provider: AIProviderName.ANTHROPIC,
|
|
243
243
|
description: "Fast and efficient Claude model for quick tasks",
|
|
@@ -380,39 +380,65 @@ Object.values(MODEL_REGISTRY).forEach((model) => {
|
|
|
380
380
|
MODEL_ALIASES[alias.toLowerCase()] = model.id;
|
|
381
381
|
});
|
|
382
382
|
});
|
|
383
|
-
//
|
|
384
|
-
Object.
|
|
385
|
-
|
|
386
|
-
fastest: "gpt-4o-mini",
|
|
387
|
-
cheapest: "gemini-2.5-flash",
|
|
388
|
-
"best-coding": "claude-3-5-sonnet-20241022",
|
|
389
|
-
"best-analysis": "gemini-2.5-pro",
|
|
390
|
-
"best-creative": "claude-3-5-sonnet-20241022",
|
|
391
|
-
"best-value": "gemini-2.5-flash",
|
|
392
|
-
local: "llama3.2:latest",
|
|
383
|
+
// Pull canonical alias recommendations from core/types
|
|
384
|
+
Object.entries(DEFAULT_MODEL_ALIASES).forEach(([k, v]) => {
|
|
385
|
+
MODEL_ALIASES[k.toLowerCase().replace(/_/g, "-")] = v;
|
|
393
386
|
});
|
|
387
|
+
MODEL_ALIASES.local = "llama3.2:latest";
|
|
394
388
|
/**
|
|
395
389
|
* Use case to model mappings
|
|
396
390
|
*/
|
|
397
391
|
export const USE_CASE_RECOMMENDATIONS = {
|
|
398
|
-
coding: [
|
|
399
|
-
|
|
400
|
-
|
|
392
|
+
coding: [
|
|
393
|
+
AnthropicModels.CLAUDE_3_5_SONNET,
|
|
394
|
+
OpenAIModels.GPT_4O,
|
|
395
|
+
GoogleAIModels.GEMINI_2_5_PRO,
|
|
396
|
+
],
|
|
397
|
+
creative: [
|
|
398
|
+
AnthropicModels.CLAUDE_3_5_SONNET,
|
|
399
|
+
OpenAIModels.GPT_4O,
|
|
400
|
+
GoogleAIModels.GEMINI_2_5_PRO,
|
|
401
|
+
],
|
|
402
|
+
analysis: [
|
|
403
|
+
GoogleAIModels.GEMINI_2_5_PRO,
|
|
404
|
+
AnthropicModels.CLAUDE_3_5_SONNET,
|
|
405
|
+
OpenAIModels.GPT_4O,
|
|
406
|
+
],
|
|
401
407
|
conversation: [
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
408
|
+
OpenAIModels.GPT_4O,
|
|
409
|
+
AnthropicModels.CLAUDE_3_5_SONNET,
|
|
410
|
+
AnthropicModels.CLAUDE_3_5_HAIKU,
|
|
411
|
+
],
|
|
412
|
+
reasoning: [
|
|
413
|
+
AnthropicModels.CLAUDE_3_5_SONNET,
|
|
414
|
+
GoogleAIModels.GEMINI_2_5_PRO,
|
|
415
|
+
OpenAIModels.GPT_4O,
|
|
416
|
+
],
|
|
417
|
+
translation: [
|
|
418
|
+
GoogleAIModels.GEMINI_2_5_PRO,
|
|
419
|
+
OpenAIModels.GPT_4O,
|
|
420
|
+
AnthropicModels.CLAUDE_3_5_HAIKU,
|
|
405
421
|
],
|
|
406
|
-
reasoning: ["claude-3-5-sonnet-20241022", "gemini-2.5-pro", "gpt-4o"],
|
|
407
|
-
translation: ["gemini-2.5-pro", "gpt-4o", "claude-3-5-haiku-20241022"],
|
|
408
422
|
summarization: [
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
423
|
+
GoogleAIModels.GEMINI_2_5_FLASH,
|
|
424
|
+
OpenAIModels.GPT_4O_MINI,
|
|
425
|
+
AnthropicModels.CLAUDE_3_5_HAIKU,
|
|
426
|
+
],
|
|
427
|
+
"cost-effective": [
|
|
428
|
+
GoogleAIModels.GEMINI_2_5_FLASH,
|
|
429
|
+
OpenAIModels.GPT_4O_MINI,
|
|
430
|
+
"mistral-small-latest",
|
|
431
|
+
],
|
|
432
|
+
"high-quality": [
|
|
433
|
+
AnthropicModels.CLAUDE_3_5_SONNET,
|
|
434
|
+
OpenAIModels.GPT_4O,
|
|
435
|
+
GoogleAIModels.GEMINI_2_5_PRO,
|
|
436
|
+
],
|
|
437
|
+
fast: [
|
|
438
|
+
OpenAIModels.GPT_4O_MINI,
|
|
439
|
+
GoogleAIModels.GEMINI_2_5_FLASH,
|
|
440
|
+
AnthropicModels.CLAUDE_3_5_HAIKU,
|
|
412
441
|
],
|
|
413
|
-
"cost-effective": ["gemini-2.5-flash", "gpt-4o-mini", "mistral-small-latest"],
|
|
414
|
-
"high-quality": ["claude-3-5-sonnet-20241022", "gpt-4o", "gemini-2.5-pro"],
|
|
415
|
-
fast: ["gpt-4o-mini", "gemini-2.5-flash", "claude-3-5-haiku-20241022"],
|
|
416
442
|
};
|
|
417
443
|
/**
|
|
418
444
|
* Get all models
|
package/dist/lib/neurolink.d.ts
CHANGED
|
@@ -146,7 +146,7 @@ export declare class NeuroLink {
|
|
|
146
146
|
*/
|
|
147
147
|
private registerDirectToolsServerInternal;
|
|
148
148
|
/**
|
|
149
|
-
* Load MCP configuration from .mcp-config.json
|
|
149
|
+
* Load MCP configuration from .mcp-config.json with parallel loading for improved performance
|
|
150
150
|
*/
|
|
151
151
|
private loadMCPConfigurationInternal;
|
|
152
152
|
/**
|
package/dist/lib/neurolink.js
CHANGED
|
@@ -16,6 +16,7 @@ catch {
|
|
|
16
16
|
import { AIProviderFactory } from "./core/factory.js";
|
|
17
17
|
import { mcpLogger } from "./utils/logger.js";
|
|
18
18
|
import { SYSTEM_LIMITS } from "./core/constants.js";
|
|
19
|
+
import { NANOSECOND_TO_MS_DIVISOR, MCP_TIMEOUTS, SERVER_CONFIG, TOOL_TIMEOUTS, RETRY_ATTEMPTS, RETRY_DELAYS, CIRCUIT_BREAKER, CIRCUIT_BREAKER_RESET_MS, MEMORY_THRESHOLDS, PROVIDER_TIMEOUTS, PERFORMANCE_THRESHOLDS, } from "./constants/index.js";
|
|
19
20
|
import pLimit from "p-limit";
|
|
20
21
|
import { toolRegistry } from "./mcp/toolRegistry.js";
|
|
21
22
|
import { logger } from "./utils/logger.js";
|
|
@@ -164,7 +165,7 @@ export class NeuroLink {
|
|
|
164
165
|
elapsedMs: Date.now() - constructorStartTime,
|
|
165
166
|
elapsedNs: (process.hrtime.bigint() - constructorHrTimeStart).toString(),
|
|
166
167
|
registrySetupDurationNs: registrySetupDurationNs.toString(),
|
|
167
|
-
registrySetupDurationMs: Number(registrySetupDurationNs) /
|
|
168
|
+
registrySetupDurationMs: Number(registrySetupDurationNs) / NANOSECOND_TO_MS_DIVISOR,
|
|
168
169
|
enableManualMCP: false,
|
|
169
170
|
message: "ProviderRegistry configured successfully with security settings",
|
|
170
171
|
});
|
|
@@ -179,7 +180,7 @@ export class NeuroLink {
|
|
|
179
180
|
elapsedMs: Date.now() - constructorStartTime,
|
|
180
181
|
elapsedNs: (process.hrtime.bigint() - constructorHrTimeStart).toString(),
|
|
181
182
|
registrySetupDurationNs: registrySetupDurationNs.toString(),
|
|
182
|
-
registrySetupDurationMs: Number(registrySetupDurationNs) /
|
|
183
|
+
registrySetupDurationMs: Number(registrySetupDurationNs) / NANOSECOND_TO_MS_DIVISOR,
|
|
183
184
|
error: error instanceof Error ? error.message : String(error),
|
|
184
185
|
errorName: error instanceof Error ? error.name : "UnknownError",
|
|
185
186
|
errorStack: error instanceof Error ? error.stack : undefined,
|
|
@@ -224,9 +225,9 @@ export class NeuroLink {
|
|
|
224
225
|
elapsedMs: Date.now() - constructorStartTime,
|
|
225
226
|
elapsedNs: (process.hrtime.bigint() - constructorHrTimeStart).toString(),
|
|
226
227
|
memoryInitDurationNs: memoryInitDurationNs.toString(),
|
|
227
|
-
memoryInitDurationMs: Number(memoryInitDurationNs) /
|
|
228
|
+
memoryInitDurationMs: Number(memoryInitDurationNs) / NANOSECOND_TO_MS_DIVISOR,
|
|
228
229
|
memoryManagerCreateDurationNs: memoryManagerCreateDurationNs.toString(),
|
|
229
|
-
memoryManagerCreateDurationMs: Number(memoryManagerCreateDurationNs) /
|
|
230
|
+
memoryManagerCreateDurationMs: Number(memoryManagerCreateDurationNs) / NANOSECOND_TO_MS_DIVISOR,
|
|
230
231
|
finalMemoryConfig: {
|
|
231
232
|
maxSessions: memoryConfig.maxSessions,
|
|
232
233
|
maxTurnsPerSession: memoryConfig.maxTurnsPerSession,
|
|
@@ -245,7 +246,7 @@ export class NeuroLink {
|
|
|
245
246
|
elapsedMs: Date.now() - constructorStartTime,
|
|
246
247
|
elapsedNs: (process.hrtime.bigint() - constructorHrTimeStart).toString(),
|
|
247
248
|
memoryInitDurationNs: memoryInitDurationNs.toString(),
|
|
248
|
-
memoryInitDurationMs: Number(memoryInitDurationNs) /
|
|
249
|
+
memoryInitDurationMs: Number(memoryInitDurationNs) / NANOSECOND_TO_MS_DIVISOR,
|
|
249
250
|
error: error instanceof Error ? error.message : String(error),
|
|
250
251
|
errorName: error instanceof Error ? error.name : "UnknownError",
|
|
251
252
|
errorStack: error instanceof Error ? error.stack : undefined,
|
|
@@ -289,8 +290,8 @@ export class NeuroLink {
|
|
|
289
290
|
elapsedNs: (process.hrtime.bigint() - constructorHrTimeStart).toString(),
|
|
290
291
|
externalServerInitStartTimeNs: externalServerInitStartTime.toString(),
|
|
291
292
|
serverManagerConfig: {
|
|
292
|
-
maxServers:
|
|
293
|
-
defaultTimeout:
|
|
293
|
+
maxServers: SERVER_CONFIG.MAX_MCP_SERVERS,
|
|
294
|
+
defaultTimeout: MCP_TIMEOUTS.EXTERNAL_SERVER_STARTUP_MS,
|
|
294
295
|
enableAutoRestart: true,
|
|
295
296
|
enablePerformanceMonitoring: true,
|
|
296
297
|
},
|
|
@@ -317,7 +318,7 @@ export class NeuroLink {
|
|
|
317
318
|
elapsedMs: Date.now() - constructorStartTime,
|
|
318
319
|
elapsedNs: (process.hrtime.bigint() - constructorHrTimeStart).toString(),
|
|
319
320
|
externalServerInitDurationNs: externalServerInitDurationNs.toString(),
|
|
320
|
-
externalServerInitDurationMs: Number(externalServerInitDurationNs) /
|
|
321
|
+
externalServerInitDurationMs: Number(externalServerInitDurationNs) / NANOSECOND_TO_MS_DIVISOR,
|
|
321
322
|
hasExternalServerManager: !!this.externalServerManager,
|
|
322
323
|
message: "External server manager initialized successfully",
|
|
323
324
|
});
|
|
@@ -333,7 +334,7 @@ export class NeuroLink {
|
|
|
333
334
|
elapsedMs: Date.now() - constructorStartTime,
|
|
334
335
|
elapsedNs: (process.hrtime.bigint() - constructorHrTimeStart).toString(),
|
|
335
336
|
externalServerInitDurationNs: externalServerInitDurationNs.toString(),
|
|
336
|
-
externalServerInitDurationMs: Number(externalServerInitDurationNs) /
|
|
337
|
+
externalServerInitDurationMs: Number(externalServerInitDurationNs) / NANOSECOND_TO_MS_DIVISOR,
|
|
337
338
|
error: error instanceof Error ? error.message : String(error),
|
|
338
339
|
errorName: error instanceof Error ? error.name : "UnknownError",
|
|
339
340
|
errorStack: error instanceof Error ? error.stack : undefined,
|
|
@@ -418,7 +419,7 @@ export class NeuroLink {
|
|
|
418
419
|
elapsedMs: Date.now() - constructorStartTime,
|
|
419
420
|
elapsedNs: (process.hrtime.bigint() - constructorHrTimeStart).toString(),
|
|
420
421
|
eventHandlerSetupDurationNs: eventHandlerSetupDurationNs.toString(),
|
|
421
|
-
eventHandlerSetupDurationMs: Number(eventHandlerSetupDurationNs) /
|
|
422
|
+
eventHandlerSetupDurationMs: Number(eventHandlerSetupDurationNs) / NANOSECOND_TO_MS_DIVISOR,
|
|
422
423
|
eventHandlersCount: 5,
|
|
423
424
|
eventHandlerTypes: [
|
|
424
425
|
"connected",
|
|
@@ -441,7 +442,7 @@ export class NeuroLink {
|
|
|
441
442
|
constructorId,
|
|
442
443
|
timestamp: new Date().toISOString(),
|
|
443
444
|
constructorDurationNs: constructorDurationNs.toString(),
|
|
444
|
-
constructorDurationMs: Number(constructorDurationNs) /
|
|
445
|
+
constructorDurationMs: Number(constructorDurationNs) / NANOSECOND_TO_MS_DIVISOR,
|
|
445
446
|
totalElapsedMs: Date.now() - constructorStartTime,
|
|
446
447
|
finalState: {
|
|
447
448
|
hasConversationMemory: !!this.conversationMemory,
|
|
@@ -542,7 +543,7 @@ export class NeuroLink {
|
|
|
542
543
|
elapsedMs: Date.now() - mcpInitStartTime,
|
|
543
544
|
elapsedNs: (process.hrtime.bigint() - mcpInitHrTimeStart).toString(),
|
|
544
545
|
performanceImportDurationNs: performanceImportDurationNs.toString(),
|
|
545
|
-
performanceImportDurationMs: Number(performanceImportDurationNs) /
|
|
546
|
+
performanceImportDurationMs: Number(performanceImportDurationNs) / NANOSECOND_TO_MS_DIVISOR,
|
|
546
547
|
hasMemoryManager: !!MemoryManager,
|
|
547
548
|
message: "MemoryManager imported successfully",
|
|
548
549
|
});
|
|
@@ -558,7 +559,7 @@ export class NeuroLink {
|
|
|
558
559
|
elapsedMs: Date.now() - mcpInitStartTime,
|
|
559
560
|
elapsedNs: (process.hrtime.bigint() - mcpInitHrTimeStart).toString(),
|
|
560
561
|
performanceImportDurationNs: performanceImportDurationNs.toString(),
|
|
561
|
-
performanceImportDurationMs: Number(performanceImportDurationNs) /
|
|
562
|
+
performanceImportDurationMs: Number(performanceImportDurationNs) / NANOSECOND_TO_MS_DIVISOR,
|
|
562
563
|
error: error instanceof Error ? error.message : String(error),
|
|
563
564
|
errorName: error instanceof Error ? error.name : "UnknownError",
|
|
564
565
|
message: "MemoryManager import failed - continuing without performance tracking",
|
|
@@ -590,7 +591,7 @@ export class NeuroLink {
|
|
|
590
591
|
*/
|
|
591
592
|
async initializeToolRegistryInternal(mcpInitId, mcpInitStartTime, mcpInitHrTimeStart) {
|
|
592
593
|
const toolRegistryStartTime = process.hrtime.bigint();
|
|
593
|
-
const initTimeout =
|
|
594
|
+
const initTimeout = MCP_TIMEOUTS.INITIALIZATION_MS;
|
|
594
595
|
logger.debug(`[NeuroLink] ⏱️ LOG_POINT_M007_TOOL_REGISTRY_TIMEOUT_SETUP`, {
|
|
595
596
|
logPoint: "M007_TOOL_REGISTRY_TIMEOUT_SETUP",
|
|
596
597
|
mcpInitId,
|
|
@@ -616,7 +617,7 @@ export class NeuroLink {
|
|
|
616
617
|
elapsedMs: Date.now() - mcpInitStartTime,
|
|
617
618
|
elapsedNs: (process.hrtime.bigint() - mcpInitHrTimeStart).toString(),
|
|
618
619
|
toolRegistryDurationNs: toolRegistryDurationNs.toString(),
|
|
619
|
-
toolRegistryDurationMs: Number(toolRegistryDurationNs) /
|
|
620
|
+
toolRegistryDurationMs: Number(toolRegistryDurationNs) / NANOSECOND_TO_MS_DIVISOR,
|
|
620
621
|
message: "Tool registry initialization completed within timeout",
|
|
621
622
|
});
|
|
622
623
|
}
|
|
@@ -644,7 +645,7 @@ export class NeuroLink {
|
|
|
644
645
|
elapsedMs: Date.now() - mcpInitStartTime,
|
|
645
646
|
elapsedNs: (process.hrtime.bigint() - mcpInitHrTimeStart).toString(),
|
|
646
647
|
providerRegistryDurationNs: providerRegistryDurationNs.toString(),
|
|
647
|
-
providerRegistryDurationMs: Number(providerRegistryDurationNs) /
|
|
648
|
+
providerRegistryDurationMs: Number(providerRegistryDurationNs) / NANOSECOND_TO_MS_DIVISOR,
|
|
648
649
|
message: "Provider registry registration completed successfully",
|
|
649
650
|
});
|
|
650
651
|
}
|
|
@@ -674,7 +675,7 @@ export class NeuroLink {
|
|
|
674
675
|
elapsedMs: Date.now() - mcpInitStartTime,
|
|
675
676
|
elapsedNs: (process.hrtime.bigint() - mcpInitHrTimeStart).toString(),
|
|
676
677
|
directToolsDurationNs: directToolsDurationNs.toString(),
|
|
677
|
-
directToolsDurationMs: Number(directToolsDurationNs) /
|
|
678
|
+
directToolsDurationMs: Number(directToolsDurationNs) / NANOSECOND_TO_MS_DIVISOR,
|
|
678
679
|
serverId: "neurolink-direct",
|
|
679
680
|
message: "Direct tools server registered successfully",
|
|
680
681
|
});
|
|
@@ -692,7 +693,7 @@ export class NeuroLink {
|
|
|
692
693
|
elapsedMs: Date.now() - mcpInitStartTime,
|
|
693
694
|
elapsedNs: (process.hrtime.bigint() - mcpInitHrTimeStart).toString(),
|
|
694
695
|
directToolsDurationNs: directToolsDurationNs.toString(),
|
|
695
|
-
directToolsDurationMs: Number(directToolsDurationNs) /
|
|
696
|
+
directToolsDurationMs: Number(directToolsDurationNs) / NANOSECOND_TO_MS_DIVISOR,
|
|
696
697
|
error: error instanceof Error ? error.message : String(error),
|
|
697
698
|
errorName: error instanceof Error ? error.name : "UnknownError",
|
|
698
699
|
errorStack: error instanceof Error ? error.stack : undefined,
|
|
@@ -705,7 +706,7 @@ export class NeuroLink {
|
|
|
705
706
|
}
|
|
706
707
|
}
|
|
707
708
|
/**
|
|
708
|
-
* Load MCP configuration from .mcp-config.json
|
|
709
|
+
* Load MCP configuration from .mcp-config.json with parallel loading for improved performance
|
|
709
710
|
*/
|
|
710
711
|
async loadMCPConfigurationInternal(mcpInitId, mcpInitStartTime, mcpInitHrTimeStart) {
|
|
711
712
|
const mcpConfigStartTime = process.hrtime.bigint();
|
|
@@ -720,7 +721,8 @@ export class NeuroLink {
|
|
|
720
721
|
message: "Starting MCP configuration loading from .mcp-config.json",
|
|
721
722
|
});
|
|
722
723
|
try {
|
|
723
|
-
const configResult = await this.externalServerManager.loadMCPConfiguration(
|
|
724
|
+
const configResult = await this.externalServerManager.loadMCPConfiguration(undefined, // Use default config path
|
|
725
|
+
{ parallel: true });
|
|
724
726
|
const mcpConfigSuccessTime = process.hrtime.bigint();
|
|
725
727
|
const mcpConfigDurationNs = mcpConfigSuccessTime - mcpConfigStartTime;
|
|
726
728
|
logger.debug(`[NeuroLink] ✅ LOG_POINT_M015_MCP_CONFIG_SUCCESS`, {
|
|
@@ -730,7 +732,7 @@ export class NeuroLink {
|
|
|
730
732
|
elapsedMs: Date.now() - mcpInitStartTime,
|
|
731
733
|
elapsedNs: (process.hrtime.bigint() - mcpInitHrTimeStart).toString(),
|
|
732
734
|
mcpConfigDurationNs: mcpConfigDurationNs.toString(),
|
|
733
|
-
mcpConfigDurationMs: Number(mcpConfigDurationNs) /
|
|
735
|
+
mcpConfigDurationMs: Number(mcpConfigDurationNs) / NANOSECOND_TO_MS_DIVISOR,
|
|
734
736
|
serversLoaded: configResult.serversLoaded,
|
|
735
737
|
errorsCount: configResult.errors.length,
|
|
736
738
|
configResult: {
|
|
@@ -773,7 +775,7 @@ export class NeuroLink {
|
|
|
773
775
|
initTime: `${initTime}ms`,
|
|
774
776
|
memoryUsed: `${memoryDelta}MB`,
|
|
775
777
|
});
|
|
776
|
-
if (memoryDelta >
|
|
778
|
+
if (memoryDelta > MEMORY_THRESHOLDS.MODERATE_USAGE_MB) {
|
|
777
779
|
mcpLogger.debug("💡 Memory cleanup suggestion: MCP initialization used significant memory. Consider calling MemoryManager.forceGC() after heavy operations.");
|
|
778
780
|
}
|
|
779
781
|
}
|
|
@@ -1119,7 +1121,7 @@ export class NeuroLink {
|
|
|
1119
1121
|
elapsedMs: Date.now() - generateInternalStartTime,
|
|
1120
1122
|
elapsedNs: (process.hrtime.bigint() - generateInternalHrTimeStart).toString(),
|
|
1121
1123
|
conversationMemoryDurationNs: conversationMemoryDurationNs.toString(),
|
|
1122
|
-
conversationMemoryDurationMs: Number(conversationMemoryDurationNs) /
|
|
1124
|
+
conversationMemoryDurationMs: Number(conversationMemoryDurationNs) / NANOSECOND_TO_MS_DIVISOR,
|
|
1123
1125
|
message: "Conversation memory initialization completed successfully",
|
|
1124
1126
|
});
|
|
1125
1127
|
}
|
|
@@ -1164,7 +1166,7 @@ export class NeuroLink {
|
|
|
1164
1166
|
* Perform MCP generation with retry logic
|
|
1165
1167
|
*/
|
|
1166
1168
|
async performMCPGenerationRetries(options, generateInternalId, generateInternalStartTime, generateInternalHrTimeStart, functionTag) {
|
|
1167
|
-
const maxMcpRetries =
|
|
1169
|
+
const maxMcpRetries = RETRY_ATTEMPTS.QUICK;
|
|
1168
1170
|
const mcpRetryLoopStartTime = process.hrtime.bigint();
|
|
1169
1171
|
logger.debug(`[NeuroLink] 🔄 LOG_POINT_G006_MCP_RETRY_LOOP_START`, {
|
|
1170
1172
|
logPoint: "G006_MCP_RETRY_LOOP_START",
|
|
@@ -1206,7 +1208,7 @@ export class NeuroLink {
|
|
|
1206
1208
|
elapsedMs: Date.now() - generateInternalStartTime,
|
|
1207
1209
|
elapsedNs: (process.hrtime.bigint() - generateInternalHrTimeStart).toString(),
|
|
1208
1210
|
mcpAttemptDurationNs: mcpAttemptDurationNs.toString(),
|
|
1209
|
-
mcpAttemptDurationMs: Number(mcpAttemptDurationNs) /
|
|
1211
|
+
mcpAttemptDurationMs: Number(mcpAttemptDurationNs) / NANOSECOND_TO_MS_DIVISOR,
|
|
1210
1212
|
currentAttempt: attempt,
|
|
1211
1213
|
resultAnalysis: {
|
|
1212
1214
|
hasResult: !!mcpResult,
|
|
@@ -1325,7 +1327,7 @@ export class NeuroLink {
|
|
|
1325
1327
|
elapsedMs: Date.now() - tryMCPStartTime,
|
|
1326
1328
|
elapsedNs: (process.hrtime.bigint() - tryMCPHrTimeStart).toString(),
|
|
1327
1329
|
mcpInitCheckDurationNs: mcpInitCheckDurationNs.toString(),
|
|
1328
|
-
mcpInitCheckDurationMs: Number(mcpInitCheckDurationNs) /
|
|
1330
|
+
mcpInitCheckDurationMs: Number(mcpInitCheckDurationNs) / NANOSECOND_TO_MS_DIVISOR,
|
|
1329
1331
|
mcpInitializedAfter: this.mcpInitialized,
|
|
1330
1332
|
initializationSuccessful: this.mcpInitialized,
|
|
1331
1333
|
message: "MCP initialization check completed",
|
|
@@ -1781,7 +1783,7 @@ export class NeuroLink {
|
|
|
1781
1783
|
elapsedMs: Date.now() - startTime,
|
|
1782
1784
|
elapsedNs: (process.hrtime.bigint() - hrTimeStart).toString(),
|
|
1783
1785
|
validationDurationNs: validationDurationNs.toString(),
|
|
1784
|
-
validationDurationMs: Number(validationDurationNs) /
|
|
1786
|
+
validationDurationMs: Number(validationDurationNs) / NANOSECOND_TO_MS_DIVISOR,
|
|
1785
1787
|
validationError: "Stream options must include either input.text or input.audio",
|
|
1786
1788
|
message: "EXHAUSTIVE validation failure analysis with character-level debugging",
|
|
1787
1789
|
});
|
|
@@ -1796,7 +1798,7 @@ export class NeuroLink {
|
|
|
1796
1798
|
elapsedMs: Date.now() - startTime,
|
|
1797
1799
|
elapsedNs: (process.hrtime.bigint() - hrTimeStart).toString(),
|
|
1798
1800
|
validationDurationNs: validationDurationNs.toString(),
|
|
1799
|
-
validationDurationMs: Number(validationDurationNs) /
|
|
1801
|
+
validationDurationMs: Number(validationDurationNs) / NANOSECOND_TO_MS_DIVISOR,
|
|
1800
1802
|
inputTextValid: hasText,
|
|
1801
1803
|
inputAudioPresent: hasAudio,
|
|
1802
1804
|
inputTextLength: hasText ? options.input.text.length : 0,
|
|
@@ -2314,16 +2316,16 @@ export class NeuroLink {
|
|
|
2314
2316
|
this.emitter.emit("tool:start", toolName, params);
|
|
2315
2317
|
// Set default options
|
|
2316
2318
|
const finalOptions = {
|
|
2317
|
-
timeout: options?.timeout ||
|
|
2318
|
-
maxRetries: options?.maxRetries ||
|
|
2319
|
-
retryDelayMs: options?.retryDelayMs ||
|
|
2319
|
+
timeout: options?.timeout || TOOL_TIMEOUTS.EXECUTION_DEFAULT_MS, // 30 second default timeout
|
|
2320
|
+
maxRetries: options?.maxRetries || RETRY_ATTEMPTS.DEFAULT, // Default 2 retries for retriable errors
|
|
2321
|
+
retryDelayMs: options?.retryDelayMs || RETRY_DELAYS.BASE_MS, // 1 second delay between retries
|
|
2320
2322
|
};
|
|
2321
2323
|
// Track memory usage for tool execution
|
|
2322
2324
|
const { MemoryManager } = await import("./utils/performance.js");
|
|
2323
2325
|
const startMemory = MemoryManager.getMemoryUsageMB();
|
|
2324
2326
|
// Get or create circuit breaker for this tool
|
|
2325
2327
|
if (!this.toolCircuitBreakers.has(toolName)) {
|
|
2326
|
-
this.toolCircuitBreakers.set(toolName, new CircuitBreaker(
|
|
2328
|
+
this.toolCircuitBreakers.set(toolName, new CircuitBreaker(CIRCUIT_BREAKER.FAILURE_THRESHOLD, CIRCUIT_BREAKER_RESET_MS));
|
|
2327
2329
|
}
|
|
2328
2330
|
const circuitBreaker = this.toolCircuitBreakers.get(toolName);
|
|
2329
2331
|
// Initialize metrics for this tool if not exists
|
|
@@ -2646,10 +2648,10 @@ export class NeuroLink {
|
|
|
2646
2648
|
// Check memory usage after tool enumeration
|
|
2647
2649
|
const endMemory = MemoryManager.getMemoryUsageMB();
|
|
2648
2650
|
const memoryDelta = endMemory.heapUsed - startMemory.heapUsed;
|
|
2649
|
-
if (memoryDelta >
|
|
2651
|
+
if (memoryDelta > MEMORY_THRESHOLDS.LOW_USAGE_MB) {
|
|
2650
2652
|
mcpLogger.debug(`🔍 Tool listing used ${memoryDelta}MB memory (large tool registry detected)`);
|
|
2651
2653
|
// Optimized collection patterns should reduce memory usage significantly
|
|
2652
|
-
if (uniqueTools.length >
|
|
2654
|
+
if (uniqueTools.length > PERFORMANCE_THRESHOLDS.LARGE_TOOL_COLLECTION) {
|
|
2653
2655
|
mcpLogger.debug("💡 Tool collection optimized for large sets. Memory usage reduced through efficient object reuse.");
|
|
2654
2656
|
}
|
|
2655
2657
|
}
|
|
@@ -2721,7 +2723,7 @@ export class NeuroLink {
|
|
|
2721
2723
|
try {
|
|
2722
2724
|
const response = await fetch("http://localhost:11434/api/tags", {
|
|
2723
2725
|
method: "GET",
|
|
2724
|
-
signal: AbortSignal.timeout(
|
|
2726
|
+
signal: AbortSignal.timeout(PROVIDER_TIMEOUTS.AUTH_MS),
|
|
2725
2727
|
});
|
|
2726
2728
|
if (!response.ok) {
|
|
2727
2729
|
throw new Error("Ollama service not responding");
|
|
@@ -3098,7 +3100,7 @@ export class NeuroLink {
|
|
|
3098
3100
|
resetToolCircuitBreaker(toolName) {
|
|
3099
3101
|
if (this.toolCircuitBreakers.has(toolName)) {
|
|
3100
3102
|
// Create a new circuit breaker (effectively resets it)
|
|
3101
|
-
this.toolCircuitBreakers.set(toolName, new CircuitBreaker(
|
|
3103
|
+
this.toolCircuitBreakers.set(toolName, new CircuitBreaker(CIRCUIT_BREAKER.FAILURE_THRESHOLD, CIRCUIT_BREAKER_RESET_MS));
|
|
3102
3104
|
mcpLogger.info(`Circuit breaker reset for tool: ${toolName}`);
|
|
3103
3105
|
}
|
|
3104
3106
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type LanguageModelV1 } from "ai";
|
|
2
2
|
import { BaseProvider } from "../core/baseProvider.js";
|
|
3
|
-
import type { AIProviderName } from "../types
|
|
3
|
+
import type { AIProviderName } from "../core/types.js";
|
|
4
4
|
import type { StreamOptions, StreamResult } from "../types/streamTypes.js";
|
|
5
5
|
export declare class AzureOpenAIProvider extends BaseProvider {
|
|
6
6
|
private apiKey;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createAzure } from "@ai-sdk/azure";
|
|
2
2
|
import { streamText } from "ai";
|
|
3
3
|
import { BaseProvider } from "../core/baseProvider.js";
|
|
4
|
+
import { APIVersions } from "../core/types.js";
|
|
4
5
|
import { validateApiKey, createAzureAPIKeyConfig, createAzureEndpointConfig, } from "../utils/providerConfig.js";
|
|
5
6
|
import { logger } from "../utils/logger.js";
|
|
6
7
|
import { buildMessagesArray } from "../utils/messageBuilder.js";
|
|
@@ -24,7 +25,7 @@ export class AzureOpenAIProvider extends BaseProvider {
|
|
|
24
25
|
process.env.AZURE_OPENAI_DEPLOYMENT ||
|
|
25
26
|
process.env.AZURE_OPENAI_DEPLOYMENT_ID ||
|
|
26
27
|
"gpt-4o";
|
|
27
|
-
this.apiVersion = process.env.AZURE_API_VERSION ||
|
|
28
|
+
this.apiVersion = process.env.AZURE_API_VERSION || APIVersions.AZURE_LATEST;
|
|
28
29
|
// Configuration validation - now using consolidated utility
|
|
29
30
|
if (!this.apiKey) {
|
|
30
31
|
validateApiKey(createAzureAPIKeyConfig());
|
|
@@ -15,6 +15,31 @@ export interface ProviderConfigOptions {
|
|
|
15
15
|
instructions: string[];
|
|
16
16
|
fallbackEnvVars?: string[];
|
|
17
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* API key format validation patterns (extracted from advanced validation system)
|
|
20
|
+
* Exported for use across the codebase to replace scattered regex patterns
|
|
21
|
+
*/
|
|
22
|
+
export declare const API_KEY_FORMATS: Record<string, RegExp>;
|
|
23
|
+
/**
|
|
24
|
+
* API key length constants to replace scattered magic numbers
|
|
25
|
+
*/
|
|
26
|
+
export declare const API_KEY_LENGTHS: {
|
|
27
|
+
readonly OPENAI_MIN: 48;
|
|
28
|
+
readonly ANTHROPIC_MIN: 95;
|
|
29
|
+
readonly HUGGINGFACE_EXACT: 37;
|
|
30
|
+
readonly AZURE_MIN: 32;
|
|
31
|
+
readonly MISTRAL_EXACT: 32;
|
|
32
|
+
readonly AWS_ACCESS_KEY: 20;
|
|
33
|
+
readonly GOOGLE_AI_EXACT: 39;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Project ID format validation (for Google Cloud)
|
|
37
|
+
*/
|
|
38
|
+
export declare const PROJECT_ID_FORMAT: {
|
|
39
|
+
readonly MIN_LENGTH: 6;
|
|
40
|
+
readonly MAX_LENGTH: 30;
|
|
41
|
+
readonly PATTERN: RegExp;
|
|
42
|
+
};
|
|
18
43
|
/**
|
|
19
44
|
* Enhanced validation result with format checking
|
|
20
45
|
*/
|
|
@@ -6,16 +6,37 @@
|
|
|
6
6
|
*/
|
|
7
7
|
/**
|
|
8
8
|
* API key format validation patterns (extracted from advanced validation system)
|
|
9
|
+
* Exported for use across the codebase to replace scattered regex patterns
|
|
9
10
|
*/
|
|
10
|
-
const API_KEY_FORMATS = {
|
|
11
|
+
export const API_KEY_FORMATS = {
|
|
11
12
|
openai: /^sk-[A-Za-z0-9]{48,}$/,
|
|
12
13
|
anthropic: /^sk-ant-[A-Za-z0-9\-_]{95,}$/,
|
|
13
14
|
"google-ai": /^AIza[A-Za-z0-9\-_]{35}$/,
|
|
14
15
|
huggingface: /^hf_[A-Za-z0-9]{37}$/,
|
|
15
16
|
mistral: /^[A-Za-z0-9]{32}$/,
|
|
16
|
-
azure: /^[A-Za-z0-9]{32
|
|
17
|
+
azure: /^[A-Za-z0-9]{32}$/,
|
|
17
18
|
aws: /^[A-Z0-9]{20}$/, // Access Key ID format
|
|
18
|
-
|
|
19
|
+
bedrock: /^[A-Z0-9]{20}$/, // AWS access key ID: 20 uppercase alphanumerics
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* API key length constants to replace scattered magic numbers
|
|
23
|
+
*/
|
|
24
|
+
export const API_KEY_LENGTHS = {
|
|
25
|
+
OPENAI_MIN: 48, // OpenAI API keys minimum length
|
|
26
|
+
ANTHROPIC_MIN: 95, // Anthropic API keys minimum length
|
|
27
|
+
HUGGINGFACE_EXACT: 37, // HuggingFace tokens exact length
|
|
28
|
+
AZURE_MIN: 32, // Azure OpenAI API keys minimum length
|
|
29
|
+
MISTRAL_EXACT: 32, // Mistral API keys exact length
|
|
30
|
+
AWS_ACCESS_KEY: 20, // AWS access key ID exact length
|
|
31
|
+
GOOGLE_AI_EXACT: 39, // Google AI Studio keys exact length (with AIza prefix)
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Project ID format validation (for Google Cloud)
|
|
35
|
+
*/
|
|
36
|
+
export const PROJECT_ID_FORMAT = {
|
|
37
|
+
MIN_LENGTH: 6, // Minimum project ID length
|
|
38
|
+
MAX_LENGTH: 30, // Maximum project ID length
|
|
39
|
+
PATTERN: /^[a-z][a-z0-9-]{4,28}[a-z0-9]$/, // Google Cloud project ID format
|
|
19
40
|
};
|
|
20
41
|
/**
|
|
21
42
|
* Validates API key format for a specific provider
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Provider Health Checking System
|
|
3
3
|
* Prevents 500 errors by validating provider availability and configuration
|
|
4
4
|
*/
|
|
5
|
-
import { AIProviderName } from "../types
|
|
5
|
+
import { AIProviderName } from "../core/types.js";
|
|
6
6
|
export interface ProviderHealthStatus {
|
|
7
7
|
provider: AIProviderName;
|
|
8
8
|
isHealthy: boolean;
|