@juspay/neurolink 7.0.0 → 7.2.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.
Files changed (101) hide show
  1. package/CHANGELOG.md +15 -4
  2. package/README.md +16 -11
  3. package/dist/cli/commands/config.d.ts +2 -2
  4. package/dist/cli/commands/config.js +22 -21
  5. package/dist/cli/commands/mcp.d.ts +79 -0
  6. package/dist/cli/commands/mcp.js +916 -0
  7. package/dist/cli/commands/models.d.ts +63 -0
  8. package/dist/cli/commands/models.js +653 -0
  9. package/dist/cli/commands/ollama.js +56 -55
  10. package/dist/cli/factories/commandFactory.d.ts +67 -2
  11. package/dist/cli/factories/commandFactory.js +840 -92
  12. package/dist/cli/index.d.ts +6 -0
  13. package/dist/cli/index.js +42 -999
  14. package/dist/cli/utils/completeSetup.js +9 -8
  15. package/dist/cli/utils/envManager.js +7 -6
  16. package/dist/cli/utils/interactiveSetup.js +20 -19
  17. package/dist/core/analytics.js +25 -38
  18. package/dist/core/baseProvider.d.ts +8 -0
  19. package/dist/core/baseProvider.js +177 -68
  20. package/dist/core/constants.d.ts +11 -0
  21. package/dist/core/constants.js +17 -0
  22. package/dist/core/evaluation.js +25 -14
  23. package/dist/core/factory.js +21 -18
  24. package/dist/core/streamAnalytics.d.ts +65 -0
  25. package/dist/core/streamAnalytics.js +125 -0
  26. package/dist/factories/providerRegistry.js +3 -1
  27. package/dist/lib/core/analytics.js +25 -38
  28. package/dist/lib/core/baseProvider.d.ts +8 -0
  29. package/dist/lib/core/baseProvider.js +177 -68
  30. package/dist/lib/core/constants.d.ts +11 -0
  31. package/dist/lib/core/constants.js +17 -0
  32. package/dist/lib/core/evaluation.js +25 -14
  33. package/dist/lib/core/factory.js +22 -18
  34. package/dist/lib/core/streamAnalytics.d.ts +65 -0
  35. package/dist/lib/core/streamAnalytics.js +125 -0
  36. package/dist/lib/factories/providerRegistry.js +3 -1
  37. package/dist/lib/mcp/toolRegistry.d.ts +5 -0
  38. package/dist/lib/mcp/toolRegistry.js +60 -0
  39. package/dist/lib/models/modelRegistry.d.ts +132 -0
  40. package/dist/lib/models/modelRegistry.js +483 -0
  41. package/dist/lib/models/modelResolver.d.ts +115 -0
  42. package/dist/lib/models/modelResolver.js +467 -0
  43. package/dist/lib/neurolink.d.ts +4 -1
  44. package/dist/lib/neurolink.js +108 -69
  45. package/dist/lib/providers/anthropic.js +3 -0
  46. package/dist/lib/providers/googleAiStudio.js +13 -0
  47. package/dist/lib/providers/huggingFace.js +15 -3
  48. package/dist/lib/providers/mistral.js +19 -7
  49. package/dist/lib/providers/ollama.js +31 -7
  50. package/dist/lib/providers/openAI.js +12 -0
  51. package/dist/lib/sdk/toolRegistration.js +17 -0
  52. package/dist/lib/types/cli.d.ts +56 -1
  53. package/dist/lib/types/contextTypes.d.ts +110 -0
  54. package/dist/lib/types/contextTypes.js +176 -0
  55. package/dist/lib/types/index.d.ts +4 -1
  56. package/dist/lib/types/mcpTypes.d.ts +118 -7
  57. package/dist/lib/types/providers.d.ts +81 -0
  58. package/dist/lib/types/streamTypes.d.ts +44 -7
  59. package/dist/lib/types/tools.d.ts +9 -0
  60. package/dist/lib/types/universalProviderOptions.d.ts +3 -1
  61. package/dist/lib/types/universalProviderOptions.js +2 -1
  62. package/dist/lib/utils/logger.d.ts +7 -0
  63. package/dist/lib/utils/logger.js +16 -6
  64. package/dist/lib/utils/performance.d.ts +105 -0
  65. package/dist/lib/utils/performance.js +210 -0
  66. package/dist/lib/utils/providerUtils.js +9 -2
  67. package/dist/lib/utils/retryHandler.d.ts +89 -0
  68. package/dist/lib/utils/retryHandler.js +269 -0
  69. package/dist/mcp/toolRegistry.d.ts +5 -0
  70. package/dist/mcp/toolRegistry.js +60 -0
  71. package/dist/models/modelRegistry.d.ts +132 -0
  72. package/dist/models/modelRegistry.js +483 -0
  73. package/dist/models/modelResolver.d.ts +115 -0
  74. package/dist/models/modelResolver.js +468 -0
  75. package/dist/neurolink.d.ts +4 -1
  76. package/dist/neurolink.js +108 -69
  77. package/dist/providers/anthropic.js +3 -0
  78. package/dist/providers/googleAiStudio.js +13 -0
  79. package/dist/providers/huggingFace.js +15 -3
  80. package/dist/providers/mistral.js +19 -7
  81. package/dist/providers/ollama.js +31 -7
  82. package/dist/providers/openAI.js +12 -0
  83. package/dist/sdk/toolRegistration.js +17 -0
  84. package/dist/types/cli.d.ts +56 -1
  85. package/dist/types/contextTypes.d.ts +110 -0
  86. package/dist/types/contextTypes.js +177 -0
  87. package/dist/types/index.d.ts +4 -1
  88. package/dist/types/mcpTypes.d.ts +118 -7
  89. package/dist/types/providers.d.ts +81 -0
  90. package/dist/types/streamTypes.d.ts +44 -7
  91. package/dist/types/tools.d.ts +9 -0
  92. package/dist/types/universalProviderOptions.d.ts +3 -1
  93. package/dist/types/universalProviderOptions.js +3 -1
  94. package/dist/utils/logger.d.ts +7 -0
  95. package/dist/utils/logger.js +16 -6
  96. package/dist/utils/performance.d.ts +105 -0
  97. package/dist/utils/performance.js +210 -0
  98. package/dist/utils/providerUtils.js +9 -2
  99. package/dist/utils/retryHandler.d.ts +89 -0
  100. package/dist/utils/retryHandler.js +269 -0
  101. package/package.json +2 -1
@@ -2,6 +2,7 @@ import { execSync } from "child_process";
2
2
  import chalk from "chalk";
3
3
  import ora from "ora";
4
4
  import inquirer from "inquirer";
5
+ import { logger } from "../../lib/utils/logger.js";
5
6
  export function addOllamaCommands(cli) {
6
7
  cli.command("ollama <command>", "Manage Ollama local AI models", (yargs) => {
7
8
  return yargs
@@ -33,33 +34,33 @@ async function listModelsHandler() {
33
34
  const output = execSync("ollama list", { encoding: "utf8" });
34
35
  spinner.succeed("Installed models:");
35
36
  if (output.trim()) {
36
- console.log(output);
37
+ logger.always(output);
37
38
  }
38
39
  else {
39
- console.log(chalk.yellow('No models installed. Use "neurolink ollama pull <model>" to download a model.'));
40
+ logger.always(chalk.yellow('No models installed. Use "neurolink ollama pull <model>" to download a model.'));
40
41
  }
41
42
  }
42
43
  catch (error) {
43
44
  spinner.fail("Failed to list models. Is Ollama installed?");
44
45
  const errorMessage = error instanceof Error ? error.message : String(error);
45
- console.error(chalk.red("Error:", errorMessage));
46
- console.log(chalk.blue("\nTip: Install Ollama from https://ollama.ai"));
46
+ logger.error(chalk.red("Error:", errorMessage));
47
+ logger.always(chalk.blue("\nTip: Install Ollama from https://ollama.ai"));
47
48
  process.exit(1);
48
49
  }
49
50
  }
50
51
  async function pullModelHandler(argv) {
51
52
  const { model } = argv;
52
- console.log(chalk.blue(`Downloading model: ${model}`));
53
- console.log(chalk.gray("This may take several minutes..."));
53
+ logger.always(chalk.blue(`Downloading model: ${model}`));
54
+ logger.always(chalk.gray("This may take several minutes..."));
54
55
  try {
55
56
  execSync(`ollama pull ${model}`, { stdio: "inherit" });
56
- console.log(chalk.green(`\n✅ Successfully downloaded ${model}`));
57
- console.log(chalk.blue(`\nTest it with: npx @juspay/neurolink generate "Hello!" --provider ollama --model ${model}`));
57
+ logger.always(chalk.green(`\n✅ Successfully downloaded ${model}`));
58
+ logger.always(chalk.blue(`\nTest it with: npx @juspay/neurolink generate "Hello!" --provider ollama --model ${model}`));
58
59
  }
59
60
  catch (error) {
60
- console.error(chalk.red(`\n❌ Failed to download ${model}`));
61
+ logger.error(chalk.red(`\n❌ Failed to download ${model}`));
61
62
  const errorMessage = error instanceof Error ? error.message : String(error);
62
- console.error(chalk.red("Error:", errorMessage));
63
+ logger.error(chalk.red("Error:", errorMessage));
63
64
  process.exit(1);
64
65
  }
65
66
  }
@@ -75,7 +76,7 @@ async function removeModelHandler(argv) {
75
76
  },
76
77
  ]);
77
78
  if (!confirm) {
78
- console.log(chalk.yellow("Removal cancelled."));
79
+ logger.always(chalk.yellow("Removal cancelled."));
79
80
  return;
80
81
  }
81
82
  const spinner = ora(`Removing model ${model}...`).start();
@@ -86,7 +87,7 @@ async function removeModelHandler(argv) {
86
87
  catch (error) {
87
88
  spinner.fail(`Failed to remove ${model}`);
88
89
  const errorMessage = error instanceof Error ? error.message : String(error);
89
- console.error(chalk.red("Error:", errorMessage));
90
+ logger.error(chalk.red("Error:", errorMessage));
90
91
  process.exit(1);
91
92
  }
92
93
  }
@@ -103,7 +104,7 @@ async function statusHandler() {
103
104
  });
104
105
  const data = JSON.parse(response);
105
106
  if (data.models && data.models.length > 0) {
106
- console.log(chalk.green(`\n${data.models.length} models available`));
107
+ logger.always(chalk.green(`\n${data.models.length} models available`));
107
108
  }
108
109
  }
109
110
  catch {
@@ -112,18 +113,18 @@ async function statusHandler() {
112
113
  }
113
114
  catch (error) {
114
115
  spinner.fail("Ollama service is not running");
115
- console.log(chalk.yellow("\nStart Ollama with: ollama serve"));
116
- console.log(chalk.blue("Or restart the Ollama app if using the desktop version"));
116
+ logger.always(chalk.yellow("\nStart Ollama with: ollama serve"));
117
+ logger.always(chalk.blue("Or restart the Ollama app if using the desktop version"));
117
118
  process.exit(1);
118
119
  }
119
120
  }
120
121
  async function startHandler() {
121
- console.log(chalk.blue("Starting Ollama service..."));
122
+ logger.always(chalk.blue("Starting Ollama service..."));
122
123
  try {
123
124
  // Check if already running
124
125
  try {
125
126
  execSync("ollama list", { encoding: "utf8" });
126
- console.log(chalk.yellow("Ollama service is already running!"));
127
+ logger.always(chalk.yellow("Ollama service is already running!"));
127
128
  return;
128
129
  }
129
130
  catch {
@@ -132,43 +133,43 @@ async function startHandler() {
132
133
  // Different approaches for different platforms
133
134
  if (process.platform === "darwin") {
134
135
  // macOS
135
- console.log(chalk.gray("Starting Ollama on macOS..."));
136
+ logger.always(chalk.gray("Starting Ollama on macOS..."));
136
137
  try {
137
138
  execSync("open -a Ollama");
138
- console.log(chalk.green("✅ Ollama app started"));
139
+ logger.always(chalk.green("✅ Ollama app started"));
139
140
  }
140
141
  catch {
141
142
  // Try service command
142
143
  execSync("ollama serve > /dev/null 2>&1 &", { stdio: "ignore" });
143
- console.log(chalk.green("✅ Ollama service started"));
144
+ logger.always(chalk.green("✅ Ollama service started"));
144
145
  }
145
146
  }
146
147
  else if (process.platform === "linux") {
147
148
  // Linux
148
- console.log(chalk.gray("Starting Ollama service on Linux..."));
149
+ logger.always(chalk.gray("Starting Ollama service on Linux..."));
149
150
  try {
150
151
  execSync("systemctl start ollama", { encoding: "utf8" });
151
- console.log(chalk.green("✅ Ollama service started"));
152
+ logger.always(chalk.green("✅ Ollama service started"));
152
153
  }
153
154
  catch {
154
155
  // Try direct command
155
156
  execSync("ollama serve > /dev/null 2>&1 &", { stdio: "ignore" });
156
- console.log(chalk.green("✅ Ollama service started"));
157
+ logger.always(chalk.green("✅ Ollama service started"));
157
158
  }
158
159
  }
159
160
  else {
160
161
  // Windows
161
- console.log(chalk.gray("Starting Ollama on Windows..."));
162
+ logger.always(chalk.gray("Starting Ollama on Windows..."));
162
163
  execSync("start ollama serve", { stdio: "ignore" });
163
- console.log(chalk.green("✅ Ollama service started"));
164
+ logger.always(chalk.green("✅ Ollama service started"));
164
165
  }
165
- console.log(chalk.blue("\nWait a few seconds for the service to initialize..."));
166
+ logger.always(chalk.blue("\nWait a few seconds for the service to initialize..."));
166
167
  }
167
168
  catch (error) {
168
- console.error(chalk.red("Failed to start Ollama service"));
169
+ logger.error(chalk.red("Failed to start Ollama service"));
169
170
  const errorMessage = error instanceof Error ? error.message : String(error);
170
- console.error(chalk.red("Error:", errorMessage));
171
- console.log(chalk.blue("\nTry starting Ollama manually or check installation"));
171
+ logger.error(chalk.red("Error:", errorMessage));
172
+ logger.always(chalk.blue("\nTry starting Ollama manually or check installation"));
172
173
  process.exit(1);
173
174
  }
174
175
  }
@@ -201,11 +202,11 @@ async function stopHandler() {
201
202
  }
202
203
  catch (error) {
203
204
  spinner.fail("Failed to stop Ollama service");
204
- console.error(chalk.red("It may not be running or requires manual stop"));
205
+ logger.error(chalk.red("It may not be running or requires manual stop"));
205
206
  }
206
207
  }
207
208
  async function setupHandler() {
208
- console.log(chalk.blue("🦙 Welcome to Ollama Setup!\n"));
209
+ logger.always(chalk.blue("🦙 Welcome to Ollama Setup!\n"));
209
210
  // Check if Ollama is installed
210
211
  const checkSpinner = ora("Checking Ollama installation...").start();
211
212
  let isInstalled = false;
@@ -218,20 +219,20 @@ async function setupHandler() {
218
219
  checkSpinner.fail("Ollama is not installed");
219
220
  }
220
221
  if (!isInstalled) {
221
- console.log(chalk.yellow("\nOllama needs to be installed first."));
222
- console.log(chalk.blue("\nInstallation instructions:"));
222
+ logger.always(chalk.yellow("\nOllama needs to be installed first."));
223
+ logger.always(chalk.blue("\nInstallation instructions:"));
223
224
  if (process.platform === "darwin") {
224
- console.log("\nFor macOS:");
225
- console.log(chalk.gray(" brew install ollama"));
226
- console.log(chalk.gray(" # or download from https://ollama.ai"));
225
+ logger.always("\nFor macOS:");
226
+ logger.always(chalk.gray(" brew install ollama"));
227
+ logger.always(chalk.gray(" # or download from https://ollama.ai"));
227
228
  }
228
229
  else if (process.platform === "linux") {
229
- console.log("\nFor Linux:");
230
- console.log(chalk.gray(" curl -fsSL https://ollama.ai/install.sh | sh"));
230
+ logger.always("\nFor Linux:");
231
+ logger.always(chalk.gray(" curl -fsSL https://ollama.ai/install.sh | sh"));
231
232
  }
232
233
  else {
233
- console.log("\nFor Windows:");
234
- console.log(chalk.gray(" Download from https://ollama.ai"));
234
+ logger.always("\nFor Windows:");
235
+ logger.always(chalk.gray(" Download from https://ollama.ai"));
235
236
  }
236
237
  const { proceedAnyway } = await inquirer.prompt([
237
238
  {
@@ -242,7 +243,7 @@ async function setupHandler() {
242
243
  },
243
244
  ]);
244
245
  if (!proceedAnyway) {
245
- console.log(chalk.blue("\nInstall Ollama and run setup again!"));
246
+ logger.always(chalk.blue("\nInstall Ollama and run setup again!"));
246
247
  return;
247
248
  }
248
249
  }
@@ -251,10 +252,10 @@ async function setupHandler() {
251
252
  try {
252
253
  execSync("ollama list", { encoding: "utf8" });
253
254
  serviceRunning = true;
254
- console.log(chalk.green("\n✅ Ollama service is running"));
255
+ logger.always(chalk.green("\n✅ Ollama service is running"));
255
256
  }
256
257
  catch {
257
- console.log(chalk.yellow("\n⚠️ Ollama service is not running"));
258
+ logger.always(chalk.yellow("\n⚠️ Ollama service is not running"));
258
259
  const { startService } = await inquirer.prompt([
259
260
  {
260
261
  type: "confirm",
@@ -270,12 +271,12 @@ async function setupHandler() {
270
271
  }
271
272
  if (serviceRunning) {
272
273
  // List available models
273
- console.log(chalk.blue("\n📦 Popular Ollama models:"));
274
- console.log(" • llama2 (7B) - General purpose");
275
- console.log(" • codellama (7B) - Code generation");
276
- console.log(" • mistral (7B) - Fast and efficient");
277
- console.log(" • tinyllama (1B) - Lightweight");
278
- console.log(" • phi (2.7B) - Microsoft's compact model");
274
+ logger.always(chalk.blue("\n📦 Popular Ollama models:"));
275
+ logger.always(" • llama2 (7B) - General purpose");
276
+ logger.always(" • codellama (7B) - Code generation");
277
+ logger.always(" • mistral (7B) - Fast and efficient");
278
+ logger.always(" • tinyllama (1B) - Lightweight");
279
+ logger.always(" • phi (2.7B) - Microsoft's compact model");
279
280
  const { downloadModel } = await inquirer.prompt([
280
281
  {
281
282
  type: "confirm",
@@ -322,13 +323,13 @@ async function setupHandler() {
322
323
  }
323
324
  }
324
325
  // Final instructions
325
- console.log(chalk.green("\n✅ Setup complete!\n"));
326
- console.log(chalk.blue("Next steps:"));
327
- console.log("1. List models: " + chalk.gray("neurolink ollama list-models"));
328
- console.log("2. Generate text: " +
326
+ logger.always(chalk.green("\n✅ Setup complete!\n"));
327
+ logger.always(chalk.blue("Next steps:"));
328
+ logger.always("1. List models: " + chalk.gray("neurolink ollama list-models"));
329
+ logger.always("2. Generate text: " +
329
330
  chalk.gray('neurolink generate "Hello!" --provider ollama'));
330
- console.log("3. Use specific model: " +
331
+ logger.always("3. Use specific model: " +
331
332
  chalk.gray('neurolink generate "Hello!" --provider ollama --model codellama'));
332
- console.log(chalk.gray("\nFor more information, see: https://docs.neurolink.ai/providers/ollama"));
333
+ logger.always(chalk.gray("\nFor more information, see: https://docs.neurolink.ai/providers/ollama"));
333
334
  }
334
335
  export default addOllamaCommands;
@@ -1,19 +1,84 @@
1
1
  import type { CommandModule } from "yargs";
2
- import type { UnknownRecord } from "../../lib/types/common.js";
3
2
  /**
4
3
  * CLI Command Factory for generate commands
5
4
  */
6
5
  export declare class CLICommandFactory {
6
+ private static readonly commonOptions;
7
+ private static buildOptions;
8
+ private static processOptions;
9
+ private static handleOutput;
10
+ private static isValidTokenUsage;
11
+ private static formatAnalyticsForTextMode;
7
12
  /**
8
13
  * Create the new primary 'generate' command
9
14
  */
10
15
  static createGenerateCommand(): CommandModule;
16
+ /**
17
+ * Create stream command
18
+ */
19
+ static createStreamCommand(): CommandModule;
20
+ /**
21
+ * Create batch command
22
+ */
23
+ static createBatchCommand(): CommandModule;
24
+ /**
25
+ * Create provider commands
26
+ */
27
+ static createProviderCommands(): CommandModule;
28
+ /**
29
+ * Create status command (alias for provider status)
30
+ */
31
+ static createStatusCommand(): CommandModule;
32
+ /**
33
+ * Create models commands
34
+ */
35
+ static createModelsCommands(): CommandModule;
36
+ /**
37
+ * Create MCP commands
38
+ */
39
+ static createMCPCommands(): CommandModule;
40
+ /**
41
+ * Create discover command
42
+ */
43
+ static createDiscoverCommand(): CommandModule;
44
+ /**
45
+ * Create config commands
46
+ */
47
+ static createConfigCommands(): CommandModule;
48
+ /**
49
+ * Create get-best-provider command
50
+ */
51
+ static createBestProviderCommand(): CommandModule;
52
+ /**
53
+ * Create completion command
54
+ */
55
+ static createCompletionCommand(): CommandModule;
11
56
  /**
12
57
  * Execute provider status command
13
58
  */
14
- executeProviderStatus(argv: UnknownRecord): Promise<void>;
59
+ private static executeProviderStatus;
15
60
  /**
16
61
  * Execute the generate command
17
62
  */
18
63
  private static executeGenerate;
64
+ /**
65
+ * Execute the stream command
66
+ */
67
+ private static executeStream;
68
+ /**
69
+ * Execute the batch command
70
+ */
71
+ private static executeBatch;
72
+ /**
73
+ * Execute config export command
74
+ */
75
+ private static executeConfigExport;
76
+ /**
77
+ * Execute get best provider command
78
+ */
79
+ private static executeGetBestProvider;
80
+ /**
81
+ * Execute completion command
82
+ */
83
+ private static executeCompletion;
19
84
  }