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

Commit d2c83b4

Browse files
namchuailouis-jan
andauthored
[DRAFT] feat: add cortex-js (#530)
Signed-off-by: James <namnh0122@gmail.com> Co-authored-by: Louis <louis@jan.ai>
1 parent e7ae2e5 commit d2c83b4

File tree

138 files changed

+3038
-6197
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

138 files changed

+3038
-6197
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# cortex-js
2+
cortex-js/cortex.db
3+
dist
4+
*.lock
5+
node_modules
6+
.turbo

cortex-js/.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
EXTENSIONS_PATH=<EXTENSIONS_PATH>
2+
CORTEX_MODELS_DIR=<CORTEX_MODELS_DIR>
3+
CORTEX_BINARY_PATH=<CORTEX_BINARY_PATH>

cortex-js/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,7 @@ pids
5454

5555
# Diagnostic reports (https://nodejs.org/api/report.html)
5656
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
57+
58+
# cortex-js
59+
cortex.db
60+
dist

cortex-js/constant.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
export const databaseName = 'cortex';
22

33
export const databaseFile = `${databaseName}.db`;
4+
5+
export const defaultCortexJsHost = 'localhost';
6+
export const defaultCortexJsPort = 7331;

cortex-js/package.json

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33
"version": "0.0.1",
44
"description": "",
55
"author": "",
6-
"private": true,
7-
"license": "UNLICENSED",
6+
"license": "AGPL-3.0",
7+
"bin": {
8+
"cortex": "./dist/src/command.js"
9+
},
810
"scripts": {
9-
"build": "nest build",
11+
"dev": "nest dev",
12+
"build": "yarn build:extensions && nest build",
1013
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
14+
"build:extensions": "for dir in ./src/extensions/*/; do (cd \"$dir\" && yarn && yarn build); done",
1115
"start": "nest start",
1216
"start:dev": "nest start --watch",
1317
"start:debug": "nest start --debug --watch",
@@ -21,28 +25,39 @@
2125
"typeorm": "typeorm-ts-node-esm"
2226
},
2327
"dependencies": {
28+
"@nestjs/axios": "^3.0.2",
2429
"@nestjs/common": "^10.0.0",
30+
"@nestjs/config": "^3.2.2",
2531
"@nestjs/core": "^10.0.0",
2632
"@nestjs/devtools-integration": "^0.1.6",
2733
"@nestjs/mapped-types": "*",
2834
"@nestjs/platform-express": "^10.0.0",
2935
"@nestjs/swagger": "^7.3.1",
36+
"axios": "^1.6.8",
3037
"class-transformer": "^0.5.1",
3138
"class-validator": "^0.14.1",
39+
"cli-progress": "^3.12.0",
40+
"nest-commander": "^3.13.0",
41+
"node-fetch": "2",
42+
"readline": "^1.3.0",
3243
"reflect-metadata": "^0.2.0",
44+
"request": "^2.88.2",
45+
"request-progress": "^3.0.0",
3346
"rxjs": "^7.8.1",
3447
"sqlite": "^5.1.1",
3548
"sqlite3": "^5.1.7",
36-
"typeorm": "^0.3.20"
49+
"typeorm": "^0.3.20",
50+
"ulid": "^2.3.0"
3751
},
3852
"devDependencies": {
3953
"@nestjs/cli": "^10.0.0",
4054
"@nestjs/schematics": "^10.0.0",
4155
"@nestjs/testing": "^10.0.0",
4256
"@nestjs/typeorm": "^10.0.2",
57+
"@types/cli-progress": "^3.11.5",
4358
"@types/express": "^4.17.17",
4459
"@types/jest": "^29.5.2",
45-
"@types/node": "^20.3.1",
60+
"@types/node": "^20.12.9",
4661
"@types/supertest": "^6.0.0",
4762
"@typescript-eslint/eslint-plugin": "^6.0.0",
4863
"@typescript-eslint/parser": "^6.0.0",
@@ -55,10 +70,12 @@
5570
"supertest": "^6.3.3",
5671
"ts-jest": "^29.1.0",
5772
"ts-loader": "^9.4.3",
58-
"ts-node": "^10.9.2",
5973
"tsconfig-paths": "^4.2.0",
6074
"typescript": "^5.1.3"
6175
},
76+
"files": [
77+
"dist"
78+
],
6279
"jest": {
6380
"moduleFileExtensions": [
6481
"js",

cortex-js/src/app.controller.spec.ts

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

cortex-js/src/app.controller.ts

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

cortex-js/src/app.module.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,35 @@
11
import { Module } from '@nestjs/common';
2-
import { AppController } from './app.controller';
3-
import { ThreadsController } from './threads/threads.controller';
4-
import { ModelsController } from './models/models.controller';
5-
import { MessagesModule } from './messages/messages.module';
6-
import { ThreadsModule } from './threads/threads.module';
7-
import { ModelsModule } from './models/models.module';
2+
import { MessagesModule } from './usecases/messages/messages.module';
3+
import { ThreadsModule } from './usecases/threads/threads.module';
4+
import { ModelsModule } from './usecases/models/models.module';
85
import { DevtoolsModule } from '@nestjs/devtools-integration';
9-
import { CoreModule } from './core/core.module';
10-
import { DatabaseModule } from './database/database.module';
6+
import { DatabaseModule } from './infrastructure/database/database.module';
7+
import { ChatModule } from './usecases/chat/chat.module';
8+
import { AssistantsModule } from './usecases/assistants/assistants.module';
9+
import { InferenceSettingsModule } from './usecases/inference-settings/inference-settings.module';
10+
import { ExtensionModule } from './infrastructure/repositories/extensions/extension.module';
11+
import { CortexModule } from './usecases/cortex/cortex.module';
12+
import { ConfigModule } from '@nestjs/config';
1113

1214
@Module({
1315
imports: [
1416
DevtoolsModule.register({
1517
http: process.env.NODE_ENV !== 'production',
1618
}),
19+
ConfigModule.forRoot({
20+
isGlobal: true,
21+
envFilePath:
22+
process.env.NODE_ENV === 'production' ? '.env' : '.env.development',
23+
}),
1724
DatabaseModule,
1825
MessagesModule,
1926
ThreadsModule,
2027
ModelsModule,
21-
CoreModule,
28+
ChatModule,
29+
AssistantsModule,
30+
InferenceSettingsModule,
31+
CortexModule,
32+
ExtensionModule,
2233
],
23-
controllers: [AppController, ThreadsController, ModelsController],
2434
})
2535
export class AppModule {}

cortex-js/src/command.module.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { Module } from '@nestjs/common';
2+
import { BasicCommand } from './infrastructure/commanders/basic-command.commander';
3+
import { ModelsModule } from './usecases/models/models.module';
4+
import { DatabaseModule } from './infrastructure/database/database.module';
5+
import { ConfigModule } from '@nestjs/config';
6+
import { CortexModule } from './usecases/cortex/cortex.module';
7+
import { ServeCommand } from './infrastructure/commanders/serve.command';
8+
import { PullCommand } from './infrastructure/commanders/pull.command';
9+
import { InferenceCommand } from './infrastructure/commanders/inference.command';
10+
11+
@Module({
12+
imports: [
13+
ConfigModule.forRoot({
14+
isGlobal: true,
15+
envFilePath:
16+
process.env.NODE_ENV !== 'production' ? '.env.development' : '.env',
17+
}),
18+
DatabaseModule,
19+
ModelsModule,
20+
CortexModule,
21+
],
22+
providers: [BasicCommand, PullCommand, ServeCommand, InferenceCommand],
23+
})
24+
export class CommandModule {}

cortex-js/src/command.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env node --no-warnings
2+
import { CommandFactory } from 'nest-commander';
3+
import { CommandModule } from './command.module';
4+
5+
async function bootstrap() {
6+
await CommandFactory.run(CommandModule);
7+
}
8+
9+
bootstrap();

0 commit comments

Comments
 (0)