@juspay/neurolink 6.1.0 → 6.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -6
- package/dist/agent/direct-tools.js +6 -5
- package/dist/cli/commands/config.d.ts +13 -13
- package/dist/cli/index.js +3 -9
- package/dist/config/configManager.js +11 -10
- package/dist/core/analytics.d.ts +11 -1
- package/dist/core/analytics.js +2 -2
- package/dist/core/base-provider.js +4 -18
- package/dist/core/dynamic-models.d.ts +8 -8
- package/dist/core/factory.js +3 -11
- package/dist/index.d.ts +2 -4
- package/dist/index.js +2 -11
- package/dist/lib/agent/direct-tools.js +6 -5
- package/dist/lib/config/configManager.js +11 -10
- package/dist/lib/core/analytics.d.ts +11 -1
- package/dist/lib/core/analytics.js +2 -2
- package/dist/lib/core/base-provider.js +4 -18
- package/dist/lib/core/dynamic-models.d.ts +8 -8
- package/dist/lib/core/factory.js +3 -11
- package/dist/lib/index.d.ts +2 -4
- package/dist/lib/index.js +2 -11
- package/dist/lib/mcp/factory.d.ts +1 -1
- package/dist/lib/mcp/index.d.ts +9 -21
- package/dist/lib/mcp/index.js +16 -57
- package/dist/lib/mcp/registry.js +1 -1
- package/dist/lib/mcp/servers/ai-providers/ai-analysis-tools.js +2 -1
- package/dist/lib/mcp/tool-registry.js +1 -1
- package/dist/lib/neurolink.d.ts +1 -9
- package/dist/lib/neurolink.js +22 -71
- package/dist/lib/providers/amazon-bedrock.js +5 -16
- package/dist/lib/providers/anthropic-baseprovider.js +3 -21
- package/dist/lib/providers/anthropic.js +4 -7
- package/dist/lib/providers/azure-openai.js +6 -3
- package/dist/lib/providers/google-vertex.js +5 -9
- package/dist/lib/providers/huggingFace.js +5 -10
- package/dist/lib/providers/mistral.js +5 -8
- package/dist/lib/providers/openAI.js +4 -7
- package/dist/lib/telemetry/index.js +2 -1
- package/dist/lib/utils/logger.d.ts +62 -2
- package/dist/lib/utils/logger.js +174 -9
- package/dist/lib/utils/providerConfig.d.ts +117 -0
- package/dist/lib/utils/providerConfig.js +353 -0
- package/dist/lib/utils/providerUtils.d.ts +2 -1
- package/dist/lib/utils/providerUtils.js +53 -36
- package/dist/lib/utils/timeout.d.ts +72 -1
- package/dist/lib/utils/timeout.js +203 -2
- package/dist/mcp/factory.d.ts +1 -1
- package/dist/mcp/index.d.ts +9 -21
- package/dist/mcp/index.js +16 -57
- package/dist/mcp/registry.js +1 -1
- package/dist/mcp/servers/ai-providers/ai-analysis-tools.js +2 -1
- package/dist/mcp/tool-registry.js +1 -1
- package/dist/neurolink.d.ts +1 -9
- package/dist/neurolink.js +22 -71
- package/dist/providers/amazon-bedrock.js +5 -16
- package/dist/providers/anthropic-baseprovider.js +3 -21
- package/dist/providers/anthropic.js +4 -7
- package/dist/providers/azure-openai.js +6 -3
- package/dist/providers/google-vertex.js +5 -9
- package/dist/providers/huggingFace.js +5 -10
- package/dist/providers/mistral.js +5 -8
- package/dist/providers/openAI.js +4 -7
- package/dist/telemetry/index.js +2 -1
- package/dist/utils/logger.d.ts +62 -2
- package/dist/utils/logger.js +174 -9
- package/dist/utils/providerConfig.d.ts +117 -0
- package/dist/utils/providerConfig.js +353 -0
- package/dist/utils/providerUtils.d.ts +2 -1
- package/dist/utils/providerUtils.js +53 -36
- package/dist/utils/timeout.d.ts +72 -1
- package/dist/utils/timeout.js +203 -2
- package/package.json +1 -1
- package/dist/chat/client-utils.d.ts +0 -95
- package/dist/chat/client-utils.js +0 -315
- package/dist/chat/index.d.ts +0 -24
- package/dist/chat/index.js +0 -33
- package/dist/chat/session-storage.d.ts +0 -77
- package/dist/chat/session-storage.js +0 -233
- package/dist/chat/session.d.ts +0 -96
- package/dist/chat/session.js +0 -257
- package/dist/chat/sse-handler.d.ts +0 -49
- package/dist/chat/sse-handler.js +0 -259
- package/dist/chat/types.d.ts +0 -74
- package/dist/chat/types.js +0 -5
- package/dist/chat/websocket-chat-handler.d.ts +0 -37
- package/dist/chat/websocket-chat-handler.js +0 -262
- package/dist/cli/commands/mcp.d.ts +0 -20
- package/dist/cli/commands/mcp.js +0 -1272
- package/dist/core/defaults.d.ts +0 -19
- package/dist/core/defaults.js +0 -29
- package/dist/core/evaluation-config.d.ts +0 -29
- package/dist/core/evaluation-config.js +0 -144
- package/dist/factories/compatibility-factory.d.ts +0 -35
- package/dist/factories/compatibility-factory.js +0 -71
- package/dist/factories/provider-generate-factory.d.ts +0 -20
- package/dist/factories/provider-generate-factory.js +0 -93
- package/dist/lib/chat/client-utils.d.ts +0 -95
- package/dist/lib/chat/client-utils.js +0 -315
- package/dist/lib/chat/index.d.ts +0 -24
- package/dist/lib/chat/index.js +0 -33
- package/dist/lib/chat/session-storage.d.ts +0 -77
- package/dist/lib/chat/session-storage.js +0 -233
- package/dist/lib/chat/session.d.ts +0 -96
- package/dist/lib/chat/session.js +0 -257
- package/dist/lib/chat/sse-handler.d.ts +0 -49
- package/dist/lib/chat/sse-handler.js +0 -259
- package/dist/lib/chat/types.d.ts +0 -74
- package/dist/lib/chat/types.js +0 -5
- package/dist/lib/chat/websocket-chat-handler.d.ts +0 -37
- package/dist/lib/chat/websocket-chat-handler.js +0 -262
- package/dist/lib/core/defaults.d.ts +0 -19
- package/dist/lib/core/defaults.js +0 -29
- package/dist/lib/core/evaluation-config.d.ts +0 -29
- package/dist/lib/core/evaluation-config.js +0 -144
- package/dist/lib/factories/compatibility-factory.d.ts +0 -35
- package/dist/lib/factories/compatibility-factory.js +0 -71
- package/dist/lib/factories/provider-generate-factory.d.ts +0 -20
- package/dist/lib/factories/provider-generate-factory.js +0 -93
- package/dist/lib/mcp/adapters/plugin-bridge.d.ts +0 -40
- package/dist/lib/mcp/adapters/plugin-bridge.js +0 -89
- package/dist/lib/mcp/auto-discovery.d.ts +0 -62
- package/dist/lib/mcp/auto-discovery.js +0 -149
- package/dist/lib/mcp/client.d.ts +0 -68
- package/dist/lib/mcp/client.js +0 -248
- package/dist/lib/mcp/config.d.ts +0 -31
- package/dist/lib/mcp/config.js +0 -99
- package/dist/lib/mcp/context-manager.d.ts +0 -171
- package/dist/lib/mcp/context-manager.js +0 -362
- package/dist/lib/mcp/contracts/mcp-contract.d.ts +0 -169
- package/dist/lib/mcp/contracts/mcp-contract.js +0 -58
- package/dist/lib/mcp/core/plugin-manager.d.ts +0 -46
- package/dist/lib/mcp/core/plugin-manager.js +0 -110
- package/dist/lib/mcp/demo/plugin-demo.d.ts +0 -20
- package/dist/lib/mcp/demo/plugin-demo.js +0 -118
- package/dist/lib/mcp/dynamic-chain-executor.d.ts +0 -225
- package/dist/lib/mcp/dynamic-chain-executor.js +0 -489
- package/dist/lib/mcp/dynamic-orchestrator.d.ts +0 -115
- package/dist/lib/mcp/dynamic-orchestrator.js +0 -351
- package/dist/lib/mcp/ecosystem.d.ts +0 -75
- package/dist/lib/mcp/ecosystem.js +0 -161
- package/dist/lib/mcp/error-manager.d.ts +0 -254
- package/dist/lib/mcp/error-manager.js +0 -501
- package/dist/lib/mcp/error-recovery.d.ts +0 -159
- package/dist/lib/mcp/error-recovery.js +0 -405
- package/dist/lib/mcp/external-client.d.ts +0 -88
- package/dist/lib/mcp/external-client.js +0 -331
- package/dist/lib/mcp/external-manager.d.ts +0 -112
- package/dist/lib/mcp/external-manager.js +0 -308
- package/dist/lib/mcp/function-calling.d.ts +0 -65
- package/dist/lib/mcp/function-calling.js +0 -642
- package/dist/lib/mcp/health-monitor.d.ts +0 -257
- package/dist/lib/mcp/health-monitor.js +0 -630
- package/dist/lib/mcp/initialize-tools.d.ts +0 -29
- package/dist/lib/mcp/initialize-tools.js +0 -261
- package/dist/lib/mcp/initialize.d.ts +0 -18
- package/dist/lib/mcp/initialize.js +0 -62
- package/dist/lib/mcp/logging.d.ts +0 -38
- package/dist/lib/mcp/logging.js +0 -100
- package/dist/lib/mcp/manager.d.ts +0 -68
- package/dist/lib/mcp/manager.js +0 -176
- package/dist/lib/mcp/neurolink-mcp-client.d.ts +0 -97
- package/dist/lib/mcp/neurolink-mcp-client.js +0 -462
- package/dist/lib/mcp/orchestrator.d.ts +0 -302
- package/dist/lib/mcp/orchestrator.js +0 -703
- package/dist/lib/mcp/plugin-manager.d.ts +0 -98
- package/dist/lib/mcp/plugin-manager.js +0 -296
- package/dist/lib/mcp/plugins/core/filesystem-mcp.d.ts +0 -36
- package/dist/lib/mcp/plugins/core/filesystem-mcp.js +0 -142
- package/dist/lib/mcp/plugins/filesystem-mcp.d.ts +0 -37
- package/dist/lib/mcp/plugins/filesystem-mcp.js +0 -54
- package/dist/lib/mcp/security-manager.d.ts +0 -87
- package/dist/lib/mcp/security-manager.js +0 -344
- package/dist/lib/mcp/semaphore-manager.d.ts +0 -137
- package/dist/lib/mcp/semaphore-manager.js +0 -329
- package/dist/lib/mcp/session-manager.d.ts +0 -187
- package/dist/lib/mcp/session-manager.js +0 -400
- package/dist/lib/mcp/session-persistence.d.ts +0 -93
- package/dist/lib/mcp/session-persistence.js +0 -301
- package/dist/lib/mcp/tool-integration.d.ts +0 -58
- package/dist/lib/mcp/tool-integration.js +0 -203
- package/dist/lib/mcp/transport-manager.d.ts +0 -154
- package/dist/lib/mcp/transport-manager.js +0 -334
- package/dist/lib/mcp/unified-mcp.d.ts +0 -133
- package/dist/lib/mcp/unified-mcp.js +0 -251
- package/dist/lib/mcp/unified-registry.d.ts +0 -165
- package/dist/lib/mcp/unified-registry.js +0 -538
- package/dist/lib/providers/analytics-helper.d.ts +0 -38
- package/dist/lib/providers/analytics-helper.js +0 -216
- package/dist/lib/providers/function-calling-provider.d.ts +0 -142
- package/dist/lib/providers/function-calling-provider.js +0 -630
- package/dist/lib/providers/mcp-provider.d.ts +0 -75
- package/dist/lib/providers/mcp-provider.js +0 -283
- package/dist/lib/providers/timeout-wrapper.d.ts +0 -40
- package/dist/lib/providers/timeout-wrapper.js +0 -100
- package/dist/lib/sdk/tool-extension.d.ts +0 -181
- package/dist/lib/sdk/tool-extension.js +0 -284
- package/dist/lib/services/streaming/streaming-manager.d.ts +0 -29
- package/dist/lib/services/streaming/streaming-manager.js +0 -245
- package/dist/lib/services/types.d.ts +0 -156
- package/dist/lib/services/types.js +0 -2
- package/dist/lib/services/websocket/websocket-server.d.ts +0 -34
- package/dist/lib/services/websocket/websocket-server.js +0 -305
- package/dist/lib/utils/provider-validation.d.ts +0 -36
- package/dist/lib/utils/provider-validation.js +0 -625
- package/dist/lib/utils/providerUtils-fixed.d.ts +0 -8
- package/dist/lib/utils/providerUtils-fixed.js +0 -94
- package/dist/lib/utils/streaming-utils.d.ts +0 -79
- package/dist/lib/utils/streaming-utils.js +0 -198
- package/dist/lib/utils/timeout-manager.d.ts +0 -75
- package/dist/lib/utils/timeout-manager.js +0 -244
- package/dist/mcp/adapters/plugin-bridge.d.ts +0 -40
- package/dist/mcp/adapters/plugin-bridge.js +0 -89
- package/dist/mcp/auto-discovery.d.ts +0 -62
- package/dist/mcp/auto-discovery.js +0 -149
- package/dist/mcp/client.d.ts +0 -68
- package/dist/mcp/client.js +0 -248
- package/dist/mcp/config.d.ts +0 -31
- package/dist/mcp/config.js +0 -99
- package/dist/mcp/context-manager.d.ts +0 -171
- package/dist/mcp/context-manager.js +0 -362
- package/dist/mcp/contracts/mcp-contract.d.ts +0 -169
- package/dist/mcp/contracts/mcp-contract.js +0 -58
- package/dist/mcp/core/plugin-manager.d.ts +0 -46
- package/dist/mcp/core/plugin-manager.js +0 -110
- package/dist/mcp/demo/plugin-demo.d.ts +0 -20
- package/dist/mcp/demo/plugin-demo.js +0 -118
- package/dist/mcp/dynamic-chain-executor.d.ts +0 -225
- package/dist/mcp/dynamic-chain-executor.js +0 -489
- package/dist/mcp/dynamic-orchestrator.d.ts +0 -115
- package/dist/mcp/dynamic-orchestrator.js +0 -351
- package/dist/mcp/ecosystem.d.ts +0 -75
- package/dist/mcp/ecosystem.js +0 -162
- package/dist/mcp/error-manager.d.ts +0 -254
- package/dist/mcp/error-manager.js +0 -501
- package/dist/mcp/error-recovery.d.ts +0 -159
- package/dist/mcp/error-recovery.js +0 -405
- package/dist/mcp/external-client.d.ts +0 -88
- package/dist/mcp/external-client.js +0 -331
- package/dist/mcp/external-manager.d.ts +0 -112
- package/dist/mcp/external-manager.js +0 -308
- package/dist/mcp/function-calling.d.ts +0 -65
- package/dist/mcp/function-calling.js +0 -642
- package/dist/mcp/health-monitor.d.ts +0 -257
- package/dist/mcp/health-monitor.js +0 -630
- package/dist/mcp/initialize-tools.d.ts +0 -29
- package/dist/mcp/initialize-tools.js +0 -262
- package/dist/mcp/initialize.d.ts +0 -18
- package/dist/mcp/initialize.js +0 -62
- package/dist/mcp/logging.d.ts +0 -38
- package/dist/mcp/logging.js +0 -100
- package/dist/mcp/manager.d.ts +0 -68
- package/dist/mcp/manager.js +0 -176
- package/dist/mcp/neurolink-mcp-client.d.ts +0 -97
- package/dist/mcp/neurolink-mcp-client.js +0 -462
- package/dist/mcp/orchestrator.d.ts +0 -302
- package/dist/mcp/orchestrator.js +0 -703
- package/dist/mcp/plugin-manager.d.ts +0 -98
- package/dist/mcp/plugin-manager.js +0 -297
- package/dist/mcp/plugins/core/filesystem-mcp.d.ts +0 -36
- package/dist/mcp/plugins/core/filesystem-mcp.js +0 -142
- package/dist/mcp/plugins/core/neurolink-mcp.json +0 -17
- package/dist/mcp/plugins/filesystem-mcp.d.ts +0 -37
- package/dist/mcp/plugins/filesystem-mcp.js +0 -54
- package/dist/mcp/security-manager.d.ts +0 -87
- package/dist/mcp/security-manager.js +0 -344
- package/dist/mcp/semaphore-manager.d.ts +0 -137
- package/dist/mcp/semaphore-manager.js +0 -329
- package/dist/mcp/session-manager.d.ts +0 -187
- package/dist/mcp/session-manager.js +0 -400
- package/dist/mcp/session-persistence.d.ts +0 -93
- package/dist/mcp/session-persistence.js +0 -302
- package/dist/mcp/tool-integration.d.ts +0 -58
- package/dist/mcp/tool-integration.js +0 -203
- package/dist/mcp/transport-manager.d.ts +0 -154
- package/dist/mcp/transport-manager.js +0 -335
- package/dist/mcp/unified-mcp.d.ts +0 -133
- package/dist/mcp/unified-mcp.js +0 -251
- package/dist/mcp/unified-registry.d.ts +0 -165
- package/dist/mcp/unified-registry.js +0 -539
- package/dist/providers/analytics-helper.d.ts +0 -38
- package/dist/providers/analytics-helper.js +0 -216
- package/dist/providers/function-calling-provider.d.ts +0 -142
- package/dist/providers/function-calling-provider.js +0 -630
- package/dist/providers/mcp-provider.d.ts +0 -75
- package/dist/providers/mcp-provider.js +0 -283
- package/dist/providers/timeout-wrapper.d.ts +0 -40
- package/dist/providers/timeout-wrapper.js +0 -100
- package/dist/sdk/tool-extension.d.ts +0 -181
- package/dist/sdk/tool-extension.js +0 -284
- package/dist/services/streaming/streaming-manager.d.ts +0 -29
- package/dist/services/streaming/streaming-manager.js +0 -245
- package/dist/services/types.d.ts +0 -156
- package/dist/services/types.js +0 -2
- package/dist/services/websocket/websocket-server.d.ts +0 -34
- package/dist/services/websocket/websocket-server.js +0 -306
- package/dist/utils/provider-validation.d.ts +0 -36
- package/dist/utils/provider-validation.js +0 -625
- package/dist/utils/providerUtils-fixed.d.ts +0 -8
- package/dist/utils/providerUtils-fixed.js +0 -94
- package/dist/utils/streaming-utils.d.ts +0 -79
- package/dist/utils/streaming-utils.js +0 -198
- package/dist/utils/timeout-manager.d.ts +0 -75
- package/dist/utils/timeout-manager.js +0 -244
package/dist/lib/chat/types.d.ts
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Phase 3: SSE Chat Utilities
|
|
3
|
-
* Type definitions for chat infrastructure
|
|
4
|
-
*/
|
|
5
|
-
import type { JsonValue } from "../types/common.js";
|
|
6
|
-
export interface ChatMessage {
|
|
7
|
-
id: string;
|
|
8
|
-
role: "user" | "assistant" | "system";
|
|
9
|
-
content: string;
|
|
10
|
-
timestamp: number;
|
|
11
|
-
metadata?: {
|
|
12
|
-
provider?: string;
|
|
13
|
-
model?: string;
|
|
14
|
-
tokens?: number;
|
|
15
|
-
duration?: number;
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
export interface ChatRequest {
|
|
19
|
-
sessionId: string;
|
|
20
|
-
message: string;
|
|
21
|
-
role?: "user";
|
|
22
|
-
options?: {
|
|
23
|
-
temperature?: number;
|
|
24
|
-
maxTokens?: number;
|
|
25
|
-
systemPrompt?: string;
|
|
26
|
-
streamResponse?: boolean;
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
export interface SSEOptions {
|
|
30
|
-
maxConnections?: number;
|
|
31
|
-
heartbeatInterval?: number;
|
|
32
|
-
connectionTimeout?: number;
|
|
33
|
-
enableCors?: boolean;
|
|
34
|
-
corsOrigins?: string[];
|
|
35
|
-
}
|
|
36
|
-
export interface SessionOptions {
|
|
37
|
-
maxHistory?: number;
|
|
38
|
-
persistenceAdapter?: "memory" | "redis" | "file";
|
|
39
|
-
contextWindowSize?: number;
|
|
40
|
-
autoSave?: boolean;
|
|
41
|
-
ttl?: number;
|
|
42
|
-
}
|
|
43
|
-
export interface SSEEvent {
|
|
44
|
-
type: "data" | "error" | "progress" | "complete" | "heartbeat";
|
|
45
|
-
data: JsonValue;
|
|
46
|
-
id?: string;
|
|
47
|
-
retry?: number;
|
|
48
|
-
}
|
|
49
|
-
export interface ChatSessionState {
|
|
50
|
-
id: string;
|
|
51
|
-
messages: ChatMessage[];
|
|
52
|
-
createdAt: number;
|
|
53
|
-
lastActivity: number;
|
|
54
|
-
metadata?: Record<string, JsonValue>;
|
|
55
|
-
}
|
|
56
|
-
export interface StreamingChatResponse {
|
|
57
|
-
sessionId: string;
|
|
58
|
-
messageId: string;
|
|
59
|
-
stream: ReadableStream;
|
|
60
|
-
response: Response;
|
|
61
|
-
}
|
|
62
|
-
export interface SessionStorage {
|
|
63
|
-
get(sessionId: string): Promise<ChatSessionState | null>;
|
|
64
|
-
set(sessionId: string, state: ChatSessionState): Promise<void>;
|
|
65
|
-
delete(sessionId: string): Promise<void>;
|
|
66
|
-
list(): Promise<string[]>;
|
|
67
|
-
cleanup(maxAge: number): Promise<number>;
|
|
68
|
-
}
|
|
69
|
-
export interface ContextManager {
|
|
70
|
-
addMessage(sessionId: string, message: ChatMessage): Promise<void>;
|
|
71
|
-
getHistory(sessionId: string, limit?: number): Promise<ChatMessage[]>;
|
|
72
|
-
trimContext(sessionId: string, maxTokens: number): Promise<number>;
|
|
73
|
-
estimateTokens(messages: ChatMessage[]): number;
|
|
74
|
-
}
|
package/dist/lib/chat/types.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { SSEChatHandler } from "./sse-handler.js";
|
|
2
|
-
import type { AIProvider } from "../core/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";
|
|
6
|
-
export interface WebSocketChatOptions {
|
|
7
|
-
sseOptions?: UnknownRecord;
|
|
8
|
-
wsOptions?: WebSocketOptions;
|
|
9
|
-
enableTypingIndicators?: boolean;
|
|
10
|
-
enablePresenceTracking?: boolean;
|
|
11
|
-
enableMessageSync?: boolean;
|
|
12
|
-
}
|
|
13
|
-
export declare class WebSocketChatHandler extends SSEChatHandler {
|
|
14
|
-
private wsServer;
|
|
15
|
-
private streamingManager;
|
|
16
|
-
protected options: WebSocketChatOptions & Required<SSEOptions>;
|
|
17
|
-
private typingIndicators;
|
|
18
|
-
private presenceTracking;
|
|
19
|
-
constructor(provider: AIProvider, options?: WebSocketChatOptions);
|
|
20
|
-
private setupWebSocketHandlers;
|
|
21
|
-
handleWebSocketChatRequest(connectionId: string, request: ChatRequest): Promise<void>;
|
|
22
|
-
handleGroupChat(roomId: string, request: GroupChatRequest): Promise<void>;
|
|
23
|
-
handleStreamingChat(connectionId: string, request: StreamingChatRequest): Promise<void>;
|
|
24
|
-
enableTypingIndicators(roomId: string): Promise<void>;
|
|
25
|
-
enablePresenceTracking(roomId: string): Promise<void>;
|
|
26
|
-
enableMessageSynchronization(roomId: string): Promise<void>;
|
|
27
|
-
private sendToConnection;
|
|
28
|
-
private sendError;
|
|
29
|
-
private showTypingIndicator;
|
|
30
|
-
private clearTypingIndicator;
|
|
31
|
-
private updatePresence;
|
|
32
|
-
private handleWebSocketChatMessage;
|
|
33
|
-
getConnectionCount(): number;
|
|
34
|
-
getRoomCount(): number;
|
|
35
|
-
getStreamingMetrics(): import("../services/types.js").StreamingMetrics;
|
|
36
|
-
close(): void;
|
|
37
|
-
}
|
|
@@ -1,262 +0,0 @@
|
|
|
1
|
-
import { SSEChatHandler } from "./sse-handler.js";
|
|
2
|
-
import { NeuroLinkWebSocketServer } from "../services/websocket/websocket-server.js";
|
|
3
|
-
import { StreamingManager } from "../services/streaming/streaming-manager.js";
|
|
4
|
-
import { randomUUID } from "crypto";
|
|
5
|
-
export class WebSocketChatHandler extends SSEChatHandler {
|
|
6
|
-
wsServer;
|
|
7
|
-
streamingManager;
|
|
8
|
-
options;
|
|
9
|
-
typingIndicators = new Map();
|
|
10
|
-
presenceTracking = new Map();
|
|
11
|
-
constructor(provider, options = {}) {
|
|
12
|
-
super(provider, options.sseOptions);
|
|
13
|
-
this.options = {
|
|
14
|
-
enableTypingIndicators: true,
|
|
15
|
-
enablePresenceTracking: true,
|
|
16
|
-
enableMessageSync: true,
|
|
17
|
-
maxConnections: 100,
|
|
18
|
-
heartbeatInterval: 30000,
|
|
19
|
-
connectionTimeout: 300000,
|
|
20
|
-
enableCors: true,
|
|
21
|
-
corsOrigins: ["*"],
|
|
22
|
-
...options,
|
|
23
|
-
};
|
|
24
|
-
this.wsServer = new NeuroLinkWebSocketServer(options.wsOptions);
|
|
25
|
-
this.streamingManager = new StreamingManager();
|
|
26
|
-
this.setupWebSocketHandlers();
|
|
27
|
-
}
|
|
28
|
-
setupWebSocketHandlers() {
|
|
29
|
-
this.wsServer.on("connection", ({ connectionId }) => {
|
|
30
|
-
console.log(`[WebSocket Chat] New connection: ${connectionId}`);
|
|
31
|
-
if (this.options.enablePresenceTracking) {
|
|
32
|
-
this.updatePresence(connectionId, "online");
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
this.wsServer.on("disconnection", ({ connectionId }) => {
|
|
36
|
-
console.log(`[WebSocket Chat] Disconnection: ${connectionId}`);
|
|
37
|
-
if (this.options.enablePresenceTracking) {
|
|
38
|
-
this.updatePresence(connectionId, "offline");
|
|
39
|
-
}
|
|
40
|
-
this.clearTypingIndicator(connectionId);
|
|
41
|
-
});
|
|
42
|
-
this.wsServer.on("chat-message", ({ connectionId, message }) => {
|
|
43
|
-
this.handleWebSocketChatMessage(connectionId, message);
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
// Enhanced Chat Capabilities
|
|
47
|
-
async handleWebSocketChatRequest(connectionId, request) {
|
|
48
|
-
try {
|
|
49
|
-
if (this.options.enableTypingIndicators) {
|
|
50
|
-
this.showTypingIndicator(connectionId, "assistant");
|
|
51
|
-
}
|
|
52
|
-
// Create streaming session for this chat
|
|
53
|
-
const streamingSession = await this.streamingManager.createStreamingSession({
|
|
54
|
-
provider: this.provider.constructor.name,
|
|
55
|
-
model: "default", // Should get from provider
|
|
56
|
-
streamingMode: "real-time",
|
|
57
|
-
compressionEnabled: true,
|
|
58
|
-
maxChunkSize: 1024,
|
|
59
|
-
bufferSize: 4096,
|
|
60
|
-
latencyTarget: 200,
|
|
61
|
-
});
|
|
62
|
-
// Generate AI response
|
|
63
|
-
const result = await this.provider.generate({
|
|
64
|
-
prompt: request.message,
|
|
65
|
-
temperature: request.options?.temperature,
|
|
66
|
-
maxTokens: request.options?.maxTokens,
|
|
67
|
-
});
|
|
68
|
-
if (!result || !result.content) {
|
|
69
|
-
throw new Error("Invalid AI response");
|
|
70
|
-
}
|
|
71
|
-
// Send response via WebSocket
|
|
72
|
-
const responseMessage = {
|
|
73
|
-
id: randomUUID(),
|
|
74
|
-
type: "ai-response",
|
|
75
|
-
connectionId,
|
|
76
|
-
timestamp: Date.now(),
|
|
77
|
-
data: {
|
|
78
|
-
text: result.content,
|
|
79
|
-
sessionId: request.sessionId,
|
|
80
|
-
metadata: {
|
|
81
|
-
provider: this.provider.constructor.name,
|
|
82
|
-
tokens: result.usage?.totalTokens,
|
|
83
|
-
latency: Date.now() - Date.now(), // Should track actual timing
|
|
84
|
-
},
|
|
85
|
-
},
|
|
86
|
-
};
|
|
87
|
-
this.sendToConnection(connectionId, responseMessage);
|
|
88
|
-
if (this.options.enableTypingIndicators) {
|
|
89
|
-
this.clearTypingIndicator(connectionId);
|
|
90
|
-
}
|
|
91
|
-
await this.streamingManager.terminateStreamingSession(streamingSession.id);
|
|
92
|
-
}
|
|
93
|
-
catch (error) {
|
|
94
|
-
console.error("[WebSocket Chat] Error handling chat request:", error);
|
|
95
|
-
this.sendError(connectionId, "Failed to process chat request");
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
async handleGroupChat(roomId, request) {
|
|
99
|
-
try {
|
|
100
|
-
// Process AI request
|
|
101
|
-
const result = await this.provider.generate({
|
|
102
|
-
prompt: request.prompt,
|
|
103
|
-
temperature: request.options?.temperature,
|
|
104
|
-
maxTokens: request.options?.maxTokens,
|
|
105
|
-
});
|
|
106
|
-
if (!result || !result.content) {
|
|
107
|
-
throw new Error("Invalid AI response");
|
|
108
|
-
}
|
|
109
|
-
// Broadcast to room
|
|
110
|
-
const broadcastMessage = {
|
|
111
|
-
id: randomUUID(),
|
|
112
|
-
type: "ai-response",
|
|
113
|
-
connectionId: "system",
|
|
114
|
-
timestamp: Date.now(),
|
|
115
|
-
data: {
|
|
116
|
-
text: result.content,
|
|
117
|
-
sessionId: request.sessionId,
|
|
118
|
-
userId: request.userId,
|
|
119
|
-
isGroupMessage: true,
|
|
120
|
-
metadata: {
|
|
121
|
-
provider: this.provider.constructor.name,
|
|
122
|
-
tokens: result.usage?.totalTokens,
|
|
123
|
-
},
|
|
124
|
-
},
|
|
125
|
-
};
|
|
126
|
-
this.wsServer.broadcastToRoom(roomId, broadcastMessage);
|
|
127
|
-
}
|
|
128
|
-
catch (error) {
|
|
129
|
-
console.error("[WebSocket Chat] Error handling group chat:", error);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
async handleStreamingChat(connectionId, request) {
|
|
133
|
-
try {
|
|
134
|
-
const streamingOptions = request.streamingOptions || {};
|
|
135
|
-
// Create streaming channel
|
|
136
|
-
const channelId = randomUUID();
|
|
137
|
-
const channel = this.wsServer.createStreamingChannel(connectionId, channelId);
|
|
138
|
-
// Generate response
|
|
139
|
-
const result = await this.provider.generate({
|
|
140
|
-
prompt: request.prompt,
|
|
141
|
-
...request.options,
|
|
142
|
-
});
|
|
143
|
-
if (!result || !result.content) {
|
|
144
|
-
throw new Error("Invalid AI response");
|
|
145
|
-
}
|
|
146
|
-
// Send complete response
|
|
147
|
-
const responseMessage = {
|
|
148
|
-
id: randomUUID(),
|
|
149
|
-
type: "ai-response",
|
|
150
|
-
connectionId,
|
|
151
|
-
timestamp: Date.now(),
|
|
152
|
-
data: {
|
|
153
|
-
text: result.content,
|
|
154
|
-
isStreamingComplete: true,
|
|
155
|
-
channelId,
|
|
156
|
-
},
|
|
157
|
-
};
|
|
158
|
-
this.sendToConnection(connectionId, responseMessage);
|
|
159
|
-
}
|
|
160
|
-
catch (error) {
|
|
161
|
-
console.error("[WebSocket Chat] Error handling streaming chat:", error);
|
|
162
|
-
this.sendError(connectionId, "Failed to process streaming chat");
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
// Real-time Features
|
|
166
|
-
async enableTypingIndicators(roomId) {
|
|
167
|
-
this.options.enableTypingIndicators = true;
|
|
168
|
-
console.log(`[WebSocket Chat] Enabled typing indicators for room ${roomId}`);
|
|
169
|
-
}
|
|
170
|
-
async enablePresenceTracking(roomId) {
|
|
171
|
-
this.options.enablePresenceTracking = true;
|
|
172
|
-
console.log(`[WebSocket Chat] Enabled presence tracking for room ${roomId}`);
|
|
173
|
-
}
|
|
174
|
-
async enableMessageSynchronization(roomId) {
|
|
175
|
-
this.options.enableMessageSync = true;
|
|
176
|
-
console.log(`[WebSocket Chat] Enabled message sync for room ${roomId}`);
|
|
177
|
-
}
|
|
178
|
-
// Helper methods
|
|
179
|
-
sendToConnection(connectionId, message) {
|
|
180
|
-
// Use the WebSocket server's public send method
|
|
181
|
-
this.wsServer.sendMessage(connectionId, message);
|
|
182
|
-
}
|
|
183
|
-
sendError(connectionId, errorMessage) {
|
|
184
|
-
const errorMsg = {
|
|
185
|
-
id: randomUUID(),
|
|
186
|
-
type: "error",
|
|
187
|
-
connectionId,
|
|
188
|
-
timestamp: Date.now(),
|
|
189
|
-
data: { error: errorMessage },
|
|
190
|
-
};
|
|
191
|
-
this.sendToConnection(connectionId, errorMsg);
|
|
192
|
-
}
|
|
193
|
-
showTypingIndicator(connectionId, sender) {
|
|
194
|
-
if (!this.options.enableTypingIndicators) {
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
const message = {
|
|
198
|
-
id: randomUUID(),
|
|
199
|
-
type: "system",
|
|
200
|
-
connectionId,
|
|
201
|
-
timestamp: Date.now(),
|
|
202
|
-
data: {
|
|
203
|
-
event: "typing_start",
|
|
204
|
-
sender,
|
|
205
|
-
},
|
|
206
|
-
};
|
|
207
|
-
this.sendToConnection(connectionId, message);
|
|
208
|
-
}
|
|
209
|
-
clearTypingIndicator(connectionId) {
|
|
210
|
-
const timeout = this.typingIndicators.get(connectionId);
|
|
211
|
-
if (timeout) {
|
|
212
|
-
clearTimeout(timeout);
|
|
213
|
-
this.typingIndicators.delete(connectionId);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
updatePresence(connectionId, status) {
|
|
217
|
-
if (!this.options.enablePresenceTracking) {
|
|
218
|
-
return;
|
|
219
|
-
}
|
|
220
|
-
this.presenceTracking.set(connectionId, {
|
|
221
|
-
lastSeen: Date.now(),
|
|
222
|
-
status,
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
handleWebSocketChatMessage(connectionId, message) {
|
|
226
|
-
const data = message.data;
|
|
227
|
-
if (!data || typeof data !== "object") {
|
|
228
|
-
return;
|
|
229
|
-
}
|
|
230
|
-
switch (data.event) {
|
|
231
|
-
case "chat_request":
|
|
232
|
-
this.handleWebSocketChatRequest(connectionId, data.request);
|
|
233
|
-
break;
|
|
234
|
-
case "join_room":
|
|
235
|
-
this.wsServer.joinRoom(connectionId, data.roomId);
|
|
236
|
-
break;
|
|
237
|
-
case "leave_room":
|
|
238
|
-
this.wsServer.leaveRoom(connectionId, data.roomId);
|
|
239
|
-
break;
|
|
240
|
-
case "typing_start":
|
|
241
|
-
this.showTypingIndicator(connectionId, data.sender || "user");
|
|
242
|
-
break;
|
|
243
|
-
case "typing_stop":
|
|
244
|
-
this.clearTypingIndicator(connectionId);
|
|
245
|
-
break;
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
// Public API
|
|
249
|
-
getConnectionCount() {
|
|
250
|
-
return this.wsServer.getConnectionCount();
|
|
251
|
-
}
|
|
252
|
-
getRoomCount() {
|
|
253
|
-
return this.wsServer.getRoomCount();
|
|
254
|
-
}
|
|
255
|
-
getStreamingMetrics() {
|
|
256
|
-
return this.streamingManager.getStreamingMetrics();
|
|
257
|
-
}
|
|
258
|
-
close() {
|
|
259
|
-
this.wsServer.close();
|
|
260
|
-
this.streamingManager.destroy();
|
|
261
|
-
}
|
|
262
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Default value helper functions for NeuroLink
|
|
3
|
-
* Centralized logic for applying defaults across the system
|
|
4
|
-
*/
|
|
5
|
-
import type { UnknownRecord } from "../types/common.js";
|
|
6
|
-
/**
|
|
7
|
-
* Apply default values to options object
|
|
8
|
-
* User-provided values take precedence over defaults
|
|
9
|
-
*/
|
|
10
|
-
export declare function applyDefaults(options: UnknownRecord): UnknownRecord;
|
|
11
|
-
/**
|
|
12
|
-
* Get default max tokens for a specific provider
|
|
13
|
-
* Can be extended for provider-specific overrides in the future
|
|
14
|
-
*/
|
|
15
|
-
export declare function getDefaultMaxTokens(provider?: string): number;
|
|
16
|
-
/**
|
|
17
|
-
* Get default temperature for a specific use case
|
|
18
|
-
*/
|
|
19
|
-
export declare function getDefaultTemperature(useCase?: string): number;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Default value helper functions for NeuroLink
|
|
3
|
-
* Centralized logic for applying defaults across the system
|
|
4
|
-
*/
|
|
5
|
-
import { ENV_DEFAULTS, } from "./constants.js";
|
|
6
|
-
/**
|
|
7
|
-
* Apply default values to options object
|
|
8
|
-
* User-provided values take precedence over defaults
|
|
9
|
-
*/
|
|
10
|
-
export function applyDefaults(options) {
|
|
11
|
-
return {
|
|
12
|
-
maxTokens: ENV_DEFAULTS.maxTokens,
|
|
13
|
-
temperature: ENV_DEFAULTS.temperature,
|
|
14
|
-
...options, // User overrides take precedence
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Get default max tokens for a specific provider
|
|
19
|
-
* Can be extended for provider-specific overrides in the future
|
|
20
|
-
*/
|
|
21
|
-
export function getDefaultMaxTokens(provider) {
|
|
22
|
-
return ENV_DEFAULTS.maxTokens;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Get default temperature for a specific use case
|
|
26
|
-
*/
|
|
27
|
-
export function getDefaultTemperature(useCase) {
|
|
28
|
-
return ENV_DEFAULTS.temperature;
|
|
29
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { EvaluationConfig } from "./types.js";
|
|
2
|
-
/**
|
|
3
|
-
* Parse evaluation configuration from environment variables
|
|
4
|
-
*/
|
|
5
|
-
export declare function parseEvaluationConfig(): EvaluationConfig;
|
|
6
|
-
/**
|
|
7
|
-
* Get intelligent provider fallback order
|
|
8
|
-
*/
|
|
9
|
-
export declare function getProviderFallbackOrder(config: EvaluationConfig): string[];
|
|
10
|
-
/**
|
|
11
|
-
* Estimate evaluation cost
|
|
12
|
-
*/
|
|
13
|
-
export declare function estimateEvaluationCost(providerName: string, mode: string, promptLength: number, expectedResponseLength?: number): number;
|
|
14
|
-
/**
|
|
15
|
-
* Validate evaluation configuration
|
|
16
|
-
*/
|
|
17
|
-
export declare function validateEvaluationConfig(config: EvaluationConfig): string[];
|
|
18
|
-
/**
|
|
19
|
-
* Get configuration with validation and defaults
|
|
20
|
-
*/
|
|
21
|
-
export declare function getValidatedEvaluationConfig(): EvaluationConfig;
|
|
22
|
-
/**
|
|
23
|
-
* Check if evaluation is enabled for the current configuration
|
|
24
|
-
*/
|
|
25
|
-
export declare function isEvaluationEnabled(): boolean;
|
|
26
|
-
/**
|
|
27
|
-
* Get cost-optimized provider based on configuration
|
|
28
|
-
*/
|
|
29
|
-
export declare function getCostOptimizedProvider(config: EvaluationConfig): string | null;
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import { getAvailableProviders, sortProvidersByPreference, getProviderConfig, } from "./evaluation-providers.js";
|
|
2
|
-
import { logger } from "../utils/logger.js";
|
|
3
|
-
/**
|
|
4
|
-
* Parse evaluation configuration from environment variables
|
|
5
|
-
*/
|
|
6
|
-
export function parseEvaluationConfig() {
|
|
7
|
-
return {
|
|
8
|
-
provider: process.env.NEUROLINK_EVALUATION_PROVIDER || "google-ai",
|
|
9
|
-
model: process.env.NEUROLINK_EVALUATION_MODEL || "gemini-2.5-flash",
|
|
10
|
-
mode: process.env.NEUROLINK_EVALUATION_MODE || "fast",
|
|
11
|
-
fallbackEnabled: process.env.NEUROLINK_EVALUATION_FALLBACK_ENABLED !== "false",
|
|
12
|
-
fallbackProviders: (process.env.NEUROLINK_EVALUATION_FALLBACK_PROVIDERS ||
|
|
13
|
-
"openai,anthropic,vertex,bedrock").split(","),
|
|
14
|
-
timeout: parseInt(process.env.NEUROLINK_EVALUATION_TIMEOUT || "10000"),
|
|
15
|
-
maxTokens: parseInt(process.env.NEUROLINK_EVALUATION_MAX_TOKENS || "500"),
|
|
16
|
-
temperature: parseFloat(process.env.NEUROLINK_EVALUATION_TEMPERATURE || "0.1"),
|
|
17
|
-
preferCheap: process.env.NEUROLINK_EVALUATION_PREFER_CHEAP !== "false",
|
|
18
|
-
maxCostPerEval: parseFloat(process.env.NEUROLINK_EVALUATION_MAX_COST_PER_EVAL || "0.01"),
|
|
19
|
-
retryAttempts: parseInt(process.env.NEUROLINK_EVALUATION_RETRY_ATTEMPTS || "2"),
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Get intelligent provider fallback order
|
|
24
|
-
*/
|
|
25
|
-
export function getProviderFallbackOrder(config) {
|
|
26
|
-
const available = getAvailableProviders();
|
|
27
|
-
const sorted = sortProvidersByPreference(available, config.preferCheap);
|
|
28
|
-
// Start with user's preferred provider
|
|
29
|
-
const fallbackOrder = [config.provider];
|
|
30
|
-
// Add configured fallbacks
|
|
31
|
-
config.fallbackProviders.forEach((provider) => {
|
|
32
|
-
if (!fallbackOrder.includes(provider)) {
|
|
33
|
-
fallbackOrder.push(provider);
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
// Add remaining available providers
|
|
37
|
-
sorted.forEach((providerConfig) => {
|
|
38
|
-
if (!fallbackOrder.includes(providerConfig.provider)) {
|
|
39
|
-
fallbackOrder.push(providerConfig.provider);
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
logger.debug("[EvaluationConfig] Provider fallback order:", fallbackOrder);
|
|
43
|
-
return fallbackOrder;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Estimate evaluation cost
|
|
47
|
-
*/
|
|
48
|
-
export function estimateEvaluationCost(providerName, mode, promptLength, expectedResponseLength = 200) {
|
|
49
|
-
const config = getProviderConfig(providerName);
|
|
50
|
-
if (!config || !config.costPerToken) {
|
|
51
|
-
return 0;
|
|
52
|
-
}
|
|
53
|
-
const inputTokens = Math.ceil(promptLength / 4); // Rough token estimation
|
|
54
|
-
const outputTokens = expectedResponseLength / 4;
|
|
55
|
-
return (inputTokens * config.costPerToken.input +
|
|
56
|
-
outputTokens * config.costPerToken.output);
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Validate evaluation configuration
|
|
60
|
-
*/
|
|
61
|
-
export function validateEvaluationConfig(config) {
|
|
62
|
-
const errors = [];
|
|
63
|
-
// Validate provider
|
|
64
|
-
if (!getProviderConfig(config.provider)) {
|
|
65
|
-
errors.push(`Invalid provider: ${config.provider}`);
|
|
66
|
-
}
|
|
67
|
-
// Validate mode
|
|
68
|
-
if (!["fast", "balanced", "quality"].includes(config.mode)) {
|
|
69
|
-
errors.push(`Invalid mode: ${config.mode}. Must be 'fast', 'balanced', or 'quality'`);
|
|
70
|
-
}
|
|
71
|
-
// Validate timeout
|
|
72
|
-
if (config.timeout <= 0 || config.timeout > 60000) {
|
|
73
|
-
errors.push(`Invalid timeout: ${config.timeout}. Must be between 1 and 60000ms`);
|
|
74
|
-
}
|
|
75
|
-
// Validate max tokens
|
|
76
|
-
if (config.maxTokens <= 0 || config.maxTokens > 4000) {
|
|
77
|
-
errors.push(`Invalid maxTokens: ${config.maxTokens}. Must be between 1 and 4000`);
|
|
78
|
-
}
|
|
79
|
-
// Validate temperature
|
|
80
|
-
if (config.temperature < 0 || config.temperature > 2) {
|
|
81
|
-
errors.push(`Invalid temperature: ${config.temperature}. Must be between 0 and 2`);
|
|
82
|
-
}
|
|
83
|
-
// Validate max cost
|
|
84
|
-
if (config.maxCostPerEval <= 0) {
|
|
85
|
-
errors.push(`Invalid maxCostPerEval: ${config.maxCostPerEval}. Must be greater than 0`);
|
|
86
|
-
}
|
|
87
|
-
// Validate retry attempts
|
|
88
|
-
if (config.retryAttempts < 0 || config.retryAttempts > 5) {
|
|
89
|
-
errors.push(`Invalid retryAttempts: ${config.retryAttempts}. Must be between 0 and 5`);
|
|
90
|
-
}
|
|
91
|
-
return errors;
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Get configuration with validation and defaults
|
|
95
|
-
*/
|
|
96
|
-
export function getValidatedEvaluationConfig() {
|
|
97
|
-
const config = parseEvaluationConfig();
|
|
98
|
-
const errors = validateEvaluationConfig(config);
|
|
99
|
-
if (errors.length > 0) {
|
|
100
|
-
logger.warn("[EvaluationConfig] Configuration validation errors:", errors);
|
|
101
|
-
// Return default configuration if validation fails
|
|
102
|
-
return {
|
|
103
|
-
provider: "google-ai",
|
|
104
|
-
model: "gemini-2.5-flash",
|
|
105
|
-
mode: "fast",
|
|
106
|
-
fallbackEnabled: true,
|
|
107
|
-
fallbackProviders: ["openai", "anthropic"],
|
|
108
|
-
timeout: 10000,
|
|
109
|
-
maxTokens: 500,
|
|
110
|
-
temperature: 0.1,
|
|
111
|
-
preferCheap: true,
|
|
112
|
-
maxCostPerEval: 0.01,
|
|
113
|
-
retryAttempts: 2,
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
return config;
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Check if evaluation is enabled for the current configuration
|
|
120
|
-
*/
|
|
121
|
-
export function isEvaluationEnabled() {
|
|
122
|
-
// Check if at least one provider is available
|
|
123
|
-
const available = getAvailableProviders();
|
|
124
|
-
return available.length > 0;
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Get cost-optimized provider based on configuration
|
|
128
|
-
*/
|
|
129
|
-
export function getCostOptimizedProvider(config) {
|
|
130
|
-
const available = getAvailableProviders();
|
|
131
|
-
if (available.length === 0) {
|
|
132
|
-
return null;
|
|
133
|
-
}
|
|
134
|
-
const sorted = sortProvidersByPreference(available, true); // Always prefer cheap for cost optimization
|
|
135
|
-
// Find the cheapest provider that meets cost requirements
|
|
136
|
-
for (const providerConfig of sorted) {
|
|
137
|
-
const estimatedCost = estimateEvaluationCost(providerConfig.provider, config.mode, 1000);
|
|
138
|
-
if (estimatedCost <= config.maxCostPerEval) {
|
|
139
|
-
return providerConfig.provider;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
// If no provider meets cost requirements, return the cheapest one
|
|
143
|
-
return sorted[0].provider;
|
|
144
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type { GenerateOptions, GenerateResult } from "../types/generate-types.js";
|
|
2
|
-
import type { TextGenerationOptions } from "../core/types.js";
|
|
3
|
-
/**
|
|
4
|
-
* Compatibility conversion factory for seamless migration
|
|
5
|
-
* between generateText and generate functions
|
|
6
|
-
*/
|
|
7
|
-
export declare class CompatibilityConversionFactory {
|
|
8
|
-
/**
|
|
9
|
-
* Convert TextGenerationOptions to GenerateOptions
|
|
10
|
-
*/
|
|
11
|
-
static convertTextToGenerate(options: TextGenerationOptions): GenerateOptions;
|
|
12
|
-
/**
|
|
13
|
-
* Convert GenerateResult to legacy TextGenerationResult format
|
|
14
|
-
*/
|
|
15
|
-
static convertGenerateToText(result: GenerateResult): {
|
|
16
|
-
content: string;
|
|
17
|
-
provider?: string;
|
|
18
|
-
model?: string;
|
|
19
|
-
usage?: {
|
|
20
|
-
inputTokens: number;
|
|
21
|
-
outputTokens: number;
|
|
22
|
-
totalTokens: number;
|
|
23
|
-
};
|
|
24
|
-
responseTime?: number;
|
|
25
|
-
toolsUsed?: number;
|
|
26
|
-
toolExecutions?: unknown[];
|
|
27
|
-
analytics?: unknown;
|
|
28
|
-
evaluation?: unknown;
|
|
29
|
-
[key: string]: unknown;
|
|
30
|
-
};
|
|
31
|
-
/**
|
|
32
|
-
* Convert GenerateOptions to TextGenerationOptions
|
|
33
|
-
*/
|
|
34
|
-
static convertGenerateToText_Options(options: GenerateOptions): TextGenerationOptions;
|
|
35
|
-
}
|