MCPcopy Create free account
hub / github.com/Noumena-Network/code / loadInstalledPluginsV2

Function loadInstalledPluginsV2

src/utils/plugins/installedPluginsManager.ts:317–368  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

315 * @returns V2 format data with array-per-plugin structure
316 */
317export function loadInstalledPluginsV2(): InstalledPluginsFileV2 {
318 migrateLegacyOfficialMarketplaceState()
319
320 // Return cached V2 data if available
321 if (installedPluginsCacheV2 !== null) {
322 return installedPluginsCacheV2
323 }
324
325 const filePath = getInstalledPluginsFilePath()
326
327 try {
328 const rawData = readInstalledPluginsFileRaw()
329
330 if (rawData) {
331 if (rawData.version === 2) {
332 // V2 format - validate and return
333 const validated = InstalledPluginsFileSchemaV2().parse(rawData.data)
334 installedPluginsCacheV2 = validated
335 logForDebugging(
336 `Loaded ${Object.keys(validated.plugins).length} installed plugins from ${filePath}`,
337 )
338 return validated
339 }
340
341 // V1 format - convert to V2
342 const v1Validated = InstalledPluginsFileSchemaV1().parse(rawData.data)
343 const v2Data = migrateV1ToV2(v1Validated)
344 installedPluginsCacheV2 = v2Data
345 logForDebugging(
346 `Loaded and converted ${Object.keys(v1Validated.plugins).length} plugins from V1 format`,
347 )
348 return v2Data
349 }
350
351 // File doesn't exist - return empty V2
352 logForDebugging(
353 `installed_plugins.json doesn't exist, returning empty V2 object`,
354 )
355 installedPluginsCacheV2 = { version: 2, plugins: {} }
356 return installedPluginsCacheV2
357 } catch (error) {
358 const errorMsg = errorMessage(error)
359 logForDebugging(
360 `Failed to load installed_plugins.json: ${errorMsg}. Starting with empty state.`,
361 { level: 'error' },
362 )
363 logError(toError(error))
364
365 installedPluginsCacheV2 = { version: 2, plugins: {} }
366 return installedPluginsCacheV2
367 }
368}
369
370/**
371 * Save installed plugins in V2 format to installed_plugins.json.

Callers 14

findUnmatchedFunction · 0.85
isPluginInstalledFunction · 0.85
handleSingleOperationFunction · 0.85
callFunction · 0.85
pluginListHandlerFunction · 0.85
resolveDelistedPluginIdFunction · 0.85

Calls 9

migrateV1ToV2Function · 0.85
keysMethod · 0.80
logForDebuggingFunction · 0.50
errorMessageFunction · 0.50
logErrorFunction · 0.50
toErrorFunction · 0.50

Tested by

no test coverage detected