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.
Files changed (314) hide show
  1. package/dist/cli/commands/install.js +1 -106
  2. package/dist/cli/commands/install.js.map +1 -0
  3. package/dist/cli/commands/list.js +1 -90
  4. package/dist/cli/commands/list.js.map +1 -0
  5. package/dist/cli/commands/pull.js +1 -16
  6. package/dist/cli/commands/pull.js.map +1 -0
  7. package/dist/cli/commands/serve.js +1 -33
  8. package/dist/cli/commands/serve.js.map +1 -0
  9. package/dist/cli/commands/uninstall.js +1 -46
  10. package/dist/cli/commands/uninstall.js.map +1 -0
  11. package/dist/cli/index.js +1 -65
  12. package/dist/cli/index.js.map +1 -0
  13. package/dist/core/installers/clients/BaseClientInstaller.js +1 -282
  14. package/dist/core/installers/clients/BaseClientInstaller.js.map +1 -0
  15. package/dist/core/installers/clients/ClientInstaller.js +1 -163
  16. package/dist/core/installers/clients/ClientInstaller.js.map +1 -0
  17. package/dist/core/installers/clients/ClientInstallerFactory.js +1 -36
  18. package/dist/core/installers/clients/ClientInstallerFactory.js.map +1 -0
  19. package/dist/core/installers/clients/ClineInstaller.js +1 -30
  20. package/dist/core/installers/clients/ClineInstaller.js.map +1 -0
  21. package/dist/core/installers/clients/ExtensionInstaller.js +1 -151
  22. package/dist/core/installers/clients/ExtensionInstaller.js.map +1 -0
  23. package/dist/core/installers/clients/GithubCopilotInstaller.js +1 -68
  24. package/dist/core/installers/clients/GithubCopilotInstaller.js.map +1 -0
  25. package/dist/core/installers/clients/MSRooCodeInstaller.js +1 -28
  26. package/dist/core/installers/clients/MSRooCodeInstaller.js.map +1 -0
  27. package/dist/core/installers/index.js +1 -8
  28. package/dist/core/installers/index.js.map +1 -0
  29. package/dist/core/installers/requirements/BaseInstaller.js +1 -56
  30. package/dist/core/installers/requirements/BaseInstaller.js.map +1 -0
  31. package/dist/core/installers/requirements/CommandInstaller.js +1 -213
  32. package/dist/core/installers/requirements/CommandInstaller.js.map +1 -0
  33. package/dist/core/installers/requirements/GeneralInstaller.js +1 -126
  34. package/dist/core/installers/requirements/GeneralInstaller.js.map +1 -0
  35. package/dist/core/installers/requirements/InstallerFactory.js +1 -99
  36. package/dist/core/installers/requirements/InstallerFactory.js.map +1 -0
  37. package/dist/core/installers/requirements/NpmInstaller.js +1 -235
  38. package/dist/core/installers/requirements/NpmInstaller.js.map +1 -0
  39. package/dist/core/installers/requirements/NugetInstaller.js +1 -188
  40. package/dist/core/installers/requirements/NugetInstaller.js.map +1 -0
  41. package/dist/core/installers/requirements/PipInstaller.js +1 -192
  42. package/dist/core/installers/requirements/PipInstaller.js.map +1 -0
  43. package/dist/core/installers/requirements/RequirementInstaller.js +1 -2
  44. package/dist/core/installers/requirements/RequirementInstaller.js.map +1 -0
  45. package/dist/core/loaders/ConfigurationLoader.js +1 -256
  46. package/dist/core/loaders/ConfigurationLoader.js.map +1 -0
  47. package/dist/core/loaders/ConfigurationProvider.js +1 -383
  48. package/dist/core/loaders/ConfigurationProvider.js.map +1 -0
  49. package/dist/core/loaders/InstallOperationManager.js +1 -310
  50. package/dist/core/loaders/InstallOperationManager.js.map +1 -0
  51. package/dist/core/loaders/ServerSchemaLoader.js +1 -108
  52. package/dist/core/loaders/ServerSchemaLoader.js.map +1 -0
  53. package/dist/core/loaders/ServerSchemaProvider.js +1 -89
  54. package/dist/core/loaders/ServerSchemaProvider.js.map +1 -0
  55. package/dist/core/loaders/SystemSettingsManager.js +1 -256
  56. package/dist/core/loaders/SystemSettingsManager.js.map +1 -0
  57. package/dist/core/metadatas/constants.js +1 -100
  58. package/dist/core/metadatas/constants.js.map +1 -0
  59. package/dist/core/metadatas/recordingConstants.js +1 -46
  60. package/dist/core/metadatas/recordingConstants.js.map +1 -0
  61. package/dist/core/metadatas/types.js +1 -15
  62. package/dist/core/metadatas/types.js.map +1 -0
  63. package/dist/core/onboard/FeedOnboardService.js +1 -422
  64. package/dist/core/onboard/FeedOnboardService.js.map +1 -0
  65. package/dist/core/onboard/OnboardProcessor.js +1 -333
  66. package/dist/core/onboard/OnboardProcessor.js.map +1 -0
  67. package/dist/core/onboard/OnboardStatus.js +1 -9
  68. package/dist/core/onboard/OnboardStatus.js.map +1 -0
  69. package/dist/core/onboard/OnboardStatusManager.js +1 -360
  70. package/dist/core/onboard/OnboardStatusManager.js.map +1 -0
  71. package/dist/core/validators/FeedValidator.js +1 -133
  72. package/dist/core/validators/FeedValidator.js.map +1 -0
  73. package/dist/core/validators/IServerValidator.js +1 -1
  74. package/dist/core/validators/IServerValidator.js.map +1 -0
  75. package/dist/core/validators/SSEServerValidator.js +1 -38
  76. package/dist/core/validators/SSEServerValidator.js.map +1 -0
  77. package/dist/core/validators/ServerValidatorFactory.js +1 -44
  78. package/dist/core/validators/ServerValidatorFactory.js.map +1 -0
  79. package/dist/core/validators/StdioServerValidator.js +1 -281
  80. package/dist/core/validators/StdioServerValidator.js.map +1 -0
  81. package/dist/index.js +1 -18
  82. package/dist/index.js.map +1 -0
  83. package/dist/services/InstallationService.js +1 -81
  84. package/dist/services/InstallationService.js.map +1 -0
  85. package/dist/services/MCPManager.js +1 -197
  86. package/dist/services/MCPManager.js.map +1 -0
  87. package/dist/services/RequirementService.js +1 -548
  88. package/dist/services/RequirementService.js.map +1 -0
  89. package/dist/services/ServerService.js +1 -127
  90. package/dist/services/ServerService.js.map +1 -0
  91. package/dist/services/TelemetryService.js +1 -53
  92. package/dist/services/TelemetryService.js.map +1 -0
  93. package/dist/utils/UpdateCheckTracker.js +1 -79
  94. package/dist/utils/UpdateCheckTracker.js.map +1 -0
  95. package/dist/utils/adoUtils.js +1 -254
  96. package/dist/utils/adoUtils.js.map +1 -0
  97. package/dist/utils/clientUtils.js +1 -65
  98. package/dist/utils/clientUtils.js.map +1 -0
  99. package/dist/utils/feedUtils.js +1 -28
  100. package/dist/utils/feedUtils.js.map +1 -0
  101. package/dist/utils/githubAuth.js +1 -177
  102. package/dist/utils/githubAuth.js.map +1 -0
  103. package/dist/utils/githubUtils.js +1 -125
  104. package/dist/utils/githubUtils.js.map +1 -0
  105. package/dist/utils/logger.js +1 -176
  106. package/dist/utils/logger.js.map +1 -0
  107. package/dist/utils/macroExpressionUtils.js +1 -93
  108. package/dist/utils/macroExpressionUtils.js.map +1 -0
  109. package/dist/utils/osUtils.js +1 -664
  110. package/dist/utils/osUtils.js.map +1 -0
  111. package/dist/utils/versionUtils.js +1 -101
  112. package/dist/utils/versionUtils.js.map +1 -0
  113. package/dist/web/contract/serverContract.js +1 -1
  114. package/dist/web/contract/serverContract.js.map +1 -0
  115. package/dist/web/public/js/api.js +2 -132
  116. package/dist/web/public/js/api.js.map +1 -0
  117. package/dist/web/public/js/detailsWidget.js +2 -264
  118. package/dist/web/public/js/detailsWidget.js.map +1 -0
  119. package/dist/web/public/js/flights/flights.js +2 -127
  120. package/dist/web/public/js/flights/flights.js.map +1 -0
  121. package/dist/web/public/js/modal/index.js +2 -52
  122. package/dist/web/public/js/modal/index.js.map +1 -0
  123. package/dist/web/public/js/modal/installModal.js +2 -162
  124. package/dist/web/public/js/modal/installModal.js.map +1 -0
  125. package/dist/web/public/js/modal/installation.js +2 -266
  126. package/dist/web/public/js/modal/installation.js.map +1 -0
  127. package/dist/web/public/js/modal/loadingModal.js +2 -182
  128. package/dist/web/public/js/modal/loadingModal.js.map +1 -0
  129. package/dist/web/public/js/modal/modalSetup.js +2 -595
  130. package/dist/web/public/js/modal/modalSetup.js.map +1 -0
  131. package/dist/web/public/js/modal/modalUtils.js +2 -37
  132. package/dist/web/public/js/modal/modalUtils.js.map +1 -0
  133. package/dist/web/public/js/modal/versionUtils.js +2 -20
  134. package/dist/web/public/js/modal/versionUtils.js.map +1 -0
  135. package/dist/web/public/js/modal.js +2 -42
  136. package/dist/web/public/js/modal.js.map +1 -0
  137. package/dist/web/public/js/notifications.js +2 -137
  138. package/dist/web/public/js/notifications.js.map +1 -0
  139. package/dist/web/public/js/onboard/formProcessor.js +2 -1037
  140. package/dist/web/public/js/onboard/formProcessor.js.map +1 -0
  141. package/dist/web/public/js/onboard/index.js +2 -374
  142. package/dist/web/public/js/onboard/index.js.map +1 -0
  143. package/dist/web/public/js/onboard/publishHandler.js +2 -172
  144. package/dist/web/public/js/onboard/publishHandler.js.map +1 -0
  145. package/dist/web/public/js/onboard/state.js +2 -76
  146. package/dist/web/public/js/onboard/state.js.map +1 -0
  147. package/dist/web/public/js/onboard/templates.js +2 -342
  148. package/dist/web/public/js/onboard/templates.js.map +1 -0
  149. package/dist/web/public/js/onboard/uiHandlers.js +2 -1076
  150. package/dist/web/public/js/onboard/uiHandlers.js.map +1 -0
  151. package/dist/web/public/js/onboard/validationHandlers.js +2 -493
  152. package/dist/web/public/js/onboard/validationHandlers.js.map +1 -0
  153. package/dist/web/public/js/serverCategoryDetails.js +2 -364
  154. package/dist/web/public/js/serverCategoryDetails.js.map +1 -0
  155. package/dist/web/public/js/serverCategoryList.js +2 -241
  156. package/dist/web/public/js/serverCategoryList.js.map +1 -0
  157. package/dist/web/public/js/settings.js +2 -314
  158. package/dist/web/public/js/settings.js.map +1 -0
  159. package/dist/web/server.js +1 -404
  160. package/dist/web/server.js.map +1 -0
  161. package/package.json +8 -2
  162. package/.github/ISSUE_TEMPLATE/JitAccess.yml +0 -28
  163. package/.github/acl/access.yml +0 -20
  164. package/.github/compliance/inventory.yml +0 -5
  165. package/.github/policies/jit.yml +0 -19
  166. package/.github/workflows/build.yml +0 -28
  167. package/.roo/rules-code/rules.md +0 -88
  168. package/dist/cli/commands/start.d.ts +0 -2
  169. package/dist/cli/commands/start.js +0 -32
  170. package/dist/cli/commands/sync.d.ts +0 -2
  171. package/dist/cli/commands/sync.js +0 -17
  172. package/dist/core/ConfigurationLoader.d.ts +0 -32
  173. package/dist/core/ConfigurationLoader.js +0 -236
  174. package/dist/core/ConfigurationProvider.d.ts +0 -35
  175. package/dist/core/ConfigurationProvider.js +0 -375
  176. package/dist/core/InstallationService.d.ts +0 -50
  177. package/dist/core/InstallationService.js +0 -350
  178. package/dist/core/MCPManager.d.ts +0 -28
  179. package/dist/core/MCPManager.js +0 -188
  180. package/dist/core/RequirementService.d.ts +0 -40
  181. package/dist/core/RequirementService.js +0 -110
  182. package/dist/core/ServerSchemaLoader.d.ts +0 -11
  183. package/dist/core/ServerSchemaLoader.js +0 -43
  184. package/dist/core/ServerSchemaProvider.d.ts +0 -17
  185. package/dist/core/ServerSchemaProvider.js +0 -120
  186. package/dist/core/constants.d.ts +0 -47
  187. package/dist/core/constants.js +0 -94
  188. package/dist/core/installers/BaseInstaller.d.ts +0 -74
  189. package/dist/core/installers/BaseInstaller.js +0 -253
  190. package/dist/core/installers/ClientInstaller.d.ts +0 -23
  191. package/dist/core/installers/ClientInstaller.js +0 -564
  192. package/dist/core/installers/CommandInstaller.d.ts +0 -37
  193. package/dist/core/installers/CommandInstaller.js +0 -173
  194. package/dist/core/installers/GeneralInstaller.d.ts +0 -33
  195. package/dist/core/installers/GeneralInstaller.js +0 -85
  196. package/dist/core/installers/InstallerFactory.d.ts +0 -54
  197. package/dist/core/installers/InstallerFactory.js +0 -97
  198. package/dist/core/installers/NpmInstaller.d.ts +0 -26
  199. package/dist/core/installers/NpmInstaller.js +0 -127
  200. package/dist/core/installers/PipInstaller.d.ts +0 -28
  201. package/dist/core/installers/PipInstaller.js +0 -127
  202. package/dist/core/installers/RequirementInstaller.d.ts +0 -33
  203. package/dist/core/installers/RequirementInstaller.js +0 -3
  204. package/dist/core/types.d.ts +0 -166
  205. package/dist/core/types.js +0 -16
  206. package/dist/services/InstallRequestValidator.d.ts +0 -21
  207. package/dist/services/InstallRequestValidator.js +0 -99
  208. package/dist/web/public/js/modal/installHandler.js +0 -227
  209. package/dist/web/public/js/modal/loadingUI.js +0 -74
  210. package/dist/web/public/js/modal/messageQueue.js +0 -112
  211. package/dist/web/public/js/modal/modalUI.js +0 -214
  212. package/dist/web/public/js/modal/version.js +0 -20
  213. package/dist/web/public/js/onboard/ONBOARDING_PAGE_DESIGN.md +0 -370
  214. package/docs/ONBOARDING_PAGE_DESIGN.md +0 -260
  215. package/docs/Telemetry.md +0 -136
  216. package/memory-bank/activeContext.md +0 -26
  217. package/memory-bank/decisionLog.md +0 -91
  218. package/memory-bank/productContext.md +0 -41
  219. package/memory-bank/progress.md +0 -35
  220. package/memory-bank/systemPatterns.md +0 -10
  221. package/src/cli/commands/install.ts +0 -139
  222. package/src/cli/commands/list.ts +0 -113
  223. package/src/cli/commands/pull.ts +0 -16
  224. package/src/cli/commands/serve.ts +0 -39
  225. package/src/cli/commands/uninstall.ts +0 -64
  226. package/src/cli/index.ts +0 -82
  227. package/src/core/installers/clients/BaseClientInstaller.ts +0 -341
  228. package/src/core/installers/clients/ClientInstaller.ts +0 -222
  229. package/src/core/installers/clients/ClientInstallerFactory.ts +0 -43
  230. package/src/core/installers/clients/ClineInstaller.ts +0 -35
  231. package/src/core/installers/clients/ExtensionInstaller.ts +0 -165
  232. package/src/core/installers/clients/GithubCopilotInstaller.ts +0 -79
  233. package/src/core/installers/clients/MSRooCodeInstaller.ts +0 -32
  234. package/src/core/installers/index.ts +0 -11
  235. package/src/core/installers/requirements/BaseInstaller.ts +0 -85
  236. package/src/core/installers/requirements/CommandInstaller.ts +0 -231
  237. package/src/core/installers/requirements/GeneralInstaller.ts +0 -133
  238. package/src/core/installers/requirements/InstallerFactory.ts +0 -114
  239. package/src/core/installers/requirements/NpmInstaller.ts +0 -271
  240. package/src/core/installers/requirements/NugetInstaller.ts +0 -203
  241. package/src/core/installers/requirements/PipInstaller.ts +0 -207
  242. package/src/core/installers/requirements/RequirementInstaller.ts +0 -42
  243. package/src/core/loaders/ConfigurationLoader.ts +0 -298
  244. package/src/core/loaders/ConfigurationProvider.ts +0 -462
  245. package/src/core/loaders/InstallOperationManager.ts +0 -367
  246. package/src/core/loaders/ServerSchemaLoader.ts +0 -117
  247. package/src/core/loaders/ServerSchemaProvider.ts +0 -99
  248. package/src/core/loaders/SystemSettingsManager.ts +0 -278
  249. package/src/core/metadatas/constants.ts +0 -122
  250. package/src/core/metadatas/recordingConstants.ts +0 -65
  251. package/src/core/metadatas/types.ts +0 -202
  252. package/src/core/onboard/FeedOnboardService.ts +0 -501
  253. package/src/core/onboard/OnboardProcessor.ts +0 -356
  254. package/src/core/onboard/OnboardStatus.ts +0 -60
  255. package/src/core/onboard/OnboardStatusManager.ts +0 -416
  256. package/src/core/validators/FeedValidator.ts +0 -135
  257. package/src/core/validators/IServerValidator.ts +0 -21
  258. package/src/core/validators/SSEServerValidator.ts +0 -43
  259. package/src/core/validators/ServerValidatorFactory.ts +0 -51
  260. package/src/core/validators/StdioServerValidator.ts +0 -313
  261. package/src/index.ts +0 -44
  262. package/src/services/InstallationService.ts +0 -102
  263. package/src/services/MCPManager.ts +0 -249
  264. package/src/services/RequirementService.ts +0 -627
  265. package/src/services/ServerService.ts +0 -161
  266. package/src/services/TelemetryService.ts +0 -59
  267. package/src/utils/UpdateCheckTracker.ts +0 -86
  268. package/src/utils/adoUtils.ts +0 -293
  269. package/src/utils/clientUtils.ts +0 -72
  270. package/src/utils/feedUtils.ts +0 -31
  271. package/src/utils/githubAuth.ts +0 -212
  272. package/src/utils/githubUtils.ts +0 -164
  273. package/src/utils/logger.ts +0 -195
  274. package/src/utils/macroExpressionUtils.ts +0 -104
  275. package/src/utils/osUtils.ts +0 -700
  276. package/src/utils/versionUtils.ts +0 -114
  277. package/src/web/contract/serverContract.ts +0 -74
  278. package/src/web/public/css/detailsWidget.css +0 -235
  279. package/src/web/public/css/modal.css +0 -757
  280. package/src/web/public/css/notifications.css +0 -101
  281. package/src/web/public/css/onboard.css +0 -107
  282. package/src/web/public/css/serverCategoryList.css +0 -120
  283. package/src/web/public/css/serverDetails.css +0 -139
  284. package/src/web/public/index.html +0 -359
  285. package/src/web/public/js/api.js +0 -132
  286. package/src/web/public/js/detailsWidget.js +0 -264
  287. package/src/web/public/js/flights/flights.js +0 -127
  288. package/src/web/public/js/modal/index.js +0 -52
  289. package/src/web/public/js/modal/installModal.js +0 -162
  290. package/src/web/public/js/modal/installation.js +0 -266
  291. package/src/web/public/js/modal/loadingModal.js +0 -182
  292. package/src/web/public/js/modal/modalSetup.js +0 -595
  293. package/src/web/public/js/modal/modalUtils.js +0 -37
  294. package/src/web/public/js/modal/versionUtils.js +0 -20
  295. package/src/web/public/js/modal.js +0 -42
  296. package/src/web/public/js/notifications.js +0 -137
  297. package/src/web/public/js/onboard/formProcessor.js +0 -1037
  298. package/src/web/public/js/onboard/index.js +0 -374
  299. package/src/web/public/js/onboard/publishHandler.js +0 -172
  300. package/src/web/public/js/onboard/state.js +0 -76
  301. package/src/web/public/js/onboard/templates.js +0 -342
  302. package/src/web/public/js/onboard/uiHandlers.js +0 -1076
  303. package/src/web/public/js/onboard/validationHandlers.js +0 -493
  304. package/src/web/public/js/serverCategoryDetails.js +0 -364
  305. package/src/web/public/js/serverCategoryList.js +0 -241
  306. package/src/web/public/js/settings.js +0 -314
  307. package/src/web/public/modal.html +0 -84
  308. package/src/web/public/onboard.html +0 -296
  309. package/src/web/public/settings.html +0 -135
  310. package/src/web/public/styles.css +0 -277
  311. package/src/web/server.ts +0 -478
  312. package/tsconfig.json +0 -18
  313. package/wiki/Installation.md +0 -3
  314. package/wiki/Publish.md +0 -3
@@ -1,311 +1,2 @@
1
- import fs from 'fs/promises';
2
- import path from 'path';
3
- import { SETTINGS_DIR } from '../metadatas/constants.js';
4
- import { Logger } from '../../utils/logger.js';
5
- const INSTALL_STATUS_DIR = path.join(SETTINGS_DIR, 'InstallOperationStatus');
6
- export class InstallOperationManager {
7
- installOperationStatus = {};
8
- statusLock = Promise.resolve();
9
- categoryName;
10
- serverName;
11
- statusFilePath;
12
- /**
13
- * Creates an InstallOperationManager instance for a specific category and server.
14
- * @param categoryName The name of the category.
15
- * @param serverName The name of the server.
16
- */
17
- constructor(categoryName, serverName) {
18
- this.categoryName = categoryName;
19
- this.serverName = serverName;
20
- this.statusFilePath = path.join(INSTALL_STATUS_DIR, this.categoryName, `${this.serverName}.json`);
21
- this.loadStatuses().catch(error => Logger.error('Failed to initialize InstallOperationManager:', error));
22
- }
23
- /**
24
- * Returns an InstallOperationManager instance for the given category and server.
25
- * @param categoryName The name of the category.
26
- * @param serverName The name of the server.
27
- */
28
- static instanceMap = new Map();
29
- /**
30
- * Returns a cached InstallOperationManager instance for the given category and server.
31
- * If an instance does not exist, it will be created and cached.
32
- * @param categoryName The name of the category.
33
- * @param serverName The name of the server.
34
- */
35
- static getInstance(categoryName, serverName) {
36
- const key = `${categoryName}::${serverName}`;
37
- if (!this.instanceMap.has(key)) {
38
- this.instanceMap.set(key, new InstallOperationManager(categoryName, serverName));
39
- }
40
- return this.instanceMap.get(key);
41
- }
42
- async withLock(operation) {
43
- const current = this.statusLock;
44
- let resolve;
45
- this.statusLock = new Promise(r => resolve = r);
46
- try {
47
- await current;
48
- return await operation();
49
- }
50
- finally {
51
- resolve();
52
- }
53
- }
54
- async loadStatuses() {
55
- await this.withLock(async () => {
56
- try {
57
- await fs.mkdir(path.dirname(this.statusFilePath), { recursive: true });
58
- const data = await fs.readFile(this.statusFilePath, 'utf-8');
59
- this.installOperationStatus = JSON.parse(data);
60
- }
61
- catch (error) {
62
- if (error.code === 'ENOENT') {
63
- this.installOperationStatus = {};
64
- await this.saveStatuses(); // Create the file if it doesn't exist
65
- }
66
- else {
67
- Logger.error('Failed to load install operation statuses:', error);
68
- this.installOperationStatus = {}; // Initialize with empty statuses in case of other errors
69
- }
70
- }
71
- });
72
- }
73
- async saveStatuses() {
74
- await fs.mkdir(path.dirname(this.statusFilePath), { recursive: true });
75
- await fs.writeFile(this.statusFilePath, JSON.stringify(this.installOperationStatus, null, 2));
76
- }
77
- get operationKey() {
78
- return `${this.categoryName}-${this.serverName}`;
79
- }
80
- /**
81
- * Record a step for this category/server instance.
82
- */
83
- async recordStep(stepName, status, message) {
84
- return await this.withLock(async () => {
85
- let operationDetails = this.installOperationStatus[this.operationKey];
86
- const newStep = {
87
- name: stepName,
88
- status,
89
- message,
90
- timestamp: new Date().toISOString(),
91
- };
92
- if (!operationDetails) {
93
- operationDetails = {
94
- currentStep: stepName,
95
- steps: [newStep],
96
- lastUpdated: new Date().toISOString(),
97
- error: status === 'failed' ? message : undefined,
98
- overallStatus: status === 'failed' ? 'failed' : 'in-progress',
99
- };
100
- }
101
- else {
102
- // Check for an existing unfinished step with the same name
103
- const existingStepIndex = operationDetails.steps.findIndex(s => s.name === stepName && s.status !== 'completed' && s.status !== 'failed');
104
- if (existingStepIndex !== -1) {
105
- // Update the existing unfinished step
106
- operationDetails.steps[existingStepIndex] = newStep;
107
- }
108
- else {
109
- operationDetails.steps.push(newStep);
110
- }
111
- operationDetails.currentStep = stepName;
112
- operationDetails.lastUpdated = new Date().toISOString();
113
- if (status === 'failed') {
114
- operationDetails.overallStatus = 'failed';
115
- if (!operationDetails.error) { // Store the first error
116
- operationDetails.error = message;
117
- }
118
- // Mark all in-progress steps as cancelled
119
- operationDetails.steps = operationDetails.steps.map(s => s.status === 'in-progress'
120
- ? {
121
- ...s,
122
- status: 'canceled',
123
- message: (s.message ? s.message + ' ' : '') + '[Canceled due to failure]',
124
- timestamp: new Date().toISOString(),
125
- }
126
- : s);
127
- }
128
- else if (status === 'completed' && stepName.toLowerCase().includes('completed')) {
129
- // Check if all steps are completed or if there are any failures
130
- const allStepsCompleted = operationDetails.steps.every(s => s.status === 'completed' || (s.name === stepName && status === 'completed'));
131
- operationDetails.overallStatus = allStepsCompleted ? 'completed' : 'in-progress';
132
- if (allStepsCompleted) {
133
- operationDetails.error = undefined; // Clear error on completion
134
- }
135
- }
136
- else {
137
- if (operationDetails.overallStatus !== 'failed') {
138
- operationDetails.overallStatus = 'in-progress';
139
- }
140
- }
141
- }
142
- // Special handling for the "InstallCompleted" step or similar final step names
143
- if (stepName === 'InstallCompleted') {
144
- operationDetails.overallStatus = status === 'completed' ? 'completed' : 'failed';
145
- if (status === 'completed')
146
- operationDetails.error = undefined;
147
- }
148
- this.installOperationStatus[this.operationKey] = operationDetails;
149
- await this.saveStatuses();
150
- return operationDetails;
151
- });
152
- }
153
- /**
154
- * Resets (deletes) the operation status for this category/server.
155
- * This is useful to call before starting a new installation attempt.
156
- */
157
- async resetOperation() {
158
- await this.withLock(async () => {
159
- if (this.installOperationStatus[this.operationKey]) {
160
- delete this.installOperationStatus[this.operationKey];
161
- Logger.info(`Reset installation operation status for ${this.operationKey}`);
162
- await this.saveStatuses();
163
- }
164
- });
165
- return this;
166
- }
167
- /**
168
- * Gets the details for this category/server.
169
- */
170
- async getDetails() {
171
- await this.loadStatuses(); // Ensure latest statuses are loaded
172
- return this.installOperationStatus[this.operationKey];
173
- }
174
- /**
175
- * Gets all operation details in this file (for this category/server).
176
- */
177
- async getAllDetails() {
178
- await this.loadStatuses();
179
- return this.installOperationStatus;
180
- }
181
- /**
182
- * Explicitly mark the overall status of an operation as 'completed' or 'failed'.
183
- * This can be used to force the final state regardless of step details.
184
- * @param status 'completed' or 'failed'
185
- * @param error Optional error message if failed
186
- */
187
- async markOverallStatus(status, error) {
188
- return await this.withLock(async () => {
189
- const operationDetails = this.installOperationStatus[this.operationKey];
190
- if (!operationDetails)
191
- return undefined;
192
- operationDetails.overallStatus = status;
193
- operationDetails.lastUpdated = new Date().toISOString();
194
- if (status === 'failed') {
195
- if (error) {
196
- operationDetails.error = error;
197
- }
198
- // Mark all in-progress steps as cancelled
199
- operationDetails.steps = operationDetails.steps.map(s => s.status === 'in-progress'
200
- ? {
201
- ...s,
202
- status: 'canceled',
203
- message: (s.message ? s.message + ' ' : '') + '[Canceled due to failure]',
204
- timestamp: new Date().toISOString(),
205
- }
206
- : s);
207
- }
208
- if (status === 'completed') {
209
- operationDetails.error = undefined;
210
- }
211
- await this.saveStatuses();
212
- return operationDetails;
213
- });
214
- }
215
- /**
216
- * Executes a function and records its step status as 'in-progress', 'completed', or 'failed'.
217
- *
218
- * Useful for wrapping tasks with consistent status tracking and flexible error handling.
219
- *
220
- * @template T The return type of the function being executed.
221
- *
222
- * @param fn The function to execute. Can be synchronous or asynchronous.
223
- * @param options Optional configuration:
224
- * - stepName: Custom name for the step. Defaults to the function name or 'unnamedStep'.
225
- * - inProgressMessage: Optional message to log when the step starts.
226
- * - endMessage: Optional static string or function to generate a final message from the result or error.
227
- * - onResult: A function `(result: T) => boolean` that determines whether the step was successful. Defaults to always `true`.
228
- * - onError: Optional function `(error) => { result: T; message: string } | never` that handles an error and may return a fallback result and message, or throw.
229
- *
230
- * @returns A promise that resolves with the result of the function if successful, or rethrows on failure.
231
- *
232
- * @throws The original error or any error thrown from `onError`.
233
- */
234
- async recording(fn, options) {
235
- const { stepName, inProgressMessage = 'Step in progress', endMessage, onResult = () => true, onError } = options || {};
236
- const resolvedStepName = stepName ?? (fn.name || 'unnamedStep');
237
- const getEndMessage = (data, fallback) => typeof endMessage === 'function' ? endMessage(data) || 'Step completed' : endMessage ?? fallback;
238
- await this.recordStep(resolvedStepName, 'in-progress', inProgressMessage);
239
- try {
240
- const result = await Promise.resolve(fn());
241
- const isSuccess = onResult(result);
242
- await this.recordStep(resolvedStepName, isSuccess ? 'completed' : 'failed', getEndMessage(result, isSuccess ? 'Step completed successfully' : 'Step failed'));
243
- return result;
244
- }
245
- catch (err) {
246
- if (!onError) {
247
- await this.recordStep(resolvedStepName, 'failed', err?.message || String(err));
248
- throw err;
249
- }
250
- try {
251
- const { result, message } = await onError(err);
252
- await this.recordStep(resolvedStepName, 'failed', message);
253
- return result;
254
- }
255
- catch (onErrorThrown) {
256
- await this.recordStep(resolvedStepName, 'failed', onErrorThrown?.message || String(onErrorThrown));
257
- throw onErrorThrown;
258
- }
259
- }
260
- }
261
- /**
262
- * Executes an asynchronous "fire-and-forget" task and records its step status as 'in-progress', 'completed', or 'failed'.
263
- *
264
- * Unlike `recording`, this does not await the result — it runs the task in the background.
265
- * Useful for side-effecting operations like updates or notifications where progress should be logged but not block flow.
266
- *
267
- * @template T The resolved type of the asynchronous task.
268
- *
269
- * @param fn The async function to execute.
270
- * @param options Optional configuration:
271
- * - stepName: Custom name for the step. Defaults to the function name or 'unnamedStep'.
272
- * - inProgressMessage: Message to log when the step starts.
273
- * - endMessage: Static string or function to generate the final message from result or error.
274
- * - onResult: A boolean or function `(result: T) => boolean` to determine if the step is successful.
275
- * - onError: A function `(error) => string` or `Promise<string>` to handle errors and return a message.
276
- * If it throws, the error is rethrown and logged.
277
- * - onComplete: Optional callback to run after completion, regardless of success or failure.
278
- *
279
- * @returns void
280
- */
281
- recordingAsync(fn, options) {
282
- const { stepName, inProgressMessage = 'Step in progress', endMessage, onResult = () => true, onError, onComplete, } = options || {};
283
- const resolvedStepName = stepName ?? (fn.name || 'unnamedStep');
284
- const getMessage = (data, fallback) => typeof endMessage === 'function' ? endMessage(data) : endMessage ?? fallback;
285
- this.recordStep(resolvedStepName, 'in-progress', inProgressMessage).then(() => {
286
- fn()
287
- .then(result => {
288
- const isSuccess = onResult(result);
289
- const message = getMessage(result, isSuccess ? 'Step completed successfully' : 'Step failed');
290
- this.recordStep(resolvedStepName, isSuccess ? 'completed' : 'failed', message).then(onComplete).catch();
291
- })
292
- .catch(async (err) => {
293
- if (onError) {
294
- try {
295
- const errorMessage = await onError(err);
296
- await this.recordStep(resolvedStepName, 'failed', errorMessage);
297
- }
298
- catch (onErrorThrown) {
299
- await this.recordStep(resolvedStepName, 'failed', onErrorThrown?.message || String(onErrorThrown));
300
- throw onErrorThrown;
301
- }
302
- }
303
- else {
304
- const fallback = getMessage(err, err?.message || String(err));
305
- await this.recordStep(resolvedStepName, 'failed', fallback);
306
- }
307
- });
308
- });
309
- }
310
- }
1
+ import fs from"fs/promises";import path from"path";import{SETTINGS_DIR}from"../metadatas/constants.js";import{Logger}from"../../utils/logger.js";const INSTALL_STATUS_DIR=path.join(SETTINGS_DIR,"InstallOperationStatus");export class InstallOperationManager{installOperationStatus={};statusLock=Promise.resolve();categoryName;serverName;statusFilePath;constructor(t,e){this.categoryName=t,this.serverName=e,this.statusFilePath=path.join(INSTALL_STATUS_DIR,this.categoryName,`${this.serverName}.json`),this.loadStatuses().catch((t=>Logger.error("Failed to initialize InstallOperationManager:",t)))}static instanceMap=new Map;static getInstance(t,e){const s=`${t}::${e}`;return this.instanceMap.has(s)||this.instanceMap.set(s,new InstallOperationManager(t,e)),this.instanceMap.get(s)}async withLock(t){const e=this.statusLock;let s;this.statusLock=new Promise((t=>s=t));try{return await e,await t()}finally{s()}}async loadStatuses(){await this.withLock((async()=>{try{await fs.mkdir(path.dirname(this.statusFilePath),{recursive:!0});const t=await fs.readFile(this.statusFilePath,"utf-8");this.installOperationStatus=JSON.parse(t)}catch(t){"ENOENT"===t.code?(this.installOperationStatus={},await this.saveStatuses()):(Logger.error("Failed to load install operation statuses:",t),this.installOperationStatus={})}}))}async saveStatuses(){await fs.mkdir(path.dirname(this.statusFilePath),{recursive:!0}),await fs.writeFile(this.statusFilePath,JSON.stringify(this.installOperationStatus,null,2))}get operationKey(){return`${this.categoryName}-${this.serverName}`}async recordStep(t,e,s){return await this.withLock((async()=>{let a=this.installOperationStatus[this.operationKey];const i={name:t,status:e,message:s,timestamp:(new Date).toISOString()};if(a){const r=a.steps.findIndex((e=>e.name===t&&"completed"!==e.status&&"failed"!==e.status));if(-1!==r?a.steps[r]=i:a.steps.push(i),a.currentStep=t,a.lastUpdated=(new Date).toISOString(),"failed"===e)a.overallStatus="failed",a.error||(a.error=s),a.steps=a.steps.map((t=>"in-progress"===t.status?{...t,status:"canceled",message:(t.message?t.message+" ":"")+"[Canceled due to failure]",timestamp:(new Date).toISOString()}:t));else if("completed"===e&&t.toLowerCase().includes("completed")){const s=a.steps.every((s=>"completed"===s.status||s.name===t&&"completed"===e));a.overallStatus=s?"completed":"in-progress",s&&(a.error=void 0)}else"failed"!==a.overallStatus&&(a.overallStatus="in-progress")}else a={currentStep:t,steps:[i],lastUpdated:(new Date).toISOString(),error:"failed"===e?s:void 0,overallStatus:"failed"===e?"failed":"in-progress"};return"InstallCompleted"===t&&(a.overallStatus="completed"===e?"completed":"failed","completed"===e&&(a.error=void 0)),this.installOperationStatus[this.operationKey]=a,await this.saveStatuses(),a}))}async resetOperation(){return await this.withLock((async()=>{this.installOperationStatus[this.operationKey]&&(delete this.installOperationStatus[this.operationKey],Logger.info(`Reset installation operation status for ${this.operationKey}`),await this.saveStatuses())})),this}async getDetails(){return await this.loadStatuses(),this.installOperationStatus[this.operationKey]}async getAllDetails(){return await this.loadStatuses(),this.installOperationStatus}async markOverallStatus(t,e){return await this.withLock((async()=>{const s=this.installOperationStatus[this.operationKey];if(s)return s.overallStatus=t,s.lastUpdated=(new Date).toISOString(),"failed"===t&&(e&&(s.error=e),s.steps=s.steps.map((t=>"in-progress"===t.status?{...t,status:"canceled",message:(t.message?t.message+" ":"")+"[Canceled due to failure]",timestamp:(new Date).toISOString()}:t))),"completed"===t&&(s.error=void 0),await this.saveStatuses(),s}))}async recording(t,e){const{stepName:s,inProgressMessage:a="Step in progress",endMessage:i,onResult:r=()=>!0,onError:o}=e||{},n=s??(t.name||"unnamedStep");await this.recordStep(n,"in-progress",a);try{const e=await Promise.resolve(t()),s=r(e);return await this.recordStep(n,s?"completed":"failed",(l=e,p=s?"Step completed successfully":"Step failed","function"==typeof i?i(l)||"Step completed":i??p)),e}catch(t){if(!o)throw await this.recordStep(n,"failed",t?.message||String(t)),t;try{const{result:e,message:s}=await o(t);return await this.recordStep(n,"failed",s),e}catch(t){throw await this.recordStep(n,"failed",t?.message||String(t)),t}}var l,p}recordingAsync(t,e){const{stepName:s,inProgressMessage:a="Step in progress",endMessage:i,onResult:r=()=>!0,onError:o,onComplete:n}=e||{},l=s??(t.name||"unnamedStep"),p=(t,e)=>"function"==typeof i?i(t):i??e;this.recordStep(l,"in-progress",a).then((()=>{t().then((t=>{const e=r(t),s=p(t,e?"Step completed successfully":"Step failed");this.recordStep(l,e?"completed":"failed",s).then(n).catch()})).catch((async t=>{if(o)try{const e=await o(t);await this.recordStep(l,"failed",e)}catch(t){throw await this.recordStep(l,"failed",t?.message||String(t)),t}else{const e=p(t,t?.message||String(t));await this.recordStep(l,"failed",e)}}))}))}}
311
2
  //# sourceMappingURL=InstallOperationManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["fs","path","SETTINGS_DIR","Logger","INSTALL_STATUS_DIR","join","InstallOperationManager","installOperationStatus","statusLock","Promise","resolve","categoryName","serverName","statusFilePath","constructor","this","loadStatuses","catch","error","static","Map","getInstance","key","instanceMap","has","set","get","withLock","operation","current","r","async","mkdir","dirname","recursive","data","readFile","JSON","parse","code","saveStatuses","writeFile","stringify","operationKey","recordStep","stepName","status","message","operationDetails","newStep","name","timestamp","Date","toISOString","existingStepIndex","steps","findIndex","s","push","currentStep","lastUpdated","overallStatus","map","toLowerCase","includes","allStepsCompleted","every","undefined","resetOperation","info","getDetails","getAllDetails","markOverallStatus","recording","fn","options","inProgressMessage","endMessage","onResult","onError","resolvedStepName","result","isSuccess","fallback","err","String","onErrorThrown","recordingAsync","onComplete","getMessage","then","errorMessage"],"sources":["../../../src/core/loaders/InstallOperationManager.ts"],"mappings":"OAAOA,OAAQ,qBACRC,SAAU,cACRC,iBAAoB,mCAEpBC,WAAc,wBAEvB,MAAMC,mBAAqBH,KAAKI,KAAKH,aAAc,iCAE7C,MAAOI,wBACHC,uBAAkE,GAClEC,WAA4BC,QAAQC,UAC3BC,aACAC,WACAC,eAOjB,WAAAC,CAAYH,EAAsBC,GAChCG,KAAKJ,aAAeA,EACpBI,KAAKH,WAAaA,EAClBG,KAAKF,eAAiBZ,KAAKI,KACzBD,mBACAW,KAAKJ,aACL,GAAGI,KAAKH,mBAEVG,KAAKC,eAAeC,OAAMC,GAASf,OAAOe,MAAM,gDAAiDA,IACnG,CAOQC,mBAA2D,IAAIC,IAQhE,kBAAOC,CAAYV,EAAsBC,GAC9C,MAAMU,EAAM,GAAGX,MAAiBC,IAIhC,OAHKG,KAAKQ,YAAYC,IAAIF,IACxBP,KAAKQ,YAAYE,IAAIH,EAAK,IAAIhB,wBAAwBK,EAAcC,IAE/DG,KAAKQ,YAAYG,IAAIJ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SAAWM,GAAyBvC,SAAWsC,OAAOC,IACxFA,CACR,CACF,CAxBsB,IAACnD,EAASgD,CAyBlC,CAuBO,cAAAI,CAAkBb,EAAsBC,GAS7C,MAAM9B,SACJA,EAAQ+B,kBACRA,EAAoB,mBAAkBC,WACtCA,EAAUC,SACVA,EAAW,KAAM,EAAIC,QACrBA,EAAOS,WACPA,GACEb,GAAW,GAETK,EAAmBnC,IAAa6B,EAAGxB,MAAQ,eAC3CuC,EAAa,CAACtD,EAASgD,IAA2C,mBAAfN,EAA4BA,EAAW1C,GAAQ0C,GAAcM,EAEtHpE,KAAK6B,WAAWoC,EAAkB,cAAeJ,GAAmBc,MAAK,KACvEhB,IACGgB,MAAKT,IACJ,MAAMC,EAAYJ,EAASG,GACrBlC,EAAU0C,EAAWR,EAAQC,EAAY,8BAAgC,eAC/EnE,KAAK6B,WAAWoC,EAAkBE,EAAY,YAAc,SAAUnC,GAAS2C,KAAKF,GAAYvE,OAAO,IAExGA,OAAMc,MAAOqD,IACZ,GAAIL,EACF,IACE,MAAMY,QAAqBZ,EAAQK,SAC7BrE,KAAK6B,WAAWoC,EAAkB,SAAUW,EACpD,CAAE,MAAOL,GAEP,YADMvE,KAAK6B,WAAWoC,EAAkB,SAAWM,GAAyBvC,SAAWsC,OAAOC,IACxFA,CACR,KACK,CACL,MAAMH,EAAWM,EAAWL,EAAMA,GAAerC,SAAWsC,OAAOD,UAC7DrE,KAAK6B,WAAWoC,EAAkB,SAAUG,EACpD,IACA,GAER","ignoreList":[]}
@@ -1,109 +1,2 @@
1
- import fs from 'fs/promises';
2
- import path from 'path';
3
- import { Logger } from '../../utils/logger.js';
4
- export class ServerSchemaLoader {
5
- /**
6
- * Loads a single schema file.
7
- * @param filePath The absolute path to the schema file.
8
- * @returns A Promise that resolves to the ServerSchema or undefined if not found or error.
9
- */
10
- static async loadSchema(filePath) {
11
- try {
12
- const content = await fs.readFile(filePath, 'utf8');
13
- const schema = JSON.parse(content);
14
- return {
15
- schema: schema
16
- };
17
- }
18
- catch (error) {
19
- if (error.code === 'ENOENT') {
20
- Logger.debug(`No schema file found at ${filePath}`);
21
- return undefined;
22
- }
23
- Logger.error(`Error loading schema from ${filePath}:`, error);
24
- // Optionally rethrow or return undefined based on desired error handling
25
- return undefined;
26
- }
27
- }
28
- /**
29
- * Loads all schemas from the default feeds directory.
30
- * @param defaultFeedsDir The path to the default feeds directory.
31
- * @param schemaMap The map to populate with loaded schemas.
32
- */
33
- static async loadAllDefaultSchemas(defaultFeedsDir, schemaMap) {
34
- schemaMap.clear(); // Clear map for initial load from default directory
35
- try {
36
- const categoryDirs = await fs.readdir(defaultFeedsDir, { withFileTypes: true });
37
- for (const categoryDir of categoryDirs) {
38
- if (categoryDir.isDirectory()) {
39
- const categoryName = categoryDir.name;
40
- const categoryPath = path.join(defaultFeedsDir, categoryName);
41
- const serverFiles = await fs.readdir(categoryPath);
42
- const serverSchemas = new Map();
43
- for (const file of serverFiles) {
44
- if (file.endsWith('.json')) {
45
- try {
46
- const schemaFilePath = path.join(categoryPath, file);
47
- const schema = await this.loadSchema(schemaFilePath);
48
- if (schema) {
49
- serverSchemas.set(file, schema); // file is serverName
50
- Logger.debug(`Loaded schema '${file}' for category '${categoryName}' from default directory`);
51
- }
52
- }
53
- catch (error) { // Error already logged in loadSchema
54
- Logger.error(`Skipping schema file ${file} in category ${categoryName} due to loading error.`);
55
- }
56
- }
57
- }
58
- if (serverSchemas.size > 0) {
59
- schemaMap.set(categoryName, serverSchemas);
60
- }
61
- }
62
- }
63
- }
64
- catch (error) {
65
- Logger.error(`Error reading schemas from default directory ${defaultFeedsDir}:`, error);
66
- }
67
- }
68
- /**
69
- * Loads schemas from an adhoc directory for a specific category.
70
- * @param adhocSchemasDir The path to the adhoc schemas directory.
71
- * @param categoryName The name of the category for these adhoc schemas.
72
- * @param schemaMap The map to update with loaded adhoc schemas.
73
- */
74
- static async loadAdhocSchemas(adhocSchemasDir, categoryName, schemaMap) {
75
- try {
76
- const serverFiles = await fs.readdir(adhocSchemasDir);
77
- if (schemaMap.has(categoryName)) {
78
- 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`);
79
- }
80
- let serverSchemas = schemaMap.get(categoryName);
81
- if (!serverSchemas) {
82
- serverSchemas = new Map();
83
- }
84
- for (const file of serverFiles) {
85
- if (file.endsWith('.json')) {
86
- try {
87
- const schemaFilePath = path.join(adhocSchemasDir, file);
88
- const schema = await this.loadSchema(schemaFilePath);
89
- if (schema) {
90
- serverSchemas.set(file, schema); // file is serverName
91
- Logger.debug(`Loaded adhoc schema '${file}' for category '${categoryName}'`);
92
- }
93
- }
94
- catch (error) { // Error already logged in loadSchema
95
- Logger.error(`Skipping adhoc schema file ${file} in category ${categoryName} due to loading error.`);
96
- }
97
- }
98
- }
99
- if (serverSchemas.size > 0) {
100
- schemaMap.set(categoryName, serverSchemas);
101
- }
102
- }
103
- catch (error) {
104
- // This case should ideally be caught by the fs.access check in ServerSchemaProvider.initialize
105
- Logger.error(`Error reading adhoc schemas from directory ${adhocSchemasDir} for category ${categoryName}:`, error);
106
- }
107
- }
108
- }
1
+ import fs from"fs/promises";import path from"path";import{Logger}from"../../utils/logger.js";export class ServerSchemaLoader{static async loadSchema(r){try{const e=await fs.readFile(r,"utf8");return{schema:JSON.parse(e)}}catch(e){return"ENOENT"===e.code?void Logger.debug(`No schema file found at ${r}`):void Logger.error(`Error loading schema from ${r}:`,e)}}static async loadAllDefaultSchemas(r,e){e.clear();try{const o=await fs.readdir(r,{withFileTypes:!0});for(const a of o)if(a.isDirectory()){const o=a.name,t=path.join(r,o),c=await fs.readdir(t),i=new Map;for(const r of c)if(r.endsWith(".json"))try{const e=path.join(t,r),a=await this.loadSchema(e);a&&(i.set(r,a),Logger.debug(`Loaded schema '${r}' for category '${o}' from default directory`))}catch(e){Logger.error(`Skipping schema file ${r} in category ${o} due to loading error.`)}i.size>0&&e.set(o,i)}}catch(e){Logger.error(`Error reading schemas from default directory ${r}:`,e)}}static async loadAdhocSchemas(r,e,o){try{const a=await fs.readdir(r);o.has(e)&&Logger.warn(`Adhoc schema category '${e}' (from dir: ${r}) conflicts with an existing category. Adhoc schemas in this category will override existing ones.`);let t=o.get(e);t||(t=new Map);for(const o of a)if(o.endsWith(".json"))try{const a=path.join(r,o),c=await this.loadSchema(a);c&&(t.set(o,c),Logger.debug(`Loaded adhoc schema '${o}' for category '${e}'`))}catch(r){Logger.error(`Skipping adhoc schema file ${o} in category ${e} due to loading error.`)}t.size>0&&o.set(e,t)}catch(o){Logger.error(`Error reading adhoc schemas from directory ${r} for category ${e}:`,o)}}}
109
2
  //# sourceMappingURL=ServerSchemaLoader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["fs","path","Logger","ServerSchemaLoader","loadSchema","filePath","content","readFile","schema","JSON","parse","error","code","debug","loadAllDefaultSchemas","defaultFeedsDir","schemaMap","clear","categoryDirs","readdir","withFileTypes","categoryDir","isDirectory","categoryName","name","categoryPath","join","serverFiles","serverSchemas","Map","file","endsWith","schemaFilePath","this","set","size","loadAdhocSchemas","adhocSchemasDir","has","warn","get"],"sources":["../../../src/core/loaders/ServerSchemaLoader.ts"],"mappings":"OAAOA,OAAQ,qBACRC,SAAU,cAERC,WAAc,+BAGjB,MAAOC,mBAOF,uBAAaC,CAAWC,GAC3B,IACI,MAAMC,QAAgBN,GAAGO,SAASF,EAAU,QAG5C,MAAO,CACHG,OAHWC,KAAKC,MAAMJ,GAK9B,CAAE,MAAOK,GACL,MAA8C,WAAzCA,EAAgCC,UACjCV,OAAOW,MAAM,2BAA2BR,UAG5CH,OAAOS,MAAM,6BAA6BN,KAAaM,EAG3D,CACJ,CAOO,kCAAaG,CAAsBC,EAAyBC,GAC/DA,EAAUC,QAEV,IACI,MAAMC,QAAqBlB,GAAGmB,QAAQJ,EAAiB,CAAEK,eAAe,IAExE,IAAK,MAAMC,KAAeH,EACtB,GAAIG,EAAYC,cAA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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
- export class ServerSchemaProvider {
7
- static instance;
8
- schemaMap;
9
- schemaLock = Promise.resolve();
10
- constructor() {
11
- this.schemaMap = new Map();
12
- }
13
- static getInstance() {
14
- if (!ServerSchemaProvider.instance) {
15
- ServerSchemaProvider.instance = new ServerSchemaProvider();
16
- // Initialize is now called with optional adhocSchemasDir,
17
- // but getInstance is often called without it initially.
18
- // The actual loading with adhoc dir will happen when MCPManager calls initialize.
19
- }
20
- return ServerSchemaProvider.instance;
21
- }
22
- async withLock(operation) {
23
- const current = this.schemaLock;
24
- let resolve;
25
- this.schemaLock = new Promise(r => resolve = r);
26
- try {
27
- await current;
28
- return await operation();
29
- }
30
- finally {
31
- resolve();
32
- }
33
- }
34
- async initialize(adhocSchemasDir) {
35
- await this.withLock(async () => {
36
- try {
37
- // Create default feeds directory if it doesn't exist
38
- await fs.mkdir(LOCAL_FEEDS_SCHEMA_DIR, { recursive: true });
39
- // Load all schemas from the default feeds directory
40
- await ServerSchemaLoader.loadAllDefaultSchemas(LOCAL_FEEDS_SCHEMA_DIR, this.schemaMap);
41
- // Load schemas from adhoc directory if provided
42
- if (adhocSchemasDir) {
43
- try {
44
- await fs.access(adhocSchemasDir); // Check if directory exists
45
- const adhocCategoryName = path.basename(adhocSchemasDir);
46
- Logger.info(`Loading adhoc schemas from: ${adhocSchemasDir} for category: ${adhocCategoryName}`);
47
- await ServerSchemaLoader.loadAdhocSchemas(adhocSchemasDir, adhocCategoryName, this.schemaMap);
48
- }
49
- catch (error) {
50
- if (error.code === 'ENOENT') {
51
- Logger.warn(`Adhoc schemas directory not found: ${adhocSchemasDir}`);
52
- }
53
- else {
54
- Logger.error(`Error accessing adhoc schemas directory ${adhocSchemasDir}:`, error);
55
- }
56
- }
57
- }
58
- }
59
- catch (error) {
60
- Logger.error('Error during schema initialization:', error);
61
- throw error;
62
- }
63
- });
64
- }
65
- // The actual loading methods (loadSchema, loadAllSchemas, loadAdhocSchemas) have been moved to ServerSchemaLoader.
66
- // ServerSchemaProvider now delegates to ServerSchemaLoader for these operations.
67
- async getSchema(categoryName, schemaFileName) {
68
- return await this.withLock(async () => {
69
- const categorySchemas = this.schemaMap.get(categoryName);
70
- if (!categorySchemas) {
71
- Logger.debug(`No schemas found for category ${categoryName}`);
72
- return undefined;
73
- }
74
- const schema = categorySchemas.get(schemaFileName);
75
- if (!schema) {
76
- Logger.debug(`Schema ${schemaFileName} not found in category ${categoryName}`);
77
- }
78
- return schema;
79
- });
80
- }
81
- async reloadSchemas() {
82
- return await this.withLock(async () => {
83
- // Reloading should re-evaluate both default and any configured adhoc directory
84
- // For simplicity, we assume initialize would be called again if adhoc path changes.
85
- // This reload will just reload from the paths known during the last full initialize.
86
- await this.initialize(); // This will re-load default and adhoc if adhocSchemasDir was set
87
- });
88
- }
89
- }
1
+ import fs from"fs/promises";import path from"path";import{LOCAL_FEEDS_SCHEMA_DIR}from"../metadatas/constants.js";import{Logger}from"../../utils/logger.js";import{ServerSchemaLoader}from"./ServerSchemaLoader.js";export class ServerSchemaProvider{static instance;schemaMap;schemaLock=Promise.resolve();constructor(){this.schemaMap=new Map}static getInstance(){return ServerSchemaProvider.instance||(ServerSchemaProvider.instance=new ServerSchemaProvider),ServerSchemaProvider.instance}async withLock(e){const a=this.schemaLock;let r;this.schemaLock=new Promise((e=>r=e));try{return await a,await e()}finally{r()}}async initialize(e){await this.withLock((async()=>{try{if(await fs.mkdir(LOCAL_FEEDS_SCHEMA_DIR,{recursive:!0}),await ServerSchemaLoader.loadAllDefaultSchemas(LOCAL_FEEDS_SCHEMA_DIR,this.schemaMap),e)try{await fs.access(e);const a=path.basename(e);Logger.info(`Loading adhoc schemas from: ${e} for category: ${a}`),await ServerSchemaLoader.loadAdhocSchemas(e,a,this.schemaMap)}catch(a){"ENOENT"===a.code?Logger.warn(`Adhoc schemas directory not found: ${e}`):Logger.error(`Error accessing adhoc schemas directory ${e}:`,a)}}catch(e){throw Logger.error("Error during schema initialization:",e),e}}))}async getSchema(e,a){return await this.withLock((async()=>{const r=this.schemaMap.get(e);if(!r)return void Logger.debug(`No schemas found for category ${e}`);const t=r.get(a);return t||Logger.debug(`Schema ${a} not found in category ${e}`),t}))}async reloadSchemas(){return await this.withLock((async()=>{await this.initialize()}))}}
90
2
  //# sourceMappingURL=ServerSchemaProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["fs","path","LOCAL_FEEDS_SCHEMA_DIR","Logger","ServerSchemaLoader","ServerSchemaProvider","static","schemaMap","schemaLock","Promise","resolve","constructor","this","Map","getInstance","instance","withLock","operation","current","r","initialize","adhocSchemasDir","async","mkdir","recursive","loadAllDefaultSchemas","access","adhocCategoryName","basename","info","loadAdhocSchemas","error","code","warn","getSchema","categoryName","schemaFileName","categorySchemas","get","debug","schema","reloadSchemas"],"sources":["../../../src/core/loaders/ServerSchemaProvider.ts"],"mappings":"OAAOA,OAAQ,qBACRC,SAAU,cACRC,2BAA8B,mCAC9BC,WAAc,+BACdC,uBAA0B,iCAM7B,MAAOC,qBACDC,gBACAC,UACAC,WAA4BC,QAAQC,UAE5C,WAAAC,GACIC,KAAKL,UAAY,IAAIM,GACzB,CAEO,kBAAOC,GAOV,OANKT,qBAAqBU,WACtBV,qBAAqBU,SAAW,IAAIV,sBAKjCA,qBAAqBU,QAChC,CAEQ,cAAMC,CAAYC,GACtB,MAAMC,EAAUN,KAAKJ,WACrB,IAAIE,EACJE,KAAKJ,WAAa,IAAIC,SAAcU,GAAKT,EAAUS,IACnD,IAEI,aADMD,QACOD,GACjB,C,QACIP,GACJ,CACJ,CAEA,gBAAMU,CAAWC,SACPT,KAAKI,UAASM,UAChB,IAQI,SANMtB,GAAGuB,MAAMrB,uBAAwB,CAAEsB,WAAW,UAG9CpB,mBAAmBqB,sBAAsBvB,uBAAwBU,KAAKL,WA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