@juspay/neurolink 7.14.2 → 7.14.4
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.
- package/CHANGELOG.md +12 -0
- package/dist/cli/commands/config.d.ts +66 -66
- package/dist/core/baseProvider.d.ts +12 -7
- package/dist/core/baseProvider.js +118 -125
- package/dist/core/constants.d.ts +5 -0
- package/dist/core/constants.js +6 -0
- package/dist/core/dynamicModels.d.ts +4 -4
- package/dist/core/factory.d.ts +2 -4
- package/dist/core/types.d.ts +8 -22
- package/dist/index.d.ts +1 -4
- package/dist/lib/core/baseProvider.d.ts +12 -7
- package/dist/lib/core/baseProvider.js +118 -125
- package/dist/lib/core/constants.d.ts +5 -0
- package/dist/lib/core/constants.js +6 -0
- package/dist/lib/core/dynamicModels.d.ts +8 -8
- package/dist/lib/core/factory.d.ts +2 -4
- package/dist/lib/core/types.d.ts +8 -22
- package/dist/lib/index.d.ts +1 -4
- package/dist/lib/mcp/contracts/mcpContract.d.ts +6 -19
- package/dist/lib/mcp/externalServerManager.d.ts +2 -4
- package/dist/lib/mcp/externalServerManager.js +7 -8
- package/dist/lib/mcp/factory.d.ts +61 -7
- package/dist/lib/mcp/factory.js +36 -23
- package/dist/lib/mcp/mcpClientFactory.d.ts +2 -1
- package/dist/lib/mcp/mcpClientFactory.js +73 -26
- package/dist/lib/mcp/registry.d.ts +1 -1
- package/dist/lib/mcp/toolDiscoveryService.d.ts +1 -1
- package/dist/lib/mcp/toolDiscoveryService.js +50 -19
- package/dist/lib/mcp/toolRegistry.d.ts +23 -1
- package/dist/lib/mcp/toolRegistry.js +108 -17
- package/dist/lib/models/modelResolver.js +2 -1
- package/dist/lib/neurolink.d.ts +12 -8
- package/dist/lib/neurolink.js +130 -134
- package/dist/lib/providers/amazonBedrock.d.ts +2 -2
- package/dist/lib/providers/anthropic.d.ts +3 -3
- package/dist/lib/providers/googleAiStudio.d.ts +2 -2
- package/dist/lib/providers/mistral.d.ts +3 -3
- package/dist/lib/providers/ollama.d.ts +2 -2
- package/dist/lib/providers/openAI.d.ts +3 -3
- package/dist/lib/providers/openaiCompatible.d.ts +2 -2
- package/dist/lib/providers/sagemaker/client.d.ts +2 -5
- package/dist/lib/providers/sagemaker/language-model.d.ts +4 -6
- package/dist/lib/providers/sagemaker/parsers.js +5 -4
- package/dist/lib/sdk/toolRegistration.d.ts +6 -6
- package/dist/lib/sdk/toolRegistration.js +17 -56
- package/dist/lib/types/generateTypes.d.ts +9 -9
- package/dist/lib/types/streamTypes.d.ts +4 -4
- package/dist/lib/types/tools.d.ts +15 -7
- package/dist/lib/types/typeAliases.d.ts +412 -0
- package/dist/lib/types/typeAliases.js +48 -0
- package/dist/lib/utils/factoryProcessing.d.ts +2 -1
- package/dist/lib/utils/factoryProcessing.js +4 -3
- package/dist/lib/utils/parameterValidation.d.ts +97 -0
- package/dist/lib/utils/parameterValidation.js +452 -0
- package/dist/lib/utils/transformationUtils.d.ts +204 -0
- package/dist/lib/utils/transformationUtils.js +334 -0
- package/dist/lib/utils/typeUtils.d.ts +77 -0
- package/dist/lib/utils/typeUtils.js +97 -0
- package/dist/mcp/contracts/mcpContract.d.ts +6 -19
- package/dist/mcp/externalServerManager.d.ts +2 -4
- package/dist/mcp/externalServerManager.js +7 -8
- package/dist/mcp/factory.d.ts +61 -7
- package/dist/mcp/factory.js +36 -23
- package/dist/mcp/mcpClientFactory.d.ts +2 -1
- package/dist/mcp/mcpClientFactory.js +73 -26
- package/dist/mcp/registry.d.ts +1 -1
- package/dist/mcp/toolDiscoveryService.d.ts +1 -1
- package/dist/mcp/toolDiscoveryService.js +50 -19
- package/dist/mcp/toolRegistry.d.ts +23 -1
- package/dist/mcp/toolRegistry.js +108 -17
- package/dist/models/modelResolver.js +2 -1
- package/dist/neurolink.d.ts +12 -8
- package/dist/neurolink.js +130 -134
- package/dist/providers/amazonBedrock.d.ts +2 -2
- package/dist/providers/anthropic.d.ts +3 -3
- package/dist/providers/googleAiStudio.d.ts +2 -2
- package/dist/providers/mistral.d.ts +3 -3
- package/dist/providers/ollama.d.ts +2 -2
- package/dist/providers/openAI.d.ts +3 -3
- package/dist/providers/openaiCompatible.d.ts +2 -2
- package/dist/providers/sagemaker/client.d.ts +2 -5
- package/dist/providers/sagemaker/language-model.d.ts +4 -6
- package/dist/providers/sagemaker/parsers.js +5 -4
- package/dist/sdk/toolRegistration.d.ts +6 -6
- package/dist/sdk/toolRegistration.js +17 -56
- package/dist/types/generateTypes.d.ts +9 -9
- package/dist/types/streamTypes.d.ts +4 -4
- package/dist/types/tools.d.ts +15 -7
- package/dist/types/typeAliases.d.ts +412 -0
- package/dist/types/typeAliases.js +48 -0
- package/dist/utils/factoryProcessing.d.ts +2 -1
- package/dist/utils/factoryProcessing.js +4 -3
- package/dist/utils/parameterValidation.d.ts +97 -0
- package/dist/utils/parameterValidation.js +452 -0
- package/dist/utils/transformationUtils.d.ts +204 -0
- package/dist/utils/transformationUtils.js +334 -0
- package/dist/utils/typeUtils.d.ts +77 -0
- package/dist/utils/typeUtils.js +97 -0
- package/package.json +1 -1
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Comprehensive Type Alias Library
|
|
3
|
+
* Centralizes commonly used complex types to improve readability and maintainability
|
|
4
|
+
*/
|
|
5
|
+
import type { ZodType, ZodTypeDef } from "zod";
|
|
6
|
+
import type { Schema } from "ai";
|
|
7
|
+
import type { JsonValue, JsonObject } from "./common.js";
|
|
8
|
+
/**
|
|
9
|
+
* Type alias for complex Zod schema type to improve readability
|
|
10
|
+
* Used across providers and validation systems
|
|
11
|
+
*/
|
|
12
|
+
export type ZodUnknownSchema = ZodType<unknown, ZodTypeDef, unknown>;
|
|
13
|
+
/**
|
|
14
|
+
* Union type for schema validation (Zod or AI SDK schema)
|
|
15
|
+
* Commonly used in provider interfaces and validation functions
|
|
16
|
+
*/
|
|
17
|
+
export type ValidationSchema = ZodUnknownSchema | Schema<unknown>;
|
|
18
|
+
/**
|
|
19
|
+
* Optional validation schema type
|
|
20
|
+
* Used in optional schema parameters across the codebase
|
|
21
|
+
*/
|
|
22
|
+
export type OptionalValidationSchema = ValidationSchema | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Standard unknown record type for flexible object structures
|
|
25
|
+
* Most commonly used record type across the codebase
|
|
26
|
+
*/
|
|
27
|
+
export type StandardRecord = Record<string, unknown>;
|
|
28
|
+
/**
|
|
29
|
+
* String-valued record for configuration and metadata
|
|
30
|
+
* Common in environment variables and config objects
|
|
31
|
+
*/
|
|
32
|
+
export type StringRecord = Record<string, string>;
|
|
33
|
+
/**
|
|
34
|
+
* Number-valued record for metrics and counters
|
|
35
|
+
* Used in performance monitoring and statistics
|
|
36
|
+
*/
|
|
37
|
+
export type NumberRecord = Record<string, number>;
|
|
38
|
+
/**
|
|
39
|
+
* Boolean-valued record for feature flags and settings
|
|
40
|
+
* Common in configuration and capability objects
|
|
41
|
+
*/
|
|
42
|
+
export type BooleanRecord = Record<string, boolean>;
|
|
43
|
+
/**
|
|
44
|
+
* Mixed primitive record for configuration objects
|
|
45
|
+
* Allows string, number, boolean values
|
|
46
|
+
*/
|
|
47
|
+
export type PrimitiveRecord = Record<string, string | number | boolean>;
|
|
48
|
+
/**
|
|
49
|
+
* JSON-safe record type for API communication
|
|
50
|
+
* Ensures values are JSON-serializable
|
|
51
|
+
*/
|
|
52
|
+
export type JsonRecord = Record<string, JsonValue>;
|
|
53
|
+
/**
|
|
54
|
+
* Optional record types for flexible parameters
|
|
55
|
+
*/
|
|
56
|
+
export type OptionalStandardRecord = StandardRecord | undefined;
|
|
57
|
+
export type OptionalStringRecord = StringRecord | undefined;
|
|
58
|
+
export type OptionalJsonRecord = JsonRecord | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* Standard async function type for tool execution
|
|
61
|
+
* Most common function signature in the codebase
|
|
62
|
+
*/
|
|
63
|
+
export type AsyncFunction<TParams = unknown, TResult = unknown> = (params: TParams) => Promise<TResult>;
|
|
64
|
+
/**
|
|
65
|
+
* Tool execution function with context
|
|
66
|
+
* Standard pattern for MCP tool execution
|
|
67
|
+
*/
|
|
68
|
+
export type ToolExecutionFunction<TParams = unknown, TResult = unknown> = (params: TParams, context?: StandardRecord) => Promise<TResult>;
|
|
69
|
+
/**
|
|
70
|
+
* Event handler function type
|
|
71
|
+
* Common in event-driven architectures
|
|
72
|
+
*/
|
|
73
|
+
export type EventHandler<TEvent = unknown> = (event: TEvent) => void | Promise<void>;
|
|
74
|
+
/**
|
|
75
|
+
* Async event handler function type
|
|
76
|
+
*/
|
|
77
|
+
export type AsyncEventHandler<TEvent = unknown> = (event: TEvent) => Promise<void>;
|
|
78
|
+
/**
|
|
79
|
+
* Validation function type
|
|
80
|
+
* Common pattern for input validation
|
|
81
|
+
*/
|
|
82
|
+
export type ValidationFunction<T = unknown> = (value: T) => boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Transformation function type
|
|
85
|
+
* Common in data processing pipelines
|
|
86
|
+
*/
|
|
87
|
+
export type TransformFunction<TInput = unknown, TOutput = unknown> = (input: TInput) => TOutput;
|
|
88
|
+
/**
|
|
89
|
+
* Async transformation function type
|
|
90
|
+
*/
|
|
91
|
+
export type AsyncTransformFunction<TInput = unknown, TOutput = unknown> = (input: TInput) => Promise<TOutput>;
|
|
92
|
+
/**
|
|
93
|
+
* Array of unknown values
|
|
94
|
+
* Common for flexible array parameters
|
|
95
|
+
*/
|
|
96
|
+
export type UnknownArray = unknown[];
|
|
97
|
+
/**
|
|
98
|
+
* Array of standard records
|
|
99
|
+
* Common in data collections
|
|
100
|
+
*/
|
|
101
|
+
export type RecordArray = StandardRecord[];
|
|
102
|
+
/**
|
|
103
|
+
* Array of JSON objects
|
|
104
|
+
* API-safe array type
|
|
105
|
+
*/
|
|
106
|
+
export type JsonArray = JsonObject[];
|
|
107
|
+
/**
|
|
108
|
+
* String array type
|
|
109
|
+
* Very common for lists of identifiers, names, etc.
|
|
110
|
+
*/
|
|
111
|
+
export type StringArray = string[];
|
|
112
|
+
/**
|
|
113
|
+
* Number array type
|
|
114
|
+
* Common for metrics, coordinates, etc.
|
|
115
|
+
*/
|
|
116
|
+
export type NumberArray = number[];
|
|
117
|
+
/**
|
|
118
|
+
* Optional array types
|
|
119
|
+
*/
|
|
120
|
+
export type OptionalStringArray = StringArray | undefined;
|
|
121
|
+
export type OptionalRecordArray = RecordArray | undefined;
|
|
122
|
+
/**
|
|
123
|
+
* Provider configuration type
|
|
124
|
+
* Common structure for AI provider settings
|
|
125
|
+
*/
|
|
126
|
+
export type ProviderConfig = {
|
|
127
|
+
apiKey?: string;
|
|
128
|
+
baseUrl?: string;
|
|
129
|
+
model?: string;
|
|
130
|
+
timeout?: number;
|
|
131
|
+
retries?: number;
|
|
132
|
+
metadata?: StandardRecord;
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* API response structure
|
|
136
|
+
* Standard response format across providers
|
|
137
|
+
*/
|
|
138
|
+
export type ApiResponse<TData = unknown> = {
|
|
139
|
+
success: boolean;
|
|
140
|
+
data?: TData;
|
|
141
|
+
error?: string;
|
|
142
|
+
metadata?: StandardRecord;
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* Async API response type
|
|
146
|
+
*/
|
|
147
|
+
export type AsyncApiResponse<TData = unknown> = Promise<ApiResponse<TData>>;
|
|
148
|
+
/**
|
|
149
|
+
* Paginated response structure
|
|
150
|
+
* Common in list APIs
|
|
151
|
+
*/
|
|
152
|
+
export type PaginatedResponse<TData = unknown> = ApiResponse<TData> & {
|
|
153
|
+
pagination?: {
|
|
154
|
+
page: number;
|
|
155
|
+
limit: number;
|
|
156
|
+
total: number;
|
|
157
|
+
hasNext: boolean;
|
|
158
|
+
};
|
|
159
|
+
};
|
|
160
|
+
/**
|
|
161
|
+
* Basic execution context
|
|
162
|
+
* Minimal context for tool execution
|
|
163
|
+
*/
|
|
164
|
+
export type BasicContext = {
|
|
165
|
+
sessionId?: string;
|
|
166
|
+
userId?: string;
|
|
167
|
+
timestamp?: number;
|
|
168
|
+
};
|
|
169
|
+
/**
|
|
170
|
+
* Enhanced execution context
|
|
171
|
+
* Extended context with additional metadata
|
|
172
|
+
*/
|
|
173
|
+
export type EnhancedContext = BasicContext & {
|
|
174
|
+
requestId?: string;
|
|
175
|
+
metadata?: StandardRecord;
|
|
176
|
+
timeout?: number;
|
|
177
|
+
};
|
|
178
|
+
/**
|
|
179
|
+
* Tool execution context with capabilities
|
|
180
|
+
* Full context for complex tool operations
|
|
181
|
+
*/
|
|
182
|
+
export type ToolContext = EnhancedContext & {
|
|
183
|
+
capabilities?: StringArray;
|
|
184
|
+
permissions?: StringArray;
|
|
185
|
+
environment?: string;
|
|
186
|
+
};
|
|
187
|
+
/**
|
|
188
|
+
* Standard error structure
|
|
189
|
+
* Consistent error format across the codebase
|
|
190
|
+
*/
|
|
191
|
+
export type StandardError = {
|
|
192
|
+
message: string;
|
|
193
|
+
code?: string;
|
|
194
|
+
details?: StandardRecord;
|
|
195
|
+
stack?: string;
|
|
196
|
+
};
|
|
197
|
+
/**
|
|
198
|
+
* Result type with success/error pattern
|
|
199
|
+
* Common pattern for operation results
|
|
200
|
+
*/
|
|
201
|
+
export type Result<TData = unknown, TError = StandardError> = {
|
|
202
|
+
success: true;
|
|
203
|
+
data: TData;
|
|
204
|
+
} | {
|
|
205
|
+
success: false;
|
|
206
|
+
error: TError;
|
|
207
|
+
};
|
|
208
|
+
/**
|
|
209
|
+
* Async result type
|
|
210
|
+
*/
|
|
211
|
+
export type AsyncResult<TData = unknown, TError = StandardError> = Promise<Result<TData, TError>>;
|
|
212
|
+
/**
|
|
213
|
+
* Operation result with metadata
|
|
214
|
+
* Enhanced result type with additional context
|
|
215
|
+
*/
|
|
216
|
+
export type OperationResult<TData = unknown> = Result<TData> & {
|
|
217
|
+
duration?: number;
|
|
218
|
+
metadata?: StandardRecord;
|
|
219
|
+
};
|
|
220
|
+
/**
|
|
221
|
+
* Nullable type alias
|
|
222
|
+
* Common pattern for optional values
|
|
223
|
+
*/
|
|
224
|
+
export type Nullable<T> = T | null;
|
|
225
|
+
/**
|
|
226
|
+
* Optional type alias (more explicit than T | undefined)
|
|
227
|
+
*/
|
|
228
|
+
export type Optional<T> = T | undefined;
|
|
229
|
+
/**
|
|
230
|
+
* Maybe type (combines null and undefined)
|
|
231
|
+
*/
|
|
232
|
+
export type Maybe<T> = T | null | undefined;
|
|
233
|
+
/**
|
|
234
|
+
* Non-empty string type
|
|
235
|
+
* Useful for validated string inputs
|
|
236
|
+
*/
|
|
237
|
+
export type NonEmptyString = string & {
|
|
238
|
+
readonly __brand: unique symbol;
|
|
239
|
+
};
|
|
240
|
+
/**
|
|
241
|
+
* Positive number type
|
|
242
|
+
* Useful for validated numeric inputs
|
|
243
|
+
*/
|
|
244
|
+
export type PositiveNumber = number & {
|
|
245
|
+
readonly __brand: unique symbol;
|
|
246
|
+
};
|
|
247
|
+
/**
|
|
248
|
+
* Timestamp type (number representing milliseconds since epoch)
|
|
249
|
+
*/
|
|
250
|
+
export type Timestamp = number & {
|
|
251
|
+
readonly __brand: unique symbol;
|
|
252
|
+
};
|
|
253
|
+
/**
|
|
254
|
+
* ID type for entity identifiers
|
|
255
|
+
*/
|
|
256
|
+
export type EntityId = string & {
|
|
257
|
+
readonly __brand: unique symbol;
|
|
258
|
+
};
|
|
259
|
+
/**
|
|
260
|
+
* Feature flag configuration
|
|
261
|
+
* Common structure for feature toggles
|
|
262
|
+
*/
|
|
263
|
+
export type FeatureConfig = BooleanRecord & {
|
|
264
|
+
enabled?: boolean;
|
|
265
|
+
metadata?: StandardRecord;
|
|
266
|
+
};
|
|
267
|
+
/**
|
|
268
|
+
* Service configuration
|
|
269
|
+
* Standard structure for service settings
|
|
270
|
+
*/
|
|
271
|
+
export type ServiceConfig = {
|
|
272
|
+
enabled?: boolean;
|
|
273
|
+
timeout?: number;
|
|
274
|
+
retries?: number;
|
|
275
|
+
endpoint?: string;
|
|
276
|
+
apiKey?: string;
|
|
277
|
+
metadata?: StandardRecord;
|
|
278
|
+
};
|
|
279
|
+
/**
|
|
280
|
+
* Cache configuration
|
|
281
|
+
* Common caching parameters
|
|
282
|
+
*/
|
|
283
|
+
export type CacheConfig = {
|
|
284
|
+
enabled?: boolean;
|
|
285
|
+
ttl?: number;
|
|
286
|
+
maxSize?: number;
|
|
287
|
+
strategy?: "memory" | "redis" | "hybrid";
|
|
288
|
+
};
|
|
289
|
+
/**
|
|
290
|
+
* Rate limiting configuration
|
|
291
|
+
* Common rate limiting parameters
|
|
292
|
+
*/
|
|
293
|
+
export type RateLimitConfig = {
|
|
294
|
+
enabled?: boolean;
|
|
295
|
+
requestsPerMinute?: number;
|
|
296
|
+
requestsPerHour?: number;
|
|
297
|
+
burstLimit?: number;
|
|
298
|
+
};
|
|
299
|
+
/**
|
|
300
|
+
* Simple success/error result (different from generic OperationResult)
|
|
301
|
+
* Used for basic operation feedback without data payload
|
|
302
|
+
*/
|
|
303
|
+
export type SimpleResult = {
|
|
304
|
+
success: boolean;
|
|
305
|
+
error?: string;
|
|
306
|
+
};
|
|
307
|
+
/**
|
|
308
|
+
* Connectivity test result for providers
|
|
309
|
+
* Standard format for testing provider connections
|
|
310
|
+
*/
|
|
311
|
+
export type ConnectivityResult = {
|
|
312
|
+
success: boolean;
|
|
313
|
+
error?: string;
|
|
314
|
+
};
|
|
315
|
+
/**
|
|
316
|
+
* Connection result with latency information
|
|
317
|
+
* Used for detailed connection testing with performance metrics
|
|
318
|
+
*/
|
|
319
|
+
export type ConnectionResult = {
|
|
320
|
+
connected: boolean;
|
|
321
|
+
latency?: number;
|
|
322
|
+
error?: string;
|
|
323
|
+
};
|
|
324
|
+
/**
|
|
325
|
+
* Provider pair result for fallback configurations
|
|
326
|
+
* Used when creating primary/fallback provider setups
|
|
327
|
+
*/
|
|
328
|
+
export type ProviderPairResult<T = unknown> = {
|
|
329
|
+
primary: T;
|
|
330
|
+
fallback: T;
|
|
331
|
+
};
|
|
332
|
+
/**
|
|
333
|
+
* Tool execution result with enhanced prompt
|
|
334
|
+
* Common pattern in tool orchestration scenarios
|
|
335
|
+
*/
|
|
336
|
+
export type ToolExecutionResult = {
|
|
337
|
+
toolResults: unknown[];
|
|
338
|
+
enhancedPrompt: string;
|
|
339
|
+
};
|
|
340
|
+
/**
|
|
341
|
+
* Batch operation result with count and errors
|
|
342
|
+
* Standard pattern for operations that process multiple items
|
|
343
|
+
*/
|
|
344
|
+
export type BatchOperationResult = {
|
|
345
|
+
success: boolean;
|
|
346
|
+
error?: string;
|
|
347
|
+
toolCount?: number;
|
|
348
|
+
};
|
|
349
|
+
/**
|
|
350
|
+
* Server loading result with detailed feedback
|
|
351
|
+
* Used when loading multiple servers with error tracking
|
|
352
|
+
*/
|
|
353
|
+
export type ServerLoadResult = {
|
|
354
|
+
serversLoaded: number;
|
|
355
|
+
errors: string[];
|
|
356
|
+
};
|
|
357
|
+
/**
|
|
358
|
+
* Transport connection result for MCP operations
|
|
359
|
+
* Standard format for MCP transport establishment
|
|
360
|
+
* Note: Using proper types instead of unknown to fix TypeScript compilation
|
|
361
|
+
*/
|
|
362
|
+
export type TransportResult = {
|
|
363
|
+
transport: unknown;
|
|
364
|
+
process?: unknown;
|
|
365
|
+
};
|
|
366
|
+
/**
|
|
367
|
+
* Transport result with required process (for stdio transport)
|
|
368
|
+
* Used when process is guaranteed to be present
|
|
369
|
+
*/
|
|
370
|
+
export type TransportWithProcessResult = {
|
|
371
|
+
transport: unknown;
|
|
372
|
+
process: unknown;
|
|
373
|
+
};
|
|
374
|
+
/**
|
|
375
|
+
* Transport result without process (for network transports)
|
|
376
|
+
* Used for SSE and WebSocket transports that don't spawn processes
|
|
377
|
+
*/
|
|
378
|
+
export type NetworkTransportResult = {
|
|
379
|
+
transport: unknown;
|
|
380
|
+
};
|
|
381
|
+
/**
|
|
382
|
+
* Re-export commonly used types from other modules
|
|
383
|
+
* Provides one-stop shop for type imports
|
|
384
|
+
*/
|
|
385
|
+
export type { JsonValue, JsonObject, UnknownRecord } from "./common.js";
|
|
386
|
+
/**
|
|
387
|
+
* Type guard for checking if value is a StandardRecord
|
|
388
|
+
*
|
|
389
|
+
* @param value - Value to check
|
|
390
|
+
* @returns True if value is a non-null object (but not an array)
|
|
391
|
+
*
|
|
392
|
+
* @example
|
|
393
|
+
* ```typescript
|
|
394
|
+
* if (isStandardRecord(data)) {
|
|
395
|
+
* // TypeScript now knows data is Record<string, unknown>
|
|
396
|
+
* console.log(data.someProperty);
|
|
397
|
+
* }
|
|
398
|
+
* ```
|
|
399
|
+
*/
|
|
400
|
+
export declare function isStandardRecord(value: unknown): value is StandardRecord;
|
|
401
|
+
/**
|
|
402
|
+
* Type guard for checking if value is a JsonRecord
|
|
403
|
+
*/
|
|
404
|
+
export declare function isJsonRecord(value: unknown): value is JsonRecord;
|
|
405
|
+
/**
|
|
406
|
+
* Type guard for checking if value is a StringArray
|
|
407
|
+
*/
|
|
408
|
+
export declare function isStringArray(value: unknown): value is StringArray;
|
|
409
|
+
/**
|
|
410
|
+
* Type guard for checking if value is an AsyncFunction
|
|
411
|
+
*/
|
|
412
|
+
export declare function isAsyncFunction(value: unknown): value is AsyncFunction;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Comprehensive Type Alias Library
|
|
3
|
+
* Centralizes commonly used complex types to improve readability and maintainability
|
|
4
|
+
*/
|
|
5
|
+
// ============================================================================
|
|
6
|
+
// TYPE GUARDS AND UTILITIES
|
|
7
|
+
// ============================================================================
|
|
8
|
+
/**
|
|
9
|
+
* Type guard for checking if value is a StandardRecord
|
|
10
|
+
*
|
|
11
|
+
* @param value - Value to check
|
|
12
|
+
* @returns True if value is a non-null object (but not an array)
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* if (isStandardRecord(data)) {
|
|
17
|
+
* // TypeScript now knows data is Record<string, unknown>
|
|
18
|
+
* console.log(data.someProperty);
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export function isStandardRecord(value) {
|
|
23
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Type guard for checking if value is a JsonRecord
|
|
27
|
+
*/
|
|
28
|
+
export function isJsonRecord(value) {
|
|
29
|
+
return (isStandardRecord(value) &&
|
|
30
|
+
Object.values(value).every((val) => val === null ||
|
|
31
|
+
typeof val === "string" ||
|
|
32
|
+
typeof val === "number" ||
|
|
33
|
+
typeof val === "boolean" ||
|
|
34
|
+
Array.isArray(val) ||
|
|
35
|
+
isJsonRecord(val)));
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Type guard for checking if value is a StringArray
|
|
39
|
+
*/
|
|
40
|
+
export function isStringArray(value) {
|
|
41
|
+
return (Array.isArray(value) && value.every((item) => typeof item === "string"));
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Type guard for checking if value is an AsyncFunction
|
|
45
|
+
*/
|
|
46
|
+
export function isAsyncFunction(value) {
|
|
47
|
+
return typeof value === "function";
|
|
48
|
+
}
|
|
@@ -7,6 +7,7 @@ import type { GenerateOptions } from "../types/generateTypes.js";
|
|
|
7
7
|
import type { StreamOptions } from "../types/streamTypes.js";
|
|
8
8
|
import type { TextGenerationOptions } from "../core/types.js";
|
|
9
9
|
import type { UnknownRecord, JsonValue } from "../types/common.js";
|
|
10
|
+
import type { StandardRecord } from "../types/typeAliases.js";
|
|
10
11
|
/**
|
|
11
12
|
* Process factory configuration from enhanced options (with caching)
|
|
12
13
|
* Extracts and validates factory config for provider integration
|
|
@@ -14,7 +15,7 @@ import type { UnknownRecord, JsonValue } from "../types/common.js";
|
|
|
14
15
|
export declare function processFactoryOptions(options: GenerateOptions | StreamOptions): {
|
|
15
16
|
hasFactoryConfig: boolean;
|
|
16
17
|
domainType?: string;
|
|
17
|
-
domainConfig?:
|
|
18
|
+
domainConfig?: StandardRecord;
|
|
18
19
|
enhancementType?: string;
|
|
19
20
|
processedContext?: Record<string, JsonValue>;
|
|
20
21
|
};
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* Processes factory configuration and ensures it flows through to AI providers
|
|
5
5
|
*/
|
|
6
6
|
import { logger } from "./logger.js";
|
|
7
|
+
import { isNonNullObject } from "./typeUtils.js";
|
|
7
8
|
// Removed crypto import - using faster string-based hash instead
|
|
8
9
|
/**
|
|
9
10
|
* LRU Cache for factory processing results
|
|
@@ -48,7 +49,7 @@ class FactoryProcessingCache {
|
|
|
48
49
|
*/
|
|
49
50
|
generateCacheKey(options) {
|
|
50
51
|
// Use object identity cache if possible for performance
|
|
51
|
-
if (
|
|
52
|
+
if (isNonNullObject(options)) {
|
|
52
53
|
const cachedKey = this.objectKeyCache.get(options);
|
|
53
54
|
if (cachedKey) {
|
|
54
55
|
this.stats.keysCacheHits++;
|
|
@@ -63,7 +64,7 @@ class FactoryProcessingCache {
|
|
|
63
64
|
const combinedHash = this.combineHashes(factoryConfigHash, contextHash);
|
|
64
65
|
const key = combinedHash.toString(16);
|
|
65
66
|
// Cache the computed key for future use (WeakMap auto-cleans on GC)
|
|
66
|
-
if (
|
|
67
|
+
if (isNonNullObject(options)) {
|
|
67
68
|
this.objectKeyCache.set(options, key);
|
|
68
69
|
}
|
|
69
70
|
return key;
|
|
@@ -351,7 +352,7 @@ function isJsonValue(value) {
|
|
|
351
352
|
if (Array.isArray(value)) {
|
|
352
353
|
return value.every((item) => isJsonValue(item));
|
|
353
354
|
}
|
|
354
|
-
if (
|
|
355
|
+
if (isNonNullObject(value)) {
|
|
355
356
|
const obj = value;
|
|
356
357
|
return Object.values(obj).every((val) => isJsonValue(val));
|
|
357
358
|
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parameter Validation Utilities
|
|
3
|
+
* Provides consistent parameter validation across all tool interfaces
|
|
4
|
+
*/
|
|
5
|
+
import type { ValidationSchema, StringArray } from "../types/typeAliases.js";
|
|
6
|
+
/**
|
|
7
|
+
* Custom error class for parameter validation failures
|
|
8
|
+
* Provides detailed information about validation errors including field context and suggestions
|
|
9
|
+
*/
|
|
10
|
+
export declare class ValidationError extends Error {
|
|
11
|
+
field?: string | undefined;
|
|
12
|
+
code?: string | undefined;
|
|
13
|
+
suggestions?: StringArray | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Creates a new ValidationError
|
|
16
|
+
* @param message - Human-readable error message
|
|
17
|
+
* @param field - Name of the field that failed validation (optional)
|
|
18
|
+
* @param code - Error code for programmatic handling (optional)
|
|
19
|
+
* @param suggestions - Array of suggested fixes (optional)
|
|
20
|
+
*/
|
|
21
|
+
constructor(message: string, field?: string | undefined, code?: string | undefined, suggestions?: StringArray | undefined);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Result of a validation operation
|
|
25
|
+
* Contains validation status, errors, warnings, and suggestions for improvement
|
|
26
|
+
*/
|
|
27
|
+
export interface ValidationResult {
|
|
28
|
+
/** Whether the validation passed without errors */
|
|
29
|
+
isValid: boolean;
|
|
30
|
+
/** Array of validation errors that must be fixed */
|
|
31
|
+
errors: ValidationError[];
|
|
32
|
+
/** Array of warning messages that should be addressed */
|
|
33
|
+
warnings: string[];
|
|
34
|
+
/** Array of suggestions to improve the validated object */
|
|
35
|
+
suggestions: StringArray;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Validate that a string parameter is present and non-empty
|
|
39
|
+
*/
|
|
40
|
+
export declare function validateRequiredString(value: unknown, fieldName: string, minLength?: number): ValidationError | null;
|
|
41
|
+
/**
|
|
42
|
+
* Validate that a number parameter is within acceptable range
|
|
43
|
+
*/
|
|
44
|
+
export declare function validateNumberRange(value: unknown, fieldName: string, min: number, max: number, required?: boolean): ValidationError | null;
|
|
45
|
+
/**
|
|
46
|
+
* Validate that a function parameter is async and has correct signature
|
|
47
|
+
*/
|
|
48
|
+
export declare function validateAsyncFunction(value: unknown, fieldName: string, expectedParams?: StringArray): ValidationError | null;
|
|
49
|
+
/**
|
|
50
|
+
* Validate object structure with required properties
|
|
51
|
+
*/
|
|
52
|
+
export declare function validateObjectStructure(value: unknown, fieldName: string, requiredProperties: StringArray, optionalProperties?: StringArray): ValidationError | null;
|
|
53
|
+
/**
|
|
54
|
+
* Validate tool name according to naming conventions
|
|
55
|
+
*/
|
|
56
|
+
export declare function validateToolName(name: unknown): ValidationError | null;
|
|
57
|
+
/**
|
|
58
|
+
* Validate tool description for clarity and usefulness
|
|
59
|
+
*/
|
|
60
|
+
export declare function validateToolDescription(description: unknown): ValidationError | null;
|
|
61
|
+
/**
|
|
62
|
+
* Validate MCP tool structure comprehensively
|
|
63
|
+
*/
|
|
64
|
+
export declare function validateMCPTool(tool: unknown): ValidationResult;
|
|
65
|
+
/**
|
|
66
|
+
* Validate text generation options
|
|
67
|
+
*/
|
|
68
|
+
export declare function validateTextGenerationOptions(options: unknown): ValidationResult;
|
|
69
|
+
/**
|
|
70
|
+
* Validate stream options
|
|
71
|
+
*/
|
|
72
|
+
export declare function validateStreamOptions(options: unknown): ValidationResult;
|
|
73
|
+
/**
|
|
74
|
+
* Validate generate options (unified interface)
|
|
75
|
+
*/
|
|
76
|
+
export declare function validateGenerateOptions(options: unknown): ValidationResult;
|
|
77
|
+
/**
|
|
78
|
+
* Validate tool execution parameters
|
|
79
|
+
*/
|
|
80
|
+
export declare function validateToolExecutionParams(toolName: string, params: unknown, expectedSchema?: ValidationSchema): ValidationResult;
|
|
81
|
+
/**
|
|
82
|
+
* Validate multiple tools at once
|
|
83
|
+
*/
|
|
84
|
+
export declare function validateToolBatch(tools: Record<string, unknown>): {
|
|
85
|
+
isValid: boolean;
|
|
86
|
+
validTools: string[];
|
|
87
|
+
invalidTools: string[];
|
|
88
|
+
results: Record<string, ValidationResult>;
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Create a validation error summary for logging
|
|
92
|
+
*/
|
|
93
|
+
export declare function createValidationSummary(result: ValidationResult): string;
|
|
94
|
+
/**
|
|
95
|
+
* Check if validation result has only warnings (no errors)
|
|
96
|
+
*/
|
|
97
|
+
export declare function hasOnlyWarnings(result: ValidationResult): boolean;
|