@juspay/neurolink 7.14.1 → 7.14.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cli/commands/config.d.ts +66 -66
  3. package/dist/core/baseProvider.d.ts +12 -7
  4. package/dist/core/baseProvider.js +118 -125
  5. package/dist/core/constants.d.ts +5 -0
  6. package/dist/core/constants.js +6 -0
  7. package/dist/core/dynamicModels.d.ts +4 -4
  8. package/dist/core/factory.d.ts +2 -4
  9. package/dist/core/types.d.ts +8 -22
  10. package/dist/index.d.ts +19 -4
  11. package/dist/index.js +21 -0
  12. package/dist/lib/core/baseProvider.d.ts +12 -7
  13. package/dist/lib/core/baseProvider.js +118 -125
  14. package/dist/lib/core/constants.d.ts +5 -0
  15. package/dist/lib/core/constants.js +6 -0
  16. package/dist/lib/core/dynamicModels.d.ts +8 -8
  17. package/dist/lib/core/factory.d.ts +2 -4
  18. package/dist/lib/core/types.d.ts +8 -22
  19. package/dist/lib/index.d.ts +19 -4
  20. package/dist/lib/index.js +21 -0
  21. package/dist/lib/mcp/contracts/mcpContract.d.ts +6 -19
  22. package/dist/lib/mcp/externalServerManager.d.ts +2 -4
  23. package/dist/lib/mcp/externalServerManager.js +7 -8
  24. package/dist/lib/mcp/factory.d.ts +61 -7
  25. package/dist/lib/mcp/factory.js +36 -23
  26. package/dist/lib/mcp/mcpClientFactory.d.ts +2 -1
  27. package/dist/lib/mcp/mcpClientFactory.js +73 -26
  28. package/dist/lib/mcp/registry.d.ts +1 -1
  29. package/dist/lib/mcp/toolDiscoveryService.d.ts +1 -1
  30. package/dist/lib/mcp/toolDiscoveryService.js +50 -19
  31. package/dist/lib/mcp/toolRegistry.d.ts +23 -1
  32. package/dist/lib/mcp/toolRegistry.js +108 -17
  33. package/dist/lib/models/modelResolver.js +2 -1
  34. package/dist/lib/neurolink.d.ts +12 -8
  35. package/dist/lib/neurolink.js +130 -134
  36. package/dist/lib/providers/amazonBedrock.d.ts +2 -2
  37. package/dist/lib/providers/anthropic.d.ts +3 -3
  38. package/dist/lib/providers/googleAiStudio.d.ts +2 -2
  39. package/dist/lib/providers/mistral.d.ts +3 -3
  40. package/dist/lib/providers/ollama.d.ts +2 -2
  41. package/dist/lib/providers/openAI.d.ts +3 -3
  42. package/dist/lib/providers/openaiCompatible.d.ts +2 -2
  43. package/dist/lib/providers/sagemaker/client.d.ts +2 -5
  44. package/dist/lib/providers/sagemaker/language-model.d.ts +4 -6
  45. package/dist/lib/providers/sagemaker/parsers.js +5 -4
  46. package/dist/lib/sdk/toolRegistration.d.ts +6 -6
  47. package/dist/lib/sdk/toolRegistration.js +17 -56
  48. package/dist/lib/types/generateTypes.d.ts +9 -9
  49. package/dist/lib/types/streamTypes.d.ts +4 -4
  50. package/dist/lib/types/tools.d.ts +15 -7
  51. package/dist/lib/types/typeAliases.d.ts +412 -0
  52. package/dist/lib/types/typeAliases.js +48 -0
  53. package/dist/lib/utils/factoryProcessing.d.ts +2 -1
  54. package/dist/lib/utils/factoryProcessing.js +4 -3
  55. package/dist/lib/utils/parameterValidation.d.ts +97 -0
  56. package/dist/lib/utils/parameterValidation.js +452 -0
  57. package/dist/lib/utils/transformationUtils.d.ts +204 -0
  58. package/dist/lib/utils/transformationUtils.js +334 -0
  59. package/dist/lib/utils/typeUtils.d.ts +77 -0
  60. package/dist/lib/utils/typeUtils.js +97 -0
  61. package/dist/mcp/contracts/mcpContract.d.ts +6 -19
  62. package/dist/mcp/externalServerManager.d.ts +2 -4
  63. package/dist/mcp/externalServerManager.js +7 -8
  64. package/dist/mcp/factory.d.ts +61 -7
  65. package/dist/mcp/factory.js +36 -23
  66. package/dist/mcp/mcpClientFactory.d.ts +2 -1
  67. package/dist/mcp/mcpClientFactory.js +73 -26
  68. package/dist/mcp/registry.d.ts +1 -1
  69. package/dist/mcp/toolDiscoveryService.d.ts +1 -1
  70. package/dist/mcp/toolDiscoveryService.js +50 -19
  71. package/dist/mcp/toolRegistry.d.ts +23 -1
  72. package/dist/mcp/toolRegistry.js +108 -17
  73. package/dist/models/modelResolver.js +2 -1
  74. package/dist/neurolink.d.ts +12 -8
  75. package/dist/neurolink.js +130 -134
  76. package/dist/providers/amazonBedrock.d.ts +2 -2
  77. package/dist/providers/anthropic.d.ts +3 -3
  78. package/dist/providers/googleAiStudio.d.ts +2 -2
  79. package/dist/providers/mistral.d.ts +3 -3
  80. package/dist/providers/ollama.d.ts +2 -2
  81. package/dist/providers/openAI.d.ts +3 -3
  82. package/dist/providers/openaiCompatible.d.ts +2 -2
  83. package/dist/providers/sagemaker/client.d.ts +2 -5
  84. package/dist/providers/sagemaker/language-model.d.ts +4 -6
  85. package/dist/providers/sagemaker/parsers.js +5 -4
  86. package/dist/sdk/toolRegistration.d.ts +6 -6
  87. package/dist/sdk/toolRegistration.js +17 -56
  88. package/dist/types/generateTypes.d.ts +9 -9
  89. package/dist/types/streamTypes.d.ts +4 -4
  90. package/dist/types/tools.d.ts +15 -7
  91. package/dist/types/typeAliases.d.ts +412 -0
  92. package/dist/types/typeAliases.js +48 -0
  93. package/dist/utils/factoryProcessing.d.ts +2 -1
  94. package/dist/utils/factoryProcessing.js +4 -3
  95. package/dist/utils/parameterValidation.d.ts +97 -0
  96. package/dist/utils/parameterValidation.js +452 -0
  97. package/dist/utils/transformationUtils.d.ts +204 -0
  98. package/dist/utils/transformationUtils.js +334 -0
  99. package/dist/utils/typeUtils.d.ts +77 -0
  100. package/dist/utils/typeUtils.js +97 -0
  101. package/package.json +1 -1
@@ -5,7 +5,7 @@
5
5
  import { z } from "zod";
6
6
  import { logger } from "../utils/logger.js";
7
7
  import type { MCPServerInfo, MCPServerCategory } from "../types/mcpTypes.js";
8
- import type { ToolArgs, ToolContext as CoreToolContext, ToolResult, SimpleTool as CoreSimpleTool } from "../types/tools.js";
8
+ import type { ToolArgs, ToolContext as CoreToolContext, ToolResult, SimpleTool as CoreSimpleTool, ZodUnknownSchema } from "../types/tools.js";
9
9
  import type { JsonValue } from "../types/common.js";
10
10
  /**
11
11
  * Enhanced validation configuration
@@ -39,7 +39,7 @@ export interface ToolContext extends CoreToolContext {
39
39
  /**
40
40
  * Call another tool
41
41
  */
42
- callTool?: (name: string, args: ToolArgs) => Promise<ToolResult>;
42
+ callTool?: (name: string, params: ToolArgs) => Promise<ToolResult>;
43
43
  /**
44
44
  * Logger instance
45
45
  */
@@ -57,11 +57,11 @@ export interface SimpleTool<TArgs = ToolArgs, TResult = JsonValue> extends Omit<
57
57
  /**
58
58
  * Parameters schema using Zod (optional)
59
59
  */
60
- parameters?: z.ZodSchema;
60
+ parameters?: ZodUnknownSchema;
61
61
  /**
62
62
  * Tool execution function
63
63
  */
64
- execute: (args: TArgs, context?: ToolContext) => Promise<TResult> | TResult;
64
+ execute: (params: TArgs, context?: ToolContext) => Promise<TResult>;
65
65
  /**
66
66
  * Optional metadata
67
67
  */
@@ -99,9 +99,9 @@ export declare function createValidatedTool(name: string, config: SimpleTool, op
99
99
  /**
100
100
  * Helper to create a tool with typed parameters
101
101
  */
102
- export declare function createTypedTool<TParams extends z.ZodSchema>(config: Omit<SimpleTool, "execute"> & {
102
+ export declare function createTypedTool<TParams extends ZodUnknownSchema>(config: Omit<SimpleTool, "execute"> & {
103
103
  parameters: TParams;
104
- execute: (args: z.infer<TParams>, context?: ToolContext) => Promise<JsonValue> | JsonValue;
104
+ execute: (params: z.infer<TParams>, context?: ToolContext) => Promise<JsonValue> | JsonValue;
105
105
  }): SimpleTool;
106
106
  /**
107
107
  * Validate tool configuration with detailed error messages
@@ -4,6 +4,7 @@
4
4
  */
5
5
  import { logger } from "../utils/logger.js";
6
6
  import { createMCPServerInfo } from "../utils/mcpDefaults.js";
7
+ import { validateToolName, validateToolDescription, } from "../utils/parameterValidation.js";
7
8
  /**
8
9
  * Configuration constants for tool validation
9
10
  */
@@ -153,39 +154,15 @@ export function createTypedTool(config) {
153
154
  return config;
154
155
  }
155
156
  /**
156
- * Enhanced tool name validation
157
+ * Enhanced tool name validation using centralized utilities
157
158
  */
158
- function validateToolName(name) {
159
- // Basic validation
160
- if (!name || typeof name !== "string" || name.trim() === "") {
161
- throw new Error(`Invalid tool name: must be a non-empty string. Received: ${name}`);
159
+ function validateToolNameLegacy(name) {
160
+ const error = validateToolName(name);
161
+ if (error) {
162
+ throw error;
162
163
  }
164
+ // Additional legacy-specific validations
163
165
  const trimmedName = name.trim();
164
- // Length validation
165
- if (trimmedName.length < VALIDATION_CONFIG.NAME_MIN_LENGTH) {
166
- throw new Error(`Tool name too short: '${name}' (${trimmedName.length} chars). ` +
167
- `Minimum length: ${VALIDATION_CONFIG.NAME_MIN_LENGTH} characters. ` +
168
- `Example: 'get_data', 'send_email'`);
169
- }
170
- // Only check name length if limit is greater than 0 (0 means unlimited)
171
- if (VALIDATION_CONFIG.NAME_MAX_LENGTH > 0 &&
172
- trimmedName.length > VALIDATION_CONFIG.NAME_MAX_LENGTH) {
173
- throw new Error(`Tool name too long: '${name}' (${trimmedName.length} chars). ` +
174
- `Maximum length: ${VALIDATION_CONFIG.NAME_MAX_LENGTH} characters. ` +
175
- `Consider shortening: '${trimmedName.substring(0, 20)}...'`);
176
- }
177
- // Format validation (alphanumeric, hyphens, underscores only)
178
- const validNamePattern = /^[a-zA-Z0-9_-]+$/;
179
- if (!validNamePattern.test(trimmedName)) {
180
- throw new Error(`Invalid tool name format: '${name}'. Tool names must contain only alphanumeric characters, hyphens, and underscores. ` +
181
- `Examples: 'calculate-tax', 'get_weather', 'sendEmail123'`);
182
- }
183
- // Reserved name validation
184
- if (VALIDATION_CONFIG.RESERVED_NAMES.has(trimmedName.toLowerCase())) {
185
- throw new Error(`Tool name '${name}' is reserved and cannot be used. ` +
186
- `Reserved names include: ${Array.from(VALIDATION_CONFIG.RESERVED_NAMES).slice(0, 5).join(", ")}... ` +
187
- `Try variations like: '${trimmedName}_tool', 'custom_${trimmedName}', '${trimmedName}_helper'`);
188
- }
189
166
  // Naming convention suggestions using pre-compiled patterns for performance
190
167
  const hasGoodPattern = VALIDATION_CONFIG.COMPILED_PATTERN_REGEXES.some((patternRegex) => {
191
168
  return patternRegex.test(trimmedName);
@@ -196,31 +173,15 @@ function validateToolName(name) {
196
173
  }
197
174
  }
198
175
  /**
199
- * Enhanced description validation
176
+ * Enhanced description validation using centralized utilities
200
177
  */
201
- function validateToolDescription(name, description) {
202
- if (!description ||
203
- typeof description !== "string" ||
204
- description.trim() === "") {
205
- throw new Error(`Tool '${name}' must have a non-empty description string. ` +
206
- `Example: { description: "Calculates mathematical expressions", execute: async (params) => {...} }`);
178
+ function validateToolDescriptionLegacy(name, description) {
179
+ const error = validateToolDescription(description);
180
+ if (error) {
181
+ throw new Error(`Tool '${name}': ${error.message}`);
207
182
  }
183
+ // Additional legacy-specific validations
208
184
  const trimmedDescription = description.trim();
209
- // Length validation
210
- if (trimmedDescription.length < VALIDATION_CONFIG.DESCRIPTION_MIN_LENGTH) {
211
- throw new Error(`Tool '${name}' description too short: ${trimmedDescription.length} characters. ` +
212
- `Minimum length: ${VALIDATION_CONFIG.DESCRIPTION_MIN_LENGTH} characters. ` +
213
- `The description should clearly explain what the tool does and when to use it. ` +
214
- `Example: "Fetches current weather data for a specified location using coordinates or city name"`);
215
- }
216
- // Only check description length if limit is greater than 0 (0 means unlimited)
217
- if (VALIDATION_CONFIG.DESCRIPTION_MAX_LENGTH > 0 &&
218
- trimmedDescription.length > VALIDATION_CONFIG.DESCRIPTION_MAX_LENGTH) {
219
- throw new Error(`Tool '${name}' description too long: ${trimmedDescription.length} characters. ` +
220
- `Maximum length: ${VALIDATION_CONFIG.DESCRIPTION_MAX_LENGTH} characters. ` +
221
- `Current description: "${trimmedDescription.substring(0, 50)}..." ` +
222
- `Try to be more concise while keeping the essential information.`);
223
- }
224
185
  // Quality suggestions
225
186
  const hasActionWord = /^(get|fetch|calculate|send|create|update|delete|validate|process|generate|parse|convert)/i.test(trimmedDescription);
226
187
  if (!hasActionWord) {
@@ -231,15 +192,15 @@ function validateToolDescription(name, description) {
231
192
  * Validate tool configuration with detailed error messages
232
193
  */
233
194
  export function validateTool(name, tool) {
234
- // Enhanced tool name validation
235
- validateToolName(name);
195
+ // Enhanced tool name validation using centralized utilities
196
+ validateToolNameLegacy(name);
236
197
  // Validate tool object
237
198
  if (!tool || typeof tool !== "object") {
238
199
  throw new Error(`Tool '${name}' must be an object with description and execute properties. Received: ${typeof tool}. ` +
239
200
  `Expected format: { description: "Tool description", execute: async (params) => { ... } }`);
240
201
  }
241
- // Enhanced description validation
242
- validateToolDescription(name, tool.description);
202
+ // Enhanced description validation using centralized utilities
203
+ validateToolDescriptionLegacy(name, tool.description);
243
204
  // Validate execute function with signature guidance
244
205
  if (typeof tool.execute !== "function") {
245
206
  throw new Error(`Tool '${name}' must have an execute function. ` +
@@ -1,5 +1,5 @@
1
- import type { ZodType, ZodTypeDef } from "zod";
2
- import type { Tool, Schema } from "ai";
1
+ import type { Tool } from "ai";
2
+ import type { ValidationSchema, StandardRecord } from "./typeAliases.js";
3
3
  import type { AIProviderName, AnalyticsData, EvaluationData } from "../core/types.js";
4
4
  /**
5
5
  * Generate function options interface - Primary method for content generation
@@ -17,13 +17,13 @@ export interface GenerateOptions {
17
17
  temperature?: number;
18
18
  maxTokens?: number;
19
19
  systemPrompt?: string;
20
- schema?: ZodType<unknown, ZodTypeDef, unknown> | Schema<unknown>;
20
+ schema?: ValidationSchema;
21
21
  tools?: Record<string, Tool>;
22
22
  timeout?: number | string;
23
23
  disableTools?: boolean;
24
24
  enableEvaluation?: boolean;
25
25
  enableAnalytics?: boolean;
26
- context?: Record<string, unknown>;
26
+ context?: StandardRecord;
27
27
  evaluationDomain?: string;
28
28
  toolUsageContext?: string;
29
29
  conversationHistory?: Array<{
@@ -32,7 +32,7 @@ export interface GenerateOptions {
32
32
  }>;
33
33
  factoryConfig?: {
34
34
  domainType?: string;
35
- domainConfig?: Record<string, unknown>;
35
+ domainConfig?: StandardRecord;
36
36
  enhancementType?: "domain-configuration" | "streaming-optimization" | "mcp-integration" | "legacy-migration" | "context-conversion";
37
37
  preserveLegacyFields?: boolean;
38
38
  validateDomainData?: boolean;
@@ -65,20 +65,20 @@ export interface GenerateResult {
65
65
  toolCalls?: Array<{
66
66
  toolCallId: string;
67
67
  toolName: string;
68
- args: Record<string, unknown>;
68
+ args: StandardRecord;
69
69
  }>;
70
70
  toolResults?: unknown[];
71
71
  toolsUsed?: string[];
72
72
  toolExecutions?: Array<{
73
73
  name: string;
74
- input: Record<string, unknown>;
74
+ input: StandardRecord;
75
75
  output: unknown;
76
76
  }>;
77
77
  enhancedWithTools?: boolean;
78
78
  availableTools?: Array<{
79
79
  name: string;
80
80
  description: string;
81
- parameters: Record<string, unknown>;
81
+ parameters: StandardRecord;
82
82
  }>;
83
83
  analytics?: AnalyticsData;
84
84
  evaluation?: EvaluationData;
@@ -87,7 +87,7 @@ export interface GenerateResult {
87
87
  enhancementType?: string;
88
88
  domainType?: string;
89
89
  processingTime?: number;
90
- configurationUsed?: Record<string, unknown>;
90
+ configurationUsed?: StandardRecord;
91
91
  migrationPerformed?: boolean;
92
92
  legacyFieldsPreserved?: boolean;
93
93
  };
@@ -1,5 +1,5 @@
1
- import type { ZodType, ZodTypeDef } from "zod";
2
- import type { Tool, Schema } from "ai";
1
+ import type { Tool } from "ai";
2
+ import type { ValidationSchema, StandardRecord } from "./typeAliases.js";
3
3
  import type { AIProviderName, AnalyticsData, EvaluationData } from "../core/types.js";
4
4
  import type { UnknownRecord, JsonValue } from "./common.js";
5
5
  import type { ChatMessage } from "./conversationTypes.js";
@@ -80,7 +80,7 @@ export interface StreamOptions {
80
80
  temperature?: number;
81
81
  maxTokens?: number;
82
82
  systemPrompt?: string;
83
- schema?: ZodType<unknown, ZodTypeDef, unknown> | Schema<unknown>;
83
+ schema?: ValidationSchema;
84
84
  tools?: Record<string, Tool>;
85
85
  timeout?: number | string;
86
86
  disableTools?: boolean;
@@ -96,7 +96,7 @@ export interface StreamOptions {
96
96
  }>;
97
97
  factoryConfig?: {
98
98
  domainType?: string;
99
- domainConfig?: Record<string, unknown>;
99
+ domainConfig?: StandardRecord;
100
100
  enhancementType?: "domain-configuration" | "streaming-optimization" | "mcp-integration" | "legacy-migration" | "context-conversion";
101
101
  preserveLegacyFields?: boolean;
102
102
  validateDomainData?: boolean;
@@ -4,10 +4,18 @@
4
4
  */
5
5
  import { z } from "zod";
6
6
  import type { Result, JsonValue, ErrorInfo } from "./common.js";
7
+ /**
8
+ * Commonly used Zod schema type aliases for cleaner type declarations
9
+ */
10
+ import type { ZodUnknownSchema } from "./typeAliases.js";
11
+ export type { ZodUnknownSchema } from "./typeAliases.js";
12
+ export type ZodAnySchema = z.ZodSchema<unknown>;
13
+ export type ZodObjectSchema = z.ZodObject<z.ZodRawShape>;
14
+ export type ZodStringSchema = z.ZodString;
7
15
  /**
8
16
  * Tool parameter schema types
9
17
  */
10
- export type ToolParameterSchema = z.ZodSchema | Record<string, JsonValue>;
18
+ export type ToolParameterSchema = ZodUnknownSchema | Record<string, JsonValue>;
11
19
  /**
12
20
  * Standard tool input parameters
13
21
  */
@@ -78,16 +86,16 @@ export interface ToolDefinition<TArgs = ToolArgs, TResult = JsonValue> {
78
86
  description: string;
79
87
  parameters?: ToolParameterSchema;
80
88
  metadata?: ToolMetadata;
81
- execute: (args: TArgs, context?: ToolContext) => Promise<ToolResult<TResult>> | ToolResult<TResult>;
89
+ execute: (params: TArgs, context?: ToolContext) => Promise<ToolResult<TResult>> | ToolResult<TResult>;
82
90
  }
83
91
  /**
84
92
  * Simple tool interface (for SDK)
85
93
  */
86
94
  export interface SimpleTool<TArgs = ToolArgs, TResult = JsonValue> {
87
95
  description: string;
88
- parameters?: z.ZodSchema;
96
+ parameters?: ZodUnknownSchema;
89
97
  metadata?: ToolMetadata;
90
- execute: (args: TArgs, context?: ToolContext) => Promise<TResult> | TResult;
98
+ execute: (params: TArgs, context?: ToolContext) => Promise<TResult>;
91
99
  }
92
100
  /**
93
101
  * Tool registry entry
@@ -105,7 +113,7 @@ export interface ToolRegistryEntry {
105
113
  */
106
114
  export interface ToolExecution {
107
115
  toolName: string;
108
- args: ToolArgs;
116
+ params: ToolArgs;
109
117
  result: ToolResult;
110
118
  executionTime: number;
111
119
  timestamp: number;
@@ -124,7 +132,7 @@ export interface AvailableTool {
124
132
  * Tool validation options
125
133
  */
126
134
  export interface ToolValidationOptions {
127
- customValidator?: (toolName: string, args: ToolArgs) => boolean | Promise<boolean>;
135
+ customValidator?: (toolName: string, params: ToolArgs) => boolean | Promise<boolean>;
128
136
  validateSchema?: boolean;
129
137
  allowUnknownProperties?: boolean;
130
138
  }
@@ -143,7 +151,7 @@ export interface AiSdkToolCall {
143
151
  type: "tool-call";
144
152
  toolCallId: string;
145
153
  toolName: string;
146
- args: ToolArgs;
154
+ params: ToolArgs;
147
155
  }
148
156
  /**
149
157
  * Tool call result (for AI SDK integration)