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

Commit ebf697b

Browse files
authored
chore: fix cortex bundle relative path lookup (#758)
1 parent 64364c2 commit ebf697b

File tree

5 files changed

+86
-109
lines changed

5 files changed

+86
-109
lines changed

.github/workflows/cortex-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: CI Cortex CPP
1+
name: CI Cortex Release
22

33
on:
44
push:

cortex-js/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
"dev": "nest dev",
1313
"build": "nest build && cpx \"cpuinfo/bin/**\" dist/bin",
1414
"build:binary": "run-script-os && cpx \"cpuinfo/bin/**\" dist/bin",
15-
"build:binary:windows": "bun build --compile --target=bun-windows-x64 ./src/command.js --outfile cortex.exe --external @nestjs/microservices --external @nestjs/websockets/socket-module --external class-transformer/storage",
16-
"build:binary:linux": "bun build --compile --target=bun-linux-x64 ./src/command.js --outfile cortex --external @nestjs/microservices --external @nestjs/websockets/socket-module --external class-transformer/storage",
17-
"build:binary:macos": "bun build --compile --target=bun-darwin-arm64 ./src/command.js --outfile cortex --external @nestjs/microservices --external @nestjs/websockets/socket-module --external class-transformer/storage",
15+
"build:binary:windows": "bun build --compile --target=bun-windows-x64 ./src/command.ts --outfile cortex.exe --external @nestjs/microservices --external @nestjs/websockets/socket-module --external class-transformer/storage",
16+
"build:binary:linux": "bun build --compile --target=bun-linux-x64 ./src/command.ts --outfile cortex --external @nestjs/microservices --external @nestjs/websockets/socket-module --external class-transformer/storage",
17+
"build:binary:macos": "bun build --compile --target=bun-darwin-arm64 ./src/command.ts --outfile cortex --external @nestjs/microservices --external @nestjs/websockets/socket-module --external class-transformer/storage",
1818
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
1919
"build:extensions": "run-script-os",
2020
"build:extensions:windows": "powershell -command \"$jobs = Get-ChildItem -Path './src/extensions' -Directory | ForEach-Object { Start-Job -Name ($_.Name) -ScriptBlock { param($_dir); try { Set-Location $_dir; yarn; yarn build; Write-Output 'Build successful in ' + $_dir } catch { Write-Error 'Error in ' + $_dir; throw } } -ArgumentList $_.FullName }; $jobs | Wait-Job; $jobs | ForEach-Object { Receive-Job -Job $_ -Keep } | ForEach-Object { Write-Host $_ }; $failed = $jobs | Where-Object { $_.State -ne 'Completed' -or $_.ChildJobs[0].JobStateInfo.State -ne 'Completed' }; if ($failed) { Exit 1 }\"",

cortex-js/src/app.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { NestFactory } from '@nestjs/core';
2+
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
3+
import { AppModule } from './app.module';
4+
import { FileManagerService } from './infrastructure/services/file-manager/file-manager.service';
5+
import { ValidationPipe } from '@nestjs/common';
6+
export const getApp = async () => {
7+
const app = await NestFactory.create(AppModule, {
8+
snapshot: true,
9+
cors: true,
10+
logger: console
11+
});
12+
13+
const fileService = app.get(FileManagerService);
14+
await fileService.getConfig();
15+
16+
app.useGlobalPipes(
17+
new ValidationPipe({
18+
transform: true,
19+
enableDebugMessages: true,
20+
}),
21+
);
22+
23+
const config = new DocumentBuilder()
24+
.setTitle('Cortex API')
25+
.setDescription(
26+
'Cortex API provides a command-line interface (CLI) for seamless interaction with large language models (LLMs). Fully compatible with the [OpenAI API](https://platform.openai.com/docs/api-reference), it enables straightforward command execution and management of LLM interactions.',
27+
)
28+
.setVersion('1.0')
29+
.addTag(
30+
'Inference',
31+
'This endpoint initiates interaction with a Language Learning Model (LLM).',
32+
)
33+
.addTag(
34+
'Assistants',
35+
'These endpoints manage the lifecycle of an Assistant within a conversation thread.',
36+
)
37+
.addTag(
38+
'Models',
39+
'These endpoints provide a list and descriptions of all available models within the Cortex framework.',
40+
)
41+
.addTag(
42+
'Messages',
43+
'These endpoints manage the retrieval and storage of conversation content, including responses from LLMs and other metadata related to chat interactions.',
44+
)
45+
.addTag(
46+
'Threads',
47+
'These endpoints handle the creation, retrieval, updating, and deletion of conversation threads.',
48+
)
49+
.addTag(
50+
'Embeddings',
51+
'Endpoint for creating and retrieving embedding vectors from text inputs using specified models.',
52+
)
53+
.addTag(
54+
'Status',
55+
"Endpoint for actively querying the health status of the Cortex's API server.",
56+
)
57+
.addTag(
58+
'Processes',
59+
'Endpoint for terminating the Cortex API server processes.',
60+
)
61+
.addTag(
62+
'Events',
63+
'Endpoints for observing Cortex statuses through event notifications.',
64+
)
65+
.addServer('http://localhost:1337')
66+
.addServer('http://localhost:1337/v1')
67+
.build();
68+
const document = SwaggerModule.createDocument(app, config);
69+
70+
SwaggerModule.setup('api', app, document);
71+
return app;
72+
};
Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import { spawn } from 'child_process';
21
import {
32
defaultCortexJsHost,
43
defaultCortexJsPort,
54
} from '@/infrastructure/constants/cortex';
65
import { CommandRunner, SubCommand, Option } from 'nest-commander';
7-
import { join } from 'path';
86
import { SetCommandContext } from './decorators/CommandContext';
97
import { ServeStopCommand } from './sub-commands/serve-stop.command';
108
import { ContextService } from '../services/context/context.service';
9+
import { getApp } from '@/app';
10+
import { Logger } from '@nestjs/common';
1111

1212
type ServeOptions = {
1313
address?: string;
@@ -30,32 +30,14 @@ export class ServeCommand extends CommandRunner {
3030
const host = options?.address || defaultCortexJsHost;
3131
const port = options?.port || defaultCortexJsPort;
3232

33-
return this.startServer(host, port, options);
33+
return this.startServer(host, port);
3434
}
3535

36-
private async startServer(
37-
host: string,
38-
port: number,
39-
options: ServeOptions = { detach: false },
40-
) {
41-
const serveProcess = spawn(
42-
'node',
43-
[join(__dirname, '../../../dist/src/main.js')],
44-
{
45-
env: {
46-
...process.env,
47-
CORTEX_JS_HOST: host,
48-
CORTEX_JS_PORT: port.toString(),
49-
NODE_ENV: 'production',
50-
},
51-
stdio: options?.detach ? 'ignore' : 'inherit',
52-
detached: options?.detach,
53-
},
54-
);
55-
if (options?.detach) {
56-
serveProcess.unref();
57-
console.log('Started server at http://%s:%d', host, port);
58-
}
36+
private async startServer(host: string, port: number) {
37+
const app = await getApp();
38+
39+
await app.listen(port, host);
40+
console.log(`Started server at http://${host}:${port}`);
5941
}
6042

6143
@Option({
@@ -73,14 +55,4 @@ export class ServeCommand extends CommandRunner {
7355
parsePort(value: string) {
7456
return parseInt(value, 10);
7557
}
76-
77-
@Option({
78-
flags: '-d, --detach',
79-
description: 'Run the server in detached mode',
80-
defaultValue: false,
81-
name: 'detach',
82-
})
83-
parseDetach() {
84-
return true;
85-
}
8658
}

cortex-js/src/main.ts

Lines changed: 2 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,11 @@
1-
import { NestFactory } from '@nestjs/core';
2-
import { AppModule } from './app.module';
3-
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
4-
import { ValidationPipe } from '@nestjs/common';
51
import {
62
defaultCortexJsHost,
73
defaultCortexJsPort,
84
} from '@/infrastructure/constants/cortex';
9-
import { FileManagerService } from './infrastructure/services/file-manager/file-manager.service';
5+
import { getApp } from './app';
106

117
async function bootstrap() {
12-
const app = await NestFactory.create(AppModule, {
13-
snapshot: true,
14-
cors: true,
15-
});
16-
17-
const fileService = app.get(FileManagerService);
18-
await fileService.getConfig();
19-
20-
app.useGlobalPipes(
21-
new ValidationPipe({
22-
transform: true,
23-
enableDebugMessages: true,
24-
}),
25-
);
26-
27-
const config = new DocumentBuilder()
28-
.setTitle('Cortex API')
29-
.setDescription(
30-
'Cortex API provides a command-line interface (CLI) for seamless interaction with large language models (LLMs). Fully compatible with the [OpenAI API](https://platform.openai.com/docs/api-reference), it enables straightforward command execution and management of LLM interactions.',
31-
)
32-
.setVersion('1.0')
33-
.addTag(
34-
'Inference',
35-
'This endpoint initiates interaction with a Language Learning Model (LLM).',
36-
)
37-
.addTag(
38-
'Assistants',
39-
'These endpoints manage the lifecycle of an Assistant within a conversation thread.',
40-
)
41-
.addTag(
42-
'Models',
43-
'These endpoints provide a list and descriptions of all available models within the Cortex framework.',
44-
)
45-
.addTag(
46-
'Messages',
47-
'These endpoints manage the retrieval and storage of conversation content, including responses from LLMs and other metadata related to chat interactions.',
48-
)
49-
.addTag(
50-
'Threads',
51-
'These endpoints handle the creation, retrieval, updating, and deletion of conversation threads.',
52-
)
53-
.addTag(
54-
'Embeddings',
55-
'Endpoint for creating and retrieving embedding vectors from text inputs using specified models.',
56-
)
57-
.addTag(
58-
'Status',
59-
"Endpoint for actively querying the health status of the Cortex's API server.",
60-
)
61-
.addTag(
62-
'Processes',
63-
'Endpoint for terminating the Cortex API server processes.',
64-
)
65-
.addTag(
66-
'Events',
67-
'Endpoints for observing Cortex statuses through event notifications.',
68-
)
69-
.addServer('http://localhost:1337')
70-
.addServer('http://localhost:1337/v1')
71-
.build();
72-
const document = SwaggerModule.createDocument(app, config);
73-
74-
SwaggerModule.setup('api', app, document);
75-
8+
const app = await getApp();
769
// getting port from env
7710
const host = process.env.CORTEX_JS_HOST || defaultCortexJsHost;
7811
const port = process.env.CORTEX_JS_PORT || defaultCortexJsPort;

0 commit comments

Comments
 (0)