Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit 5dc16c6

Browse files
authored
chore: enhance error output (#923)
1 parent 75c3f64 commit 5dc16c6

28 files changed

+114
-160
lines changed

cortex-js/src/command.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { EnginesListCommand } from './infrastructure/commanders/engines/engines-
2828
import { EnginesGetCommand } from './infrastructure/commanders/engines/engines-get.command';
2929
import { EnginesInitCommand } from './infrastructure/commanders/engines/engines-init.command';
3030
import { EnginesSetCommand } from './infrastructure/commanders/engines/engines-set.command';
31+
import { CortexClientModule } from './infrastructure/commanders/services/cortex.client.module';
3132

3233
@Module({
3334
imports: [
@@ -41,6 +42,7 @@ import { EnginesSetCommand } from './infrastructure/commanders/engines/engines-s
4142
FileManagerModule,
4243
TelemetryModule,
4344
ContextModule,
45+
CortexClientModule,
4446
],
4547
providers: [
4648
CortexCommand,

cortex-js/src/extensions/extensions.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import OpenAIEngineExtension from './openai.engine';
55
import { HttpModule, HttpService } from '@nestjs/axios';
66
import { ConfigsUsecases } from '@/usecases/configs/configs.usecase';
77
import { ConfigsModule } from '@/usecases/configs/configs.module';
8-
import { EventEmitter2, EventEmitterModule } from '@nestjs/event-emitter';
8+
import { EventEmitter2 } from '@nestjs/event-emitter';
99
import AnthropicEngineExtension from './anthropic.engine';
1010

1111
const provider = {

cortex-js/src/infrastructure/commanders/base.command.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { CommandRunner } from 'nest-commander';
22
import { Injectable } from '@nestjs/common';
33
import { CortexUsecases } from '@/usecases/cortex/cortex.usecases';
4-
import Cortex from '@cortexso/cortex.js';
54
import ora from 'ora';
65

76
@Injectable()
@@ -21,7 +20,9 @@ export abstract class BaseCommand extends CommandRunner {
2120
const checkingSpinner = ora('Checking API server online...').start();
2221
const result = await this.cortexUseCases.isAPIServerOnline();
2322
if (!result) {
24-
checkingSpinner.fail('API server is offline');
23+
checkingSpinner.fail(
24+
'API server is offline. Please run "cortex" before running this command',
25+
);
2526
process.exit(1);
2627
}
2728
checkingSpinner.succeed('API server is online');

cortex-js/src/infrastructure/commanders/base.subcommand.ts

Lines changed: 0 additions & 30 deletions
This file was deleted.

cortex-js/src/infrastructure/commanders/benchmark.command.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { BenchmarkHardware } from '@/domain/telemetry/telemetry.interface';
1616
import { defaultBenchmarkConfiguration } from '../constants/benchmark';
1717
import { inspect } from 'util';
1818
import { Cortex } from '@cortexso/cortex.js';
19-
import { BaseSubCommand } from './base.subcommand';
19+
import { CortexClient } from './services/cortex.client';
2020

2121
@SubCommand({
2222
name: 'benchmark',
@@ -27,11 +27,12 @@ import { BaseSubCommand } from './base.subcommand';
2727
description:
2828
'Benchmark and analyze the performance of a specific AI model using a variety of system resources',
2929
})
30-
export class BenchmarkCommand extends BaseSubCommand {
30+
export class BenchmarkCommand extends BaseCommand {
3131
constructor(
3232
private readonly cortexUsecases: CortexUsecases,
3333
private readonly fileService: FileManagerService,
3434
private readonly telemetryUsecases: TelemetryUsecases,
35+
private readonly cortex: CortexClient,
3536
) {
3637
super(cortexUsecases);
3738
}

cortex-js/src/infrastructure/commanders/chat.command.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { isRemoteEngine } from '@/utils/normalize-model-id';
1717
import { Cortex } from '@cortexso/cortex.js';
1818
import { ChatClient } from './services/chat-client';
1919
import { downloadModelProgress } from '@/utils/pull-model';
20-
import { BaseSubCommand } from './base.subcommand';
20+
import { CortexClient } from './services/cortex.client';
2121

2222
type ChatOptions = {
2323
threadId?: string;
@@ -37,7 +37,7 @@ type ChatOptions = {
3737
},
3838
})
3939
@SetCommandContext()
40-
export class ChatCommand extends BaseSubCommand {
40+
export class ChatCommand extends BaseCommand {
4141
chatClient: ChatClient;
4242

4343
constructor(
@@ -46,6 +46,7 @@ export class ChatCommand extends BaseSubCommand {
4646
private readonly fileService: FileManagerService,
4747
protected readonly cortexUsecases: CortexUsecases,
4848
protected readonly contextService: ContextService,
49+
protected readonly cortex: CortexClient,
4950
) {
5051
super(cortexUsecases);
5152
this.chatClient = new ChatClient(this.cortex);
@@ -66,7 +67,7 @@ export class ChatCommand extends BaseSubCommand {
6667
// first input might be message input
6768
message = passedParams.length
6869
? passedParams.join(' ')
69-
: options.message ?? '';
70+
: (options.message ?? '');
7071
// If model ID is not provided, prompt user to select from running models
7172
const { data: models } = await this.cortex.models.list();
7273
if (models.length === 1) {

cortex-js/src/infrastructure/commanders/cortex-command.commander.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import { FileManagerService } from '../services/file-manager/file-manager.servic
1919
import { CortexUsecases } from '@/usecases/cortex/cortex.usecases';
2020
import { ServeStopCommand } from './serve-stop.command';
2121
import ora from 'ora';
22-
import { printSlogan } from '@/utils/logo';
2322
import { EnginesSetCommand } from './engines/engines-set.command';
2423

2524
type ServeOptions = {
@@ -77,7 +76,6 @@ export class CortexCommand extends CommandRunner {
7776
const showVersion = options?.version || false;
7877
const dataFolderPath = options?.dataFolder;
7978
if (showVersion) {
80-
printSlogan();
8179
console.log('\n');
8280
console.log(`Cortex CLI - v${pkg.version}`);
8381
console.log(chalk.blue(`Github: ${pkg.homepage}`));

cortex-js/src/infrastructure/commanders/embeddings.command.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { CortexUsecases } from '@/usecases/cortex/cortex.usecases';
44
import { BaseCommand } from './base.command';
55
import { Cortex } from '@cortexso/cortex.js';
66
import ora from 'ora';
7-
import { BaseSubCommand } from './base.subcommand';
7+
import { CortexClient } from './services/cortex.client';
88

99
interface EmbeddingCommandOptions {
1010
encoding_format?: string;
@@ -21,9 +21,10 @@ interface EmbeddingCommandOptions {
2121
'Model to use for embedding. If not provided, it will prompt to select from running models.',
2222
},
2323
})
24-
export class EmbeddingCommand extends BaseSubCommand {
24+
export class EmbeddingCommand extends BaseCommand {
2525
constructor(
2626
private readonly inquirerService: InquirerService,
27+
private readonly cortex: CortexClient,
2728
readonly cortexUsecases: CortexUsecases,
2829
) {
2930
super(cortexUsecases);

cortex-js/src/infrastructure/commanders/engines.command.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export class EnginesCommand extends BaseCommand {
6161
) {
6262
const commandInstance = this.moduleRef.get(commandClass, { strict: false });
6363
if (commandInstance) {
64-
await commandInstance.run(params, options);
64+
await commandInstance.runCommand(params, options);
6565
} else {
6666
console.error('Command not found.');
6767
}

cortex-js/src/infrastructure/commanders/engines/engines-get.command.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ContextService } from '@/infrastructure/services/context/context.servic
44
import { EngineNamesMap, Engines } from '../types/engine.interface';
55
import { BaseCommand } from '../base.command';
66
import { CortexUsecases } from '@/usecases/cortex/cortex.usecases';
7-
import { BaseSubCommand } from '../base.subcommand';
7+
import { CortexClient } from '../services/cortex.client';
88

99
@SubCommand({
1010
name: '<name> get',
@@ -14,10 +14,11 @@ import { BaseSubCommand } from '../base.subcommand';
1414
},
1515
})
1616
@SetCommandContext()
17-
export class EnginesGetCommand extends BaseSubCommand {
17+
export class EnginesGetCommand extends BaseCommand {
1818
constructor(
1919
readonly contextService: ContextService,
2020
readonly cortexUsecases: CortexUsecases,
21+
private readonly cortex: CortexClient,
2122
) {
2223
super(cortexUsecases);
2324
}

0 commit comments

Comments
 (0)