imcp 0.1.6 → 0.1.8-dev
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/commands/install.js +1 -106
- package/dist/cli/commands/install.js.map +1 -0
- package/dist/cli/commands/list.js +1 -90
- package/dist/cli/commands/list.js.map +1 -0
- package/dist/cli/commands/pull.js +1 -16
- package/dist/cli/commands/pull.js.map +1 -0
- package/dist/cli/commands/serve.js +1 -33
- package/dist/cli/commands/serve.js.map +1 -0
- package/dist/cli/commands/uninstall.js +1 -46
- package/dist/cli/commands/uninstall.js.map +1 -0
- package/dist/cli/index.js +1 -65
- package/dist/cli/index.js.map +1 -0
- package/dist/core/installers/clients/BaseClientInstaller.js +1 -282
- package/dist/core/installers/clients/BaseClientInstaller.js.map +1 -0
- package/dist/core/installers/clients/ClientInstaller.js +1 -163
- package/dist/core/installers/clients/ClientInstaller.js.map +1 -0
- package/dist/core/installers/clients/ClientInstallerFactory.js +1 -36
- package/dist/core/installers/clients/ClientInstallerFactory.js.map +1 -0
- package/dist/core/installers/clients/ClineInstaller.js +1 -30
- package/dist/core/installers/clients/ClineInstaller.js.map +1 -0
- package/dist/core/installers/clients/ExtensionInstaller.js +1 -151
- package/dist/core/installers/clients/ExtensionInstaller.js.map +1 -0
- package/dist/core/installers/clients/GithubCopilotInstaller.js +1 -68
- package/dist/core/installers/clients/GithubCopilotInstaller.js.map +1 -0
- package/dist/core/installers/clients/MSRooCodeInstaller.js +1 -28
- package/dist/core/installers/clients/MSRooCodeInstaller.js.map +1 -0
- package/dist/core/installers/index.js +1 -8
- package/dist/core/installers/index.js.map +1 -0
- package/dist/core/installers/requirements/BaseInstaller.js +1 -56
- package/dist/core/installers/requirements/BaseInstaller.js.map +1 -0
- package/dist/core/installers/requirements/CommandInstaller.js +1 -213
- package/dist/core/installers/requirements/CommandInstaller.js.map +1 -0
- package/dist/core/installers/requirements/GeneralInstaller.js +1 -126
- package/dist/core/installers/requirements/GeneralInstaller.js.map +1 -0
- package/dist/core/installers/requirements/InstallerFactory.js +1 -99
- package/dist/core/installers/requirements/InstallerFactory.js.map +1 -0
- package/dist/core/installers/requirements/NpmInstaller.js +1 -235
- package/dist/core/installers/requirements/NpmInstaller.js.map +1 -0
- package/dist/core/installers/requirements/NugetInstaller.js +1 -188
- package/dist/core/installers/requirements/NugetInstaller.js.map +1 -0
- package/dist/core/installers/requirements/PipInstaller.js +1 -192
- package/dist/core/installers/requirements/PipInstaller.js.map +1 -0
- package/dist/core/installers/requirements/RequirementInstaller.js +1 -2
- package/dist/core/installers/requirements/RequirementInstaller.js.map +1 -0
- package/dist/core/loaders/ConfigurationLoader.js +1 -256
- package/dist/core/loaders/ConfigurationLoader.js.map +1 -0
- package/dist/core/loaders/ConfigurationProvider.js +1 -383
- package/dist/core/loaders/ConfigurationProvider.js.map +1 -0
- package/dist/core/loaders/InstallOperationManager.js +1 -310
- package/dist/core/loaders/InstallOperationManager.js.map +1 -0
- package/dist/core/loaders/ServerSchemaLoader.js +1 -108
- package/dist/core/loaders/ServerSchemaLoader.js.map +1 -0
- package/dist/core/loaders/ServerSchemaProvider.js +1 -89
- package/dist/core/loaders/ServerSchemaProvider.js.map +1 -0
- package/dist/core/loaders/SystemSettingsManager.js +1 -256
- package/dist/core/loaders/SystemSettingsManager.js.map +1 -0
- package/dist/core/metadatas/constants.js +1 -100
- package/dist/core/metadatas/constants.js.map +1 -0
- package/dist/core/metadatas/recordingConstants.js +1 -46
- package/dist/core/metadatas/recordingConstants.js.map +1 -0
- package/dist/core/metadatas/types.js +1 -15
- package/dist/core/metadatas/types.js.map +1 -0
- package/dist/core/onboard/FeedOnboardService.js +1 -422
- package/dist/core/onboard/FeedOnboardService.js.map +1 -0
- package/dist/core/onboard/OnboardProcessor.js +1 -333
- package/dist/core/onboard/OnboardProcessor.js.map +1 -0
- package/dist/core/onboard/OnboardStatus.js +1 -9
- package/dist/core/onboard/OnboardStatus.js.map +1 -0
- package/dist/core/onboard/OnboardStatusManager.js +1 -360
- package/dist/core/onboard/OnboardStatusManager.js.map +1 -0
- package/dist/core/validators/FeedValidator.js +1 -133
- package/dist/core/validators/FeedValidator.js.map +1 -0
- package/dist/core/validators/IServerValidator.js +1 -1
- package/dist/core/validators/IServerValidator.js.map +1 -0
- package/dist/core/validators/SSEServerValidator.js +1 -38
- package/dist/core/validators/SSEServerValidator.js.map +1 -0
- package/dist/core/validators/ServerValidatorFactory.js +1 -44
- package/dist/core/validators/ServerValidatorFactory.js.map +1 -0
- package/dist/core/validators/StdioServerValidator.js +1 -281
- package/dist/core/validators/StdioServerValidator.js.map +1 -0
- package/dist/index.js +1 -18
- package/dist/index.js.map +1 -0
- package/dist/services/InstallationService.js +1 -81
- package/dist/services/InstallationService.js.map +1 -0
- package/dist/services/MCPManager.js +1 -197
- package/dist/services/MCPManager.js.map +1 -0
- package/dist/services/RequirementService.js +1 -548
- package/dist/services/RequirementService.js.map +1 -0
- package/dist/services/ServerService.js +1 -127
- package/dist/services/ServerService.js.map +1 -0
- package/dist/services/TelemetryService.js +1 -53
- package/dist/services/TelemetryService.js.map +1 -0
- package/dist/utils/UpdateCheckTracker.js +1 -79
- package/dist/utils/UpdateCheckTracker.js.map +1 -0
- package/dist/utils/adoUtils.js +1 -254
- package/dist/utils/adoUtils.js.map +1 -0
- package/dist/utils/clientUtils.js +1 -65
- package/dist/utils/clientUtils.js.map +1 -0
- package/dist/utils/feedUtils.js +1 -28
- package/dist/utils/feedUtils.js.map +1 -0
- package/dist/utils/githubAuth.js +1 -177
- package/dist/utils/githubAuth.js.map +1 -0
- package/dist/utils/githubUtils.js +1 -125
- package/dist/utils/githubUtils.js.map +1 -0
- package/dist/utils/logger.js +1 -176
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/macroExpressionUtils.js +1 -93
- package/dist/utils/macroExpressionUtils.js.map +1 -0
- package/dist/utils/osUtils.js +1 -664
- package/dist/utils/osUtils.js.map +1 -0
- package/dist/utils/versionUtils.js +1 -101
- package/dist/utils/versionUtils.js.map +1 -0
- package/dist/web/contract/serverContract.js +1 -1
- package/dist/web/contract/serverContract.js.map +1 -0
- package/dist/web/public/js/api.js +2 -132
- package/dist/web/public/js/api.js.map +1 -0
- package/dist/web/public/js/detailsWidget.js +2 -264
- package/dist/web/public/js/detailsWidget.js.map +1 -0
- package/dist/web/public/js/flights/flights.js +2 -127
- package/dist/web/public/js/flights/flights.js.map +1 -0
- package/dist/web/public/js/modal/index.js +2 -52
- package/dist/web/public/js/modal/index.js.map +1 -0
- package/dist/web/public/js/modal/installModal.js +2 -162
- package/dist/web/public/js/modal/installModal.js.map +1 -0
- package/dist/web/public/js/modal/installation.js +2 -266
- package/dist/web/public/js/modal/installation.js.map +1 -0
- package/dist/web/public/js/modal/loadingModal.js +2 -182
- package/dist/web/public/js/modal/loadingModal.js.map +1 -0
- package/dist/web/public/js/modal/modalSetup.js +2 -595
- package/dist/web/public/js/modal/modalSetup.js.map +1 -0
- package/dist/web/public/js/modal/modalUtils.js +2 -37
- package/dist/web/public/js/modal/modalUtils.js.map +1 -0
- package/dist/web/public/js/modal/versionUtils.js +2 -20
- package/dist/web/public/js/modal/versionUtils.js.map +1 -0
- package/dist/web/public/js/modal.js +2 -42
- package/dist/web/public/js/modal.js.map +1 -0
- package/dist/web/public/js/notifications.js +2 -137
- package/dist/web/public/js/notifications.js.map +1 -0
- package/dist/web/public/js/onboard/formProcessor.js +2 -1037
- package/dist/web/public/js/onboard/formProcessor.js.map +1 -0
- package/dist/web/public/js/onboard/index.js +2 -374
- package/dist/web/public/js/onboard/index.js.map +1 -0
- package/dist/web/public/js/onboard/publishHandler.js +2 -172
- package/dist/web/public/js/onboard/publishHandler.js.map +1 -0
- package/dist/web/public/js/onboard/state.js +2 -76
- package/dist/web/public/js/onboard/state.js.map +1 -0
- package/dist/web/public/js/onboard/templates.js +2 -342
- package/dist/web/public/js/onboard/templates.js.map +1 -0
- package/dist/web/public/js/onboard/uiHandlers.js +2 -1076
- package/dist/web/public/js/onboard/uiHandlers.js.map +1 -0
- package/dist/web/public/js/onboard/validationHandlers.js +2 -493
- package/dist/web/public/js/onboard/validationHandlers.js.map +1 -0
- package/dist/web/public/js/serverCategoryDetails.js +2 -364
- package/dist/web/public/js/serverCategoryDetails.js.map +1 -0
- package/dist/web/public/js/serverCategoryList.js +2 -241
- package/dist/web/public/js/serverCategoryList.js.map +1 -0
- package/dist/web/public/js/settings.js +2 -314
- package/dist/web/public/js/settings.js.map +1 -0
- package/dist/web/server.js +1 -404
- package/dist/web/server.js.map +1 -0
- package/package.json +8 -2
- package/.github/ISSUE_TEMPLATE/JitAccess.yml +0 -28
- package/.github/acl/access.yml +0 -20
- package/.github/compliance/inventory.yml +0 -5
- package/.github/policies/jit.yml +0 -19
- package/.github/workflows/build.yml +0 -28
- package/.roo/rules-code/rules.md +0 -88
- package/dist/cli/commands/start.d.ts +0 -2
- package/dist/cli/commands/start.js +0 -32
- package/dist/cli/commands/sync.d.ts +0 -2
- package/dist/cli/commands/sync.js +0 -17
- package/dist/core/ConfigurationLoader.d.ts +0 -32
- package/dist/core/ConfigurationLoader.js +0 -236
- package/dist/core/ConfigurationProvider.d.ts +0 -35
- package/dist/core/ConfigurationProvider.js +0 -375
- package/dist/core/InstallationService.d.ts +0 -50
- package/dist/core/InstallationService.js +0 -350
- package/dist/core/MCPManager.d.ts +0 -28
- package/dist/core/MCPManager.js +0 -188
- package/dist/core/RequirementService.d.ts +0 -40
- package/dist/core/RequirementService.js +0 -110
- package/dist/core/ServerSchemaLoader.d.ts +0 -11
- package/dist/core/ServerSchemaLoader.js +0 -43
- package/dist/core/ServerSchemaProvider.d.ts +0 -17
- package/dist/core/ServerSchemaProvider.js +0 -120
- package/dist/core/constants.d.ts +0 -47
- package/dist/core/constants.js +0 -94
- package/dist/core/installers/BaseInstaller.d.ts +0 -74
- package/dist/core/installers/BaseInstaller.js +0 -253
- package/dist/core/installers/ClientInstaller.d.ts +0 -23
- package/dist/core/installers/ClientInstaller.js +0 -564
- package/dist/core/installers/CommandInstaller.d.ts +0 -37
- package/dist/core/installers/CommandInstaller.js +0 -173
- package/dist/core/installers/GeneralInstaller.d.ts +0 -33
- package/dist/core/installers/GeneralInstaller.js +0 -85
- package/dist/core/installers/InstallerFactory.d.ts +0 -54
- package/dist/core/installers/InstallerFactory.js +0 -97
- package/dist/core/installers/NpmInstaller.d.ts +0 -26
- package/dist/core/installers/NpmInstaller.js +0 -127
- package/dist/core/installers/PipInstaller.d.ts +0 -28
- package/dist/core/installers/PipInstaller.js +0 -127
- package/dist/core/installers/RequirementInstaller.d.ts +0 -33
- package/dist/core/installers/RequirementInstaller.js +0 -3
- package/dist/core/types.d.ts +0 -166
- package/dist/core/types.js +0 -16
- package/dist/services/InstallRequestValidator.d.ts +0 -21
- package/dist/services/InstallRequestValidator.js +0 -99
- package/dist/web/public/js/modal/installHandler.js +0 -227
- package/dist/web/public/js/modal/loadingUI.js +0 -74
- package/dist/web/public/js/modal/messageQueue.js +0 -112
- package/dist/web/public/js/modal/modalUI.js +0 -214
- package/dist/web/public/js/modal/version.js +0 -20
- package/dist/web/public/js/onboard/ONBOARDING_PAGE_DESIGN.md +0 -370
- package/docs/ONBOARDING_PAGE_DESIGN.md +0 -260
- package/docs/Telemetry.md +0 -136
- package/memory-bank/activeContext.md +0 -26
- package/memory-bank/decisionLog.md +0 -91
- package/memory-bank/productContext.md +0 -41
- package/memory-bank/progress.md +0 -35
- package/memory-bank/systemPatterns.md +0 -10
- package/src/cli/commands/install.ts +0 -139
- package/src/cli/commands/list.ts +0 -113
- package/src/cli/commands/pull.ts +0 -16
- package/src/cli/commands/serve.ts +0 -39
- package/src/cli/commands/uninstall.ts +0 -64
- package/src/cli/index.ts +0 -82
- package/src/core/installers/clients/BaseClientInstaller.ts +0 -341
- package/src/core/installers/clients/ClientInstaller.ts +0 -222
- package/src/core/installers/clients/ClientInstallerFactory.ts +0 -43
- package/src/core/installers/clients/ClineInstaller.ts +0 -35
- package/src/core/installers/clients/ExtensionInstaller.ts +0 -165
- package/src/core/installers/clients/GithubCopilotInstaller.ts +0 -79
- package/src/core/installers/clients/MSRooCodeInstaller.ts +0 -32
- package/src/core/installers/index.ts +0 -11
- package/src/core/installers/requirements/BaseInstaller.ts +0 -85
- package/src/core/installers/requirements/CommandInstaller.ts +0 -231
- package/src/core/installers/requirements/GeneralInstaller.ts +0 -133
- package/src/core/installers/requirements/InstallerFactory.ts +0 -114
- package/src/core/installers/requirements/NpmInstaller.ts +0 -271
- package/src/core/installers/requirements/NugetInstaller.ts +0 -203
- package/src/core/installers/requirements/PipInstaller.ts +0 -207
- package/src/core/installers/requirements/RequirementInstaller.ts +0 -42
- package/src/core/loaders/ConfigurationLoader.ts +0 -298
- package/src/core/loaders/ConfigurationProvider.ts +0 -462
- package/src/core/loaders/InstallOperationManager.ts +0 -367
- package/src/core/loaders/ServerSchemaLoader.ts +0 -117
- package/src/core/loaders/ServerSchemaProvider.ts +0 -99
- package/src/core/loaders/SystemSettingsManager.ts +0 -278
- package/src/core/metadatas/constants.ts +0 -122
- package/src/core/metadatas/recordingConstants.ts +0 -65
- package/src/core/metadatas/types.ts +0 -202
- package/src/core/onboard/FeedOnboardService.ts +0 -501
- package/src/core/onboard/OnboardProcessor.ts +0 -356
- package/src/core/onboard/OnboardStatus.ts +0 -60
- package/src/core/onboard/OnboardStatusManager.ts +0 -416
- package/src/core/validators/FeedValidator.ts +0 -135
- package/src/core/validators/IServerValidator.ts +0 -21
- package/src/core/validators/SSEServerValidator.ts +0 -43
- package/src/core/validators/ServerValidatorFactory.ts +0 -51
- package/src/core/validators/StdioServerValidator.ts +0 -313
- package/src/index.ts +0 -44
- package/src/services/InstallationService.ts +0 -102
- package/src/services/MCPManager.ts +0 -249
- package/src/services/RequirementService.ts +0 -627
- package/src/services/ServerService.ts +0 -161
- package/src/services/TelemetryService.ts +0 -59
- package/src/utils/UpdateCheckTracker.ts +0 -86
- package/src/utils/adoUtils.ts +0 -293
- package/src/utils/clientUtils.ts +0 -72
- package/src/utils/feedUtils.ts +0 -31
- package/src/utils/githubAuth.ts +0 -212
- package/src/utils/githubUtils.ts +0 -164
- package/src/utils/logger.ts +0 -195
- package/src/utils/macroExpressionUtils.ts +0 -104
- package/src/utils/osUtils.ts +0 -700
- package/src/utils/versionUtils.ts +0 -114
- package/src/web/contract/serverContract.ts +0 -74
- package/src/web/public/css/detailsWidget.css +0 -235
- package/src/web/public/css/modal.css +0 -757
- package/src/web/public/css/notifications.css +0 -101
- package/src/web/public/css/onboard.css +0 -107
- package/src/web/public/css/serverCategoryList.css +0 -120
- package/src/web/public/css/serverDetails.css +0 -139
- package/src/web/public/index.html +0 -359
- package/src/web/public/js/api.js +0 -132
- package/src/web/public/js/detailsWidget.js +0 -264
- package/src/web/public/js/flights/flights.js +0 -127
- package/src/web/public/js/modal/index.js +0 -52
- package/src/web/public/js/modal/installModal.js +0 -162
- package/src/web/public/js/modal/installation.js +0 -266
- package/src/web/public/js/modal/loadingModal.js +0 -182
- package/src/web/public/js/modal/modalSetup.js +0 -595
- package/src/web/public/js/modal/modalUtils.js +0 -37
- package/src/web/public/js/modal/versionUtils.js +0 -20
- package/src/web/public/js/modal.js +0 -42
- package/src/web/public/js/notifications.js +0 -137
- package/src/web/public/js/onboard/formProcessor.js +0 -1037
- package/src/web/public/js/onboard/index.js +0 -374
- package/src/web/public/js/onboard/publishHandler.js +0 -172
- package/src/web/public/js/onboard/state.js +0 -76
- package/src/web/public/js/onboard/templates.js +0 -342
- package/src/web/public/js/onboard/uiHandlers.js +0 -1076
- package/src/web/public/js/onboard/validationHandlers.js +0 -493
- package/src/web/public/js/serverCategoryDetails.js +0 -364
- package/src/web/public/js/serverCategoryList.js +0 -241
- package/src/web/public/js/settings.js +0 -314
- package/src/web/public/modal.html +0 -84
- package/src/web/public/onboard.html +0 -296
- package/src/web/public/settings.html +0 -135
- package/src/web/public/styles.css +0 -277
- package/src/web/server.ts +0 -478
- package/tsconfig.json +0 -18
- package/wiki/Installation.md +0 -3
- package/wiki/Publish.md +0 -3
|
@@ -1,367 +0,0 @@
|
|
|
1
|
-
import fs from 'fs/promises';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { SETTINGS_DIR } from '../metadatas/constants.js';
|
|
4
|
-
import { InstallOperationDetails, InstallOperationStep } from '../metadatas/types.js';
|
|
5
|
-
import { Logger } from '../../utils/logger.js';
|
|
6
|
-
|
|
7
|
-
const INSTALL_STATUS_DIR = path.join(SETTINGS_DIR, 'InstallOperationStatus');
|
|
8
|
-
|
|
9
|
-
export class InstallOperationManager {
|
|
10
|
-
private installOperationStatus: Record<string, InstallOperationDetails> = {};
|
|
11
|
-
private statusLock: Promise<void> = Promise.resolve();
|
|
12
|
-
private readonly categoryName: string;
|
|
13
|
-
private readonly serverName: string;
|
|
14
|
-
private readonly statusFilePath: string;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Creates an InstallOperationManager instance for a specific category and server.
|
|
18
|
-
* @param categoryName The name of the category.
|
|
19
|
-
* @param serverName The name of the server.
|
|
20
|
-
*/
|
|
21
|
-
constructor(categoryName: string, serverName: string) {
|
|
22
|
-
this.categoryName = categoryName;
|
|
23
|
-
this.serverName = serverName;
|
|
24
|
-
this.statusFilePath = path.join(
|
|
25
|
-
INSTALL_STATUS_DIR,
|
|
26
|
-
this.categoryName,
|
|
27
|
-
`${this.serverName}.json`
|
|
28
|
-
);
|
|
29
|
-
this.loadStatuses().catch(error => Logger.error('Failed to initialize InstallOperationManager:', error));
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Returns an InstallOperationManager instance for the given category and server.
|
|
34
|
-
* @param categoryName The name of the category.
|
|
35
|
-
* @param serverName The name of the server.
|
|
36
|
-
*/
|
|
37
|
-
private static instanceMap: Map<string, InstallOperationManager> = new Map();
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Returns a cached InstallOperationManager instance for the given category and server.
|
|
41
|
-
* If an instance does not exist, it will be created and cached.
|
|
42
|
-
* @param categoryName The name of the category.
|
|
43
|
-
* @param serverName The name of the server.
|
|
44
|
-
*/
|
|
45
|
-
public static getInstance(categoryName: string, serverName: string): InstallOperationManager {
|
|
46
|
-
const key = `${categoryName}::${serverName}`;
|
|
47
|
-
if (!this.instanceMap.has(key)) {
|
|
48
|
-
this.instanceMap.set(key, new InstallOperationManager(categoryName, serverName));
|
|
49
|
-
}
|
|
50
|
-
return this.instanceMap.get(key)!;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
private async withLock<T>(operation: () => Promise<T>): Promise<T> {
|
|
54
|
-
const current = this.statusLock;
|
|
55
|
-
let resolve: () => void;
|
|
56
|
-
this.statusLock = new Promise<void>(r => resolve = r);
|
|
57
|
-
try {
|
|
58
|
-
await current;
|
|
59
|
-
return await operation();
|
|
60
|
-
} finally {
|
|
61
|
-
resolve!();
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
private async loadStatuses(): Promise<void> {
|
|
66
|
-
await this.withLock(async () => {
|
|
67
|
-
try {
|
|
68
|
-
await fs.mkdir(path.dirname(this.statusFilePath), { recursive: true });
|
|
69
|
-
const data = await fs.readFile(this.statusFilePath, 'utf-8');
|
|
70
|
-
this.installOperationStatus = JSON.parse(data);
|
|
71
|
-
} catch (error) {
|
|
72
|
-
if ((error as NodeJS.ErrnoException).code === 'ENOENT') {
|
|
73
|
-
this.installOperationStatus = {};
|
|
74
|
-
await this.saveStatuses(); // Create the file if it doesn't exist
|
|
75
|
-
} else {
|
|
76
|
-
Logger.error('Failed to load install operation statuses:', error);
|
|
77
|
-
this.installOperationStatus = {}; // Initialize with empty statuses in case of other errors
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
private async saveStatuses(): Promise<void> {
|
|
84
|
-
await fs.mkdir(path.dirname(this.statusFilePath), { recursive: true });
|
|
85
|
-
await fs.writeFile(this.statusFilePath, JSON.stringify(this.installOperationStatus, null, 2));
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
private get operationKey(): string {
|
|
89
|
-
return `${this.categoryName}-${this.serverName}`;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Record a step for this category/server instance.
|
|
94
|
-
*/
|
|
95
|
-
public async recordStep(
|
|
96
|
-
stepName: string,
|
|
97
|
-
status: 'pending' | 'in-progress' | 'completed' | 'failed',
|
|
98
|
-
message?: string
|
|
99
|
-
): Promise<InstallOperationDetails> {
|
|
100
|
-
return await this.withLock(async () => {
|
|
101
|
-
let operationDetails = this.installOperationStatus[this.operationKey];
|
|
102
|
-
|
|
103
|
-
const newStep: InstallOperationStep = {
|
|
104
|
-
name: stepName,
|
|
105
|
-
status,
|
|
106
|
-
message,
|
|
107
|
-
timestamp: new Date().toISOString(),
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
if (!operationDetails) {
|
|
111
|
-
operationDetails = {
|
|
112
|
-
currentStep: stepName,
|
|
113
|
-
steps: [newStep],
|
|
114
|
-
lastUpdated: new Date().toISOString(),
|
|
115
|
-
error: status === 'failed' ? message : undefined,
|
|
116
|
-
overallStatus: status === 'failed' ? 'failed' : 'in-progress',
|
|
117
|
-
};
|
|
118
|
-
} else {
|
|
119
|
-
// Check for an existing unfinished step with the same name
|
|
120
|
-
const existingStepIndex = operationDetails.steps.findIndex(
|
|
121
|
-
s => s.name === stepName && s.status !== 'completed' && s.status !== 'failed'
|
|
122
|
-
);
|
|
123
|
-
if (existingStepIndex !== -1) {
|
|
124
|
-
// Update the existing unfinished step
|
|
125
|
-
operationDetails.steps[existingStepIndex] = newStep;
|
|
126
|
-
} else {
|
|
127
|
-
operationDetails.steps.push(newStep);
|
|
128
|
-
}
|
|
129
|
-
operationDetails.currentStep = stepName;
|
|
130
|
-
operationDetails.lastUpdated = new Date().toISOString();
|
|
131
|
-
|
|
132
|
-
if (status === 'failed') {
|
|
133
|
-
operationDetails.overallStatus = 'failed';
|
|
134
|
-
if (!operationDetails.error) { // Store the first error
|
|
135
|
-
operationDetails.error = message;
|
|
136
|
-
}
|
|
137
|
-
// Mark all in-progress steps as cancelled
|
|
138
|
-
operationDetails.steps = operationDetails.steps.map(s =>
|
|
139
|
-
s.status === 'in-progress'
|
|
140
|
-
? {
|
|
141
|
-
...s,
|
|
142
|
-
status: 'canceled',
|
|
143
|
-
message: (s.message ? s.message + ' ' : '') + '[Canceled due to failure]',
|
|
144
|
-
timestamp: new Date().toISOString(),
|
|
145
|
-
}
|
|
146
|
-
: s
|
|
147
|
-
);
|
|
148
|
-
} else if (status === 'completed' && stepName.toLowerCase().includes('completed')) {
|
|
149
|
-
// Check if all steps are completed or if there are any failures
|
|
150
|
-
const allStepsCompleted = operationDetails.steps.every(s =>
|
|
151
|
-
s.status === 'completed' || (s.name === stepName && status === 'completed')
|
|
152
|
-
);
|
|
153
|
-
operationDetails.overallStatus = allStepsCompleted ? 'completed' : 'in-progress';
|
|
154
|
-
if (allStepsCompleted) {
|
|
155
|
-
operationDetails.error = undefined; // Clear error on completion
|
|
156
|
-
}
|
|
157
|
-
} else {
|
|
158
|
-
if (operationDetails.overallStatus !== 'failed') {
|
|
159
|
-
operationDetails.overallStatus = 'in-progress';
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// Special handling for the "InstallCompleted" step or similar final step names
|
|
165
|
-
if (stepName === 'InstallCompleted') {
|
|
166
|
-
operationDetails.overallStatus = status === 'completed' ? 'completed' : 'failed';
|
|
167
|
-
if (status === 'completed') operationDetails.error = undefined;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
this.installOperationStatus[this.operationKey] = operationDetails;
|
|
171
|
-
await this.saveStatuses();
|
|
172
|
-
return operationDetails;
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* Resets (deletes) the operation status for this category/server.
|
|
178
|
-
* This is useful to call before starting a new installation attempt.
|
|
179
|
-
*/
|
|
180
|
-
public async resetOperation(): Promise<InstallOperationManager> {
|
|
181
|
-
await this.withLock(async () => {
|
|
182
|
-
if (this.installOperationStatus[this.operationKey]) {
|
|
183
|
-
delete this.installOperationStatus[this.operationKey];
|
|
184
|
-
Logger.info(`Reset installation operation status for ${this.operationKey}`);
|
|
185
|
-
await this.saveStatuses();
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
return this;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* Gets the details for this category/server.
|
|
193
|
-
*/
|
|
194
|
-
public async getDetails(): Promise<InstallOperationDetails | undefined> {
|
|
195
|
-
await this.loadStatuses(); // Ensure latest statuses are loaded
|
|
196
|
-
return this.installOperationStatus[this.operationKey];
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Gets all operation details in this file (for this category/server).
|
|
201
|
-
*/
|
|
202
|
-
public async getAllDetails(): Promise<Record<string, InstallOperationDetails>> {
|
|
203
|
-
await this.loadStatuses();
|
|
204
|
-
return this.installOperationStatus;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* Explicitly mark the overall status of an operation as 'completed' or 'failed'.
|
|
209
|
-
* This can be used to force the final state regardless of step details.
|
|
210
|
-
* @param status 'completed' or 'failed'
|
|
211
|
-
* @param error Optional error message if failed
|
|
212
|
-
*/
|
|
213
|
-
public async markOverallStatus(status: 'completed' | 'failed', error?: string): Promise<InstallOperationDetails | undefined> {
|
|
214
|
-
return await this.withLock(async () => {
|
|
215
|
-
const operationDetails = this.installOperationStatus[this.operationKey];
|
|
216
|
-
if (!operationDetails) return undefined;
|
|
217
|
-
operationDetails.overallStatus = status;
|
|
218
|
-
operationDetails.lastUpdated = new Date().toISOString();
|
|
219
|
-
if (status === 'failed') {
|
|
220
|
-
if (error) {
|
|
221
|
-
operationDetails.error = error;
|
|
222
|
-
}
|
|
223
|
-
// Mark all in-progress steps as cancelled
|
|
224
|
-
operationDetails.steps = operationDetails.steps.map(s =>
|
|
225
|
-
s.status === 'in-progress'
|
|
226
|
-
? {
|
|
227
|
-
...s,
|
|
228
|
-
status: 'canceled',
|
|
229
|
-
message: (s.message ? s.message + ' ' : '') + '[Canceled due to failure]',
|
|
230
|
-
timestamp: new Date().toISOString(),
|
|
231
|
-
}
|
|
232
|
-
: s
|
|
233
|
-
);
|
|
234
|
-
}
|
|
235
|
-
if (status === 'completed') {
|
|
236
|
-
operationDetails.error = undefined;
|
|
237
|
-
}
|
|
238
|
-
await this.saveStatuses();
|
|
239
|
-
return operationDetails;
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
/**
|
|
244
|
-
* Executes a function and records its step status as 'in-progress', 'completed', or 'failed'.
|
|
245
|
-
*
|
|
246
|
-
* Useful for wrapping tasks with consistent status tracking and flexible error handling.
|
|
247
|
-
*
|
|
248
|
-
* @template T The return type of the function being executed.
|
|
249
|
-
*
|
|
250
|
-
* @param fn The function to execute. Can be synchronous or asynchronous.
|
|
251
|
-
* @param options Optional configuration:
|
|
252
|
-
* - stepName: Custom name for the step. Defaults to the function name or 'unnamedStep'.
|
|
253
|
-
* - inProgressMessage: Optional message to log when the step starts.
|
|
254
|
-
* - endMessage: Optional static string or function to generate a final message from the result or error.
|
|
255
|
-
* - onResult: A function `(result: T) => boolean` that determines whether the step was successful. Defaults to always `true`.
|
|
256
|
-
* - onError: Optional function `(error) => { result: T; message: string } | never` that handles an error and may return a fallback result and message, or throw.
|
|
257
|
-
*
|
|
258
|
-
* @returns A promise that resolves with the result of the function if successful, or rethrows on failure.
|
|
259
|
-
*
|
|
260
|
-
* @throws The original error or any error thrown from `onError`.
|
|
261
|
-
*/
|
|
262
|
-
public async recording<T>(
|
|
263
|
-
fn: () => T | Promise<T>,
|
|
264
|
-
options?: {
|
|
265
|
-
stepName?: string;
|
|
266
|
-
inProgressMessage?: string;
|
|
267
|
-
endMessage?: string | ((data: T) => string | undefined);
|
|
268
|
-
onResult?: (result: T) => boolean;
|
|
269
|
-
onError?: (error: unknown) => { result: T; message: string } | Promise<{ result: T; message: string }> | never;
|
|
270
|
-
}
|
|
271
|
-
): Promise<T> {
|
|
272
|
-
const { stepName, inProgressMessage = 'Step in progress', endMessage, onResult = () => true, onError } = options || {};
|
|
273
|
-
|
|
274
|
-
const resolvedStepName = stepName ?? (fn.name || 'unnamedStep');
|
|
275
|
-
const getEndMessage = (data: T, fallback: string) =>
|
|
276
|
-
typeof endMessage === 'function' ? endMessage(data) || 'Step completed' : endMessage ?? fallback;
|
|
277
|
-
|
|
278
|
-
await this.recordStep(resolvedStepName, 'in-progress', inProgressMessage);
|
|
279
|
-
|
|
280
|
-
try {
|
|
281
|
-
const result = await Promise.resolve(fn());
|
|
282
|
-
const isSuccess = onResult(result);
|
|
283
|
-
await this.recordStep(resolvedStepName, isSuccess ? 'completed' : 'failed', getEndMessage(result, isSuccess ? 'Step completed successfully' : 'Step failed'));
|
|
284
|
-
return result;
|
|
285
|
-
} catch (err) {
|
|
286
|
-
if (!onError) {
|
|
287
|
-
await this.recordStep(resolvedStepName, 'failed', (err as Error)?.message || String(err));
|
|
288
|
-
throw err;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
try {
|
|
292
|
-
const { result, message } = await onError(err);
|
|
293
|
-
await this.recordStep(resolvedStepName, 'failed', message);
|
|
294
|
-
return result;
|
|
295
|
-
} catch (onErrorThrown) {
|
|
296
|
-
await this.recordStep(resolvedStepName, 'failed', (onErrorThrown as Error)?.message || String(onErrorThrown));
|
|
297
|
-
throw onErrorThrown;
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
/**
|
|
304
|
-
* Executes an asynchronous "fire-and-forget" task and records its step status as 'in-progress', 'completed', or 'failed'.
|
|
305
|
-
*
|
|
306
|
-
* Unlike `recording`, this does not await the result — it runs the task in the background.
|
|
307
|
-
* Useful for side-effecting operations like updates or notifications where progress should be logged but not block flow.
|
|
308
|
-
*
|
|
309
|
-
* @template T The resolved type of the asynchronous task.
|
|
310
|
-
*
|
|
311
|
-
* @param fn The async function to execute.
|
|
312
|
-
* @param options Optional configuration:
|
|
313
|
-
* - stepName: Custom name for the step. Defaults to the function name or 'unnamedStep'.
|
|
314
|
-
* - inProgressMessage: Message to log when the step starts.
|
|
315
|
-
* - endMessage: Static string or function to generate the final message from result or error.
|
|
316
|
-
* - onResult: A boolean or function `(result: T) => boolean` to determine if the step is successful.
|
|
317
|
-
* - onError: A function `(error) => string` or `Promise<string>` to handle errors and return a message.
|
|
318
|
-
* If it throws, the error is rethrown and logged.
|
|
319
|
-
* - onComplete: Optional callback to run after completion, regardless of success or failure.
|
|
320
|
-
*
|
|
321
|
-
* @returns void
|
|
322
|
-
*/
|
|
323
|
-
public recordingAsync<T>(fn: () => Promise<T>, options?: {
|
|
324
|
-
stepName?: string;
|
|
325
|
-
inProgressMessage?: string;
|
|
326
|
-
endMessage?: string | ((result: T) => string);
|
|
327
|
-
onResult?: (result: T) => boolean;
|
|
328
|
-
onError?: (error: unknown) => string | Promise<string> | never;
|
|
329
|
-
onComplete?: () => void;
|
|
330
|
-
}
|
|
331
|
-
): void {
|
|
332
|
-
const {
|
|
333
|
-
stepName,
|
|
334
|
-
inProgressMessage = 'Step in progress',
|
|
335
|
-
endMessage,
|
|
336
|
-
onResult = () => true,
|
|
337
|
-
onError,
|
|
338
|
-
onComplete,
|
|
339
|
-
} = options || {};
|
|
340
|
-
|
|
341
|
-
const resolvedStepName = stepName ?? (fn.name || 'unnamedStep');
|
|
342
|
-
const getMessage = (data: T, fallback: string) => typeof endMessage === 'function' ? endMessage(data) : endMessage ?? fallback;
|
|
343
|
-
|
|
344
|
-
this.recordStep(resolvedStepName, 'in-progress', inProgressMessage).then(() => {
|
|
345
|
-
fn()
|
|
346
|
-
.then(result => {
|
|
347
|
-
const isSuccess = onResult(result);
|
|
348
|
-
const message = getMessage(result, isSuccess ? 'Step completed successfully' : 'Step failed');
|
|
349
|
-
this.recordStep(resolvedStepName, isSuccess ? 'completed' : 'failed', message).then(onComplete).catch();
|
|
350
|
-
})
|
|
351
|
-
.catch(async (err) => {
|
|
352
|
-
if (onError) {
|
|
353
|
-
try {
|
|
354
|
-
const errorMessage = await onError(err);
|
|
355
|
-
await this.recordStep(resolvedStepName, 'failed', errorMessage);
|
|
356
|
-
} catch (onErrorThrown) {
|
|
357
|
-
await this.recordStep(resolvedStepName, 'failed', (onErrorThrown as Error)?.message || String(onErrorThrown));
|
|
358
|
-
throw onErrorThrown;
|
|
359
|
-
}
|
|
360
|
-
} else {
|
|
361
|
-
const fallback = getMessage(err, (err as Error)?.message || String(err));
|
|
362
|
-
await this.recordStep(resolvedStepName, 'failed', fallback);
|
|
363
|
-
}
|
|
364
|
-
});
|
|
365
|
-
});
|
|
366
|
-
}
|
|
367
|
-
}
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import fs from 'fs/promises';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { LOCAL_FEEDS_SCHEMA_DIR } from '../metadatas/constants.js';
|
|
4
|
-
import { Logger } from '../../utils/logger.js';
|
|
5
|
-
import { ServerSchema } from './ServerSchemaProvider.js';
|
|
6
|
-
|
|
7
|
-
export class ServerSchemaLoader {
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Loads a single schema file.
|
|
11
|
-
* @param filePath The absolute path to the schema file.
|
|
12
|
-
* @returns A Promise that resolves to the ServerSchema or undefined if not found or error.
|
|
13
|
-
*/
|
|
14
|
-
public static async loadSchema(filePath: string): Promise<ServerSchema | undefined> {
|
|
15
|
-
try {
|
|
16
|
-
const content = await fs.readFile(filePath, 'utf8');
|
|
17
|
-
const schema = JSON.parse(content);
|
|
18
|
-
|
|
19
|
-
return {
|
|
20
|
-
schema: schema
|
|
21
|
-
};
|
|
22
|
-
} catch (error) {
|
|
23
|
-
if ((error as NodeJS.ErrnoException).code === 'ENOENT') {
|
|
24
|
-
Logger.debug(`No schema file found at ${filePath}`);
|
|
25
|
-
return undefined;
|
|
26
|
-
}
|
|
27
|
-
Logger.error(`Error loading schema from ${filePath}:`, error);
|
|
28
|
-
// Optionally rethrow or return undefined based on desired error handling
|
|
29
|
-
return undefined;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Loads all schemas from the default feeds directory.
|
|
35
|
-
* @param defaultFeedsDir The path to the default feeds directory.
|
|
36
|
-
* @param schemaMap The map to populate with loaded schemas.
|
|
37
|
-
*/
|
|
38
|
-
public static async loadAllDefaultSchemas(defaultFeedsDir: string, schemaMap: Map<string, Map<string, ServerSchema>>): Promise<void> {
|
|
39
|
-
schemaMap.clear(); // Clear map for initial load from default directory
|
|
40
|
-
|
|
41
|
-
try {
|
|
42
|
-
const categoryDirs = await fs.readdir(defaultFeedsDir, { withFileTypes: true });
|
|
43
|
-
|
|
44
|
-
for (const categoryDir of categoryDirs) {
|
|
45
|
-
if (categoryDir.isDirectory()) {
|
|
46
|
-
const categoryName = categoryDir.name;
|
|
47
|
-
const categoryPath = path.join(defaultFeedsDir, categoryName);
|
|
48
|
-
const serverFiles = await fs.readdir(categoryPath);
|
|
49
|
-
const serverSchemas = new Map<string, ServerSchema>();
|
|
50
|
-
|
|
51
|
-
for (const file of serverFiles) {
|
|
52
|
-
if (file.endsWith('.json')) {
|
|
53
|
-
try {
|
|
54
|
-
const schemaFilePath = path.join(categoryPath, file);
|
|
55
|
-
const schema = await this.loadSchema(schemaFilePath);
|
|
56
|
-
if (schema) {
|
|
57
|
-
serverSchemas.set(file, schema); // file is serverName
|
|
58
|
-
Logger.debug(`Loaded schema '${file}' for category '${categoryName}' from default directory`);
|
|
59
|
-
}
|
|
60
|
-
} catch (error) { // Error already logged in loadSchema
|
|
61
|
-
Logger.error(`Skipping schema file ${file} in category ${categoryName} due to loading error.`);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
if (serverSchemas.size > 0) {
|
|
66
|
-
schemaMap.set(categoryName, serverSchemas);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
} catch (error) {
|
|
71
|
-
Logger.error(`Error reading schemas from default directory ${defaultFeedsDir}:`, error);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Loads schemas from an adhoc directory for a specific category.
|
|
77
|
-
* @param adhocSchemasDir The path to the adhoc schemas directory.
|
|
78
|
-
* @param categoryName The name of the category for these adhoc schemas.
|
|
79
|
-
* @param schemaMap The map to update with loaded adhoc schemas.
|
|
80
|
-
*/
|
|
81
|
-
public static async loadAdhocSchemas(adhocSchemasDir: string, categoryName: string, schemaMap: Map<string, Map<string, ServerSchema>>): Promise<void> {
|
|
82
|
-
try {
|
|
83
|
-
const serverFiles = await fs.readdir(adhocSchemasDir);
|
|
84
|
-
|
|
85
|
-
if (schemaMap.has(categoryName)) {
|
|
86
|
-
Logger.warn(`\x1b[33mAdhoc schema category '${categoryName}' (from dir: ${adhocSchemasDir}) conflicts with an existing category. Adhoc schemas in this category will override existing ones.\x1b[0m`);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
let serverSchemas = schemaMap.get(categoryName);
|
|
90
|
-
if (!serverSchemas) {
|
|
91
|
-
serverSchemas = new Map<string, ServerSchema>();
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
for (const file of serverFiles) {
|
|
95
|
-
if (file.endsWith('.json')) {
|
|
96
|
-
try {
|
|
97
|
-
const schemaFilePath = path.join(adhocSchemasDir, file);
|
|
98
|
-
const schema = await this.loadSchema(schemaFilePath);
|
|
99
|
-
if (schema) {
|
|
100
|
-
serverSchemas.set(file, schema); // file is serverName
|
|
101
|
-
Logger.debug(`Loaded adhoc schema '${file}' for category '${categoryName}'`);
|
|
102
|
-
}
|
|
103
|
-
} catch (error) { // Error already logged in loadSchema
|
|
104
|
-
Logger.error(`Skipping adhoc schema file ${file} in category ${categoryName} due to loading error.`);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
if (serverSchemas.size > 0) {
|
|
110
|
-
schemaMap.set(categoryName, serverSchemas);
|
|
111
|
-
}
|
|
112
|
-
} catch (error) {
|
|
113
|
-
// This case should ideally be caught by the fs.access check in ServerSchemaProvider.initialize
|
|
114
|
-
Logger.error(`Error reading adhoc schemas from directory ${adhocSchemasDir} for category ${categoryName}:`, error);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import fs from 'fs/promises';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { LOCAL_FEEDS_SCHEMA_DIR } from '../metadatas/constants.js';
|
|
4
|
-
import { Logger } from '../../utils/logger.js';
|
|
5
|
-
import { ServerSchemaLoader } from './ServerSchemaLoader.js';
|
|
6
|
-
|
|
7
|
-
export interface ServerSchema {
|
|
8
|
-
schema: Record<string, any>;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export class ServerSchemaProvider {
|
|
12
|
-
private static instance: ServerSchemaProvider;
|
|
13
|
-
private schemaMap: Map<string, Map<string, ServerSchema>>;
|
|
14
|
-
private schemaLock: Promise<void> = Promise.resolve();
|
|
15
|
-
|
|
16
|
-
private constructor() {
|
|
17
|
-
this.schemaMap = new Map();
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
public static getInstance(): ServerSchemaProvider {
|
|
21
|
-
if (!ServerSchemaProvider.instance) {
|
|
22
|
-
ServerSchemaProvider.instance = new ServerSchemaProvider();
|
|
23
|
-
// Initialize is now called with optional adhocSchemasDir,
|
|
24
|
-
// but getInstance is often called without it initially.
|
|
25
|
-
// The actual loading with adhoc dir will happen when MCPManager calls initialize.
|
|
26
|
-
}
|
|
27
|
-
return ServerSchemaProvider.instance;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
private async withLock<T>(operation: () => Promise<T>): Promise<T> {
|
|
31
|
-
const current = this.schemaLock;
|
|
32
|
-
let resolve: () => void;
|
|
33
|
-
this.schemaLock = new Promise<void>(r => resolve = r);
|
|
34
|
-
try {
|
|
35
|
-
await current;
|
|
36
|
-
return await operation();
|
|
37
|
-
} finally {
|
|
38
|
-
resolve!();
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
async initialize(adhocSchemasDir?: string): Promise<void> {
|
|
43
|
-
await this.withLock(async () => {
|
|
44
|
-
try {
|
|
45
|
-
// Create default feeds directory if it doesn't exist
|
|
46
|
-
await fs.mkdir(LOCAL_FEEDS_SCHEMA_DIR, { recursive: true });
|
|
47
|
-
|
|
48
|
-
// Load all schemas from the default feeds directory
|
|
49
|
-
await ServerSchemaLoader.loadAllDefaultSchemas(LOCAL_FEEDS_SCHEMA_DIR, this.schemaMap);
|
|
50
|
-
|
|
51
|
-
// Load schemas from adhoc directory if provided
|
|
52
|
-
if (adhocSchemasDir) {
|
|
53
|
-
try {
|
|
54
|
-
await fs.access(adhocSchemasDir); // Check if directory exists
|
|
55
|
-
const adhocCategoryName = path.basename(adhocSchemasDir);
|
|
56
|
-
Logger.info(`Loading adhoc schemas from: ${adhocSchemasDir} for category: ${adhocCategoryName}`);
|
|
57
|
-
await ServerSchemaLoader.loadAdhocSchemas(adhocSchemasDir, adhocCategoryName, this.schemaMap);
|
|
58
|
-
} catch (error) {
|
|
59
|
-
if ((error as NodeJS.ErrnoException).code === 'ENOENT') {
|
|
60
|
-
Logger.warn(`Adhoc schemas directory not found: ${adhocSchemasDir}`);
|
|
61
|
-
} else {
|
|
62
|
-
Logger.error(`Error accessing adhoc schemas directory ${adhocSchemasDir}:`, error);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
} catch (error) {
|
|
67
|
-
Logger.error('Error during schema initialization:', error);
|
|
68
|
-
throw error;
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// The actual loading methods (loadSchema, loadAllSchemas, loadAdhocSchemas) have been moved to ServerSchemaLoader.
|
|
74
|
-
// ServerSchemaProvider now delegates to ServerSchemaLoader for these operations.
|
|
75
|
-
|
|
76
|
-
async getSchema(categoryName: string, schemaFileName: string): Promise<ServerSchema | undefined> {
|
|
77
|
-
return await this.withLock(async () => {
|
|
78
|
-
const categorySchemas = this.schemaMap.get(categoryName);
|
|
79
|
-
if (!categorySchemas) {
|
|
80
|
-
Logger.debug(`No schemas found for category ${categoryName}`);
|
|
81
|
-
return undefined;
|
|
82
|
-
}
|
|
83
|
-
const schema = categorySchemas.get(schemaFileName);
|
|
84
|
-
if (!schema) {
|
|
85
|
-
Logger.debug(`Schema ${schemaFileName} not found in category ${categoryName}`);
|
|
86
|
-
}
|
|
87
|
-
return schema;
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
async reloadSchemas(): Promise<void> {
|
|
92
|
-
return await this.withLock(async () => {
|
|
93
|
-
// Reloading should re-evaluate both default and any configured adhoc directory
|
|
94
|
-
// For simplicity, we assume initialize would be called again if adhoc path changes.
|
|
95
|
-
// This reload will just reload from the paths known during the last full initialize.
|
|
96
|
-
await this.initialize(); // This will re-load default and adhoc if adhocSchemasDir was set
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
}
|