TidGi-Desktop/src/services/libs/bindServiceAndProxy.ts
linonetwo 541f351428 feat: integrate memeloop runtime into TidGi-Desktop (#desktop-integrate-memeloop)
- Rename src/services/externalAPI/ → src/services/providerRegistry/
- Service identifier: ExternalAPI → ProviderRegistry
- Backward compat maintained: renderer still accesses via window.service.externalAPI
- IPC channel name unchanged for wire compatibility
- Enhanced interface with generateFromAI(), generateSpeech(), generateImage() etc.
- Added BehaviorSubject observables (defaultConfig$, providers$)
- Added auto-fill logic for default models, API call logging, retry utility

- New memeloopWorker.ts: runs MemeLoopRuntime in Node.js worker thread
- New memeloopWorkerFactory.ts: Vite ?nodeWorker bundling
- New terminal/sessionManager.ts: interactive shell session management for agent tools
- AgentInstanceService: added memeloopTaskAgentWorkerHandler framework
  - Worker conversation lifecycle: ensure/bind/cleanup/cancel
  - Bidirectional sync: worker updates → main DB → renderer
  - ask-question and tool-approval event routing
- tools/zxScript.ts: added terminal-execute/follow/respond/cancel/list tools

- Import Theme from @memeloop/prompt-editor/web
- Merge base templates/widgets with TidGi custom overrides
- Re-export ConditionalFieldConfig from shared package

- Fix race condition in NewTabContent.tsx: await closeTab() before addTab()
  to prevent concurrent zustand state updates that lose activeTabId
- Same fix applied in AgentsPlugin.tsx onSelect handler
- ChatTabContent: keep input enabled during agent fetch to avoid MUI disabled
  rendering differences that break E2E selectors
- Revert InputContainer.tsx slotProps→inputProps regression (keep MUI v6 API)

- Added: memeloop, memeloop-node, @memeloop/protocol, @memeloop/prompt-editor (linked)

- Unit tests: 59 files, 499 tests passed
- E2E @agent: 8 scenarios passed
- E2E @agentTool: 3 scenarios passed
- E2E @newAgent + @editAgentDefinition: 2 scenarios passed"
2026-04-04 02:15:31 +08:00

160 lines
12 KiB
TypeScript

/**
* Don't forget to edit src/preload/common/services.ts to export service to renderer process
*/
import { registerProxy } from 'electron-ipc-cat/server';
import { container } from '@services/container';
import serviceIdentifier from '@services/serviceIdentifier';
import { AgentBrowserService } from '@services/agentBrowser';
import { AgentDefinitionService } from '@services/agentDefinition';
import { AgentInstanceService } from '@services/agentInstance';
import { Authentication } from '@services/auth';
import { ContextService } from '@services/context';
import { DatabaseService } from '@services/database';
import { DeepLinkService } from '@services/deepLink';
import { Git } from '@services/git';
import { GitServerService } from '@services/gitServer';
import { MenuService } from '@services/menu';
import { NativeService } from '@services/native';
import { NotificationService } from '@services/notifications';
import { Preference } from '@services/preferences';
import { Sync } from '@services/sync';
import { SystemPreference } from '@services/systemPreferences';
import { ThemeService } from '@services/theme';
import { Updater } from '@services/updater';
import { View } from '@services/view';
import { Wiki } from '@services/wiki';
import { WikiEmbeddingService } from '@services/wikiEmbedding';
import { WikiGitWorkspace } from '@services/wikiGitWorkspace';
import { Window } from '@services/windows';
import { Workspace } from '@services/workspaces';
import { WorkspaceView } from '@services/workspacesView';
import { AgentBrowserServiceIPCDescriptor, type IAgentBrowserService } from '@services/agentBrowser/interface';
import { AgentDefinitionServiceIPCDescriptor, type IAgentDefinitionService } from '@services/agentDefinition/interface';
import { AgentInstanceServiceIPCDescriptor, type IAgentInstanceService } from '@services/agentInstance/interface';
import type { IAuthenticationService } from '@services/auth/interface';
import { AuthenticationServiceIPCDescriptor } from '@services/auth/interface';
import type { IContextService } from '@services/context/interface';
import { ContextServiceIPCDescriptor } from '@services/context/interface';
import type { IDatabaseService } from '@services/database/interface';
import { DatabaseServiceIPCDescriptor } from '@services/database/interface';
import type { IDeepLinkService } from '@services/deepLink/interface';
import { DeepLinkServiceIPCDescriptor } from '@services/deepLink/interface';
import type { IGitService } from '@services/git/interface';
import { GitServiceIPCDescriptor } from '@services/git/interface';
import type { IGitServerService } from '@services/gitServer/interface';
import { GitServerServiceIPCDescriptor } from '@services/gitServer/interface';
import type { IMenuService } from '@services/menu/interface';
import { MenuServiceIPCDescriptor } from '@services/menu/interface';
import type { INativeService } from '@services/native/interface';
import { NativeServiceIPCDescriptor } from '@services/native/interface';
import type { INotificationService } from '@services/notifications/interface';
import { NotificationServiceIPCDescriptor } from '@services/notifications/interface';
import type { IPreferenceService } from '@services/preferences/interface';
import { PreferenceServiceIPCDescriptor } from '@services/preferences/interface';
import type { ISyncService } from '@services/sync/interface';
import { SyncServiceIPCDescriptor } from '@services/sync/interface';
import type { ISystemPreferenceService } from '@services/systemPreferences/interface';
import { SystemPreferenceServiceIPCDescriptor } from '@services/systemPreferences/interface';
import type { IThemeService } from '@services/theme/interface';
import { ThemeServiceIPCDescriptor } from '@services/theme/interface';
import type { IUpdaterService } from '@services/updater/interface';
import { UpdaterServiceIPCDescriptor } from '@services/updater/interface';
import type { IViewService } from '@services/view/interface';
import { ViewServiceIPCDescriptor } from '@services/view/interface';
import type { IWikiService } from '@services/wiki/interface';
import { WikiServiceIPCDescriptor } from '@services/wiki/interface';
import type { IWikiEmbeddingService } from '@services/wikiEmbedding/interface';
import { WikiEmbeddingServiceIPCDescriptor } from '@services/wikiEmbedding/interface';
import type { IWikiGitWorkspaceService } from '@services/wikiGitWorkspace/interface';
import { WikiGitWorkspaceServiceIPCDescriptor } from '@services/wikiGitWorkspace/interface';
import type { IWindowService } from '@services/windows/interface';
import { WindowServiceIPCDescriptor } from '@services/windows/interface';
import type { IWorkspaceService } from '@services/workspaces/interface';
import { WorkspaceServiceIPCDescriptor } from '@services/workspaces/interface';
import type { IWorkspaceViewService } from '@services/workspacesView/interface';
import { WorkspaceViewServiceIPCDescriptor } from '@services/workspacesView/interface';
import { ProviderRegistryService } from '../providerRegistry';
import { ProviderRegistryServiceIPCDescriptor, type IProviderRegistryService } from '../providerRegistry/interface';
export function bindServiceAndProxy(): void {
container.bind<IAgentBrowserService>(serviceIdentifier.AgentBrowser).to(AgentBrowserService).inSingletonScope();
container.bind<IAgentDefinitionService>(serviceIdentifier.AgentDefinition).to(AgentDefinitionService).inSingletonScope();
container.bind<IAgentInstanceService>(serviceIdentifier.AgentInstance).to(AgentInstanceService).inSingletonScope();
container.bind<IAuthenticationService>(serviceIdentifier.Authentication).to(Authentication).inSingletonScope();
container.bind<IContextService>(serviceIdentifier.Context).to(ContextService).inSingletonScope();
container.bind<IDatabaseService>(serviceIdentifier.Database).to(DatabaseService).inSingletonScope();
container.bind<IDeepLinkService>(serviceIdentifier.DeepLink).to(DeepLinkService).inSingletonScope();
container.bind<IProviderRegistryService>(serviceIdentifier.ProviderRegistry).to(ProviderRegistryService).inSingletonScope();
container.bind<IGitService>(serviceIdentifier.Git).to(Git).inSingletonScope();
container.bind<IGitServerService>(serviceIdentifier.GitServer).to(GitServerService).inSingletonScope();
container.bind<IMenuService>(serviceIdentifier.MenuService).to(MenuService).inSingletonScope();
container.bind<INativeService>(serviceIdentifier.NativeService).to(NativeService).inSingletonScope();
container.bind<INotificationService>(serviceIdentifier.NotificationService).to(NotificationService).inSingletonScope();
container.bind<IPreferenceService>(serviceIdentifier.Preference).to(Preference).inSingletonScope();
container.bind<ISyncService>(serviceIdentifier.Sync).to(Sync).inSingletonScope();
container.bind<ISystemPreferenceService>(serviceIdentifier.SystemPreference).to(SystemPreference).inSingletonScope();
container.bind<IThemeService>(serviceIdentifier.ThemeService).to(ThemeService).inSingletonScope();
container.bind<IUpdaterService>(serviceIdentifier.Updater).to(Updater).inSingletonScope();
container.bind<IViewService>(serviceIdentifier.View).to(View).inSingletonScope();
container.bind<IWikiEmbeddingService>(serviceIdentifier.WikiEmbedding).to(WikiEmbeddingService).inSingletonScope();
container.bind<IWikiGitWorkspaceService>(serviceIdentifier.WikiGitWorkspace).to(WikiGitWorkspace).inSingletonScope();
container.bind<IWikiService>(serviceIdentifier.Wiki).to(Wiki).inSingletonScope();
container.bind<IWindowService>(serviceIdentifier.Window).to(Window).inSingletonScope();
container.bind<IWorkspaceService>(serviceIdentifier.Workspace).to(Workspace).inSingletonScope();
container.bind<IWorkspaceViewService>(serviceIdentifier.WorkspaceView).to(WorkspaceView).inSingletonScope();
const agentBrowserService = container.get<IAgentBrowserService>(serviceIdentifier.AgentBrowser);
const agentDefinitionService = container.get<IAgentDefinitionService>(serviceIdentifier.AgentDefinition);
const agentInstanceService = container.get<IAgentInstanceService>(serviceIdentifier.AgentInstance);
const authService = container.get<IAuthenticationService>(serviceIdentifier.Authentication);
const contextService = container.get<IContextService>(serviceIdentifier.Context);
const databaseService = container.get<IDatabaseService>(serviceIdentifier.Database);
const deepLinkService = container.get<IDeepLinkService>(serviceIdentifier.DeepLink);
const providerRegistryService = container.get<IProviderRegistryService>(serviceIdentifier.ProviderRegistry);
const gitService = container.get<IGitService>(serviceIdentifier.Git);
const gitServerService = container.get<IGitServerService>(serviceIdentifier.GitServer);
const menuService = container.get<IMenuService>(serviceIdentifier.MenuService);
const nativeService = container.get<INativeService>(serviceIdentifier.NativeService);
const notificationService = container.get<INotificationService>(serviceIdentifier.NotificationService);
const preferenceService = container.get<IPreferenceService>(serviceIdentifier.Preference);
const syncService = container.get<ISyncService>(serviceIdentifier.Sync);
const systemPreferenceService = container.get<ISystemPreferenceService>(serviceIdentifier.SystemPreference);
const themeService = container.get<IThemeService>(serviceIdentifier.ThemeService);
const updaterService = container.get<IUpdaterService>(serviceIdentifier.Updater);
const viewService = container.get<IViewService>(serviceIdentifier.View);
const wikiEmbeddingService = container.get<IWikiEmbeddingService>(serviceIdentifier.WikiEmbedding);
const wikiGitWorkspaceService = container.get<IWikiGitWorkspaceService>(serviceIdentifier.WikiGitWorkspace);
const wikiService = container.get<IWikiService>(serviceIdentifier.Wiki);
const windowService = container.get<IWindowService>(serviceIdentifier.Window);
const workspaceService = container.get<IWorkspaceService>(serviceIdentifier.Workspace);
const workspaceViewService = container.get<IWorkspaceViewService>(serviceIdentifier.WorkspaceView);
registerProxy(agentBrowserService, AgentBrowserServiceIPCDescriptor);
registerProxy(agentDefinitionService, AgentDefinitionServiceIPCDescriptor);
registerProxy(agentInstanceService, AgentInstanceServiceIPCDescriptor);
registerProxy(authService, AuthenticationServiceIPCDescriptor);
registerProxy(contextService, ContextServiceIPCDescriptor);
registerProxy(databaseService, DatabaseServiceIPCDescriptor);
registerProxy(deepLinkService, DeepLinkServiceIPCDescriptor);
registerProxy(providerRegistryService, ProviderRegistryServiceIPCDescriptor);
registerProxy(gitService, GitServiceIPCDescriptor);
registerProxy(gitServerService, GitServerServiceIPCDescriptor);
registerProxy(menuService, MenuServiceIPCDescriptor);
registerProxy(nativeService, NativeServiceIPCDescriptor);
registerProxy(notificationService, NotificationServiceIPCDescriptor);
registerProxy(preferenceService, PreferenceServiceIPCDescriptor);
registerProxy(syncService, SyncServiceIPCDescriptor);
registerProxy(systemPreferenceService, SystemPreferenceServiceIPCDescriptor);
registerProxy(themeService, ThemeServiceIPCDescriptor);
registerProxy(updaterService, UpdaterServiceIPCDescriptor);
registerProxy(viewService, ViewServiceIPCDescriptor);
registerProxy(wikiEmbeddingService, WikiEmbeddingServiceIPCDescriptor);
registerProxy(wikiGitWorkspaceService, WikiGitWorkspaceServiceIPCDescriptor);
registerProxy(wikiService, WikiServiceIPCDescriptor);
registerProxy(windowService, WindowServiceIPCDescriptor);
registerProxy(workspaceService, WorkspaceServiceIPCDescriptor);
registerProxy(workspaceViewService, WorkspaceViewServiceIPCDescriptor);
}