@juspay/neurolink 9.75.0 → 9.77.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 (51) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/browser/neurolink.min.js +341 -341
  3. package/dist/core/baseProvider.js +29 -4
  4. package/dist/core/toolDedup.d.ts +51 -0
  5. package/dist/core/toolDedup.js +193 -0
  6. package/dist/index.d.ts +31 -0
  7. package/dist/index.js +35 -0
  8. package/dist/lib/core/baseProvider.js +29 -4
  9. package/dist/lib/core/toolDedup.d.ts +51 -0
  10. package/dist/lib/core/toolDedup.js +194 -0
  11. package/dist/lib/index.d.ts +31 -0
  12. package/dist/lib/index.js +35 -0
  13. package/dist/lib/neurolink.d.ts +36 -1
  14. package/dist/lib/neurolink.js +387 -90
  15. package/dist/lib/routing/index.d.ts +7 -0
  16. package/dist/lib/routing/index.js +8 -0
  17. package/dist/lib/routing/modelPool.d.ts +83 -0
  18. package/dist/lib/routing/modelPool.js +243 -0
  19. package/dist/lib/routing/requestRouter.d.ts +30 -0
  20. package/dist/lib/routing/requestRouter.js +81 -0
  21. package/dist/lib/types/config.d.ts +32 -2
  22. package/dist/lib/types/index.d.ts +3 -0
  23. package/dist/lib/types/index.js +5 -0
  24. package/dist/lib/types/modelPool.d.ts +47 -0
  25. package/dist/lib/types/modelPool.js +11 -0
  26. package/dist/lib/types/requestRouter.d.ts +75 -0
  27. package/dist/lib/types/requestRouter.js +16 -0
  28. package/dist/lib/types/toolDedup.d.ts +45 -0
  29. package/dist/lib/types/toolDedup.js +14 -0
  30. package/dist/lib/utils/providerErrorClassification.d.ts +24 -0
  31. package/dist/lib/utils/providerErrorClassification.js +89 -0
  32. package/dist/neurolink.d.ts +36 -1
  33. package/dist/neurolink.js +387 -90
  34. package/dist/routing/index.d.ts +7 -0
  35. package/dist/routing/index.js +7 -0
  36. package/dist/routing/modelPool.d.ts +83 -0
  37. package/dist/routing/modelPool.js +242 -0
  38. package/dist/routing/requestRouter.d.ts +30 -0
  39. package/dist/routing/requestRouter.js +80 -0
  40. package/dist/types/config.d.ts +32 -2
  41. package/dist/types/index.d.ts +3 -0
  42. package/dist/types/index.js +5 -0
  43. package/dist/types/modelPool.d.ts +47 -0
  44. package/dist/types/modelPool.js +10 -0
  45. package/dist/types/requestRouter.d.ts +75 -0
  46. package/dist/types/requestRouter.js +15 -0
  47. package/dist/types/toolDedup.d.ts +45 -0
  48. package/dist/types/toolDedup.js +13 -0
  49. package/dist/utils/providerErrorClassification.d.ts +24 -0
  50. package/dist/utils/providerErrorClassification.js +88 -0
  51. package/package.json +6 -2
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Shared provider-error classification utilities used by both neurolink.ts and
3
+ * the ModelPool routing subsystem.
4
+ *
5
+ * Extracted here to avoid duplication and to ensure that typed error classes
6
+ * (AuthenticationError, AuthorizationError, ModelAccessDeniedError) are
7
+ * checked consistently in both code paths.
8
+ */
9
+ /**
10
+ * Detects whether an error object looks like a model-access-denied condition.
11
+ * Matches LiteLLM "team not allowed" / "team can only access models=[...]"
12
+ * plus typed-error name/code markers when the full typed class is not present.
13
+ */
14
+ export declare function looksLikeModelAccessDenied(error: unknown): boolean;
15
+ /**
16
+ * Returns true when the error is definitively non-retryable: typed error
17
+ * classes (auth, access-denied, invalid-model), non-retryable HTTP status
18
+ * codes, or deterministic 400-class message patterns.
19
+ *
20
+ * NOTE: ContextBudgetExceededError is intentionally NOT non-retryable —
21
+ * each provider has its own context window, so a budget rejection on one
22
+ * provider does not preclude another provider accepting the same payload.
23
+ */
24
+ export declare function isNonRetryableProviderError(error: unknown): boolean;
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Shared provider-error classification utilities used by both neurolink.ts and
3
+ * the ModelPool routing subsystem.
4
+ *
5
+ * Extracted here to avoid duplication and to ensure that typed error classes
6
+ * (AuthenticationError, AuthorizationError, ModelAccessDeniedError) are
7
+ * checked consistently in both code paths.
8
+ */
9
+ import { AuthenticationError, AuthorizationError, InvalidModelError, ModelAccessDeniedError, } from "../types/index.js";
10
+ import { NON_RETRYABLE_HTTP_STATUS_CODES, isDeterministicClientErrorMessage, } from "./retryability.js";
11
+ /**
12
+ * Detects whether an error object looks like a model-access-denied condition.
13
+ * Matches LiteLLM "team not allowed" / "team can only access models=[...]"
14
+ * plus typed-error name/code markers when the full typed class is not present.
15
+ */
16
+ export function looksLikeModelAccessDenied(error) {
17
+ if (!error) {
18
+ return false;
19
+ }
20
+ const e = error;
21
+ if (e.name === "ModelAccessDeniedError") {
22
+ return true;
23
+ }
24
+ if (e.code === "MODEL_ACCESS_DENIED") {
25
+ return true;
26
+ }
27
+ const msg = typeof e.message === "string"
28
+ ? e.message
29
+ : error instanceof Error
30
+ ? error.message
31
+ : String(error);
32
+ if (!msg) {
33
+ return false;
34
+ }
35
+ const lower = msg.toLowerCase();
36
+ return ((lower.includes("team") && lower.includes("not allowed")) ||
37
+ lower.includes("team can only access") ||
38
+ /not\s+allowed\s+to\s+access\s+(this\s+)?model/i.test(msg));
39
+ }
40
+ /**
41
+ * Returns true when the error is definitively non-retryable: typed error
42
+ * classes (auth, access-denied, invalid-model), non-retryable HTTP status
43
+ * codes, or deterministic 400-class message patterns.
44
+ *
45
+ * NOTE: ContextBudgetExceededError is intentionally NOT non-retryable —
46
+ * each provider has its own context window, so a budget rejection on one
47
+ * provider does not preclude another provider accepting the same payload.
48
+ */
49
+ export function isNonRetryableProviderError(error) {
50
+ if (error instanceof InvalidModelError) {
51
+ return true;
52
+ }
53
+ if (error instanceof AuthenticationError) {
54
+ return true;
55
+ }
56
+ if (error instanceof AuthorizationError) {
57
+ return true;
58
+ }
59
+ if (error instanceof ModelAccessDeniedError) {
60
+ return true;
61
+ }
62
+ if (error && typeof error === "object") {
63
+ const err = error;
64
+ const status = typeof err.status === "number"
65
+ ? err.status
66
+ : typeof err.statusCode === "number"
67
+ ? err.statusCode
68
+ : undefined;
69
+ if (status !== undefined &&
70
+ NON_RETRYABLE_HTTP_STATUS_CODES.includes(status)) {
71
+ return true;
72
+ }
73
+ }
74
+ if (error instanceof Error) {
75
+ const msg = error.message;
76
+ if (msg.includes("NOT_FOUND") ||
77
+ msg.includes("Model Not Found") ||
78
+ msg.includes("model not found") ||
79
+ msg.includes("PERMISSION_DENIED") ||
80
+ msg.includes("UNAUTHENTICATED")) {
81
+ return true;
82
+ }
83
+ if (isDeterministicClientErrorMessage(msg)) {
84
+ return true;
85
+ }
86
+ }
87
+ return false;
88
+ }
89
+ //# sourceMappingURL=providerErrorClassification.js.map
@@ -5,7 +5,7 @@
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, 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, StreamGenerationEndContext, ToolRoutingServerDescriptor } 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, StreamGenerationEndContext, ToolRoutingServerDescriptor, ToolDedupConfig } 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";
@@ -102,12 +102,15 @@ export declare class NeuroLink {
102
102
  private conversationMemoryConfig?;
103
103
  private toolRoutingConfig?;
104
104
  private toolRoutingCacheInstance?;
105
+ private toolDedupConfig?;
105
106
  private enableOrchestration;
106
107
  private authProvider?;
107
108
  private pendingAuthConfig?;
108
109
  private authInitPromise?;
109
110
  private credentials?;
110
111
  private readonly fallbackConfig;
112
+ private readonly modelPool;
113
+ private readonly requestRouter;
111
114
  /**
112
115
  * Merge instance-level credentials with per-call credentials.
113
116
  *
@@ -611,6 +614,25 @@ export declare class NeuroLink {
611
614
  private maybeHandleEarlyGenerateResult;
612
615
  private runStandardGenerateRequest;
613
616
  private maybeApplyGenerateOrchestration;
617
+ /**
618
+ * Applies the host-configured `requestRouter` to `options` in place.
619
+ *
620
+ * The router is skipped when:
621
+ * - no `requestRouter` is configured on this instance, or
622
+ * - the caller explicitly set both `options.provider` AND `options.model`
623
+ * (we only skip the router if BOTH are set; a caller setting only one
624
+ * still lets the router fill in the other field).
625
+ *
626
+ * Fails open: any router error is logged at WARN level and the call
627
+ * continues with the original options unmodified.
628
+ *
629
+ * @param options — the mutable options object (generate or stream).
630
+ * @param promptText — the text prompt used to build the RouterInputContext.
631
+ * @param hasTools — true when at least one tool is available for this call.
632
+ * @param requiresVision — true when the call includes image attachments.
633
+ * @param thinkingLevel — optional thinking level string from the call options.
634
+ */
635
+ private applyRequestRouter;
614
636
  private prepareGenerateAugmentations;
615
637
  private buildGenerateTextOptions;
616
638
  private finalizeGenerateRequestResult;
@@ -1089,6 +1111,19 @@ export declare class NeuroLink {
1089
1111
  * @see {@link NeuroLink.executeTool} for events related to tool execution
1090
1112
  */
1091
1113
  getEventEmitter(): TypedEventEmitter<NeuroLinkEvents>;
1114
+ /**
1115
+ * Returns the instance-level tool-dedup configuration, or `undefined` when
1116
+ * toolDedup was not provided at construction time.
1117
+ *
1118
+ * The stored object is returned as-is whenever `toolDedup` was supplied,
1119
+ * including when `enabled: false` — only the complete absence of a `toolDedup`
1120
+ * option results in `undefined`.
1121
+ *
1122
+ * Called by `BaseProvider.applyToolFiltering` so the dedup pass uses the
1123
+ * same config for every generate/stream call without threading an extra
1124
+ * parameter through the full call stack.
1125
+ */
1126
+ getToolDedupConfig(): ToolDedupConfig | undefined;
1092
1127
  /**
1093
1128
  * Curator P1-1: synchronous credential health check for a single provider.
1094
1129
  *