@juspay/neurolink 9.42.0 → 9.43.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.
- package/CHANGELOG.md +8 -0
- package/dist/auth/anthropicOAuth.js +12 -0
- package/dist/browser/neurolink.min.js +335 -334
- package/dist/cli/commands/mcp.d.ts +6 -0
- package/dist/cli/commands/mcp.js +200 -184
- package/dist/cli/commands/proxy.js +560 -518
- package/dist/core/baseProvider.d.ts +6 -1
- package/dist/core/baseProvider.js +219 -232
- package/dist/core/factory.d.ts +3 -0
- package/dist/core/factory.js +140 -190
- package/dist/core/modules/ToolsManager.d.ts +1 -0
- package/dist/core/modules/ToolsManager.js +40 -42
- package/dist/core/toolEvents.d.ts +3 -0
- package/dist/core/toolEvents.js +7 -0
- package/dist/evaluation/pipeline/evaluationPipeline.js +5 -2
- package/dist/evaluation/scorers/scorerRegistry.d.ts +3 -0
- package/dist/evaluation/scorers/scorerRegistry.js +356 -284
- package/dist/lib/auth/anthropicOAuth.js +12 -0
- package/dist/lib/core/baseProvider.d.ts +6 -1
- package/dist/lib/core/baseProvider.js +219 -232
- package/dist/lib/core/factory.d.ts +3 -0
- package/dist/lib/core/factory.js +140 -190
- package/dist/lib/core/modules/ToolsManager.d.ts +1 -0
- package/dist/lib/core/modules/ToolsManager.js +40 -42
- package/dist/lib/core/toolEvents.d.ts +3 -0
- package/dist/lib/core/toolEvents.js +8 -0
- package/dist/lib/evaluation/pipeline/evaluationPipeline.js +5 -2
- package/dist/lib/evaluation/scorers/scorerRegistry.d.ts +3 -0
- package/dist/lib/evaluation/scorers/scorerRegistry.js +356 -284
- package/dist/lib/mcp/toolRegistry.d.ts +2 -0
- package/dist/lib/mcp/toolRegistry.js +32 -31
- package/dist/lib/neurolink.d.ts +38 -0
- package/dist/lib/neurolink.js +1890 -1707
- package/dist/lib/providers/googleAiStudio.js +0 -5
- package/dist/lib/providers/googleNativeGemini3.d.ts +4 -0
- package/dist/lib/providers/googleNativeGemini3.js +39 -1
- package/dist/lib/providers/googleVertex.d.ts +10 -0
- package/dist/lib/providers/googleVertex.js +445 -445
- package/dist/lib/providers/litellm.d.ts +1 -0
- package/dist/lib/providers/litellm.js +73 -64
- package/dist/lib/providers/ollama.js +17 -4
- package/dist/lib/providers/openAI.d.ts +2 -0
- package/dist/lib/providers/openAI.js +139 -140
- package/dist/lib/proxy/claudeFormat.js +14 -5
- package/dist/lib/proxy/oauthFetch.js +298 -318
- package/dist/lib/proxy/proxyConfig.js +3 -1
- package/dist/lib/proxy/proxyFetch.js +250 -222
- package/dist/lib/proxy/proxyHealth.d.ts +17 -0
- package/dist/lib/proxy/proxyHealth.js +55 -0
- package/dist/lib/proxy/requestLogger.js +140 -48
- package/dist/lib/proxy/routingPolicy.d.ts +33 -0
- package/dist/lib/proxy/routingPolicy.js +255 -0
- package/dist/lib/proxy/snapshotPersistence.d.ts +2 -0
- package/dist/lib/proxy/snapshotPersistence.js +41 -0
- package/dist/lib/proxy/sseInterceptor.js +36 -11
- package/dist/lib/server/routes/claudeProxyRoutes.d.ts +2 -1
- package/dist/lib/server/routes/claudeProxyRoutes.js +2916 -2377
- package/dist/lib/services/server/ai/observability/instrumentation.js +194 -218
- package/dist/lib/tasks/backends/bullmqBackend.js +24 -18
- package/dist/lib/tasks/store/redisTaskStore.js +42 -17
- package/dist/lib/tasks/taskManager.d.ts +2 -0
- package/dist/lib/tasks/taskManager.js +100 -5
- package/dist/lib/telemetry/telemetryService.js +9 -5
- package/dist/lib/types/cli.d.ts +4 -0
- package/dist/lib/types/proxyTypes.d.ts +211 -1
- package/dist/lib/types/tools.d.ts +18 -0
- package/dist/lib/utils/providerHealth.d.ts +1 -0
- package/dist/lib/utils/providerHealth.js +46 -31
- package/dist/lib/utils/providerUtils.js +11 -22
- package/dist/lib/utils/schemaConversion.d.ts +1 -0
- package/dist/lib/utils/schemaConversion.js +3 -0
- package/dist/mcp/toolRegistry.d.ts +2 -0
- package/dist/mcp/toolRegistry.js +32 -31
- package/dist/neurolink.d.ts +38 -0
- package/dist/neurolink.js +1890 -1707
- package/dist/providers/googleAiStudio.js +0 -5
- package/dist/providers/googleNativeGemini3.d.ts +4 -0
- package/dist/providers/googleNativeGemini3.js +39 -1
- package/dist/providers/googleVertex.d.ts +10 -0
- package/dist/providers/googleVertex.js +445 -445
- package/dist/providers/litellm.d.ts +1 -0
- package/dist/providers/litellm.js +73 -64
- package/dist/providers/ollama.js +17 -4
- package/dist/providers/openAI.d.ts +2 -0
- package/dist/providers/openAI.js +139 -140
- package/dist/proxy/claudeFormat.js +14 -5
- package/dist/proxy/oauthFetch.js +298 -318
- package/dist/proxy/proxyConfig.js +3 -1
- package/dist/proxy/proxyFetch.js +250 -222
- package/dist/proxy/proxyHealth.d.ts +17 -0
- package/dist/proxy/proxyHealth.js +54 -0
- package/dist/proxy/requestLogger.js +140 -48
- package/dist/proxy/routingPolicy.d.ts +33 -0
- package/dist/proxy/routingPolicy.js +254 -0
- package/dist/proxy/snapshotPersistence.d.ts +2 -0
- package/dist/proxy/snapshotPersistence.js +40 -0
- package/dist/proxy/sseInterceptor.js +36 -11
- package/dist/server/routes/claudeProxyRoutes.d.ts +2 -1
- package/dist/server/routes/claudeProxyRoutes.js +2916 -2377
- package/dist/services/server/ai/observability/instrumentation.js +194 -218
- package/dist/tasks/backends/bullmqBackend.js +24 -18
- package/dist/tasks/store/redisTaskStore.js +42 -17
- package/dist/tasks/taskManager.d.ts +2 -0
- package/dist/tasks/taskManager.js +100 -5
- package/dist/telemetry/telemetryService.js +9 -5
- package/dist/types/cli.d.ts +4 -0
- package/dist/types/proxyTypes.d.ts +211 -1
- package/dist/types/tools.d.ts +18 -0
- package/dist/utils/providerHealth.d.ts +1 -0
- package/dist/utils/providerHealth.js +46 -31
- package/dist/utils/providerUtils.js +12 -22
- package/dist/utils/schemaConversion.d.ts +1 -0
- package/dist/utils/schemaConversion.js +3 -0
- package/package.json +3 -2
- package/scripts/observability/check-proxy-telemetry.mjs +1 -1
- package/scripts/observability/manage-local-openobserve.sh +36 -5
|
@@ -50,7 +50,8 @@ export async function getBestProvider(requestedProvider) {
|
|
|
50
50
|
return process.env.DEFAULT_PROVIDER;
|
|
51
51
|
}
|
|
52
52
|
// Special case for Ollama - prioritize local when available
|
|
53
|
-
if (process.env.OLLAMA_BASE_URL
|
|
53
|
+
if ((process.env.OLLAMA_BASE_URL || process.env.OLLAMA_API_BASE) &&
|
|
54
|
+
process.env.OLLAMA_MODEL) {
|
|
54
55
|
try {
|
|
55
56
|
if (await isProviderAvailable("ollama")) {
|
|
56
57
|
logger.debug(`[getBestProvider] Prioritizing working local Ollama`);
|
|
@@ -64,7 +65,7 @@ export async function getBestProvider(requestedProvider) {
|
|
|
64
65
|
/**
|
|
65
66
|
* Provider priority order rationale:
|
|
66
67
|
* - LiteLLM and Ollama are prioritized first for local/self-hosted deployments,
|
|
67
|
-
* avoiding
|
|
68
|
+
* avoiding unnecessary dependence on external providers during fallback scenarios.
|
|
68
69
|
* - Vertex (Google Cloud AI) follows for enterprise-grade reliability.
|
|
69
70
|
* - Google AI follows as second cloud priority for comprehensive Google AI ecosystem support.
|
|
70
71
|
* - OpenAI maintains high priority due to its consistent reliability and broad model support.
|
|
@@ -72,8 +73,8 @@ export async function getBestProvider(requestedProvider) {
|
|
|
72
73
|
* Please update this comment if the order is changed in the future, and document the rationale for maintainability.
|
|
73
74
|
*/
|
|
74
75
|
const providers = [
|
|
75
|
-
"litellm", // Prioritize self-hosted
|
|
76
|
-
"ollama", // Local models
|
|
76
|
+
"litellm", // Prioritize self-hosted proxy deployments first
|
|
77
|
+
"ollama", // Local models when the configured runtime target is installed
|
|
77
78
|
"vertex", // Google Cloud AI (enterprise)
|
|
78
79
|
"google-ai", // Google AI ecosystem support
|
|
79
80
|
"openai", // Reliable with broad model support
|
|
@@ -101,25 +102,13 @@ async function isProviderAvailable(providerName) {
|
|
|
101
102
|
if (!hasProviderEnvVars(providerName) && providerName !== "ollama") {
|
|
102
103
|
return false;
|
|
103
104
|
}
|
|
105
|
+
if (providerName === "litellm") {
|
|
106
|
+
const availability = await ProviderHealthChecker.checkFallbackProviderAvailability(AIProviderName.LITELLM, process.env.LITELLM_MODEL || "openai/gpt-4o-mini");
|
|
107
|
+
return availability.available;
|
|
108
|
+
}
|
|
104
109
|
if (providerName === "ollama") {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
method: "GET",
|
|
108
|
-
signal: AbortSignal.timeout(2000),
|
|
109
|
-
});
|
|
110
|
-
if (response.ok) {
|
|
111
|
-
const { models } = await response.json();
|
|
112
|
-
const defaultOllamaModel = process.env.OLLAMA_MODEL || "llama3.1:8b";
|
|
113
|
-
// Check for exact match first, then prefix match (e.g. "gemma3:27b" matches "gemma3:27b-fp16")
|
|
114
|
-
return models.some((m) => m.name === defaultOllamaModel ||
|
|
115
|
-
(typeof m.name === "string" &&
|
|
116
|
-
m.name.startsWith(defaultOllamaModel.split(":")[0] + ":")));
|
|
117
|
-
}
|
|
118
|
-
return false;
|
|
119
|
-
}
|
|
120
|
-
catch {
|
|
121
|
-
return false;
|
|
122
|
-
}
|
|
110
|
+
const availability = await ProviderHealthChecker.checkFallbackProviderAvailability(AIProviderName.OLLAMA, process.env.OLLAMA_MODEL || "llama3.1:8b");
|
|
111
|
+
return availability.available;
|
|
123
112
|
}
|
|
124
113
|
try {
|
|
125
114
|
const provider = await AIProviderFactory.createProvider(providerName);
|
|
@@ -20,6 +20,7 @@ export declare function inlineJsonSchema(schema: Record<string, unknown>, defini
|
|
|
20
20
|
* 3. Plain JSON Schema objects (have `type`/`properties` but no `_def`) — returned as-is
|
|
21
21
|
*/
|
|
22
22
|
export declare function convertZodToJsonSchema(zodSchema: ZodUnknownSchema): object;
|
|
23
|
+
export declare function normalizeJsonSchemaObject(schema: Record<string, unknown> | undefined | null): Record<string, unknown>;
|
|
23
24
|
/**
|
|
24
25
|
* Check if a value is a Zod schema
|
|
25
26
|
*/
|
|
@@ -138,6 +138,9 @@ export function convertZodToJsonSchema(zodSchema) {
|
|
|
138
138
|
return { type: "object", properties: {} };
|
|
139
139
|
}
|
|
140
140
|
}
|
|
141
|
+
export function normalizeJsonSchemaObject(schema) {
|
|
142
|
+
return ensureTypeField(inlineJsonSchema(schema ? { ...schema } : { type: "object", properties: {} }));
|
|
143
|
+
}
|
|
141
144
|
/**
|
|
142
145
|
* Ensure a JSON Schema object has a `type` field (required by Vertex/Gemini).
|
|
143
146
|
*/
|
|
@@ -69,6 +69,8 @@ export declare class MCPToolRegistry extends MCPRegistry {
|
|
|
69
69
|
permissions?: string[];
|
|
70
70
|
context?: ExecutionContext;
|
|
71
71
|
}): Promise<ToolInfo[]>;
|
|
72
|
+
private resolveToolExecutionTarget;
|
|
73
|
+
private createExecutionContext;
|
|
72
74
|
/**
|
|
73
75
|
* Get tool information with server details
|
|
74
76
|
*/
|
package/dist/mcp/toolRegistry.js
CHANGED
|
@@ -9,6 +9,7 @@ import { shouldDisableBuiltinTools } from "../utils/toolUtils.js";
|
|
|
9
9
|
import { directAgentTools } from "../agent/directTools.js";
|
|
10
10
|
import { detectCategory, createMCPServerInfo } from "../utils/mcpDefaults.js";
|
|
11
11
|
import { FlexibleToolValidator } from "./flexibleToolValidator.js";
|
|
12
|
+
import { ErrorFactory } from "../utils/errorHandling.js";
|
|
12
13
|
import { HITLUserRejectedError, HITLTimeoutError } from "../hitl/hitlErrors.js";
|
|
13
14
|
import { withSpan, tracers, ATTR } from "../telemetry/index.js";
|
|
14
15
|
import { getAuthContext } from "../auth/authContext.js";
|
|
@@ -263,22 +264,7 @@ export class MCPToolRegistry extends MCPRegistry {
|
|
|
263
264
|
hasContext: context !== undefined,
|
|
264
265
|
sessionId: context?.sessionId,
|
|
265
266
|
});
|
|
266
|
-
|
|
267
|
-
let tool = this.tools.get(toolName);
|
|
268
|
-
registryLogger.info(`🔍 [TOOL_LOOKUP] Direct lookup result for '${toolName}':`, !!tool);
|
|
269
|
-
// If not found, search for tool by name across all entries (for backward compatibility)
|
|
270
|
-
let toolId = toolName;
|
|
271
|
-
if (!tool) {
|
|
272
|
-
const matches = Array.from(this.tools.entries()).filter(([, toolInfo]) => toolInfo.name === toolName);
|
|
273
|
-
if (matches.length > 1) {
|
|
274
|
-
throw new Error(`Ambiguous tool name '${toolName}'. Use fully-qualified name 'serverId.${toolName}'.`);
|
|
275
|
-
}
|
|
276
|
-
if (matches.length === 1) {
|
|
277
|
-
const [candidateToolId, toolInfo] = matches[0];
|
|
278
|
-
tool = toolInfo;
|
|
279
|
-
toolId = candidateToolId;
|
|
280
|
-
}
|
|
281
|
-
}
|
|
267
|
+
const { tool, toolId } = this.resolveToolExecutionTarget(toolName);
|
|
282
268
|
if (!tool) {
|
|
283
269
|
throw new Error(`Tool '${toolName}' not found in registry`);
|
|
284
270
|
}
|
|
@@ -291,21 +277,7 @@ export class MCPToolRegistry extends MCPRegistry {
|
|
|
291
277
|
: "mcp";
|
|
292
278
|
span.setAttribute("tool.type", toolType);
|
|
293
279
|
span.setAttribute(ATTR.MCP_SERVER_ID, serverId);
|
|
294
|
-
|
|
295
|
-
let authUserId;
|
|
296
|
-
try {
|
|
297
|
-
const authCtx = getAuthContext();
|
|
298
|
-
authUserId = authCtx?.user?.id;
|
|
299
|
-
}
|
|
300
|
-
catch {
|
|
301
|
-
// Auth context not available — that's fine
|
|
302
|
-
}
|
|
303
|
-
// Create execution context if not provided
|
|
304
|
-
const execContext = {
|
|
305
|
-
...context,
|
|
306
|
-
sessionId: context?.sessionId ?? randomUUID(),
|
|
307
|
-
userId: context?.userId ?? authUserId,
|
|
308
|
-
};
|
|
280
|
+
const execContext = this.createExecutionContext(context);
|
|
309
281
|
// Get the tool implementation using the resolved toolId
|
|
310
282
|
const toolImpl = this.toolImplementations.get(toolId);
|
|
311
283
|
registryLogger.debug(`Looking for tool '${toolName}' (toolId: '${toolId}'), found: ${!!toolImpl}, type: ${typeof toolImpl?.execute}`);
|
|
@@ -504,6 +476,35 @@ export class MCPToolRegistry extends MCPRegistry {
|
|
|
504
476
|
registryLogger.debug(`Listed ${result.length} unique tools (${filter ? "filtered" : "unfiltered"})`);
|
|
505
477
|
return result;
|
|
506
478
|
}
|
|
479
|
+
resolveToolExecutionTarget(toolName) {
|
|
480
|
+
let tool = this.tools.get(toolName);
|
|
481
|
+
registryLogger.info(`🔍 [TOOL_LOOKUP] Direct lookup result for '${toolName}':`, !!tool);
|
|
482
|
+
let toolId = toolName;
|
|
483
|
+
if (!tool) {
|
|
484
|
+
const matches = Array.from(this.tools.entries()).filter(([, toolInfo]) => toolInfo.name === toolName);
|
|
485
|
+
if (matches.length > 1) {
|
|
486
|
+
throw ErrorFactory.toolExecutionFailed(toolName, new Error(`Ambiguous tool name '${toolName}'. Use fully-qualified name 'serverId.${toolName}'.`));
|
|
487
|
+
}
|
|
488
|
+
if (matches.length === 1) {
|
|
489
|
+
[toolId, tool] = matches[0];
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
return { tool, toolId };
|
|
493
|
+
}
|
|
494
|
+
createExecutionContext(context) {
|
|
495
|
+
let authUserId;
|
|
496
|
+
try {
|
|
497
|
+
authUserId = getAuthContext()?.user?.id;
|
|
498
|
+
}
|
|
499
|
+
catch {
|
|
500
|
+
// Auth context not available — that's fine
|
|
501
|
+
}
|
|
502
|
+
return {
|
|
503
|
+
...context,
|
|
504
|
+
sessionId: context?.sessionId ?? randomUUID(),
|
|
505
|
+
userId: context?.userId ?? authUserId,
|
|
506
|
+
};
|
|
507
|
+
}
|
|
507
508
|
/**
|
|
508
509
|
* Get tool information with server details
|
|
509
510
|
*/
|
package/dist/neurolink.d.ts
CHANGED
|
@@ -81,6 +81,12 @@ export declare class NeuroLink {
|
|
|
81
81
|
* Extract and set Langfuse context from options with proper async scoping
|
|
82
82
|
*/
|
|
83
83
|
private setLangfuseContextFromOptions;
|
|
84
|
+
private createMetricsTraceContext;
|
|
85
|
+
private enforceSessionBudget;
|
|
86
|
+
private assertInputText;
|
|
87
|
+
private applyAuthenticatedRequestContext;
|
|
88
|
+
private applyGenerateLifecycleMiddleware;
|
|
89
|
+
private applyStreamLifecycleMiddleware;
|
|
84
90
|
private initializeMemoryConfig;
|
|
85
91
|
/**
|
|
86
92
|
* Lazy initialization for memory — called during generate/stream.
|
|
@@ -526,6 +532,16 @@ export declare class NeuroLink {
|
|
|
526
532
|
* @since 1.0.0
|
|
527
533
|
*/
|
|
528
534
|
generate(optionsOrPrompt: GenerateOptions | string): Promise<GenerateResult>;
|
|
535
|
+
private executeGenerateWithMetricsContext;
|
|
536
|
+
private executeGenerateRequest;
|
|
537
|
+
private prepareGenerateRequest;
|
|
538
|
+
private maybeHandleEarlyGenerateResult;
|
|
539
|
+
private runStandardGenerateRequest;
|
|
540
|
+
private maybeApplyGenerateOrchestration;
|
|
541
|
+
private prepareGenerateAugmentations;
|
|
542
|
+
private buildGenerateTextOptions;
|
|
543
|
+
private finalizeGenerateRequestResult;
|
|
544
|
+
private emitGenerateErrorEvent;
|
|
529
545
|
/**
|
|
530
546
|
* Schedule non-blocking memory storage after generate completes.
|
|
531
547
|
*/
|
|
@@ -560,6 +576,13 @@ export declare class NeuroLink {
|
|
|
560
576
|
* 5. Store conversation turn for future context
|
|
561
577
|
*/
|
|
562
578
|
private generateTextInternal;
|
|
579
|
+
private executeGenerateTextInternalWithSpan;
|
|
580
|
+
private initializeGenerateTextInternalContext;
|
|
581
|
+
private runGenerateTextInternalFlow;
|
|
582
|
+
private captureOriginalConversationMessagesForRecovery;
|
|
583
|
+
private finalizeGenerateTextInternalResult;
|
|
584
|
+
private handleGenerateTextInternalFailure;
|
|
585
|
+
private tryRecoverGenerateTextOverflow;
|
|
563
586
|
/**
|
|
564
587
|
* Log generateTextInternal start with comprehensive analysis
|
|
565
588
|
*/
|
|
@@ -585,6 +608,11 @@ export declare class NeuroLink {
|
|
|
585
608
|
* Try MCP-enhanced generation (no fallback recursion)
|
|
586
609
|
*/
|
|
587
610
|
private tryMCPGeneration;
|
|
611
|
+
private prepareMCPGenerationContext;
|
|
612
|
+
private logMCPConversationSummary;
|
|
613
|
+
private ensureMCPGenerationBudget;
|
|
614
|
+
private compactMCPConversationForBudget;
|
|
615
|
+
private generateWithMCPProvider;
|
|
588
616
|
/**
|
|
589
617
|
* Direct provider generation (no MCP, no recursion)
|
|
590
618
|
*/
|
|
@@ -660,6 +688,10 @@ export declare class NeuroLink {
|
|
|
660
688
|
* @throws {Error} When conversation memory operations fail (if enabled)
|
|
661
689
|
*/
|
|
662
690
|
stream(options: StreamOptions): Promise<StreamResult>;
|
|
691
|
+
private executeStreamRequest;
|
|
692
|
+
private validateStreamRequestOptions;
|
|
693
|
+
private maybeHandleWorkflowStreamRequest;
|
|
694
|
+
private runStandardStreamRequest;
|
|
663
695
|
/**
|
|
664
696
|
* Prepare stream options: initialize memory, MCP, retrieval, orchestration,
|
|
665
697
|
* Ollama tool auto-disable, factory processing, and tool detection.
|
|
@@ -1061,6 +1093,12 @@ export declare class NeuroLink {
|
|
|
1061
1093
|
[key: string]: unknown;
|
|
1062
1094
|
};
|
|
1063
1095
|
}): Promise<T>;
|
|
1096
|
+
private createToolExecutionContext;
|
|
1097
|
+
private executeToolWithSpan;
|
|
1098
|
+
private prepareToolExecutionState;
|
|
1099
|
+
private runPreparedToolExecution;
|
|
1100
|
+
private handleSuccessfulToolExecution;
|
|
1101
|
+
private handleFailedToolExecution;
|
|
1064
1102
|
/**
|
|
1065
1103
|
* Internal tool execution method with MCP enhancements wired in:
|
|
1066
1104
|
* - ToolCache: check/store cached results for non-destructive tools
|