@juspay/neurolink 7.36.0 → 7.37.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 (34) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/config/taskClassificationConfig.d.ts +51 -0
  3. package/dist/config/taskClassificationConfig.js +148 -0
  4. package/dist/lib/config/taskClassificationConfig.d.ts +51 -0
  5. package/dist/lib/config/taskClassificationConfig.js +148 -0
  6. package/dist/lib/neurolink.d.ts +20 -0
  7. package/dist/lib/neurolink.js +268 -5
  8. package/dist/lib/types/index.d.ts +2 -0
  9. package/dist/lib/types/index.js +2 -0
  10. package/dist/lib/types/taskClassificationTypes.d.ts +52 -0
  11. package/dist/lib/types/taskClassificationTypes.js +5 -0
  12. package/dist/lib/utils/modelRouter.d.ts +107 -0
  13. package/dist/lib/utils/modelRouter.js +292 -0
  14. package/dist/lib/utils/promptRedaction.d.ts +29 -0
  15. package/dist/lib/utils/promptRedaction.js +62 -0
  16. package/dist/lib/utils/taskClassificationUtils.d.ts +55 -0
  17. package/dist/lib/utils/taskClassificationUtils.js +149 -0
  18. package/dist/lib/utils/taskClassifier.d.ts +23 -0
  19. package/dist/lib/utils/taskClassifier.js +94 -0
  20. package/dist/neurolink.d.ts +20 -0
  21. package/dist/neurolink.js +268 -5
  22. package/dist/types/index.d.ts +2 -0
  23. package/dist/types/index.js +2 -0
  24. package/dist/types/taskClassificationTypes.d.ts +52 -0
  25. package/dist/types/taskClassificationTypes.js +5 -0
  26. package/dist/utils/modelRouter.d.ts +107 -0
  27. package/dist/utils/modelRouter.js +292 -0
  28. package/dist/utils/promptRedaction.d.ts +29 -0
  29. package/dist/utils/promptRedaction.js +62 -0
  30. package/dist/utils/taskClassificationUtils.d.ts +55 -0
  31. package/dist/utils/taskClassificationUtils.js +149 -0
  32. package/dist/utils/taskClassifier.d.ts +23 -0
  33. package/dist/utils/taskClassifier.js +94 -0
  34. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## [7.37.0](https://github.com/juspay/neurolink/compare/v7.36.0...v7.37.0) (2025-09-10)
2
+
3
+ ### Features
4
+
5
+ - **(sdk):** Add advanced orchestration of model and providers BZ-43839 ([840d697](https://github.com/juspay/neurolink/commit/840d697aa6ef3e5e4c511a9482fc7e80006d2534))
6
+
1
7
  ## [7.36.0](https://github.com/juspay/neurolink/compare/v7.35.0...v7.36.0) (2025-09-10)
2
8
 
3
9
  ### Features
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Task Classification Configuration
3
+ * Contains patterns, keywords, and scoring weights for task classification
4
+ */
5
+ /**
6
+ * Regular expression patterns that indicate fast response tasks
7
+ */
8
+ export declare const FAST_PATTERNS: RegExp[];
9
+ /**
10
+ * Regular expression patterns that indicate reasoning tasks
11
+ */
12
+ export declare const REASONING_PATTERNS: RegExp[];
13
+ /**
14
+ * Keywords that indicate fast tasks regardless of context
15
+ */
16
+ export declare const FAST_KEYWORDS: string[];
17
+ /**
18
+ * Keywords that indicate reasoning tasks regardless of context
19
+ */
20
+ export declare const REASONING_KEYWORDS: string[];
21
+ /**
22
+ * Scoring weights for different classification factors
23
+ */
24
+ export declare const SCORING_WEIGHTS: {
25
+ readonly SHORT_PROMPT_BONUS: 2;
26
+ readonly LONG_PROMPT_BONUS: 1;
27
+ readonly PATTERN_MATCH_SCORE: 3;
28
+ readonly KEYWORD_MATCH_SCORE: 1;
29
+ readonly MULTIPLE_QUESTIONS_BONUS: 1;
30
+ readonly MULTI_SENTENCE_BONUS: 1;
31
+ readonly TECHNICAL_DOMAIN_BONUS: 1;
32
+ readonly SIMPLE_DEFINITION_BONUS: 2;
33
+ };
34
+ /**
35
+ * Classification thresholds and constraints
36
+ */
37
+ export declare const CLASSIFICATION_THRESHOLDS: {
38
+ readonly SHORT_PROMPT_LENGTH: 50;
39
+ readonly LONG_PROMPT_LENGTH: 200;
40
+ readonly SIMPLE_DEFINITION_LENGTH: 100;
41
+ readonly MIN_CONFIDENCE: 0.6;
42
+ readonly MAX_CONFIDENCE: 0.95;
43
+ readonly DEFAULT_CONFIDENCE: 0.5;
44
+ };
45
+ /**
46
+ * Domain-specific patterns for enhanced classification
47
+ */
48
+ export declare const DOMAIN_PATTERNS: {
49
+ readonly TECHNICAL: RegExp;
50
+ readonly SIMPLE_DEFINITION: RegExp;
51
+ };
@@ -0,0 +1,148 @@
1
+ /**
2
+ * Task Classification Configuration
3
+ * Contains patterns, keywords, and scoring weights for task classification
4
+ */
5
+ /**
6
+ * Regular expression patterns that indicate fast response tasks
7
+ */
8
+ export const FAST_PATTERNS = [
9
+ // Greetings and social
10
+ /^(hi|hello|hey|good morning|good afternoon|good evening)/i,
11
+ /^(thanks?|thank you|thx)/i,
12
+ /^(yes|no|ok|okay|sure|fine)/i,
13
+ // Simple questions
14
+ /^what is\s+\w+\??$/i,
15
+ /^how are you/i,
16
+ /^tell me about\s+\w+$/i,
17
+ // Simple requests
18
+ /^(list|show|display)\s+/i,
19
+ /^give me\s+/i,
20
+ /^can you\s+(help|assist)/i,
21
+ // Simple definitions
22
+ /^define\s+/i,
23
+ /^meaning of\s+/i,
24
+ /^what does\s+\w+\s+mean/i,
25
+ // Quick facts
26
+ /^when (is|was|did)/i,
27
+ /^where (is|was)/i,
28
+ /^who (is|was)/i,
29
+ // Simple translations
30
+ /^translate\s+["'].*["']\s+to\s+\w+/i,
31
+ /^how do you say\s+/i,
32
+ ];
33
+ /**
34
+ * Regular expression patterns that indicate reasoning tasks
35
+ */
36
+ export const REASONING_PATTERNS = [
37
+ // Analysis and comparison
38
+ /\b(analyz|compar|evaluat|assess|examin)\w*/i,
39
+ /\b(pros and cons|advantages and disadvantages)/i,
40
+ /\b(better|worse|best|worst)\b.*\b(than|versus|vs)\b/i,
41
+ // Problem solving
42
+ /\b(solve|solution|problem|issue|challenge)\b/i,
43
+ /\b(how to|step by step|strategy|approach)\b/i,
44
+ /\b(optimize|improve|enhance|maximize|minimize)\b/i,
45
+ // Planning and design
46
+ /\b(plan|design|architect|structure|framework)\b/i,
47
+ /\b(implement|develop|build|create|construct)\b/i,
48
+ /\b(roadmap|timeline|schedule|phases)\b/i,
49
+ // Complex questions
50
+ /\b(why|explain|reason|cause|effect|impact)\b/i,
51
+ /\b(implications|consequences|considerations)\b/i,
52
+ /\b(should I|would you recommend|what if)\b/i,
53
+ // Research and investigation
54
+ /\b(research|investigate|explore|discover)\b/i,
55
+ /\b(evidence|proof|validate|verify)\b/i,
56
+ /\b(trends|patterns|insights|conclusions)\b/i,
57
+ // Business and strategy
58
+ /\b(business|strategy|market|competitive|financial)\b/i,
59
+ /\b(ROI|revenue|profit|investment|budget)\b/i,
60
+ /\b(stakeholder|customer|user experience|UX)\b/i,
61
+ // Technical complexity
62
+ /\b(algorithm|architecture|system|infrastructure)\b/i,
63
+ /\b(performance|scalability|security|reliability)\b/i,
64
+ /\b(integration|API|database|server)\b/i,
65
+ ];
66
+ /**
67
+ * Keywords that indicate fast tasks regardless of context
68
+ */
69
+ export const FAST_KEYWORDS = [
70
+ "quick",
71
+ "simple",
72
+ "brief",
73
+ "short",
74
+ "summary",
75
+ "overview",
76
+ "definition",
77
+ "meaning",
78
+ "list",
79
+ "show",
80
+ "display",
81
+ "name",
82
+ "tell",
83
+ "what",
84
+ "when",
85
+ "where",
86
+ "who",
87
+ "how many",
88
+ "count",
89
+ ];
90
+ /**
91
+ * Keywords that indicate reasoning tasks regardless of context
92
+ */
93
+ export const REASONING_KEYWORDS = [
94
+ "complex",
95
+ "detailed",
96
+ "comprehensive",
97
+ "thorough",
98
+ "in-depth",
99
+ "analyze",
100
+ "compare",
101
+ "evaluate",
102
+ "assess",
103
+ "research",
104
+ "investigate",
105
+ "strategy",
106
+ "plan",
107
+ "design",
108
+ "solve",
109
+ "optimize",
110
+ "recommend",
111
+ "explain",
112
+ "why",
113
+ "justify",
114
+ "pros",
115
+ "cons",
116
+ "trade-offs",
117
+ ];
118
+ /**
119
+ * Scoring weights for different classification factors
120
+ */
121
+ export const SCORING_WEIGHTS = {
122
+ SHORT_PROMPT_BONUS: 2,
123
+ LONG_PROMPT_BONUS: 1,
124
+ PATTERN_MATCH_SCORE: 3,
125
+ KEYWORD_MATCH_SCORE: 1,
126
+ MULTIPLE_QUESTIONS_BONUS: 1,
127
+ MULTI_SENTENCE_BONUS: 1,
128
+ TECHNICAL_DOMAIN_BONUS: 1,
129
+ SIMPLE_DEFINITION_BONUS: 2,
130
+ };
131
+ /**
132
+ * Classification thresholds and constraints
133
+ */
134
+ export const CLASSIFICATION_THRESHOLDS = {
135
+ SHORT_PROMPT_LENGTH: 50,
136
+ LONG_PROMPT_LENGTH: 200,
137
+ SIMPLE_DEFINITION_LENGTH: 100,
138
+ MIN_CONFIDENCE: 0.6,
139
+ MAX_CONFIDENCE: 0.95,
140
+ DEFAULT_CONFIDENCE: 0.5,
141
+ };
142
+ /**
143
+ * Domain-specific patterns for enhanced classification
144
+ */
145
+ export const DOMAIN_PATTERNS = {
146
+ TECHNICAL: /\b(code|programming|development|software)\b/i,
147
+ SIMPLE_DEFINITION: /\b(definition|meaning|what is)\b/i,
148
+ };
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Task Classification Configuration
3
+ * Contains patterns, keywords, and scoring weights for task classification
4
+ */
5
+ /**
6
+ * Regular expression patterns that indicate fast response tasks
7
+ */
8
+ export declare const FAST_PATTERNS: RegExp[];
9
+ /**
10
+ * Regular expression patterns that indicate reasoning tasks
11
+ */
12
+ export declare const REASONING_PATTERNS: RegExp[];
13
+ /**
14
+ * Keywords that indicate fast tasks regardless of context
15
+ */
16
+ export declare const FAST_KEYWORDS: string[];
17
+ /**
18
+ * Keywords that indicate reasoning tasks regardless of context
19
+ */
20
+ export declare const REASONING_KEYWORDS: string[];
21
+ /**
22
+ * Scoring weights for different classification factors
23
+ */
24
+ export declare const SCORING_WEIGHTS: {
25
+ readonly SHORT_PROMPT_BONUS: 2;
26
+ readonly LONG_PROMPT_BONUS: 1;
27
+ readonly PATTERN_MATCH_SCORE: 3;
28
+ readonly KEYWORD_MATCH_SCORE: 1;
29
+ readonly MULTIPLE_QUESTIONS_BONUS: 1;
30
+ readonly MULTI_SENTENCE_BONUS: 1;
31
+ readonly TECHNICAL_DOMAIN_BONUS: 1;
32
+ readonly SIMPLE_DEFINITION_BONUS: 2;
33
+ };
34
+ /**
35
+ * Classification thresholds and constraints
36
+ */
37
+ export declare const CLASSIFICATION_THRESHOLDS: {
38
+ readonly SHORT_PROMPT_LENGTH: 50;
39
+ readonly LONG_PROMPT_LENGTH: 200;
40
+ readonly SIMPLE_DEFINITION_LENGTH: 100;
41
+ readonly MIN_CONFIDENCE: 0.6;
42
+ readonly MAX_CONFIDENCE: 0.95;
43
+ readonly DEFAULT_CONFIDENCE: 0.5;
44
+ };
45
+ /**
46
+ * Domain-specific patterns for enhanced classification
47
+ */
48
+ export declare const DOMAIN_PATTERNS: {
49
+ readonly TECHNICAL: RegExp;
50
+ readonly SIMPLE_DEFINITION: RegExp;
51
+ };
@@ -0,0 +1,148 @@
1
+ /**
2
+ * Task Classification Configuration
3
+ * Contains patterns, keywords, and scoring weights for task classification
4
+ */
5
+ /**
6
+ * Regular expression patterns that indicate fast response tasks
7
+ */
8
+ export const FAST_PATTERNS = [
9
+ // Greetings and social
10
+ /^(hi|hello|hey|good morning|good afternoon|good evening)/i,
11
+ /^(thanks?|thank you|thx)/i,
12
+ /^(yes|no|ok|okay|sure|fine)/i,
13
+ // Simple questions
14
+ /^what is\s+\w+\??$/i,
15
+ /^how are you/i,
16
+ /^tell me about\s+\w+$/i,
17
+ // Simple requests
18
+ /^(list|show|display)\s+/i,
19
+ /^give me\s+/i,
20
+ /^can you\s+(help|assist)/i,
21
+ // Simple definitions
22
+ /^define\s+/i,
23
+ /^meaning of\s+/i,
24
+ /^what does\s+\w+\s+mean/i,
25
+ // Quick facts
26
+ /^when (is|was|did)/i,
27
+ /^where (is|was)/i,
28
+ /^who (is|was)/i,
29
+ // Simple translations
30
+ /^translate\s+["'].*["']\s+to\s+\w+/i,
31
+ /^how do you say\s+/i,
32
+ ];
33
+ /**
34
+ * Regular expression patterns that indicate reasoning tasks
35
+ */
36
+ export const REASONING_PATTERNS = [
37
+ // Analysis and comparison
38
+ /\b(analyz|compar|evaluat|assess|examin)\w*/i,
39
+ /\b(pros and cons|advantages and disadvantages)/i,
40
+ /\b(better|worse|best|worst)\b.*\b(than|versus|vs)\b/i,
41
+ // Problem solving
42
+ /\b(solve|solution|problem|issue|challenge)\b/i,
43
+ /\b(how to|step by step|strategy|approach)\b/i,
44
+ /\b(optimize|improve|enhance|maximize|minimize)\b/i,
45
+ // Planning and design
46
+ /\b(plan|design|architect|structure|framework)\b/i,
47
+ /\b(implement|develop|build|create|construct)\b/i,
48
+ /\b(roadmap|timeline|schedule|phases)\b/i,
49
+ // Complex questions
50
+ /\b(why|explain|reason|cause|effect|impact)\b/i,
51
+ /\b(implications|consequences|considerations)\b/i,
52
+ /\b(should I|would you recommend|what if)\b/i,
53
+ // Research and investigation
54
+ /\b(research|investigate|explore|discover)\b/i,
55
+ /\b(evidence|proof|validate|verify)\b/i,
56
+ /\b(trends|patterns|insights|conclusions)\b/i,
57
+ // Business and strategy
58
+ /\b(business|strategy|market|competitive|financial)\b/i,
59
+ /\b(ROI|revenue|profit|investment|budget)\b/i,
60
+ /\b(stakeholder|customer|user experience|UX)\b/i,
61
+ // Technical complexity
62
+ /\b(algorithm|architecture|system|infrastructure)\b/i,
63
+ /\b(performance|scalability|security|reliability)\b/i,
64
+ /\b(integration|API|database|server)\b/i,
65
+ ];
66
+ /**
67
+ * Keywords that indicate fast tasks regardless of context
68
+ */
69
+ export const FAST_KEYWORDS = [
70
+ "quick",
71
+ "simple",
72
+ "brief",
73
+ "short",
74
+ "summary",
75
+ "overview",
76
+ "definition",
77
+ "meaning",
78
+ "list",
79
+ "show",
80
+ "display",
81
+ "name",
82
+ "tell",
83
+ "what",
84
+ "when",
85
+ "where",
86
+ "who",
87
+ "how many",
88
+ "count",
89
+ ];
90
+ /**
91
+ * Keywords that indicate reasoning tasks regardless of context
92
+ */
93
+ export const REASONING_KEYWORDS = [
94
+ "complex",
95
+ "detailed",
96
+ "comprehensive",
97
+ "thorough",
98
+ "in-depth",
99
+ "analyze",
100
+ "compare",
101
+ "evaluate",
102
+ "assess",
103
+ "research",
104
+ "investigate",
105
+ "strategy",
106
+ "plan",
107
+ "design",
108
+ "solve",
109
+ "optimize",
110
+ "recommend",
111
+ "explain",
112
+ "why",
113
+ "justify",
114
+ "pros",
115
+ "cons",
116
+ "trade-offs",
117
+ ];
118
+ /**
119
+ * Scoring weights for different classification factors
120
+ */
121
+ export const SCORING_WEIGHTS = {
122
+ SHORT_PROMPT_BONUS: 2,
123
+ LONG_PROMPT_BONUS: 1,
124
+ PATTERN_MATCH_SCORE: 3,
125
+ KEYWORD_MATCH_SCORE: 1,
126
+ MULTIPLE_QUESTIONS_BONUS: 1,
127
+ MULTI_SENTENCE_BONUS: 1,
128
+ TECHNICAL_DOMAIN_BONUS: 1,
129
+ SIMPLE_DEFINITION_BONUS: 2,
130
+ };
131
+ /**
132
+ * Classification thresholds and constraints
133
+ */
134
+ export const CLASSIFICATION_THRESHOLDS = {
135
+ SHORT_PROMPT_LENGTH: 50,
136
+ LONG_PROMPT_LENGTH: 200,
137
+ SIMPLE_DEFINITION_LENGTH: 100,
138
+ MIN_CONFIDENCE: 0.6,
139
+ MAX_CONFIDENCE: 0.95,
140
+ DEFAULT_CONFIDENCE: 0.5,
141
+ };
142
+ /**
143
+ * Domain-specific patterns for enhanced classification
144
+ */
145
+ export const DOMAIN_PATTERNS = {
146
+ TECHNICAL: /\b(code|programming|development|software)\b/i,
147
+ SIMPLE_DEFINITION: /\b(definition|meaning|what is)\b/i,
148
+ };
@@ -62,6 +62,7 @@ export declare class NeuroLink {
62
62
  private conversationMemory?;
63
63
  private conversationMemoryNeedsInit;
64
64
  private conversationMemoryConfig?;
65
+ private enableOrchestration;
65
66
  /**
66
67
  * Creates a new NeuroLink instance for AI text generation with MCP tool integration.
67
68
  *
@@ -70,6 +71,7 @@ export declare class NeuroLink {
70
71
  * @param config.conversationMemory.enabled - Whether to enable conversation memory (default: false)
71
72
  * @param config.conversationMemory.maxSessions - Maximum number of concurrent sessions (default: 100)
72
73
  * @param config.conversationMemory.maxTurnsPerSession - Maximum conversation turns per session (default: 50)
74
+ * @param config.enableOrchestration - Whether to enable smart model orchestration (default: false)
73
75
  *
74
76
  * @example
75
77
  * ```typescript
@@ -84,6 +86,11 @@ export declare class NeuroLink {
84
86
  * maxTurnsPerSession: 20
85
87
  * }
86
88
  * });
89
+ *
90
+ * // With orchestration enabled
91
+ * const neurolink = new NeuroLink({
92
+ * enableOrchestration: true
93
+ * });
87
94
  * ```
88
95
  *
89
96
  * @throws {Error} When provider registry setup fails
@@ -92,6 +99,7 @@ export declare class NeuroLink {
92
99
  */
93
100
  constructor(config?: {
94
101
  conversationMemory?: Partial<ConversationMemoryConfig>;
102
+ enableOrchestration?: boolean;
95
103
  });
96
104
  /**
97
105
  * Log constructor start with comprehensive environment analysis
@@ -158,6 +166,18 @@ export declare class NeuroLink {
158
166
  * Log MCP initialization completion
159
167
  */
160
168
  private logMCPInitComplete;
169
+ /**
170
+ * Apply orchestration to determine optimal provider and model
171
+ * @param options - Original GenerateOptions
172
+ * @returns Modified options with orchestrated provider marked in context, or empty object if validation fails
173
+ */
174
+ private applyOrchestration;
175
+ /**
176
+ * Apply orchestration to determine optimal provider and model for streaming
177
+ * @param options - Original StreamOptions
178
+ * @returns Modified options with orchestrated provider marked in context, or empty object if validation fails
179
+ */
180
+ private applyStreamOrchestration;
161
181
  /**
162
182
  * MAIN ENTRY POINT: Enhanced generate method with new function signature
163
183
  * Replaces both generateText and legacy methods