@juspay/neurolink 9.51.3 → 9.52.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 (118) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/artifacts/artifactStore.d.ts +56 -0
  3. package/dist/artifacts/artifactStore.js +143 -0
  4. package/dist/browser/neurolink.min.js +311 -298
  5. package/dist/cli/commands/mcp.d.ts +6 -0
  6. package/dist/cli/commands/mcp.js +128 -86
  7. package/dist/cli/loop/optionsSchema.d.ts +1 -1
  8. package/dist/core/factory.d.ts +2 -2
  9. package/dist/core/factory.js +4 -4
  10. package/dist/core/redisConversationMemoryManager.js +20 -0
  11. package/dist/factories/providerFactory.d.ts +4 -4
  12. package/dist/factories/providerFactory.js +20 -7
  13. package/dist/factories/providerRegistry.d.ts +5 -0
  14. package/dist/factories/providerRegistry.js +45 -26
  15. package/dist/lib/artifacts/artifactStore.d.ts +56 -0
  16. package/dist/lib/artifacts/artifactStore.js +144 -0
  17. package/dist/lib/core/factory.d.ts +2 -2
  18. package/dist/lib/core/factory.js +4 -4
  19. package/dist/lib/core/redisConversationMemoryManager.js +20 -0
  20. package/dist/lib/factories/providerFactory.d.ts +4 -4
  21. package/dist/lib/factories/providerFactory.js +20 -7
  22. package/dist/lib/factories/providerRegistry.d.ts +5 -0
  23. package/dist/lib/factories/providerRegistry.js +45 -26
  24. package/dist/lib/mcp/externalServerManager.d.ts +6 -0
  25. package/dist/lib/mcp/externalServerManager.js +9 -0
  26. package/dist/lib/mcp/mcpOutputNormalizer.d.ts +49 -0
  27. package/dist/lib/mcp/mcpOutputNormalizer.js +182 -0
  28. package/dist/lib/mcp/toolDiscoveryService.d.ts +10 -0
  29. package/dist/lib/mcp/toolDiscoveryService.js +32 -1
  30. package/dist/lib/memory/memoryRetrievalTools.d.ts +64 -9
  31. package/dist/lib/memory/memoryRetrievalTools.js +77 -9
  32. package/dist/lib/neurolink.d.ts +23 -0
  33. package/dist/lib/neurolink.js +128 -86
  34. package/dist/lib/providers/amazonBedrock.d.ts +6 -1
  35. package/dist/lib/providers/amazonBedrock.js +14 -2
  36. package/dist/lib/providers/amazonSagemaker.d.ts +7 -1
  37. package/dist/lib/providers/amazonSagemaker.js +21 -3
  38. package/dist/lib/providers/anthropic.d.ts +4 -1
  39. package/dist/lib/providers/anthropic.js +18 -5
  40. package/dist/lib/providers/azureOpenai.d.ts +2 -1
  41. package/dist/lib/providers/azureOpenai.js +10 -5
  42. package/dist/lib/providers/googleAiStudio.d.ts +4 -1
  43. package/dist/lib/providers/googleAiStudio.js +6 -7
  44. package/dist/lib/providers/googleVertex.d.ts +3 -1
  45. package/dist/lib/providers/googleVertex.js +96 -17
  46. package/dist/lib/providers/huggingFace.d.ts +2 -1
  47. package/dist/lib/providers/huggingFace.js +4 -4
  48. package/dist/lib/providers/litellm.d.ts +5 -1
  49. package/dist/lib/providers/litellm.js +14 -9
  50. package/dist/lib/providers/mistral.d.ts +2 -1
  51. package/dist/lib/providers/mistral.js +2 -2
  52. package/dist/lib/providers/ollama.d.ts +3 -1
  53. package/dist/lib/providers/ollama.js +2 -2
  54. package/dist/lib/providers/openAI.d.ts +5 -1
  55. package/dist/lib/providers/openAI.js +15 -5
  56. package/dist/lib/providers/openRouter.d.ts +5 -1
  57. package/dist/lib/providers/openRouter.js +17 -5
  58. package/dist/lib/providers/openaiCompatible.d.ts +4 -1
  59. package/dist/lib/providers/openaiCompatible.js +15 -3
  60. package/dist/lib/session/globalSessionState.js +44 -1
  61. package/dist/lib/types/artifactTypes.d.ts +63 -0
  62. package/dist/lib/types/artifactTypes.js +11 -0
  63. package/dist/lib/types/configTypes.d.ts +39 -0
  64. package/dist/lib/types/conversation.d.ts +7 -0
  65. package/dist/lib/types/generateTypes.d.ts +13 -0
  66. package/dist/lib/types/index.d.ts +2 -0
  67. package/dist/lib/types/mcpOutputTypes.d.ts +40 -0
  68. package/dist/lib/types/mcpOutputTypes.js +9 -0
  69. package/dist/lib/types/providers.d.ts +75 -0
  70. package/dist/lib/types/streamTypes.d.ts +7 -1
  71. package/dist/mcp/externalServerManager.d.ts +6 -0
  72. package/dist/mcp/externalServerManager.js +9 -0
  73. package/dist/mcp/mcpOutputNormalizer.d.ts +49 -0
  74. package/dist/mcp/mcpOutputNormalizer.js +181 -0
  75. package/dist/mcp/toolDiscoveryService.d.ts +10 -0
  76. package/dist/mcp/toolDiscoveryService.js +32 -1
  77. package/dist/memory/memoryRetrievalTools.d.ts +64 -9
  78. package/dist/memory/memoryRetrievalTools.js +77 -9
  79. package/dist/neurolink.d.ts +23 -0
  80. package/dist/neurolink.js +128 -86
  81. package/dist/providers/amazonBedrock.d.ts +6 -1
  82. package/dist/providers/amazonBedrock.js +14 -2
  83. package/dist/providers/amazonSagemaker.d.ts +7 -1
  84. package/dist/providers/amazonSagemaker.js +21 -3
  85. package/dist/providers/anthropic.d.ts +4 -1
  86. package/dist/providers/anthropic.js +18 -5
  87. package/dist/providers/azureOpenai.d.ts +2 -1
  88. package/dist/providers/azureOpenai.js +10 -5
  89. package/dist/providers/googleAiStudio.d.ts +4 -1
  90. package/dist/providers/googleAiStudio.js +6 -7
  91. package/dist/providers/googleVertex.d.ts +3 -1
  92. package/dist/providers/googleVertex.js +96 -17
  93. package/dist/providers/huggingFace.d.ts +2 -1
  94. package/dist/providers/huggingFace.js +4 -4
  95. package/dist/providers/litellm.d.ts +5 -1
  96. package/dist/providers/litellm.js +14 -9
  97. package/dist/providers/mistral.d.ts +2 -1
  98. package/dist/providers/mistral.js +2 -2
  99. package/dist/providers/ollama.d.ts +3 -1
  100. package/dist/providers/ollama.js +2 -2
  101. package/dist/providers/openAI.d.ts +5 -1
  102. package/dist/providers/openAI.js +15 -5
  103. package/dist/providers/openRouter.d.ts +5 -1
  104. package/dist/providers/openRouter.js +17 -5
  105. package/dist/providers/openaiCompatible.d.ts +4 -1
  106. package/dist/providers/openaiCompatible.js +15 -3
  107. package/dist/session/globalSessionState.js +44 -1
  108. package/dist/types/artifactTypes.d.ts +63 -0
  109. package/dist/types/artifactTypes.js +10 -0
  110. package/dist/types/configTypes.d.ts +39 -0
  111. package/dist/types/conversation.d.ts +7 -0
  112. package/dist/types/generateTypes.d.ts +13 -0
  113. package/dist/types/index.d.ts +2 -0
  114. package/dist/types/mcpOutputTypes.d.ts +40 -0
  115. package/dist/types/mcpOutputTypes.js +8 -0
  116. package/dist/types/providers.d.ts +75 -0
  117. package/dist/types/streamTypes.d.ts +7 -1
  118. package/package.json +3 -2
@@ -18,7 +18,9 @@ export declare class OllamaProvider extends BaseProvider {
18
18
  private ollamaModel;
19
19
  private baseUrl;
20
20
  private timeout;
21
- constructor(modelName?: string);
21
+ constructor(modelName?: string, credentials?: {
22
+ baseURL?: string;
23
+ });
22
24
  protected getProviderName(): AIProviderName;
23
25
  protected getDefaultModel(): string;
24
26
  /**
@@ -523,9 +523,9 @@ export class OllamaProvider extends BaseProvider {
523
523
  ollamaModel;
524
524
  baseUrl;
525
525
  timeout;
526
- constructor(modelName) {
526
+ constructor(modelName, credentials) {
527
527
  super(modelName, "ollama");
528
- this.baseUrl = getOllamaBaseUrl();
528
+ this.baseUrl = credentials?.baseURL ?? getOllamaBaseUrl();
529
529
  this.timeout = getOllamaTimeout();
530
530
  // Initialize Ollama model
531
531
  this.ollamaModel = new OllamaLanguageModel(this.modelName || getDefaultOllamaModel(), this.baseUrl, this.timeout);
@@ -10,7 +10,11 @@ import type { ValidationSchema } from "../types/typeAliases.js";
10
10
  */
11
11
  export declare class OpenAIProvider extends BaseProvider {
12
12
  private model;
13
- constructor(modelName?: string, neurolink?: NeuroLink);
13
+ private credentials?;
14
+ constructor(modelName?: string, neurolink?: NeuroLink, _region?: string, credentials?: {
15
+ apiKey?: string;
16
+ baseURL?: string;
17
+ });
14
18
  /**
15
19
  * Check if this provider supports tool/function calling
16
20
  */
@@ -36,11 +36,14 @@ const streamTracer = trace.getTracer("neurolink.provider.openai");
36
36
  */
37
37
  export class OpenAIProvider extends BaseProvider {
38
38
  model;
39
- constructor(modelName, neurolink) {
39
+ credentials;
40
+ constructor(modelName, neurolink, _region, credentials) {
40
41
  super(modelName || getOpenAIModel(), AIProviderName.OPENAI, neurolink);
42
+ this.credentials = credentials;
41
43
  // Initialize OpenAI provider with proxy support
42
44
  const openai = createOpenAI({
43
- apiKey: getOpenAIApiKey(),
45
+ apiKey: credentials?.apiKey ?? getOpenAIApiKey(),
46
+ ...(credentials?.baseURL ? { baseURL: credentials.baseURL } : {}),
44
47
  fetch: createProxyFetch(),
45
48
  });
46
49
  // Initialize model
@@ -554,9 +557,12 @@ export class OpenAIProvider extends BaseProvider {
554
557
  });
555
558
  try {
556
559
  // Create embedding model using the AI SDK
557
- // Create the OpenAI provider
560
+ // Create the OpenAI provider, preferring per-instance credentials over env vars
558
561
  const openai = createOpenAI({
559
- apiKey: getOpenAIApiKey(),
562
+ apiKey: this.credentials?.apiKey ?? getOpenAIApiKey(),
563
+ ...(this.credentials?.baseURL
564
+ ? { baseURL: this.credentials.baseURL }
565
+ : {}),
560
566
  fetch: createProxyFetch(),
561
567
  });
562
568
  // Get the text embedding model
@@ -596,8 +602,12 @@ export class OpenAIProvider extends BaseProvider {
596
602
  count: texts.length,
597
603
  });
598
604
  try {
605
+ // Prefer per-instance credentials over env vars
599
606
  const openai = createOpenAI({
600
- apiKey: getOpenAIApiKey(),
607
+ apiKey: this.credentials?.apiKey ?? getOpenAIApiKey(),
608
+ ...(this.credentials?.baseURL
609
+ ? { baseURL: this.credentials.baseURL }
610
+ : {}),
601
611
  fetch: createProxyFetch(),
602
612
  });
603
613
  const embeddingModel = openai.textEmbeddingModel(embeddingModelName);
@@ -10,12 +10,16 @@ import type { StreamOptions, StreamResult } from "../types/streamTypes.js";
10
10
  export declare class OpenRouterProvider extends BaseProvider {
11
11
  private model;
12
12
  private openRouterClient;
13
+ private config;
13
14
  private static modelsCache;
14
15
  private static modelsCacheTime;
15
16
  private static readonly MODELS_CACHE_DURATION;
16
17
  private static toolCapableModels;
17
18
  private static capabilitiesCached;
18
- constructor(modelName?: string, sdk?: unknown);
19
+ constructor(modelName?: string, sdk?: unknown, _region?: string, credentials?: {
20
+ apiKey?: string;
21
+ baseURL?: string;
22
+ });
19
23
  protected getProviderName(): AIProviderName;
20
24
  protected getDefaultModel(): string;
21
25
  /**
@@ -47,6 +47,7 @@ const getDefaultOpenRouterModel = () => {
47
47
  export class OpenRouterProvider extends BaseProvider {
48
48
  model;
49
49
  openRouterClient;
50
+ config;
50
51
  // Cache for available models to avoid repeated API calls
51
52
  static modelsCache = [];
52
53
  static modelsCacheTime = 0;
@@ -54,10 +55,20 @@ export class OpenRouterProvider extends BaseProvider {
54
55
  // Cache for model capabilities (which models support tools)
55
56
  static toolCapableModels = new Set();
56
57
  static capabilitiesCached = false;
57
- constructor(modelName, sdk) {
58
+ constructor(modelName, sdk, _region, credentials) {
58
59
  super(modelName, AIProviderName.OPENROUTER, sdk);
59
- // Initialize OpenRouter using the official SDK
60
- const config = getOpenRouterConfig();
60
+ // Build config: prefer credentials over env vars to avoid throwing when env vars are absent
61
+ if (credentials?.apiKey) {
62
+ this.config = {
63
+ apiKey: credentials.apiKey,
64
+ referer: process.env.OPENROUTER_REFERER,
65
+ appName: process.env.OPENROUTER_APP_NAME,
66
+ };
67
+ }
68
+ else {
69
+ this.config = getOpenRouterConfig(); // throws if OPENROUTER_API_KEY missing
70
+ }
71
+ const config = this.config;
61
72
  // Build headers for attribution on openrouter.ai/activity dashboard
62
73
  const headers = {};
63
74
  if (config.referer) {
@@ -69,6 +80,7 @@ export class OpenRouterProvider extends BaseProvider {
69
80
  // Create OpenRouter client with optional attribution headers
70
81
  this.openRouterClient = createOpenRouter({
71
82
  apiKey: config.apiKey,
83
+ ...(credentials?.baseURL ? { baseURL: credentials.baseURL } : {}),
72
84
  ...(Object.keys(headers).length > 0 && { headers }),
73
85
  });
74
86
  // Initialize model with OpenRouter client
@@ -437,7 +449,7 @@ export class OpenRouterProvider extends BaseProvider {
437
449
  */
438
450
  async fetchModelsFromAPI() {
439
451
  const functionTag = "OpenRouterProvider.fetchModelsFromAPI";
440
- const config = getOpenRouterConfig();
452
+ const config = this.config;
441
453
  const modelsUrl = "https://openrouter.ai/api/v1/models";
442
454
  const controller = new AbortController();
443
455
  const timeoutId = setTimeout(() => controller.abort(), MODELS_DISCOVERY_TIMEOUT_MS);
@@ -499,7 +511,7 @@ export class OpenRouterProvider extends BaseProvider {
499
511
  return; // Already cached
500
512
  }
501
513
  try {
502
- const config = getOpenRouterConfig();
514
+ const config = this.config;
503
515
  const modelsUrl = "https://openrouter.ai/api/v1/models";
504
516
  const controller = new AbortController();
505
517
  const timeoutId = setTimeout(() => controller.abort(), MODELS_DISCOVERY_TIMEOUT_MS);
@@ -12,7 +12,10 @@ export declare class OpenAICompatibleProvider extends BaseProvider {
12
12
  private config;
13
13
  private discoveredModel?;
14
14
  private customOpenAI;
15
- constructor(modelName?: string, sdk?: unknown);
15
+ constructor(modelName?: string, sdk?: unknown, _region?: string, credentials?: {
16
+ apiKey?: string;
17
+ baseURL?: string;
18
+ });
16
19
  protected getProviderName(): AIProviderName;
17
20
  protected getDefaultModel(): string;
18
21
  /**
@@ -45,10 +45,22 @@ export class OpenAICompatibleProvider extends BaseProvider {
45
45
  config;
46
46
  discoveredModel;
47
47
  customOpenAI;
48
- constructor(modelName, sdk) {
48
+ constructor(modelName, sdk, _region, credentials) {
49
49
  super(modelName, "openai-compatible", sdk);
50
- // Initialize OpenAI Compatible configuration
51
- this.config = getOpenAICompatibleConfig();
50
+ // Build config: prefer credentials over env vars to avoid throwing when env vars are absent
51
+ if (credentials?.apiKey && credentials?.baseURL) {
52
+ this.config = {
53
+ apiKey: credentials.apiKey,
54
+ baseURL: credentials.baseURL,
55
+ };
56
+ }
57
+ else {
58
+ const envConfig = getOpenAICompatibleConfig(); // throws if env vars missing
59
+ this.config = {
60
+ apiKey: credentials?.apiKey ?? envConfig.apiKey,
61
+ baseURL: credentials?.baseURL ?? envConfig.baseURL,
62
+ };
63
+ }
52
64
  // Create OpenAI SDK instance configured for custom endpoint
53
65
  // This allows us to use OpenAI-compatible API by simply changing the baseURL
54
66
  this.customOpenAI = createOpenAI({
@@ -1,6 +1,33 @@
1
1
  import { nanoid } from "nanoid";
2
2
  import { NeuroLink } from "../neurolink.js";
3
3
  import { buildObservabilityConfigFromEnv } from "../utils/observabilityHelpers.js";
4
+ /**
5
+ * Build mcp.outputLimits config from environment variables.
6
+ * Reads NEUROLINK_MCP_OUTPUT_STRATEGY and NEUROLINK_MCP_MAX_OUTPUT_BYTES.
7
+ * Returns undefined when neither variable is set (no overhead).
8
+ */
9
+ function buildMcpOutputLimitsFromEnv() {
10
+ const strategyRaw = process.env.NEUROLINK_MCP_OUTPUT_STRATEGY;
11
+ const maxBytesRaw = process.env.NEUROLINK_MCP_MAX_OUTPUT_BYTES;
12
+ const warnBytesRaw = process.env.NEUROLINK_MCP_WARN_OUTPUT_BYTES;
13
+ if (!strategyRaw && !maxBytesRaw) {
14
+ return undefined;
15
+ }
16
+ const strategy = strategyRaw === "inline" || strategyRaw === "externalize"
17
+ ? strategyRaw
18
+ : "externalize"; // safe default when only maxBytes is set
19
+ const maxBytes = maxBytesRaw ? parseInt(maxBytesRaw, 10) : undefined;
20
+ const warnBytes = warnBytesRaw ? parseInt(warnBytesRaw, 10) : undefined;
21
+ return {
22
+ strategy,
23
+ ...(maxBytes !== undefined && Number.isFinite(maxBytes) && maxBytes >= 0
24
+ ? { maxBytes }
25
+ : {}),
26
+ ...(warnBytes !== undefined && Number.isFinite(warnBytes) && warnBytes >= 0
27
+ ? { warnBytes }
28
+ : {}),
29
+ };
30
+ }
4
31
  export class GlobalSessionManager {
5
32
  static instance;
6
33
  loopSession = null;
@@ -25,6 +52,14 @@ export class GlobalSessionManager {
25
52
  if (observabilityConfig) {
26
53
  neurolinkOptions.observability = observabilityConfig;
27
54
  }
55
+ // Add MCP output limits from environment variables (CLI usage)
56
+ const mcpOutputLimits = buildMcpOutputLimitsFromEnv();
57
+ if (mcpOutputLimits) {
58
+ neurolinkOptions.mcp = {
59
+ ...neurolinkOptions.mcp,
60
+ outputLimits: mcpOutputLimits,
61
+ };
62
+ }
28
63
  this.loopSession = {
29
64
  neurolinkInstance: new NeuroLink(neurolinkOptions),
30
65
  sessionId,
@@ -99,7 +134,15 @@ export class GlobalSessionManager {
99
134
  }
100
135
  // Create new NeuroLink with observability config from environment (CLI usage)
101
136
  const observabilityConfig = buildObservabilityConfigFromEnv();
102
- return new NeuroLink(observabilityConfig ? { observability: observabilityConfig } : undefined);
137
+ const mcpOutputLimits = buildMcpOutputLimitsFromEnv();
138
+ const options = {};
139
+ if (observabilityConfig) {
140
+ options.observability = observabilityConfig;
141
+ }
142
+ if (mcpOutputLimits) {
143
+ options.mcp = { outputLimits: mcpOutputLimits };
144
+ }
145
+ return new NeuroLink(Object.keys(options).length ? options : undefined);
103
146
  }
104
147
  getCurrentSessionId() {
105
148
  return this.getLoopSession()?.sessionId;
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Artifact Store Types (canonical location)
3
+ *
4
+ * Types for the MCP large-output artifact storage system.
5
+ * When mcp.outputLimits.strategy = "externalize", oversized MCP tool outputs
6
+ * are stored as artifacts and the model receives a compact surrogate instead.
7
+ *
8
+ * @module types/artifactTypes
9
+ */
10
+ /** Metadata recorded alongside a stored artifact. */
11
+ export type ArtifactMeta = {
12
+ /** Tool name that produced the output. */
13
+ toolName: string;
14
+ /** MCP server ID. */
15
+ serverId: string;
16
+ /** Session that triggered the tool call (optional). */
17
+ sessionId?: string;
18
+ /** Serialized byte size of the full payload. */
19
+ sizeBytes: number;
20
+ /** Whether the payload is valid JSON or plain text. */
21
+ contentType: "json" | "text";
22
+ /** Unix epoch ms when the artifact was created. */
23
+ createdAt: number;
24
+ };
25
+ /** Lightweight descriptor returned after a successful ArtifactStore.store(). */
26
+ export type ArtifactRef = {
27
+ /** UUID v4 — stable identifier used in surrogate results and metadata. */
28
+ id: string;
29
+ /** First N characters of the payload (for surrogate headers). */
30
+ preview: string;
31
+ /** Full serialized byte size. */
32
+ sizeBytes: number;
33
+ /** Stored metadata. */
34
+ meta: ArtifactMeta;
35
+ };
36
+ /**
37
+ * Pluggable storage contract for externalized MCP tool outputs.
38
+ *
39
+ * Default backend: LocalTempArtifactStore (filesystem, single-process).
40
+ * Future backends can implement this interface for S3, Redis blobs, etc.
41
+ */
42
+ export interface ArtifactStore {
43
+ /**
44
+ * Persist a payload and return a lightweight reference.
45
+ * @param payload Serialized tool output (JSON string or plain text).
46
+ * @param meta Descriptor without `createdAt` (assigned internally).
47
+ */
48
+ store(payload: string, meta: Omit<ArtifactMeta, "createdAt">): Promise<ArtifactRef>;
49
+ /**
50
+ * Retrieve the full payload by artifact ID.
51
+ * Returns `null` if the artifact is not found or has been cleaned up.
52
+ */
53
+ retrieve(id: string): Promise<string | null>;
54
+ /** Delete a single artifact. No-op if the ID does not exist. */
55
+ delete(id: string): Promise<void>;
56
+ /**
57
+ * Delete all artifacts older than `olderThanMs` milliseconds.
58
+ * Returns the number of artifacts deleted.
59
+ */
60
+ cleanup(olderThanMs: number): Promise<number>;
61
+ /** Generate a short preview string from a serialized payload. */
62
+ generatePreview(payload: string): string;
63
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Artifact Store Types (canonical location)
3
+ *
4
+ * Types for the MCP large-output artifact storage system.
5
+ * When mcp.outputLimits.strategy = "externalize", oversized MCP tool outputs
6
+ * are stored as artifacts and the model receives a compact surrogate instead.
7
+ *
8
+ * @module types/artifactTypes
9
+ */
10
+ export {};
@@ -11,6 +11,7 @@ import type { RoutingStrategy } from "../mcp/routing/index.js";
11
11
  import type { CacheStrategy } from "../mcp/caching/index.js";
12
12
  import type { ToolMiddleware } from "../mcp/toolIntegration.js";
13
13
  import type { MastraAuthProvider, AuthProviderType, AuthProviderConfig, Auth0Config, ClerkConfig, FirebaseConfig, SupabaseConfig, WorkOSConfig, BetterAuthConfig, JWTConfig, OAuth2Config, CognitoConfig, KeycloakConfig, AuthenticatedContext } from "./authTypes.js";
14
+ import type { NeurolinkCredentials } from "./providers.js";
14
15
  /**
15
16
  * Main NeuroLink configuration type
16
17
  */
@@ -39,6 +40,12 @@ export type NeurolinkConstructorConfig = {
39
40
  auth?: NeuroLinkAuthConfig;
40
41
  /** TaskManager configuration (scheduled and self-running tasks) */
41
42
  tasks?: TaskManagerConfig;
43
+ /**
44
+ * Per-provider credential overrides.
45
+ * When set here, applies as the default for all generate()/stream() calls
46
+ * from this NeuroLink instance. Per-call credentials override these.
47
+ */
48
+ credentials?: NeurolinkCredentials;
42
49
  };
43
50
  /**
44
51
  * Configuration for MCP enhancement modules wired into generate()/stream() paths.
@@ -90,6 +97,38 @@ export type MCPEnhancementsConfig = {
90
97
  };
91
98
  /** Global tool middleware applied to every tool execution. Default: empty. */
92
99
  middleware?: ToolMiddleware[];
100
+ /**
101
+ * Large MCP tool output handling.
102
+ *
103
+ * MCP servers can return arbitrarily large payloads. Without limits these
104
+ * are loaded entirely into memory, cached in full, stored whole in Redis, and
105
+ * injected into the LLM context window — all of which silently fail at scale.
106
+ *
107
+ * When configured, NeuroLink intercepts oversized outputs at the tool boundary
108
+ * (before caching and before memory persistence) and applies the chosen
109
+ * strategy so the model receives a compact surrogate instead of a firehose.
110
+ *
111
+ * Two strategies:
112
+ * - "inline" Keep sending the full payload to the model regardless of
113
+ * size. A warning is emitted above warnBytes.
114
+ * - "externalize" Store the full payload on disk as an artifact and return a
115
+ * compact surrogate with a head/tail preview and an artifact
116
+ * ID. The model uses `retrieve_context` with that ID to read
117
+ * the full output on demand, with offset/limit pagination.
118
+ *
119
+ * Defaults (when `outputLimits` is set):
120
+ * strategy = "externalize"
121
+ * maxBytes = 100 KB (100 * 1024)
122
+ * warnBytes = 50 KB (50 * 1024)
123
+ */
124
+ outputLimits?: {
125
+ /** What to do when output exceeds maxBytes. Default: "externalize". */
126
+ strategy?: "inline" | "externalize";
127
+ /** Byte ceiling above which the strategy fires. Default: 102400 (100 KB). */
128
+ maxBytes?: number;
129
+ /** Bytes at which a warning is emitted even when still inline. Default: 51200 (50 KB). */
130
+ warnBytes?: number;
131
+ };
93
132
  };
94
133
  /**
95
134
  * Authentication configuration for NeuroLink SDK
@@ -231,6 +231,13 @@ export type ChatMessageMetadata = {
231
231
  toolOutputPreview?: string;
232
232
  /** Original byte size of the full tool output before any truncation */
233
233
  originalSize?: number;
234
+ /**
235
+ * Artifact store ID for an externalized MCP tool output.
236
+ * Set when `mcp.outputLimits.strategy = "externalize"` and the tool output
237
+ * exceeded `maxBytes`. Use retrieve_context with this ID to fetch the full
238
+ * payload from the local artifact store.
239
+ */
240
+ artifactId?: string;
234
241
  };
235
242
  /**
236
243
  * Chat message format for conversation history
@@ -11,6 +11,7 @@ import type { DirectorModeOptions, DirectorSegment, VideoGenerationResult, Video
11
11
  import type { PPTGenerationResult, PPTOutputOptions } from "./pptTypes.js";
12
12
  import type { TTSOptions, TTSResult } from "./ttsTypes.js";
13
13
  import type { StandardRecord, ValidationSchema, ZodUnknownSchema } from "./typeAliases.js";
14
+ import type { NeurolinkCredentials } from "./providers.js";
14
15
  /**
15
16
  * Generate function options type - Primary method for content generation
16
17
  * Supports multimodal content while maintaining backward compatibility
@@ -424,6 +425,12 @@ export type GenerateOptions = {
424
425
  auth?: {
425
426
  token: string;
426
427
  };
428
+ /**
429
+ * Per-provider credential overrides for this request.
430
+ * Overrides instance-level credentials set in `new NeuroLink({ credentials })`.
431
+ * Unset providers fall through to instance credentials, then environment variables.
432
+ */
433
+ credentials?: NeurolinkCredentials;
427
434
  /**
428
435
  * Per-call memory control.
429
436
  *
@@ -942,6 +949,12 @@ export type TextGenerationOptions = {
942
949
  /** Thinking level (Gemini 3: minimal|low|medium|high). Ignored for Anthropic. */
943
950
  thinkingLevel?: "minimal" | "low" | "medium" | "high";
944
951
  };
952
+ /**
953
+ * Per-provider credential overrides for this request.
954
+ * Overrides instance-level credentials set in `new NeuroLink({ credentials })`.
955
+ * Unset providers fall through to instance credentials, then environment variables.
956
+ */
957
+ credentials?: NeurolinkCredentials;
945
958
  /**
946
959
  * Optional request identifier for observability and log correlation.
947
960
  * When provided, this ID is forwarded to spans, logs, and telemetry so
@@ -6,6 +6,8 @@ export * from "./cli.js";
6
6
  export * from "./common.js";
7
7
  export type { AnalyticsConfig, BackupInfo, BackupMetadata, CacheConfig, ConfigUpdateOptions, ConfigValidationResult, FallbackConfig, MCPEnhancementsConfig, NeuroLinkConfig, PerformanceConfig, RetryConfig, ToolConfig, } from "./configTypes.js";
8
8
  export type { ExternalMCPConfigValidation, ExternalMCPManagerConfig, ExternalMCPOperationResult, ExternalMCPServerEvents, ExternalMCPServerHealth, ExternalMCPServerInstance, ExternalMCPServerStatus, ExternalMCPToolContext, ExternalMCPToolInfo, ExternalMCPToolResult, } from "./externalMcp.js";
9
+ export type { ArtifactMeta, ArtifactRef, ArtifactStore, } from "./artifactTypes.js";
10
+ export type { McpOutputContext, McpOutputNormalizerConfig, McpOutputStrategy, NormalizedMcpOutput, } from "./mcpOutputTypes.js";
9
11
  export type { AuthorizationUrlResult, CircuitBreakerConfig, CircuitBreakerEvents, CircuitBreakerState, CircuitBreakerStats, DiscoveredMcp, ExternalToolExecutionOptions, FlexibleValidationResult, HTTPRetryConfig, MCPClientResult, MCPConnectedServer, MCPDiscoveredServer, MCPExecutableTool, MCPOAuthConfig, MCPServerCategory, MCPServerConfig, MCPServerConnectionStatus, MCPServerInfo, MCPServerMetadata, MCPServerRegistryEntry, MCPServerStatus, MCPStatus, MCPToolInfo, MCPToolMetadata, MCPTransportType, McpMetadata, McpRegistry, NeuroLinkExecutionContext, NeuroLinkMCPServer, NeuroLinkMCPTool, OAuthClientInformation, OAuthTokens as McpOAuthTokens, RateLimitConfig, TokenBucketRateLimitConfig, TokenExchangeRequest, TokenStorage, ToolDiscoveryResult, ToolRegistryEvents, ToolValidationResult, } from "./mcpTypes.js";
10
12
  export type { ModelCapability, ModelFilter, ModelPricing, ModelResolutionContext, ModelStats, ModelUseCase, } from "./providers.js";
11
13
  export * from "./providers.js";
@@ -0,0 +1,40 @@
1
+ /**
2
+ * MCP Output Normalizer Types (canonical location)
3
+ *
4
+ * Types for the large MCP response handling system.
5
+ *
6
+ * @module types/mcpOutputTypes
7
+ */
8
+ /**
9
+ * Two honest strategies for oversized MCP tool outputs:
10
+ * - "inline" Full payload always sent to the model (warning logged above warnBytes).
11
+ * - "externalize" Full payload stored as an artifact; model receives a compact
12
+ * surrogate with head/tail preview and an artifact ID it can
13
+ * resolve via retrieve_context with offset/limit pagination.
14
+ */
15
+ export type McpOutputStrategy = "inline" | "externalize";
16
+ /** Configuration for McpOutputNormalizer. */
17
+ export type McpOutputNormalizerConfig = {
18
+ strategy: McpOutputStrategy;
19
+ /** Byte ceiling above which the strategy fires. */
20
+ maxBytes: number;
21
+ /** Bytes at which a warning is emitted while still inline. */
22
+ warnBytes: number;
23
+ };
24
+ /** Contextual info passed alongside the raw MCP callResult. */
25
+ export type McpOutputContext = {
26
+ toolName: string;
27
+ serverId: string;
28
+ sessionId?: string;
29
+ };
30
+ /** Value returned by McpOutputNormalizer.normalize(). */
31
+ export type NormalizedMcpOutput = {
32
+ /** The result to substitute for the raw callResult. May be a surrogate. */
33
+ result: unknown;
34
+ /** Whether the full payload was written to the artifact store. */
35
+ isExternalized: boolean;
36
+ /** Artifact ID when isExternalized === true. */
37
+ artifactId?: string;
38
+ /** Serialized byte size of the original payload. */
39
+ originalBytes: number;
40
+ };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * MCP Output Normalizer Types (canonical location)
3
+ *
4
+ * Types for the large MCP response handling system.
5
+ *
6
+ * @module types/mcpOutputTypes
7
+ */
8
+ export {};
@@ -71,6 +71,81 @@ export type AWSCredentialConfig = {
71
71
  /** Optional service endpoint override (e.g., VPC/Gov endpoints) */
72
72
  endpoint?: string;
73
73
  };
74
+ /**
75
+ * Per-provider credential overrides for generate() / stream() calls.
76
+ *
77
+ * When set on `NeurolinkConstructorConfig.credentials`, applies as the default
78
+ * for all calls from that NeuroLink instance. When set on
79
+ * `GenerateOptions.credentials` or `StreamOptions.credentials`, overrides the
80
+ * instance default for that single call.
81
+ *
82
+ * Unset providers fall through to environment variables (existing behaviour).
83
+ */
84
+ export type NeurolinkCredentials = {
85
+ openai?: {
86
+ apiKey?: string;
87
+ baseURL?: string;
88
+ };
89
+ anthropic?: {
90
+ apiKey?: string;
91
+ oauthToken?: string;
92
+ };
93
+ googleAiStudio?: {
94
+ apiKey?: string;
95
+ };
96
+ vertex?: {
97
+ projectId?: string;
98
+ location?: string;
99
+ /** Vertex Express Mode — simplified API-key auth */
100
+ apiKey?: string;
101
+ /** Full service-account JSON string */
102
+ serviceAccountKey?: string;
103
+ /** Inline service-account fields (alternative to serviceAccountKey) */
104
+ clientEmail?: string;
105
+ privateKey?: string;
106
+ };
107
+ bedrock?: {
108
+ accessKeyId?: string;
109
+ secretAccessKey?: string;
110
+ sessionToken?: string;
111
+ region?: string;
112
+ };
113
+ sagemaker?: {
114
+ accessKeyId?: string;
115
+ secretAccessKey?: string;
116
+ sessionToken?: string;
117
+ region?: string;
118
+ endpoint?: string;
119
+ };
120
+ azure?: {
121
+ apiKey?: string;
122
+ resourceName?: string;
123
+ deploymentName?: string;
124
+ apiVersion?: string;
125
+ };
126
+ mistral?: {
127
+ apiKey?: string;
128
+ };
129
+ huggingFace?: {
130
+ apiKey?: string;
131
+ baseURL?: string;
132
+ };
133
+ openrouter?: {
134
+ apiKey?: string;
135
+ baseURL?: string;
136
+ };
137
+ litellm?: {
138
+ apiKey?: string;
139
+ baseURL?: string;
140
+ };
141
+ openaiCompatible?: {
142
+ apiKey?: string;
143
+ baseURL?: string;
144
+ };
145
+ ollama?: {
146
+ baseURL?: string;
147
+ };
148
+ };
74
149
  /**
75
150
  * AWS Credential Validation Result
76
151
  */
@@ -9,7 +9,7 @@ import type { JsonValue, UnknownRecord } from "./common.js";
9
9
  import type { Content, ImageWithAltText } from "./content.js";
10
10
  import type { ChatMessage } from "./conversation.js";
11
11
  import type { AdditionalMemoryUser } from "./generateTypes.js";
12
- import type { AIModelProviderConfig } from "./providers.js";
12
+ import type { AIModelProviderConfig, NeurolinkCredentials } from "./providers.js";
13
13
  import type { TTSChunk, TTSOptions } from "./ttsTypes.js";
14
14
  import type { StandardRecord, ValidationSchema } from "./typeAliases.js";
15
15
  /**
@@ -444,6 +444,12 @@ export type StreamOptions = {
444
444
  auth?: {
445
445
  token: string;
446
446
  };
447
+ /**
448
+ * Per-provider credential overrides for this request.
449
+ * Overrides instance-level credentials set in `new NeuroLink({ credentials })`.
450
+ * Unset providers fall through to instance credentials, then environment variables.
451
+ */
452
+ credentials?: NeurolinkCredentials;
447
453
  /**
448
454
  * Per-call memory control.
449
455
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juspay/neurolink",
3
- "version": "9.51.3",
3
+ "version": "9.52.0",
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": {
@@ -81,6 +81,7 @@
81
81
  "test:servers": "npx tsx test/continuous-test-suite-servers.ts",
82
82
  "test:tracing": "npx tsx test/continuous-test-suite-tracing.ts",
83
83
  "test:tts": "npx tsx test/continuous-test-suite-tts.ts",
84
+ "test:credentials": "tsx test/continuous-test-suite-credentials.ts",
84
85
  "test:workflow": "npx tsx test/continuous-test-suite-workflow.ts",
85
86
  "test:ci": "pnpm run test && pnpm run test:client",
86
87
  "test:performance": "tsx tools/testing/performanceMonitor.ts",
@@ -229,8 +230,8 @@
229
230
  "adm-zip": "^0.5.16",
230
231
  "ai": "^6.0.134",
231
232
  "bullmq": "^5.52.2",
232
- "croner": "^9.1.0",
233
233
  "chalk": "^5.6.2",
234
+ "croner": "^9.1.0",
234
235
  "csv-parser": "^3.2.0",
235
236
  "dotenv": "^17.3.1",
236
237
  "exceljs": "^4.4.0",