Files
zn-ai/electron/gateway/manager.ts
duanshuwen b1dea9a5c2 feat: implement task management store with IPC integration
- Added a new task store in `src-react/stores/task.ts` to manage tasks and their statuses.
- Implemented functions for creating, executing, and retrying tasks, along with handling task progress and completion.
- Introduced persistence for tasks using IPC.
- Created utility functions for normalizing room types and building subtasks.
- Added a new CSS file for global styles in `src-react/styles.css`.
- Created runtime types in `src-react/types/runtime.ts` and exported them.
- Updated the main entry points for Vue and React applications to support dynamic framework loading.
- Refactored chat model interfaces and utility functions into `src/shared/chat-model.ts`.
- Updated TypeScript configuration to include paths for React components and types.
- Enhanced Vite configuration to support both Vue and React frameworks.
2026-04-17 07:09:56 +08:00

62 lines
2.0 KiB
TypeScript

import { BrowserWindow } from 'electron';
import { windowManager } from '@electron/service/window-service';
import logManager from '@electron/service/logger';
import type { GatewayEvent } from './types';
import * as chatHandlers from './handlers/chat';
import * as providerHandlers from './handlers/provider';
class GatewayManager {
private initialized = false;
async init(): Promise<void> {
if (this.initialized) return;
this.initialized = true;
logManager.info('GatewayManager initialized');
this.broadcast({ type: 'gateway:status', status: 'connected' });
}
async rpc(method: string, params: any): Promise<any> {
if (!this.initialized) {
await this.init();
}
logManager.info(`Gateway RPC: ${method}`, params);
switch (method) {
case 'chat.send':
return chatHandlers.handleChatSend(params, (event) => this.broadcast(event));
case 'chat.history':
return chatHandlers.handleChatHistory(params);
case 'chat.abort':
return chatHandlers.handleChatAbort(params, (event) => this.broadcast(event));
case 'session.list':
return chatHandlers.handleSessionList();
case 'session.delete':
return chatHandlers.handleSessionDelete(params);
case 'provider.list':
return providerHandlers.handleProviderList();
case 'provider.getDefault':
return providerHandlers.handleProviderGetDefault();
default:
throw new Error(`Unknown gateway RPC method: ${method}`);
}
}
broadcast(event: GatewayEvent): void {
const mainWindow = BrowserWindow.getAllWindows().find(
(win) => windowManager.getName(win) === 'main'
);
if (mainWindow && !mainWindow.isDestroyed()) {
mainWindow.webContents.send('gateway:event', event);
}
}
reloadProviders(): void {
logManager.info('GatewayManager reloading providers');
// For now, providers are resolved on each chat.send call,
// so no in-memory cache to invalidate. Future: notify active sessions.
}
}
export const gatewayManager = new GatewayManager();