@juspay/neurolink 7.1.0 → 7.2.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 (92) hide show
  1. package/CHANGELOG.md +8 -2
  2. package/README.md +16 -11
  3. package/dist/cli/commands/config.d.ts +2 -2
  4. package/dist/cli/commands/config.js +22 -21
  5. package/dist/cli/commands/mcp.d.ts +79 -0
  6. package/dist/cli/commands/mcp.js +916 -0
  7. package/dist/cli/commands/models.d.ts +63 -0
  8. package/dist/cli/commands/models.js +653 -0
  9. package/dist/cli/commands/ollama.js +56 -55
  10. package/dist/cli/factories/commandFactory.d.ts +14 -0
  11. package/dist/cli/factories/commandFactory.js +346 -47
  12. package/dist/cli/index.js +25 -10
  13. package/dist/cli/utils/completeSetup.js +9 -8
  14. package/dist/cli/utils/envManager.js +7 -6
  15. package/dist/cli/utils/interactiveSetup.js +20 -19
  16. package/dist/core/analytics.js +25 -38
  17. package/dist/core/baseProvider.d.ts +8 -0
  18. package/dist/core/baseProvider.js +177 -68
  19. package/dist/core/constants.d.ts +11 -0
  20. package/dist/core/constants.js +17 -0
  21. package/dist/core/evaluation.js +25 -14
  22. package/dist/core/factory.js +19 -18
  23. package/dist/core/streamAnalytics.d.ts +65 -0
  24. package/dist/core/streamAnalytics.js +125 -0
  25. package/dist/lib/core/analytics.js +25 -38
  26. package/dist/lib/core/baseProvider.d.ts +8 -0
  27. package/dist/lib/core/baseProvider.js +177 -68
  28. package/dist/lib/core/constants.d.ts +11 -0
  29. package/dist/lib/core/constants.js +17 -0
  30. package/dist/lib/core/evaluation.js +25 -14
  31. package/dist/lib/core/factory.js +19 -18
  32. package/dist/lib/core/streamAnalytics.d.ts +65 -0
  33. package/dist/lib/core/streamAnalytics.js +125 -0
  34. package/dist/lib/models/modelRegistry.d.ts +132 -0
  35. package/dist/lib/models/modelRegistry.js +483 -0
  36. package/dist/lib/models/modelResolver.d.ts +115 -0
  37. package/dist/lib/models/modelResolver.js +467 -0
  38. package/dist/lib/neurolink.d.ts +4 -1
  39. package/dist/lib/neurolink.js +101 -67
  40. package/dist/lib/providers/anthropic.js +3 -0
  41. package/dist/lib/providers/googleAiStudio.js +13 -0
  42. package/dist/lib/providers/huggingFace.js +15 -3
  43. package/dist/lib/providers/mistral.js +19 -7
  44. package/dist/lib/providers/ollama.js +31 -7
  45. package/dist/lib/providers/openAI.js +12 -0
  46. package/dist/lib/sdk/toolRegistration.js +2 -2
  47. package/dist/lib/types/cli.d.ts +56 -1
  48. package/dist/lib/types/contextTypes.d.ts +110 -0
  49. package/dist/lib/types/contextTypes.js +176 -0
  50. package/dist/lib/types/index.d.ts +4 -1
  51. package/dist/lib/types/mcpTypes.d.ts +118 -7
  52. package/dist/lib/types/providers.d.ts +81 -0
  53. package/dist/lib/types/streamTypes.d.ts +44 -7
  54. package/dist/lib/types/tools.d.ts +9 -0
  55. package/dist/lib/types/universalProviderOptions.d.ts +3 -1
  56. package/dist/lib/types/universalProviderOptions.js +2 -1
  57. package/dist/lib/utils/logger.d.ts +7 -0
  58. package/dist/lib/utils/logger.js +11 -0
  59. package/dist/lib/utils/performance.d.ts +105 -0
  60. package/dist/lib/utils/performance.js +210 -0
  61. package/dist/lib/utils/retryHandler.d.ts +89 -0
  62. package/dist/lib/utils/retryHandler.js +269 -0
  63. package/dist/models/modelRegistry.d.ts +132 -0
  64. package/dist/models/modelRegistry.js +483 -0
  65. package/dist/models/modelResolver.d.ts +115 -0
  66. package/dist/models/modelResolver.js +468 -0
  67. package/dist/neurolink.d.ts +4 -1
  68. package/dist/neurolink.js +101 -67
  69. package/dist/providers/anthropic.js +3 -0
  70. package/dist/providers/googleAiStudio.js +13 -0
  71. package/dist/providers/huggingFace.js +15 -3
  72. package/dist/providers/mistral.js +19 -7
  73. package/dist/providers/ollama.js +31 -7
  74. package/dist/providers/openAI.js +12 -0
  75. package/dist/sdk/toolRegistration.js +2 -2
  76. package/dist/types/cli.d.ts +56 -1
  77. package/dist/types/contextTypes.d.ts +110 -0
  78. package/dist/types/contextTypes.js +177 -0
  79. package/dist/types/index.d.ts +4 -1
  80. package/dist/types/mcpTypes.d.ts +118 -7
  81. package/dist/types/providers.d.ts +81 -0
  82. package/dist/types/streamTypes.d.ts +44 -7
  83. package/dist/types/tools.d.ts +9 -0
  84. package/dist/types/universalProviderOptions.d.ts +3 -1
  85. package/dist/types/universalProviderOptions.js +3 -1
  86. package/dist/utils/logger.d.ts +7 -0
  87. package/dist/utils/logger.js +11 -0
  88. package/dist/utils/performance.d.ts +105 -0
  89. package/dist/utils/performance.js +210 -0
  90. package/dist/utils/retryHandler.d.ts +89 -0
  91. package/dist/utils/retryHandler.js +269 -0
  92. package/package.json +2 -1
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Context Types for NeuroLink - Factory Pattern Implementation
3
+ * Provides type-safe context integration for AI generation
4
+ */
5
+ import { JsonObject } from "./common.js";
6
+ /**
7
+ * Base context interface for all AI operations
8
+ */
9
+ export interface BaseContext {
10
+ userId?: string;
11
+ sessionId?: string;
12
+ requestId?: string;
13
+ userRole?: string;
14
+ userPreferences?: JsonObject;
15
+ userMetadata?: JsonObject;
16
+ applicationContext?: {
17
+ name: string;
18
+ version?: string;
19
+ environment?: "development" | "staging" | "production";
20
+ };
21
+ organizationId?: string;
22
+ departmentId?: string;
23
+ projectId?: string;
24
+ [key: string]: unknown;
25
+ }
26
+ /**
27
+ * Context integration mode types
28
+ */
29
+ export type ContextIntegrationMode = "prompt_prefix" | "prompt_suffix" | "system_prompt" | "metadata_only" | "structured_prompt" | "none";
30
+ /**
31
+ * Context configuration for AI generation
32
+ */
33
+ export interface ContextConfig {
34
+ mode: ContextIntegrationMode;
35
+ includeInPrompt?: boolean;
36
+ includeInAnalytics?: boolean;
37
+ includeInEvaluation?: boolean;
38
+ template?: string;
39
+ maxLength?: number;
40
+ }
41
+ /**
42
+ * Context processing result
43
+ */
44
+ export interface ProcessedContext {
45
+ originalContext: BaseContext;
46
+ processedContext: string | null;
47
+ config: ContextConfig;
48
+ metadata: {
49
+ truncated: boolean;
50
+ processingTime: number;
51
+ template: string;
52
+ mode: ContextIntegrationMode;
53
+ };
54
+ }
55
+ /**
56
+ * Factory for context processing
57
+ */
58
+ export declare class ContextFactory {
59
+ /**
60
+ * Default context configuration
61
+ */
62
+ static readonly DEFAULT_CONFIG: ContextConfig;
63
+ /**
64
+ * Validate and normalize context data
65
+ */
66
+ static validateContext(context: unknown): BaseContext | null;
67
+ /**
68
+ * Process context for AI generation based on configuration
69
+ */
70
+ static processContext(context: BaseContext, config?: Partial<ContextConfig>): ProcessedContext;
71
+ /**
72
+ * Format context for prompt integration
73
+ */
74
+ private static formatContextForPrompt;
75
+ /**
76
+ * Format context as prompt prefix
77
+ */
78
+ private static formatAsPrefix;
79
+ /**
80
+ * Format context as prompt suffix
81
+ */
82
+ private static formatAsSuffix;
83
+ /**
84
+ * Format context for system prompt
85
+ */
86
+ private static formatForSystemPrompt;
87
+ /**
88
+ * Format context in structured format
89
+ */
90
+ private static formatStructured;
91
+ /**
92
+ * Extract analytics data from context
93
+ */
94
+ static extractAnalyticsContext(context: BaseContext): JsonObject;
95
+ /**
96
+ * Extract evaluation context
97
+ */
98
+ static extractEvaluationContext(context: BaseContext): JsonObject;
99
+ }
100
+ /**
101
+ * Type guard to check if value is valid context
102
+ */
103
+ export declare function isValidContext(value: unknown): value is BaseContext;
104
+ /**
105
+ * Context integration options for AI generation
106
+ */
107
+ export interface ContextIntegrationOptions {
108
+ context?: BaseContext;
109
+ contextConfig?: Partial<ContextConfig>;
110
+ }
@@ -0,0 +1,177 @@
1
+ /**
2
+ * Context Types for NeuroLink - Factory Pattern Implementation
3
+ * Provides type-safe context integration for AI generation
4
+ */
5
+ import { JsonValue, JsonObject } from "./common.js";
6
+ /**
7
+ * Factory for context processing
8
+ */
9
+ export class ContextFactory {
10
+ /**
11
+ * Default context configuration
12
+ */
13
+ static DEFAULT_CONFIG = {
14
+ mode: "metadata_only",
15
+ includeInPrompt: false,
16
+ includeInAnalytics: true,
17
+ includeInEvaluation: true,
18
+ maxLength: 1000,
19
+ };
20
+ /**
21
+ * Validate and normalize context data
22
+ */
23
+ static validateContext(context) {
24
+ if (!context || typeof context !== "object") {
25
+ return null;
26
+ }
27
+ try {
28
+ // Ensure it's JSON serializable
29
+ const serialized = JSON.stringify(context);
30
+ const parsed = JSON.parse(serialized);
31
+ // Basic validation
32
+ if (typeof parsed !== "object" || Array.isArray(parsed)) {
33
+ return null;
34
+ }
35
+ return parsed;
36
+ }
37
+ catch {
38
+ return null;
39
+ }
40
+ }
41
+ /**
42
+ * Process context for AI generation based on configuration
43
+ */
44
+ static processContext(context, config = {}) {
45
+ const startTime = Date.now();
46
+ const finalConfig = { ...this.DEFAULT_CONFIG, ...config };
47
+ let processedContext = null;
48
+ const template = "default";
49
+ let truncated = false;
50
+ if (finalConfig.includeInPrompt && finalConfig.mode !== "metadata_only") {
51
+ processedContext = this.formatContextForPrompt(context, finalConfig);
52
+ // Truncate if necessary
53
+ if (finalConfig.maxLength &&
54
+ processedContext.length > finalConfig.maxLength) {
55
+ processedContext =
56
+ processedContext.substring(0, finalConfig.maxLength) + "...";
57
+ truncated = true;
58
+ }
59
+ }
60
+ const processingTime = Date.now() - startTime;
61
+ return {
62
+ originalContext: context,
63
+ processedContext,
64
+ config: finalConfig,
65
+ metadata: {
66
+ truncated,
67
+ processingTime,
68
+ template,
69
+ mode: finalConfig.mode,
70
+ },
71
+ };
72
+ }
73
+ /**
74
+ * Format context for prompt integration
75
+ */
76
+ static formatContextForPrompt(context, config) {
77
+ switch (config.mode) {
78
+ case "prompt_prefix":
79
+ return this.formatAsPrefix(context);
80
+ case "prompt_suffix":
81
+ return this.formatAsSuffix(context);
82
+ case "system_prompt":
83
+ return this.formatForSystemPrompt(context);
84
+ case "structured_prompt":
85
+ return this.formatStructured(context);
86
+ case "metadata_only":
87
+ case "none":
88
+ default:
89
+ return "";
90
+ }
91
+ }
92
+ /**
93
+ * Format context as prompt prefix
94
+ */
95
+ static formatAsPrefix(context) {
96
+ const parts = [];
97
+ if (context.userId) {
98
+ parts.push(`User: ${context.userId}`);
99
+ }
100
+ if (context.userRole) {
101
+ parts.push(`Role: ${context.userRole}`);
102
+ }
103
+ if (context.sessionId) {
104
+ parts.push(`Session: ${context.sessionId}`);
105
+ }
106
+ if (parts.length === 0) {
107
+ return "";
108
+ }
109
+ return `Context: ${parts.join(", ")}\n\n`;
110
+ }
111
+ /**
112
+ * Format context as prompt suffix
113
+ */
114
+ static formatAsSuffix(context) {
115
+ const relevantKeys = Object.keys(context).filter((key) => !["userId", "sessionId", "requestId"].includes(key));
116
+ if (relevantKeys.length === 0) {
117
+ return "";
118
+ }
119
+ const contextData = relevantKeys.reduce((acc, key) => {
120
+ acc[key] = context[key];
121
+ return acc;
122
+ }, {});
123
+ return `\n\nAdditional Context: ${JSON.stringify(contextData, null, 2)}`;
124
+ }
125
+ /**
126
+ * Format context for system prompt
127
+ */
128
+ static formatForSystemPrompt(context) {
129
+ const parts = [];
130
+ if (context.userRole) {
131
+ parts.push(`You are assisting a user with the role: ${context.userRole}`);
132
+ }
133
+ if (context.organizationId) {
134
+ parts.push(`Organization context: ${context.organizationId}`);
135
+ }
136
+ if (context.userPreferences) {
137
+ parts.push(`User preferences: ${JSON.stringify(context.userPreferences)}`);
138
+ }
139
+ return parts.join(". ");
140
+ }
141
+ /**
142
+ * Format context in structured format
143
+ */
144
+ static formatStructured(context) {
145
+ return `[CONTEXT]\n${JSON.stringify(context, null, 2)}\n[/CONTEXT]\n\n`;
146
+ }
147
+ /**
148
+ * Extract analytics data from context
149
+ */
150
+ static extractAnalyticsContext(context) {
151
+ return {
152
+ hasUserId: !!context.userId,
153
+ hasSessionId: !!context.sessionId,
154
+ hasUserRole: !!context.userRole,
155
+ hasOrgContext: !!context.organizationId,
156
+ contextKeys: Object.keys(context),
157
+ contextSize: JSON.stringify(context).length,
158
+ };
159
+ }
160
+ /**
161
+ * Extract evaluation context
162
+ */
163
+ static extractEvaluationContext(context) {
164
+ return {
165
+ userRole: context.userRole || "unknown",
166
+ applicationContext: context.applicationContext?.name || "unknown",
167
+ organizationContext: context.organizationId || "unknown",
168
+ hasPreferences: !!context.userPreferences,
169
+ };
170
+ }
171
+ }
172
+ /**
173
+ * Type guard to check if value is valid context
174
+ */
175
+ export function isValidContext(value) {
176
+ return ContextFactory.validateContext(value) !== null;
177
+ }
@@ -9,4 +9,7 @@ export * from "./cli.js";
9
9
  export type { Unknown, UnknownRecord, UnknownArray, JsonValue, JsonObject, JsonArray, ErrorInfo, Result, FunctionParameters, } from "./common.js";
10
10
  export type { ToolArgs, ToolContext, ToolResult, ToolDefinition, SimpleTool, AvailableTool, ToolExecution, } from "./tools.js";
11
11
  export type { AISDKModel, ProviderError, TokenUsage, AnalyticsData, EvaluationData, ProviderConfig, } from "./providers.js";
12
- export type { BaseCommandArgs, GenerateCommandArgs, CommandResult, GenerateResult, StreamChunk, } from "./cli.js";
12
+ export type { BaseCommandArgs, GenerateCommandArgs, MCPCommandArgs, ModelsCommandArgs, CommandResult, GenerateResult, StreamChunk, } from "./cli.js";
13
+ export type { MCPTransportType, MCPServerStatus, MCPDiscoveredServer, MCPConnectedServer, MCPServerConfig, MCPToolInfo, MCPServerMetadata, MCPToolMetadata, MCPServerRegistryEntry, } from "./mcpTypes.js";
14
+ export type { ModelCapability, ModelUseCase, ModelFilter, ModelResolutionContext, ModelStats, ModelPricing, } from "./providers.js";
15
+ export type { ToolCallResults, ToolCalls, StreamAnalyticsData, } from "./streamTypes.js";
@@ -2,6 +2,7 @@
2
2
  * MCP Types for In-Memory Server Support
3
3
  * Enables Lighthouse and other integrations to register tools directly
4
4
  */
5
+ import type { JsonValue, JsonObject } from "./common.js";
5
6
  /**
6
7
  * In-memory MCP server configuration
7
8
  */
@@ -88,6 +89,121 @@ export interface InMemoryToolResult {
88
89
  [key: string]: unknown;
89
90
  };
90
91
  }
92
+ /**
93
+ * MCP Transport Types - Maximally Reusable
94
+ */
95
+ export type MCPTransportType = "stdio" | "websocket" | "tcp" | "unix";
96
+ /**
97
+ * MCP Server Status for CLI Operations - High Reusability
98
+ */
99
+ export interface MCPServerStatus {
100
+ /** Whether MCP is initialized */
101
+ mcpInitialized: boolean;
102
+ /** Total number of servers */
103
+ totalServers: number;
104
+ /** Number of available servers */
105
+ availableServers: number;
106
+ /** Number of auto-discovered servers */
107
+ autoDiscoveredCount: number;
108
+ /** Total number of tools */
109
+ totalTools: number;
110
+ /** Number of custom tools */
111
+ customToolsCount: number;
112
+ /** Number of in-memory servers */
113
+ inMemoryServersCount: number;
114
+ /** Error message if any */
115
+ error?: string;
116
+ /** Auto-discovered servers from various sources */
117
+ autoDiscoveredServers?: MCPDiscoveredServer[];
118
+ /** Currently connected servers */
119
+ connectedServers: MCPConnectedServer[];
120
+ /** Available tools across all servers */
121
+ availableTools: MCPToolInfo[];
122
+ /** Server registry entries */
123
+ serverRegistry?: Record<string, MCPServerConfig>;
124
+ }
125
+ /**
126
+ * Auto-discovered MCP Server - High Reusability
127
+ */
128
+ export interface MCPDiscoveredServer {
129
+ name: string;
130
+ status: "connected" | "disconnected" | "error" | "pending" | "failed";
131
+ source: string;
132
+ transport: MCPTransportType;
133
+ description?: string;
134
+ url?: string;
135
+ args?: string[];
136
+ env?: Record<string, string>;
137
+ metadata?: MCPServerMetadata;
138
+ }
139
+ /**
140
+ * Connected MCP Server - High Reusability
141
+ */
142
+ export interface MCPConnectedServer {
143
+ name: string;
144
+ transport: MCPTransportType;
145
+ connected: boolean;
146
+ description?: string;
147
+ tools: MCPToolInfo[];
148
+ lastSeen?: Date;
149
+ connectionTime?: Date;
150
+ metadata?: MCPServerMetadata;
151
+ }
152
+ /**
153
+ * MCP Server Configuration - Maximally Reusable
154
+ */
155
+ export interface MCPServerConfig {
156
+ name: string;
157
+ transport: MCPTransportType;
158
+ description?: string;
159
+ command?: string;
160
+ args?: string[];
161
+ env?: Record<string, string>;
162
+ url?: string;
163
+ timeout?: number;
164
+ retries?: number;
165
+ metadata?: MCPServerMetadata;
166
+ }
167
+ /**
168
+ * MCP Tool Information - High Reusability
169
+ */
170
+ export interface MCPToolInfo {
171
+ name: string;
172
+ description: string;
173
+ serverId: string;
174
+ isExternal: boolean;
175
+ isImplemented?: boolean;
176
+ inputSchema?: JsonObject;
177
+ outputSchema?: JsonObject;
178
+ metadata?: MCPToolMetadata;
179
+ }
180
+ /**
181
+ * MCP Server Metadata - Extensible
182
+ */
183
+ export type MCPServerMetadata = {
184
+ [key: string]: JsonValue;
185
+ } & {
186
+ provider?: string;
187
+ version?: string;
188
+ author?: string;
189
+ category?: string;
190
+ tags?: string[];
191
+ };
192
+ /**
193
+ * MCP Tool Metadata - Extensible
194
+ */
195
+ export type MCPToolMetadata = {
196
+ [key: string]: JsonValue;
197
+ } & {
198
+ category?: string;
199
+ tags?: string[];
200
+ complexity?: "simple" | "medium" | "complex";
201
+ executionTime?: number;
202
+ };
203
+ /**
204
+ * MCP Server Registry Entry - For Object.entries() usage
205
+ */
206
+ export type MCPServerRegistryEntry = [string, MCPServerConfig];
91
207
  /**
92
208
  * Unified MCP Registry interface
93
209
  */
@@ -99,16 +215,11 @@ export interface UnifiedMCPRegistry {
99
215
  /**
100
216
  * Get all available tools
101
217
  */
102
- getAllTools(): Promise<Array<{
103
- name: string;
104
- serverId: string;
105
- description: string;
106
- isExternal: boolean;
107
- }>>;
218
+ getAllTools(): Promise<MCPToolInfo[]>;
108
219
  /**
109
220
  * Execute a tool
110
221
  */
111
- executeTool(toolName: string, params: unknown, context: unknown): Promise<unknown>;
222
+ executeTool(toolName: string, params: JsonObject, context: JsonObject): Promise<InMemoryToolResult>;
112
223
  /**
113
224
  * Check if connected to a server
114
225
  */
@@ -42,6 +42,87 @@ export interface AnalyticsData {
42
42
  context?: JsonValue;
43
43
  [key: string]: JsonValue | undefined;
44
44
  }
45
+ /**
46
+ * Model Capabilities - Maximally Reusable
47
+ */
48
+ export type ModelCapability = "text" | "vision" | "function-calling" | "embedding" | "audio" | "video" | "code" | "reasoning" | "multimodal";
49
+ /**
50
+ * Model Use Cases - High Reusability
51
+ */
52
+ export type ModelUseCase = "chat" | "completion" | "analysis" | "coding" | "creative" | "reasoning" | "translation" | "summarization" | "classification";
53
+ /**
54
+ * Model Filter Configuration - High Reusability
55
+ */
56
+ export interface ModelFilter {
57
+ provider?: string;
58
+ capability?: ModelCapability;
59
+ useCase?: ModelUseCase;
60
+ requireVision?: boolean;
61
+ requireFunctionCalling?: boolean;
62
+ maxTokens?: number;
63
+ costLimit?: number;
64
+ }
65
+ /**
66
+ * Model Resolution Context - High Reusability
67
+ */
68
+ export interface ModelResolutionContext {
69
+ requireCapabilities?: ModelCapability[];
70
+ preferredProviders?: string[];
71
+ useCase?: ModelUseCase;
72
+ budgetConstraints?: {
73
+ maxCostPerRequest?: number;
74
+ maxTokens?: number;
75
+ };
76
+ performance?: {
77
+ maxLatency?: number;
78
+ minQuality?: number;
79
+ };
80
+ }
81
+ /**
82
+ * Model Statistics Object - High Reusability
83
+ */
84
+ export interface ModelStats {
85
+ name: string;
86
+ provider: string;
87
+ capabilities: ModelCapability[];
88
+ useCases: ModelUseCase[];
89
+ performance: {
90
+ avgLatency?: number;
91
+ avgTokensPerSecond?: number;
92
+ reliability?: number;
93
+ };
94
+ pricing?: ModelPricing;
95
+ metadata: {
96
+ [key: string]: JsonValue;
97
+ } & {
98
+ version?: string;
99
+ lastUpdated?: Date;
100
+ };
101
+ }
102
+ /**
103
+ * Model Pricing Information - High Reusability
104
+ */
105
+ export interface ModelPricing {
106
+ inputTokens?: {
107
+ price: number;
108
+ currency: string;
109
+ per: number;
110
+ };
111
+ outputTokens?: {
112
+ price: number;
113
+ currency: string;
114
+ per: number;
115
+ };
116
+ requestPrice?: {
117
+ price: number;
118
+ currency: string;
119
+ };
120
+ tier?: "free" | "basic" | "premium" | "enterprise";
121
+ average?: number;
122
+ min?: number;
123
+ max?: number;
124
+ free?: boolean;
125
+ }
45
126
  /**
46
127
  * Evaluation data structure
47
128
  */
@@ -1,25 +1,62 @@
1
1
  import type { ZodType, ZodTypeDef } from "zod";
2
2
  import type { Tool, Schema } from "ai";
3
3
  import type { AIProviderName, AnalyticsData, EvaluationData } from "../core/types.js";
4
- import type { UnknownRecord, Unknown } from "./common.js";
4
+ import type { UnknownRecord, JsonValue } from "./common.js";
5
5
  /**
6
- * Interface for tool execution calls
6
+ * Interface for tool execution calls (AI SDK compatible)
7
7
  */
8
8
  export interface ToolCall {
9
+ type?: "tool-call";
10
+ toolCallId?: string;
9
11
  toolName: string;
10
- parameters: UnknownRecord;
12
+ parameters?: UnknownRecord;
13
+ args?: UnknownRecord;
11
14
  id?: string;
12
15
  }
13
16
  /**
14
- * Interface for tool execution results
17
+ * Interface for tool execution results - Enhanced for type safety
15
18
  */
16
19
  export interface ToolResult {
17
20
  toolName: string;
18
21
  status: "success" | "failure";
19
- output?: Unknown;
22
+ output?: JsonValue;
20
23
  error?: string;
21
24
  id?: string;
22
25
  executionTime?: number;
26
+ metadata?: {
27
+ [key: string]: JsonValue;
28
+ } & {
29
+ serverId?: string;
30
+ toolCategory?: string;
31
+ isExternal?: boolean;
32
+ };
33
+ }
34
+ /**
35
+ * Tool Call Results Array - High Reusability
36
+ */
37
+ export type ToolCallResults = Array<ToolResult>;
38
+ /**
39
+ * Tool Calls Array - High Reusability
40
+ */
41
+ export type ToolCalls = Array<ToolCall>;
42
+ /**
43
+ * Stream Analytics Data - Enhanced for performance tracking
44
+ */
45
+ export interface StreamAnalyticsData {
46
+ /** Tool execution results with timing */
47
+ toolResults?: Promise<ToolCallResults>;
48
+ /** Tool calls made during stream */
49
+ toolCalls?: Promise<ToolCalls>;
50
+ /** Stream performance metrics */
51
+ performance?: {
52
+ startTime: number;
53
+ endTime?: number;
54
+ chunkCount: number;
55
+ avgChunkSize: number;
56
+ totalBytes: number;
57
+ };
58
+ /** Provider analytics */
59
+ providerAnalytics?: AnalyticsData;
23
60
  }
24
61
  /**
25
62
  * Stream function options interface - Primary method for streaming content
@@ -83,8 +120,8 @@ export interface StreamResult {
83
120
  responseTime?: number;
84
121
  fallback?: boolean;
85
122
  };
86
- analytics?: AnalyticsData;
87
- evaluation?: EvaluationData;
123
+ analytics?: AnalyticsData | Promise<AnalyticsData>;
124
+ evaluation?: EvaluationData | Promise<EvaluationData>;
88
125
  }
89
126
  /**
90
127
  * Enhanced provider interface with stream method
@@ -136,6 +136,15 @@ export interface ToolCall {
136
136
  parameters: ToolArgs;
137
137
  id?: string;
138
138
  }
139
+ /**
140
+ * AI SDK Tool Call format (from Vercel AI SDK)
141
+ */
142
+ export interface AiSdkToolCall {
143
+ type: "tool-call";
144
+ toolCallId: string;
145
+ toolName: string;
146
+ args: ToolArgs;
147
+ }
139
148
  /**
140
149
  * Tool call result (for AI SDK integration)
141
150
  */
@@ -2,6 +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
6
  /**
6
7
  * Base configuration interface for all AI providers
7
8
  * Uses Parameter Object Pattern for flexible, extensible configuration
@@ -14,7 +15,8 @@ export interface UniversalProviderOptions {
14
15
  systemPrompt?: string;
15
16
  enableAnalytics?: boolean;
16
17
  enableEvaluation?: boolean;
17
- context?: Record<string, unknown>;
18
+ context?: BaseContext;
19
+ contextConfig?: Partial<ContextConfig>;
18
20
  metadata?: Record<string, unknown>;
19
21
  extensionOptions?: Record<string, unknown>;
20
22
  }
@@ -2,6 +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
6
  /**
6
7
  * Parameter normalization utilities
7
8
  * Converts between different parameter formats for backward compatibility
@@ -45,8 +46,9 @@ export class ParameterNormalizer {
45
46
  return {
46
47
  ...defaults,
47
48
  ...options,
48
- // Merge nested objects
49
+ // Merge nested objects (type-safe context merging)
49
50
  context: { ...defaults.context, ...options.context },
51
+ contextConfig: { ...defaults.contextConfig, ...options.contextConfig },
50
52
  metadata: { ...defaults.metadata, ...options.metadata },
51
53
  };
52
54
  }
@@ -47,6 +47,12 @@ declare class NeuroLinkLogger {
47
47
  * @param args - The arguments to log. These are passed directly to `console.log`.
48
48
  */
49
49
  always(...args: unknown[]): void;
50
+ /**
51
+ * Displays tabular data unconditionally using `console.table`.
52
+ *
53
+ * @param data - The data to display in table format
54
+ */
55
+ table(data: unknown): void;
50
56
  }
51
57
  export declare const logger: {
52
58
  debug: (...args: unknown[]) => void;
@@ -54,6 +60,7 @@ export declare const logger: {
54
60
  warn: (...args: unknown[]) => void;
55
61
  error: (...args: unknown[]) => void;
56
62
  always: (...args: unknown[]) => void;
63
+ table: (data: unknown) => void;
57
64
  setLogLevel: (level: LogLevel) => void;
58
65
  getLogs: (level?: LogLevel) => LogEntry[];
59
66
  clearLogs: () => void;