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

Commit 1356360

Browse files
chore: group system apis (#924)
Co-authored-by: Louis <louis@jan.ai>
1 parent 1fab7dc commit 1356360

File tree

8 files changed

+44
-70
lines changed

8 files changed

+44
-70
lines changed

cortex-js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"class-validator": "^0.14.1",
5656
"cli-progress": "^3.12.0",
5757
"cortex-cpp": "0.4.34",
58-
"@cortexso/cortex.js": "^0.1.2",
58+
"@cortexso/cortex.js": "^0.1.3",
5959
"cpu-instructions": "^0.0.11",
6060
"decompress": "^4.2.1",
6161
"js-yaml": "^4.1.0",

cortex-js/src/app.module.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,12 @@ import { TelemetryModule } from './usecases/telemetry/telemetry.module';
1616
import { APP_FILTER } from '@nestjs/core';
1717
import { GlobalExceptionFilter } from './infrastructure/exception/global.exception';
1818
import { EventEmitterModule } from '@nestjs/event-emitter';
19-
import { EventsController } from './infrastructure/controllers/events.controller';
2019
import { AssistantsController } from './infrastructure/controllers/assistants.controller';
2120
import { ChatController } from './infrastructure/controllers/chat.controller';
2221
import { EmbeddingsController } from './infrastructure/controllers/embeddings.controller';
2322
import { ModelsController } from './infrastructure/controllers/models.controller';
2423
import { ThreadsController } from './infrastructure/controllers/threads.controller';
25-
import { StatusController } from './infrastructure/controllers/status.controller';
26-
import { ProcessController } from './infrastructure/controllers/process.controller';
24+
import { SystemController } from './infrastructure/controllers/system.controller';
2725
import { DownloadManagerModule } from './infrastructure/services/download-manager/download-manager.module';
2826
import { ContextModule } from './infrastructure/services/context/context.module';
2927
import { ExtensionsModule } from './extensions/extensions.module';
@@ -66,9 +64,7 @@ import { ResourceManagerModule } from './infrastructure/services/resources-manag
6664
EmbeddingsController,
6765
ModelsController,
6866
ThreadsController,
69-
StatusController,
70-
ProcessController,
71-
EventsController,
67+
SystemController,
7268
EnginesController,
7369
],
7470
providers: [

cortex-js/src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
CORTEX_JS_STOP_API_SERVER_URL,
2+
CORTEX_JS_SYSTEM_URL,
33
defaultCortexJsHost,
44
defaultCortexJsPort,
55
} from '@/infrastructure/constants/cortex';
@@ -33,8 +33,8 @@ export async function start(host?: string, port?: number) {
3333
* Stop the API server
3434
* @returns
3535
*/
36-
export async function stop() {
37-
return fetch(CORTEX_JS_STOP_API_SERVER_URL(), {
36+
export async function stop(host?: string, port?: number) {
37+
return fetch(CORTEX_JS_SYSTEM_URL(host, port), {
3838
method: 'DELETE',
3939
}).catch(() => {});
4040
}

cortex-js/src/infrastructure/constants/cortex.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,13 @@ export const CORTEX_CPP_MODELS_URL = (
3636
port: number = defaultCortexCppPort,
3737
) => `http://${host}:${port}/inferences/server/models`;
3838

39-
export const CORTEX_JS_HEALTH_URL = (
39+
export const CORTEX_JS_SYSTEM_URL = (
4040
host: string = defaultCortexJsHost,
4141
port: number = defaultCortexJsPort,
42-
) => `http://${host}:${port}/v1/health`;
42+
) => `http://${host}:${port}/v1/system`;
4343

4444
export const CORTEX_JS_HEALTH_URL_WITH_API_PATH = (apiUrl: string) =>
45-
`${apiUrl}/v1/health`;
46-
47-
export const CORTEX_JS_STOP_API_SERVER_URL = (
48-
host: string = defaultCortexJsHost,
49-
port: number = defaultCortexJsPort,
50-
) => `http://${host}:${port}/v1/process`;
45+
`${apiUrl}/v1/system`;
5146

5247
// INITIALIZATION
5348
export const CORTEX_RELEASES_URL =

cortex-js/src/infrastructure/controllers/process.controller.ts

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

cortex-js/src/infrastructure/controllers/status.controller.ts

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

cortex-js/src/infrastructure/controllers/events.controller.ts renamed to cortex-js/src/infrastructure/controllers/system.controller.ts

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import {
1111
} from '@/domain/models/model.event';
1212
import { DownloadManagerService } from '@/infrastructure/services/download-manager/download-manager.service';
1313
import { ModelsUsecases } from '@/usecases/models/models.usecases';
14-
import { Controller, Sse } from '@nestjs/common';
14+
import { Controller, Delete, Get, HttpCode, Sse } from '@nestjs/common';
1515
import { EventEmitter2 } from '@nestjs/event-emitter';
16-
import { ApiOperation, ApiTags } from '@nestjs/swagger';
16+
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
1717
import {
1818
Observable,
1919
catchError,
@@ -31,21 +31,44 @@ import {
3131
import { ResourcesManagerService } from '../services/resources-manager/resources-manager.service';
3232
import { ResourceEvent } from '@/domain/models/resource.interface';
3333

34-
@ApiTags('Events')
35-
@Controller('events')
36-
export class EventsController {
34+
@ApiTags('System')
35+
@Controller('system')
36+
export class SystemController {
3737
constructor(
3838
private readonly downloadManagerService: DownloadManagerService,
3939
private readonly modelsUsecases: ModelsUsecases,
4040
private readonly eventEmitter: EventEmitter2,
4141
private readonly resourcesManagerService: ResourcesManagerService,
4242
) {}
4343

44+
@ApiOperation({
45+
summary: 'Terminate api server',
46+
description: 'Terminates the Cortex API endpoint server for the detached mode.',
47+
})
48+
@Delete()
49+
async delete() {
50+
process.exit(0);
51+
}
52+
53+
@ApiOperation({
54+
summary: "Get health status",
55+
description: "Retrieves the health status of your Cortex's system.",
56+
})
57+
@HttpCode(200)
58+
@ApiResponse({
59+
status: 200,
60+
description: 'Ok',
61+
})
62+
@Get()
63+
async get() {
64+
return 'OK';
65+
}
66+
4467
@ApiOperation({
4568
summary: 'Get download status',
4669
description: "Retrieves the model's download status.",
4770
})
48-
@Sse('download')
71+
@Sse('events/download')
4972
downloadEvent(): Observable<DownloadStateEvent> {
5073
const latestDownloadState$: Observable<DownloadStateEvent> = of({
5174
data: this.downloadManagerService.getDownloadStates(),
@@ -65,7 +88,7 @@ export class EventsController {
6588
summary: 'Get model status',
6689
description: 'Retrieves all the available model statuses within Cortex.',
6790
})
68-
@Sse('model')
91+
@Sse('events/model')
6992
modelEvent(): Observable<ModelStatusAndEvent> {
7093
const latestModelStatus$: Observable<Record<ModelId, ModelStatus>> = of(
7194
this.modelsUsecases.getModelStatuses(),
@@ -85,7 +108,7 @@ export class EventsController {
85108
summary: 'Get resources status',
86109
description: 'Retrieves the resources status of the system.',
87110
})
88-
@Sse('resources')
111+
@Sse('events/resources')
89112
resourcesEvent(): Observable<ResourceEvent> {
90113
const initialData$ = from(
91114
this.resourcesManagerService.getResourceStatuses(),

cortex-js/src/usecases/cortex/cortex.usecases.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import { FileManagerService } from '@/infrastructure/services/file-manager/file-
99
import {
1010
CORTEX_CPP_HEALTH_Z_URL,
1111
CORTEX_CPP_PROCESS_DESTROY_URL,
12-
CORTEX_JS_HEALTH_URL,
13-
CORTEX_JS_STOP_API_SERVER_URL,
12+
CORTEX_JS_SYSTEM_URL,
1413
defaultCortexJsHost,
1514
defaultCortexJsPort,
1615
} from '@/infrastructure/constants/cortex';
@@ -120,7 +119,7 @@ export class CortexUsecases {
120119
* @returns
121120
*/
122121
async stopServe(): Promise<void> {
123-
return fetch(CORTEX_JS_STOP_API_SERVER_URL(), {
122+
return fetch(CORTEX_JS_SYSTEM_URL(), {
124123
method: 'DELETE',
125124
})
126125
.then(() => {})
@@ -195,7 +194,7 @@ export class CortexUsecases {
195194
const apiServerHost = host || configApiServerHost || defaultCortexJsHost;
196195
const apiServerPort = port || configApiServerPort || defaultCortexJsPort;
197196
return firstValueFrom(
198-
this.httpService.get(CORTEX_JS_HEALTH_URL(apiServerHost, apiServerPort)),
197+
this.httpService.get(CORTEX_JS_SYSTEM_URL(apiServerHost, apiServerPort)),
199198
)
200199
.then((res) => res.status === HttpStatus.OK)
201200
.catch(() => false);
@@ -211,7 +210,7 @@ export class CortexUsecases {
211210
const apiServerHost = configApiServerHost || defaultCortexJsHost;
212211
const apiServerPort = configApiServerPort || defaultCortexJsPort;
213212
await this.stopCortex();
214-
return fetch(CORTEX_JS_STOP_API_SERVER_URL(apiServerHost, apiServerPort), {
213+
return fetch(CORTEX_JS_SYSTEM_URL(apiServerHost, apiServerPort), {
215214
method: 'DELETE',
216215
}).catch(() => {});
217216
}

0 commit comments

Comments
 (0)