@juspay/neurolink 3.0.1 → 4.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 +57 -6
- package/README.md +235 -2
- package/dist/agent/direct-tools.d.ts +6 -6
- package/dist/chat/client-utils.d.ts +92 -0
- package/dist/chat/client-utils.js +298 -0
- package/dist/chat/index.d.ts +27 -0
- package/dist/chat/index.js +41 -0
- package/dist/chat/session-storage.d.ts +77 -0
- package/dist/chat/session-storage.js +233 -0
- package/dist/chat/session.d.ts +95 -0
- package/dist/chat/session.js +257 -0
- package/dist/chat/sse-handler.d.ts +49 -0
- package/dist/chat/sse-handler.js +266 -0
- package/dist/chat/types.d.ts +73 -0
- package/dist/chat/types.js +5 -0
- package/dist/chat/websocket-chat-handler.d.ts +36 -0
- package/dist/chat/websocket-chat-handler.js +262 -0
- package/dist/cli/commands/config.js +12 -12
- package/dist/cli/commands/mcp.js +3 -4
- package/dist/cli/index.d.ts +0 -7
- package/dist/cli/index.js +247 -28
- package/dist/config/configManager.d.ts +60 -0
- package/dist/config/configManager.js +300 -0
- package/dist/config/types.d.ts +136 -0
- package/dist/config/types.js +43 -0
- package/dist/core/analytics.d.ts +23 -0
- package/dist/core/analytics.js +131 -0
- package/dist/core/constants.d.ts +41 -0
- package/dist/core/constants.js +50 -0
- package/dist/core/defaults.d.ts +18 -0
- package/dist/core/defaults.js +29 -0
- package/dist/core/evaluation-config.d.ts +29 -0
- package/dist/core/evaluation-config.js +144 -0
- package/dist/core/evaluation-providers.d.ts +30 -0
- package/dist/core/evaluation-providers.js +187 -0
- package/dist/core/evaluation.d.ts +117 -0
- package/dist/core/evaluation.js +528 -0
- package/dist/core/factory.js +33 -25
- package/dist/core/types.d.ts +165 -6
- package/dist/core/types.js +3 -4
- package/dist/index.d.ts +9 -4
- package/dist/index.js +25 -4
- package/dist/lib/agent/direct-tools.d.ts +6 -6
- package/dist/lib/chat/client-utils.d.ts +92 -0
- package/dist/lib/chat/client-utils.js +298 -0
- package/dist/lib/chat/index.d.ts +27 -0
- package/dist/lib/chat/index.js +41 -0
- package/dist/lib/chat/session-storage.d.ts +77 -0
- package/dist/lib/chat/session-storage.js +233 -0
- package/dist/lib/chat/session.d.ts +95 -0
- package/dist/lib/chat/session.js +257 -0
- package/dist/lib/chat/sse-handler.d.ts +49 -0
- package/dist/lib/chat/sse-handler.js +266 -0
- package/dist/lib/chat/types.d.ts +73 -0
- package/dist/lib/chat/types.js +5 -0
- package/dist/lib/chat/websocket-chat-handler.d.ts +36 -0
- package/dist/lib/chat/websocket-chat-handler.js +262 -0
- package/dist/lib/config/configManager.d.ts +60 -0
- package/dist/lib/config/configManager.js +300 -0
- package/dist/lib/config/types.d.ts +136 -0
- package/dist/lib/config/types.js +43 -0
- package/dist/lib/core/analytics.d.ts +23 -0
- package/dist/lib/core/analytics.js +131 -0
- package/dist/lib/core/constants.d.ts +41 -0
- package/dist/lib/core/constants.js +50 -0
- package/dist/lib/core/defaults.d.ts +18 -0
- package/dist/lib/core/defaults.js +29 -0
- package/dist/lib/core/evaluation-config.d.ts +29 -0
- package/dist/lib/core/evaluation-config.js +144 -0
- package/dist/lib/core/evaluation-providers.d.ts +30 -0
- package/dist/lib/core/evaluation-providers.js +187 -0
- package/dist/lib/core/evaluation.d.ts +117 -0
- package/dist/lib/core/evaluation.js +528 -0
- package/dist/lib/core/factory.js +33 -26
- package/dist/lib/core/types.d.ts +165 -6
- package/dist/lib/core/types.js +3 -4
- package/dist/lib/index.d.ts +9 -4
- package/dist/lib/index.js +25 -4
- package/dist/lib/mcp/contracts/mcpContract.d.ts +118 -0
- package/dist/lib/mcp/contracts/mcpContract.js +5 -0
- package/dist/lib/mcp/function-calling.js +11 -3
- package/dist/lib/mcp/logging.js +5 -0
- package/dist/lib/mcp/neurolink-mcp-client.js +2 -1
- package/dist/lib/mcp/orchestrator.js +18 -9
- package/dist/lib/mcp/registry.d.ts +49 -16
- package/dist/lib/mcp/registry.js +80 -6
- package/dist/lib/mcp/servers/ai-providers/ai-workflow-tools.js +5 -4
- package/dist/lib/mcp/tool-integration.js +1 -1
- package/dist/lib/mcp/tool-registry.d.ts +55 -34
- package/dist/lib/mcp/tool-registry.js +111 -97
- package/dist/lib/mcp/unified-mcp.js +6 -1
- package/dist/lib/mcp/unified-registry.d.ts +12 -4
- package/dist/lib/mcp/unified-registry.js +17 -4
- package/dist/lib/neurolink.d.ts +26 -0
- package/dist/lib/neurolink.js +43 -1
- package/dist/lib/providers/agent-enhanced-provider.d.ts +11 -2
- package/dist/lib/providers/agent-enhanced-provider.js +86 -15
- package/dist/lib/providers/amazonBedrock.d.ts +9 -1
- package/dist/lib/providers/amazonBedrock.js +26 -2
- package/dist/lib/providers/analytics-helper.d.ts +53 -0
- package/dist/lib/providers/analytics-helper.js +151 -0
- package/dist/lib/providers/anthropic.d.ts +11 -1
- package/dist/lib/providers/anthropic.js +29 -4
- package/dist/lib/providers/azureOpenAI.d.ts +3 -1
- package/dist/lib/providers/azureOpenAI.js +28 -4
- package/dist/lib/providers/function-calling-provider.d.ts +9 -1
- package/dist/lib/providers/function-calling-provider.js +14 -1
- package/dist/lib/providers/googleAIStudio.d.ts +15 -1
- package/dist/lib/providers/googleAIStudio.js +32 -2
- package/dist/lib/providers/googleVertexAI.d.ts +9 -1
- package/dist/lib/providers/googleVertexAI.js +31 -2
- package/dist/lib/providers/huggingFace.d.ts +3 -1
- package/dist/lib/providers/huggingFace.js +26 -3
- package/dist/lib/providers/mcp-provider.d.ts +9 -1
- package/dist/lib/providers/mcp-provider.js +12 -0
- package/dist/lib/providers/mistralAI.d.ts +3 -1
- package/dist/lib/providers/mistralAI.js +25 -2
- package/dist/lib/providers/ollama.d.ts +3 -1
- package/dist/lib/providers/ollama.js +27 -4
- package/dist/lib/providers/openAI.d.ts +15 -1
- package/dist/lib/providers/openAI.js +32 -2
- package/dist/lib/proxy/proxy-fetch.js +8 -7
- package/dist/lib/services/streaming/streaming-manager.d.ts +29 -0
- package/dist/lib/services/streaming/streaming-manager.js +244 -0
- package/dist/lib/services/types.d.ts +155 -0
- package/dist/lib/services/types.js +2 -0
- package/dist/lib/services/websocket/websocket-server.d.ts +34 -0
- package/dist/lib/services/websocket/websocket-server.js +304 -0
- package/dist/lib/telemetry/index.d.ts +15 -0
- package/dist/lib/telemetry/index.js +22 -0
- package/dist/lib/telemetry/telemetry-service.d.ts +47 -0
- package/dist/lib/telemetry/telemetry-service.js +259 -0
- package/dist/lib/utils/streaming-utils.d.ts +67 -0
- package/dist/lib/utils/streaming-utils.js +201 -0
- package/dist/mcp/contracts/mcpContract.d.ts +118 -0
- package/dist/mcp/contracts/mcpContract.js +5 -0
- package/dist/mcp/function-calling.js +11 -3
- package/dist/mcp/logging.js +5 -0
- package/dist/mcp/neurolink-mcp-client.js +2 -1
- package/dist/mcp/orchestrator.js +18 -9
- package/dist/mcp/registry.d.ts +49 -16
- package/dist/mcp/registry.js +80 -6
- package/dist/mcp/servers/ai-providers/ai-workflow-tools.d.ts +2 -2
- package/dist/mcp/servers/ai-providers/ai-workflow-tools.js +5 -4
- package/dist/mcp/tool-integration.js +1 -1
- package/dist/mcp/tool-registry.d.ts +55 -34
- package/dist/mcp/tool-registry.js +111 -97
- package/dist/mcp/unified-mcp.js +6 -1
- package/dist/mcp/unified-registry.d.ts +12 -4
- package/dist/mcp/unified-registry.js +17 -4
- package/dist/neurolink.d.ts +26 -0
- package/dist/neurolink.js +43 -1
- package/dist/providers/agent-enhanced-provider.d.ts +11 -2
- package/dist/providers/agent-enhanced-provider.js +86 -15
- package/dist/providers/amazonBedrock.d.ts +9 -1
- package/dist/providers/amazonBedrock.js +26 -2
- package/dist/providers/analytics-helper.d.ts +53 -0
- package/dist/providers/analytics-helper.js +151 -0
- package/dist/providers/anthropic.d.ts +11 -1
- package/dist/providers/anthropic.js +29 -4
- package/dist/providers/azureOpenAI.d.ts +3 -1
- package/dist/providers/azureOpenAI.js +29 -4
- package/dist/providers/function-calling-provider.d.ts +9 -1
- package/dist/providers/function-calling-provider.js +14 -1
- package/dist/providers/googleAIStudio.d.ts +15 -1
- package/dist/providers/googleAIStudio.js +32 -2
- package/dist/providers/googleVertexAI.d.ts +9 -1
- package/dist/providers/googleVertexAI.js +31 -2
- package/dist/providers/huggingFace.d.ts +3 -1
- package/dist/providers/huggingFace.js +26 -3
- package/dist/providers/mcp-provider.d.ts +9 -1
- package/dist/providers/mcp-provider.js +12 -0
- package/dist/providers/mistralAI.d.ts +3 -1
- package/dist/providers/mistralAI.js +25 -2
- package/dist/providers/ollama.d.ts +3 -1
- package/dist/providers/ollama.js +27 -4
- package/dist/providers/openAI.d.ts +15 -1
- package/dist/providers/openAI.js +33 -2
- package/dist/proxy/proxy-fetch.js +8 -7
- package/dist/services/streaming/streaming-manager.d.ts +29 -0
- package/dist/services/streaming/streaming-manager.js +244 -0
- package/dist/services/types.d.ts +155 -0
- package/dist/services/types.js +2 -0
- package/dist/services/websocket/websocket-server.d.ts +34 -0
- package/dist/services/websocket/websocket-server.js +304 -0
- package/dist/telemetry/index.d.ts +15 -0
- package/dist/telemetry/index.js +22 -0
- package/dist/telemetry/telemetry-service.d.ts +47 -0
- package/dist/telemetry/telemetry-service.js +261 -0
- package/dist/utils/streaming-utils.d.ts +67 -0
- package/dist/utils/streaming-utils.js +201 -0
- package/package.json +18 -2
package/dist/cli/index.js
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
// CRITICAL: Set MCP logging level before ANY imports
|
|
3
|
+
if (!process.argv.includes("--debug")) {
|
|
4
|
+
process.env.MCP_LOG_LEVEL = "error"; // Only show MCP errors unless debugging
|
|
5
|
+
}
|
|
6
|
+
else {
|
|
7
|
+
process.env.MCP_LOG_LEVEL = "info"; // Show MCP logs when debugging
|
|
8
|
+
}
|
|
2
9
|
/**
|
|
3
10
|
* NeuroLink CLI - Enhanced Simplified Approach
|
|
4
11
|
*
|
|
@@ -16,6 +23,84 @@ import { addMCPCommands } from "./commands/mcp.js";
|
|
|
16
23
|
import { addOllamaCommands } from "./commands/ollama.js";
|
|
17
24
|
import { agentGenerateCommand } from "./commands/agent-generate.js";
|
|
18
25
|
import { AgentEnhancedProvider } from "../lib/providers/agent-enhanced-provider.js";
|
|
26
|
+
import { logger } from "../lib/utils/logger.js";
|
|
27
|
+
/**
|
|
28
|
+
* Helper functions for displaying analytics and evaluation results
|
|
29
|
+
* Addresses DRY principle - extracted shared parts into reusable functions
|
|
30
|
+
*/
|
|
31
|
+
function displayDebugInfo(title, data, debug) {
|
|
32
|
+
if (debug) {
|
|
33
|
+
console.log(chalk.blue(title));
|
|
34
|
+
console.log(JSON.stringify(data, null, 2));
|
|
35
|
+
console.log();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function displayMissingDataWarning(type) {
|
|
39
|
+
console.log();
|
|
40
|
+
console.log(chalk.red(`⚠️ ${type} enabled but no data received`));
|
|
41
|
+
console.log();
|
|
42
|
+
}
|
|
43
|
+
function formatAnalytics(analytics) {
|
|
44
|
+
console.log();
|
|
45
|
+
console.log(chalk.blue("📊 Analytics:"));
|
|
46
|
+
console.log(` 🚀 Provider: ${analytics.provider}`);
|
|
47
|
+
console.log(` 🤖 Model: ${analytics.model}`);
|
|
48
|
+
if (analytics.tokens) {
|
|
49
|
+
console.log(` 💬 Tokens: ${analytics.tokens.totalTokens || analytics.tokens.total || "unknown"}`);
|
|
50
|
+
}
|
|
51
|
+
console.log(` ⏱️ Response Time: ${analytics.responseTime}ms`);
|
|
52
|
+
if (analytics.context) {
|
|
53
|
+
console.log(` 📋 Context: ${Object.keys(analytics.context).length} fields`);
|
|
54
|
+
}
|
|
55
|
+
console.log();
|
|
56
|
+
}
|
|
57
|
+
function formatEvaluation(evaluation) {
|
|
58
|
+
console.log();
|
|
59
|
+
console.log(chalk.blue("⭐ Response Quality Evaluation:"));
|
|
60
|
+
console.log(` 📊 Scores: Relevance ${evaluation.relevanceScore || evaluation.relevance}/10, Accuracy ${evaluation.accuracyScore || evaluation.accuracy}/10, Completeness ${evaluation.completenessScore || evaluation.completeness}/10`);
|
|
61
|
+
console.log(` 🎯 Overall Quality: ${evaluation.overall}/10`);
|
|
62
|
+
const severity = evaluation.alertSeverity || "none";
|
|
63
|
+
const severityColors = {
|
|
64
|
+
high: chalk.red,
|
|
65
|
+
medium: chalk.yellow,
|
|
66
|
+
low: chalk.blue,
|
|
67
|
+
none: chalk.green,
|
|
68
|
+
};
|
|
69
|
+
const severityColor = severityColors[severity] || chalk.gray;
|
|
70
|
+
console.log(` 🚨 Alert Level: ${severityColor(severity)}`);
|
|
71
|
+
if (evaluation.reasoning) {
|
|
72
|
+
console.log(` 💭 Analysis: ${evaluation.reasoning}`);
|
|
73
|
+
}
|
|
74
|
+
if (evaluation.suggestedImprovements) {
|
|
75
|
+
console.log(` 💡 Improvements: ${evaluation.suggestedImprovements}`);
|
|
76
|
+
}
|
|
77
|
+
const evalModel = evaluation.evaluationModel || "unknown";
|
|
78
|
+
const evalTime = evaluation.evaluationTime
|
|
79
|
+
? `${evaluation.evaluationTime}ms`
|
|
80
|
+
: "unknown";
|
|
81
|
+
console.log(` 🤖 Evaluated by: ${evalModel} (${evalTime})`);
|
|
82
|
+
console.log();
|
|
83
|
+
}
|
|
84
|
+
function displayAnalyticsAndEvaluation(result, argv) {
|
|
85
|
+
if (result && result.analytics) {
|
|
86
|
+
displayDebugInfo("📊 Analytics:", result.analytics, argv.debug);
|
|
87
|
+
if (!argv.debug) {
|
|
88
|
+
formatAnalytics(result.analytics);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
else if (argv.enableAnalytics) {
|
|
92
|
+
displayMissingDataWarning("Analytics");
|
|
93
|
+
}
|
|
94
|
+
if (result && result.evaluation) {
|
|
95
|
+
displayDebugInfo("⭐ Response Evaluation:", result.evaluation, argv.debug);
|
|
96
|
+
if (!argv.debug) {
|
|
97
|
+
formatEvaluation(result.evaluation);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
else if (argv.enableEvaluation) {
|
|
101
|
+
displayMissingDataWarning("Evaluation");
|
|
102
|
+
}
|
|
103
|
+
}
|
|
19
104
|
// Load environment variables from .env file
|
|
20
105
|
try {
|
|
21
106
|
// Try to import and configure dotenv
|
|
@@ -129,10 +214,12 @@ const cli = yargs(args)
|
|
|
129
214
|
// Control SDK logging based on debug flag
|
|
130
215
|
if (argv.debug) {
|
|
131
216
|
process.env.NEUROLINK_DEBUG = "true";
|
|
217
|
+
process.env.MCP_LOG_LEVEL = "info"; // Show MCP logs in debug mode
|
|
132
218
|
}
|
|
133
219
|
else {
|
|
134
220
|
// Always set to false when debug is not enabled (including when not provided)
|
|
135
221
|
process.env.NEUROLINK_DEBUG = "false";
|
|
222
|
+
process.env.MCP_LOG_LEVEL = "error"; // Hide MCP info logs when not debugging
|
|
136
223
|
}
|
|
137
224
|
// Keep existing quiet middleware
|
|
138
225
|
if (process.env.NEUROLINK_QUIET === "true" &&
|
|
@@ -252,19 +339,46 @@ const cli = yargs(args)
|
|
|
252
339
|
default: false,
|
|
253
340
|
description: "Enable debug mode with verbose output",
|
|
254
341
|
}) // Kept for potential specific debug logic
|
|
255
|
-
.option("timeout", {
|
|
256
|
-
type: "string",
|
|
257
|
-
default: "30s",
|
|
258
|
-
description: "Timeout for the request (e.g., 30s, 2m, 1h, 5000)",
|
|
259
|
-
})
|
|
260
342
|
.option("model", {
|
|
261
343
|
type: "string",
|
|
262
344
|
description: "Specific model to use (e.g. gemini-2.5-pro, gemini-2.5-flash)",
|
|
345
|
+
})
|
|
346
|
+
.option("timeout", {
|
|
347
|
+
type: "number",
|
|
348
|
+
default: 120,
|
|
349
|
+
description: "Maximum execution time in seconds (default: 120)",
|
|
263
350
|
})
|
|
264
351
|
.option("disable-tools", {
|
|
265
352
|
type: "boolean",
|
|
266
353
|
default: false,
|
|
267
354
|
description: "Disable MCP tool integration (tools enabled by default)",
|
|
355
|
+
})
|
|
356
|
+
.option("enable-analytics", {
|
|
357
|
+
type: "boolean",
|
|
358
|
+
default: false,
|
|
359
|
+
description: "Enable usage analytics collection",
|
|
360
|
+
})
|
|
361
|
+
.option("enable-evaluation", {
|
|
362
|
+
type: "boolean",
|
|
363
|
+
default: false,
|
|
364
|
+
description: "Enable AI response quality evaluation",
|
|
365
|
+
})
|
|
366
|
+
.option("evaluation-domain", {
|
|
367
|
+
type: "string",
|
|
368
|
+
description: "Domain expertise for evaluation (e.g., 'AI coding assistant', 'Customer service expert')",
|
|
369
|
+
})
|
|
370
|
+
.option("tool-usage-context", {
|
|
371
|
+
type: "string",
|
|
372
|
+
description: "Tool usage context for evaluation (e.g., 'Used sales-data MCP tools')",
|
|
373
|
+
})
|
|
374
|
+
.option("lighthouse-style", {
|
|
375
|
+
type: "boolean",
|
|
376
|
+
default: false,
|
|
377
|
+
description: "Use Lighthouse-compatible domain-aware evaluation",
|
|
378
|
+
})
|
|
379
|
+
.option("context", {
|
|
380
|
+
type: "string",
|
|
381
|
+
description: "JSON context object for custom data",
|
|
268
382
|
})
|
|
269
383
|
.example('$0 generate-text "Hello world"', "Basic text generation")
|
|
270
384
|
.example('$0 generate-text "Write a story" --provider openai', "Use specific provider")
|
|
@@ -289,10 +403,25 @@ const cli = yargs(args)
|
|
|
289
403
|
? null
|
|
290
404
|
: ora("🤖 Generating text...").start();
|
|
291
405
|
try {
|
|
292
|
-
//
|
|
293
|
-
|
|
406
|
+
// CRITICAL: Add master timeout to prevent infinite hangs
|
|
407
|
+
const cliTimeout = argv.timeout ? argv.timeout * 1000 : 120000; // Default 2 minutes
|
|
408
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
409
|
+
setTimeout(() => {
|
|
410
|
+
reject(new Error(`CLI operation timed out after ${cliTimeout / 1000} seconds. Use --timeout to adjust.`));
|
|
411
|
+
}, cliTimeout);
|
|
412
|
+
});
|
|
294
413
|
// Use AgentEnhancedProvider when tools are enabled, otherwise use standard SDK
|
|
295
414
|
let generatePromise;
|
|
415
|
+
// Parse context if provided
|
|
416
|
+
let contextObj;
|
|
417
|
+
if (argv.context) {
|
|
418
|
+
try {
|
|
419
|
+
contextObj = JSON.parse(argv.context);
|
|
420
|
+
}
|
|
421
|
+
catch {
|
|
422
|
+
throw new Error("Invalid JSON provided for --context option");
|
|
423
|
+
}
|
|
424
|
+
}
|
|
296
425
|
if (argv.disableTools === true) {
|
|
297
426
|
// Tools disabled - use standard SDK
|
|
298
427
|
generatePromise = sdk.generateText({
|
|
@@ -305,6 +434,13 @@ const cli = yargs(args)
|
|
|
305
434
|
maxTokens: argv.maxTokens,
|
|
306
435
|
systemPrompt: argv.system,
|
|
307
436
|
timeout: argv.timeout,
|
|
437
|
+
// NEW: Analytics and evaluation support
|
|
438
|
+
enableAnalytics: argv.enableAnalytics,
|
|
439
|
+
enableEvaluation: argv.enableEvaluation,
|
|
440
|
+
context: contextObj,
|
|
441
|
+
// NEW: Lighthouse-compatible domain-aware evaluation
|
|
442
|
+
evaluationDomain: argv.evaluationDomain,
|
|
443
|
+
toolUsageContext: argv.toolUsageContext,
|
|
308
444
|
});
|
|
309
445
|
}
|
|
310
446
|
else {
|
|
@@ -326,37 +462,52 @@ const cli = yargs(args)
|
|
|
326
462
|
model: argv.model, // Use specified model or default
|
|
327
463
|
toolCategory: "all", // Enable all tool categories
|
|
328
464
|
});
|
|
329
|
-
generatePromise = agentProvider.generateText(
|
|
465
|
+
generatePromise = agentProvider.generateText({
|
|
466
|
+
prompt: argv.prompt,
|
|
467
|
+
temperature: argv.temperature,
|
|
468
|
+
maxTokens: argv.maxTokens, // Respect user's token limit - no artificial caps
|
|
469
|
+
systemPrompt: argv.system,
|
|
470
|
+
// NEW: Analytics and evaluation support
|
|
471
|
+
enableAnalytics: argv.enableAnalytics,
|
|
472
|
+
enableEvaluation: argv.enableEvaluation,
|
|
473
|
+
context: contextObj,
|
|
474
|
+
// NEW: Lighthouse-compatible domain-aware evaluation
|
|
475
|
+
evaluationDomain: argv.evaluationDomain,
|
|
476
|
+
toolUsageContext: argv.toolUsageContext,
|
|
477
|
+
});
|
|
330
478
|
}
|
|
331
|
-
|
|
479
|
+
// Wrap generation with master timeout to prevent infinite hangs
|
|
480
|
+
const result = await Promise.race([generatePromise, timeoutPromise]);
|
|
332
481
|
if (argv.format === "json" && originalConsole.log) {
|
|
333
482
|
Object.assign(console, originalConsole);
|
|
334
483
|
}
|
|
335
484
|
if (spinner) {
|
|
336
485
|
spinner.succeed(chalk.green("✅ Text generated successfully!"));
|
|
337
486
|
}
|
|
338
|
-
|
|
339
|
-
const responseText =
|
|
340
|
-
|
|
341
|
-
:
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
completionTokens: 0,
|
|
346
|
-
totalTokens: 0,
|
|
347
|
-
}
|
|
348
|
-
: { promptTokens: 0, completionTokens: 0, totalTokens: 0 };
|
|
487
|
+
const typedResult = result;
|
|
488
|
+
const responseText = typedResult?.text || typedResult?.content || "";
|
|
489
|
+
const responseUsage = typedResult?.usage || {
|
|
490
|
+
promptTokens: 0,
|
|
491
|
+
completionTokens: 0,
|
|
492
|
+
totalTokens: 0,
|
|
493
|
+
};
|
|
349
494
|
if (argv.format === "json") {
|
|
350
495
|
const jsonOutput = {
|
|
351
496
|
content: responseText,
|
|
352
|
-
provider:
|
|
353
|
-
? result.provider || argv.provider
|
|
354
|
-
: argv.provider,
|
|
497
|
+
provider: typedResult?.provider || argv.provider,
|
|
355
498
|
usage: responseUsage,
|
|
356
|
-
responseTime:
|
|
357
|
-
toolCalls:
|
|
358
|
-
toolResults:
|
|
499
|
+
responseTime: typedResult?.responseTime || 0,
|
|
500
|
+
toolCalls: typedResult?.toolCalls || [],
|
|
501
|
+
toolResults: typedResult?.toolResults || [],
|
|
359
502
|
};
|
|
503
|
+
// Include analytics if present
|
|
504
|
+
if (typedResult?.analytics) {
|
|
505
|
+
jsonOutput.analytics = typedResult.analytics;
|
|
506
|
+
}
|
|
507
|
+
// Include evaluation if present
|
|
508
|
+
if (typedResult?.evaluation) {
|
|
509
|
+
jsonOutput.evaluation = typedResult.evaluation;
|
|
510
|
+
}
|
|
360
511
|
process.stdout.write(JSON.stringify(jsonOutput, null, 2) + "\n");
|
|
361
512
|
}
|
|
362
513
|
else if (argv.debug) {
|
|
@@ -386,6 +537,21 @@ const cli = yargs(args)
|
|
|
386
537
|
}
|
|
387
538
|
console.log();
|
|
388
539
|
}
|
|
540
|
+
// DEBUG: Show what's in the result object
|
|
541
|
+
if (argv.debug) {
|
|
542
|
+
logger.debug("Result object keys:", {
|
|
543
|
+
keys: Object.keys(result || {}),
|
|
544
|
+
});
|
|
545
|
+
logger.debug("Enhancement status:", {
|
|
546
|
+
hasAnalytics: !!(result && result.analytics),
|
|
547
|
+
hasEvaluation: !!(result && result.evaluation),
|
|
548
|
+
enableAnalytics: argv.enableAnalytics,
|
|
549
|
+
enableEvaluation: argv.enableEvaluation,
|
|
550
|
+
hasContext: !!contextObj,
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
// Show analytics and evaluation if enabled
|
|
554
|
+
displayAnalyticsAndEvaluation(result, argv);
|
|
389
555
|
console.log(JSON.stringify({
|
|
390
556
|
provider: result
|
|
391
557
|
? result.provider || argv.provider
|
|
@@ -402,6 +568,8 @@ const cli = yargs(args)
|
|
|
402
568
|
if (responseText) {
|
|
403
569
|
console.log(responseText);
|
|
404
570
|
}
|
|
571
|
+
// Show analytics and evaluation if enabled
|
|
572
|
+
displayAnalyticsAndEvaluation(result, argv);
|
|
405
573
|
}
|
|
406
574
|
// Explicitly exit to prevent hanging, especially with Google AI Studio
|
|
407
575
|
process.exit(0);
|
|
@@ -458,7 +626,7 @@ const cli = yargs(args)
|
|
|
458
626
|
})
|
|
459
627
|
.option("model", {
|
|
460
628
|
type: "string",
|
|
461
|
-
description: "Specific model to use (e.g., gemini-
|
|
629
|
+
description: "Specific model to use (e.g., gemini-2.5-pro, gemini-2.5-flash)",
|
|
462
630
|
})
|
|
463
631
|
.option("debug", {
|
|
464
632
|
type: "boolean",
|
|
@@ -469,6 +637,33 @@ const cli = yargs(args)
|
|
|
469
637
|
type: "boolean",
|
|
470
638
|
default: false,
|
|
471
639
|
description: "Disable MCP tool integration (tools enabled by default)",
|
|
640
|
+
})
|
|
641
|
+
.option("enable-analytics", {
|
|
642
|
+
type: "boolean",
|
|
643
|
+
default: false,
|
|
644
|
+
description: "Enable usage analytics collection",
|
|
645
|
+
})
|
|
646
|
+
.option("enable-evaluation", {
|
|
647
|
+
type: "boolean",
|
|
648
|
+
default: false,
|
|
649
|
+
description: "Enable AI response quality evaluation",
|
|
650
|
+
})
|
|
651
|
+
.option("evaluation-domain", {
|
|
652
|
+
type: "string",
|
|
653
|
+
description: "Domain expertise for evaluation (e.g., 'AI coding assistant', 'Customer service expert')",
|
|
654
|
+
})
|
|
655
|
+
.option("tool-usage-context", {
|
|
656
|
+
type: "string",
|
|
657
|
+
description: "Tool usage context for evaluation (e.g., 'Used sales-data MCP tools')",
|
|
658
|
+
})
|
|
659
|
+
.option("lighthouse-style", {
|
|
660
|
+
type: "boolean",
|
|
661
|
+
default: false,
|
|
662
|
+
description: "Use Lighthouse-compatible domain-aware evaluation",
|
|
663
|
+
})
|
|
664
|
+
.option("context", {
|
|
665
|
+
type: "string",
|
|
666
|
+
description: "JSON context object for custom data",
|
|
472
667
|
})
|
|
473
668
|
.example('$0 stream "Tell me a story"', "Stream a story in real-time")
|
|
474
669
|
.example('$0 stream "What time is it?"', "Stream with natural tool integration (default)")
|
|
@@ -482,6 +677,16 @@ const cli = yargs(args)
|
|
|
482
677
|
console.log(chalk.blue(`🔄 Streaming from ${argv.provider} provider with debug logging...\n`));
|
|
483
678
|
}
|
|
484
679
|
try {
|
|
680
|
+
// Parse context if provided
|
|
681
|
+
let contextObj;
|
|
682
|
+
if (argv.context) {
|
|
683
|
+
try {
|
|
684
|
+
contextObj = JSON.parse(argv.context);
|
|
685
|
+
}
|
|
686
|
+
catch {
|
|
687
|
+
throw new Error("Invalid JSON provided for --context option");
|
|
688
|
+
}
|
|
689
|
+
}
|
|
485
690
|
let stream;
|
|
486
691
|
if (argv.disableTools === true) {
|
|
487
692
|
// Tools disabled - use standard SDK
|
|
@@ -493,6 +698,10 @@ const cli = yargs(args)
|
|
|
493
698
|
model: argv.model,
|
|
494
699
|
temperature: argv.temperature,
|
|
495
700
|
timeout: argv.timeout,
|
|
701
|
+
// NEW: Analytics and evaluation support
|
|
702
|
+
enableAnalytics: argv.enableAnalytics,
|
|
703
|
+
enableEvaluation: argv.enableEvaluation,
|
|
704
|
+
context: contextObj,
|
|
496
705
|
});
|
|
497
706
|
}
|
|
498
707
|
else {
|
|
@@ -516,7 +725,14 @@ const cli = yargs(args)
|
|
|
516
725
|
});
|
|
517
726
|
// Note: AgentEnhancedProvider doesn't support streaming with tools yet
|
|
518
727
|
// Fall back to generateText for now
|
|
519
|
-
const result = await agentProvider.generateText(
|
|
728
|
+
const result = await agentProvider.generateText({
|
|
729
|
+
prompt: argv.prompt,
|
|
730
|
+
temperature: argv.temperature,
|
|
731
|
+
// NEW: Analytics and evaluation support
|
|
732
|
+
enableAnalytics: argv.enableAnalytics,
|
|
733
|
+
enableEvaluation: argv.enableEvaluation,
|
|
734
|
+
context: contextObj,
|
|
735
|
+
});
|
|
520
736
|
// Simulate streaming by outputting the result
|
|
521
737
|
const text = result?.text || "";
|
|
522
738
|
const CHUNK_SIZE = 10;
|
|
@@ -528,6 +744,9 @@ const cli = yargs(args)
|
|
|
528
744
|
if (!argv.quiet) {
|
|
529
745
|
process.stdout.write("\n");
|
|
530
746
|
}
|
|
747
|
+
// Show analytics if enabled
|
|
748
|
+
// Show analytics and evaluation if enabled
|
|
749
|
+
displayAnalyticsAndEvaluation(result, argv);
|
|
531
750
|
return; // Exit early for agent mode
|
|
532
751
|
}
|
|
533
752
|
for await (const chunk of stream) {
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NeuroLink Config Manager with Backup/Restore System
|
|
3
|
+
* Industry standard configuration management with safety mechanisms
|
|
4
|
+
*/
|
|
5
|
+
import type { NeuroLinkConfig, ProviderConfig, BackupInfo, ConfigValidationResult, ConfigUpdateOptions } from "./types.js";
|
|
6
|
+
/**
|
|
7
|
+
* Enhanced Config Manager with automatic backup/restore capabilities
|
|
8
|
+
*/
|
|
9
|
+
export declare class NeuroLinkConfigManager {
|
|
10
|
+
private configPath;
|
|
11
|
+
private backupDir;
|
|
12
|
+
private config;
|
|
13
|
+
private configCache;
|
|
14
|
+
/**
|
|
15
|
+
* Load configuration with caching
|
|
16
|
+
*/
|
|
17
|
+
loadConfig(): Promise<NeuroLinkConfig>;
|
|
18
|
+
/**
|
|
19
|
+
* Update configuration with automatic backup
|
|
20
|
+
*/
|
|
21
|
+
updateConfig(updates: Partial<NeuroLinkConfig>, options?: ConfigUpdateOptions): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Create a backup with metadata
|
|
24
|
+
*/
|
|
25
|
+
createBackup(reason?: string): Promise<string>;
|
|
26
|
+
/**
|
|
27
|
+
* List all available backups
|
|
28
|
+
*/
|
|
29
|
+
listBackups(): Promise<BackupInfo[]>;
|
|
30
|
+
/**
|
|
31
|
+
* Restore from specific backup
|
|
32
|
+
*/
|
|
33
|
+
restoreFromBackup(backupFilename: string): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Restore from latest backup
|
|
36
|
+
*/
|
|
37
|
+
restoreLatestBackup(): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Clean up old backups
|
|
40
|
+
*/
|
|
41
|
+
cleanupOldBackups(keepCount?: number): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Update provider status
|
|
44
|
+
*/
|
|
45
|
+
updateProviderStatus(providerId: string, status: Partial<ProviderConfig>): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Validate configuration
|
|
48
|
+
*/
|
|
49
|
+
validateConfig(config: NeuroLinkConfig): Promise<ConfigValidationResult>;
|
|
50
|
+
/**
|
|
51
|
+
* Generate default configuration
|
|
52
|
+
*/
|
|
53
|
+
generateDefaultConfig(): Promise<NeuroLinkConfig>;
|
|
54
|
+
private ensureBackupDirectory;
|
|
55
|
+
private readConfigFile;
|
|
56
|
+
private persistConfig;
|
|
57
|
+
private generateConfigHash;
|
|
58
|
+
private extractMetadataFromBackup;
|
|
59
|
+
private extractConfigFromBackup;
|
|
60
|
+
}
|