@juspay/neurolink 5.2.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 +82 -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/factories/command-factory.js +6 -5
- 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 +57 -23
- package/dist/core/constants.d.ts +1 -0
- package/dist/core/constants.js +1 -0
- 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 +57 -23
- package/dist/lib/core/constants.d.ts +1 -0
- package/dist/lib/core/constants.js +1 -0
- 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 +3 -1
- package/dist/lib/mcp/client.js +13 -10
- package/dist/lib/mcp/context-manager.d.ts +2 -1
- package/dist/lib/mcp/context-manager.js +8 -4
- 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 +14 -0
- package/dist/lib/mcp/function-calling.js +133 -34
- 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.d.ts +1 -0
- package/dist/lib/mcp/neurolink-mcp-client.js +22 -6
- 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 +66 -4
- package/dist/lib/providers/function-calling-provider.js +209 -10
- 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/mcp-provider.js +20 -5
- 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/streaming/streaming-manager.js +11 -10
- 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 +13 -12
- package/dist/lib/telemetry/telemetry-service.js +9 -8
- 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 +3 -1
- package/dist/mcp/client.js +13 -10
- package/dist/mcp/context-manager.d.ts +2 -1
- package/dist/mcp/context-manager.js +8 -4
- 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 +14 -0
- package/dist/mcp/function-calling.js +133 -34
- 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.d.ts +1 -0
- package/dist/mcp/neurolink-mcp-client.js +22 -6
- 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 +66 -4
- package/dist/providers/function-calling-provider.js +209 -10
- 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/mcp-provider.js +20 -5
- 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/streaming/streaming-manager.js +11 -10
- 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 +14 -12
- package/dist/telemetry/telemetry-service.js +9 -8
- 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 +12 -10
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { EventEmitter } from "events";
|
|
2
2
|
import { randomUUID } from "crypto";
|
|
3
|
+
import { logger } from "../../utils/logger.js";
|
|
3
4
|
export class StreamingManager extends EventEmitter {
|
|
4
5
|
activeSessions = new Map();
|
|
5
6
|
streamingPools = new Map();
|
|
@@ -40,7 +41,7 @@ export class StreamingManager extends EventEmitter {
|
|
|
40
41
|
};
|
|
41
42
|
this.activeSessions.set(sessionId, session);
|
|
42
43
|
this.updateGlobalMetrics();
|
|
43
|
-
|
|
44
|
+
logger.debug(`[Streaming Manager] Created session ${sessionId} for provider ${config.provider}`);
|
|
44
45
|
this.emit("session-created", session);
|
|
45
46
|
return session;
|
|
46
47
|
}
|
|
@@ -52,7 +53,7 @@ export class StreamingManager extends EventEmitter {
|
|
|
52
53
|
session.status = "terminated";
|
|
53
54
|
this.activeSessions.delete(sessionId);
|
|
54
55
|
this.updateGlobalMetrics();
|
|
55
|
-
|
|
56
|
+
logger.debug(`[Streaming Manager] Terminated session ${sessionId}`);
|
|
56
57
|
this.emit("session-terminated", session);
|
|
57
58
|
}
|
|
58
59
|
async pauseStreamingSession(sessionId) {
|
|
@@ -62,7 +63,7 @@ export class StreamingManager extends EventEmitter {
|
|
|
62
63
|
}
|
|
63
64
|
if (session.status === "active") {
|
|
64
65
|
session.status = "paused";
|
|
65
|
-
|
|
66
|
+
logger.debug(`[Streaming Manager] Paused session ${sessionId}`);
|
|
66
67
|
this.emit("session-paused", session);
|
|
67
68
|
}
|
|
68
69
|
}
|
|
@@ -74,7 +75,7 @@ export class StreamingManager extends EventEmitter {
|
|
|
74
75
|
if (session.status === "paused") {
|
|
75
76
|
session.status = "active";
|
|
76
77
|
session.lastActivity = Date.now();
|
|
77
|
-
|
|
78
|
+
logger.debug(`[Streaming Manager] Resumed session ${sessionId}`);
|
|
78
79
|
this.emit("session-resumed", session);
|
|
79
80
|
}
|
|
80
81
|
}
|
|
@@ -97,7 +98,7 @@ export class StreamingManager extends EventEmitter {
|
|
|
97
98
|
session.config.bufferSize = Math.max(session.config.bufferSize * 0.8, 1024);
|
|
98
99
|
session.config.streamingMode = "real-time";
|
|
99
100
|
}
|
|
100
|
-
|
|
101
|
+
logger.debug(`[Streaming Manager] Optimized session ${sessionId}: latency=${currentLatency}ms, mode=${session.config.streamingMode}`);
|
|
101
102
|
}
|
|
102
103
|
async enableStreamingCompression(sessionId) {
|
|
103
104
|
const session = this.activeSessions.get(sessionId);
|
|
@@ -105,7 +106,7 @@ export class StreamingManager extends EventEmitter {
|
|
|
105
106
|
return;
|
|
106
107
|
}
|
|
107
108
|
session.config.compressionEnabled = true;
|
|
108
|
-
|
|
109
|
+
logger.debug(`[Streaming Manager] Enabled compression for session ${sessionId}`);
|
|
109
110
|
}
|
|
110
111
|
async configureStreamingBuffering(sessionId, bufferConfig) {
|
|
111
112
|
const session = this.activeSessions.get(sessionId);
|
|
@@ -114,7 +115,7 @@ export class StreamingManager extends EventEmitter {
|
|
|
114
115
|
}
|
|
115
116
|
session.config.bufferSize = bufferConfig.maxSize;
|
|
116
117
|
session.config.maxChunkSize = Math.min(session.config.maxChunkSize, bufferConfig.flushThreshold);
|
|
117
|
-
|
|
118
|
+
logger.debug(`[Streaming Manager] Updated buffer config for session ${sessionId}:`, bufferConfig);
|
|
118
119
|
}
|
|
119
120
|
// Multi-Stream Coordination
|
|
120
121
|
async createStreamingPool(poolId, config) {
|
|
@@ -126,7 +127,7 @@ export class StreamingManager extends EventEmitter {
|
|
|
126
127
|
loadBalancer: config.loadBalancing,
|
|
127
128
|
};
|
|
128
129
|
this.streamingPools.set(poolId, pool);
|
|
129
|
-
|
|
130
|
+
logger.debug(`[Streaming Manager] Created pool ${poolId} with max ${config.maxConcurrentSessions} sessions`);
|
|
130
131
|
}
|
|
131
132
|
async balanceStreamingLoad(poolId) {
|
|
132
133
|
const pool = this.streamingPools.get(poolId);
|
|
@@ -160,7 +161,7 @@ export class StreamingManager extends EventEmitter {
|
|
|
160
161
|
const newMaxSessions = Math.max(1, Math.floor(pool.maxSessions * scale));
|
|
161
162
|
pool.maxSessions = newMaxSessions;
|
|
162
163
|
pool.config.maxConcurrentSessions = newMaxSessions;
|
|
163
|
-
|
|
164
|
+
logger.debug(`[Streaming Manager] Scaled pool ${poolId} to ${newMaxSessions} max sessions (${scale}x)`);
|
|
164
165
|
}
|
|
165
166
|
// Performance Monitoring
|
|
166
167
|
getStreamingMetrics(sessionId) {
|
|
@@ -217,7 +218,7 @@ export class StreamingManager extends EventEmitter {
|
|
|
217
218
|
this.healthCheckInterval = setInterval(() => {
|
|
218
219
|
const health = this.getStreamingHealthStatus();
|
|
219
220
|
if (health.status !== "healthy") {
|
|
220
|
-
|
|
221
|
+
logger.debug("[Streaming Manager] Health check:", health);
|
|
221
222
|
this.emit("health-warning", health);
|
|
222
223
|
}
|
|
223
224
|
}, 30000); // Check every 30 seconds
|
package/dist/services/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { UnknownRecord, Unknown } from "../types/common.js";
|
|
1
2
|
export interface StreamingSession {
|
|
2
3
|
id: string;
|
|
3
4
|
connectionId: string;
|
|
@@ -57,12 +58,12 @@ export interface StreamingChannel {
|
|
|
57
58
|
type: "ai-response" | "mcp-tool" | "chat" | "notification";
|
|
58
59
|
status: "open" | "closed" | "error";
|
|
59
60
|
buffer: StreamingBuffer;
|
|
60
|
-
onData: (data:
|
|
61
|
+
onData: (data: Unknown) => void;
|
|
61
62
|
onError: (error: Error) => void;
|
|
62
63
|
onClose: () => void;
|
|
63
64
|
}
|
|
64
65
|
export interface StreamingBuffer {
|
|
65
|
-
data:
|
|
66
|
+
data: Unknown[];
|
|
66
67
|
maxSize: number;
|
|
67
68
|
currentSize: number;
|
|
68
69
|
flushThreshold: number;
|
|
@@ -92,7 +93,7 @@ export interface WebSocketMessage {
|
|
|
92
93
|
connectionId: string;
|
|
93
94
|
roomId?: string;
|
|
94
95
|
timestamp: number;
|
|
95
|
-
data:
|
|
96
|
+
data: Unknown;
|
|
96
97
|
metadata?: {
|
|
97
98
|
provider?: string;
|
|
98
99
|
model?: string;
|
|
@@ -151,5 +152,5 @@ export interface ConnectionInfo {
|
|
|
151
152
|
lastActivity: number;
|
|
152
153
|
rooms: Set<string>;
|
|
153
154
|
subscriptions: Set<string>;
|
|
154
|
-
metadata:
|
|
155
|
+
metadata: UnknownRecord;
|
|
155
156
|
}
|
|
@@ -18,7 +18,7 @@ export declare class NeuroLinkWebSocketServer extends EventEmitter {
|
|
|
18
18
|
broadcastToRoom(roomId: string, message: WebSocketMessage): void;
|
|
19
19
|
createStreamingChannel(connectionId: string, channelId: string): StreamingChannel;
|
|
20
20
|
destroyStreamingChannel(channelId: string): void;
|
|
21
|
-
|
|
21
|
+
sendMessage(connectionId: string, message: WebSocketMessage): boolean;
|
|
22
22
|
private sendError;
|
|
23
23
|
private updateLastActivity;
|
|
24
24
|
private handleHeartbeat;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { WebSocketServer, WebSocket } from "ws";
|
|
2
2
|
import { EventEmitter } from "events";
|
|
3
3
|
import { randomUUID } from "crypto";
|
|
4
|
+
import { IncomingMessage } from "http";
|
|
5
|
+
import { logger } from "../../utils/logger.js";
|
|
4
6
|
export class NeuroLinkWebSocketServer extends EventEmitter {
|
|
5
7
|
wss;
|
|
6
8
|
connections = new Map();
|
|
@@ -32,7 +34,7 @@ export class NeuroLinkWebSocketServer extends EventEmitter {
|
|
|
32
34
|
this.handleConnection(ws, request);
|
|
33
35
|
});
|
|
34
36
|
this.wss.on("error", (error) => {
|
|
35
|
-
|
|
37
|
+
logger.error("[WebSocket Server] Error:", error);
|
|
36
38
|
this.emit("error", error);
|
|
37
39
|
});
|
|
38
40
|
}
|
|
@@ -43,7 +45,7 @@ export class NeuroLinkWebSocketServer extends EventEmitter {
|
|
|
43
45
|
}
|
|
44
46
|
const connectionId = randomUUID();
|
|
45
47
|
const userAgent = request.headers["user-agent"];
|
|
46
|
-
const ipAddress = request.socket
|
|
48
|
+
const ipAddress = request.socket?.remoteAddress;
|
|
47
49
|
// Store connection
|
|
48
50
|
this.connections.set(connectionId, ws);
|
|
49
51
|
this.connectionInfo.set(connectionId, {
|
|
@@ -64,7 +66,7 @@ export class NeuroLinkWebSocketServer extends EventEmitter {
|
|
|
64
66
|
this.handleDisconnection(connectionId);
|
|
65
67
|
});
|
|
66
68
|
ws.on("error", (error) => {
|
|
67
|
-
|
|
69
|
+
logger.error(`[WebSocket] Connection ${connectionId} error:`, error);
|
|
68
70
|
this.handleDisconnection(connectionId);
|
|
69
71
|
});
|
|
70
72
|
// Send connection confirmation
|
|
@@ -82,7 +84,7 @@ export class NeuroLinkWebSocketServer extends EventEmitter {
|
|
|
82
84
|
},
|
|
83
85
|
},
|
|
84
86
|
});
|
|
85
|
-
|
|
87
|
+
logger.debug(`[WebSocket] New connection: ${connectionId} (${this.connections.size}/${this.options.maxConnections})`);
|
|
86
88
|
this.emit("connection", { connectionId, userAgent, ipAddress });
|
|
87
89
|
}
|
|
88
90
|
handleMessage(connectionId, data) {
|
|
@@ -101,7 +103,7 @@ export class NeuroLinkWebSocketServer extends EventEmitter {
|
|
|
101
103
|
}
|
|
102
104
|
}
|
|
103
105
|
catch (error) {
|
|
104
|
-
|
|
106
|
+
logger.error(`[WebSocket] Invalid message from ${connectionId}:`, error);
|
|
105
107
|
this.sendError(connectionId, "Invalid message format");
|
|
106
108
|
}
|
|
107
109
|
}
|
|
@@ -124,7 +126,7 @@ export class NeuroLinkWebSocketServer extends EventEmitter {
|
|
|
124
126
|
// Clean up
|
|
125
127
|
this.connections.delete(connectionId);
|
|
126
128
|
this.connectionInfo.delete(connectionId);
|
|
127
|
-
|
|
129
|
+
logger.debug(`[WebSocket] Disconnected: ${connectionId} (${this.connections.size}/${this.options.maxConnections})`);
|
|
128
130
|
this.emit("disconnection", { connectionId });
|
|
129
131
|
}
|
|
130
132
|
// Room Management
|
|
@@ -150,7 +152,7 @@ export class NeuroLinkWebSocketServer extends EventEmitter {
|
|
|
150
152
|
memberCount: this.rooms.get(roomId).size,
|
|
151
153
|
},
|
|
152
154
|
});
|
|
153
|
-
|
|
155
|
+
logger.debug(`[WebSocket] ${connectionId} joined room ${roomId}`);
|
|
154
156
|
return true;
|
|
155
157
|
}
|
|
156
158
|
leaveRoom(connectionId, roomId) {
|
|
@@ -179,7 +181,7 @@ export class NeuroLinkWebSocketServer extends EventEmitter {
|
|
|
179
181
|
memberCount: room.size,
|
|
180
182
|
},
|
|
181
183
|
});
|
|
182
|
-
|
|
184
|
+
logger.debug(`[WebSocket] ${connectionId} left room ${roomId}`);
|
|
183
185
|
return true;
|
|
184
186
|
}
|
|
185
187
|
broadcastToRoom(roomId, message) {
|
|
@@ -231,7 +233,7 @@ export class NeuroLinkWebSocketServer extends EventEmitter {
|
|
|
231
233
|
return true;
|
|
232
234
|
}
|
|
233
235
|
catch (error) {
|
|
234
|
-
|
|
236
|
+
logger.error(`[WebSocket] Failed to send message to ${connectionId}:`, error);
|
|
235
237
|
return false;
|
|
236
238
|
}
|
|
237
239
|
}
|
|
@@ -269,7 +271,7 @@ export class NeuroLinkWebSocketServer extends EventEmitter {
|
|
|
269
271
|
const connection = this.connectionInfo.get(connectionId);
|
|
270
272
|
if (connection &&
|
|
271
273
|
Date.now() - connection.lastActivity > this.options.timeoutMs) {
|
|
272
|
-
|
|
274
|
+
logger.debug(`[WebSocket] Timeout for connection ${connectionId}`);
|
|
273
275
|
ws.terminate();
|
|
274
276
|
}
|
|
275
277
|
}
|
|
@@ -296,9 +298,9 @@ export class NeuroLinkWebSocketServer extends EventEmitter {
|
|
|
296
298
|
// Implementation for channel data handling
|
|
297
299
|
}
|
|
298
300
|
handleChannelError(channelId, error) {
|
|
299
|
-
|
|
301
|
+
logger.error(`[Streaming Channel] ${channelId} error:`, error);
|
|
300
302
|
}
|
|
301
303
|
handleChannelClose(channelId) {
|
|
302
|
-
|
|
304
|
+
logger.debug(`[Streaming Channel] ${channelId} closed`);
|
|
303
305
|
}
|
|
304
306
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { NodeSDK } from "@opentelemetry/sdk-node";
|
|
2
|
-
import { metrics, trace } from "@opentelemetry/api";
|
|
2
|
+
import { metrics, trace, } from "@opentelemetry/api";
|
|
3
3
|
import { getNodeAutoInstrumentations } from "@opentelemetry/auto-instrumentations-node";
|
|
4
4
|
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
|
|
5
5
|
import { OTLPMetricExporter } from "@opentelemetry/exporter-metrics-otlp-http";
|
|
6
6
|
import { Resource } from "@opentelemetry/resources";
|
|
7
7
|
import { ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION, } from "@opentelemetry/semantic-conventions";
|
|
8
8
|
import { PeriodicExportingMetricReader } from "@opentelemetry/sdk-metrics";
|
|
9
|
+
import { logger } from "../utils/logger.js";
|
|
9
10
|
export class TelemetryService {
|
|
10
11
|
static instance;
|
|
11
12
|
sdk;
|
|
@@ -27,7 +28,7 @@ export class TelemetryService {
|
|
|
27
28
|
this.initializeTelemetry();
|
|
28
29
|
}
|
|
29
30
|
else {
|
|
30
|
-
|
|
31
|
+
logger.debug("[Telemetry] Disabled - set NEUROLINK_TELEMETRY_ENABLED=true or configure OTEL_EXPORTER_OTLP_ENDPOINT to enable");
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
34
|
static getInstance() {
|
|
@@ -58,10 +59,10 @@ export class TelemetryService {
|
|
|
58
59
|
this.meter = metrics.getMeter("neurolink-ai");
|
|
59
60
|
this.tracer = trace.getTracer("neurolink-ai");
|
|
60
61
|
this.initializeMetrics();
|
|
61
|
-
|
|
62
|
+
logger.debug("[Telemetry] Initialized with endpoint:", process.env.OTEL_EXPORTER_OTLP_ENDPOINT);
|
|
62
63
|
}
|
|
63
64
|
catch (error) {
|
|
64
|
-
|
|
65
|
+
logger.error("[Telemetry] Failed to initialize:", error);
|
|
65
66
|
this.enabled = false;
|
|
66
67
|
}
|
|
67
68
|
}
|
|
@@ -97,10 +98,10 @@ export class TelemetryService {
|
|
|
97
98
|
}
|
|
98
99
|
try {
|
|
99
100
|
await this.sdk?.start();
|
|
100
|
-
|
|
101
|
+
logger.debug("[Telemetry] SDK started successfully");
|
|
101
102
|
}
|
|
102
103
|
catch (error) {
|
|
103
|
-
|
|
104
|
+
logger.error("[Telemetry] Failed to start SDK:", error);
|
|
104
105
|
this.enabled = false;
|
|
105
106
|
}
|
|
106
107
|
}
|
|
@@ -251,10 +252,10 @@ export class TelemetryService {
|
|
|
251
252
|
if (this.enabled && this.sdk) {
|
|
252
253
|
try {
|
|
253
254
|
await this.sdk.shutdown();
|
|
254
|
-
|
|
255
|
+
logger.debug("[Telemetry] SDK shutdown completed");
|
|
255
256
|
}
|
|
256
257
|
catch (error) {
|
|
257
|
-
|
|
258
|
+
logger.error("[Telemetry] Error during shutdown:", error);
|
|
258
259
|
}
|
|
259
260
|
}
|
|
260
261
|
}
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI-specific type definitions for NeuroLink
|
|
3
|
+
* Replaces 'any' types in CLI commands and arguments
|
|
4
|
+
*/
|
|
5
|
+
import type { UnknownRecord, JsonValue } from "./common.js";
|
|
6
|
+
import type { AnalyticsData, EvaluationData, TokenUsage } from "./providers.js";
|
|
7
|
+
import type { ToolCall, ToolResult } from "./tools.js";
|
|
8
|
+
/**
|
|
9
|
+
* Base command arguments interface
|
|
10
|
+
*/
|
|
11
|
+
export interface BaseCommandArgs {
|
|
12
|
+
/** Enable debug output */
|
|
13
|
+
debug?: boolean;
|
|
14
|
+
/** Output format */
|
|
15
|
+
format?: "text" | "json" | "table";
|
|
16
|
+
/** Verbose output */
|
|
17
|
+
verbose?: boolean;
|
|
18
|
+
/** Quiet mode */
|
|
19
|
+
quiet?: boolean;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Generate command arguments
|
|
23
|
+
*/
|
|
24
|
+
export interface GenerateCommandArgs extends BaseCommandArgs {
|
|
25
|
+
/** Input text or prompt */
|
|
26
|
+
input?: string;
|
|
27
|
+
/** AI provider to use */
|
|
28
|
+
provider?: string;
|
|
29
|
+
/** Model name */
|
|
30
|
+
model?: string;
|
|
31
|
+
/** System prompt */
|
|
32
|
+
system?: string;
|
|
33
|
+
/** Temperature setting */
|
|
34
|
+
temperature?: number;
|
|
35
|
+
/** Maximum tokens */
|
|
36
|
+
maxTokens?: number;
|
|
37
|
+
/** Enable analytics */
|
|
38
|
+
analytics?: boolean;
|
|
39
|
+
/** Enable evaluation */
|
|
40
|
+
evaluation?: boolean;
|
|
41
|
+
/** Context data */
|
|
42
|
+
context?: string;
|
|
43
|
+
/** Disable tools */
|
|
44
|
+
disableTools?: boolean;
|
|
45
|
+
/** Maximum steps for multi-turn */
|
|
46
|
+
maxSteps?: number;
|
|
47
|
+
/** Output file */
|
|
48
|
+
output?: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Stream command arguments
|
|
52
|
+
*/
|
|
53
|
+
export interface StreamCommandArgs extends BaseCommandArgs {
|
|
54
|
+
/** Input text or prompt */
|
|
55
|
+
input?: string;
|
|
56
|
+
/** AI provider to use */
|
|
57
|
+
provider?: string;
|
|
58
|
+
/** Model name */
|
|
59
|
+
model?: string;
|
|
60
|
+
/** System prompt */
|
|
61
|
+
system?: string;
|
|
62
|
+
/** Temperature setting */
|
|
63
|
+
temperature?: number;
|
|
64
|
+
/** Maximum tokens */
|
|
65
|
+
maxTokens?: number;
|
|
66
|
+
/** Disable tools */
|
|
67
|
+
disableTools?: boolean;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* MCP command arguments
|
|
71
|
+
*/
|
|
72
|
+
export interface MCPCommandArgs extends BaseCommandArgs {
|
|
73
|
+
/** MCP server name */
|
|
74
|
+
server?: string;
|
|
75
|
+
/** Tool name to execute */
|
|
76
|
+
tool?: string;
|
|
77
|
+
/** Tool parameters as JSON string */
|
|
78
|
+
params?: string;
|
|
79
|
+
/** List available tools */
|
|
80
|
+
list?: boolean;
|
|
81
|
+
/** Discover MCP servers */
|
|
82
|
+
discover?: boolean;
|
|
83
|
+
/** Show server information */
|
|
84
|
+
info?: boolean;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Ollama command arguments
|
|
88
|
+
*/
|
|
89
|
+
export interface OllamaCommandArgs extends BaseCommandArgs {
|
|
90
|
+
/** Ollama model name */
|
|
91
|
+
model?: string;
|
|
92
|
+
/** List available models */
|
|
93
|
+
list?: boolean;
|
|
94
|
+
/** Pull a model */
|
|
95
|
+
pull?: boolean;
|
|
96
|
+
/** Remove a model */
|
|
97
|
+
remove?: boolean;
|
|
98
|
+
/** Show model information */
|
|
99
|
+
show?: boolean;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Provider status command arguments
|
|
103
|
+
*/
|
|
104
|
+
export interface ProviderStatusArgs extends BaseCommandArgs {
|
|
105
|
+
/** Specific provider to check */
|
|
106
|
+
provider?: string;
|
|
107
|
+
/** Check all providers */
|
|
108
|
+
all?: boolean;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* CLI command result
|
|
112
|
+
*/
|
|
113
|
+
export interface CommandResult {
|
|
114
|
+
/** Command success status */
|
|
115
|
+
success: boolean;
|
|
116
|
+
/** Result data */
|
|
117
|
+
data?: unknown;
|
|
118
|
+
/** Error message if failed */
|
|
119
|
+
error?: string;
|
|
120
|
+
/** Output content */
|
|
121
|
+
content?: string;
|
|
122
|
+
/** Execution metadata */
|
|
123
|
+
metadata?: {
|
|
124
|
+
executionTime?: number;
|
|
125
|
+
timestamp?: number;
|
|
126
|
+
command?: string;
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Generate command result
|
|
131
|
+
*/
|
|
132
|
+
export interface GenerateResult extends CommandResult {
|
|
133
|
+
content: string;
|
|
134
|
+
provider?: string;
|
|
135
|
+
model?: string;
|
|
136
|
+
usage?: TokenUsage;
|
|
137
|
+
responseTime?: number;
|
|
138
|
+
toolCalls?: ToolCall[];
|
|
139
|
+
toolResults?: ToolResult[];
|
|
140
|
+
analytics?: AnalyticsData;
|
|
141
|
+
evaluation?: EvaluationData;
|
|
142
|
+
toolsUsed?: string[];
|
|
143
|
+
toolExecutions?: Array<{
|
|
144
|
+
toolName: string;
|
|
145
|
+
args: UnknownRecord;
|
|
146
|
+
result: unknown;
|
|
147
|
+
executionTime: number;
|
|
148
|
+
}>;
|
|
149
|
+
enhancedWithTools?: boolean;
|
|
150
|
+
availableTools?: Array<{
|
|
151
|
+
name: string;
|
|
152
|
+
description: string;
|
|
153
|
+
}>;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Stream result chunk
|
|
157
|
+
*/
|
|
158
|
+
export interface StreamChunk {
|
|
159
|
+
content?: string;
|
|
160
|
+
delta?: string;
|
|
161
|
+
done?: boolean;
|
|
162
|
+
metadata?: UnknownRecord;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* CLI output formatting options
|
|
166
|
+
*/
|
|
167
|
+
export interface OutputOptions {
|
|
168
|
+
format: "text" | "json" | "table";
|
|
169
|
+
pretty?: boolean;
|
|
170
|
+
color?: boolean;
|
|
171
|
+
compact?: boolean;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Command handler function type
|
|
175
|
+
*/
|
|
176
|
+
export type CommandHandler<TArgs = BaseCommandArgs, TResult = CommandResult> = (args: TArgs) => Promise<TResult>;
|
|
177
|
+
/**
|
|
178
|
+
* Command definition
|
|
179
|
+
*/
|
|
180
|
+
export interface CommandDefinition<TArgs = BaseCommandArgs> {
|
|
181
|
+
name: string;
|
|
182
|
+
description: string;
|
|
183
|
+
aliases?: string[];
|
|
184
|
+
args?: {
|
|
185
|
+
[K in keyof TArgs]: {
|
|
186
|
+
type: "string" | "number" | "boolean";
|
|
187
|
+
description: string;
|
|
188
|
+
required?: boolean;
|
|
189
|
+
default?: TArgs[K];
|
|
190
|
+
};
|
|
191
|
+
};
|
|
192
|
+
handler: CommandHandler<TArgs>;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* CLI context
|
|
196
|
+
*/
|
|
197
|
+
export interface CLIContext {
|
|
198
|
+
cwd: string;
|
|
199
|
+
args: string[];
|
|
200
|
+
env: NodeJS.ProcessEnv;
|
|
201
|
+
exitCode?: number;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Color mapping for CLI output
|
|
205
|
+
*/
|
|
206
|
+
export interface ColorMap {
|
|
207
|
+
[severity: string]: {
|
|
208
|
+
color: string;
|
|
209
|
+
symbol?: string;
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Display severity colors (for evaluation display)
|
|
214
|
+
*/
|
|
215
|
+
export interface SeverityColors {
|
|
216
|
+
[key: string]: {
|
|
217
|
+
color: string;
|
|
218
|
+
symbol: string;
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* JSON output structure
|
|
223
|
+
*/
|
|
224
|
+
export interface JSONOutput {
|
|
225
|
+
success: boolean;
|
|
226
|
+
data?: JsonValue;
|
|
227
|
+
error?: string;
|
|
228
|
+
metadata?: {
|
|
229
|
+
timestamp: number;
|
|
230
|
+
command: string;
|
|
231
|
+
version?: string;
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Console override for quiet mode
|
|
236
|
+
*/
|
|
237
|
+
export interface ConsoleOverride {
|
|
238
|
+
[method: string]: (() => void) | undefined;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Type guard for generate result
|
|
242
|
+
*/
|
|
243
|
+
export declare function isGenerateResult(value: unknown): value is GenerateResult;
|
|
244
|
+
/**
|
|
245
|
+
* Type guard for command result
|
|
246
|
+
*/
|
|
247
|
+
export declare function isCommandResult(value: unknown): value is CommandResult;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI-specific type definitions for NeuroLink
|
|
3
|
+
* Replaces 'any' types in CLI commands and arguments
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Type guard for generate result
|
|
7
|
+
*/
|
|
8
|
+
export function isGenerateResult(value) {
|
|
9
|
+
return (typeof value === "object" &&
|
|
10
|
+
value !== null &&
|
|
11
|
+
"content" in value &&
|
|
12
|
+
typeof value.content === "string");
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Type guard for command result
|
|
16
|
+
*/
|
|
17
|
+
export function isCommandResult(value) {
|
|
18
|
+
return (typeof value === "object" &&
|
|
19
|
+
value !== null &&
|
|
20
|
+
"success" in value &&
|
|
21
|
+
typeof value.success === "boolean");
|
|
22
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Common utility types for NeuroLink
|
|
3
|
+
* These types provide type-safe alternatives to 'any' usage
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Type-safe unknown value - use instead of 'any' when type is truly unknown
|
|
7
|
+
*/
|
|
8
|
+
export type Unknown = unknown;
|
|
9
|
+
/**
|
|
10
|
+
* Type-safe record for metadata and configuration objects
|
|
11
|
+
*/
|
|
12
|
+
export type UnknownRecord = Record<string, unknown>;
|
|
13
|
+
/**
|
|
14
|
+
* Type-safe array of unknown items
|
|
15
|
+
*/
|
|
16
|
+
export type UnknownArray = unknown[];
|
|
17
|
+
/**
|
|
18
|
+
* JSON-serializable value type
|
|
19
|
+
*/
|
|
20
|
+
export type JsonValue = string | number | boolean | null | JsonObject | JsonArray;
|
|
21
|
+
export interface JsonObject {
|
|
22
|
+
[key: string]: JsonValue;
|
|
23
|
+
}
|
|
24
|
+
export interface JsonArray extends Array<JsonValue> {
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Type-safe error handling
|
|
28
|
+
*/
|
|
29
|
+
export interface ErrorInfo {
|
|
30
|
+
message: string;
|
|
31
|
+
code?: string | number;
|
|
32
|
+
stack?: string;
|
|
33
|
+
cause?: unknown;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Generic success/error result type
|
|
37
|
+
*/
|
|
38
|
+
export interface Result<T = unknown, E = ErrorInfo> {
|
|
39
|
+
success: boolean;
|
|
40
|
+
data?: T;
|
|
41
|
+
error?: E;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Function parameter type for dynamic functions
|
|
45
|
+
*/
|
|
46
|
+
export interface FunctionParameters {
|
|
47
|
+
[key: string]: unknown;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Generic async function type
|
|
51
|
+
*/
|
|
52
|
+
export type AsyncFunction<TParams = FunctionParameters, TResult = unknown> = (params: TParams) => Promise<TResult>;
|
|
53
|
+
/**
|
|
54
|
+
* Sync function type
|
|
55
|
+
*/
|
|
56
|
+
export type SyncFunction<TParams = FunctionParameters, TResult = unknown> = (params: TParams) => TResult;
|
|
57
|
+
/**
|
|
58
|
+
* Union of async and sync functions
|
|
59
|
+
*/
|
|
60
|
+
export type AnyFunction<TParams = FunctionParameters, TResult = unknown> = AsyncFunction<TParams, TResult> | SyncFunction<TParams, TResult>;
|
|
61
|
+
/**
|
|
62
|
+
* Type guard to check if value is Error
|
|
63
|
+
*/
|
|
64
|
+
export declare function isError(value: unknown): value is Error;
|
|
65
|
+
/**
|
|
66
|
+
* Type guard to check if value is ErrorInfo
|
|
67
|
+
*/
|
|
68
|
+
export declare function isErrorInfo(value: unknown): value is ErrorInfo;
|
|
69
|
+
/**
|
|
70
|
+
* Safe error message extraction
|
|
71
|
+
*/
|
|
72
|
+
export declare function getErrorMessage(error: unknown): string;
|
|
73
|
+
/**
|
|
74
|
+
* Safe error conversion
|
|
75
|
+
*/
|
|
76
|
+
export declare function toErrorInfo(error: unknown): ErrorInfo;
|