imcp 0.1.4 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/build.yml +28 -0
- package/README.md +21 -4
- package/dist/cli/commands/start.d.ts +2 -0
- package/dist/cli/commands/start.js +32 -0
- package/dist/cli/commands/sync.d.ts +2 -0
- package/dist/cli/commands/sync.js +17 -0
- package/dist/cli/index.js +0 -0
- package/dist/core/ConfigurationLoader.d.ts +32 -0
- package/dist/core/ConfigurationLoader.js +236 -0
- package/dist/core/ConfigurationProvider.d.ts +35 -0
- package/dist/core/ConfigurationProvider.js +375 -0
- package/dist/core/InstallationService.d.ts +50 -0
- package/dist/core/InstallationService.js +350 -0
- package/dist/core/MCPManager.d.ts +28 -0
- package/dist/core/MCPManager.js +188 -0
- package/dist/core/RequirementService.d.ts +40 -0
- package/dist/core/RequirementService.js +110 -0
- package/dist/core/ServerSchemaLoader.d.ts +11 -0
- package/dist/core/ServerSchemaLoader.js +43 -0
- package/dist/core/ServerSchemaProvider.d.ts +17 -0
- package/dist/core/ServerSchemaProvider.js +120 -0
- package/dist/core/constants.d.ts +47 -0
- package/dist/core/constants.js +94 -0
- package/dist/core/installers/BaseInstaller.d.ts +74 -0
- package/dist/core/installers/BaseInstaller.js +253 -0
- package/dist/core/installers/ClientInstaller.d.ts +23 -0
- package/dist/core/installers/ClientInstaller.js +564 -0
- package/dist/core/installers/CommandInstaller.d.ts +37 -0
- package/dist/core/installers/CommandInstaller.js +173 -0
- package/dist/core/installers/GeneralInstaller.d.ts +33 -0
- package/dist/core/installers/GeneralInstaller.js +85 -0
- package/dist/core/installers/InstallerFactory.d.ts +54 -0
- package/dist/core/installers/InstallerFactory.js +97 -0
- package/dist/core/installers/NpmInstaller.d.ts +26 -0
- package/dist/core/installers/NpmInstaller.js +127 -0
- package/dist/core/installers/PipInstaller.d.ts +28 -0
- package/dist/core/installers/PipInstaller.js +127 -0
- package/dist/core/installers/RequirementInstaller.d.ts +33 -0
- package/dist/core/installers/RequirementInstaller.js +3 -0
- package/dist/core/types.d.ts +166 -0
- package/dist/core/types.js +16 -0
- package/dist/services/InstallRequestValidator.d.ts +21 -0
- package/dist/services/InstallRequestValidator.js +99 -0
- package/dist/web/public/index.html +1 -1
- package/dist/web/public/js/modal/installHandler.js +227 -0
- package/dist/web/public/js/modal/loadingUI.js +74 -0
- package/dist/web/public/js/modal/messageQueue.js +101 -45
- package/dist/web/public/js/modal/modalUI.js +214 -0
- package/dist/web/public/js/modal/version.js +20 -0
- package/dist/web/public/onboard.html +4 -4
- package/package.json +1 -1
- package/src/web/public/index.html +1 -1
- package/src/web/public/onboard.html +4 -4
- package/wiki/Installation.md +3 -0
- package/wiki/Publish.md +3 -0
- package/dist/core/onboard/InstallOperationManager.d.ts +0 -23
- package/dist/core/onboard/InstallOperationManager.js +0 -144
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { showLoadingModal, appendLoadingMessage } from './loadingUI.js';
|
|
2
|
+
import { compareVersions } from './version.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Handle bulk client installations
|
|
6
|
+
* @param {string} categoryName Category name
|
|
7
|
+
* @param {string} serverName Server name
|
|
8
|
+
* @param {string[]} targets Target clients
|
|
9
|
+
* @param {Object} options Installation options
|
|
10
|
+
*/
|
|
11
|
+
export async function handleInstallation(categoryName, serverName, targets, options = {}) {
|
|
12
|
+
const { envVars = {}, installingMessage = "Starting installation...", serverData = null } = options;
|
|
13
|
+
|
|
14
|
+
hideInstallModal();
|
|
15
|
+
initializeInstallation(installingMessage, serverData, serverName, targets);
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
await executeInstallation(categoryName, serverName, targets, options);
|
|
19
|
+
} catch (error) {
|
|
20
|
+
handleInstallationError(error);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Handle uninstallation of tools
|
|
26
|
+
* @param {string} categoryName Category name
|
|
27
|
+
* @param {Object|Array} serverList Servers to uninstall
|
|
28
|
+
* @param {string[]} targets Target clients
|
|
29
|
+
*/
|
|
30
|
+
export async function handleUninstallation(categoryName, serverList, targets) {
|
|
31
|
+
const selectedTargets = getSelectedTargets(targets);
|
|
32
|
+
validateTargets(selectedTargets);
|
|
33
|
+
|
|
34
|
+
try {
|
|
35
|
+
await executeUninstallation(categoryName, serverList, selectedTargets);
|
|
36
|
+
} catch (error) {
|
|
37
|
+
handleUninstallationError(error);
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Private helper functions
|
|
43
|
+
|
|
44
|
+
function hideInstallModal() {
|
|
45
|
+
const installModal = document.getElementById('installModal');
|
|
46
|
+
if (installModal) {
|
|
47
|
+
installModal.style.display = "none";
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function initializeInstallation(installingMessage, serverData, serverName, targets) {
|
|
52
|
+
showLoadingModal();
|
|
53
|
+
|
|
54
|
+
if (hasExistingStatus(serverData, serverName, targets)) {
|
|
55
|
+
const existingMessage = getExistingMessage(serverData, serverName, targets[0]);
|
|
56
|
+
if (existingMessage && existingMessage !== "Starting installation...") {
|
|
57
|
+
appendLoadingMessage(existingMessage);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
appendLoadingMessage(installingMessage);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function hasExistingStatus(serverData, serverName, targets) {
|
|
65
|
+
return serverData?.data?.installationStatus?.serversStatus &&
|
|
66
|
+
targets?.length > 0;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function getExistingMessage(serverData, serverName, target) {
|
|
70
|
+
const serverStatuses = serverData.data.installationStatus.serversStatus;
|
|
71
|
+
const serverStatus = serverStatuses[serverName] || { installedStatus: {} };
|
|
72
|
+
return serverStatus.installedStatus?.[target]?.message;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async function executeInstallation(categoryName, serverName, targets, options) {
|
|
76
|
+
appendLoadingMessage("Installing, please wait...");
|
|
77
|
+
|
|
78
|
+
const requestBody = buildInstallRequestBody(serverName, targets, options);
|
|
79
|
+
const response = await fetchWithErrorHandling(
|
|
80
|
+
`api/categories/${categoryName}/install`,
|
|
81
|
+
requestBody
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
if (response.success) {
|
|
85
|
+
startStatusPolling(categoryName, serverName, targets, options);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function buildInstallRequestBody(serverName, targets, options) {
|
|
90
|
+
const { envVars = {}, args = [], pythonEnv, requirements = [] } = options;
|
|
91
|
+
|
|
92
|
+
const serverOptions = {
|
|
93
|
+
targetClients: targets,
|
|
94
|
+
env: envVars,
|
|
95
|
+
args: args,
|
|
96
|
+
settings: pythonEnv ? { pythonEnv } : undefined
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
if (requirements.length > 0) {
|
|
100
|
+
serverOptions.requirements = requirements;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
serverList: {
|
|
105
|
+
[serverName]: serverOptions
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async function executeUninstallation(categoryName, serverList, selectedTargets) {
|
|
111
|
+
appendLoadingMessage('Starting uninstallation...');
|
|
112
|
+
|
|
113
|
+
const formattedServerList = formatServerList(serverList);
|
|
114
|
+
await fetchWithErrorHandling(
|
|
115
|
+
`api/categories/${categoryName}/uninstall`,
|
|
116
|
+
{
|
|
117
|
+
serverList: formattedServerList,
|
|
118
|
+
options: {
|
|
119
|
+
targets: selectedTargets,
|
|
120
|
+
removeData: true
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
appendLoadingMessage(`Successfully uninstalled from ${selectedTargets.join(', ')}`, true);
|
|
126
|
+
window.selectedClients = [];
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function formatServerList(serverList) {
|
|
130
|
+
if (Array.isArray(serverList)) {
|
|
131
|
+
return serverList.reduce((acc, server) => {
|
|
132
|
+
acc[server] = { removeData: true };
|
|
133
|
+
return acc;
|
|
134
|
+
}, {});
|
|
135
|
+
}
|
|
136
|
+
return serverList;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
async function fetchWithErrorHandling(endpoint, body) {
|
|
140
|
+
const response = await fetch(endpoint, {
|
|
141
|
+
method: 'POST',
|
|
142
|
+
headers: {
|
|
143
|
+
'Content-Type': 'application/json',
|
|
144
|
+
'Accept': 'application/json'
|
|
145
|
+
},
|
|
146
|
+
body: JSON.stringify(body)
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
if (!response.ok) {
|
|
150
|
+
const errorData = await response.text();
|
|
151
|
+
throw new Error(`Operation failed: ${errorData || response.statusText}`);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const result = await response.json();
|
|
155
|
+
if (!result.success) {
|
|
156
|
+
throw new Error(result.error || 'Operation failed');
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return result;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function handleInstallationError(error) {
|
|
163
|
+
console.error('[LoadingModal] Error:', error);
|
|
164
|
+
appendLoadingMessage(`<span style="color:red;">Error: ${error.message}</span>`);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function handleUninstallationError(error) {
|
|
168
|
+
console.error('Error uninstalling tools:', error);
|
|
169
|
+
appendLoadingMessage(`Error: ${error.message}`, true);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function getSelectedTargets(targets) {
|
|
173
|
+
return window.selectedClients || (Array.isArray(targets) ? targets : [targets]);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function validateTargets(selectedTargets) {
|
|
177
|
+
if (!selectedTargets || selectedTargets.length === 0) {
|
|
178
|
+
throw new Error('Please select at least one client to uninstall.');
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// Status polling functionality
|
|
183
|
+
async function startStatusPolling(categoryName, serverName, targets, options) {
|
|
184
|
+
const { requirements = [] } = options;
|
|
185
|
+
let lastMessages = {};
|
|
186
|
+
let lastRequirementMessages = {};
|
|
187
|
+
let lastRequirementErrorMessages = {};
|
|
188
|
+
let completionMessageSent = false;
|
|
189
|
+
|
|
190
|
+
const startTime = Date.now();
|
|
191
|
+
const maxTimeout = 10 * 60 * 1000; // 10 minutes
|
|
192
|
+
|
|
193
|
+
while (Date.now() - startTime < maxTimeout) {
|
|
194
|
+
try {
|
|
195
|
+
const status = await pollStatus(categoryName, serverName, targets, requirements);
|
|
196
|
+
|
|
197
|
+
if (status.isComplete) {
|
|
198
|
+
sendCompletionMessage(status, targets);
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
updateMessages(status, lastMessages, lastRequirementMessages, lastRequirementErrorMessages);
|
|
203
|
+
} catch (error) {
|
|
204
|
+
console.error('[LoadingModal] Error polling status:', error);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
handlePollingTimeout(completionMessageSent);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
async function pollStatus(categoryName, serverName, targets, requirements) {
|
|
214
|
+
const response = await fetch(`api/categories/${categoryName}`);
|
|
215
|
+
if (!response.ok) {
|
|
216
|
+
throw new Error('Failed to fetch status');
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const data = await response.json();
|
|
220
|
+
return processStatusData(data, serverName, targets, requirements);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function processStatusData(data, serverName, targets, requirements) {
|
|
224
|
+
// Implementation details for processing status data
|
|
225
|
+
// This would include checking requirements status and target status
|
|
226
|
+
// Returns an object with status information
|
|
227
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { queueMessage } from './messageQueue.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Display the installation loading modal and prepare it for messages
|
|
5
|
+
* @param {string} operation Operation name to display
|
|
6
|
+
*/
|
|
7
|
+
export function showLoadingModal(operation = 'Installing') {
|
|
8
|
+
const elements = getLoadingElements();
|
|
9
|
+
if (!elements) {
|
|
10
|
+
console.error('[LoadingModal] Required elements not found');
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
elements.modal.style.display = 'block';
|
|
15
|
+
elements.messageContainer.innerHTML = '';
|
|
16
|
+
elements.title.textContent = `${operation}...`;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Hide the installation loading modal
|
|
21
|
+
*/
|
|
22
|
+
export function hideLoadingModal() {
|
|
23
|
+
const modal = document.getElementById('installLoadingModal');
|
|
24
|
+
if (!modal) {
|
|
25
|
+
console.error('[LoadingModal] Loading modal not found');
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
modal.style.display = 'none';
|
|
30
|
+
refreshPageWithCategory();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Append a message to the loading modal
|
|
35
|
+
* @param {string} message Message to display
|
|
36
|
+
* @param {boolean} isCompletion Whether this is a completion message
|
|
37
|
+
*/
|
|
38
|
+
export function appendLoadingMessage(message, isCompletion = false) {
|
|
39
|
+
queueMessage(message, isCompletion);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Get the loading modal elements
|
|
44
|
+
* @private
|
|
45
|
+
* @returns {Object|null} Object containing modal elements or null if not found
|
|
46
|
+
*/
|
|
47
|
+
function getLoadingElements() {
|
|
48
|
+
const modal = document.getElementById('installLoadingModal');
|
|
49
|
+
const messageContainer = document.getElementById('installLoadingMessage');
|
|
50
|
+
const title = document.querySelector('.loading-title');
|
|
51
|
+
|
|
52
|
+
if (!modal || !messageContainer || !title) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return { modal, messageContainer, title };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Refresh the page maintaining category selection
|
|
61
|
+
* @private
|
|
62
|
+
*/
|
|
63
|
+
function refreshPageWithCategory() {
|
|
64
|
+
const lastSelected = localStorage.getItem('lastSelectedCategory');
|
|
65
|
+
|
|
66
|
+
setTimeout(() => {
|
|
67
|
+
if (lastSelected) {
|
|
68
|
+
window.location.href = window.location.pathname +
|
|
69
|
+
'?category=' + encodeURIComponent(lastSelected);
|
|
70
|
+
} else {
|
|
71
|
+
location.reload();
|
|
72
|
+
}
|
|
73
|
+
}, 100);
|
|
74
|
+
}
|
|
@@ -1,56 +1,112 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
// for overall status and step details, this queueing mechanism for individual
|
|
4
|
-
// step messages is no longer the primary way messages are displayed.
|
|
5
|
-
// The loadingModal.js now has `updateOverallInstallStatus` and `addInstallationStep`.
|
|
6
|
-
|
|
7
|
-
// The `updateCompletionUI` function might still be relevant if we want to
|
|
8
|
-
// change the overall modal's appearance (e.g., title, main icon) upon final completion,
|
|
9
|
-
// separate from the step-by-step updates.
|
|
1
|
+
/** @type {boolean} Flag indicating if a message is currently being appended */
|
|
2
|
+
let isAppending = false;
|
|
10
3
|
|
|
11
4
|
/** @type {boolean} Flag indicating if completion UI update is pending */
|
|
12
|
-
let completionPending = false;
|
|
5
|
+
let completionPending = false;
|
|
13
6
|
|
|
14
7
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* and a small delay).
|
|
18
|
-
* @param {'completed' | 'failed'} finalState
|
|
8
|
+
* Message queue for delayed loading modal updates.
|
|
9
|
+
* @type {Array<{msg: string, isCompletion: boolean}>}
|
|
19
10
|
*/
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
11
|
+
let messageQueue = [];
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Process messages in the queue with a delay between each message.
|
|
15
|
+
* When the queue is empty and completion is pending, triggers the completion UI.
|
|
16
|
+
* @private
|
|
17
|
+
*/
|
|
18
|
+
function processMessageQueue() {
|
|
19
|
+
if (isAppending || messageQueue.length === 0) {
|
|
20
|
+
// Only update completion UI if all messages have been displayed
|
|
21
|
+
if (messageQueue.length === 0 && completionPending) {
|
|
22
|
+
// Add small delay before showing completion to ensure last message is visible
|
|
23
|
+
setTimeout(() => {
|
|
24
|
+
updateCompletionUI();
|
|
25
|
+
completionPending = false;
|
|
26
|
+
}, 500);
|
|
27
|
+
}
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
isAppending = true;
|
|
32
|
+
const { msg, isCompletion } = messageQueue.shift();
|
|
33
|
+
|
|
34
|
+
if (isCompletion) {
|
|
35
|
+
completionPending = true;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
appendInstallLoadingMessage(msg);
|
|
39
|
+
|
|
40
|
+
setTimeout(() => {
|
|
41
|
+
isAppending = false;
|
|
42
|
+
processMessageQueue();
|
|
43
|
+
}, 1000);
|
|
35
44
|
}
|
|
36
45
|
|
|
46
|
+
/**
|
|
47
|
+
* Queue a message to be displayed with a delay.
|
|
48
|
+
* Messages are displayed sequentially with a 1-second delay between each.
|
|
49
|
+
* @param {string} msg The message to display
|
|
50
|
+
* @param {boolean} [isCompletion=false] If true, triggers completion UI after message display
|
|
51
|
+
*/
|
|
52
|
+
export function delayedAppendInstallLoadingMessage(msg, isCompletion = false) {
|
|
53
|
+
messageQueue.push({ msg, isCompletion });
|
|
54
|
+
processMessageQueue();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function updateCompletionUI() {
|
|
58
|
+
const loadingTitle = document.querySelector('.loading-title');
|
|
59
|
+
const loadingIcon = document.querySelector('.loading-icon');
|
|
60
|
+
|
|
61
|
+
if (loadingTitle) {
|
|
62
|
+
loadingTitle.textContent = 'Completed';
|
|
63
|
+
loadingTitle.classList.add('completed');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (loadingIcon) {
|
|
67
|
+
loadingIcon.innerHTML = `
|
|
68
|
+
<svg width="48" height="48" viewBox="0 0 48 48" fill="none">
|
|
69
|
+
<circle cx="24" cy="24" r="20" stroke="#059669" stroke-width="4"/>
|
|
70
|
+
<path d="M16 24l6 6 12-12" stroke="#059669" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/>
|
|
71
|
+
</svg>
|
|
72
|
+
`;
|
|
73
|
+
loadingIcon.classList.add('completed');
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Internal function to append a message to the loading modal with formatting.
|
|
79
|
+
* @private
|
|
80
|
+
* @param {string} message - The message to append
|
|
81
|
+
*/
|
|
82
|
+
function appendInstallLoadingMessage(message) {
|
|
83
|
+
const loadingMsg = document.getElementById('installLoadingMessage');
|
|
84
|
+
if (loadingMsg) {
|
|
85
|
+
// Split message on newlines
|
|
86
|
+
const lines = message.split('\n');
|
|
87
|
+
|
|
88
|
+
lines.forEach(line => {
|
|
89
|
+
// Check if line contains an error
|
|
90
|
+
const isError = line.toLowerCase().includes('error') ||
|
|
91
|
+
line.toLowerCase().includes('failed') ||
|
|
92
|
+
line.toLowerCase().includes('timeout');
|
|
37
93
|
|
|
38
|
-
|
|
39
|
-
// // This function's original content might be merged into updateOverallInstallStatus
|
|
40
|
-
// // or called if a distinct "modal completed" visual state is needed beyond the text/icon.
|
|
41
|
-
// const loadingTitle = document.querySelector('.loading-title'); // This element might not exist with new structure
|
|
42
|
-
// const loadingIcon = document.querySelector('.loading-icon'); // This element might not exist
|
|
94
|
+
const formattedMessage = line;
|
|
43
95
|
|
|
44
|
-
//
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
// }
|
|
96
|
+
// Create message container
|
|
97
|
+
const messageDiv = document.createElement('div');
|
|
98
|
+
messageDiv.className = 'message-line';
|
|
48
99
|
|
|
49
|
-
//
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
100
|
+
// Apply yellow color for error messages
|
|
101
|
+
if (isError) {
|
|
102
|
+
messageDiv.style.color = '#f59e0b';
|
|
103
|
+
}
|
|
104
|
+
messageDiv.innerHTML = formattedMessage;
|
|
53
105
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
106
|
+
loadingMsg.appendChild(messageDiv);
|
|
107
|
+
loadingMsg.scrollTop = loadingMsg.scrollHeight;
|
|
108
|
+
});
|
|
109
|
+
} else {
|
|
110
|
+
console.error('[LoadingModal] Element not found: installLoadingMessage');
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { showConfirm } from '../notifications.js';
|
|
2
|
+
import { handleInstallation, handleUninstallation } from './installHandler.js';
|
|
3
|
+
import { showLoadingModal } from './loadingUI.js';
|
|
4
|
+
import { compareVersions } from './version.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Show installation modal for MCP tools
|
|
8
|
+
* @param {string} categoryName Category name
|
|
9
|
+
* @param {string} serverName Server name
|
|
10
|
+
*/
|
|
11
|
+
export async function showInstallModal(categoryName, serverName) {
|
|
12
|
+
console.log("Showing install modal for:", serverName);
|
|
13
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
14
|
+
|
|
15
|
+
const elements = getModalElements();
|
|
16
|
+
if (!elements) return;
|
|
17
|
+
|
|
18
|
+
initializeModal(elements, serverName);
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
const { targetData, serverData } = await fetchModalData(categoryName);
|
|
22
|
+
const mcpServer = findMcpServer(serverData, serverName);
|
|
23
|
+
|
|
24
|
+
renderModalContent(elements, {
|
|
25
|
+
targetData,
|
|
26
|
+
serverData,
|
|
27
|
+
mcpServer,
|
|
28
|
+
categoryName,
|
|
29
|
+
serverName
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
setupFormHandler(elements, categoryName, serverName, serverData);
|
|
33
|
+
elements.modal.style.display = "block";
|
|
34
|
+
} catch (error) {
|
|
35
|
+
handleModalError(error, elements.targetDiv);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Close modal and refresh with selected category
|
|
41
|
+
*/
|
|
42
|
+
export function closeModal() {
|
|
43
|
+
const modal = document.getElementById('installModal');
|
|
44
|
+
if (modal) {
|
|
45
|
+
modal.style.display = "none";
|
|
46
|
+
refreshWithCategory();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Setup click outside modal handler
|
|
52
|
+
*/
|
|
53
|
+
export function setupModalOutsideClick() {
|
|
54
|
+
window.onclick = function (event) {
|
|
55
|
+
const modal = document.getElementById('installModal');
|
|
56
|
+
if (event.target === modal) {
|
|
57
|
+
closeModal();
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Private helper functions
|
|
63
|
+
|
|
64
|
+
function getModalElements() {
|
|
65
|
+
const modal = document.getElementById('installModal');
|
|
66
|
+
if (!modal) {
|
|
67
|
+
console.error('Modal container not found');
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const elements = {
|
|
72
|
+
modal,
|
|
73
|
+
title: modal.querySelector('#modalTitle'),
|
|
74
|
+
envInputs: modal.querySelector('#modalEnvInputs'),
|
|
75
|
+
targetDiv: modal.querySelector('#modalTargets'),
|
|
76
|
+
requirements: modal.querySelector('#modalRequirements'),
|
|
77
|
+
arguments: modal.querySelector('#modalArguments')
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
if (!Object.values(elements).every(Boolean)) {
|
|
81
|
+
console.error('Required modal elements not found');
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return elements;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function initializeModal(elements, serverName) {
|
|
89
|
+
window.selectedClients = [];
|
|
90
|
+
elements.title.textContent = `Install ${serverName}`;
|
|
91
|
+
clearModalSections(elements);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function clearModalSections(elements) {
|
|
95
|
+
['envInputs', 'targetDiv', 'requirements', 'arguments'].forEach(section => {
|
|
96
|
+
elements[section].innerHTML = '';
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async function fetchModalData(categoryName) {
|
|
101
|
+
const [targetResponse, serverResponse] = await Promise.all([
|
|
102
|
+
fetch('/api/targets'),
|
|
103
|
+
fetch(`/api/categories/${categoryName}`)
|
|
104
|
+
]);
|
|
105
|
+
|
|
106
|
+
if (!targetResponse.ok || !serverResponse.ok) {
|
|
107
|
+
throw new Error('Failed to fetch required data');
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const [targetData, serverData] = await Promise.all([
|
|
111
|
+
targetResponse.json(),
|
|
112
|
+
serverResponse.json()
|
|
113
|
+
]);
|
|
114
|
+
|
|
115
|
+
if (!targetData.success || !serverData.success) {
|
|
116
|
+
throw new Error('Invalid data received');
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return { targetData, serverData };
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function findMcpServer(serverData, serverName) {
|
|
123
|
+
const mcpServer = serverData.data.feedConfiguration.mcpServers
|
|
124
|
+
.find(server => server.name === serverName);
|
|
125
|
+
|
|
126
|
+
if (!mcpServer) {
|
|
127
|
+
throw new Error('Server configuration not found');
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return mcpServer;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function renderModalContent(elements, data) {
|
|
134
|
+
const { targetData, serverData, mcpServer, categoryName, serverName } = data;
|
|
135
|
+
const installationStatus = serverData.data.installationStatus || {};
|
|
136
|
+
const serverStatuses = installationStatus.serversStatus || {};
|
|
137
|
+
const serverStatus = serverStatuses[serverName] || { installedStatus: {} };
|
|
138
|
+
|
|
139
|
+
renderClientSection(elements.targetDiv, targetData.data, serverStatus, serverName, categoryName);
|
|
140
|
+
renderEnvironmentSection(elements.envInputs, mcpServer, targetData.clientMcpSettings, serverName);
|
|
141
|
+
renderArgumentsSection(elements.arguments, mcpServer);
|
|
142
|
+
renderRequirementsSection(elements.requirements, mcpServer, serverData, categoryName, serverName);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function setupFormHandler(elements, categoryName, serverName, serverData) {
|
|
146
|
+
const form = document.getElementById('installForm');
|
|
147
|
+
form.onsubmit = (e) => handleFormSubmit(e, {
|
|
148
|
+
elements,
|
|
149
|
+
categoryName,
|
|
150
|
+
serverName,
|
|
151
|
+
serverData
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function handleFormSubmit(event, options) {
|
|
156
|
+
event.preventDefault();
|
|
157
|
+
const { elements, categoryName, serverName, serverData } = options;
|
|
158
|
+
|
|
159
|
+
const formData = collectFormData(elements);
|
|
160
|
+
if (!validateFormData(formData)) return;
|
|
161
|
+
|
|
162
|
+
const installOptions = buildInstallOptions(formData, serverData, serverName);
|
|
163
|
+
handleInstallation(categoryName, serverName, formData.targets, installOptions);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function collectFormData(elements) {
|
|
167
|
+
return {
|
|
168
|
+
envVars: getEnvironmentVariables(elements.envInputs),
|
|
169
|
+
args: getArguments(elements.arguments),
|
|
170
|
+
pythonEnv: getPythonEnvironment(),
|
|
171
|
+
targets: getSelectedTargets(),
|
|
172
|
+
requirements: getSelectedRequirements()
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function validateFormData(formData) {
|
|
177
|
+
const { targets, requirements } = formData;
|
|
178
|
+
if (targets.length === 0 && requirements.length === 0) {
|
|
179
|
+
showError('Please select at least one client or requirement to update.');
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
return true;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function handleModalError(error, targetDiv) {
|
|
186
|
+
console.error("Error loading data:", error);
|
|
187
|
+
targetDiv.innerHTML = `<p class="text-red-500">Error: ${error.message}</p>`;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function refreshWithCategory() {
|
|
191
|
+
const lastSelected = localStorage.getItem('lastSelectedCategory');
|
|
192
|
+
setTimeout(() => {
|
|
193
|
+
if (lastSelected) {
|
|
194
|
+
window.location.href = window.location.pathname + '?category=' + encodeURIComponent(lastSelected);
|
|
195
|
+
} else {
|
|
196
|
+
location.reload();
|
|
197
|
+
}
|
|
198
|
+
}, 100);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// Add CSS styles for the toggle switch
|
|
202
|
+
const styleElement = document.createElement('style');
|
|
203
|
+
styleElement.textContent = `
|
|
204
|
+
.toggle-bg.bg-blue-500 {
|
|
205
|
+
background-color: #3b82f6;
|
|
206
|
+
}
|
|
207
|
+
.toggle-bg {
|
|
208
|
+
transition: background-color 0.3s;
|
|
209
|
+
}
|
|
210
|
+
.toggle-bg div {
|
|
211
|
+
transition: transform 0.3s;
|
|
212
|
+
}
|
|
213
|
+
`;
|
|
214
|
+
document.head.appendChild(styleElement);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple version comparison function
|
|
3
|
+
* @param {string} v1 First version
|
|
4
|
+
* @param {string} v2 Second version
|
|
5
|
+
* @returns {number} 1 if v1 > v2, -1 if v1 < v2, 0 if equal
|
|
6
|
+
*/
|
|
7
|
+
export function compareVersions(v1, v2) {
|
|
8
|
+
const v1Parts = v1.split('.').map(Number);
|
|
9
|
+
const v2Parts = v2.split('.').map(Number);
|
|
10
|
+
|
|
11
|
+
for (let i = 0; i < Math.max(v1Parts.length, v2Parts.length); i++) {
|
|
12
|
+
const v1Part = v1Parts[i] || 0;
|
|
13
|
+
const v2Part = v2Parts[i] || 0;
|
|
14
|
+
|
|
15
|
+
if (v1Part > v2Part) return 1;
|
|
16
|
+
if (v1Part < v2Part) return -1;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return 0;
|
|
20
|
+
}
|