@juspay/neurolink 7.6.1 → 7.7.1

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 (138) hide show
  1. package/CHANGELOG.md +15 -4
  2. package/README.md +78 -3
  3. package/dist/cli/commands/config.d.ts +275 -3
  4. package/dist/cli/commands/config.js +121 -0
  5. package/dist/cli/commands/mcp.js +77 -28
  6. package/dist/cli/factories/commandFactory.js +359 -6
  7. package/dist/core/analytics.js +7 -27
  8. package/dist/core/baseProvider.js +43 -4
  9. package/dist/core/constants.d.ts +46 -0
  10. package/dist/core/constants.js +47 -0
  11. package/dist/core/dynamicModels.d.ts +16 -4
  12. package/dist/core/dynamicModels.js +130 -26
  13. package/dist/core/evaluation.js +5 -1
  14. package/dist/core/evaluationProviders.d.ts +6 -2
  15. package/dist/core/evaluationProviders.js +41 -125
  16. package/dist/core/factory.d.ts +5 -0
  17. package/dist/core/factory.js +62 -50
  18. package/dist/core/modelConfiguration.d.ts +246 -0
  19. package/dist/core/modelConfiguration.js +775 -0
  20. package/dist/core/types.d.ts +22 -3
  21. package/dist/core/types.js +5 -1
  22. package/dist/factories/providerRegistry.js +3 -3
  23. package/dist/index.d.ts +1 -1
  24. package/dist/index.js +1 -1
  25. package/dist/lib/core/analytics.js +7 -27
  26. package/dist/lib/core/baseProvider.js +43 -4
  27. package/dist/lib/core/constants.d.ts +46 -0
  28. package/dist/lib/core/constants.js +47 -0
  29. package/dist/lib/core/dynamicModels.d.ts +16 -4
  30. package/dist/lib/core/dynamicModels.js +130 -26
  31. package/dist/lib/core/evaluation.js +5 -1
  32. package/dist/lib/core/evaluationProviders.d.ts +6 -2
  33. package/dist/lib/core/evaluationProviders.js +41 -125
  34. package/dist/lib/core/factory.d.ts +5 -0
  35. package/dist/lib/core/factory.js +63 -50
  36. package/dist/lib/core/modelConfiguration.d.ts +246 -0
  37. package/dist/lib/core/modelConfiguration.js +775 -0
  38. package/dist/lib/core/types.d.ts +22 -3
  39. package/dist/lib/core/types.js +5 -1
  40. package/dist/lib/factories/providerRegistry.js +3 -3
  41. package/dist/lib/index.d.ts +1 -1
  42. package/dist/lib/index.js +1 -1
  43. package/dist/lib/mcp/factory.d.ts +5 -5
  44. package/dist/lib/mcp/factory.js +2 -2
  45. package/dist/lib/mcp/servers/utilities/utilityServer.d.ts +1 -1
  46. package/dist/lib/mcp/servers/utilities/utilityServer.js +1 -1
  47. package/dist/lib/mcp/toolRegistry.js +2 -2
  48. package/dist/lib/neurolink.d.ts +168 -12
  49. package/dist/lib/neurolink.js +685 -123
  50. package/dist/lib/providers/anthropic.js +52 -2
  51. package/dist/lib/providers/googleAiStudio.js +4 -0
  52. package/dist/lib/providers/googleVertex.d.ts +75 -9
  53. package/dist/lib/providers/googleVertex.js +365 -46
  54. package/dist/lib/providers/huggingFace.d.ts +52 -11
  55. package/dist/lib/providers/huggingFace.js +180 -42
  56. package/dist/lib/providers/litellm.d.ts +9 -9
  57. package/dist/lib/providers/litellm.js +103 -16
  58. package/dist/lib/providers/ollama.d.ts +52 -17
  59. package/dist/lib/providers/ollama.js +276 -68
  60. package/dist/lib/sdk/toolRegistration.d.ts +42 -0
  61. package/dist/lib/sdk/toolRegistration.js +269 -27
  62. package/dist/lib/telemetry/telemetryService.d.ts +6 -0
  63. package/dist/lib/telemetry/telemetryService.js +38 -3
  64. package/dist/lib/types/contextTypes.d.ts +75 -11
  65. package/dist/lib/types/contextTypes.js +227 -1
  66. package/dist/lib/types/domainTypes.d.ts +62 -0
  67. package/dist/lib/types/domainTypes.js +5 -0
  68. package/dist/lib/types/generateTypes.d.ts +52 -0
  69. package/dist/lib/types/index.d.ts +1 -0
  70. package/dist/lib/types/mcpTypes.d.ts +1 -1
  71. package/dist/lib/types/mcpTypes.js +1 -1
  72. package/dist/lib/types/streamTypes.d.ts +14 -0
  73. package/dist/lib/types/universalProviderOptions.d.ts +1 -1
  74. package/dist/lib/utils/errorHandling.d.ts +142 -0
  75. package/dist/lib/utils/errorHandling.js +316 -0
  76. package/dist/lib/utils/factoryProcessing.d.ts +74 -0
  77. package/dist/lib/utils/factoryProcessing.js +588 -0
  78. package/dist/lib/utils/optionsConversion.d.ts +54 -0
  79. package/dist/lib/utils/optionsConversion.js +126 -0
  80. package/dist/lib/utils/optionsUtils.d.ts +246 -0
  81. package/dist/lib/utils/optionsUtils.js +960 -0
  82. package/dist/lib/utils/providerConfig.js +6 -2
  83. package/dist/lib/utils/providerHealth.d.ts +107 -0
  84. package/dist/lib/utils/providerHealth.js +543 -0
  85. package/dist/lib/utils/providerUtils.d.ts +17 -0
  86. package/dist/lib/utils/providerUtils.js +271 -16
  87. package/dist/lib/utils/timeout.js +1 -1
  88. package/dist/lib/utils/tokenLimits.d.ts +33 -0
  89. package/dist/lib/utils/tokenLimits.js +118 -0
  90. package/dist/mcp/factory.d.ts +5 -5
  91. package/dist/mcp/factory.js +2 -2
  92. package/dist/mcp/servers/utilities/utilityServer.d.ts +1 -1
  93. package/dist/mcp/servers/utilities/utilityServer.js +1 -1
  94. package/dist/mcp/toolRegistry.js +2 -2
  95. package/dist/neurolink.d.ts +168 -12
  96. package/dist/neurolink.js +685 -123
  97. package/dist/providers/anthropic.js +52 -2
  98. package/dist/providers/googleAiStudio.js +4 -0
  99. package/dist/providers/googleVertex.d.ts +75 -9
  100. package/dist/providers/googleVertex.js +365 -46
  101. package/dist/providers/huggingFace.d.ts +52 -11
  102. package/dist/providers/huggingFace.js +181 -43
  103. package/dist/providers/litellm.d.ts +9 -9
  104. package/dist/providers/litellm.js +103 -16
  105. package/dist/providers/ollama.d.ts +52 -17
  106. package/dist/providers/ollama.js +276 -68
  107. package/dist/sdk/toolRegistration.d.ts +42 -0
  108. package/dist/sdk/toolRegistration.js +269 -27
  109. package/dist/telemetry/telemetryService.d.ts +6 -0
  110. package/dist/telemetry/telemetryService.js +38 -3
  111. package/dist/types/contextTypes.d.ts +75 -11
  112. package/dist/types/contextTypes.js +227 -2
  113. package/dist/types/domainTypes.d.ts +62 -0
  114. package/dist/types/domainTypes.js +5 -0
  115. package/dist/types/generateTypes.d.ts +52 -0
  116. package/dist/types/index.d.ts +1 -0
  117. package/dist/types/mcpTypes.d.ts +1 -1
  118. package/dist/types/mcpTypes.js +1 -1
  119. package/dist/types/streamTypes.d.ts +14 -0
  120. package/dist/types/universalProviderOptions.d.ts +1 -1
  121. package/dist/types/universalProviderOptions.js +0 -1
  122. package/dist/utils/errorHandling.d.ts +142 -0
  123. package/dist/utils/errorHandling.js +316 -0
  124. package/dist/utils/factoryProcessing.d.ts +74 -0
  125. package/dist/utils/factoryProcessing.js +588 -0
  126. package/dist/utils/optionsConversion.d.ts +54 -0
  127. package/dist/utils/optionsConversion.js +126 -0
  128. package/dist/utils/optionsUtils.d.ts +246 -0
  129. package/dist/utils/optionsUtils.js +960 -0
  130. package/dist/utils/providerConfig.js +6 -2
  131. package/dist/utils/providerHealth.d.ts +107 -0
  132. package/dist/utils/providerHealth.js +543 -0
  133. package/dist/utils/providerUtils.d.ts +17 -0
  134. package/dist/utils/providerUtils.js +271 -16
  135. package/dist/utils/timeout.js +1 -1
  136. package/dist/utils/tokenLimits.d.ts +33 -0
  137. package/dist/utils/tokenLimits.js +118 -0
  138. package/package.json +2 -2
@@ -2,11 +2,123 @@
2
2
  * Context Types for NeuroLink - Factory Pattern Implementation
3
3
  * Provides type-safe context integration for AI generation
4
4
  */
5
- import { JsonValue, JsonObject } from "./common.js";
6
5
  /**
7
6
  * Factory for context processing
8
7
  */
9
8
  export class ContextFactory {
9
+ /**
10
+ * Default framework fields configuration
11
+ */
12
+ static DEFAULT_FRAMEWORK_FIELDS = {
13
+ defaultFields: [
14
+ "sessionId",
15
+ "userId",
16
+ "apiToken",
17
+ "authToken",
18
+ "apiEndpoint",
19
+ "serviceUrl",
20
+ "endpoint",
21
+ "environment",
22
+ "region",
23
+ "enabledFeatures",
24
+ "platformType",
25
+ "platformUrl",
26
+ "platformId",
27
+ "enableDemoMode",
28
+ ],
29
+ additionalFields: [],
30
+ includeFields: [],
31
+ };
32
+ /**
33
+ * Current framework fields configuration
34
+ */
35
+ static frameworkFieldsConfig = ContextFactory.DEFAULT_FRAMEWORK_FIELDS;
36
+ /**
37
+ * Flag to track if framework fields have been initialized
38
+ */
39
+ static isFrameworkFieldsInitialized = false;
40
+ /**
41
+ * Configure framework fields for exclusion from custom data
42
+ */
43
+ static configureFrameworkFields(config) {
44
+ ContextFactory.frameworkFieldsConfig = {
45
+ ...ContextFactory.DEFAULT_FRAMEWORK_FIELDS,
46
+ ...config,
47
+ };
48
+ ContextFactory.isFrameworkFieldsInitialized = true;
49
+ }
50
+ /**
51
+ * Get current framework fields configuration
52
+ * Ensures lazy initialization if not already loaded
53
+ */
54
+ static getFrameworkFieldsConfig() {
55
+ // Lazy initialization - load from environment if not explicitly configured
56
+ if (!ContextFactory.isFrameworkFieldsInitialized) {
57
+ ContextFactory.loadFrameworkFieldsFromEnv();
58
+ ContextFactory.isFrameworkFieldsInitialized = true;
59
+ }
60
+ return { ...ContextFactory.frameworkFieldsConfig };
61
+ }
62
+ /**
63
+ * Reset framework fields configuration to default
64
+ */
65
+ static resetFrameworkFieldsConfig() {
66
+ ContextFactory.frameworkFieldsConfig = {
67
+ ...ContextFactory.DEFAULT_FRAMEWORK_FIELDS,
68
+ };
69
+ }
70
+ /**
71
+ * Load framework fields configuration from environment variables
72
+ * Supports NEUROLINK_CONTEXT_EXCLUDE_FIELDS and NEUROLINK_CONTEXT_INCLUDE_FIELDS
73
+ */
74
+ static loadFrameworkFieldsFromEnv() {
75
+ const excludeFields = process.env.NEUROLINK_CONTEXT_EXCLUDE_FIELDS;
76
+ const includeFields = process.env.NEUROLINK_CONTEXT_INCLUDE_FIELDS;
77
+ const overrideFields = process.env.NEUROLINK_CONTEXT_OVERRIDE_FIELDS;
78
+ const config = {};
79
+ if (excludeFields) {
80
+ config.additionalFields = excludeFields
81
+ .split(",")
82
+ .map((f) => f.trim())
83
+ .filter(Boolean);
84
+ }
85
+ if (includeFields) {
86
+ config.includeFields = includeFields
87
+ .split(",")
88
+ .map((f) => f.trim())
89
+ .filter(Boolean);
90
+ }
91
+ if (overrideFields) {
92
+ config.overrideFields = overrideFields
93
+ .split(",")
94
+ .map((f) => f.trim())
95
+ .filter(Boolean);
96
+ }
97
+ // Optimized check: avoid creating array with Object.keys() for simple property existence check
98
+ const hasConfigChanges = config.additionalFields || config.includeFields || config.overrideFields;
99
+ if (hasConfigChanges) {
100
+ ContextFactory.configureFrameworkFields(config);
101
+ }
102
+ ContextFactory.isFrameworkFieldsInitialized = true;
103
+ }
104
+ /**
105
+ * Add additional fields to exclude
106
+ */
107
+ static addFrameworkFieldsToExclude(fields) {
108
+ const currentConfig = ContextFactory.frameworkFieldsConfig;
109
+ ContextFactory.configureFrameworkFields({
110
+ additionalFields: [...(currentConfig.additionalFields || []), ...fields],
111
+ });
112
+ }
113
+ /**
114
+ * Add fields to include (override exclusion)
115
+ */
116
+ static addFrameworkFieldsToInclude(fields) {
117
+ const currentConfig = ContextFactory.frameworkFieldsConfig;
118
+ ContextFactory.configureFrameworkFields({
119
+ includeFields: [...(currentConfig.includeFields || []), ...fields],
120
+ });
121
+ }
10
122
  /**
11
123
  * Default context configuration
12
124
  */
@@ -172,6 +284,119 @@ export class ContextFactory {
172
284
  /**
173
285
  * Type guard to check if value is valid context
174
286
  */
175
- export function isValidContext(value) {
287
+ function isValidContext(value) {
176
288
  return ContextFactory.validateContext(value) !== null;
177
289
  }
290
+ export class ContextConverter {
291
+ /**
292
+ * Convert legacy business context to generic domain context
293
+ * Based on business context patterns
294
+ */
295
+ static convertBusinessContext(legacyContext, domainType, options = {}) {
296
+ const { preserveLegacyFields = false, validateDomainData = true, includeMetadata = true, } = options;
297
+ return {
298
+ sessionId: legacyContext.sessionId,
299
+ userId: legacyContext.userId,
300
+ config: {
301
+ domainType,
302
+ providerConfig: {
303
+ token: legacyContext.apiToken ||
304
+ legacyContext.authToken ||
305
+ legacyContext.accessToken,
306
+ endpoint: legacyContext.apiEndpoint || legacyContext.serviceUrl,
307
+ provider: this.inferProvider(legacyContext),
308
+ },
309
+ platformConfig: {
310
+ type: legacyContext.platformType || "generic",
311
+ url: legacyContext.platformUrl || legacyContext.serviceUrl,
312
+ id: legacyContext.platformId || legacyContext.serviceId,
313
+ integrations: legacyContext.platformIntegrations || [],
314
+ },
315
+ operationalConfig: {
316
+ demoMode: legacyContext.enableDemoMode || false,
317
+ environment: legacyContext.environment || "production",
318
+ region: legacyContext.region,
319
+ features: legacyContext.enabledFeatures || [],
320
+ },
321
+ customData: {
322
+ // Preserve domain-specific fields if needed
323
+ ...(preserveLegacyFields
324
+ ? {
325
+ entityId: legacyContext.entityId || legacyContext.organizationId,
326
+ departmentId: legacyContext.departmentId,
327
+ projectId: legacyContext.projectId,
328
+ }
329
+ : {}),
330
+ // Include any additional custom data
331
+ ...this.extractCustomData(legacyContext),
332
+ },
333
+ },
334
+ metadata: includeMetadata
335
+ ? {
336
+ convertedFrom: "legacy-business-context",
337
+ conversionTime: Date.now(),
338
+ originalKeys: Object.keys(legacyContext),
339
+ domainType,
340
+ }
341
+ : undefined,
342
+ };
343
+ }
344
+ /**
345
+ * Create execution context for any domain
346
+ */
347
+ static createDomainContext(domainType, domainData, sessionInfo = {}) {
348
+ return {
349
+ sessionId: sessionInfo.sessionId || `session_${Date.now()}`,
350
+ userId: sessionInfo.userId,
351
+ config: {
352
+ domainType,
353
+ customData: domainData,
354
+ },
355
+ metadata: {
356
+ source: "domain-context-factory",
357
+ createdAt: Date.now(),
358
+ domainType,
359
+ },
360
+ };
361
+ }
362
+ static inferProvider(context) {
363
+ // Generic provider inference based on context structure
364
+ if (context.apiToken || context.authToken) {
365
+ return "api-provider";
366
+ }
367
+ if (context.serviceUrl || context.endpoint) {
368
+ return "service-provider";
369
+ }
370
+ return "generic-provider";
371
+ }
372
+ static extractCustomData(context) {
373
+ // Get current framework fields configuration
374
+ const config = ContextFactory.getFrameworkFieldsConfig();
375
+ // Build the set of fields to exclude
376
+ let fieldsToExclude;
377
+ if (config.overrideFields) {
378
+ // Use override fields completely
379
+ fieldsToExclude = new Set(config.overrideFields);
380
+ }
381
+ else {
382
+ // Use default fields + additional fields
383
+ fieldsToExclude = new Set([
384
+ ...config.defaultFields,
385
+ ...(config.additionalFields || []),
386
+ ]);
387
+ }
388
+ // Remove any fields that should be included despite being in the exclude list
389
+ if (config.includeFields) {
390
+ config.includeFields.forEach((field) => fieldsToExclude.delete(field));
391
+ }
392
+ const customData = {};
393
+ Object.entries(context).forEach(([key, value]) => {
394
+ if (!fieldsToExclude.has(key)) {
395
+ customData[key] = value;
396
+ }
397
+ });
398
+ return customData;
399
+ }
400
+ }
401
+ // Framework fields configuration loading moved to lazy initialization
402
+ // Call ContextFactory.loadFrameworkFieldsFromEnv() explicitly in application entrypoint or test setup
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Domain Types for Factory Pattern Implementation
3
+ * Provides type-safe domain configuration and factory pattern support
4
+ */
5
+ import type { JsonObject } from "./common.js";
6
+ /**
7
+ * Supported domain types for factory configuration
8
+ */
9
+ export type DomainType = "healthcare" | "finance" | "analytics" | "ecommerce" | "education" | "legal" | "technology" | "generic";
10
+ /**
11
+ * Domain evaluation criteria interface
12
+ */
13
+ export interface DomainEvaluationCriteria {
14
+ accuracyWeight: number;
15
+ completenessWeight: number;
16
+ relevanceWeight: number;
17
+ terminologyWeight: number;
18
+ domainSpecificRules: string[];
19
+ failurePatterns: string[];
20
+ successPatterns: string[];
21
+ }
22
+ /**
23
+ * Domain configuration interface
24
+ */
25
+ export interface DomainConfig {
26
+ domainType: DomainType;
27
+ domainName: string;
28
+ description: string;
29
+ evaluationCriteria: DomainEvaluationCriteria;
30
+ customData?: JsonObject;
31
+ metadata?: {
32
+ version: string;
33
+ createdAt: number;
34
+ updatedAt: number;
35
+ };
36
+ }
37
+ /**
38
+ * Domain template for factory registration
39
+ */
40
+ export interface DomainTemplate {
41
+ domainType: DomainType;
42
+ template: Partial<DomainConfig>;
43
+ isDefault?: boolean;
44
+ }
45
+ /**
46
+ * Domain validation rule
47
+ */
48
+ export interface DomainValidationRule {
49
+ ruleName: string;
50
+ ruleType: "required" | "pattern" | "range" | "custom";
51
+ validation: (value: unknown) => boolean;
52
+ errorMessage: string;
53
+ }
54
+ /**
55
+ * Domain configuration options for factory
56
+ */
57
+ export interface DomainConfigOptions {
58
+ domainType: DomainType;
59
+ customConfig?: Partial<DomainConfig>;
60
+ validateDomainData?: boolean;
61
+ includeDefaults?: boolean;
62
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Domain Types for Factory Pattern Implementation
3
+ * Provides type-safe domain configuration and factory pattern support
4
+ */
5
+ export {};
@@ -30,6 +30,20 @@ export interface GenerateOptions {
30
30
  role: string;
31
31
  content: string;
32
32
  }>;
33
+ factoryConfig?: {
34
+ domainType?: string;
35
+ domainConfig?: Record<string, unknown>;
36
+ enhancementType?: "domain-configuration" | "streaming-optimization" | "mcp-integration" | "legacy-migration" | "context-conversion";
37
+ preserveLegacyFields?: boolean;
38
+ validateDomainData?: boolean;
39
+ };
40
+ streaming?: {
41
+ enabled?: boolean;
42
+ chunkSize?: number;
43
+ bufferSize?: number;
44
+ enableProgress?: boolean;
45
+ fallbackToGenerate?: boolean;
46
+ };
33
47
  }
34
48
  /**
35
49
  * Generate function result interface - Primary output format
@@ -69,6 +83,31 @@ export interface GenerateResult {
69
83
  }>;
70
84
  analytics?: AnalyticsData;
71
85
  evaluation?: EvaluationData;
86
+ factoryMetadata?: {
87
+ enhancementApplied: boolean;
88
+ enhancementType?: string;
89
+ domainType?: string;
90
+ processingTime?: number;
91
+ configurationUsed?: Record<string, unknown>;
92
+ migrationPerformed?: boolean;
93
+ legacyFieldsPreserved?: boolean;
94
+ };
95
+ streamingMetadata?: {
96
+ streamingUsed: boolean;
97
+ fallbackToGenerate?: boolean;
98
+ chunkCount?: number;
99
+ streamingDuration?: number;
100
+ streamId?: string;
101
+ bufferOptimization?: boolean;
102
+ };
103
+ }
104
+ /**
105
+ * Unified options for both generation and streaming
106
+ * Supports factory patterns and domain configuration
107
+ */
108
+ export interface UnifiedGenerationOptions extends GenerateOptions {
109
+ preferStreaming?: boolean;
110
+ streamingFallback?: boolean;
72
111
  }
73
112
  /**
74
113
  * Enhanced provider interface with generate method
@@ -78,3 +117,16 @@ export interface EnhancedProvider {
78
117
  getName(): string;
79
118
  isAvailable(): Promise<boolean>;
80
119
  }
120
+ /**
121
+ * Factory-enhanced provider interface
122
+ * Supports domain configuration and streaming optimizations
123
+ */
124
+ export interface FactoryEnhancedProvider extends EnhancedProvider {
125
+ generateWithFactory(options: UnifiedGenerationOptions): Promise<GenerateResult>;
126
+ getDomainSupport(): string[];
127
+ getStreamingCapabilities(): {
128
+ supportsStreaming: boolean;
129
+ maxChunkSize: number;
130
+ bufferOptimizations: boolean;
131
+ };
132
+ }
@@ -13,3 +13,4 @@ export type { BaseCommandArgs, GenerateCommandArgs, MCPCommandArgs, ModelsComman
13
13
  export type { MCPTransportType, MCPServerStatus, MCPDiscoveredServer, MCPConnectedServer, MCPServerConfig, MCPToolInfo, MCPServerMetadata, MCPToolMetadata, MCPServerRegistryEntry, } from "./mcpTypes.js";
14
14
  export type { ModelCapability, ModelUseCase, ModelFilter, ModelResolutionContext, ModelStats, ModelPricing, } from "./providers.js";
15
15
  export type { ToolCallResults, ToolCalls, StreamAnalyticsData, } from "./streamTypes.js";
16
+ export type { DomainType, DomainConfig, DomainTemplate, DomainConfigOptions, DomainEvaluationCriteria, DomainValidationRule, } from "./domainTypes.js";
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * MCP Types for In-Memory Server Support
3
- * Enables Lighthouse and other integrations to register tools directly
3
+ * Enables various integrations to register tools directly
4
4
  */
5
5
  import type { JsonValue, JsonObject } from "./common.js";
6
6
  /**
@@ -1,5 +1,5 @@
1
1
  /**
2
2
  * MCP Types for In-Memory Server Support
3
- * Enables Lighthouse and other integrations to register tools directly
3
+ * Enables various integrations to register tools directly
4
4
  */
5
5
  export {};
@@ -93,6 +93,20 @@ export interface StreamOptions {
93
93
  role: string;
94
94
  content: string;
95
95
  }>;
96
+ factoryConfig?: {
97
+ domainType?: string;
98
+ domainConfig?: Record<string, unknown>;
99
+ enhancementType?: "domain-configuration" | "streaming-optimization" | "mcp-integration" | "legacy-migration" | "context-conversion";
100
+ preserveLegacyFields?: boolean;
101
+ validateDomainData?: boolean;
102
+ };
103
+ streaming?: {
104
+ enabled?: boolean;
105
+ chunkSize?: number;
106
+ bufferSize?: number;
107
+ enableProgress?: boolean;
108
+ fallbackToGenerate?: boolean;
109
+ };
96
110
  }
97
111
  /**
98
112
  * Stream function result interface - Primary output format for streaming
@@ -2,7 +2,7 @@
2
2
  * Universal Provider Options Interface (Phase 1: Factory Pattern)
3
3
  * Based on TypeScript factory pattern best practices for AI provider abstraction
4
4
  */
5
- import { BaseContext, ContextConfig } from "./contextTypes.js";
5
+ import type { BaseContext, ContextConfig } from "./contextTypes.js";
6
6
  /**
7
7
  * Base configuration interface for all AI providers
8
8
  * Uses Parameter Object Pattern for flexible, extensible configuration
@@ -2,7 +2,6 @@
2
2
  * Universal Provider Options Interface (Phase 1: Factory Pattern)
3
3
  * Based on TypeScript factory pattern best practices for AI provider abstraction
4
4
  */
5
- import { BaseContext, ContextConfig } from "./contextTypes.js";
6
5
  /**
7
6
  * Parameter normalization utilities
8
7
  * Converts between different parameter formats for backward compatibility
@@ -0,0 +1,142 @@
1
+ /**
2
+ * Robust Error Handling Utilities for NeuroLink
3
+ * Provides structured error management for tool execution and system operations
4
+ */
5
+ export declare enum ErrorCategory {
6
+ VALIDATION = "validation",
7
+ TIMEOUT = "timeout",
8
+ NETWORK = "network",
9
+ RESOURCE = "resource",
10
+ PERMISSION = "permission",
11
+ CONFIGURATION = "configuration",
12
+ EXECUTION = "execution",
13
+ SYSTEM = "system"
14
+ }
15
+ export declare enum ErrorSeverity {
16
+ LOW = "low",
17
+ MEDIUM = "medium",
18
+ HIGH = "high",
19
+ CRITICAL = "critical"
20
+ }
21
+ export interface StructuredError {
22
+ code: string;
23
+ message: string;
24
+ category: ErrorCategory;
25
+ severity: ErrorSeverity;
26
+ retriable: boolean;
27
+ context?: Record<string, unknown>;
28
+ originalError?: Error;
29
+ timestamp: Date;
30
+ toolName?: string;
31
+ serverId?: string;
32
+ }
33
+ export declare const ERROR_CODES: {
34
+ readonly TOOL_NOT_FOUND: "TOOL_NOT_FOUND";
35
+ readonly TOOL_EXECUTION_FAILED: "TOOL_EXECUTION_FAILED";
36
+ readonly TOOL_TIMEOUT: "TOOL_TIMEOUT";
37
+ readonly TOOL_VALIDATION_FAILED: "TOOL_VALIDATION_FAILED";
38
+ readonly INVALID_PARAMETERS: "INVALID_PARAMETERS";
39
+ readonly MISSING_REQUIRED_PARAM: "MISSING_REQUIRED_PARAM";
40
+ readonly MEMORY_EXHAUSTED: "MEMORY_EXHAUSTED";
41
+ readonly NETWORK_ERROR: "NETWORK_ERROR";
42
+ readonly PERMISSION_DENIED: "PERMISSION_DENIED";
43
+ readonly PROVIDER_NOT_AVAILABLE: "PROVIDER_NOT_AVAILABLE";
44
+ readonly PROVIDER_AUTH_FAILED: "PROVIDER_AUTH_FAILED";
45
+ readonly PROVIDER_QUOTA_EXCEEDED: "PROVIDER_QUOTA_EXCEEDED";
46
+ readonly INVALID_CONFIGURATION: "INVALID_CONFIGURATION";
47
+ readonly MISSING_CONFIGURATION: "MISSING_CONFIGURATION";
48
+ };
49
+ /**
50
+ * Enhanced error class with structured information
51
+ */
52
+ export declare class NeuroLinkError extends Error {
53
+ readonly code: string;
54
+ readonly category: ErrorCategory;
55
+ readonly severity: ErrorSeverity;
56
+ readonly retriable: boolean;
57
+ readonly context: Record<string, unknown>;
58
+ readonly timestamp: Date;
59
+ readonly toolName?: string;
60
+ readonly serverId?: string;
61
+ constructor(options: {
62
+ code: string;
63
+ message: string;
64
+ category: ErrorCategory;
65
+ severity: ErrorSeverity;
66
+ retriable: boolean;
67
+ context?: Record<string, unknown>;
68
+ originalError?: Error;
69
+ toolName?: string;
70
+ serverId?: string;
71
+ });
72
+ /**
73
+ * Convert to JSON for logging and serialization
74
+ */
75
+ toJSON(): StructuredError;
76
+ }
77
+ /**
78
+ * Error factory for common error scenarios
79
+ */
80
+ export declare class ErrorFactory {
81
+ /**
82
+ * Create a tool not found error
83
+ */
84
+ static toolNotFound(toolName: string, availableTools?: string[]): NeuroLinkError;
85
+ /**
86
+ * Create a tool execution failed error
87
+ */
88
+ static toolExecutionFailed(toolName: string, originalError: Error, serverId?: string): NeuroLinkError;
89
+ /**
90
+ * Create a tool timeout error
91
+ */
92
+ static toolTimeout(toolName: string, timeoutMs: number, serverId?: string): NeuroLinkError;
93
+ /**
94
+ * Create a parameter validation error
95
+ */
96
+ static invalidParameters(toolName: string, validationError: Error, providedParams?: unknown): NeuroLinkError;
97
+ /**
98
+ * Create a network error
99
+ */
100
+ static networkError(toolName: string, originalError: Error, serverId?: string): NeuroLinkError;
101
+ /**
102
+ * Create a memory exhaustion error
103
+ */
104
+ static memoryExhausted(toolName: string, memoryUsageMB: number): NeuroLinkError;
105
+ }
106
+ /**
107
+ * Timeout wrapper for async operations
108
+ */
109
+ export declare function withTimeout<T>(promise: Promise<T>, timeoutMs: number, timeoutError?: Error): Promise<T>;
110
+ /**
111
+ * Retry mechanism for retriable operations
112
+ */
113
+ export declare function withRetry<T>(operation: () => Promise<T>, options: {
114
+ maxAttempts: number;
115
+ delayMs: number;
116
+ isRetriable?: (error: Error) => boolean;
117
+ onRetry?: (attempt: number, error: Error) => void;
118
+ }): Promise<T>;
119
+ /**
120
+ * Circuit breaker for preventing cascading failures
121
+ */
122
+ export declare class CircuitBreaker {
123
+ private readonly failureThreshold;
124
+ private readonly resetTimeoutMs;
125
+ private failures;
126
+ private lastFailureTime;
127
+ private state;
128
+ constructor(failureThreshold?: number, resetTimeoutMs?: number);
129
+ execute<T>(operation: () => Promise<T>): Promise<T>;
130
+ private onSuccess;
131
+ private onFailure;
132
+ getState(): "closed" | "open" | "half-open";
133
+ getFailureCount(): number;
134
+ }
135
+ /**
136
+ * Error handler that decides whether to retry based on error type
137
+ */
138
+ export declare function isRetriableError(error: Error): boolean;
139
+ /**
140
+ * Enhanced error logger that provides structured logging
141
+ */
142
+ export declare function logStructuredError(error: NeuroLinkError, context?: Record<string, unknown>): void;