@@ -13,6 +13,10 @@ import type {
1313 MaiBotConfigImportResult ,
1414 MaiBotDataImportResult ,
1515 MaiBotDataResetResult ,
16+ MaiBotInstalledPlugin ,
17+ MaiBotPluginListResult ,
18+ MaiBotPluginOperationRequest ,
19+ MaiBotPluginOperationResult ,
1620 ManagedPythonPackageName ,
1721 ModuleRuntimeVersions ,
1822 ModuleUpdateResult ,
@@ -40,6 +44,7 @@ import type {
4044} from "../../shared/contracts" ;
4145import { InitManager } from "../services/init-manager" ;
4246import { LogStore } from "../services/log-store" ;
47+ import { MaiBotPluginClient } from "../services/maibot-plugin-client" ;
4348import { ModuleUpdater } from "../services/module-updater" ;
4449import { PythonDependencyManager } from "../services/python-dependency-manager" ;
4550import { ServiceManager } from "../services/service-manager" ;
@@ -377,6 +382,11 @@ export function registerAppIpc({
377382 } ) ;
378383 } ;
379384
385+ const maibotPluginClient = new MaiBotPluginClient ( {
386+ maibotRoot : join ( paths . modulesRoot , "MaiBot" ) ,
387+ gitPath : initManager . getGitPath ( ) ,
388+ } ) ;
389+
380390 serviceManager . on ( "snapshot" , ( services : ServiceDescriptor [ ] ) => {
381391 const window = getMainWindow ( ) ;
382392 window ?. webContents . send ( "services:snapshot" , services ) ;
@@ -581,6 +591,55 @@ export function registerAppIpc({
581591 } ,
582592 ) ;
583593
594+ ipcMain . handle ( "plugins:listMarket" , async ( ) : Promise < MaiBotPluginListResult > => {
595+ return maibotPluginClient . listMarket ( ) ;
596+ } ) ;
597+
598+ ipcMain . handle ( "plugins:listInstalled" , async ( ) : Promise < MaiBotInstalledPlugin [ ] > => {
599+ return maibotPluginClient . listInstalled ( ) ;
600+ } ) ;
601+
602+ ipcMain . handle (
603+ "plugins:install" ,
604+ async ( _event , request : MaiBotPluginOperationRequest ) : Promise < MaiBotPluginOperationResult > => {
605+ if ( ! request . pluginId || ! request . repositoryUrl ) {
606+ throw new Error ( "Plugin id and repository url are required." ) ;
607+ }
608+ const result = await maibotPluginClient . install ( request . pluginId , request . repositoryUrl , request . branch ) ;
609+ logStore . append ( "desktop" , "system" , `MaiBot plugin installed: ${ request . pluginId } ` ) ;
610+ return result ;
611+ } ,
612+ ) ;
613+
614+ ipcMain . handle (
615+ "plugins:update" ,
616+ async ( _event , request : MaiBotPluginOperationRequest ) : Promise < MaiBotPluginOperationResult > => {
617+ if ( ! request . pluginId || ! request . repositoryUrl ) {
618+ throw new Error ( "Plugin id and repository url are required." ) ;
619+ }
620+ const result = await maibotPluginClient . update (
621+ request . pluginId ,
622+ request . repositoryUrl ,
623+ request . branch ,
624+ request . latestVersion ,
625+ ) ;
626+ logStore . append ( "desktop" , "system" , `MaiBot plugin updated: ${ request . pluginId } ` ) ;
627+ return result ;
628+ } ,
629+ ) ;
630+
631+ ipcMain . handle (
632+ "plugins:uninstall" ,
633+ async ( _event , pluginId : string ) : Promise < MaiBotPluginOperationResult > => {
634+ if ( ! pluginId ) {
635+ throw new Error ( "Plugin id is required." ) ;
636+ }
637+ const result = await maibotPluginClient . uninstall ( pluginId ) ;
638+ logStore . append ( "desktop" , "system" , `MaiBot plugin uninstalled: ${ pluginId } ` ) ;
639+ return result ;
640+ } ,
641+ ) ;
642+
584643 ipcMain . handle ( "pythonDeps:getState" , ( ) : PythonOverridesState => {
585644 return pythonDependencyManager . getState ( ) ;
586645 } ) ;
0 commit comments