Skip to content

Commit 0fb527a

Browse files
committed
fix lint and address review comment
1 parent 9a94643 commit 0fb527a

4 files changed

Lines changed: 58 additions & 14 deletions

File tree

apps/mcp-server/src/config/env-loader.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ export class EnvLoader {
8686
if (validLevels.includes(env.LOG_LEVEL)) {
8787
config.logLevel = env.LOG_LEVEL as any;
8888
} else {
89-
process.stderr.write(`Warning: Invalid LOG_LEVEL: ${env.LOG_LEVEL}. Using default 'info'.\n`);
89+
process.stderr.write(
90+
`Warning: Invalid LOG_LEVEL: ${env.LOG_LEVEL}. Using default 'info'.\n`,
91+
);
9092
}
9193
}
9294

@@ -96,7 +98,9 @@ export class EnvLoader {
9698
if (!isNaN(size) && size > 0) {
9799
config.maxStorageSize = size;
98100
} else {
99-
process.stderr.write(`Warning: Invalid MAX_STORAGE_SIZE: ${env.MAX_STORAGE_SIZE}. Using default.\n`);
101+
process.stderr.write(
102+
`Warning: Invalid MAX_STORAGE_SIZE: ${env.MAX_STORAGE_SIZE}. Using default.\n`,
103+
);
100104
}
101105
}
102106

@@ -110,7 +114,9 @@ export class EnvLoader {
110114
if (!isNaN(interval) && interval > 0) {
111115
config.metricsInterval = interval;
112116
} else {
113-
process.stderr.write(`Warning: Invalid METRICS_INTERVAL: ${env.METRICS_INTERVAL}. Using default.\n`);
117+
process.stderr.write(
118+
`Warning: Invalid METRICS_INTERVAL: ${env.METRICS_INTERVAL}. Using default.\n`,
119+
);
114120
}
115121
}
116122

apps/mcp-server/src/config/server-config.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,12 @@ export function getDefaultAuthConfig(): AuthConfig {
4545
};
4646
}
4747

48-
// For backwards compatibility - but prefer using getDefaultAuthConfig()
48+
/**
49+
* Default auth config - reads API key at module load time for backward compatibility.
50+
* For runtime reading of env vars, use getDefaultAuthConfig() instead.
51+
*/
4952
export const DEFAULT_AUTH_CONFIG: AuthConfig = {
50-
defaultApiKey: undefined, // Will be set at runtime via getDefaultAuthConfig()
53+
defaultApiKey: process.env.LIGHTHOUSE_API_KEY,
5154
enablePerRequestAuth: true,
5255
requireAuthentication: true,
5356
keyValidationCache: {
@@ -131,15 +134,18 @@ export function getDefaultServerConfig(): ServerConfig {
131134
};
132135
}
133136

134-
// For backwards compatibility - prefer using getDefaultServerConfig()
137+
/**
138+
* Default server config - reads API key at module load time for backward compatibility.
139+
* For runtime reading of env vars, use getDefaultServerConfig() instead.
140+
*/
135141
export const DEFAULT_SERVER_CONFIG: ServerConfig = {
136142
name: "lighthouse-storage",
137143
version: "0.1.0",
138144
logLevel: "info",
139145
maxStorageSize: 1024 * 1024 * 1024, // 1GB
140146
enableMetrics: true,
141147
metricsInterval: 60000, // 1 minute
142-
lighthouseApiKey: undefined, // Will be set at runtime
148+
lighthouseApiKey: process.env.LIGHTHOUSE_API_KEY,
143149
authentication: DEFAULT_AUTH_CONFIG,
144150
performance: DEFAULT_PERFORMANCE_CONFIG,
145151
multiTenancy: DEFAULT_MULTI_TENANCY_CONFIG,

apps/mcp-server/src/services/LighthouseService.ts

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ import { LighthouseAISDK, EnhancedAccessCondition } from "@lighthouse-tooling/sd
66
import { UploadResult, DownloadResult, AccessCondition, Dataset } from "@lighthouse-tooling/types";
77
import { Logger } from "@lighthouse-tooling/shared";
88
import { ILighthouseService, StoredFile } from "./ILighthouseService.js";
9-
import {
10-
IStorageService,
11-
InMemoryStorageService,
12-
} from "../storage/InMemoryStorageService.js";
9+
import { IStorageService, InMemoryStorageService } from "../storage/InMemoryStorageService.js";
1310
import { createStorageService } from "../storage/StorageFactory.js";
1411

1512
export class LighthouseService implements ILighthouseService {
@@ -53,6 +50,10 @@ export class LighthouseService implements ILighthouseService {
5350
if (!this.storageInitialized) {
5451
try {
5552
const newStorage = await createStorageService(this.dbPath);
53+
54+
// Migrate any data from in-memory storage to new storage
55+
this.migrateStorage(this.storage, newStorage);
56+
5657
// Close old in-memory storage
5758
this.storage.close();
5859
this.storage = newStorage;
@@ -73,6 +74,37 @@ export class LighthouseService implements ILighthouseService {
7374
}
7475
}
7576

77+
/**
78+
* Migrate data from old storage to new storage
79+
* This ensures no data is lost when upgrading from in-memory to SQLite
80+
*/
81+
private migrateStorage(oldStorage: IStorageService, newStorage: IStorageService): void {
82+
try {
83+
// Migrate files
84+
const files = oldStorage.listFiles();
85+
for (const file of files) {
86+
newStorage.saveFile(file);
87+
}
88+
89+
// Migrate datasets
90+
const { datasets } = oldStorage.listDatasets();
91+
for (const dataset of datasets) {
92+
newStorage.saveDataset(dataset);
93+
}
94+
95+
if (files.length > 0 || datasets.length > 0) {
96+
this.logger.info("Migrated data from in-memory to persistent storage", {
97+
fileCount: files.length,
98+
datasetCount: datasets.length,
99+
});
100+
}
101+
} catch (error) {
102+
this.logger.warn("Failed to migrate some data during storage upgrade", {
103+
error: error instanceof Error ? error.message : String(error),
104+
});
105+
}
106+
}
107+
76108
/**
77109
* Set up event listeners for SDK events
78110
*/

apps/mcp-server/src/storage/InMemoryStorageService.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export class InMemoryStorageService implements IStorageService {
6565
*/
6666
listFiles(limit?: number, offset?: number): StoredFile[] {
6767
const allFiles = Array.from(this.files.values()).sort(
68-
(a, b) => b.uploadedAt.getTime() - a.uploadedAt.getTime()
68+
(a, b) => b.uploadedAt.getTime() - a.uploadedAt.getTime(),
6969
);
7070

7171
const start = offset || 0;
@@ -119,13 +119,13 @@ export class InMemoryStorageService implements IStorageService {
119119
*/
120120
listDatasets(
121121
limit?: number,
122-
offset?: number
122+
offset?: number,
123123
): {
124124
datasets: Dataset[];
125125
total: number;
126126
} {
127127
const allDatasets = Array.from(this.datasets.values()).sort(
128-
(a, b) => b.updatedAt.getTime() - a.updatedAt.getTime()
128+
(a, b) => b.updatedAt.getTime() - a.updatedAt.getTime(),
129129
);
130130

131131
const start = offset || 0;

0 commit comments

Comments
 (0)