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

Commit d22fdd3

Browse files
authored
refactor: deprecate cortex configs (#901)
1 parent ef7c7b7 commit d22fdd3

27 files changed

+188
-353
lines changed

cortex-js/src/app.module.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import { ContextModule } from './infrastructure/services/context/context.module'
2929
import { ExtensionsModule } from './extensions/extensions.module';
3030
import { ConfigsModule } from './usecases/configs/configs.module';
3131
import { EnginesModule } from './usecases/engines/engines.module';
32-
import { ConfigsController } from './infrastructure/controllers/configs.controller';
3332
import { EnginesController } from './infrastructure/controllers/engines.controller';
3433
import { ResourceManagerModule } from './infrastructure/services/resources-manager/resources-manager.module';
3534

@@ -70,7 +69,6 @@ import { ResourceManagerModule } from './infrastructure/services/resources-manag
7069
StatusController,
7170
ProcessController,
7271
EventsController,
73-
ConfigsController,
7472
EnginesController,
7573
],
7674
providers: [

cortex-js/src/command.module.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { AssistantsModule } from './usecases/assistants/assistants.module';
2121
import { MessagesModule } from './usecases/messages/messages.module';
2222
import { FileManagerModule } from './infrastructure/services/file-manager/file-manager.module';
2323
import { PSCommand } from './infrastructure/commanders/ps.command';
24-
import { KillCommand } from './infrastructure/commanders/kill.command';
2524
import { PresetCommand } from './infrastructure/commanders/presets.command';
2625
import { TelemetryModule } from './usecases/telemetry/telemetry.module';
2726
import { TelemetryCommand } from './infrastructure/commanders/telemetry.command';
@@ -33,16 +32,13 @@ import { ServeStopCommand } from './infrastructure/commanders/sub-commands/serve
3332
import { ContextModule } from './infrastructure/services/context/context.module';
3433
import { CliUsecasesModule } from './infrastructure/commanders/usecases/cli.usecases.module';
3534
import { ExtensionsModule } from './extensions/extensions.module';
36-
import { ConfigsCommand } from './infrastructure/commanders/configs.command';
3735
import { EnginesCommand } from './infrastructure/commanders/engines.command';
3836
import { ConfigsModule } from './usecases/configs/configs.module';
3937
import { EnginesModule } from './usecases/engines/engines.module';
40-
import { ConfigsGetCommand } from './infrastructure/commanders/configs/configs-get.command';
41-
import { ConfigsListCommand } from './infrastructure/commanders/configs/configs-list.command';
42-
import { ConfigsSetCommand } from './infrastructure/commanders/configs/configs-set.command';
4338
import { EnginesListCommand } from './infrastructure/commanders/engines/engines-list.command';
4439
import { EnginesGetCommand } from './infrastructure/commanders/engines/engines-get.command';
4540
import { EnginesInitCommand } from './infrastructure/commanders/engines/engines-init.command';
41+
import { EnginesSetCommand } from './infrastructure/commanders/engines/engines-set.command';
4642

4743
@Module({
4844
imports: [
@@ -73,7 +69,6 @@ import { EnginesInitCommand } from './infrastructure/commanders/engines/engines-
7369
ModelsCommand,
7470
ChatCommand,
7571
PSCommand,
76-
KillCommand,
7772
PresetCommand,
7873
EmbeddingCommand,
7974
BenchmarkCommand,
@@ -100,16 +95,11 @@ import { EnginesInitCommand } from './infrastructure/commanders/engines/engines-
10095
// Serve
10196
ServeStopCommand,
10297

103-
// Configs
104-
ConfigsCommand,
105-
ConfigsGetCommand,
106-
ConfigsListCommand,
107-
ConfigsSetCommand,
108-
10998
// Engines
11099
EnginesListCommand,
111100
EnginesGetCommand,
112101
EnginesInitCommand,
102+
EnginesSetCommand,
113103
],
114104
})
115105
export class CommandModule {}

cortex-js/src/domain/abstracts/engine.abstract.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ import stream from 'stream';
33
import { Model, ModelSettingParams } from '../../domain/models/model.interface';
44
import { Extension } from './extension.abstract';
55

6+
export enum EngineStatus {
7+
READY = 'READY',
8+
MISSING_CONFIGURATION = 'MISSING_CONFIGURATION',
9+
NOT_INITIALIZED = 'NOT_INITIALIZED',
10+
ERROR = 'ERROR',
11+
}
12+
613
/**
714
* This class should be extended by any class that represents an engine extension.
815
* It provides methods for loading and unloading models, and for making inference requests.
@@ -14,7 +21,7 @@ export abstract class EngineExtension extends Extension {
1421

1522
transformResponse?: Function;
1623

17-
initalized: boolean = false;
24+
status: EngineStatus = EngineStatus.READY;
1825

1926
/**
2027
* Makes an inference request to the engine.

cortex-js/src/domain/abstracts/extension.abstract.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ export abstract class Extension {
2121
/** @type {string} Extension's version. */
2222
version?: string;
2323

24-
/** @type {boolean} Whether the extension is initialized or not. */
25-
initalized: boolean;
24+
/** @type {string} The status of the extension. */
25+
status: string;
2626

2727
/**
2828
* Called when the extension is loaded.

cortex-js/src/extensions/anthropic.engine.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { OAIEngineExtension } from '../domain/abstracts/oai.abstract';
44
import { ConfigsUsecases } from '@/usecases/configs/configs.usecase';
55
import { EventEmitter2 } from '@nestjs/event-emitter';
66
import _ from 'lodash';
7+
import { EngineStatus } from '@/domain/abstracts/engine.abstract';
78

89
/**
910
* A class that implements the InferenceExtension interface from the @janhq/core package.
@@ -16,7 +17,6 @@ export default class AnthropicEngineExtension extends OAIEngineExtension {
1617
productName = 'Anthropic Inference Engine';
1718
description = 'This extension enables Anthropic chat completion API calls';
1819
version = '0.0.1';
19-
initalized = true;
2020
apiKey?: string;
2121

2222
constructor(
@@ -29,6 +29,10 @@ export default class AnthropicEngineExtension extends OAIEngineExtension {
2929
eventEmmitter.on('config.updated', async (data) => {
3030
if (data.group === this.name) {
3131
this.apiKey = data.value;
32+
this.status =
33+
(this.apiKey?.length ?? 0) > 0
34+
? EngineStatus.READY
35+
: EngineStatus.MISSING_CONFIGURATION;
3236
}
3337
});
3438
}
@@ -38,6 +42,10 @@ export default class AnthropicEngineExtension extends OAIEngineExtension {
3842
this.name,
3943
)) as unknown as { apiKey: string };
4044
this.apiKey = configs?.apiKey;
45+
this.status =
46+
(this.apiKey?.length ?? 0) > 0
47+
? EngineStatus.READY
48+
: EngineStatus.MISSING_CONFIGURATION;
4149
}
4250

4351
override async inference(

cortex-js/src/extensions/groq.engine.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { HttpService } from '@nestjs/axios';
22
import { OAIEngineExtension } from '../domain/abstracts/oai.abstract';
33
import { ConfigsUsecases } from '@/usecases/configs/configs.usecase';
44
import { EventEmitter2 } from '@nestjs/event-emitter';
5+
import { EngineStatus } from '@/domain/abstracts/engine.abstract';
56

67
/**
78
* A class that implements the InferenceExtension interface from the @janhq/core package.
@@ -14,7 +15,6 @@ export default class GroqEngineExtension extends OAIEngineExtension {
1415
productName = 'Groq Inference Engine';
1516
description = 'This extension enables fast Groq chat completion API calls';
1617
version = '0.0.1';
17-
initalized = true;
1818
apiKey?: string;
1919

2020
constructor(
@@ -27,6 +27,10 @@ export default class GroqEngineExtension extends OAIEngineExtension {
2727
eventEmmitter.on('config.updated', async (data) => {
2828
if (data.group === this.name) {
2929
this.apiKey = data.value;
30+
this.status =
31+
(this.apiKey?.length ?? 0) > 0
32+
? EngineStatus.READY
33+
: EngineStatus.MISSING_CONFIGURATION;
3034
}
3135
});
3236
}
@@ -37,5 +41,9 @@ export default class GroqEngineExtension extends OAIEngineExtension {
3741
)) as unknown as { apiKey: string };
3842

3943
this.apiKey = configs?.apiKey;
44+
this.status =
45+
(this.apiKey?.length ?? 0) > 0
46+
? EngineStatus.READY
47+
: EngineStatus.MISSING_CONFIGURATION;
4048
}
4149
}

cortex-js/src/extensions/mistral.engine.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { HttpService } from '@nestjs/axios';
22
import { OAIEngineExtension } from '../domain/abstracts/oai.abstract';
33
import { ConfigsUsecases } from '@/usecases/configs/configs.usecase';
44
import { EventEmitter2 } from '@nestjs/event-emitter';
5+
import { EngineStatus } from '@/domain/abstracts/engine.abstract';
56

67
/**
78
* A class that implements the InferenceExtension interface from the @janhq/core package.
@@ -14,7 +15,6 @@ export default class MistralEngineExtension extends OAIEngineExtension {
1415
productName = 'Mistral Inference Engine';
1516
description = 'This extension enables Mistral chat completion API calls';
1617
version = '0.0.1';
17-
initalized = true;
1818
apiKey?: string;
1919

2020
constructor(
@@ -27,6 +27,10 @@ export default class MistralEngineExtension extends OAIEngineExtension {
2727
eventEmmitter.on('config.updated', async (data) => {
2828
if (data.group === this.name) {
2929
this.apiKey = data.value;
30+
this.status =
31+
(this.apiKey?.length ?? 0) > 0
32+
? EngineStatus.READY
33+
: EngineStatus.MISSING_CONFIGURATION;
3034
}
3135
});
3236
}
@@ -36,5 +40,9 @@ export default class MistralEngineExtension extends OAIEngineExtension {
3640
this.name,
3741
)) as unknown as { apiKey: string };
3842
this.apiKey = configs?.apiKey;
43+
this.status =
44+
(this.apiKey?.length ?? 0) > 0
45+
? EngineStatus.READY
46+
: EngineStatus.MISSING_CONFIGURATION;
3947
}
4048
}

cortex-js/src/extensions/openai.engine.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { HttpService } from '@nestjs/axios';
22
import { OAIEngineExtension } from '../domain/abstracts/oai.abstract';
33
import { ConfigsUsecases } from '@/usecases/configs/configs.usecase';
44
import { EventEmitter2 } from '@nestjs/event-emitter';
5+
import { EngineStatus } from '@/domain/abstracts/engine.abstract';
56

67
/**
78
* A class that implements the InferenceExtension interface from the @janhq/core package.
@@ -14,7 +15,6 @@ export default class OpenAIEngineExtension extends OAIEngineExtension {
1415
productName = 'OpenAI Inference Engine';
1516
description = 'This extension enables OpenAI chat completion API calls';
1617
version = '0.0.1';
17-
initalized = true;
1818
apiKey?: string;
1919

2020
constructor(
@@ -27,6 +27,10 @@ export default class OpenAIEngineExtension extends OAIEngineExtension {
2727
eventEmmitter.on('config.updated', async (data) => {
2828
if (data.group === this.name) {
2929
this.apiKey = data.value;
30+
this.status =
31+
(this.apiKey?.length ?? 0) > 0
32+
? EngineStatus.READY
33+
: EngineStatus.MISSING_CONFIGURATION;
3034
}
3135
});
3236
}
@@ -36,5 +40,9 @@ export default class OpenAIEngineExtension extends OAIEngineExtension {
3640
this.name,
3741
)) as unknown as { apiKey: string };
3842
this.apiKey = configs?.apiKey;
43+
this.status =
44+
(this.apiKey?.length ?? 0) > 0
45+
? EngineStatus.READY
46+
: EngineStatus.MISSING_CONFIGURATION;
3947
}
4048
}

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

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

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

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

0 commit comments

Comments
 (0)