@juspay/neurolink 1.5.3 → 1.9.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 +241 -1
- package/README.md +113 -20
- package/dist/agent/direct-tools.d.ts +1203 -0
- package/dist/agent/direct-tools.js +387 -0
- package/dist/cli/commands/agent-generate.d.ts +2 -0
- package/dist/cli/commands/agent-generate.js +70 -0
- package/dist/cli/commands/config.d.ts +76 -9
- package/dist/cli/commands/config.js +358 -233
- package/dist/cli/commands/mcp.d.ts +2 -1
- package/dist/cli/commands/mcp.js +874 -146
- package/dist/cli/commands/ollama.d.ts +8 -0
- package/dist/cli/commands/ollama.js +333 -0
- package/dist/cli/index.js +591 -327
- package/dist/cli/utils/complete-setup.d.ts +19 -0
- package/dist/cli/utils/complete-setup.js +81 -0
- package/dist/cli/utils/env-manager.d.ts +44 -0
- package/dist/cli/utils/env-manager.js +226 -0
- package/dist/cli/utils/interactive-setup.d.ts +48 -0
- package/dist/cli/utils/interactive-setup.js +302 -0
- package/dist/core/dynamic-models.d.ts +208 -0
- package/dist/core/dynamic-models.js +250 -0
- package/dist/core/factory.d.ts +13 -6
- package/dist/core/factory.js +180 -50
- package/dist/core/types.d.ts +8 -3
- package/dist/core/types.js +7 -4
- package/dist/index.d.ts +16 -16
- package/dist/index.js +16 -16
- package/dist/lib/agent/direct-tools.d.ts +1203 -0
- package/dist/lib/agent/direct-tools.js +387 -0
- package/dist/lib/core/dynamic-models.d.ts +208 -0
- package/dist/lib/core/dynamic-models.js +250 -0
- package/dist/lib/core/factory.d.ts +13 -6
- package/dist/lib/core/factory.js +180 -50
- package/dist/lib/core/types.d.ts +8 -3
- package/dist/lib/core/types.js +7 -4
- package/dist/lib/index.d.ts +16 -16
- package/dist/lib/index.js +16 -16
- package/dist/lib/mcp/auto-discovery.d.ts +120 -0
- package/dist/lib/mcp/auto-discovery.js +793 -0
- package/dist/lib/mcp/client.d.ts +66 -0
- package/dist/lib/mcp/client.js +245 -0
- package/dist/lib/mcp/config.d.ts +31 -0
- package/dist/lib/mcp/config.js +74 -0
- package/dist/lib/mcp/context-manager.d.ts +4 -4
- package/dist/lib/mcp/context-manager.js +24 -18
- package/dist/lib/mcp/factory.d.ts +28 -11
- package/dist/lib/mcp/factory.js +36 -29
- package/dist/lib/mcp/function-calling.d.ts +51 -0
- package/dist/lib/mcp/function-calling.js +510 -0
- package/dist/lib/mcp/index.d.ts +190 -0
- package/dist/lib/mcp/index.js +156 -0
- package/dist/lib/mcp/initialize-tools.d.ts +28 -0
- package/dist/lib/mcp/initialize-tools.js +209 -0
- package/dist/lib/mcp/initialize.d.ts +17 -0
- package/dist/lib/mcp/initialize.js +51 -0
- package/dist/lib/mcp/logging.d.ts +71 -0
- package/dist/lib/mcp/logging.js +183 -0
- package/dist/lib/mcp/manager.d.ts +67 -0
- package/dist/lib/mcp/manager.js +176 -0
- package/dist/lib/mcp/neurolink-mcp-client.d.ts +96 -0
- package/dist/lib/mcp/neurolink-mcp-client.js +417 -0
- package/dist/lib/mcp/orchestrator.d.ts +3 -3
- package/dist/lib/mcp/orchestrator.js +46 -43
- package/dist/lib/mcp/registry.d.ts +2 -2
- package/dist/lib/mcp/registry.js +42 -33
- package/dist/lib/mcp/servers/ai-providers/ai-analysis-tools.d.ts +1 -1
- package/dist/lib/mcp/servers/ai-providers/ai-analysis-tools.js +205 -66
- package/dist/lib/mcp/servers/ai-providers/ai-core-server.js +143 -99
- package/dist/lib/mcp/servers/ai-providers/ai-workflow-tools.d.ts +6 -6
- package/dist/lib/mcp/servers/ai-providers/ai-workflow-tools.js +404 -251
- package/dist/lib/mcp/servers/utilities/utility-server.d.ts +8 -0
- package/dist/lib/mcp/servers/utilities/utility-server.js +326 -0
- package/dist/lib/mcp/tool-integration.d.ts +67 -0
- package/dist/lib/mcp/tool-integration.js +179 -0
- package/dist/lib/mcp/unified-registry.d.ts +269 -0
- package/dist/lib/mcp/unified-registry.js +1411 -0
- package/dist/lib/neurolink.d.ts +68 -6
- package/dist/lib/neurolink.js +314 -42
- package/dist/lib/providers/agent-enhanced-provider.d.ts +59 -0
- package/dist/lib/providers/agent-enhanced-provider.js +242 -0
- package/dist/lib/providers/amazonBedrock.d.ts +3 -3
- package/dist/lib/providers/amazonBedrock.js +54 -50
- package/dist/lib/providers/anthropic.d.ts +2 -2
- package/dist/lib/providers/anthropic.js +92 -84
- package/dist/lib/providers/azureOpenAI.d.ts +2 -2
- package/dist/lib/providers/azureOpenAI.js +97 -86
- package/dist/lib/providers/function-calling-provider.d.ts +70 -0
- package/dist/lib/providers/function-calling-provider.js +359 -0
- package/dist/lib/providers/googleAIStudio.d.ts +10 -5
- package/dist/lib/providers/googleAIStudio.js +60 -38
- package/dist/lib/providers/googleVertexAI.d.ts +3 -3
- package/dist/lib/providers/googleVertexAI.js +96 -86
- package/dist/lib/providers/huggingFace.d.ts +31 -0
- package/dist/lib/providers/huggingFace.js +362 -0
- package/dist/lib/providers/index.d.ts +14 -8
- package/dist/lib/providers/index.js +18 -12
- package/dist/lib/providers/mcp-provider.d.ts +62 -0
- package/dist/lib/providers/mcp-provider.js +183 -0
- package/dist/lib/providers/mistralAI.d.ts +32 -0
- package/dist/lib/providers/mistralAI.js +223 -0
- package/dist/lib/providers/ollama.d.ts +51 -0
- package/dist/lib/providers/ollama.js +508 -0
- package/dist/lib/providers/openAI.d.ts +7 -3
- package/dist/lib/providers/openAI.js +45 -33
- package/dist/lib/utils/logger.js +2 -2
- package/dist/lib/utils/providerUtils.js +59 -22
- package/dist/mcp/auto-discovery.d.ts +120 -0
- package/dist/mcp/auto-discovery.js +794 -0
- package/dist/mcp/client.d.ts +66 -0
- package/dist/mcp/client.js +245 -0
- package/dist/mcp/config.d.ts +31 -0
- package/dist/mcp/config.js +74 -0
- package/dist/mcp/context-manager.d.ts +4 -4
- package/dist/mcp/context-manager.js +24 -18
- package/dist/mcp/factory.d.ts +28 -11
- package/dist/mcp/factory.js +36 -29
- package/dist/mcp/function-calling.d.ts +51 -0
- package/dist/mcp/function-calling.js +510 -0
- package/dist/mcp/index.d.ts +190 -0
- package/dist/mcp/index.js +156 -0
- package/dist/mcp/initialize-tools.d.ts +28 -0
- package/dist/mcp/initialize-tools.js +210 -0
- package/dist/mcp/initialize.d.ts +17 -0
- package/dist/mcp/initialize.js +51 -0
- package/dist/mcp/logging.d.ts +71 -0
- package/dist/mcp/logging.js +183 -0
- package/dist/mcp/manager.d.ts +67 -0
- package/dist/mcp/manager.js +176 -0
- package/dist/mcp/neurolink-mcp-client.d.ts +96 -0
- package/dist/mcp/neurolink-mcp-client.js +417 -0
- package/dist/mcp/orchestrator.d.ts +3 -3
- package/dist/mcp/orchestrator.js +46 -43
- package/dist/mcp/registry.d.ts +2 -2
- package/dist/mcp/registry.js +42 -33
- package/dist/mcp/servers/ai-providers/ai-analysis-tools.d.ts +1 -1
- package/dist/mcp/servers/ai-providers/ai-analysis-tools.js +205 -66
- package/dist/mcp/servers/ai-providers/ai-core-server.js +143 -99
- package/dist/mcp/servers/ai-providers/ai-workflow-tools.d.ts +6 -6
- package/dist/mcp/servers/ai-providers/ai-workflow-tools.js +404 -253
- package/dist/mcp/servers/utilities/utility-server.d.ts +8 -0
- package/dist/mcp/servers/utilities/utility-server.js +326 -0
- package/dist/mcp/tool-integration.d.ts +67 -0
- package/dist/mcp/tool-integration.js +179 -0
- package/dist/mcp/unified-registry.d.ts +269 -0
- package/dist/mcp/unified-registry.js +1411 -0
- package/dist/neurolink.d.ts +68 -6
- package/dist/neurolink.js +314 -42
- package/dist/providers/agent-enhanced-provider.d.ts +59 -0
- package/dist/providers/agent-enhanced-provider.js +242 -0
- package/dist/providers/amazonBedrock.d.ts +3 -3
- package/dist/providers/amazonBedrock.js +54 -50
- package/dist/providers/anthropic.d.ts +2 -2
- package/dist/providers/anthropic.js +92 -84
- package/dist/providers/azureOpenAI.d.ts +2 -2
- package/dist/providers/azureOpenAI.js +97 -86
- package/dist/providers/function-calling-provider.d.ts +70 -0
- package/dist/providers/function-calling-provider.js +359 -0
- package/dist/providers/googleAIStudio.d.ts +10 -5
- package/dist/providers/googleAIStudio.js +60 -38
- package/dist/providers/googleVertexAI.d.ts +3 -3
- package/dist/providers/googleVertexAI.js +96 -86
- package/dist/providers/huggingFace.d.ts +31 -0
- package/dist/providers/huggingFace.js +362 -0
- package/dist/providers/index.d.ts +14 -8
- package/dist/providers/index.js +18 -12
- package/dist/providers/mcp-provider.d.ts +62 -0
- package/dist/providers/mcp-provider.js +183 -0
- package/dist/providers/mistralAI.d.ts +32 -0
- package/dist/providers/mistralAI.js +223 -0
- package/dist/providers/ollama.d.ts +51 -0
- package/dist/providers/ollama.js +508 -0
- package/dist/providers/openAI.d.ts +7 -3
- package/dist/providers/openAI.js +45 -33
- package/dist/utils/logger.js +2 -2
- package/dist/utils/providerUtils.js +59 -22
- package/package.json +28 -4
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Complete Setup Integration for NeuroLink CLI
|
|
3
|
+
*
|
|
4
|
+
* Orchestrates the entire setup process: interactive wizard, environment management,
|
|
5
|
+
* provider testing, and summary display.
|
|
6
|
+
*/
|
|
7
|
+
import { type SetupResult } from "./interactive-setup.js";
|
|
8
|
+
/**
|
|
9
|
+
* Run the complete interactive setup process
|
|
10
|
+
*/
|
|
11
|
+
export declare function runCompleteSetup(quiet?: boolean): Promise<SetupResult>;
|
|
12
|
+
/**
|
|
13
|
+
* Wrapper for config setup command
|
|
14
|
+
*/
|
|
15
|
+
export declare function configSetup(quiet?: boolean): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Wrapper for config init command (alias for setup)
|
|
18
|
+
*/
|
|
19
|
+
export declare function configInit(quiet?: boolean): Promise<void>;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Complete Setup Integration for NeuroLink CLI
|
|
3
|
+
*
|
|
4
|
+
* Orchestrates the entire setup process: interactive wizard, environment management,
|
|
5
|
+
* provider testing, and summary display.
|
|
6
|
+
*/
|
|
7
|
+
import { runInteractiveSetup, testProviderConnectivity, displaySetupSummary, } from "./interactive-setup.js";
|
|
8
|
+
import { updateEnvFile, displayEnvUpdateSummary } from "./env-manager.js";
|
|
9
|
+
import chalk from "chalk";
|
|
10
|
+
/**
|
|
11
|
+
* Run the complete interactive setup process
|
|
12
|
+
*/
|
|
13
|
+
export async function runCompleteSetup(quiet = false) {
|
|
14
|
+
try {
|
|
15
|
+
// Step 1: Run interactive setup wizard
|
|
16
|
+
if (!quiet) {
|
|
17
|
+
console.log(chalk.blue("🚀 Starting NeuroLink Configuration Setup...\n"));
|
|
18
|
+
}
|
|
19
|
+
const setupResult = await runInteractiveSetup(quiet);
|
|
20
|
+
// If no providers selected, exit early
|
|
21
|
+
if (setupResult.selectedProviders.length === 0) {
|
|
22
|
+
if (!quiet) {
|
|
23
|
+
console.log(chalk.yellow("⚠️ No providers selected. Setup cancelled."));
|
|
24
|
+
}
|
|
25
|
+
return setupResult;
|
|
26
|
+
}
|
|
27
|
+
// Step 2: Update environment file with credentials
|
|
28
|
+
if (Object.keys(setupResult.credentials).length > 0) {
|
|
29
|
+
if (!quiet) {
|
|
30
|
+
console.log(chalk.blue("\n💾 Updating environment configuration...\n"));
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
const envResult = updateEnvFile(setupResult.credentials, ".env", true);
|
|
34
|
+
setupResult.envFileBackup = envResult.backup.backupPath;
|
|
35
|
+
if (!quiet) {
|
|
36
|
+
displayEnvUpdateSummary(envResult, false);
|
|
37
|
+
}
|
|
38
|
+
// Update process.env for immediate testing
|
|
39
|
+
for (const [key, value] of Object.entries(setupResult.credentials)) {
|
|
40
|
+
process.env[key] = value;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
if (!quiet) {
|
|
45
|
+
console.error(chalk.red(`❌ Failed to update environment file: ${error instanceof Error ? error.message : String(error)}`));
|
|
46
|
+
}
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
// Step 3: Test provider connectivity
|
|
51
|
+
if (!quiet) {
|
|
52
|
+
console.log(chalk.blue("\n🧪 Testing configured providers...\n"));
|
|
53
|
+
}
|
|
54
|
+
setupResult.testResults = await testProviderConnectivity(setupResult.selectedProviders, quiet);
|
|
55
|
+
// Step 4: Display summary
|
|
56
|
+
displaySetupSummary(setupResult, quiet);
|
|
57
|
+
return setupResult;
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
if (!quiet) {
|
|
61
|
+
console.error(chalk.red(`❌ Setup failed: ${error instanceof Error ? error.message : String(error)}`));
|
|
62
|
+
console.log(chalk.yellow("💡 You can retry setup with: neurolink config setup"));
|
|
63
|
+
}
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Wrapper for config setup command
|
|
69
|
+
*/
|
|
70
|
+
export async function configSetup(quiet = false) {
|
|
71
|
+
await runCompleteSetup(quiet);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Wrapper for config init command (alias for setup)
|
|
75
|
+
*/
|
|
76
|
+
export async function configInit(quiet = false) {
|
|
77
|
+
if (!quiet) {
|
|
78
|
+
console.log(chalk.gray("📝 config init is an alias for config setup\n"));
|
|
79
|
+
}
|
|
80
|
+
await runCompleteSetup(quiet);
|
|
81
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment File Management Utilities for NeuroLink CLI
|
|
3
|
+
*
|
|
4
|
+
* Handles .env file operations including backup, update, and validation.
|
|
5
|
+
*/
|
|
6
|
+
export interface EnvBackupResult {
|
|
7
|
+
backupPath?: string;
|
|
8
|
+
existed: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface EnvUpdateResult {
|
|
11
|
+
backup: EnvBackupResult;
|
|
12
|
+
updated: string[];
|
|
13
|
+
added: string[];
|
|
14
|
+
unchanged: string[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Create a timestamped backup of the existing .env file
|
|
18
|
+
*/
|
|
19
|
+
export declare function backupEnvFile(envPath?: string): EnvBackupResult;
|
|
20
|
+
/**
|
|
21
|
+
* Parse .env file content into key-value pairs
|
|
22
|
+
*/
|
|
23
|
+
export declare function parseEnvFile(content: string): Record<string, string>;
|
|
24
|
+
/**
|
|
25
|
+
* Generate .env file content from key-value pairs
|
|
26
|
+
*/
|
|
27
|
+
export declare function generateEnvContent(envVars: Record<string, string>, existingContent?: string): string;
|
|
28
|
+
/**
|
|
29
|
+
* Update .env file with new environment variables
|
|
30
|
+
*/
|
|
31
|
+
export declare function updateEnvFile(newVars: Record<string, string>, envPath?: string, createBackup?: boolean): EnvUpdateResult;
|
|
32
|
+
/**
|
|
33
|
+
* Display environment file update summary
|
|
34
|
+
*/
|
|
35
|
+
export declare function displayEnvUpdateSummary(result: EnvUpdateResult, quiet?: boolean): void;
|
|
36
|
+
/**
|
|
37
|
+
* Validate .env file format and required variables
|
|
38
|
+
*/
|
|
39
|
+
export declare function validateEnvFile(envPath?: string, requiredVars?: string[]): {
|
|
40
|
+
valid: boolean;
|
|
41
|
+
errors: string[];
|
|
42
|
+
warnings: string[];
|
|
43
|
+
variables: Record<string, string>;
|
|
44
|
+
};
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment File Management Utilities for NeuroLink CLI
|
|
3
|
+
*
|
|
4
|
+
* Handles .env file operations including backup, update, and validation.
|
|
5
|
+
*/
|
|
6
|
+
import fs from "fs";
|
|
7
|
+
import chalk from "chalk";
|
|
8
|
+
/**
|
|
9
|
+
* Create a timestamped backup of the existing .env file
|
|
10
|
+
*/
|
|
11
|
+
export function backupEnvFile(envPath = ".env") {
|
|
12
|
+
const result = {
|
|
13
|
+
existed: false,
|
|
14
|
+
};
|
|
15
|
+
if (fs.existsSync(envPath)) {
|
|
16
|
+
result.existed = true;
|
|
17
|
+
const timestamp = new Date()
|
|
18
|
+
.toISOString()
|
|
19
|
+
.replace(/[:.]/g, "-")
|
|
20
|
+
.replace("T", "_")
|
|
21
|
+
.split(".")[0]; // Remove milliseconds
|
|
22
|
+
const backupPath = `${envPath}.backup.${timestamp}`;
|
|
23
|
+
try {
|
|
24
|
+
fs.copyFileSync(envPath, backupPath);
|
|
25
|
+
result.backupPath = backupPath;
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
throw new Error(`Failed to create backup: ${error instanceof Error ? error.message : String(error)}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Parse .env file content into key-value pairs
|
|
35
|
+
*/
|
|
36
|
+
export function parseEnvFile(content) {
|
|
37
|
+
const result = {};
|
|
38
|
+
const lines = content.split("\n");
|
|
39
|
+
for (const line of lines) {
|
|
40
|
+
const trimmedLine = line.trim();
|
|
41
|
+
// Skip empty lines and comments
|
|
42
|
+
if (!trimmedLine || trimmedLine.startsWith("#")) {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
// Find the first = character
|
|
46
|
+
const equalIndex = trimmedLine.indexOf("=");
|
|
47
|
+
if (equalIndex === -1) {
|
|
48
|
+
continue; // Invalid line format
|
|
49
|
+
}
|
|
50
|
+
const key = trimmedLine.substring(0, equalIndex).trim();
|
|
51
|
+
const value = trimmedLine.substring(equalIndex + 1).trim();
|
|
52
|
+
// Remove surrounding quotes if present
|
|
53
|
+
const cleanValue = value.replace(/^["']|["']$/g, "");
|
|
54
|
+
result[key] = cleanValue;
|
|
55
|
+
}
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Generate .env file content from key-value pairs
|
|
60
|
+
*/
|
|
61
|
+
export function generateEnvContent(envVars, existingContent) {
|
|
62
|
+
const lines = [];
|
|
63
|
+
const existingVars = existingContent ? parseEnvFile(existingContent) : {};
|
|
64
|
+
const processedKeys = new Set();
|
|
65
|
+
// If we have existing content, preserve its structure and comments
|
|
66
|
+
if (existingContent) {
|
|
67
|
+
const existingLines = existingContent.split("\n");
|
|
68
|
+
for (const line of existingLines) {
|
|
69
|
+
const trimmedLine = line.trim();
|
|
70
|
+
// Preserve comments and empty lines
|
|
71
|
+
if (!trimmedLine || trimmedLine.startsWith("#")) {
|
|
72
|
+
lines.push(line);
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
const equalIndex = trimmedLine.indexOf("=");
|
|
76
|
+
if (equalIndex === -1) {
|
|
77
|
+
lines.push(line); // Preserve invalid lines as-is
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
const key = trimmedLine.substring(0, equalIndex).trim();
|
|
81
|
+
if (Object.prototype.hasOwnProperty.call(envVars, key)) {
|
|
82
|
+
// Update existing variable
|
|
83
|
+
lines.push(`${key}=${envVars[key]}`);
|
|
84
|
+
processedKeys.add(key);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
// Preserve existing variable
|
|
88
|
+
lines.push(line);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
// Add new variables that weren't in the existing file
|
|
93
|
+
const newVars = Object.keys(envVars).filter((key) => !processedKeys.has(key));
|
|
94
|
+
if (newVars.length > 0) {
|
|
95
|
+
if (lines.length > 0 && lines[lines.length - 1].trim() !== "") {
|
|
96
|
+
lines.push(""); // Add blank line before new variables
|
|
97
|
+
}
|
|
98
|
+
if (!existingContent) {
|
|
99
|
+
lines.push("# NeuroLink AI Provider Configuration");
|
|
100
|
+
}
|
|
101
|
+
for (const key of newVars) {
|
|
102
|
+
lines.push(`${key}=${envVars[key]}`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return lines.join("\n") + (lines.length > 0 ? "\n" : "");
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Update .env file with new environment variables
|
|
109
|
+
*/
|
|
110
|
+
export function updateEnvFile(newVars, envPath = ".env", createBackup = true) {
|
|
111
|
+
const result = {
|
|
112
|
+
backup: { existed: false },
|
|
113
|
+
updated: [],
|
|
114
|
+
added: [],
|
|
115
|
+
unchanged: [],
|
|
116
|
+
};
|
|
117
|
+
// Create backup if requested and file exists
|
|
118
|
+
if (createBackup) {
|
|
119
|
+
result.backup = backupEnvFile(envPath);
|
|
120
|
+
}
|
|
121
|
+
// Read existing content
|
|
122
|
+
let existingContent = "";
|
|
123
|
+
let existingVars = {};
|
|
124
|
+
if (fs.existsSync(envPath)) {
|
|
125
|
+
existingContent = fs.readFileSync(envPath, "utf8");
|
|
126
|
+
existingVars = parseEnvFile(existingContent);
|
|
127
|
+
}
|
|
128
|
+
// Categorize changes
|
|
129
|
+
for (const [key, value] of Object.entries(newVars)) {
|
|
130
|
+
if (Object.prototype.hasOwnProperty.call(existingVars, key)) {
|
|
131
|
+
if (existingVars[key] !== value) {
|
|
132
|
+
result.updated.push(key);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
result.unchanged.push(key);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
result.added.push(key);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
// Generate new content
|
|
143
|
+
const newContent = generateEnvContent(newVars, existingContent);
|
|
144
|
+
// Write updated file
|
|
145
|
+
try {
|
|
146
|
+
fs.writeFileSync(envPath, newContent, "utf8");
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
throw new Error(`Failed to write .env file: ${error instanceof Error ? error.message : String(error)}`);
|
|
150
|
+
}
|
|
151
|
+
return result;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Display environment file update summary
|
|
155
|
+
*/
|
|
156
|
+
export function displayEnvUpdateSummary(result, quiet = false) {
|
|
157
|
+
if (quiet) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
if (result.backup.existed && result.backup.backupPath) {
|
|
161
|
+
console.log(chalk.gray(`💾 Created backup: ${result.backup.backupPath}`));
|
|
162
|
+
}
|
|
163
|
+
if (result.added.length > 0) {
|
|
164
|
+
console.log(chalk.green(`➕ Added ${result.added.length} new variables: ${result.added.join(", ")}`));
|
|
165
|
+
}
|
|
166
|
+
if (result.updated.length > 0) {
|
|
167
|
+
console.log(chalk.yellow(`🔄 Updated ${result.updated.length} existing variables: ${result.updated.join(", ")}`));
|
|
168
|
+
}
|
|
169
|
+
if (result.unchanged.length > 0) {
|
|
170
|
+
console.log(chalk.gray(`✓ ${result.unchanged.length} variables unchanged: ${result.unchanged.join(", ")}`));
|
|
171
|
+
}
|
|
172
|
+
const totalChanges = result.added.length + result.updated.length;
|
|
173
|
+
if (totalChanges > 0) {
|
|
174
|
+
console.log(chalk.blue(`📝 Environment file updated with ${totalChanges} changes`));
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
console.log(chalk.gray("📝 No changes needed to environment file"));
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Validate .env file format and required variables
|
|
182
|
+
*/
|
|
183
|
+
export function validateEnvFile(envPath = ".env", requiredVars = []) {
|
|
184
|
+
const result = {
|
|
185
|
+
valid: true,
|
|
186
|
+
errors: [],
|
|
187
|
+
warnings: [],
|
|
188
|
+
variables: {},
|
|
189
|
+
};
|
|
190
|
+
if (!fs.existsSync(envPath)) {
|
|
191
|
+
result.valid = false;
|
|
192
|
+
result.errors.push(`Environment file not found: ${envPath}`);
|
|
193
|
+
return result;
|
|
194
|
+
}
|
|
195
|
+
try {
|
|
196
|
+
const content = fs.readFileSync(envPath, "utf8");
|
|
197
|
+
result.variables = parseEnvFile(content);
|
|
198
|
+
// Check for required variables
|
|
199
|
+
for (const requiredVar of requiredVars) {
|
|
200
|
+
if (!Object.prototype.hasOwnProperty.call(result.variables, requiredVar) ||
|
|
201
|
+
!result.variables[requiredVar]) {
|
|
202
|
+
result.valid = false;
|
|
203
|
+
result.errors.push(`Missing required variable: ${requiredVar}`);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
// Check for common formatting issues
|
|
207
|
+
const lines = content.split("\n");
|
|
208
|
+
for (let i = 0; i < lines.length; i++) {
|
|
209
|
+
const line = lines[i].trim();
|
|
210
|
+
if (!line || line.startsWith("#")) {
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
if (!line.includes("=")) {
|
|
214
|
+
result.warnings.push(`Line ${i + 1}: Invalid format (missing =)`);
|
|
215
|
+
}
|
|
216
|
+
else if (line.startsWith("=")) {
|
|
217
|
+
result.warnings.push(`Line ${i + 1}: Empty variable name`);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
catch (error) {
|
|
222
|
+
result.valid = false;
|
|
223
|
+
result.errors.push(`Failed to read environment file: ${error instanceof Error ? error.message : String(error)}`);
|
|
224
|
+
}
|
|
225
|
+
return result;
|
|
226
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interactive Setup Utilities for NeuroLink CLI
|
|
3
|
+
*
|
|
4
|
+
* Provides interactive configuration wizard with provider selection,
|
|
5
|
+
* credential collection, testing, and environment file management.
|
|
6
|
+
*/
|
|
7
|
+
import { AIProviderName } from "../../lib/core/types.js";
|
|
8
|
+
export interface ProviderConfig {
|
|
9
|
+
id: AIProviderName;
|
|
10
|
+
name: string;
|
|
11
|
+
description: string;
|
|
12
|
+
envVars: Array<{
|
|
13
|
+
key: string;
|
|
14
|
+
prompt: string;
|
|
15
|
+
secure?: boolean;
|
|
16
|
+
default?: string;
|
|
17
|
+
optional?: boolean;
|
|
18
|
+
}>;
|
|
19
|
+
}
|
|
20
|
+
export declare const PROVIDER_CONFIGS: ProviderConfig[];
|
|
21
|
+
export interface SetupResult {
|
|
22
|
+
selectedProviders: AIProviderName[];
|
|
23
|
+
credentials: Record<string, string>;
|
|
24
|
+
envFileBackup?: string;
|
|
25
|
+
testResults: Array<{
|
|
26
|
+
provider: AIProviderName;
|
|
27
|
+
status: "working" | "failed";
|
|
28
|
+
error?: string;
|
|
29
|
+
responseTime?: number;
|
|
30
|
+
}>;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Run the interactive setup wizard
|
|
34
|
+
*/
|
|
35
|
+
export declare function runInteractiveSetup(quiet?: boolean): Promise<SetupResult>;
|
|
36
|
+
/**
|
|
37
|
+
* Test provider connectivity using existing logic
|
|
38
|
+
*/
|
|
39
|
+
export declare function testProviderConnectivity(providers: AIProviderName[], quiet?: boolean): Promise<Array<{
|
|
40
|
+
provider: AIProviderName;
|
|
41
|
+
status: "working" | "failed";
|
|
42
|
+
error?: string;
|
|
43
|
+
responseTime?: number;
|
|
44
|
+
}>>;
|
|
45
|
+
/**
|
|
46
|
+
* Display setup summary
|
|
47
|
+
*/
|
|
48
|
+
export declare function displaySetupSummary(result: SetupResult, quiet?: boolean): void;
|