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

Commit dc187bc

Browse files
louis-janirfanpena
authored andcommitted
feat: cortex single executable binary (#715)
1 parent 83769b7 commit dc187bc

18 files changed

+28
-15
lines changed

cortex-js/package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"scripts": {
1212
"dev": "nest dev",
1313
"build": "yarn build:extensions && nest build && cpx \"cpuinfo/bin/**\" dist/bin",
14+
"build:binary": "yarn build && nexe dist/src/command.js --build --python=$(which python3) -o dist/cortex",
1415
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
1516
"build:extensions": "run-script-os",
1617
"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 }\"",
@@ -19,7 +20,7 @@
1920
"start": "nest start",
2021
"start:dev": "nest start --watch",
2122
"start:debug": "nest start --debug --watch",
22-
"start:prod": "node dist/main",
23+
"start:prod": "node dist/src/main --trace-deprecation",
2324
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
2425
"test": "jest",
2526
"test:watch": "jest --watch",
@@ -84,8 +85,10 @@
8485
"eslint-config-prettier": "^9.0.0",
8586
"eslint-plugin-prettier": "^5.0.0",
8687
"hanbi": "^1.0.3",
88+
"is-primitive": "^3.0.1",
8789
"jest": "^29.5.0",
8890
"nest-commander-testing": "^3.3.0",
91+
"nexe": "^4.0.0-rc.6",
8992
"prettier": "^3.0.0",
9093
"run-script-os": "^1.1.6",
9194
"source-map-support": "^0.5.21",
@@ -95,6 +98,10 @@
9598
"tsconfig-paths": "^4.2.0",
9699
"typescript": "^5.1.3"
97100
},
101+
"resolutions": {
102+
"ajv": "8.15.0",
103+
"whatwg-url": "14.0.0"
104+
},
98105
"files": [
99106
"dist"
100107
],

cortex-js/src/app.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { ModelsController } from './infrastructure/controllers/models.controller
2626
import { ThreadsController } from './infrastructure/controllers/threads.controller';
2727
import { StatusController } from './infrastructure/controllers/status.controller';
2828
import { ProcessController } from './infrastructure/controllers/process.controller';
29-
import { DownloadManagerModule } from './download-manager/download-manager.module';
29+
import { DownloadManagerModule } from './infrastructure/services/download-manager/download-manager.module';
3030

3131
@Module({
3232
imports: [

cortex-js/src/command.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { UtilModule } from './util/util.module';
3333
import { EmbeddingCommand } from './infrastructure/commanders/embeddings.command';
3434
import { BenchmarkCommand } from './infrastructure/commanders/benchmark.command';
3535
import { EventEmitterModule } from '@nestjs/event-emitter';
36-
import { DownloadManagerModule } from './download-manager/download-manager.module';
36+
import { DownloadManagerModule } from './infrastructure/services/download-manager/download-manager.module';
3737
import { ServeStopCommand } from './infrastructure/commanders/sub-commands/serve-stop.command';
3838

3939
@Module({

cortex-js/src/command.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env node --no-warnings
1+
#!/usr/bin/env node
22
import { CommandFactory } from 'nest-commander';
33
import { CommandModule } from './command.module';
44
import updateNotifier from 'update-notifier';

cortex-js/src/infrastructure/controllers/chat.controller.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { DatabaseModule } from '../database/database.module';
55
import { ExtensionModule } from '../repositories/extensions/extension.module';
66
import { ModelRepositoryModule } from '../repositories/models/model.module';
77
import { HttpModule } from '@nestjs/axios';
8-
import { DownloadManagerModule } from '@/download-manager/download-manager.module';
8+
import { DownloadManagerModule } from '@/infrastructure/services/download-manager/download-manager.module';
99
import { EventEmitterModule } from '@nestjs/event-emitter';
1010
import { TelemetryModule } from '@/usecases/telemetry/telemetry.module';
1111

cortex-js/src/infrastructure/controllers/embeddings.controller.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { DatabaseModule } from '../database/database.module';
55
import { ModelRepositoryModule } from '../repositories/models/model.module';
66
import { ExtensionModule } from '../repositories/extensions/extension.module';
77
import { HttpModule } from '@nestjs/axios';
8-
import { DownloadManagerModule } from '@/download-manager/download-manager.module';
8+
import { DownloadManagerModule } from '@/infrastructure/services/download-manager/download-manager.module';
99
import { EventEmitterModule } from '@nestjs/event-emitter';
1010
import { TelemetryModule } from '@/usecases/telemetry/telemetry.module';
1111

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
ModelStatus,
1010
ModelStatusAndEvent,
1111
} from '@/domain/models/model.event';
12-
import { DownloadManagerService } from '@/download-manager/download-manager.service';
12+
import { DownloadManagerService } from '@/infrastructure/services/download-manager/download-manager.service';
1313
import { ModelsUsecases } from '@/usecases/models/models.usecases';
1414
import { Controller, Sse } from '@nestjs/common';
1515
import { EventEmitter2 } from '@nestjs/event-emitter';

cortex-js/src/infrastructure/controllers/models.controller.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { FileManagerModule } from '@/infrastructure/services/file-manager/file-m
77
import { HttpModule } from '@nestjs/axios';
88
import { CortexUsecases } from '@/usecases/cortex/cortex.usecases';
99
import { ModelRepositoryModule } from '../repositories/models/model.module';
10-
import { DownloadManagerModule } from '@/download-manager/download-manager.module';
10+
import { DownloadManagerModule } from '@/infrastructure/services/download-manager/download-manager.module';
1111
import { EventEmitterModule } from '@nestjs/event-emitter';
1212
import { TelemetryModule } from '@/usecases/telemetry/telemetry.module';
1313
import { UtilModule } from '@/util/util.module';

cortex-js/src/infrastructure/database/mysql-database.providers.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { databaseName } from '@/infrastructure/constants/cortex';
22
import { DataSource } from 'typeorm';
3+
import { ThreadEntity } from '../entities/thread.entity';
4+
import { AssistantEntity } from '../entities/assistant.entity';
5+
import { MessageEntity } from '../entities/message.entity';
36

47
export const mysqlDatabaseProviders = [
58
{
@@ -12,7 +15,7 @@ export const mysqlDatabaseProviders = [
1215
username: 'root',
1316
password: '',
1417
database: databaseName,
15-
entities: [__dirname + '/../**/*.entity{.ts,.js}'],
18+
entities: [ThreadEntity, AssistantEntity, MessageEntity],
1619
synchronize: process.env.NODE_ENV !== 'production',
1720
});
1821

cortex-js/src/infrastructure/database/sqlite-database.providers.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { FileManagerService } from '@/infrastructure/services/file-manager/file-
22
import { databaseFile } from '@/infrastructure/constants/cortex';
33
import { join } from 'path';
44
import { DataSource } from 'typeorm';
5+
import { ThreadEntity } from '../entities/thread.entity';
6+
import { AssistantEntity } from '../entities/assistant.entity';
7+
import { MessageEntity } from '../entities/message.entity';
58

69
export const sqliteDatabaseProviders = [
710
{
@@ -14,7 +17,7 @@ export const sqliteDatabaseProviders = [
1417
type: 'sqlite',
1518
database: sqlitePath,
1619
synchronize: process.env.NODE_ENV !== 'production',
17-
entities: [__dirname + '/../**/*.entity{.ts,.js}'],
20+
entities: [ThreadEntity, AssistantEntity, MessageEntity],
1821
});
1922

2023
return dataSource.initialize();

0 commit comments

Comments
 (0)