@juspay/neurolink 9.51.1 → 9.51.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.
@@ -44,7 +44,7 @@ export type NeurolinkConstructorConfig = {
44
44
  * Configuration for MCP enhancement modules wired into generate()/stream() paths.
45
45
  *
46
46
  * These modules are automatically applied during tool execution when configured:
47
- * - cache: Tool result caching (disabled by default)
47
+ * - cache: Tool result caching (enabled by default, opt out with enabled: false)
48
48
  * - annotations: Auto-infer tool safety metadata (enabled by default)
49
49
  * - router: Multi-server tool routing (auto-activates with 2+ servers)
50
50
  * - batcher: Batch programmatic tool calls (disabled by default)
@@ -52,7 +52,7 @@ export type NeurolinkConstructorConfig = {
52
52
  * - middleware: Global tool execution middleware chain (empty by default)
53
53
  */
54
54
  export type MCPEnhancementsConfig = {
55
- /** Tool result caching. Default: disabled. Enable to cache read-only tool results. */
55
+ /** Tool result caching. Default: enabled. Set enabled: false to opt out. */
56
56
  cache?: {
57
57
  enabled?: boolean;
58
58
  /** Cache TTL in milliseconds. Default: 300000 (5 min) */
package/dist/neurolink.js CHANGED
@@ -775,17 +775,18 @@ export class NeuroLink {
775
775
  initializeMCPEnhancements(config) {
776
776
  const mcpConfig = config?.mcp;
777
777
  this.mcpEnhancementsConfig = mcpConfig;
778
- // ToolCache — disabled by default, opt-in
779
- if (mcpConfig?.cache?.enabled) {
778
+ // BZ-664: ToolCache — enabled by default to prevent duplicate tool calls.
779
+ // Callers can explicitly opt out via mcp.cache.enabled = false.
780
+ if (mcpConfig?.cache?.enabled !== false) {
780
781
  this.mcpToolResultCache = new ToolResultCache({
781
- ttl: mcpConfig.cache.ttl ?? 300_000,
782
- maxSize: mcpConfig.cache.maxSize ?? 500,
783
- strategy: mcpConfig.cache.strategy ?? "lru",
782
+ ttl: mcpConfig?.cache?.ttl ?? 300_000,
783
+ maxSize: mcpConfig?.cache?.maxSize ?? 500,
784
+ strategy: mcpConfig?.cache?.strategy ?? "lru",
784
785
  });
785
786
  logger.debug("[NeuroLink] MCP tool result cache initialized", {
786
- ttl: mcpConfig.cache.ttl ?? 300_000,
787
- maxSize: mcpConfig.cache.maxSize ?? 500,
788
- strategy: mcpConfig.cache.strategy ?? "lru",
787
+ ttl: mcpConfig?.cache?.ttl ?? 300_000,
788
+ maxSize: mcpConfig?.cache?.maxSize ?? 500,
789
+ strategy: mcpConfig?.cache?.strategy ?? "lru",
789
790
  });
790
791
  }
791
792
  // ToolCallBatcher — disabled by default, opt-in
@@ -7628,7 +7629,36 @@ Current user's request: ${currentInput}`;
7628
7629
  async executeExternalMCPTool(serverId, toolName, parameters, options) {
7629
7630
  try {
7630
7631
  mcpLogger.debug(`[NeuroLink] Executing external MCP tool: ${toolName} on ${serverId}`);
7632
+ // BZ-664: Check existing ToolResultCache before executing to avoid
7633
+ // duplicate identical calls within the same session.
7634
+ //
7635
+ // Safety guards aligned with executeToolInternal():
7636
+ // - Skip destructive tools (destructiveHint annotation)
7637
+ // - Scope cache key by serverId (two servers can expose same tool name)
7638
+ // and toolExecutionContext (prevents cross-session/user leaks)
7639
+ const toolAnnotations = this.getToolAnnotationsForExecution(toolName);
7640
+ const cacheEnabled = !!this.mcpToolResultCache &&
7641
+ !this._disableToolCacheForCurrentRequest &&
7642
+ !toolAnnotations?.destructiveHint;
7643
+ const cacheKeyArgs = {
7644
+ __serverId: serverId,
7645
+ __args: parameters,
7646
+ ...(this.toolExecutionContext
7647
+ ? { __ctx: this.toolExecutionContext }
7648
+ : {}),
7649
+ };
7650
+ if (cacheEnabled && this.mcpToolResultCache) {
7651
+ const cached = this.mcpToolResultCache.getCachedResult(toolName, cacheKeyArgs);
7652
+ if (cached !== undefined) {
7653
+ mcpLogger.debug(`[NeuroLink] Tool result cache HIT: ${toolName} on ${serverId}`);
7654
+ return cached;
7655
+ }
7656
+ }
7631
7657
  const result = await this.externalServerManager.executeTool(serverId, toolName, parameters, options);
7658
+ // BZ-664: Store result in cache after successful execution
7659
+ if (cacheEnabled && this.mcpToolResultCache) {
7660
+ this.mcpToolResultCache.cacheResult(toolName, cacheKeyArgs, result);
7661
+ }
7632
7662
  mcpLogger.debug(`[NeuroLink] External MCP tool executed successfully: ${toolName}`);
7633
7663
  return result;
7634
7664
  }
@@ -4,7 +4,7 @@ import { stepCountIs, streamText } from "ai";
4
4
  import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync, } from "fs";
5
5
  import { homedir } from "os";
6
6
  import { join } from "path";
7
- import { ANTHROPIC_TOKEN_URL, CLAUDE_CLI_USER_AGENT, CLAUDE_CODE_CLIENT_ID, } from "../auth/anthropicOAuth.js";
7
+ import { ANTHROPIC_TOKEN_URL, CLAUDE_CLI_USER_AGENT, CLAUDE_CODE_CLIENT_ID, CLAUDE_CODE_OAUTH_BETAS, } from "../auth/anthropicOAuth.js";
8
8
  import { AnthropicModels, TOKEN_EXPIRY_BUFFER_MS, } from "../constants/enums.js";
9
9
  import { BaseProvider } from "../core/baseProvider.js";
10
10
  import { DEFAULT_MAX_STEPS } from "../core/constants.js";
@@ -310,6 +310,9 @@ export class AnthropicProvider extends BaseProvider {
310
310
  anthropic = createAnthropic({
311
311
  apiKey: apiKeyToUse,
312
312
  headers,
313
+ ...(process.env.ANTHROPIC_BASE_URL && {
314
+ baseURL: process.env.ANTHROPIC_BASE_URL,
315
+ }),
313
316
  fetch: createProxyFetch(),
314
317
  });
315
318
  logger.debug("Anthropic Provider initialized with API key", {
@@ -354,9 +357,23 @@ export class AnthropicProvider extends BaseProvider {
354
357
  */
355
358
  getAuthHeaders() {
356
359
  const headers = {};
357
- // Add beta headers if enabled
360
+ // When routing through proxy (ANTHROPIC_BASE_URL set), use the full
361
+ // OAuth beta set so the proxy forwards them upstream. Without these,
362
+ // Anthropic treats the request with tighter non-subscription rate limits.
363
+ const usingProxy = !!process.env.ANTHROPIC_BASE_URL;
358
364
  if (this.enableBetaFeatures) {
359
- headers["anthropic-beta"] = ANTHROPIC_BETA_HEADERS["anthropic-beta"];
365
+ if (usingProxy) {
366
+ headers["anthropic-beta"] = [
367
+ ...CLAUDE_CODE_OAUTH_BETAS,
368
+ "fine-grained-tool-streaming-2025-05-14",
369
+ "context-1m-2025-08-07",
370
+ "interleaved-thinking-2025-05-14",
371
+ "redact-thinking-2026-02-12",
372
+ ].join(",");
373
+ }
374
+ else {
375
+ headers["anthropic-beta"] = ANTHROPIC_BETA_HEADERS["anthropic-beta"];
376
+ }
360
377
  }
361
378
  // Add subscription-specific headers if applicable
362
379
  if (this.subscriptionTier !== "api") {
@@ -2,7 +2,7 @@ const STREAMING_CONVERSATIONAL_TOOL_THRESHOLD = 4;
2
2
  const STRONG_TOOL_FIDELITY_THRESHOLD = 8;
3
3
  const HIGH_TOOL_COUNT_THRESHOLD = 24;
4
4
  const DEFAULT_COOLDOWN_FLOOR_MS = 1_000;
5
- const HIGH_TOOL_COUNT_COOLDOWN_FLOOR_MS = 120_000;
5
+ const HIGH_TOOL_COUNT_COOLDOWN_FLOOR_MS = 10_000;
6
6
  const HIGH_FIDELITY_COOLDOWN_FLOOR_MS = 300_000;
7
7
  export function inferClaudeProxyModelTier(modelName) {
8
8
  const normalized = modelName.toLowerCase();
@@ -221,10 +221,15 @@ export function applyRateLimitCooldownScope(args) {
221
221
  const rcBackoffLevels = args.state.requestClassBackoffLevels ?? {};
222
222
  const mtBackoffLevels = args.state.modelTierBackoffLevels ?? {};
223
223
  const scopedBackoffLevel = Math.max(rcBackoffLevels[requestClassKey] ?? 0, mtBackoffLevels[modelTierKey] ?? 0);
224
- const floorMs = args.profile.modelTier === "opus" || args.profile.requiresStrongToolFidelity
225
- ? HIGH_FIDELITY_COOLDOWN_FLOOR_MS
226
- : args.profile.isHighToolCountNonStream
227
- ? HIGH_TOOL_COUNT_COOLDOWN_FLOOR_MS
224
+ // High-tool-count-non-stream gets its own (lower) floor so that requests
225
+ // recover faster once proper OAuth betas are forwarded. Check it first
226
+ // because every >=24-tool request also satisfies requiresStrongToolFidelity
227
+ // (threshold 8), which would otherwise shadow this branch.
228
+ const floorMs = args.profile.isHighToolCountNonStream
229
+ ? HIGH_TOOL_COUNT_COOLDOWN_FLOOR_MS
230
+ : args.profile.modelTier === "opus" ||
231
+ args.profile.requiresStrongToolFidelity
232
+ ? HIGH_FIDELITY_COOLDOWN_FLOOR_MS
228
233
  : DEFAULT_COOLDOWN_FLOOR_MS;
229
234
  const baseCooldownMs = Math.max(args.retryAfterMs ?? 0, floorMs);
230
235
  const backoffMs = Math.min(baseCooldownMs * 2 ** scopedBackoffLevel, args.capMs);
@@ -44,7 +44,7 @@ export type NeurolinkConstructorConfig = {
44
44
  * Configuration for MCP enhancement modules wired into generate()/stream() paths.
45
45
  *
46
46
  * These modules are automatically applied during tool execution when configured:
47
- * - cache: Tool result caching (disabled by default)
47
+ * - cache: Tool result caching (enabled by default, opt out with enabled: false)
48
48
  * - annotations: Auto-infer tool safety metadata (enabled by default)
49
49
  * - router: Multi-server tool routing (auto-activates with 2+ servers)
50
50
  * - batcher: Batch programmatic tool calls (disabled by default)
@@ -52,7 +52,7 @@ export type NeurolinkConstructorConfig = {
52
52
  * - middleware: Global tool execution middleware chain (empty by default)
53
53
  */
54
54
  export type MCPEnhancementsConfig = {
55
- /** Tool result caching. Default: disabled. Enable to cache read-only tool results. */
55
+ /** Tool result caching. Default: enabled. Set enabled: false to opt out. */
56
56
  cache?: {
57
57
  enabled?: boolean;
58
58
  /** Cache TTL in milliseconds. Default: 300000 (5 min) */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juspay/neurolink",
3
- "version": "9.51.1",
3
+ "version": "9.51.3",
4
4
  "packageManager": "pnpm@10.15.1",
5
5
  "description": "Universal AI Development Platform with working MCP integration, multi-provider support, and professional CLI. Built-in tools operational, 58+ external MCP servers discoverable. Connect to filesystem, GitHub, database operations, and more. Build, test, and deploy AI applications with 13 providers: OpenAI, Anthropic, Google AI, AWS Bedrock, Azure, Hugging Face, Ollama, and Mistral AI.",
6
6
  "author": {