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

Commit 793f0dc

Browse files
committed
fix: persists engine version on init
1 parent d07e092 commit 793f0dc

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

cortex-js/src/infrastructure/providers/cortex/cortex.provider.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { readdirSync } from 'node:fs';
1313
import { normalizeModelId } from '@/utils/normalize-model-id';
1414
import { firstValueFrom } from 'rxjs';
1515
import { FileManagerService } from '@/infrastructure/services/file-manager/file-manager.service';
16+
import { existsSync, readFileSync } from 'fs';
1617

1718
export interface ModelStatResponse {
1819
object: string;
@@ -37,6 +38,7 @@ export default class CortexProvider extends OAIEngineExtension {
3738
protected readonly fileManagerService: FileManagerService,
3839
) {
3940
super(httpService);
41+
this.persistEngineVersion();
4042
}
4143

4244
// Override the inference method to make an inference request to the engine
@@ -165,4 +167,14 @@ export default class CortexProvider extends OAIEngineExtension {
165167
// Return an error if none of the conditions are met
166168
return { error: 'Cannot split prompt template' };
167169
};
170+
171+
private persistEngineVersion = async () => {
172+
const versionFilePath = join(
173+
await this.fileManagerService.getCortexCppEnginePath(),
174+
this.name,
175+
'version.txt',
176+
);
177+
if (existsSync(versionFilePath))
178+
this.version = readFileSync(versionFilePath, 'utf-8');
179+
};
168180
}

cortex-js/src/infrastructure/repositories/extensions/extension.repository.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class ExtensionRepositoryImpl implements ExtensionRepository {
3131
// Watch engine folder only for now
3232
fileService.getCortexCppEnginePath().then((path) => {
3333
if (!existsSync(path)) mkdirSync(path);
34-
watch(path, (eventType, filename) => {
34+
watch(path, () => {
3535
this.extensions.clear();
3636
this.loadCoreExtensions();
3737
this.loadExternalExtensions();

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ForbiddenException, Injectable } from '@nestjs/common';
22
import { ExtensionRepository } from '@/domain/repositories/extension.interface';
33

4-
import { cpSync, existsSync, mkdirSync, readdirSync } from 'fs';
4+
import { cpSync, existsSync, mkdirSync, readdirSync, writeFileSync } from 'fs';
55
import { join } from 'path';
66
import { HttpService } from '@nestjs/axios';
77
import decompress from 'decompress';
@@ -23,7 +23,7 @@ import { CommonResponseDto } from '@/infrastructure/dtos/common/common-response.
2323
import { EngineStatus } from '@/domain/abstracts/engine.abstract';
2424
import { ConfigsUsecases } from '../configs/configs.usecase';
2525
import { defaultInstallationOptions } from '@/utils/init';
26-
import { isEmpty } from "lodash"
26+
import { isEmpty } from 'lodash';
2727
@Injectable()
2828
export class EnginesUsecases {
2929
constructor(
@@ -276,6 +276,7 @@ export class EnginesUsecases {
276276
engine,
277277
DownloadType.Engine,
278278
{ [toDownloadAsset.browser_download_url]: destination },
279+
// On completed - post processing
279280
async () => {
280281
try {
281282
await decompress(destination, engineDir);
@@ -288,9 +289,15 @@ export class EnginesUsecases {
288289
// Copy the additional files to the cortex-cpp directory
289290
for (const file of readdirSync(join(engineDir, engine))) {
290291
if (!file.includes('engine')) {
291-
await cpSync(join(engineDir, engine, file), join(engineDir, file));
292+
cpSync(join(engineDir, engine, file), join(engineDir, file));
292293
}
293294
}
295+
296+
writeFileSync(
297+
join(engineDir, engine, 'version.txt'),
298+
release.tag_name.replace(/^v/, ''),
299+
'utf-8',
300+
);
294301
},
295302
);
296303
}

0 commit comments

Comments
 (0)