@juspay/neurolink 7.26.0 → 7.27.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 CHANGED
@@ -1,3 +1,11 @@
1
+ ## [7.27.0](https://github.com/juspay/neurolink/compare/v7.26.1...v7.27.0) (2025-08-24)
2
+
3
+ ### Features
4
+
5
+ - **(History):** Added the functionality to export the conversation history for debugging purpose ([71cec7e](https://github.com/juspay/neurolink/commit/71cec7e30154d80c123cae022806dfea58edbe69))
6
+
7
+ ## [7.26.1](https://github.com/juspay/neurolink/compare/v7.26.0...v7.26.1) (2025-08-21)
8
+
1
9
  ## [7.26.0](https://github.com/juspay/neurolink/compare/v7.25.0...v7.26.0) (2025-08-21)
2
10
 
3
11
  ### Features
@@ -53,6 +53,14 @@ export declare class CLICommandFactory {
53
53
  * Create get-best-provider command
54
54
  */
55
55
  static createBestProviderCommand(): CommandModule;
56
+ /**
57
+ * Create Ollama commands
58
+ */
59
+ static createOllamaCommands(): CommandModule;
60
+ /**
61
+ * Create SageMaker commands
62
+ */
63
+ static createSageMakerCommands(): CommandModule;
56
64
  /**
57
65
  * Create completion command
58
66
  */
@@ -3,6 +3,8 @@ import { configManager } from "../commands/config.js";
3
3
  import { ContextFactory, } from "../../lib/types/contextTypes.js";
4
4
  import { ModelsCommandFactory } from "../commands/models.js";
5
5
  import { MCPCommandFactory } from "../commands/mcp.js";
6
+ import { OllamaCommandFactory } from "./ollamaCommandFactory.js";
7
+ import { SageMakerCommandFactory } from "./sagemakerCommandFactory.js";
6
8
  import ora from "ora";
7
9
  import chalk from "chalk";
8
10
  import { logger } from "../../lib/utils/logger.js";
@@ -514,6 +516,18 @@ export class CLICommandFactory {
514
516
  handler: async (argv) => await this.executeGetBestProvider(argv),
515
517
  };
516
518
  }
519
+ /**
520
+ * Create Ollama commands
521
+ */
522
+ static createOllamaCommands() {
523
+ return OllamaCommandFactory.createOllamaCommands();
524
+ }
525
+ /**
526
+ * Create SageMaker commands
527
+ */
528
+ static createSageMakerCommands() {
529
+ return SageMakerCommandFactory.createSageMakerCommands();
530
+ }
517
531
  /**
518
532
  * Create completion command
519
533
  */
@@ -0,0 +1,38 @@
1
+ import type { CommandModule } from "yargs";
2
+ /**
3
+ * Factory for creating Ollama CLI commands using the Factory Pattern
4
+ */
5
+ export declare class OllamaCommandFactory {
6
+ /**
7
+ * Create the Ollama command group
8
+ */
9
+ static createOllamaCommands(): CommandModule;
10
+ /**
11
+ * Handler for listing installed models
12
+ */
13
+ private static listModelsHandler;
14
+ /**
15
+ * Handler for pulling/downloading models
16
+ */
17
+ private static pullModelHandler;
18
+ /**
19
+ * Handler for removing models
20
+ */
21
+ private static removeModelHandler;
22
+ /**
23
+ * Handler for checking Ollama service status
24
+ */
25
+ private static statusHandler;
26
+ /**
27
+ * Handler for starting Ollama service
28
+ */
29
+ private static startHandler;
30
+ /**
31
+ * Handler for stopping Ollama service
32
+ */
33
+ private static stopHandler;
34
+ /**
35
+ * Handler for interactive Ollama setup
36
+ */
37
+ private static setupHandler;
38
+ }
@@ -0,0 +1,375 @@
1
+ import { execSync } from "child_process";
2
+ import chalk from "chalk";
3
+ import ora from "ora";
4
+ import inquirer from "inquirer";
5
+ import { logger } from "../../lib/utils/logger.js";
6
+ /**
7
+ * Factory for creating Ollama CLI commands using the Factory Pattern
8
+ */
9
+ export class OllamaCommandFactory {
10
+ /**
11
+ * Create the Ollama command group
12
+ */
13
+ static createOllamaCommands() {
14
+ return {
15
+ command: "ollama <command>",
16
+ describe: "Manage Ollama local AI models",
17
+ builder: (yargs) => {
18
+ return yargs
19
+ .command("list-models", "List installed Ollama models", {}, this.listModelsHandler)
20
+ .command("pull <model>", "Download an Ollama model", {
21
+ model: {
22
+ describe: "Model name to download",
23
+ type: "string",
24
+ demandOption: true,
25
+ },
26
+ }, this.pullModelHandler)
27
+ .command("remove <model>", "Remove an Ollama model", {
28
+ model: {
29
+ describe: "Model name to remove",
30
+ type: "string",
31
+ demandOption: true,
32
+ },
33
+ }, this.removeModelHandler)
34
+ .command("status", "Check Ollama service status", {}, this.statusHandler)
35
+ .command("start", "Start Ollama service", {}, this.startHandler)
36
+ .command("stop", "Stop Ollama service", {}, this.stopHandler)
37
+ .command("setup", "Interactive Ollama setup", {}, this.setupHandler)
38
+ .demandCommand(1, "Please specify a command");
39
+ },
40
+ handler: () => { }, // No-op handler as subcommands handle everything
41
+ };
42
+ }
43
+ /**
44
+ * Handler for listing installed models
45
+ */
46
+ static async listModelsHandler() {
47
+ const spinner = ora("Fetching installed models...").start();
48
+ try {
49
+ const output = execSync("ollama list", { encoding: "utf8" });
50
+ spinner.succeed("Installed models:");
51
+ if (output.trim()) {
52
+ logger.always(output);
53
+ }
54
+ else {
55
+ logger.always(chalk.yellow('No models installed. Use "neurolink ollama pull <model>" to download a model.'));
56
+ }
57
+ }
58
+ catch (error) {
59
+ spinner.fail("Failed to list models. Is Ollama installed?");
60
+ const errorMessage = error instanceof Error ? error.message : String(error);
61
+ logger.error(chalk.red("Error:", errorMessage));
62
+ logger.always(chalk.blue("\nTip: Install Ollama from https://ollama.ai"));
63
+ process.exit(1);
64
+ }
65
+ }
66
+ /**
67
+ * Handler for pulling/downloading models
68
+ */
69
+ static async pullModelHandler(argv) {
70
+ const { model } = argv;
71
+ logger.always(chalk.blue(`Downloading model: ${model}`));
72
+ logger.always(chalk.gray("This may take several minutes..."));
73
+ try {
74
+ execSync(`ollama pull ${model}`, { stdio: "inherit" });
75
+ logger.always(chalk.green(`\n✅ Successfully downloaded ${model}`));
76
+ logger.always(chalk.blue(`\nTest it with: npx @juspay/neurolink generate "Hello!" --provider ollama --model ${model}`));
77
+ }
78
+ catch (error) {
79
+ logger.error(chalk.red(`\n❌ Failed to download ${model}`));
80
+ const errorMessage = error instanceof Error ? error.message : String(error);
81
+ logger.error(chalk.red("Error:", errorMessage));
82
+ process.exit(1);
83
+ }
84
+ }
85
+ /**
86
+ * Handler for removing models
87
+ */
88
+ static async removeModelHandler(argv) {
89
+ const { model } = argv;
90
+ // Confirm removal
91
+ const { confirm } = await inquirer.prompt([
92
+ {
93
+ type: "confirm",
94
+ name: "confirm",
95
+ message: `Are you sure you want to remove model "${model}"?`,
96
+ default: false,
97
+ },
98
+ ]);
99
+ if (!confirm) {
100
+ logger.always(chalk.yellow("Removal cancelled."));
101
+ return;
102
+ }
103
+ const spinner = ora(`Removing model ${model}...`).start();
104
+ try {
105
+ execSync(`ollama rm ${model}`, { encoding: "utf8" });
106
+ spinner.succeed(`Successfully removed ${model}`);
107
+ }
108
+ catch (error) {
109
+ spinner.fail(`Failed to remove ${model}`);
110
+ const errorMessage = error instanceof Error ? error.message : String(error);
111
+ logger.error(chalk.red("Error:", errorMessage));
112
+ process.exit(1);
113
+ }
114
+ }
115
+ /**
116
+ * Handler for checking Ollama service status
117
+ */
118
+ static async statusHandler() {
119
+ const spinner = ora("Checking Ollama service status...").start();
120
+ try {
121
+ // Try to run a simple command
122
+ execSync("ollama list", { encoding: "utf8" });
123
+ spinner.succeed("Ollama service is running");
124
+ // Get additional info
125
+ try {
126
+ const response = execSync("curl -s http://localhost:11434/api/tags", {
127
+ encoding: "utf8",
128
+ });
129
+ const data = JSON.parse(response);
130
+ if (data.models && data.models.length > 0) {
131
+ logger.always(chalk.green(`\n${data.models.length} models available`));
132
+ }
133
+ }
134
+ catch (error) {
135
+ // Curl might not be available, that's ok. Error is ignored.
136
+ logger.debug &&
137
+ logger.debug("Optional curl command failed in statusHandler:", error);
138
+ }
139
+ }
140
+ catch (error) {
141
+ spinner.fail("Ollama service is not running");
142
+ logger.debug && logger.debug("Ollama status check failed:", error);
143
+ logger.always(chalk.yellow("\nStart Ollama with: ollama serve"));
144
+ logger.always(chalk.blue("Or restart the Ollama app if using the desktop version"));
145
+ process.exit(1);
146
+ }
147
+ }
148
+ /**
149
+ * Handler for starting Ollama service
150
+ */
151
+ static async startHandler() {
152
+ logger.always(chalk.blue("Starting Ollama service..."));
153
+ try {
154
+ // Check if already running
155
+ try {
156
+ execSync("ollama list", { encoding: "utf8" });
157
+ logger.always(chalk.yellow("Ollama service is already running!"));
158
+ return;
159
+ }
160
+ catch {
161
+ // Not running, continue to start
162
+ }
163
+ // Different approaches for different platforms
164
+ if (process.platform === "darwin") {
165
+ // macOS
166
+ logger.always(chalk.gray("Starting Ollama on macOS..."));
167
+ try {
168
+ execSync("open -a Ollama");
169
+ logger.always(chalk.green("✅ Ollama app started"));
170
+ }
171
+ catch {
172
+ // Try service command
173
+ execSync("ollama serve > /dev/null 2>&1 &", { stdio: "ignore" });
174
+ logger.always(chalk.green("✅ Ollama service started"));
175
+ }
176
+ }
177
+ else if (process.platform === "linux") {
178
+ // Linux
179
+ logger.always(chalk.gray("Starting Ollama service on Linux..."));
180
+ try {
181
+ execSync("systemctl start ollama", { encoding: "utf8" });
182
+ logger.always(chalk.green("✅ Ollama service started"));
183
+ }
184
+ catch {
185
+ // Try direct command
186
+ execSync("ollama serve > /dev/null 2>&1 &", { stdio: "ignore" });
187
+ logger.always(chalk.green("✅ Ollama service started"));
188
+ }
189
+ }
190
+ else {
191
+ // Windows
192
+ logger.always(chalk.gray("Starting Ollama on Windows..."));
193
+ execSync("start ollama serve", { stdio: "ignore" });
194
+ logger.always(chalk.green("✅ Ollama service started"));
195
+ }
196
+ logger.always(chalk.blue("\nWait a few seconds for the service to initialize..."));
197
+ }
198
+ catch (error) {
199
+ logger.error(chalk.red("Failed to start Ollama service"));
200
+ const errorMessage = error instanceof Error ? error.message : String(error);
201
+ logger.error(chalk.red("Error:", errorMessage));
202
+ logger.always(chalk.blue("\nTry starting Ollama manually or check installation"));
203
+ process.exit(1);
204
+ }
205
+ }
206
+ /**
207
+ * Handler for stopping Ollama service
208
+ */
209
+ static async stopHandler() {
210
+ const spinner = ora("Stopping Ollama service...").start();
211
+ try {
212
+ if (process.platform === "darwin") {
213
+ // macOS
214
+ try {
215
+ execSync("pkill ollama", { encoding: "utf8" });
216
+ }
217
+ catch {
218
+ execSync("killall Ollama", { encoding: "utf8" });
219
+ }
220
+ }
221
+ else if (process.platform === "linux") {
222
+ // Linux
223
+ try {
224
+ execSync("systemctl stop ollama", { encoding: "utf8" });
225
+ }
226
+ catch {
227
+ execSync("pkill ollama", { encoding: "utf8" });
228
+ }
229
+ }
230
+ else {
231
+ // Windows
232
+ execSync("taskkill /F /IM ollama.exe", { encoding: "utf8" });
233
+ }
234
+ spinner.succeed("Ollama service stopped");
235
+ }
236
+ catch (err) {
237
+ spinner.fail("Failed to stop Ollama service");
238
+ logger.error(chalk.red("It may not be running or requires manual stop"));
239
+ logger.error(chalk.red(`Error details: ${err}`));
240
+ }
241
+ }
242
+ /**
243
+ * Handler for interactive Ollama setup
244
+ */
245
+ static async setupHandler() {
246
+ logger.always(chalk.blue("🦙 Welcome to Ollama Setup!\n"));
247
+ // Check if Ollama is installed
248
+ const checkSpinner = ora("Checking Ollama installation...").start();
249
+ let isInstalled = false;
250
+ try {
251
+ execSync("ollama --version", { encoding: "utf8" });
252
+ isInstalled = true;
253
+ checkSpinner.succeed("Ollama is installed");
254
+ }
255
+ catch {
256
+ checkSpinner.fail("Ollama is not installed");
257
+ }
258
+ if (!isInstalled) {
259
+ logger.always(chalk.yellow("\nOllama needs to be installed first."));
260
+ logger.always(chalk.blue("\nInstallation instructions:"));
261
+ if (process.platform === "darwin") {
262
+ logger.always("\nFor macOS:");
263
+ logger.always(chalk.gray(" brew install ollama"));
264
+ logger.always(chalk.gray(" # or download from https://ollama.ai"));
265
+ }
266
+ else if (process.platform === "linux") {
267
+ logger.always("\nFor Linux:");
268
+ logger.always(chalk.gray(" curl -fsSL https://ollama.ai/install.sh | sh"));
269
+ }
270
+ else {
271
+ logger.always("\nFor Windows:");
272
+ logger.always(chalk.gray(" Download from https://ollama.ai"));
273
+ }
274
+ const { proceedAnyway } = await inquirer.prompt([
275
+ {
276
+ type: "confirm",
277
+ name: "proceedAnyway",
278
+ message: "Would you like to continue with setup anyway?",
279
+ default: false,
280
+ },
281
+ ]);
282
+ if (!proceedAnyway) {
283
+ logger.always(chalk.blue("\nInstall Ollama and run setup again!"));
284
+ return;
285
+ }
286
+ }
287
+ // Check if service is running
288
+ let serviceRunning = false;
289
+ try {
290
+ execSync("ollama list", { encoding: "utf8" });
291
+ serviceRunning = true;
292
+ logger.always(chalk.green("\n✅ Ollama service is running"));
293
+ }
294
+ catch {
295
+ logger.always(chalk.yellow("\n⚠️ Ollama service is not running"));
296
+ const { startService } = await inquirer.prompt([
297
+ {
298
+ type: "confirm",
299
+ name: "startService",
300
+ message: "Would you like to start the Ollama service?",
301
+ default: true,
302
+ },
303
+ ]);
304
+ if (startService) {
305
+ await this.startHandler();
306
+ serviceRunning = true;
307
+ }
308
+ }
309
+ if (serviceRunning) {
310
+ // List available models
311
+ logger.always(chalk.blue("\n📦 Popular Ollama models:"));
312
+ logger.always(" • llama2 (7B) - General purpose");
313
+ logger.always(" • codellama (7B) - Code generation");
314
+ logger.always(" • mistral (7B) - Fast and efficient");
315
+ logger.always(" • tinyllama (1B) - Lightweight");
316
+ logger.always(" • phi (2.7B) - Microsoft's compact model");
317
+ const { downloadModel } = await inquirer.prompt([
318
+ {
319
+ type: "confirm",
320
+ name: "downloadModel",
321
+ message: "Would you like to download a model?",
322
+ default: true,
323
+ },
324
+ ]);
325
+ if (downloadModel) {
326
+ const { selectedModel } = await inquirer.prompt([
327
+ {
328
+ type: "list",
329
+ name: "selectedModel",
330
+ message: "Select a model to download:",
331
+ choices: [
332
+ {
333
+ name: "llama2 (7B) - Recommended for general use",
334
+ value: "llama2",
335
+ },
336
+ {
337
+ name: "codellama (7B) - Best for code generation",
338
+ value: "codellama",
339
+ },
340
+ { name: "mistral (7B) - Fast and efficient", value: "mistral" },
341
+ {
342
+ name: "tinyllama (1B) - Lightweight, fast",
343
+ value: "tinyllama",
344
+ },
345
+ { name: "phi (2.7B) - Microsoft's compact model", value: "phi" },
346
+ { name: "Other (enter manually)", value: "other" },
347
+ ],
348
+ },
349
+ ]);
350
+ let modelToDownload = selectedModel;
351
+ if (selectedModel === "other") {
352
+ const { customModel } = await inquirer.prompt([
353
+ {
354
+ type: "input",
355
+ name: "customModel",
356
+ message: "Enter the model name:",
357
+ validate: (input) => input.trim().length > 0 || "Model name is required",
358
+ },
359
+ ]);
360
+ modelToDownload = customModel;
361
+ }
362
+ await this.pullModelHandler({ model: modelToDownload });
363
+ }
364
+ }
365
+ // Final instructions
366
+ logger.always(chalk.green("\n✅ Setup complete!\n"));
367
+ logger.always(chalk.blue("Next steps:"));
368
+ logger.always("1. List models: " + chalk.gray("neurolink ollama list-models"));
369
+ logger.always("2. Generate text: " +
370
+ chalk.gray('neurolink generate "Hello!" --provider ollama'));
371
+ logger.always("3. Use specific model: " +
372
+ chalk.gray('neurolink generate "Hello!" --provider ollama --model codellama'));
373
+ logger.always(chalk.gray("\nFor more information, see: https://docs.neurolink.ai/providers/ollama"));
374
+ }
375
+ }
@@ -0,0 +1,62 @@
1
+ import type { CommandModule } from "yargs";
2
+ /**
3
+ * Factory for creating SageMaker CLI commands using the Factory Pattern
4
+ */
5
+ export declare class SageMakerCommandFactory {
6
+ /**
7
+ * In-memory secure credential store (cleared after validation)
8
+ */
9
+ private static readonly secureCredentialStore;
10
+ /**
11
+ * Create the SageMaker command group
12
+ */
13
+ static createSageMakerCommands(): CommandModule;
14
+ /**
15
+ * Create secure configuration without exposing credentials to process.env
16
+ */
17
+ private static createSecureConfiguration;
18
+ /**
19
+ * Validate secure configuration without exposing credentials
20
+ */
21
+ private static validateSecureConfiguration;
22
+ /**
23
+ * Clear secure credentials from memory
24
+ */
25
+ private static clearSecureCredentials;
26
+ /**
27
+ * Handler for checking SageMaker status
28
+ */
29
+ private static statusHandler;
30
+ /**
31
+ * Handler for testing SageMaker endpoint connectivity
32
+ */
33
+ private static testEndpointHandler;
34
+ /**
35
+ * Handler for listing SageMaker endpoints
36
+ */
37
+ private static listEndpointsHandler;
38
+ /**
39
+ * Handler for showing configuration
40
+ */
41
+ private static configHandler;
42
+ /**
43
+ * Handler for interactive setup
44
+ */
45
+ private static setupHandler;
46
+ /**
47
+ * Handler for configuration validation
48
+ */
49
+ private static validateHandler;
50
+ /**
51
+ * Handler for performance benchmarking
52
+ */
53
+ private static benchmarkHandler;
54
+ /**
55
+ * Handler for clearing configuration cache
56
+ */
57
+ private static clearCacheHandler;
58
+ /**
59
+ * Handler for running streaming diagnostics
60
+ */
61
+ private static diagnoseHandler;
62
+ }