@juspay/neurolink 5.3.0 → 6.0.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 +76 -2
- package/dist/chat/client-utils.d.ts +3 -0
- package/dist/chat/client-utils.js +22 -5
- package/dist/chat/index.d.ts +4 -7
- package/dist/chat/index.js +0 -8
- package/dist/chat/session-storage.d.ts +2 -2
- package/dist/chat/session.d.ts +4 -3
- package/dist/chat/session.js +1 -1
- package/dist/chat/sse-handler.js +13 -21
- package/dist/chat/types.d.ts +3 -2
- package/dist/chat/websocket-chat-handler.d.ts +4 -3
- package/dist/chat/websocket-chat-handler.js +12 -12
- package/dist/cli/commands/config.d.ts +2 -2
- package/dist/cli/commands/mcp.d.ts +3 -2
- package/dist/cli/commands/mcp.js +39 -29
- package/dist/cli/commands/ollama.js +8 -4
- package/dist/cli/factories/command-factory.d.ts +2 -1
- package/dist/cli/index.js +22 -19
- package/dist/core/analytics.d.ts +3 -2
- package/dist/core/analytics.js +16 -7
- package/dist/core/base-provider.d.ts +35 -7
- package/dist/core/base-provider.js +36 -13
- package/dist/core/defaults.d.ts +2 -1
- package/dist/core/evaluation.d.ts +4 -4
- package/dist/core/evaluation.js +17 -7
- package/dist/core/factory.d.ts +3 -2
- package/dist/core/service-registry.d.ts +4 -4
- package/dist/core/types.d.ts +11 -4
- package/dist/factories/compatibility-factory.d.ts +16 -1
- package/dist/factories/compatibility-factory.js +3 -1
- package/dist/factories/provider-factory.d.ts +5 -4
- package/dist/factories/provider-factory.js +15 -24
- package/dist/factories/provider-generate-factory.js +26 -20
- package/dist/lib/chat/client-utils.d.ts +3 -0
- package/dist/lib/chat/client-utils.js +22 -5
- package/dist/lib/chat/index.d.ts +4 -7
- package/dist/lib/chat/index.js +0 -8
- package/dist/lib/chat/session-storage.d.ts +2 -2
- package/dist/lib/chat/session.d.ts +4 -3
- package/dist/lib/chat/session.js +1 -1
- package/dist/lib/chat/sse-handler.js +13 -21
- package/dist/lib/chat/types.d.ts +3 -2
- package/dist/lib/chat/websocket-chat-handler.d.ts +4 -3
- package/dist/lib/chat/websocket-chat-handler.js +12 -12
- package/dist/lib/core/analytics.d.ts +3 -2
- package/dist/lib/core/analytics.js +16 -7
- package/dist/lib/core/base-provider.d.ts +35 -7
- package/dist/lib/core/base-provider.js +36 -13
- package/dist/lib/core/defaults.d.ts +2 -1
- package/dist/lib/core/evaluation.d.ts +4 -4
- package/dist/lib/core/evaluation.js +17 -7
- package/dist/lib/core/factory.d.ts +3 -2
- package/dist/lib/core/service-registry.d.ts +4 -4
- package/dist/lib/core/types.d.ts +11 -4
- package/dist/lib/factories/compatibility-factory.d.ts +16 -1
- package/dist/lib/factories/compatibility-factory.js +3 -1
- package/dist/lib/factories/provider-factory.d.ts +5 -4
- package/dist/lib/factories/provider-factory.js +15 -24
- package/dist/lib/factories/provider-generate-factory.js +26 -20
- package/dist/lib/mcp/adapters/plugin-bridge.d.ts +5 -4
- package/dist/lib/mcp/adapters/plugin-bridge.js +13 -6
- package/dist/lib/mcp/client.d.ts +2 -1
- package/dist/lib/mcp/client.js +12 -10
- package/dist/lib/mcp/context-manager.d.ts +1 -1
- package/dist/lib/mcp/contracts/mcp-contract.d.ts +15 -8
- package/dist/lib/mcp/core/plugin-manager.d.ts +3 -2
- package/dist/lib/mcp/core/plugin-manager.js +1 -1
- package/dist/lib/mcp/demo/plugin-demo.js +3 -1
- package/dist/lib/mcp/dynamic-chain-executor.d.ts +64 -40
- package/dist/lib/mcp/dynamic-chain-executor.js +3 -3
- package/dist/lib/mcp/dynamic-orchestrator.d.ts +14 -8
- package/dist/lib/mcp/ecosystem.d.ts +4 -4
- package/dist/lib/mcp/error-manager.d.ts +2 -2
- package/dist/lib/mcp/error-recovery.d.ts +4 -3
- package/dist/lib/mcp/external-client.d.ts +1 -1
- package/dist/lib/mcp/external-client.js +14 -10
- package/dist/lib/mcp/external-manager.d.ts +3 -3
- package/dist/lib/mcp/external-manager.js +9 -3
- package/dist/lib/mcp/factory.d.ts +7 -7
- package/dist/lib/mcp/function-calling.d.ts +3 -2
- package/dist/lib/mcp/health-monitor.d.ts +2 -1
- package/dist/lib/mcp/health-monitor.js +16 -7
- package/dist/lib/mcp/index.d.ts +5 -5
- package/dist/lib/mcp/initialize-tools.d.ts +2 -1
- package/dist/lib/mcp/initialize-tools.js +10 -2
- package/dist/lib/mcp/manager.d.ts +2 -1
- package/dist/lib/mcp/neurolink-mcp-client.js +1 -1
- package/dist/lib/mcp/orchestrator.d.ts +13 -12
- package/dist/lib/mcp/orchestrator.js +10 -8
- package/dist/lib/mcp/plugin-manager.js +4 -2
- package/dist/lib/mcp/plugins/core/filesystem-mcp.d.ts +3 -2
- package/dist/lib/mcp/plugins/core/filesystem-mcp.js +5 -2
- package/dist/lib/mcp/plugins/filesystem-mcp.d.ts +2 -1
- package/dist/lib/mcp/registry.d.ts +2 -1
- package/dist/lib/mcp/registry.js +2 -1
- package/dist/lib/mcp/security-manager.d.ts +4 -2
- package/dist/lib/mcp/servers/agent/direct-tools-server.js +18 -6
- package/dist/lib/mcp/servers/ai-providers/ai-analysis-tools.d.ts +1 -16
- package/dist/lib/mcp/servers/ai-providers/ai-analysis-tools.js +21 -17
- package/dist/lib/mcp/servers/ai-providers/ai-core-server.d.ts +2 -2
- package/dist/lib/mcp/servers/ai-providers/ai-core-server.js +15 -133
- package/dist/lib/mcp/servers/ai-providers/ai-workflow-tools.d.ts +1 -97
- package/dist/lib/mcp/servers/ai-providers/ai-workflow-tools.js +18 -18
- package/dist/lib/mcp/session-manager.d.ts +4 -3
- package/dist/lib/mcp/session-persistence.js +5 -2
- package/dist/lib/mcp/tool-integration.d.ts +3 -2
- package/dist/lib/mcp/tool-integration.js +3 -1
- package/dist/lib/mcp/tool-registry.d.ts +18 -1
- package/dist/lib/mcp/tool-registry.js +11 -8
- package/dist/lib/mcp/transport-manager.d.ts +2 -1
- package/dist/lib/mcp/transport-manager.js +5 -1
- package/dist/lib/mcp/unified-mcp.d.ts +5 -5
- package/dist/lib/mcp/unified-registry.d.ts +18 -2
- package/dist/lib/mcp/unified-registry.js +52 -3
- package/dist/lib/neurolink.d.ts +2 -2
- package/dist/lib/neurolink.js +40 -15
- package/dist/lib/providers/amazon-bedrock.d.ts +1 -1
- package/dist/lib/providers/amazon-bedrock.js +8 -7
- package/dist/lib/providers/analytics-helper.d.ts +8 -23
- package/dist/lib/providers/analytics-helper.js +95 -33
- package/dist/lib/providers/anthropic-baseprovider.d.ts +3 -3
- package/dist/lib/providers/anthropic-baseprovider.js +6 -5
- package/dist/lib/providers/anthropic.d.ts +2 -2
- package/dist/lib/providers/anthropic.js +11 -4
- package/dist/lib/providers/azure-openai.d.ts +5 -4
- package/dist/lib/providers/azure-openai.js +10 -4
- package/dist/lib/providers/function-calling-provider.d.ts +2 -2
- package/dist/lib/providers/function-calling-provider.js +1 -1
- package/dist/lib/providers/google-ai-studio.d.ts +2 -2
- package/dist/lib/providers/google-ai-studio.js +9 -3
- package/dist/lib/providers/google-vertex.d.ts +2 -2
- package/dist/lib/providers/google-vertex.js +18 -12
- package/dist/lib/providers/huggingFace.d.ts +1 -1
- package/dist/lib/providers/huggingFace.js +8 -4
- package/dist/lib/providers/mcp-provider.d.ts +3 -3
- package/dist/lib/providers/mistral.d.ts +34 -27
- package/dist/lib/providers/mistral.js +115 -107
- package/dist/lib/providers/ollama.d.ts +2 -1
- package/dist/lib/providers/ollama.js +43 -3
- package/dist/lib/providers/openAI.d.ts +1 -1
- package/dist/lib/providers/openAI.js +8 -4
- package/dist/lib/proxy/proxy-fetch.js +3 -2
- package/dist/lib/sdk/tool-extension.d.ts +12 -12
- package/dist/lib/sdk/tool-extension.js +2 -1
- package/dist/lib/sdk/tool-registration.d.ts +16 -12
- package/dist/lib/sdk/tool-registration.js +3 -2
- package/dist/lib/services/types.d.ts +5 -4
- package/dist/lib/services/websocket/websocket-server.d.ts +1 -1
- package/dist/lib/services/websocket/websocket-server.js +1 -1
- package/dist/lib/telemetry/telemetry-service.js +1 -1
- package/dist/lib/types/cli.d.ts +247 -0
- package/dist/lib/types/cli.js +22 -0
- package/dist/lib/types/common.d.ts +76 -0
- package/dist/lib/types/common.js +52 -0
- package/dist/lib/types/generate-types.d.ts +6 -6
- package/dist/lib/types/index.d.ts +12 -0
- package/dist/lib/types/index.js +12 -0
- package/dist/lib/types/mcp-types.d.ts +7 -7
- package/dist/lib/types/providers.d.ts +158 -0
- package/dist/lib/types/providers.js +23 -0
- package/dist/lib/types/stream-types.d.ts +4 -3
- package/dist/lib/types/tools.d.ts +154 -0
- package/dist/lib/types/tools.js +24 -0
- package/dist/lib/utils/logger.d.ts +5 -5
- package/dist/lib/utils/provider-validation.d.ts +2 -1
- package/dist/mcp/adapters/plugin-bridge.d.ts +5 -4
- package/dist/mcp/adapters/plugin-bridge.js +13 -6
- package/dist/mcp/client.d.ts +2 -1
- package/dist/mcp/client.js +12 -10
- package/dist/mcp/context-manager.d.ts +1 -1
- package/dist/mcp/contracts/mcp-contract.d.ts +15 -8
- package/dist/mcp/core/plugin-manager.d.ts +3 -2
- package/dist/mcp/core/plugin-manager.js +1 -1
- package/dist/mcp/demo/plugin-demo.js +3 -1
- package/dist/mcp/dynamic-chain-executor.d.ts +64 -40
- package/dist/mcp/dynamic-chain-executor.js +3 -3
- package/dist/mcp/dynamic-orchestrator.d.ts +14 -8
- package/dist/mcp/dynamic-orchestrator.js +1 -1
- package/dist/mcp/ecosystem.d.ts +4 -4
- package/dist/mcp/error-manager.d.ts +2 -2
- package/dist/mcp/error-recovery.d.ts +4 -3
- package/dist/mcp/external-client.d.ts +1 -1
- package/dist/mcp/external-client.js +14 -10
- package/dist/mcp/external-manager.d.ts +3 -3
- package/dist/mcp/external-manager.js +9 -3
- package/dist/mcp/factory.d.ts +7 -7
- package/dist/mcp/function-calling.d.ts +3 -2
- package/dist/mcp/health-monitor.d.ts +2 -1
- package/dist/mcp/health-monitor.js +16 -7
- package/dist/mcp/index.d.ts +5 -5
- package/dist/mcp/initialize-tools.d.ts +2 -1
- package/dist/mcp/initialize-tools.js +10 -2
- package/dist/mcp/manager.d.ts +2 -1
- package/dist/mcp/neurolink-mcp-client.js +1 -1
- package/dist/mcp/orchestrator.d.ts +13 -12
- package/dist/mcp/orchestrator.js +10 -8
- package/dist/mcp/plugin-manager.js +4 -2
- package/dist/mcp/plugins/core/filesystem-mcp.d.ts +3 -2
- package/dist/mcp/plugins/core/filesystem-mcp.js +5 -2
- package/dist/mcp/plugins/filesystem-mcp.d.ts +2 -1
- package/dist/mcp/registry.d.ts +2 -1
- package/dist/mcp/registry.js +2 -1
- package/dist/mcp/security-manager.d.ts +4 -2
- package/dist/mcp/servers/agent/direct-tools-server.js +19 -6
- package/dist/mcp/servers/ai-providers/ai-analysis-tools.d.ts +1 -16
- package/dist/mcp/servers/ai-providers/ai-analysis-tools.js +21 -17
- package/dist/mcp/servers/ai-providers/ai-core-server.d.ts +2 -2
- package/dist/mcp/servers/ai-providers/ai-core-server.js +15 -132
- package/dist/mcp/servers/ai-providers/ai-workflow-tools.d.ts +1 -97
- package/dist/mcp/servers/ai-providers/ai-workflow-tools.js +18 -18
- package/dist/mcp/session-manager.d.ts +4 -3
- package/dist/mcp/session-persistence.js +5 -2
- package/dist/mcp/tool-integration.d.ts +3 -2
- package/dist/mcp/tool-integration.js +3 -1
- package/dist/mcp/tool-registry.d.ts +18 -1
- package/dist/mcp/tool-registry.js +11 -8
- package/dist/mcp/transport-manager.d.ts +2 -1
- package/dist/mcp/transport-manager.js +5 -1
- package/dist/mcp/unified-mcp.d.ts +5 -5
- package/dist/mcp/unified-registry.d.ts +18 -2
- package/dist/mcp/unified-registry.js +52 -3
- package/dist/neurolink.d.ts +2 -2
- package/dist/neurolink.js +40 -15
- package/dist/providers/amazon-bedrock.d.ts +1 -1
- package/dist/providers/amazon-bedrock.js +8 -7
- package/dist/providers/analytics-helper.d.ts +8 -23
- package/dist/providers/analytics-helper.js +95 -33
- package/dist/providers/anthropic-baseprovider.d.ts +3 -3
- package/dist/providers/anthropic-baseprovider.js +6 -5
- package/dist/providers/anthropic.d.ts +2 -2
- package/dist/providers/anthropic.js +11 -4
- package/dist/providers/azure-openai.d.ts +5 -4
- package/dist/providers/azure-openai.js +10 -4
- package/dist/providers/function-calling-provider.d.ts +2 -2
- package/dist/providers/function-calling-provider.js +1 -1
- package/dist/providers/google-ai-studio.d.ts +2 -2
- package/dist/providers/google-ai-studio.js +9 -3
- package/dist/providers/google-vertex.d.ts +2 -2
- package/dist/providers/google-vertex.js +18 -12
- package/dist/providers/huggingFace.d.ts +1 -1
- package/dist/providers/huggingFace.js +8 -4
- package/dist/providers/mcp-provider.d.ts +3 -3
- package/dist/providers/mistral.d.ts +34 -27
- package/dist/providers/mistral.js +116 -108
- package/dist/providers/ollama.d.ts +2 -1
- package/dist/providers/ollama.js +43 -3
- package/dist/providers/openAI.d.ts +1 -1
- package/dist/providers/openAI.js +8 -4
- package/dist/proxy/proxy-fetch.js +3 -2
- package/dist/sdk/tool-extension.d.ts +12 -12
- package/dist/sdk/tool-extension.js +2 -1
- package/dist/sdk/tool-registration.d.ts +16 -12
- package/dist/sdk/tool-registration.js +3 -2
- package/dist/services/types.d.ts +5 -4
- package/dist/services/websocket/websocket-server.d.ts +1 -1
- package/dist/services/websocket/websocket-server.js +2 -1
- package/dist/telemetry/telemetry-service.js +1 -1
- package/dist/types/cli.d.ts +247 -0
- package/dist/types/cli.js +22 -0
- package/dist/types/common.d.ts +76 -0
- package/dist/types/common.js +52 -0
- package/dist/types/generate-types.d.ts +6 -6
- package/dist/types/index.d.ts +12 -0
- package/dist/types/index.js +12 -0
- package/dist/types/mcp-types.d.ts +7 -7
- package/dist/types/providers.d.ts +158 -0
- package/dist/types/providers.js +23 -0
- package/dist/types/stream-types.d.ts +4 -3
- package/dist/types/tools.d.ts +154 -0
- package/dist/types/tools.js +25 -0
- package/dist/utils/logger.d.ts +5 -5
- package/dist/utils/provider-validation.d.ts +2 -1
- package/package.json +1 -1
|
@@ -37,32 +37,23 @@ export class ProviderFactory {
|
|
|
37
37
|
}
|
|
38
38
|
const model = modelName || registration.defaultModel;
|
|
39
39
|
try {
|
|
40
|
-
//
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
registration.constructor) {
|
|
46
|
-
// It's a class constructor
|
|
47
|
-
return new registration.constructor(model, providerName, sdk);
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
// It's a factory function - call it and await if it returns a promise
|
|
51
|
-
const result = registration.constructor(model, providerName, sdk);
|
|
52
|
-
if (result && typeof result.then === "function") {
|
|
53
|
-
// It's a Promise (async factory)
|
|
54
|
-
return await result;
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
// It's a sync result, return it
|
|
58
|
-
return result;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
40
|
+
// Try calling as factory function first, then fallback to constructor
|
|
41
|
+
let result;
|
|
42
|
+
try {
|
|
43
|
+
// Try as factory function
|
|
44
|
+
result = registration.constructor(model, providerName, sdk);
|
|
61
45
|
}
|
|
62
|
-
|
|
63
|
-
// Fallback
|
|
64
|
-
|
|
46
|
+
catch (factoryError) {
|
|
47
|
+
// Fallback to constructor
|
|
48
|
+
result = new registration.constructor(model, providerName, sdk);
|
|
65
49
|
}
|
|
50
|
+
// Only await if result is actually a Promise
|
|
51
|
+
if (result &&
|
|
52
|
+
typeof result === "object" &&
|
|
53
|
+
typeof result.then === "function") {
|
|
54
|
+
return await result;
|
|
55
|
+
}
|
|
56
|
+
return result;
|
|
66
57
|
}
|
|
67
58
|
catch (error) {
|
|
68
59
|
logger.error(`Failed to create provider ${providerName}:`, error);
|
|
@@ -37,35 +37,41 @@ export class ProviderGenerateFactory {
|
|
|
37
37
|
try {
|
|
38
38
|
// Use existing generate method for identical performance
|
|
39
39
|
const textResult = await provider.generate(textOptions);
|
|
40
|
+
if (!textResult) {
|
|
41
|
+
throw new Error("Generate method returned null result");
|
|
42
|
+
}
|
|
40
43
|
// Convert back to GenerateResult format with type safety
|
|
41
44
|
const generateResult = {
|
|
42
|
-
content: textResult
|
|
43
|
-
outputs: { text: textResult
|
|
44
|
-
provider: textResult
|
|
45
|
-
model: textResult
|
|
46
|
-
usage: textResult
|
|
45
|
+
content: textResult.content || "",
|
|
46
|
+
outputs: { text: textResult.content || "" },
|
|
47
|
+
provider: textResult.provider,
|
|
48
|
+
model: textResult.model,
|
|
49
|
+
usage: textResult.usage
|
|
47
50
|
? {
|
|
48
|
-
inputTokens: textResult.usage
|
|
49
|
-
outputTokens: textResult.usage
|
|
50
|
-
totalTokens: textResult.usage
|
|
51
|
+
inputTokens: textResult.usage.inputTokens || 0,
|
|
52
|
+
outputTokens: textResult.usage.outputTokens || 0,
|
|
53
|
+
totalTokens: textResult.usage.totalTokens || 0,
|
|
51
54
|
}
|
|
52
55
|
: undefined,
|
|
53
|
-
responseTime: textResult
|
|
54
|
-
toolsUsed: textResult
|
|
55
|
-
toolExecutions: textResult
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
56
|
+
responseTime: textResult.responseTime,
|
|
57
|
+
toolsUsed: textResult.toolsUsed,
|
|
58
|
+
toolExecutions: textResult.toolExecutions?.map((te) => {
|
|
59
|
+
const toolExecution = te;
|
|
60
|
+
return {
|
|
61
|
+
name: toolExecution.toolName || toolExecution.name || "",
|
|
62
|
+
input: toolExecution.input || {},
|
|
63
|
+
output: toolExecution.output || toolExecution.result,
|
|
64
|
+
duration: toolExecution.executionTime || toolExecution.duration || 0,
|
|
65
|
+
};
|
|
66
|
+
}),
|
|
67
|
+
enhancedWithTools: textResult.enhancedWithTools,
|
|
68
|
+
availableTools: textResult.availableTools?.map((at) => ({
|
|
63
69
|
name: at.name || "",
|
|
64
70
|
description: at.description || "",
|
|
65
71
|
parameters: at.parameters || {},
|
|
66
72
|
})),
|
|
67
|
-
analytics: textResult
|
|
68
|
-
evaluation: textResult
|
|
73
|
+
analytics: textResult.analytics,
|
|
74
|
+
evaluation: textResult.evaluation,
|
|
69
75
|
};
|
|
70
76
|
return generateResult;
|
|
71
77
|
}
|
|
@@ -63,6 +63,9 @@ export declare class ChatClient {
|
|
|
63
63
|
reconnectCount: number;
|
|
64
64
|
};
|
|
65
65
|
private handleSSEEvent;
|
|
66
|
+
private isDataEventData;
|
|
67
|
+
private isErrorEventData;
|
|
68
|
+
private isCompleteEventData;
|
|
66
69
|
private handleDataEvent;
|
|
67
70
|
private handleErrorEvent;
|
|
68
71
|
private handleCompleteEvent;
|
|
@@ -140,19 +140,36 @@ export class ChatClient {
|
|
|
140
140
|
handleSSEEvent(event) {
|
|
141
141
|
switch (event.type) {
|
|
142
142
|
case "data":
|
|
143
|
-
this.
|
|
143
|
+
if (this.isDataEventData(event.data)) {
|
|
144
|
+
this.handleDataEvent(event.data);
|
|
145
|
+
}
|
|
144
146
|
break;
|
|
145
147
|
case "error":
|
|
146
|
-
this.
|
|
148
|
+
if (this.isErrorEventData(event.data)) {
|
|
149
|
+
this.handleErrorEvent(event.data);
|
|
150
|
+
}
|
|
147
151
|
break;
|
|
148
152
|
case "complete":
|
|
149
|
-
this.
|
|
153
|
+
if (this.isCompleteEventData(event.data)) {
|
|
154
|
+
this.handleCompleteEvent(event.data);
|
|
155
|
+
}
|
|
150
156
|
break;
|
|
151
157
|
case "heartbeat":
|
|
152
158
|
// Heartbeat received, connection is alive
|
|
153
159
|
break;
|
|
154
160
|
}
|
|
155
161
|
}
|
|
162
|
+
isDataEventData(data) {
|
|
163
|
+
return (typeof data === "object" &&
|
|
164
|
+
data !== null &&
|
|
165
|
+
typeof data.type === "string");
|
|
166
|
+
}
|
|
167
|
+
isErrorEventData(data) {
|
|
168
|
+
return typeof data === "object" && data !== null;
|
|
169
|
+
}
|
|
170
|
+
isCompleteEventData(data) {
|
|
171
|
+
return typeof data === "object" && data !== null;
|
|
172
|
+
}
|
|
156
173
|
handleDataEvent(data) {
|
|
157
174
|
if (data.type === "chunk") {
|
|
158
175
|
// Handle streaming response chunk
|
|
@@ -167,7 +184,7 @@ export class ChatClient {
|
|
|
167
184
|
const message = {
|
|
168
185
|
id: `msg_${Date.now()}_assistant`,
|
|
169
186
|
role: "assistant",
|
|
170
|
-
content: data.content,
|
|
187
|
+
content: data.content || "",
|
|
171
188
|
timestamp: Date.now(),
|
|
172
189
|
};
|
|
173
190
|
this.messages.push(message);
|
|
@@ -177,7 +194,7 @@ export class ChatClient {
|
|
|
177
194
|
else if (data.type === "start") {
|
|
178
195
|
// New conversation started
|
|
179
196
|
const userMessage = {
|
|
180
|
-
id: data.messageId,
|
|
197
|
+
id: String(data.messageId || `msg_${Date.now()}_user`),
|
|
181
198
|
role: "user",
|
|
182
199
|
content: data.content || "", // Use data content if available
|
|
183
200
|
timestamp: Date.now(),
|
package/dist/lib/chat/index.d.ts
CHANGED
|
@@ -11,17 +11,14 @@ export type { ChatMessage, ChatRequest, SSEOptions, SessionOptions, SSEEvent, Ch
|
|
|
11
11
|
/**
|
|
12
12
|
* Quick setup helper for SSE chat
|
|
13
13
|
*/
|
|
14
|
-
export declare function createSSEChat(provider:
|
|
14
|
+
export declare function createSSEChat(provider: unknown, options?: unknown): Promise<SSEChatHandler>;
|
|
15
15
|
/**
|
|
16
16
|
* Quick setup helper for chat session
|
|
17
17
|
*/
|
|
18
|
-
export declare function createChatSession(sessionId: string, options?:
|
|
19
|
-
/**
|
|
20
|
-
* Enhanced factory function for real-time chat
|
|
21
|
-
*/
|
|
18
|
+
export declare function createChatSession(sessionId: string, options?: unknown): Promise<import("./session.js").ChatSession>;
|
|
22
19
|
export declare function createEnhancedChatService(options: {
|
|
23
|
-
provider:
|
|
20
|
+
provider: unknown;
|
|
24
21
|
enableSSE?: boolean;
|
|
25
22
|
enableWebSocket?: boolean;
|
|
26
|
-
streamingConfig?:
|
|
23
|
+
streamingConfig?: unknown;
|
|
27
24
|
}): Promise<SSEChatHandler>;
|
package/dist/lib/chat/index.js
CHANGED
|
@@ -21,14 +21,6 @@ export async function createChatSession(sessionId, options) {
|
|
|
21
21
|
const { ChatSession } = await import("./session.js");
|
|
22
22
|
return new ChatSession(sessionId, options);
|
|
23
23
|
}
|
|
24
|
-
// Real-time Services (Phase 4) - Temporarily disabled for testing
|
|
25
|
-
// export { WebSocketChatHandler } from './websocket-chat-handler.js';
|
|
26
|
-
// export { NeuroLinkWebSocketServer } from '../services/websocket/websocket-server.js';
|
|
27
|
-
// export { StreamingManager } from '../services/streaming/streaming-manager.js';
|
|
28
|
-
// export * from '../services/types.js';
|
|
29
|
-
/**
|
|
30
|
-
* Enhanced factory function for real-time chat
|
|
31
|
-
*/
|
|
32
24
|
export async function createEnhancedChatService(options) {
|
|
33
25
|
if (options.enableWebSocket) {
|
|
34
26
|
const { WebSocketChatHandler } = await import("./websocket-chat-handler.js");
|
|
@@ -47,10 +47,10 @@ export declare class FileSessionStorage implements SessionStorage {
|
|
|
47
47
|
*/
|
|
48
48
|
interface RedisClient {
|
|
49
49
|
get(key: string): Promise<string | null>;
|
|
50
|
-
set(key: string, value: string, options?:
|
|
50
|
+
set(key: string, value: string, options?: unknown): Promise<unknown>;
|
|
51
51
|
del(key: string): Promise<number>;
|
|
52
52
|
exists(key: string): Promise<number>;
|
|
53
|
-
expire?(key: string, ttl: number): Promise<
|
|
53
|
+
expire?(key: string, ttl: number): Promise<unknown>;
|
|
54
54
|
keys?(pattern: string): Promise<string[]>;
|
|
55
55
|
}
|
|
56
56
|
export declare class RedisSessionStorage implements SessionStorage {
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Chat session management with persistence
|
|
4
4
|
*/
|
|
5
5
|
import type { ChatMessage, SessionOptions, ChatSessionState } from "./types.js";
|
|
6
|
+
import type { JsonValue } from "../types/common.js";
|
|
6
7
|
export declare class ChatSession {
|
|
7
8
|
private sessionId;
|
|
8
9
|
private messages;
|
|
@@ -15,7 +16,7 @@ export declare class ChatSession {
|
|
|
15
16
|
/**
|
|
16
17
|
* Add message to session
|
|
17
18
|
*/
|
|
18
|
-
addMessage(role: "user" | "assistant" | "system", content: string, metadata?:
|
|
19
|
+
addMessage(role: "user" | "assistant" | "system", content: string, metadata?: unknown): ChatMessage;
|
|
19
20
|
/**
|
|
20
21
|
* Get conversation history
|
|
21
22
|
*/
|
|
@@ -27,11 +28,11 @@ export declare class ChatSession {
|
|
|
27
28
|
/**
|
|
28
29
|
* Get session metadata
|
|
29
30
|
*/
|
|
30
|
-
getMetadata(): Record<string,
|
|
31
|
+
getMetadata(): Record<string, JsonValue>;
|
|
31
32
|
/**
|
|
32
33
|
* Set session metadata
|
|
33
34
|
*/
|
|
34
|
-
setMetadata(key: string, value:
|
|
35
|
+
setMetadata(key: string, value: JsonValue): void;
|
|
35
36
|
/**
|
|
36
37
|
* Clear session history
|
|
37
38
|
*/
|
package/dist/lib/chat/session.js
CHANGED
|
@@ -49,29 +49,21 @@ export class SSEChatHandler {
|
|
|
49
49
|
systemPrompt: options.systemPrompt,
|
|
50
50
|
});
|
|
51
51
|
if (aiResponse?.stream) {
|
|
52
|
-
//
|
|
52
|
+
// Iterate over the async iterable stream
|
|
53
53
|
const reader = aiResponse.stream;
|
|
54
54
|
let fullResponse = "";
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
content: value,
|
|
68
|
-
sessionId,
|
|
69
|
-
},
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
finally {
|
|
74
|
-
reader.releaseLock();
|
|
55
|
+
for await (const chunk of reader) {
|
|
56
|
+
const content = chunk.content;
|
|
57
|
+
fullResponse += content;
|
|
58
|
+
// Send chunk to client
|
|
59
|
+
await this.sendEvent(writer, {
|
|
60
|
+
type: "data",
|
|
61
|
+
data: {
|
|
62
|
+
type: "chunk",
|
|
63
|
+
content: content,
|
|
64
|
+
sessionId,
|
|
65
|
+
},
|
|
66
|
+
});
|
|
75
67
|
}
|
|
76
68
|
// Add AI response to session
|
|
77
69
|
const assistantMessage = {
|
package/dist/lib/chat/types.d.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Phase 3: SSE Chat Utilities
|
|
3
3
|
* Type definitions for chat infrastructure
|
|
4
4
|
*/
|
|
5
|
+
import type { JsonValue } from "../types/common.js";
|
|
5
6
|
export interface ChatMessage {
|
|
6
7
|
id: string;
|
|
7
8
|
role: "user" | "assistant" | "system";
|
|
@@ -41,7 +42,7 @@ export interface SessionOptions {
|
|
|
41
42
|
}
|
|
42
43
|
export interface SSEEvent {
|
|
43
44
|
type: "data" | "error" | "progress" | "complete" | "heartbeat";
|
|
44
|
-
data:
|
|
45
|
+
data: JsonValue;
|
|
45
46
|
id?: string;
|
|
46
47
|
retry?: number;
|
|
47
48
|
}
|
|
@@ -50,7 +51,7 @@ export interface ChatSessionState {
|
|
|
50
51
|
messages: ChatMessage[];
|
|
51
52
|
createdAt: number;
|
|
52
53
|
lastActivity: number;
|
|
53
|
-
metadata?: Record<string,
|
|
54
|
+
metadata?: Record<string, JsonValue>;
|
|
54
55
|
}
|
|
55
56
|
export interface StreamingChatResponse {
|
|
56
57
|
sessionId: string;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { SSEChatHandler } from "./sse-handler.js";
|
|
2
2
|
import type { AIProvider } from "../core/types.js";
|
|
3
|
-
import type { WebSocketOptions,
|
|
4
|
-
import type { SSEOptions } from "./types.js";
|
|
3
|
+
import type { WebSocketOptions, GroupChatRequest, StreamingChatRequest } from "../services/types.js";
|
|
4
|
+
import type { SSEOptions, ChatRequest } from "./types.js";
|
|
5
|
+
import type { UnknownRecord } from "../types/common.js";
|
|
5
6
|
export interface WebSocketChatOptions {
|
|
6
|
-
sseOptions?:
|
|
7
|
+
sseOptions?: UnknownRecord;
|
|
7
8
|
wsOptions?: WebSocketOptions;
|
|
8
9
|
enableTypingIndicators?: boolean;
|
|
9
10
|
enablePresenceTracking?: boolean;
|
|
@@ -61,7 +61,7 @@ export class WebSocketChatHandler extends SSEChatHandler {
|
|
|
61
61
|
});
|
|
62
62
|
// Generate AI response
|
|
63
63
|
const result = await this.provider.generate({
|
|
64
|
-
prompt: request.
|
|
64
|
+
prompt: request.message,
|
|
65
65
|
temperature: request.options?.temperature,
|
|
66
66
|
maxTokens: request.options?.maxTokens,
|
|
67
67
|
});
|
|
@@ -177,12 +177,8 @@ export class WebSocketChatHandler extends SSEChatHandler {
|
|
|
177
177
|
}
|
|
178
178
|
// Helper methods
|
|
179
179
|
sendToConnection(connectionId, message) {
|
|
180
|
-
// Use the WebSocket server's send method
|
|
181
|
-
|
|
182
|
-
if (ws && ws.readyState === 1) {
|
|
183
|
-
// WebSocket.OPEN
|
|
184
|
-
ws.send(JSON.stringify(message));
|
|
185
|
-
}
|
|
180
|
+
// Use the WebSocket server's public send method
|
|
181
|
+
this.wsServer.sendMessage(connectionId, message);
|
|
186
182
|
}
|
|
187
183
|
sendError(connectionId, errorMessage) {
|
|
188
184
|
const errorMsg = {
|
|
@@ -227,18 +223,22 @@ export class WebSocketChatHandler extends SSEChatHandler {
|
|
|
227
223
|
});
|
|
228
224
|
}
|
|
229
225
|
handleWebSocketChatMessage(connectionId, message) {
|
|
230
|
-
|
|
226
|
+
const data = message.data;
|
|
227
|
+
if (!data || typeof data !== "object") {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
switch (data.event) {
|
|
231
231
|
case "chat_request":
|
|
232
|
-
this.handleWebSocketChatRequest(connectionId,
|
|
232
|
+
this.handleWebSocketChatRequest(connectionId, data.request);
|
|
233
233
|
break;
|
|
234
234
|
case "join_room":
|
|
235
|
-
this.wsServer.joinRoom(connectionId,
|
|
235
|
+
this.wsServer.joinRoom(connectionId, data.roomId);
|
|
236
236
|
break;
|
|
237
237
|
case "leave_room":
|
|
238
|
-
this.wsServer.leaveRoom(connectionId,
|
|
238
|
+
this.wsServer.leaveRoom(connectionId, data.roomId);
|
|
239
239
|
break;
|
|
240
240
|
case "typing_start":
|
|
241
|
-
this.showTypingIndicator(connectionId,
|
|
241
|
+
this.showTypingIndicator(connectionId, data.sender || "user");
|
|
242
242
|
break;
|
|
243
243
|
case "typing_stop":
|
|
244
244
|
this.clearTypingIndicator(connectionId);
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* Provides lightweight analytics tracking for AI provider usage,
|
|
5
5
|
* including tokens, costs, performance metrics, and custom context.
|
|
6
6
|
*/
|
|
7
|
+
import type { JsonValue, UnknownRecord } from "../types/common.js";
|
|
7
8
|
export interface AnalyticsData {
|
|
8
9
|
provider: string;
|
|
9
10
|
model: string;
|
|
@@ -14,10 +15,10 @@ export interface AnalyticsData {
|
|
|
14
15
|
};
|
|
15
16
|
cost?: number;
|
|
16
17
|
responseTime: number;
|
|
17
|
-
context?: Record<string,
|
|
18
|
+
context?: Record<string, JsonValue>;
|
|
18
19
|
timestamp: string;
|
|
19
20
|
}
|
|
20
21
|
/**
|
|
21
22
|
* Create analytics data structure from AI response
|
|
22
23
|
*/
|
|
23
|
-
export declare function createAnalytics(provider: string, model: string, result:
|
|
24
|
+
export declare function createAnalytics(provider: string, model: string, result: UnknownRecord, responseTime: number, context?: Record<string, JsonValue>): AnalyticsData;
|
|
@@ -51,23 +51,30 @@ export function createAnalytics(provider, model, result, responseTime, context)
|
|
|
51
51
|
*/
|
|
52
52
|
function extractTokenUsage(result) {
|
|
53
53
|
// Handle different response formats
|
|
54
|
-
if (result.usage
|
|
54
|
+
if (result.usage &&
|
|
55
|
+
typeof result.usage === "object" &&
|
|
56
|
+
result.usage !== null) {
|
|
55
57
|
const usage = result.usage;
|
|
56
58
|
// Standard format
|
|
57
|
-
if (usage.promptTokens
|
|
58
|
-
usage.completionTokens
|
|
59
|
+
if (typeof usage.promptTokens === "number" &&
|
|
60
|
+
typeof usage.completionTokens === "number") {
|
|
59
61
|
return {
|
|
60
62
|
input: usage.promptTokens || 0,
|
|
61
63
|
output: usage.completionTokens || 0,
|
|
62
|
-
total: usage.totalTokens
|
|
64
|
+
total: typeof usage.totalTokens === "number"
|
|
65
|
+
? usage.totalTokens
|
|
66
|
+
: usage.promptTokens + usage.completionTokens,
|
|
63
67
|
};
|
|
64
68
|
}
|
|
65
69
|
// Alternative formats
|
|
66
|
-
if (usage.input_tokens
|
|
70
|
+
if (typeof usage.input_tokens === "number" &&
|
|
71
|
+
typeof usage.output_tokens === "number") {
|
|
67
72
|
return {
|
|
68
73
|
input: usage.input_tokens || 0,
|
|
69
74
|
output: usage.output_tokens || 0,
|
|
70
|
-
total: usage.total_tokens
|
|
75
|
+
total: typeof usage.total_tokens === "number"
|
|
76
|
+
? usage.total_tokens
|
|
77
|
+
: usage.input_tokens + usage.output_tokens,
|
|
71
78
|
};
|
|
72
79
|
}
|
|
73
80
|
// Generic tokens field
|
|
@@ -80,7 +87,9 @@ function extractTokenUsage(result) {
|
|
|
80
87
|
}
|
|
81
88
|
}
|
|
82
89
|
// Fallback: estimate from text length
|
|
83
|
-
const textLength = result.text
|
|
90
|
+
const textLength = (typeof result.text === "string" ? result.text.length : 0) ||
|
|
91
|
+
(typeof result.content === "string" ? result.content.length : 0) ||
|
|
92
|
+
0;
|
|
84
93
|
const estimatedTokens = Math.ceil(textLength / 4); // ~4 chars per token
|
|
85
94
|
return {
|
|
86
95
|
input: 0,
|
|
@@ -1,8 +1,35 @@
|
|
|
1
1
|
import type { ZodType, ZodTypeDef } from "zod";
|
|
2
2
|
import type { Schema } from "ai";
|
|
3
|
-
import type { Tool } from "ai";
|
|
4
|
-
import type { AIProvider, TextGenerationOptions, EnhancedGenerateResult, AnalyticsData, AIProviderName } from "../core/types.js";
|
|
3
|
+
import type { Tool, LanguageModel } from "ai";
|
|
4
|
+
import type { AIProvider, TextGenerationOptions, EnhancedGenerateResult, AnalyticsData, AIProviderName, EvaluationData } from "../core/types.js";
|
|
5
5
|
import type { StreamOptions, StreamResult } from "../types/stream-types.js";
|
|
6
|
+
import type { JsonValue, UnknownRecord } from "../types/common.js";
|
|
7
|
+
import type { ToolResult } from "../types/tools.js";
|
|
8
|
+
/**
|
|
9
|
+
* Interface for SDK with in-memory MCP servers
|
|
10
|
+
*/
|
|
11
|
+
export interface NeuroLinkSDK {
|
|
12
|
+
getInMemoryServers?: () => Map<string, {
|
|
13
|
+
server: {
|
|
14
|
+
title?: string;
|
|
15
|
+
description?: string;
|
|
16
|
+
tools?: Map<string, ToolInfo> | Record<string, ToolInfo>;
|
|
17
|
+
};
|
|
18
|
+
category?: string;
|
|
19
|
+
metadata?: UnknownRecord;
|
|
20
|
+
}>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Interface for tool information in MCP servers
|
|
24
|
+
*/
|
|
25
|
+
interface ToolInfo {
|
|
26
|
+
description?: string;
|
|
27
|
+
inputSchema?: ZodType<JsonValue>;
|
|
28
|
+
parameters?: ZodType<JsonValue>;
|
|
29
|
+
execute: (args: JsonValue) => Promise<JsonValue | ToolResult> | JsonValue | ToolResult;
|
|
30
|
+
isImplemented?: boolean;
|
|
31
|
+
metadata?: UnknownRecord;
|
|
32
|
+
}
|
|
6
33
|
/**
|
|
7
34
|
* Abstract base class for all AI providers
|
|
8
35
|
* Tools are integrated as first-class citizens - always available by default
|
|
@@ -354,8 +381,8 @@ export declare abstract class BaseProvider implements AIProvider {
|
|
|
354
381
|
protected mcpTools?: Record<string, Tool>;
|
|
355
382
|
protected sessionId?: string;
|
|
356
383
|
protected userId?: string;
|
|
357
|
-
protected sdk?:
|
|
358
|
-
constructor(modelName?: string, providerName?: AIProviderName, sdk?:
|
|
384
|
+
protected sdk?: NeuroLinkSDK;
|
|
385
|
+
constructor(modelName?: string, providerName?: AIProviderName, sdk?: NeuroLinkSDK);
|
|
359
386
|
/**
|
|
360
387
|
* Check if this provider supports tool/function calling
|
|
361
388
|
* Override in subclasses to disable tools for specific providers or models
|
|
@@ -392,7 +419,7 @@ export declare abstract class BaseProvider implements AIProvider {
|
|
|
392
419
|
* REQUIRED: Every provider MUST implement this method
|
|
393
420
|
* Returns the Vercel AI SDK model instance for this provider
|
|
394
421
|
*/
|
|
395
|
-
protected abstract getAISDKModel():
|
|
422
|
+
protected abstract getAISDKModel(): LanguageModel | Promise<LanguageModel>;
|
|
396
423
|
/**
|
|
397
424
|
* Get all available tools - direct tools are ALWAYS available
|
|
398
425
|
* MCP tools are added when available (without blocking)
|
|
@@ -405,12 +432,12 @@ export declare abstract class BaseProvider implements AIProvider {
|
|
|
405
432
|
/**
|
|
406
433
|
* Provider-specific error handling
|
|
407
434
|
*/
|
|
408
|
-
protected abstract handleProviderError(error:
|
|
435
|
+
protected abstract handleProviderError(error: unknown): Error;
|
|
409
436
|
protected normalizeTextOptions(optionsOrPrompt: TextGenerationOptions | string): TextGenerationOptions;
|
|
410
437
|
protected normalizeStreamOptions(optionsOrPrompt: StreamOptions | string): StreamOptions;
|
|
411
438
|
protected enhanceResult(result: EnhancedGenerateResult, options: TextGenerationOptions, startTime: number): Promise<EnhancedGenerateResult>;
|
|
412
439
|
protected createAnalytics(result: EnhancedGenerateResult, responseTime: number, options: TextGenerationOptions): Promise<AnalyticsData>;
|
|
413
|
-
protected createEvaluation(result: EnhancedGenerateResult, options: TextGenerationOptions): Promise<
|
|
440
|
+
protected createEvaluation(result: EnhancedGenerateResult, options: TextGenerationOptions): Promise<EvaluationData>;
|
|
414
441
|
protected validateOptions(options: TextGenerationOptions): void;
|
|
415
442
|
protected getProviderInfo(): {
|
|
416
443
|
provider: string;
|
|
@@ -421,3 +448,4 @@ export declare abstract class BaseProvider implements AIProvider {
|
|
|
421
448
|
*/
|
|
422
449
|
getTimeout(options: TextGenerationOptions | StreamOptions): number;
|
|
423
450
|
}
|
|
451
|
+
export {};
|