@juspay/neurolink 9.56.2 → 9.57.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 (66) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/auth/AuthProviderFactory.d.ts +3 -3
  3. package/dist/auth/providers/BaseAuthProvider.d.ts +2 -2
  4. package/dist/auth/providers/BaseAuthProvider.js +1 -1
  5. package/dist/auth/serverBridge.d.ts +2 -2
  6. package/dist/browser/neurolink.min.js +258 -258
  7. package/dist/cli/factories/commandFactory.js +32 -8
  8. package/dist/cli/loop/optionsSchema.js +4 -0
  9. package/dist/cli/parser.js +3 -3
  10. package/dist/dynamic/dynamicResolver.d.ts +282 -0
  11. package/dist/dynamic/dynamicResolver.js +633 -0
  12. package/dist/dynamic/index.d.ts +10 -0
  13. package/dist/dynamic/index.js +12 -0
  14. package/dist/dynamic/resolution.d.ts +17 -0
  15. package/dist/dynamic/resolution.js +21 -0
  16. package/dist/evaluation/index.js +1 -1
  17. package/dist/index.js +19 -2
  18. package/dist/lib/auth/AuthProviderFactory.d.ts +3 -3
  19. package/dist/lib/auth/providers/BaseAuthProvider.d.ts +2 -2
  20. package/dist/lib/auth/providers/BaseAuthProvider.js +1 -1
  21. package/dist/lib/auth/serverBridge.d.ts +2 -2
  22. package/dist/lib/dynamic/dynamicResolver.d.ts +282 -0
  23. package/dist/lib/dynamic/dynamicResolver.js +634 -0
  24. package/dist/lib/dynamic/index.d.ts +10 -0
  25. package/dist/lib/dynamic/index.js +13 -0
  26. package/dist/lib/dynamic/resolution.d.ts +17 -0
  27. package/dist/lib/dynamic/resolution.js +22 -0
  28. package/dist/lib/evaluation/index.js +1 -1
  29. package/dist/lib/index.js +19 -2
  30. package/dist/lib/mcp/mcpServerBase.d.ts +1 -1
  31. package/dist/lib/mcp/mcpServerBase.js +1 -1
  32. package/dist/lib/neurolink.d.ts +12 -4
  33. package/dist/lib/neurolink.js +79 -6
  34. package/dist/lib/observability/exporters/baseExporter.d.ts +1 -1
  35. package/dist/lib/observability/exporters/baseExporter.js +1 -1
  36. package/dist/lib/types/auth.d.ts +6 -6
  37. package/dist/lib/types/config.d.ts +4 -4
  38. package/dist/lib/types/dynamic.d.ts +98 -0
  39. package/dist/lib/types/dynamic.js +10 -0
  40. package/dist/lib/types/generate.d.ts +29 -0
  41. package/dist/lib/types/index.d.ts +1 -0
  42. package/dist/lib/types/index.js +2 -0
  43. package/dist/lib/types/scorer.d.ts +1 -1
  44. package/dist/lib/types/scorer.js +1 -1
  45. package/dist/lib/types/span.d.ts +1 -1
  46. package/dist/lib/types/span.js +1 -1
  47. package/dist/lib/types/stream.d.ts +6 -0
  48. package/dist/mcp/mcpServerBase.d.ts +1 -1
  49. package/dist/mcp/mcpServerBase.js +1 -1
  50. package/dist/neurolink.d.ts +12 -4
  51. package/dist/neurolink.js +79 -6
  52. package/dist/observability/exporters/baseExporter.d.ts +1 -1
  53. package/dist/observability/exporters/baseExporter.js +1 -1
  54. package/dist/types/auth.d.ts +6 -6
  55. package/dist/types/config.d.ts +4 -4
  56. package/dist/types/dynamic.d.ts +98 -0
  57. package/dist/types/dynamic.js +9 -0
  58. package/dist/types/generate.d.ts +29 -0
  59. package/dist/types/index.d.ts +1 -0
  60. package/dist/types/index.js +2 -0
  61. package/dist/types/scorer.d.ts +1 -1
  62. package/dist/types/scorer.js +1 -1
  63. package/dist/types/span.d.ts +1 -1
  64. package/dist/types/span.js +1 -1
  65. package/dist/types/stream.d.ts +6 -0
  66. package/package.json +1 -1
@@ -14,7 +14,7 @@ export * from "./pipeline/index.js";
14
14
  export * from "./reporting/index.js";
15
15
  // Re-export scorers
16
16
  export * from "./scorers/index.js";
17
- // Re-export Factory and Registry (Mastra-inspired patterns)
17
+ // Re-export Factory and Registry
18
18
  export { BatchEvaluator } from "./BatchEvaluator.js";
19
19
  export { EvaluationAggregator } from "./EvaluationAggregator.js";
20
20
  export { EvaluatorFactory, getEvaluatorFactory } from "./EvaluatorFactory.js";
package/dist/lib/index.js CHANGED
@@ -37,7 +37,7 @@ export { AIProviderFactory };
37
37
  export { GoogleTTSHandler } from "./adapters/tts/googleTTSHandler.js";
38
38
  // Config Manager export
39
39
  export { NeuroLinkConfigManager as ConfigManager } from "./config/configManager.js";
40
- // Core Infrastructure exports (Mastra-inspired patterns)
40
+ // Core Infrastructure exports (factory + registry patterns)
41
41
  export { BaseFactory, BaseRegistry, NeuroLinkFeatureError, createErrorFactory, withRetry, TypedEventEmitter, } from "./core/infrastructure/index.js";
42
42
  // ============================================================================
43
43
  // CLIENT SDK EXPORTS - Type-safe API access for browser and Node.js
@@ -107,6 +107,23 @@ export { SpanSerializer } from "./observability/utils/spanSerializer.js";
107
107
  // Middleware exports
108
108
  // Version
109
109
  export const VERSION = "1.0.0";
110
+ // ============================================================================
111
+ // Dynamic Arguments
112
+ // ============================================================================
113
+ //
114
+ // Dynamic arguments let you pass functions instead of static values to
115
+ // generate() and stream(). Resolution happens automatically before
116
+ // provider dispatch. Pass dynamicContext inline for per-request
117
+ // user/tenant/session context that dynamic functions can read.
118
+ //
119
+ // Example:
120
+ // await neurolink.generate({
121
+ // input: { text: "Hello" },
122
+ // model: (ctx) => ctx.requestContext.tenant?.plan === "enterprise"
123
+ // ? "gpt-4o" : "gpt-4o-mini",
124
+ // dynamicContext: { tenant: { id: "t1", plan: "enterprise" } },
125
+ // });
126
+ // ============================================================================
110
127
  /**
111
128
  * Quick start factory function for creating AI provider instances.
112
129
  *
@@ -348,7 +365,7 @@ export async function getTelemetryStatus() {
348
365
  export {
349
366
  // Main Evaluator
350
367
  Evaluator,
351
- // Factory and Registry (Mastra-inspired patterns)
368
+ // Factory and Registry
352
369
  EvaluationAggregator, EvaluatorFactory, getEvaluatorFactory, getEvaluatorRegistry,
353
370
  // Error utilities
354
371
  evaluationErrors, isRetryableEvaluationError, isEvaluationError, createEvaluationFailedError, createParseError, createStrategyNotFoundError, createProviderError, createMaxRetriesExceededError, createBatchEvaluationError, createConfigurationError, contextToErrorContext,
@@ -4,7 +4,7 @@
4
4
  * Abstract base class for creating custom MCP servers with consistent patterns
5
5
  * for tool registration, execution, and lifecycle management.
6
6
  *
7
- * Implements Mastra-style MCPServerBase features including:
7
+ * Implements MCPServerBase features including:
8
8
  * - Tool annotation support (readOnlyHint, destructiveHint, idempotentHint)
9
9
  * - Lifecycle hooks (onInit, onStart, onStop)
10
10
  * - Event emission for tool operations
@@ -4,7 +4,7 @@
4
4
  * Abstract base class for creating custom MCP servers with consistent patterns
5
5
  * for tool registration, execution, and lifecycle management.
6
6
  *
7
- * Implements Mastra-style MCPServerBase features including:
7
+ * Implements MCPServerBase features including:
8
8
  * - Tool annotation support (readOnlyHint, destructiveHint, idempotentHint)
9
9
  * - Lifecycle hooks (onInit, onStart, onStop)
10
10
  * - Event emission for tool operations
@@ -5,11 +5,12 @@
5
5
  * Enhanced AI provider system with natural MCP tool access.
6
6
  * Uses real MCP infrastructure for tool discovery and execution.
7
7
  */
8
- import type { CompactionConfig, CompactionResult, SpanData, ObservabilityConfig, MetricsSummary, MCPToolAnnotations, TraceView, AuthenticatedContext, MastraAuthProvider, JsonObject, NeuroLinkEvents, TypedEventEmitter, MCPEnhancementsConfig, NeuroLinkAuthConfig, NeurolinkConstructorConfig, ChatMessage, ExternalMCPOperationResult, ExternalMCPServerInstance, ExternalMCPToolInfo, GenerateOptions, GenerateResult, ProviderStatus, TextGenerationOptions, TextGenerationResult, MCPExecutableTool, MCPServerInfo, MCPStatus, StreamOptions, StreamResult, ToolExecutionContext, ToolExecutionSummary, ToolInfo, ToolRegistrationOptions, BatchOperationResult } from "./types/index.js";
8
+ import type { CompactionConfig, CompactionResult, SpanData, ObservabilityConfig, MetricsSummary, MCPToolAnnotations, TraceView, AuthenticatedContext, AuthProvider, JsonObject, NeuroLinkEvents, TypedEventEmitter, MCPEnhancementsConfig, NeuroLinkAuthConfig, NeurolinkConstructorConfig, ChatMessage, ExternalMCPOperationResult, ExternalMCPServerInstance, ExternalMCPToolInfo, GenerateOptions, GenerateResult, ProviderStatus, TextGenerationOptions, TextGenerationResult, MCPExecutableTool, MCPServerInfo, MCPStatus, StreamOptions, StreamResult, ToolExecutionContext, ToolExecutionSummary, ToolInfo, ToolRegistrationOptions, BatchOperationResult } from "./types/index.js";
9
9
  import { ConversationMemoryManager } from "./core/conversationMemoryManager.js";
10
10
  import type { RedisConversationMemoryManager } from "./core/redisConversationMemoryManager.js";
11
11
  import { ExternalServerManager } from "./mcp/externalServerManager.js";
12
12
  import { MCPToolRegistry } from "./mcp/toolRegistry.js";
13
+ import type { DynamicOptions } from "./types/index.js";
13
14
  import { TaskManager } from "./tasks/taskManager.js";
14
15
  export declare class NeuroLink {
15
16
  private mcpInitialized;
@@ -539,7 +540,7 @@ export declare class NeuroLink {
539
540
  * @see {@link stream} for streaming generation
540
541
  * @since 1.0.0
541
542
  */
542
- generate(optionsOrPrompt: GenerateOptions | string): Promise<GenerateResult>;
543
+ generate(optionsOrPrompt: GenerateOptions | DynamicOptions | string): Promise<GenerateResult>;
543
544
  private executeGenerateWithMetricsContext;
544
545
  private executeGenerateRequest;
545
546
  private prepareGenerateRequest;
@@ -695,7 +696,7 @@ export declare class NeuroLink {
695
696
  * @throws {Error} When all providers fail to generate content
696
697
  * @throws {Error} When conversation memory operations fail (if enabled)
697
698
  */
698
- stream(options: StreamOptions): Promise<StreamResult>;
699
+ stream(options: StreamOptions | DynamicOptions): Promise<StreamResult>;
699
700
  private executeStreamRequest;
700
701
  private validateStreamRequestOptions;
701
702
  private maybeHandleWorkflowStreamRequest;
@@ -1959,7 +1960,7 @@ export declare class NeuroLink {
1959
1960
  /**
1960
1961
  * Get the currently configured authentication provider
1961
1962
  */
1962
- getAuthProvider(): MastraAuthProvider | undefined;
1963
+ getAuthProvider(): AuthProvider | undefined;
1963
1964
  /**
1964
1965
  * Lazily initialize the auth provider from pendingAuthConfig.
1965
1966
  * Called on first use (generate/stream with auth token) to avoid
@@ -1993,6 +1994,13 @@ export declare class NeuroLink {
1993
1994
  * @returns The ExternalServerManager instance
1994
1995
  */
1995
1996
  getExternalServerManager(): ExternalServerManager;
1997
+ private buildResolutionContext;
1998
+ /**
1999
+ * Resolve dynamic arguments in GenerateOptions, mutating the options in place.
2000
+ * Only resolves fields that are functions; static values pass through unchanged.
2001
+ */
2002
+ private resolveDynamicOptions;
2003
+ private resolveDynamicFields;
1996
2004
  }
1997
2005
  export declare const neurolink: NeuroLink;
1998
2006
  export default neurolink;
@@ -47,6 +47,8 @@ import { ToolRouter } from "./mcp/routing/index.js";
47
47
  import { directToolsServer } from "./mcp/servers/agent/directToolsServer.js";
48
48
  import { inferAnnotations, isSafeToRetry } from "./mcp/toolAnnotations.js";
49
49
  import { MCPToolRegistry } from "./mcp/toolRegistry.js";
50
+ // Dynamic argument resolution imports
51
+ import { resolveDynamicArgument } from "./dynamic/dynamicResolver.js";
50
52
  import { initializeHippocampus } from "./memory/hippocampusInitializer.js";
51
53
  import { createMemoryRetrievalTools } from "./memory/memoryRetrievalTools.js";
52
54
  import { getMetricsAggregator, MetricsAggregator, } from "./observability/metricsAggregator.js";
@@ -2658,8 +2660,10 @@ Current user's request: ${currentInput}`;
2658
2660
  return metricsTraceContextStorage.run(this.createMetricsTraceContext(), () => this.executeGenerateRequest(optionsOrPrompt, generateSpan));
2659
2661
  }
2660
2662
  async executeGenerateRequest(optionsOrPrompt, generateSpan) {
2663
+ let resolvedOptions;
2661
2664
  try {
2662
2665
  const { options, originalPrompt } = await this.prepareGenerateRequest(optionsOrPrompt, generateSpan);
2666
+ resolvedOptions = options;
2663
2667
  const earlyResult = await this.maybeHandleEarlyGenerateResult(options, generateSpan);
2664
2668
  if (earlyResult) {
2665
2669
  generateSpan.setStatus({ code: SpanStatusCode.OK });
@@ -2680,7 +2684,7 @@ Current user's request: ${currentInput}`;
2680
2684
  generateSpan.setAttribute("neurolink.context.estimated_tokens", error.estimatedTokens);
2681
2685
  generateSpan.setAttribute("neurolink.context.available_tokens", error.availableTokens);
2682
2686
  }
2683
- this.emitGenerateErrorEvent(optionsOrPrompt, error);
2687
+ this.emitGenerateErrorEvent((resolvedOptions ?? optionsOrPrompt), error);
2684
2688
  throw error;
2685
2689
  }
2686
2690
  finally {
@@ -2693,6 +2697,8 @@ Current user's request: ${currentInput}`;
2693
2697
  const options = typeof optionsOrPrompt === "string"
2694
2698
  ? { input: { text: optionsOrPrompt } }
2695
2699
  : { ...optionsOrPrompt };
2700
+ // Dynamic argument resolution — resolve any function-valued options before downstream use
2701
+ await this.resolveDynamicOptions(options);
2696
2702
  options.model = resolveModel(options.model, this.modelAliasConfig);
2697
2703
  this._disableToolCacheForCurrentRequest = !!options.disableToolCache;
2698
2704
  generateSpan.setAttribute("neurolink.provider", options.provider || "default");
@@ -2839,6 +2845,7 @@ Current user's request: ${currentInput}`;
2839
2845
  maxSteps: options.maxSteps,
2840
2846
  toolChoice: options.toolChoice,
2841
2847
  prepareStep: options.prepareStep,
2848
+ enabledToolNames: options.enabledToolNames,
2842
2849
  enableAnalytics: options.enableAnalytics,
2843
2850
  enableEvaluation: options.enableEvaluation,
2844
2851
  context: options.context,
@@ -4331,13 +4338,18 @@ Current user's request: ${currentInput}`;
4331
4338
  * Used to filter the tool list before building the system prompt.
4332
4339
  */
4333
4340
  applyToolInfoFiltering(tools, options) {
4334
- if ((!options.toolFilter || options.toolFilter.length === 0) &&
4341
+ // enabledToolNames is an additional whitelist — merged into toolFilter
4342
+ const whitelist = [
4343
+ ...(options.toolFilter ?? []),
4344
+ ...(options.enabledToolNames ?? []),
4345
+ ];
4346
+ if (whitelist.length === 0 &&
4335
4347
  (!options.excludeTools || options.excludeTools.length === 0)) {
4336
4348
  return tools;
4337
4349
  }
4338
4350
  let filtered = tools;
4339
- if (options.toolFilter && options.toolFilter.length > 0) {
4340
- const allowSet = new Set(options.toolFilter);
4351
+ if (whitelist.length > 0) {
4352
+ const allowSet = new Set(whitelist);
4341
4353
  filtered = filtered.filter((t) => allowSet.has(t.name));
4342
4354
  }
4343
4355
  if (options.excludeTools && options.excludeTools.length > 0) {
@@ -4493,12 +4505,16 @@ Current user's request: ${currentInput}`;
4493
4505
  disableTools: options.disableTools,
4494
4506
  enableAnalytics: options.enableAnalytics,
4495
4507
  enableEvaluation: options.enableEvaluation,
4496
- contextKeys: options.context ? Object.keys(options.context) : [],
4508
+ contextKeys: options.context
4509
+ ? Object.keys(options.context ?? {})
4510
+ : [],
4497
4511
  optionKeys: Object.keys(options),
4498
4512
  });
4499
4513
  return metricsTraceContextStorage.run(this.createMetricsTraceContext(), () => this.executeStreamRequest({ ...options }));
4500
4514
  }
4501
4515
  async executeStreamRequest(options) {
4516
+ // Dynamic argument resolution — resolve any function-valued options before downstream use
4517
+ await this.resolveDynamicOptions(options);
4502
4518
  const streamSpan = tracers.sdk.startSpan("neurolink.stream", {
4503
4519
  kind: SpanKind.INTERNAL,
4504
4520
  attributes: {
@@ -8974,7 +8990,7 @@ Current user's request: ${currentInput}`;
8974
8990
  async initializeAuthProviderFromConfig(config) {
8975
8991
  let provider;
8976
8992
  let providerType;
8977
- // Duck-type check: direct MastraAuthProvider instance
8993
+ // Duck-type check: direct AuthProvider instance
8978
8994
  if ("authenticateToken" in config &&
8979
8995
  typeof config.authenticateToken === "function") {
8980
8996
  provider = config;
@@ -9075,6 +9091,63 @@ Current user's request: ${currentInput}`;
9075
9091
  getExternalServerManager() {
9076
9092
  return this.externalServerManager;
9077
9093
  }
9094
+ // ==========================================================================
9095
+ // Dynamic Argument Resolution
9096
+ // ==========================================================================
9097
+ buildResolutionContext(signal, inlineContext) {
9098
+ return {
9099
+ requestContext: inlineContext || {},
9100
+ signal,
9101
+ };
9102
+ }
9103
+ /**
9104
+ * Resolve dynamic arguments in GenerateOptions, mutating the options in place.
9105
+ * Only resolves fields that are functions; static values pass through unchanged.
9106
+ */
9107
+ async resolveDynamicOptions(options) {
9108
+ const dynamicFields = [
9109
+ "model",
9110
+ "provider",
9111
+ "temperature",
9112
+ "maxTokens",
9113
+ "systemPrompt",
9114
+ "timeout",
9115
+ "thinkingLevel",
9116
+ "disableTools",
9117
+ "enableAnalytics",
9118
+ "enableEvaluation",
9119
+ ];
9120
+ const hasDynamic = dynamicFields.some((f) => typeof options[f] === "function") ||
9121
+ typeof options.tools === "function";
9122
+ if (!hasDynamic) {
9123
+ return;
9124
+ }
9125
+ const inlineCtx = options.dynamicContext;
9126
+ await this.resolveDynamicFields(options, dynamicFields, inlineCtx);
9127
+ }
9128
+ async resolveDynamicFields(options, dynamicFields, inlineContext) {
9129
+ const resolutionContext = this.buildResolutionContext(options.abortSignal, inlineContext);
9130
+ logger.debug("[NeuroLink] Resolving dynamic arguments");
9131
+ await Promise.all(dynamicFields.map(async (field) => {
9132
+ if (typeof options[field] === "function") {
9133
+ const result = await resolveDynamicArgument(options[field], resolutionContext);
9134
+ options[field] = result.value;
9135
+ logger.debug(`[NeuroLink] Resolved dynamic ${field}: ${result.resolutionType}`);
9136
+ }
9137
+ }));
9138
+ // Handle dynamic tools → enabledToolNames mapping.
9139
+ // Per DynamicOptions.tools: DynamicArgument<string[]>, the resolver
9140
+ // must return an array of tool names. Anything else is a contract
9141
+ // violation — fail fast rather than silently disabling tooling.
9142
+ if (typeof options.tools === "function") {
9143
+ const result = await resolveDynamicArgument(options.tools, resolutionContext);
9144
+ if (!Array.isArray(result.value)) {
9145
+ throw new TypeError(`Dynamic tools resolver must return string[] (tool names), got ${typeof result.value === "object" ? "object" : typeof result.value}`);
9146
+ }
9147
+ options.enabledToolNames = result.value;
9148
+ delete options.tools;
9149
+ }
9150
+ }
9078
9151
  }
9079
9152
  // Create default instance
9080
9153
  export const neurolink = new NeuroLink();
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Abstract base class for all observability exporters
3
- * Follows NeuroLink's factory pattern and Mastra's unified exporter interface
3
+ * Follows NeuroLink's factory pattern with a unified exporter interface
4
4
  */
5
5
  import type { ExporterConfig, ExporterHealthStatus, ExportResult, SpanData } from "../../types/index.js";
6
6
  /**
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Abstract base class for all observability exporters
3
- * Follows NeuroLink's factory pattern and Mastra's unified exporter interface
3
+ * Follows NeuroLink's factory pattern with a unified exporter interface
4
4
  */
5
5
  import { logger } from "../../utils/logger.js";
6
6
  /**
@@ -490,7 +490,7 @@ export type PermissionDefinition = {
490
490
  */
491
491
  export type AuthMiddlewareOptions = {
492
492
  /** Auth provider instance */
493
- provider: MastraAuthProvider;
493
+ provider: AuthProvider;
494
494
  /** Routes to exclude from authentication */
495
495
  excludePaths?: string[];
496
496
  /** Whether auth is optional (continue if no token) */
@@ -729,7 +729,7 @@ export type CustomAuthConfig = {
729
729
  createSession?: (user: AuthUser, context?: AuthRequestContext) => Promise<AuthSession>;
730
730
  };
731
731
  /**
732
- * Configuration for MastraAuthProvider.
732
+ * Configuration for AuthProvider.
733
733
  *
734
734
  * Discriminated union of base + each provider-specific config so that
735
735
  * provider factories receive the properly typed config without requiring
@@ -819,7 +819,7 @@ export type AuthEventHandler = (event: AuthEventData) => void | Promise<void>;
819
819
  /**
820
820
  * Auth provider factory function type
821
821
  */
822
- export type AuthProviderFactoryFn = (config: AuthProviderConfig) => Promise<MastraAuthProvider>;
822
+ export type AuthProviderFactoryFn = (config: AuthProviderConfig) => Promise<AuthProvider>;
823
823
  /**
824
824
  * Auth health check result
825
825
  */
@@ -973,7 +973,7 @@ export type AuthLifecycle = {
973
973
  * Composed from focused sub-types so consumers can depend on only the
974
974
  * slice they need (e.g. `AuthTokenValidator` for token-only middleware).
975
975
  *
976
- * Implements Mastra-style auth provider pattern with unified methods for:
976
+ * Unified auth provider interface covering:
977
977
  * - Token validation (AuthTokenValidator)
978
978
  * - User authorization (AuthUserAuthorizer)
979
979
  * - Session management (AuthSessionManager)
@@ -981,7 +981,7 @@ export type AuthLifecycle = {
981
981
  * - User management (AuthUserManager)
982
982
  * - Lifecycle (AuthLifecycle)
983
983
  */
984
- export type MastraAuthProvider = AuthTokenValidator & AuthUserAuthorizer & AuthSessionManager & AuthRequestHandler & AuthUserManager & AuthLifecycle & {
984
+ export type AuthProvider = AuthTokenValidator & AuthUserAuthorizer & AuthSessionManager & AuthRequestHandler & AuthUserManager & AuthLifecycle & {
985
985
  /** Provider type identifier */
986
986
  readonly type: AuthProviderType;
987
987
  /** Provider configuration */
@@ -1019,7 +1019,7 @@ export type AuthJWKSCacheEntry = {
1019
1019
  expiresAt: number;
1020
1020
  };
1021
1021
  /** Async constructor for an auth provider given its config. */
1022
- export type AuthProviderConstructor = (config: AuthProviderConfig) => Promise<MastraAuthProvider>;
1022
+ export type AuthProviderConstructor = (config: AuthProviderConfig) => Promise<AuthProvider>;
1023
1023
  /** Registration row for an auth provider in AuthProviderFactory. */
1024
1024
  export type AuthProviderRegistration = {
1025
1025
  factory: AuthProviderConstructor;
@@ -7,7 +7,7 @@ import type { TaskManagerConfig } from "./task.js";
7
7
  import type { HITLConfig } from "../types/hitl.js";
8
8
  import type { ConversationMemoryConfig } from "./conversation.js";
9
9
  import type { ObservabilityConfig } from "./observability.js";
10
- import type { MastraAuthProvider, AuthProviderType, AuthProviderConfig, Auth0Config, ClerkConfig, FirebaseConfig, SupabaseConfig, WorkOSConfig, BetterAuthConfig, JWTConfig, OAuth2Config, CognitoConfig, KeycloakConfig, AuthenticatedContext } from "./auth.js";
10
+ import type { AuthProvider, AuthProviderType, AuthProviderConfig, Auth0Config, ClerkConfig, FirebaseConfig, SupabaseConfig, WorkOSConfig, BetterAuthConfig, JWTConfig, OAuth2Config, CognitoConfig, KeycloakConfig, AuthenticatedContext } from "./auth.js";
11
11
  import type { NeurolinkCredentials } from "./providers.js";
12
12
  /**
13
13
  * Main NeuroLink configuration type
@@ -130,8 +130,8 @@ export type MCPEnhancementsConfig = {
130
130
  /**
131
131
  * Authentication configuration for NeuroLink SDK
132
132
  */
133
- export type NeuroLinkAuthConfig = MastraAuthProvider | {
134
- provider: MastraAuthProvider;
133
+ export type NeuroLinkAuthConfig = AuthProvider | {
134
+ provider: AuthProvider;
135
135
  } | {
136
136
  type: "auth0";
137
137
  config: Auth0Config;
@@ -169,7 +169,7 @@ export type NeuroLinkAuthConfig = MastraAuthProvider | {
169
169
  /**
170
170
  * Re-export auth types for convenience
171
171
  */
172
- export type { MastraAuthProvider, AuthProviderType, AuthProviderConfig, AuthenticatedContext, };
172
+ export type { AuthProvider, AuthProviderType, AuthProviderConfig, AuthenticatedContext, };
173
173
  /**
174
174
  * Provider-specific configuration
175
175
  */
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Dynamic Arguments Type Definitions
3
+ *
4
+ * Pass functions instead of static values to generate() and stream().
5
+ * Functions are resolved at runtime before provider dispatch.
6
+ *
7
+ * @module types/dynamic
8
+ */
9
+ import type { AIProviderName } from "../constants/enums.js";
10
+ /**
11
+ * Context passed to context-aware dynamic argument functions.
12
+ * `requestContext` is whatever the consumer passed as `dynamicContext` —
13
+ * NeuroLink does not prescribe its shape.
14
+ */
15
+ export type DynamicResolutionContext = {
16
+ /** Consumer-provided context (any shape) */
17
+ requestContext: Record<string, unknown>;
18
+ /** Abort signal for cancellation */
19
+ signal?: AbortSignal;
20
+ };
21
+ /**
22
+ * A value that can be static, a function, or a context-aware function.
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * // Static
27
+ * model: "gpt-4o"
28
+ *
29
+ * // Function
30
+ * model: () => process.env.MODEL || "gpt-4o"
31
+ *
32
+ * // Context-aware
33
+ * model: (ctx) => ctx.requestContext.plan === "enterprise" ? "gpt-4o" : "gpt-4o-mini"
34
+ * ```
35
+ */
36
+ export type DynamicArgument<T> = T | (() => T) | (() => Promise<T>) | ((context: DynamicResolutionContext) => T) | ((context: DynamicResolutionContext) => Promise<T>);
37
+ /**
38
+ * Dynamic options for generate() and stream() — pass functions
39
+ * instead of static values for context-aware resolution.
40
+ */
41
+ export type DynamicOptions = {
42
+ model?: DynamicArgument<string>;
43
+ provider?: DynamicArgument<AIProviderName | string>;
44
+ temperature?: DynamicArgument<number>;
45
+ maxTokens?: DynamicArgument<number>;
46
+ systemPrompt?: DynamicArgument<string>;
47
+ /**
48
+ * Resolves to a `string[]` of tool names to enable.
49
+ * The resolved array is merged into `enabledToolNames` (and from there
50
+ * into `toolFilter`) — it does NOT replace `GenerateOptions.tools`,
51
+ * which is a `Record<string, Tool>` map of tool definitions.
52
+ */
53
+ tools?: DynamicArgument<string[]>;
54
+ timeout?: DynamicArgument<number>;
55
+ thinkingLevel?: DynamicArgument<"minimal" | "low" | "medium" | "high">;
56
+ disableTools?: DynamicArgument<boolean>;
57
+ enableAnalytics?: DynamicArgument<boolean>;
58
+ enableEvaluation?: DynamicArgument<boolean>;
59
+ input: {
60
+ text: string;
61
+ images?: Array<Buffer | string>;
62
+ files?: Array<Buffer | string>;
63
+ };
64
+ /**
65
+ * Context passed to dynamic resolver functions — any shape you want.
66
+ *
67
+ * This is intentionally separate from `GenerateOptions.context` (which is
68
+ * for telemetry/tracing metadata). If your resolvers need values from
69
+ * telemetry context (sessionId, userId, etc.), pass them here as well.
70
+ */
71
+ dynamicContext?: Record<string, unknown>;
72
+ };
73
+ export type ResolutionOptions = {
74
+ timeout?: number;
75
+ cache?: boolean;
76
+ cacheKey?: string;
77
+ cacheTtl?: number;
78
+ defaultValue?: unknown;
79
+ throwOnError?: boolean;
80
+ };
81
+ export type ResolutionResult<T> = {
82
+ value: T;
83
+ fromCache: boolean;
84
+ resolutionTime: number;
85
+ resolutionType: "static" | "sync-function" | "async-function" | "context-aware";
86
+ };
87
+ export type DynamicConfig<T> = {
88
+ [K in keyof T]: DynamicArgument<T[K]>;
89
+ };
90
+ export type ResolvedConfig<T> = {
91
+ [K in keyof T]: T[K] extends DynamicArgument<infer U> ? U : T[K];
92
+ };
93
+ export type DynamicCacheEntry<T> = {
94
+ value: T;
95
+ resolvedAt: number;
96
+ expiresAt: number;
97
+ key: string;
98
+ };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Dynamic Arguments Type Definitions
3
+ *
4
+ * Pass functions instead of static values to generate() and stream().
5
+ * Functions are resolved at runtime before provider dispatch.
6
+ *
7
+ * @module types/dynamic
8
+ */
9
+ export {};
10
+ //# sourceMappingURL=dynamic.js.map
@@ -230,6 +230,20 @@ export type GenerateOptions = {
230
230
  */
231
231
  schema?: ValidationSchema;
232
232
  tools?: Record<string, Tool>;
233
+ /**
234
+ * Filter available tools by name.
235
+ * Only tools with names in this array will be made available.
236
+ * Used by dynamic arguments to dynamically select which tools to enable.
237
+ *
238
+ * @example
239
+ * ```typescript
240
+ * await neurolink.generate({
241
+ * input: { text: "Search for information" },
242
+ * enabledToolNames: ["websearchGrounding", "readFile"]
243
+ * });
244
+ * ```
245
+ */
246
+ enabledToolNames?: string[];
233
247
  timeout?: number | string;
234
248
  /** AbortSignal for external cancellation of the AI call */
235
249
  abortSignal?: AbortSignal;
@@ -738,6 +752,21 @@ export type TextGenerationOptions = {
738
752
  director?: DirectorModeOptions;
739
753
  };
740
754
  tools?: Record<string, Tool>;
755
+ /**
756
+ * Filter available tools by name.
757
+ * Only tools with names in this array will be made available.
758
+ * Used by dynamic arguments to dynamically select which tools to enable.
759
+ * Merged into `toolFilter` before tool filtering runs.
760
+ *
761
+ * @example
762
+ * ```typescript
763
+ * await neurolink.generate({
764
+ * input: { text: "Search for information" },
765
+ * enabledToolNames: ["websearchGrounding", "readFile"]
766
+ * });
767
+ * ```
768
+ */
769
+ enabledToolNames?: string[];
741
770
  timeout?: number | string;
742
771
  /** AbortSignal for external cancellation of the AI call */
743
772
  abortSignal?: AbortSignal;
@@ -56,3 +56,4 @@ export * from "./exporter.js";
56
56
  export * from "./span.js";
57
57
  export * from "./imageGen.js";
58
58
  export * from "./elicitation.js";
59
+ export * from "./dynamic.js";
@@ -58,4 +58,6 @@ export * from "./exporter.js";
58
58
  export * from "./span.js";
59
59
  export * from "./imageGen.js";
60
60
  export * from "./elicitation.js";
61
+ // Dynamic Arguments types
62
+ export * from "./dynamic.js";
61
63
  //# sourceMappingURL=index.js.map
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @file Scorer type definitions for NeuroLink evaluation system
3
- * Mastra-style modular scorer interfaces and types
3
+ * Modular scorer interfaces and types
4
4
  */
5
5
  import type { JsonObject } from "./common.js";
6
6
  import type { EnhancedEvaluationContext } from "./evaluation.js";
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @file Scorer type definitions for NeuroLink evaluation system
3
- * Mastra-style modular scorer interfaces and types
3
+ * Modular scorer interfaces and types
4
4
  */
5
5
  export {};
6
6
  //# sourceMappingURL=scorer.js.map
@@ -4,7 +4,7 @@
4
4
  */
5
5
  /**
6
6
  * Span types for AI operations
7
- * Following Mastra's span categorization and OTel GenAI conventions
7
+ * Following OTel GenAI conventions for span categorization
8
8
  */
9
9
  export declare enum SpanType {
10
10
  /** Agent execution run (reserved for future multi-agent support) */
@@ -4,7 +4,7 @@
4
4
  */
5
5
  /**
6
6
  * Span types for AI operations
7
- * Following Mastra's span categorization and OTel GenAI conventions
7
+ * Following OTel GenAI conventions for span categorization
8
8
  */
9
9
  export var SpanType;
10
10
  (function (SpanType) {
@@ -330,6 +330,12 @@ export type StreamOptions = {
330
330
  } | undefined>;
331
331
  /** Include only these tools by name (whitelist). If set, only matching tools are available. */
332
332
  toolFilter?: string[];
333
+ /**
334
+ * Filter available tools by name.
335
+ * Used by dynamic arguments to dynamically select which tools to enable.
336
+ * Merged into `toolFilter` before tool filtering runs.
337
+ */
338
+ enabledToolNames?: string[];
333
339
  /** Exclude these tools by name (blacklist). Applied after toolFilter. */
334
340
  excludeTools?: string[];
335
341
  /** Disable tool result caching for this request (overrides global mcp.cache.enabled) */
@@ -4,7 +4,7 @@
4
4
  * Abstract base class for creating custom MCP servers with consistent patterns
5
5
  * for tool registration, execution, and lifecycle management.
6
6
  *
7
- * Implements Mastra-style MCPServerBase features including:
7
+ * Implements MCPServerBase features including:
8
8
  * - Tool annotation support (readOnlyHint, destructiveHint, idempotentHint)
9
9
  * - Lifecycle hooks (onInit, onStart, onStop)
10
10
  * - Event emission for tool operations
@@ -4,7 +4,7 @@
4
4
  * Abstract base class for creating custom MCP servers with consistent patterns
5
5
  * for tool registration, execution, and lifecycle management.
6
6
  *
7
- * Implements Mastra-style MCPServerBase features including:
7
+ * Implements MCPServerBase features including:
8
8
  * - Tool annotation support (readOnlyHint, destructiveHint, idempotentHint)
9
9
  * - Lifecycle hooks (onInit, onStart, onStop)
10
10
  * - Event emission for tool operations