imcp 0.1.4 → 0.1.5

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 (228) hide show
  1. package/README.md +21 -4
  2. package/dist/cli/commands/install.js.map +1 -0
  3. package/dist/cli/commands/list.js.map +1 -0
  4. package/dist/cli/commands/pull.js.map +1 -0
  5. package/dist/cli/commands/serve.js.map +1 -0
  6. package/dist/cli/commands/start.d.ts +2 -0
  7. package/dist/cli/commands/start.js +32 -0
  8. package/dist/cli/commands/start.js.map +1 -0
  9. package/dist/cli/commands/sync.d.ts +2 -0
  10. package/dist/cli/commands/sync.js +17 -0
  11. package/dist/cli/commands/sync.js.map +1 -0
  12. package/dist/cli/commands/uninstall.js.map +1 -0
  13. package/dist/cli/index.js +0 -0
  14. package/dist/cli/index.js.map +1 -0
  15. package/dist/core/ConfigurationLoader.d.ts +32 -0
  16. package/{src/core/loaders/ConfigurationLoader.ts → dist/core/ConfigurationLoader.js} +236 -298
  17. package/dist/core/ConfigurationLoader.js.map +1 -0
  18. package/dist/core/ConfigurationProvider.d.ts +35 -0
  19. package/{src/core/loaders/ConfigurationProvider.ts → dist/core/ConfigurationProvider.js} +375 -462
  20. package/dist/core/ConfigurationProvider.js.map +1 -0
  21. package/dist/core/InstallationService.d.ts +50 -0
  22. package/dist/core/InstallationService.js +350 -0
  23. package/dist/core/InstallationService.js.map +1 -0
  24. package/dist/core/MCPManager.d.ts +28 -0
  25. package/dist/core/MCPManager.js +188 -0
  26. package/dist/core/MCPManager.js.map +1 -0
  27. package/dist/core/RequirementService.d.ts +40 -0
  28. package/dist/core/RequirementService.js +110 -0
  29. package/dist/core/RequirementService.js.map +1 -0
  30. package/dist/core/ServerSchemaLoader.d.ts +11 -0
  31. package/dist/core/ServerSchemaLoader.js +43 -0
  32. package/dist/core/ServerSchemaLoader.js.map +1 -0
  33. package/dist/core/ServerSchemaProvider.d.ts +17 -0
  34. package/dist/core/ServerSchemaProvider.js +120 -0
  35. package/dist/core/ServerSchemaProvider.js.map +1 -0
  36. package/dist/core/constants.d.ts +47 -0
  37. package/dist/core/constants.js +94 -0
  38. package/dist/core/constants.js.map +1 -0
  39. package/dist/core/installers/BaseInstaller.d.ts +74 -0
  40. package/dist/core/installers/BaseInstaller.js +253 -0
  41. package/dist/core/installers/BaseInstaller.js.map +1 -0
  42. package/dist/core/installers/ClientInstaller.d.ts +23 -0
  43. package/dist/core/installers/ClientInstaller.js +564 -0
  44. package/dist/core/installers/ClientInstaller.js.map +1 -0
  45. package/dist/core/installers/CommandInstaller.d.ts +37 -0
  46. package/{src/core/installers/requirements/CommandInstaller.ts → dist/core/installers/CommandInstaller.js} +173 -231
  47. package/dist/core/installers/CommandInstaller.js.map +1 -0
  48. package/dist/core/installers/GeneralInstaller.d.ts +33 -0
  49. package/dist/core/installers/GeneralInstaller.js +85 -0
  50. package/dist/core/installers/GeneralInstaller.js.map +1 -0
  51. package/dist/core/installers/InstallerFactory.d.ts +54 -0
  52. package/{src/core/installers/requirements/InstallerFactory.ts → dist/core/installers/InstallerFactory.js} +97 -114
  53. package/dist/core/installers/InstallerFactory.js.map +1 -0
  54. package/dist/core/installers/NpmInstaller.d.ts +26 -0
  55. package/dist/core/installers/NpmInstaller.js +127 -0
  56. package/dist/core/installers/NpmInstaller.js.map +1 -0
  57. package/dist/core/installers/PipInstaller.d.ts +28 -0
  58. package/dist/core/installers/PipInstaller.js +127 -0
  59. package/dist/core/installers/PipInstaller.js.map +1 -0
  60. package/{src/core/installers/requirements/RequirementInstaller.ts → dist/core/installers/RequirementInstaller.d.ts} +33 -42
  61. package/dist/core/installers/RequirementInstaller.js +3 -0
  62. package/dist/core/installers/RequirementInstaller.js.map +1 -0
  63. package/dist/core/installers/clients/BaseClientInstaller.js.map +1 -0
  64. package/dist/core/installers/clients/ClientInstaller.js.map +1 -0
  65. package/dist/core/installers/clients/ClientInstallerFactory.js.map +1 -0
  66. package/dist/core/installers/clients/ClineInstaller.js.map +1 -0
  67. package/dist/core/installers/clients/ExtensionInstaller.js.map +1 -0
  68. package/dist/core/installers/clients/GithubCopilotInstaller.js.map +1 -0
  69. package/dist/core/installers/clients/MSRooCodeInstaller.js.map +1 -0
  70. package/dist/core/installers/index.js.map +1 -0
  71. package/dist/core/installers/requirements/BaseInstaller.js.map +1 -0
  72. package/dist/core/installers/requirements/CommandInstaller.js.map +1 -0
  73. package/dist/core/installers/requirements/GeneralInstaller.js.map +1 -0
  74. package/dist/core/installers/requirements/InstallerFactory.js.map +1 -0
  75. package/dist/core/installers/requirements/NpmInstaller.js.map +1 -0
  76. package/dist/core/installers/requirements/NugetInstaller.js.map +1 -0
  77. package/dist/core/installers/requirements/PipInstaller.js.map +1 -0
  78. package/dist/core/installers/requirements/RequirementInstaller.js.map +1 -0
  79. package/dist/core/loaders/ConfigurationLoader.js.map +1 -0
  80. package/dist/core/loaders/ConfigurationProvider.js.map +1 -0
  81. package/dist/core/loaders/InstallOperationManager.js.map +1 -0
  82. package/dist/core/loaders/ServerSchemaLoader.js.map +1 -0
  83. package/dist/core/loaders/ServerSchemaProvider.js.map +1 -0
  84. package/dist/core/loaders/SystemSettingsManager.js.map +1 -0
  85. package/dist/core/metadatas/constants.js.map +1 -0
  86. package/dist/core/metadatas/recordingConstants.js.map +1 -0
  87. package/dist/core/metadatas/types.js.map +1 -0
  88. package/dist/core/onboard/FeedOnboardService.js.map +1 -0
  89. package/dist/core/onboard/OnboardProcessor.js.map +1 -0
  90. package/dist/core/onboard/OnboardStatus.js.map +1 -0
  91. package/dist/core/onboard/OnboardStatusManager.js.map +1 -0
  92. package/dist/core/types.d.ts +166 -0
  93. package/dist/core/types.js +16 -0
  94. package/dist/core/types.js.map +1 -0
  95. package/dist/core/validators/FeedValidator.js.map +1 -0
  96. package/dist/core/validators/IServerValidator.js.map +1 -0
  97. package/dist/core/validators/SSEServerValidator.js.map +1 -0
  98. package/dist/core/validators/ServerValidatorFactory.js.map +1 -0
  99. package/dist/core/validators/StdioServerValidator.js.map +1 -0
  100. package/dist/index.js.map +1 -0
  101. package/dist/services/InstallRequestValidator.d.ts +21 -0
  102. package/dist/services/InstallRequestValidator.js +99 -0
  103. package/dist/services/InstallRequestValidator.js.map +1 -0
  104. package/dist/services/InstallationService.js.map +1 -0
  105. package/dist/services/MCPManager.js.map +1 -0
  106. package/dist/services/RequirementService.js.map +1 -0
  107. package/dist/services/ServerService.js.map +1 -0
  108. package/dist/services/TelemetryService.js.map +1 -0
  109. package/dist/utils/UpdateCheckTracker.js.map +1 -0
  110. package/dist/utils/adoUtils.js.map +1 -0
  111. package/dist/utils/clientUtils.js.map +1 -0
  112. package/dist/utils/feedUtils.js.map +1 -0
  113. package/dist/utils/githubAuth.js.map +1 -0
  114. package/dist/utils/githubUtils.js.map +1 -0
  115. package/dist/utils/logger.js.map +1 -0
  116. package/dist/utils/macroExpressionUtils.js.map +1 -0
  117. package/dist/utils/osUtils.js.map +1 -0
  118. package/dist/utils/versionUtils.js.map +1 -0
  119. package/dist/web/contract/serverContract.js.map +1 -0
  120. package/dist/web/public/index.html +1 -1
  121. package/dist/web/public/js/modal/installHandler.js +227 -0
  122. package/dist/web/public/js/modal/loadingUI.js +74 -0
  123. package/dist/web/public/js/modal/messageQueue.js +101 -45
  124. package/dist/web/public/js/modal/modalUI.js +214 -0
  125. package/{src/web/public/js/modal/versionUtils.js → dist/web/public/js/modal/version.js} +1 -1
  126. package/dist/web/public/onboard.html +4 -4
  127. package/dist/web/server.js.map +1 -0
  128. package/package.json +5 -1
  129. package/.github/ISSUE_TEMPLATE/JitAccess.yml +0 -28
  130. package/.github/acl/access.yml +0 -20
  131. package/.github/compliance/inventory.yml +0 -5
  132. package/.github/policies/jit.yml +0 -19
  133. package/.roo/rules-code/rules.md +0 -88
  134. package/dist/core/onboard/InstallOperationManager.d.ts +0 -23
  135. package/dist/core/onboard/InstallOperationManager.js +0 -144
  136. package/docs/ONBOARDING_PAGE_DESIGN.md +0 -260
  137. package/docs/Telemetry.md +0 -136
  138. package/memory-bank/activeContext.md +0 -26
  139. package/memory-bank/decisionLog.md +0 -91
  140. package/memory-bank/productContext.md +0 -41
  141. package/memory-bank/progress.md +0 -35
  142. package/memory-bank/systemPatterns.md +0 -10
  143. package/src/cli/commands/install.ts +0 -139
  144. package/src/cli/commands/list.ts +0 -113
  145. package/src/cli/commands/pull.ts +0 -16
  146. package/src/cli/commands/serve.ts +0 -39
  147. package/src/cli/commands/uninstall.ts +0 -64
  148. package/src/cli/index.ts +0 -82
  149. package/src/core/installers/clients/BaseClientInstaller.ts +0 -341
  150. package/src/core/installers/clients/ClientInstaller.ts +0 -222
  151. package/src/core/installers/clients/ClientInstallerFactory.ts +0 -43
  152. package/src/core/installers/clients/ClineInstaller.ts +0 -35
  153. package/src/core/installers/clients/ExtensionInstaller.ts +0 -165
  154. package/src/core/installers/clients/GithubCopilotInstaller.ts +0 -79
  155. package/src/core/installers/clients/MSRooCodeInstaller.ts +0 -32
  156. package/src/core/installers/index.ts +0 -11
  157. package/src/core/installers/requirements/BaseInstaller.ts +0 -85
  158. package/src/core/installers/requirements/GeneralInstaller.ts +0 -133
  159. package/src/core/installers/requirements/NpmInstaller.ts +0 -271
  160. package/src/core/installers/requirements/NugetInstaller.ts +0 -203
  161. package/src/core/installers/requirements/PipInstaller.ts +0 -207
  162. package/src/core/loaders/InstallOperationManager.ts +0 -367
  163. package/src/core/loaders/ServerSchemaLoader.ts +0 -117
  164. package/src/core/loaders/ServerSchemaProvider.ts +0 -99
  165. package/src/core/loaders/SystemSettingsManager.ts +0 -278
  166. package/src/core/metadatas/constants.ts +0 -122
  167. package/src/core/metadatas/recordingConstants.ts +0 -65
  168. package/src/core/metadatas/types.ts +0 -202
  169. package/src/core/onboard/FeedOnboardService.ts +0 -501
  170. package/src/core/onboard/OnboardProcessor.ts +0 -356
  171. package/src/core/onboard/OnboardStatus.ts +0 -60
  172. package/src/core/onboard/OnboardStatusManager.ts +0 -416
  173. package/src/core/validators/FeedValidator.ts +0 -135
  174. package/src/core/validators/IServerValidator.ts +0 -21
  175. package/src/core/validators/SSEServerValidator.ts +0 -43
  176. package/src/core/validators/ServerValidatorFactory.ts +0 -51
  177. package/src/core/validators/StdioServerValidator.ts +0 -313
  178. package/src/index.ts +0 -44
  179. package/src/services/InstallationService.ts +0 -102
  180. package/src/services/MCPManager.ts +0 -249
  181. package/src/services/RequirementService.ts +0 -627
  182. package/src/services/ServerService.ts +0 -161
  183. package/src/services/TelemetryService.ts +0 -59
  184. package/src/utils/UpdateCheckTracker.ts +0 -86
  185. package/src/utils/adoUtils.ts +0 -293
  186. package/src/utils/clientUtils.ts +0 -72
  187. package/src/utils/feedUtils.ts +0 -31
  188. package/src/utils/githubAuth.ts +0 -212
  189. package/src/utils/githubUtils.ts +0 -164
  190. package/src/utils/logger.ts +0 -195
  191. package/src/utils/macroExpressionUtils.ts +0 -104
  192. package/src/utils/osUtils.ts +0 -700
  193. package/src/utils/versionUtils.ts +0 -114
  194. package/src/web/contract/serverContract.ts +0 -74
  195. package/src/web/public/css/detailsWidget.css +0 -235
  196. package/src/web/public/css/modal.css +0 -757
  197. package/src/web/public/css/notifications.css +0 -101
  198. package/src/web/public/css/onboard.css +0 -107
  199. package/src/web/public/css/serverCategoryList.css +0 -120
  200. package/src/web/public/css/serverDetails.css +0 -139
  201. package/src/web/public/index.html +0 -359
  202. package/src/web/public/js/api.js +0 -132
  203. package/src/web/public/js/detailsWidget.js +0 -264
  204. package/src/web/public/js/flights/flights.js +0 -127
  205. package/src/web/public/js/modal/index.js +0 -52
  206. package/src/web/public/js/modal/installModal.js +0 -162
  207. package/src/web/public/js/modal/installation.js +0 -266
  208. package/src/web/public/js/modal/loadingModal.js +0 -182
  209. package/src/web/public/js/modal/modalSetup.js +0 -595
  210. package/src/web/public/js/modal/modalUtils.js +0 -37
  211. package/src/web/public/js/modal.js +0 -42
  212. package/src/web/public/js/notifications.js +0 -137
  213. package/src/web/public/js/onboard/formProcessor.js +0 -1037
  214. package/src/web/public/js/onboard/index.js +0 -374
  215. package/src/web/public/js/onboard/publishHandler.js +0 -172
  216. package/src/web/public/js/onboard/state.js +0 -76
  217. package/src/web/public/js/onboard/templates.js +0 -342
  218. package/src/web/public/js/onboard/uiHandlers.js +0 -1076
  219. package/src/web/public/js/onboard/validationHandlers.js +0 -493
  220. package/src/web/public/js/serverCategoryDetails.js +0 -364
  221. package/src/web/public/js/serverCategoryList.js +0 -241
  222. package/src/web/public/js/settings.js +0 -314
  223. package/src/web/public/modal.html +0 -84
  224. package/src/web/public/onboard.html +0 -296
  225. package/src/web/public/settings.html +0 -135
  226. package/src/web/public/styles.css +0 -277
  227. package/src/web/server.ts +0 -478
  228. package/tsconfig.json +0 -18
@@ -1,501 +0,0 @@
1
- import { FeedConfiguration, McpConfig } from '../metadatas/types.js';
2
- import { configProvider } from '../loaders/ConfigurationProvider.js';
3
- import { ServerSchemaProvider } from '../loaders/ServerSchemaProvider.js';
4
- import { feedValidator } from '../validators/FeedValidator.js';
5
- import { Logger, EventType, EventStatus } from '../../utils/logger.js';
6
- import { OnboardingProcessStatus, OperationStatus, OperationType, ValidationOperationResult } from './OnboardStatus.js';
7
- import { onboardStatusManager } from './OnboardStatusManager.js';
8
- import { onboardProcessor } from './OnboardProcessor.js';
9
-
10
- /**
11
- * Service for handling feed onboarding operations
12
- */
13
- export class FeedOnboardService {
14
- // tempDir and repoDir will be generated per onboarding process
15
-
16
- constructor() {
17
- // No shared tempDir or repoDir at instance level
18
- }
19
-
20
- /**
21
- * Creates an operation ID that combines feed name and operation type.
22
- * @param feedName The name of the feed.
23
- * @param operationType The type of operation.
24
- * @returns Combined operation ID string.
25
- */
26
- private createOperationId(feedName: string, operationType: OperationType): string {
27
- return `${feedName}_${operationType}`;
28
- }
29
-
30
- /**
31
- * Onboard a new feed configuration. This method performs validation and initiates the onboarding process.
32
- * @param config Feed configuration to onboard
33
- * @param forExistingCategory Whether this onboarding is for an existing category
34
- * @returns Promise resolving to operation status with optional feed configuration
35
- */
36
- public async onboardFeed(config: FeedConfiguration, forExistingCategory?: boolean): Promise<OperationStatus & { feedConfiguration?: FeedConfiguration }> {
37
- // Perform static validation first
38
- const serverList = await this.validateStaticConfig(config, forExistingCategory);
39
-
40
- // Check for an existing, succeeded VALIDATION_ONLY operation with an identical configuration.
41
- const existingSucceededValidation = await onboardStatusManager.findSucceededOperation(config.name, 'VALIDATION_ONLY', config);
42
-
43
- if (!existingSucceededValidation) {
44
- // If no matching successful validation is found, instruct user to validate first.
45
- Logger.log(`Feed ${config.name} has not been successfully validated with the current configuration. Publishing requires prior successful validation.`);
46
- // Return a specific status/message indicating validation is required.
47
- // This is not a FAILED state for an operation, but a prerequisite not met.
48
- // We'll use a custom message and potentially a specific status if we define one for "PREREQUISITE_FAILED" or similar.
49
- // For now, let's return a FAILED status for the attempted FULL_ONBOARDING initiation.
50
- // A more robust solution might involve a different return type or error code.
51
- const onboardingId = this.createOperationId(config.name, 'FULL_ONBOARDING'); // Hypothetical ID
52
- const errorMessage = `No prior successful validation found for feed: ${config.name}. Please validate the configuration before publishing.`;
53
-
54
- // Track failed event
55
- Logger.trackEvent(EventType.FEED_ONBOARD, {
56
- status: EventStatus.FAILED,
57
- feedName: config.name,
58
- errorMessage,
59
- onboardingId: onboardingId,
60
- feedConfiguration: config
61
- });
62
-
63
- return {
64
- onboardingId: onboardingId,
65
- status: OnboardingProcessStatus.FAILED, // Or a new status like 'VALIDATION_REQUIRED'
66
- message: errorMessage,
67
- lastQueried: new Date().toISOString(),
68
- feedConfiguration: config
69
- };
70
- }
71
-
72
- Logger.log(`Found existing successful validation for feed: ${config.name}. Proceeding with full onboarding.`);
73
- // If validation exists and matches, proceed to initiate FULL_ONBOARDING.
74
- // _initiateOperation will handle checks for existing non-completed or successfully completed FULL_ONBOARDING operations.
75
- const operationStatus = await this._initiateOperation(config, 'FULL_ONBOARDING', serverList, forExistingCategory);
76
-
77
- return {
78
- ...operationStatus,
79
- feedConfiguration: config
80
- };
81
- }
82
-
83
- /**
84
- * Validate a feed configuration without performing full onboarding.
85
- * This method performs static validation and initiates the validation process.
86
- * @param config Feed configuration to validate
87
- * @param forExistingCategory Whether this validation is for an existing category
88
- * @returns Promise resolving to operation status with optional feed configuration
89
- */
90
- public async validateFeed(config: FeedConfiguration, forExistingCategory?: boolean): Promise<OperationStatus & { feedConfiguration?: FeedConfiguration }> {
91
- // Perform static validation first
92
- const serverList = await this.validateStaticConfig(config, forExistingCategory);
93
-
94
- const operationStatus = await this._initiateOperation(config, 'VALIDATION_ONLY', serverList, forExistingCategory);
95
-
96
- return { ...operationStatus, feedConfiguration: config };
97
- }
98
-
99
- /**
100
- * Initiates either a full onboarding or a validation-only operation.
101
- * It checks for existing non-completed operations for the same feed and operation type.
102
- * If an existing operation is found, its status is returned. Otherwise, a new operation is created and started.
103
- * @param config The feed configuration.
104
- * @param operationType The type of operation to initiate (FULL_ONBOARDING or VALIDATION_ONLY).
105
- * @param serverList The list of server names to process.
106
- * @returns A promise that resolves to the operation status.
107
- */
108
- private async _initiateOperation(config: FeedConfiguration, operationType: OperationType, serverList: string[], forExistingCategory?: boolean): Promise<OperationStatus & { feedConfiguration?: FeedConfiguration }> {
109
- // Check for successful operations with matching configuration
110
- const succeededOperation = await onboardStatusManager.findSucceededOperation(config.name, operationType, config);
111
- if (succeededOperation) {
112
- Logger.log(`[${succeededOperation.onboardingId}] Found existing successful ${operationType} operation for feed: ${config.name} with matching configuration.`);
113
- const operationStatus: OperationStatus & { feedConfiguration?: FeedConfiguration } = {
114
- onboardingId: succeededOperation.onboardingId,
115
- status: succeededOperation.status,
116
- message: `A successful ${operationType} already exists for this feed with identical configuration.`,
117
- lastQueried: new Date().toISOString(),
118
- };
119
-
120
- if (config) {
121
- operationStatus.feedConfiguration = config;
122
- }
123
-
124
- return operationStatus;
125
- }
126
-
127
- // If no existing or matching operations found, create a new one
128
- const onboardingId = this.createOperationId(config.name, operationType);
129
- const initialStatus = await onboardStatusManager.createInitialStatus(config.name, operationType);
130
-
131
- // Use config.name as categoryName for saveFeedConfiguration
132
- await onboardStatusManager.saveFeedConfiguration(config.name, operationType, config);
133
-
134
- if (operationType === 'FULL_ONBOARDING') {
135
- // For FULL_ONBOARDING, we assume all servers defined in the config are to be processed for PR creation.
136
- // The serverList from validateStaticConfig primarily influences validation.
137
- // If specific servers need to be excluded from the PR, this logic might need adjustment.
138
- this.processFullOnboarding(onboardingId, config, operationType, serverList).catch(async (error) => {
139
- Logger.error(`[${onboardingId}] Full feed onboarding process failed:`, error);
140
- await onboardStatusManager.recordStep(
141
- config.name,
142
- operationType,
143
- 'Failed during full onboarding process',
144
- undefined, // serverName
145
- OnboardingProcessStatus.FAILED,
146
- error instanceof Error ? error.message : String(error)
147
- );
148
- });
149
- } else if (operationType === 'VALIDATION_ONLY') {
150
- this.processValidationOnly(onboardingId, config, operationType, serverList).catch(async (error) => {
151
- Logger.error(`[${onboardingId}] Feed validation process failed:`, error);
152
- await onboardStatusManager.recordStep(
153
- config.name,
154
- operationType,
155
- 'Failed during validation process',
156
- undefined, // serverName
157
- OnboardingProcessStatus.FAILED,
158
- error instanceof Error ? error.message : String(error)
159
- // TODO: Consider how to best store/pass 'validationStatus' if it's still needed at this specific failure point
160
- );
161
- });
162
- }
163
-
164
- return {
165
- onboardingId,
166
- status: OnboardingProcessStatus.PENDING,
167
- message: `New ${operationType} process started with ID: ${onboardingId}.`,
168
- lastQueried: new Date().toISOString(),
169
- };
170
- }
171
-
172
- /**
173
- * Performs static validation of the feed configuration.
174
- * @param config The feed configuration to validate.
175
- * @param forExistingCategory Whether this is for an existing category.
176
- * @returns A promise that resolves to a list of server names to be processed.
177
- * @throws Error if validation fails.
178
- */
179
- private async validateStaticConfig(config: FeedConfiguration, forExistingCategory?: boolean): Promise<string[]> {
180
- // --- Start of moved and enhanced static validation ---
181
- if (!config || typeof config !== 'object') { // Check if config itself is a valid object
182
- throw new Error('Invalid configuration: Input must be a valid object.');
183
- }
184
- if (typeof config.name !== 'string' || !config.name.trim()) {
185
- throw new Error('Invalid configuration: "name" must be a non-empty string.');
186
- }
187
- if (!Array.isArray(config.requirements)) {
188
- throw new Error('Invalid configuration: "requirements" must be an array.');
189
- }
190
- if (!Array.isArray(config.mcpServers)) {
191
- throw new Error('Invalid configuration: "mcpServers" must be an array.');
192
- }
193
- // --- End of moved static validation ---
194
-
195
- const existingConfig = await configProvider.getFeedConfiguration(config.name);
196
- // Note: operationType validation is handled at the MCP server level
197
-
198
- let serverListToProcess: string[];
199
-
200
- if (forExistingCategory) {
201
- if (!existingConfig) {
202
- throw new Error(`Cannot update non-existent category: ${config.name}. Please ensure the category name is correct or create it as a new category.`);
203
- }
204
- // For existing categories, mcpServers list must be present in the payload.
205
- if (!config.mcpServers || config.mcpServers.length === 0) {
206
- throw new Error('For an existing category, "mcpServers" must be provided and non-empty in the payload.');
207
- }
208
-
209
- const existingServerNames = new Set(existingConfig.mcpServers.map((s: McpConfig) => s.name));
210
- // Servers to process are those that are new OR existing ones marked as adhoc in the payload.
211
- const serversToProcessInPayload = config.mcpServers.filter(payloadServer => {
212
- const isNew = !existingServerNames.has(payloadServer.name);
213
- const isAdhocInPayload = payloadServer.systemTags?.adhoc === 'true';
214
- return isNew || (existingServerNames.has(payloadServer.name) && isAdhocInPayload);
215
- });
216
-
217
- if (serversToProcessInPayload.length === 0) {
218
- // If no new or editable (adhoc) servers are found in the payload for an existing category, it's an error.
219
- throw new Error(`No new or adhoc (editable) servers provided for the existing category "${config.name}". Ensure the "mcpServers" list in your payload contains at least one server not already in this category or an existing server marked with adhoc:true.`);
220
- }
221
- serverListToProcess = serversToProcessInPayload.map(s => s.name);
222
- } else { // For new categories
223
- if (existingConfig) {
224
- // If it's not for an existing category, but the category name already exists, this is an error.
225
- // Adhoc tags on servers are not relevant here as we are creating a new category.
226
- throw new Error(`Category "${config.name}" already exists. To modify an existing category, please set 'forExistingCategory' to true.`);
227
- }
228
- // For new categories, mcpServers list must be present and non-empty.
229
- if (!config.mcpServers || config.mcpServers.length === 0) {
230
- throw new Error('Server configuration ("mcpServers") must be provided and non-empty for new categories.');
231
- }
232
- // For new categories, all servers in the payload are considered.
233
- serverListToProcess = config.mcpServers.map(s => s.name);
234
- }
235
- // Remove systemTags from individual servers
236
- if (config.mcpServers && Array.isArray(config.mcpServers)) {
237
- config.mcpServers.forEach(server => {
238
- if (server.systemTags) {
239
- delete server.systemTags;
240
- }
241
- });
242
- }
243
-
244
- // Remove systemTags and PullRequest from the main config object
245
- if (config.systemTags) {
246
- delete config.systemTags;
247
- }
248
- if (config.PullRequest) {
249
- delete config.PullRequest;
250
- }
251
-
252
- return serverListToProcess;
253
- }
254
-
255
- /**
256
- * Validates the feed configuration.
257
- * Updates the onboarding status to VALIDATING, then to VALIDATED or FAILED based on the validation result.
258
- * @param onboardingId The ID of the onboarding process.
259
- * @param config The feed configuration to validate.
260
- * @param operationType The type of operation this validation is for.
261
- * @param serverList The list of server names to validate.
262
- * @throws Error if validation fails, to be caught by the calling process.
263
- */
264
- private async _validateFeedConfiguration(onboardingId: string, config: FeedConfiguration, operationType: OperationType, serverList: string[]): Promise<void> {
265
- await onboardStatusManager.recordStep(config.name, operationType, 'Validating feed configuration', undefined, OnboardingProcessStatus.VALIDATING);
266
- let overallValidationStatus: ValidationOperationResult['validationStatus'] = { isValid: true, serverResults: [] };
267
- try {
268
- await feedValidator.validate(config, config.name, operationType);
269
-
270
- // Then, validate each MCP server specified in the serverList
271
- for (const serverConfig of config.mcpServers) {
272
- if (!serverList.includes(serverConfig.name)) {
273
- Logger.log(`[${onboardingId}] Skipping validation for server ${serverConfig.name} as it's not in the specified list for this operation.`);
274
- // Optionally, record a skipped status or add to serverResults as skipped
275
- overallValidationStatus.serverResults?.push({ serverName: serverConfig.name, isValid: true, message: "Skipped (existed)" });
276
- continue;
277
- }
278
- try {
279
- await feedValidator.validateServer(serverConfig, config, config.name, operationType);
280
- overallValidationStatus.serverResults?.push({ serverName: serverConfig.name, isValid: true });
281
- await onboardStatusManager.recordStep(config.name, operationType, `Validated server: ${serverConfig.name}`, serverConfig.name, OnboardingProcessStatus.VALIDATING);
282
- await onboardStatusManager.updateStatus(config.name, operationType, { validationStatus: overallValidationStatus });
283
- } catch (serverValidationError: any) {
284
- overallValidationStatus.isValid = false;
285
- overallValidationStatus.serverResults?.push({
286
- serverName: serverConfig.name,
287
- isValid: false,
288
- message: serverValidationError.message || String(serverValidationError)
289
- });
290
- await onboardStatusManager.recordStep(
291
- config.name,
292
- operationType,
293
- `Validation failed for server: ${serverConfig.name}`,
294
- serverConfig.name,
295
- OnboardingProcessStatus.FAILED,
296
- `Server ${serverConfig.name}: ${serverValidationError.message || String(serverValidationError)}`
297
- );
298
- await onboardStatusManager.updateStatus(config.name, operationType, { validationStatus: overallValidationStatus });
299
- throw serverValidationError; // Propagate the error to fail the whole validation
300
- }
301
- }
302
-
303
- // If all *processed* servers validated successfully
304
- await onboardStatusManager.recordStep(config.name, operationType, 'All servers in feed configuration validated successfully', undefined, OnboardingProcessStatus.VALIDATED);
305
- await onboardStatusManager.updateStatus(config.name, operationType, { validationStatus: overallValidationStatus });
306
- } catch (error) {
307
- const validationError = error as any; // Assuming error might have validation details
308
- await onboardStatusManager.recordStep(
309
- config.name,
310
- operationType,
311
- 'Feed configuration validation failed',
312
- undefined,
313
- OnboardingProcessStatus.FAILED,
314
- validationError.message || String(error)
315
- );
316
- await onboardStatusManager.updateStatus(config.name, operationType, {
317
- validationStatus: {
318
- isValid: false,
319
- message: validationError.message || String(error),
320
- serverResults: overallValidationStatus.serverResults // Ensure this is up-to-date
321
- }
322
- });
323
- throw error; // Re-throw to be caught by the calling process
324
- }
325
- }
326
-
327
- /**
328
- * Processes a validation-only operation for a feed configuration.
329
- * It validates the configuration and updates the status to SUCCEEDED if validation is successful.
330
- * If validation fails, the error is handled by _validateFeedConfiguration and the calling _initiateOperation method.
331
- * @param onboardingId The ID of the onboarding process.
332
- * @param config The feed configuration.
333
- * @param operationType The type of operation (should be 'VALIDATION_ONLY').
334
- * @param serverList The list of server names to validate.
335
- */
336
- private async processValidationOnly(onboardingId: string, config: FeedConfiguration, operationType: OperationType, serverList: string[]): Promise<void> {
337
- try {
338
- // Pass operationType and serverList to _validateFeedConfiguration
339
- await this._validateFeedConfiguration(onboardingId, config, operationType, serverList);
340
- // Use config.name and operationType for getStatus
341
- const finalStatus = await onboardStatusManager.getStatus(config.name, operationType);
342
- const result: ValidationOperationResult = {
343
- validationStatus: finalStatus?.validationStatus || { isValid: true, serverResults: [] },
344
- feedConfiguration: config
345
- };
346
- // Use config.name and operationType for recordStep and updateStatus
347
- await onboardStatusManager.recordStep(
348
- config.name,
349
- operationType,
350
- 'Feed configuration validated successfully',
351
- undefined, // serverName
352
- OnboardingProcessStatus.SUCCEEDED
353
- );
354
- await onboardStatusManager.updateStatus(config.name, operationType, {
355
- errorMessage: undefined, // Clear any previous error
356
- prInfo: undefined, // Clear PR info for validation-only
357
- result: result, // Set the result
358
- validationStatus: result.validationStatus // Ensure validationStatus is also updated on success
359
- });
360
- Logger.log(`[${onboardingId}] Successfully validated feed: ${config.name}`);
361
-
362
- // Track successful validation
363
- Logger.trackEvent(EventType.FEED_VALIDATE, {
364
- status: EventStatus.SUCCESS,
365
- feedName: config.name,
366
- operationType: 'VALIDATION_ONLY',
367
- onboardingId: onboardingId,
368
- feedConfiguration: config
369
- });
370
- } catch (error) {
371
- const errorMessage = error instanceof Error ? error.message : String(error);
372
- // Error is already logged and status updated by _validateFeedConfiguration or its callers
373
- Logger.error(`[${onboardingId}] Feed validation process failed for ${config.name} (already handled):`, error);
374
-
375
- // Track validation failure
376
- Logger.trackEvent(EventType.FEED_VALIDATE, {
377
- status: EventStatus.FAILED,
378
- feedName: config.name,
379
- operationType: 'VALIDATION_ONLY',
380
- errorMessage: errorMessage,
381
- onboardingId: onboardingId,
382
- feedConfiguration: config
383
- });
384
- }
385
- }
386
-
387
-
388
- /**
389
- * Processes the full onboarding for a feed configuration.
390
- * This includes validation, forking/cloning the repository, saving the config, and creating a pull request.
391
- * Manages status updates throughout the process and handles cleanup of temporary directories.
392
- * @param onboardingId The ID of the onboarding process.
393
- * @param config The feed configuration.
394
- * @param operationType The type of operation (should be 'FULL_ONBOARDING').
395
- * @throws Error if any step of the full onboarding process fails.
396
- */
397
- private async processFullOnboarding(onboardingId: string, config: FeedConfiguration, operationType: OperationType, serverList: string[]): Promise<void> {
398
- const { tempDir, repoDir } = onboardProcessor.createDirectories(onboardingId);
399
- try {
400
- // Validation is now a prerequisite and assumed to be done if this process is initiated.
401
- // The status should be PENDING or a similar initial state from _initiateOperation.
402
- // We directly proceed to PR creation steps.
403
- // The first step recorded here will likely move status from PENDING to PR_CREATING.
404
-
405
- await onboardStatusManager.recordStep(config.name, operationType, 'Starting PR creation process (validation confirmed)', undefined, OnboardingProcessStatus.PR_CREATING);
406
-
407
- await onboardStatusManager.recordStep(config.name, operationType, 'Forking repository', undefined, OnboardingProcessStatus.PR_CREATING);
408
- await onboardProcessor.forkRepo(onboardingId, repoDir);
409
-
410
- await onboardStatusManager.recordStep(config.name, operationType, 'Cloning repository', undefined, OnboardingProcessStatus.PR_CREATING);
411
- await onboardProcessor.cloneRepo(onboardingId, tempDir, repoDir);
412
-
413
- await onboardStatusManager.recordStep(config.name, operationType, 'Setting up branch', undefined, OnboardingProcessStatus.PR_CREATING);
414
- const branchName = await onboardProcessor.setupBranch(onboardingId, config, repoDir);
415
-
416
- await onboardStatusManager.recordStep(config.name, operationType, 'Saving feed configuration to repository', undefined, OnboardingProcessStatus.PR_CREATING);
417
- const { feedFilePath, categorySchemasPath } = await onboardProcessor.saveFeedConfigToRepo(onboardingId, config, repoDir, serverList);
418
-
419
- await onboardStatusManager.recordStep(config.name, operationType, 'Creating pull request', undefined, OnboardingProcessStatus.PR_CREATING);
420
- const prInfo = await onboardProcessor.createPullRequest(onboardingId, config, repoDir, branchName);
421
-
422
- // Step 3: Finalize with SUCCEEDED status for PR creation
423
- await onboardStatusManager.recordStep(config.name, operationType, prInfo.prExists ? 'Successfully updated to existing pull request' : 'Successfully created pull request', undefined, OnboardingProcessStatus.SUCCEEDED);
424
- await onboardStatusManager.updateStatus(config.name, operationType, {
425
- errorMessage: undefined, // Clear any previous errors
426
- prInfo: prInfo,
427
- result: prInfo.url // Store PR URL as the result
428
- });
429
- Logger.log(`[${onboardingId}] Successfully created/updated PR for feed: ${config.name}. PR URL: ${prInfo.url}`);
430
-
431
- // After successful PR, re-initialize providers
432
- try {
433
- await onboardStatusManager.recordStep(config.name, operationType, 'Reloading server schemas', undefined, OnboardingProcessStatus.SUCCEEDED);
434
- Logger.log(`[${onboardingId}] Initializing ServerSchemaProvider with new schemas at ${categorySchemasPath}`);
435
- await ServerSchemaProvider.getInstance().initialize(categorySchemasPath);
436
- Logger.log(`[${onboardingId}] ServerSchemaProvider re-initialized.`);
437
-
438
- await onboardStatusManager.recordStep(config.name, operationType, 'Reloading configurations', undefined, OnboardingProcessStatus.SUCCEEDED);
439
- Logger.log(`[${onboardingId}] Initializing ConfigurationProvider with new feed file at ${feedFilePath}`);
440
- await configProvider.initialize(feedFilePath, { prLink: prInfo.url, adhocServers: serverList }); // configProvider is already an instance
441
- Logger.log(`[${onboardingId}] ConfigurationProvider re-initialized.`);
442
-
443
- Logger.log(`[${onboardingId}] Successfully completed full onboarding for feed: ${config.name}`);
444
-
445
- // Track successful onboarding
446
- Logger.trackEvent(EventType.FEED_ONBOARD, {
447
- status: EventStatus.SUCCESS,
448
- feedName: config.name,
449
- onboardingId: onboardingId,
450
- prUrl: prInfo.url,
451
- feedConfiguration: config
452
- });
453
- } catch (reinitError) {
454
- Logger.warn(`[${onboardingId}] Failed to re-initialize providers after PR creation for feed ${config.name}:`);
455
- Logger.warn(`Skipping re-initialization of providers due to error: ${reinitError}`,);
456
- }
457
-
458
- } catch (error) {
459
- Logger.error(`[${onboardingId}] Full feed onboarding process failed:`, error);
460
- const errorMessage = error instanceof Error ? error.message : String(error);
461
-
462
- // Track onboarding failure
463
- Logger.trackEvent(EventType.FEED_ONBOARD, {
464
- status: EventStatus.FAILED,
465
- feedName: config.name,
466
- onboardingId: onboardingId,
467
- errorMessage,
468
- feedConfiguration: config
469
- });
470
-
471
- // Check if status is already FAILED (e.g., by _validateFeedConfiguration)
472
- // to avoid overwriting a more specific error message or step from validation.
473
- const currentStatus = await onboardStatusManager.getStatus(config.name, operationType);
474
- if (currentStatus?.status !== OnboardingProcessStatus.FAILED) {
475
- let stepName = 'Failed during full onboarding process';
476
- if (error instanceof Error && 'step' in error && typeof error.step === 'string') {
477
- stepName = `Failed at step: ${error.step}`;
478
- } else if (currentStatus?.steps && currentStatus.steps.length > 0) {
479
- // If not already failed by validation, use the last known good step before this error
480
- stepName = `Failed after step: ${currentStatus.steps[currentStatus.steps.length - 1].stepName}`;
481
- }
482
- await onboardStatusManager.recordStep(
483
- config.name,
484
- operationType,
485
- stepName,
486
- undefined, // serverName
487
- OnboardingProcessStatus.FAILED,
488
- errorMessage
489
- );
490
- } else {
491
- // If already FAILED, the error and step were likely recorded by _validateFeedConfiguration.
492
- // Log the current error context if it's different or provides more info.
493
- Logger.log(`[${onboardingId}] Process was already marked as FAILED. Additional context - Current error: ${errorMessage}. Initial error from status: ${currentStatus.errorMessage}`);
494
- }
495
- throw error; // Re-throw to ensure the promise from processFullOnboarding is rejected.
496
- }
497
- }
498
- }
499
-
500
- // Export singleton instance
501
- export const feedOnboardService = new FeedOnboardService();