@juspay/neurolink 7.0.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.
- package/CHANGELOG.md +15 -4
- package/README.md +16 -11
- package/dist/cli/commands/config.d.ts +2 -2
- package/dist/cli/commands/config.js +22 -21
- package/dist/cli/commands/mcp.d.ts +79 -0
- package/dist/cli/commands/mcp.js +916 -0
- package/dist/cli/commands/models.d.ts +63 -0
- package/dist/cli/commands/models.js +653 -0
- package/dist/cli/commands/ollama.js +56 -55
- package/dist/cli/factories/commandFactory.d.ts +67 -2
- package/dist/cli/factories/commandFactory.js +840 -92
- package/dist/cli/index.d.ts +6 -0
- package/dist/cli/index.js +42 -999
- package/dist/cli/utils/completeSetup.js +9 -8
- package/dist/cli/utils/envManager.js +7 -6
- package/dist/cli/utils/interactiveSetup.js +20 -19
- package/dist/core/analytics.js +25 -38
- package/dist/core/baseProvider.d.ts +8 -0
- package/dist/core/baseProvider.js +177 -68
- package/dist/core/constants.d.ts +11 -0
- package/dist/core/constants.js +17 -0
- package/dist/core/evaluation.js +25 -14
- package/dist/core/factory.js +21 -18
- package/dist/core/streamAnalytics.d.ts +65 -0
- package/dist/core/streamAnalytics.js +125 -0
- package/dist/factories/providerRegistry.js +3 -1
- package/dist/lib/core/analytics.js +25 -38
- package/dist/lib/core/baseProvider.d.ts +8 -0
- package/dist/lib/core/baseProvider.js +177 -68
- package/dist/lib/core/constants.d.ts +11 -0
- package/dist/lib/core/constants.js +17 -0
- package/dist/lib/core/evaluation.js +25 -14
- package/dist/lib/core/factory.js +22 -18
- package/dist/lib/core/streamAnalytics.d.ts +65 -0
- package/dist/lib/core/streamAnalytics.js +125 -0
- package/dist/lib/factories/providerRegistry.js +3 -1
- package/dist/lib/mcp/toolRegistry.d.ts +5 -0
- package/dist/lib/mcp/toolRegistry.js +60 -0
- package/dist/lib/models/modelRegistry.d.ts +132 -0
- package/dist/lib/models/modelRegistry.js +483 -0
- package/dist/lib/models/modelResolver.d.ts +115 -0
- package/dist/lib/models/modelResolver.js +467 -0
- package/dist/lib/neurolink.d.ts +4 -1
- package/dist/lib/neurolink.js +108 -69
- package/dist/lib/providers/anthropic.js +3 -0
- package/dist/lib/providers/googleAiStudio.js +13 -0
- package/dist/lib/providers/huggingFace.js +15 -3
- package/dist/lib/providers/mistral.js +19 -7
- package/dist/lib/providers/ollama.js +31 -7
- package/dist/lib/providers/openAI.js +12 -0
- package/dist/lib/sdk/toolRegistration.js +17 -0
- package/dist/lib/types/cli.d.ts +56 -1
- package/dist/lib/types/contextTypes.d.ts +110 -0
- package/dist/lib/types/contextTypes.js +176 -0
- package/dist/lib/types/index.d.ts +4 -1
- package/dist/lib/types/mcpTypes.d.ts +118 -7
- package/dist/lib/types/providers.d.ts +81 -0
- package/dist/lib/types/streamTypes.d.ts +44 -7
- package/dist/lib/types/tools.d.ts +9 -0
- package/dist/lib/types/universalProviderOptions.d.ts +3 -1
- package/dist/lib/types/universalProviderOptions.js +2 -1
- package/dist/lib/utils/logger.d.ts +7 -0
- package/dist/lib/utils/logger.js +16 -6
- package/dist/lib/utils/performance.d.ts +105 -0
- package/dist/lib/utils/performance.js +210 -0
- package/dist/lib/utils/providerUtils.js +9 -2
- package/dist/lib/utils/retryHandler.d.ts +89 -0
- package/dist/lib/utils/retryHandler.js +269 -0
- package/dist/mcp/toolRegistry.d.ts +5 -0
- package/dist/mcp/toolRegistry.js +60 -0
- package/dist/models/modelRegistry.d.ts +132 -0
- package/dist/models/modelRegistry.js +483 -0
- package/dist/models/modelResolver.d.ts +115 -0
- package/dist/models/modelResolver.js +468 -0
- package/dist/neurolink.d.ts +4 -1
- package/dist/neurolink.js +108 -69
- package/dist/providers/anthropic.js +3 -0
- package/dist/providers/googleAiStudio.js +13 -0
- package/dist/providers/huggingFace.js +15 -3
- package/dist/providers/mistral.js +19 -7
- package/dist/providers/ollama.js +31 -7
- package/dist/providers/openAI.js +12 -0
- package/dist/sdk/toolRegistration.js +17 -0
- package/dist/types/cli.d.ts +56 -1
- package/dist/types/contextTypes.d.ts +110 -0
- package/dist/types/contextTypes.js +177 -0
- package/dist/types/index.d.ts +4 -1
- package/dist/types/mcpTypes.d.ts +118 -7
- package/dist/types/providers.d.ts +81 -0
- package/dist/types/streamTypes.d.ts +44 -7
- package/dist/types/tools.d.ts +9 -0
- package/dist/types/universalProviderOptions.d.ts +3 -1
- package/dist/types/universalProviderOptions.js +3 -1
- package/dist/utils/logger.d.ts +7 -0
- package/dist/utils/logger.js +16 -6
- package/dist/utils/performance.d.ts +105 -0
- package/dist/utils/performance.js +210 -0
- package/dist/utils/providerUtils.js +9 -2
- package/dist/utils/retryHandler.d.ts +89 -0
- package/dist/utils/retryHandler.js +269 -0
- 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,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context Types for NeuroLink - Factory Pattern Implementation
|
|
3
|
+
* Provides type-safe context integration for AI generation
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Factory for context processing
|
|
7
|
+
*/
|
|
8
|
+
export class ContextFactory {
|
|
9
|
+
/**
|
|
10
|
+
* Default context configuration
|
|
11
|
+
*/
|
|
12
|
+
static DEFAULT_CONFIG = {
|
|
13
|
+
mode: "metadata_only",
|
|
14
|
+
includeInPrompt: false,
|
|
15
|
+
includeInAnalytics: true,
|
|
16
|
+
includeInEvaluation: true,
|
|
17
|
+
maxLength: 1000,
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Validate and normalize context data
|
|
21
|
+
*/
|
|
22
|
+
static validateContext(context) {
|
|
23
|
+
if (!context || typeof context !== "object") {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
// Ensure it's JSON serializable
|
|
28
|
+
const serialized = JSON.stringify(context);
|
|
29
|
+
const parsed = JSON.parse(serialized);
|
|
30
|
+
// Basic validation
|
|
31
|
+
if (typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
return parsed;
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Process context for AI generation based on configuration
|
|
42
|
+
*/
|
|
43
|
+
static processContext(context, config = {}) {
|
|
44
|
+
const startTime = Date.now();
|
|
45
|
+
const finalConfig = { ...this.DEFAULT_CONFIG, ...config };
|
|
46
|
+
let processedContext = null;
|
|
47
|
+
const template = "default";
|
|
48
|
+
let truncated = false;
|
|
49
|
+
if (finalConfig.includeInPrompt && finalConfig.mode !== "metadata_only") {
|
|
50
|
+
processedContext = this.formatContextForPrompt(context, finalConfig);
|
|
51
|
+
// Truncate if necessary
|
|
52
|
+
if (finalConfig.maxLength &&
|
|
53
|
+
processedContext.length > finalConfig.maxLength) {
|
|
54
|
+
processedContext =
|
|
55
|
+
processedContext.substring(0, finalConfig.maxLength) + "...";
|
|
56
|
+
truncated = true;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const processingTime = Date.now() - startTime;
|
|
60
|
+
return {
|
|
61
|
+
originalContext: context,
|
|
62
|
+
processedContext,
|
|
63
|
+
config: finalConfig,
|
|
64
|
+
metadata: {
|
|
65
|
+
truncated,
|
|
66
|
+
processingTime,
|
|
67
|
+
template,
|
|
68
|
+
mode: finalConfig.mode,
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Format context for prompt integration
|
|
74
|
+
*/
|
|
75
|
+
static formatContextForPrompt(context, config) {
|
|
76
|
+
switch (config.mode) {
|
|
77
|
+
case "prompt_prefix":
|
|
78
|
+
return this.formatAsPrefix(context);
|
|
79
|
+
case "prompt_suffix":
|
|
80
|
+
return this.formatAsSuffix(context);
|
|
81
|
+
case "system_prompt":
|
|
82
|
+
return this.formatForSystemPrompt(context);
|
|
83
|
+
case "structured_prompt":
|
|
84
|
+
return this.formatStructured(context);
|
|
85
|
+
case "metadata_only":
|
|
86
|
+
case "none":
|
|
87
|
+
default:
|
|
88
|
+
return "";
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Format context as prompt prefix
|
|
93
|
+
*/
|
|
94
|
+
static formatAsPrefix(context) {
|
|
95
|
+
const parts = [];
|
|
96
|
+
if (context.userId) {
|
|
97
|
+
parts.push(`User: ${context.userId}`);
|
|
98
|
+
}
|
|
99
|
+
if (context.userRole) {
|
|
100
|
+
parts.push(`Role: ${context.userRole}`);
|
|
101
|
+
}
|
|
102
|
+
if (context.sessionId) {
|
|
103
|
+
parts.push(`Session: ${context.sessionId}`);
|
|
104
|
+
}
|
|
105
|
+
if (parts.length === 0) {
|
|
106
|
+
return "";
|
|
107
|
+
}
|
|
108
|
+
return `Context: ${parts.join(", ")}\n\n`;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Format context as prompt suffix
|
|
112
|
+
*/
|
|
113
|
+
static formatAsSuffix(context) {
|
|
114
|
+
const relevantKeys = Object.keys(context).filter((key) => !["userId", "sessionId", "requestId"].includes(key));
|
|
115
|
+
if (relevantKeys.length === 0) {
|
|
116
|
+
return "";
|
|
117
|
+
}
|
|
118
|
+
const contextData = relevantKeys.reduce((acc, key) => {
|
|
119
|
+
acc[key] = context[key];
|
|
120
|
+
return acc;
|
|
121
|
+
}, {});
|
|
122
|
+
return `\n\nAdditional Context: ${JSON.stringify(contextData, null, 2)}`;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Format context for system prompt
|
|
126
|
+
*/
|
|
127
|
+
static formatForSystemPrompt(context) {
|
|
128
|
+
const parts = [];
|
|
129
|
+
if (context.userRole) {
|
|
130
|
+
parts.push(`You are assisting a user with the role: ${context.userRole}`);
|
|
131
|
+
}
|
|
132
|
+
if (context.organizationId) {
|
|
133
|
+
parts.push(`Organization context: ${context.organizationId}`);
|
|
134
|
+
}
|
|
135
|
+
if (context.userPreferences) {
|
|
136
|
+
parts.push(`User preferences: ${JSON.stringify(context.userPreferences)}`);
|
|
137
|
+
}
|
|
138
|
+
return parts.join(". ");
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Format context in structured format
|
|
142
|
+
*/
|
|
143
|
+
static formatStructured(context) {
|
|
144
|
+
return `[CONTEXT]\n${JSON.stringify(context, null, 2)}\n[/CONTEXT]\n\n`;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Extract analytics data from context
|
|
148
|
+
*/
|
|
149
|
+
static extractAnalyticsContext(context) {
|
|
150
|
+
return {
|
|
151
|
+
hasUserId: !!context.userId,
|
|
152
|
+
hasSessionId: !!context.sessionId,
|
|
153
|
+
hasUserRole: !!context.userRole,
|
|
154
|
+
hasOrgContext: !!context.organizationId,
|
|
155
|
+
contextKeys: Object.keys(context),
|
|
156
|
+
contextSize: JSON.stringify(context).length,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Extract evaluation context
|
|
161
|
+
*/
|
|
162
|
+
static extractEvaluationContext(context) {
|
|
163
|
+
return {
|
|
164
|
+
userRole: context.userRole || "unknown",
|
|
165
|
+
applicationContext: context.applicationContext?.name || "unknown",
|
|
166
|
+
organizationContext: context.organizationId || "unknown",
|
|
167
|
+
hasPreferences: !!context.userPreferences,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Type guard to check if value is valid context
|
|
173
|
+
*/
|
|
174
|
+
export function isValidContext(value) {
|
|
175
|
+
return ContextFactory.validateContext(value) !== null;
|
|
176
|
+
}
|
|
@@ -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<
|
|
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:
|
|
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,
|
|
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
|
|
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?:
|
|
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?:
|
|
18
|
+
context?: BaseContext;
|
|
19
|
+
contextConfig?: Partial<ContextConfig>;
|
|
18
20
|
metadata?: Record<string, unknown>;
|
|
19
21
|
extensionOptions?: Record<string, unknown>;
|
|
20
22
|
}
|
|
@@ -45,8 +45,9 @@ export class ParameterNormalizer {
|
|
|
45
45
|
return {
|
|
46
46
|
...defaults,
|
|
47
47
|
...options,
|
|
48
|
-
// Merge nested objects
|
|
48
|
+
// Merge nested objects (type-safe context merging)
|
|
49
49
|
context: { ...defaults.context, ...options.context },
|
|
50
|
+
contextConfig: { ...defaults.contextConfig, ...options.contextConfig },
|
|
50
51
|
metadata: { ...defaults.metadata, ...options.metadata },
|
|
51
52
|
};
|
|
52
53
|
}
|
|
@@ -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;
|