@lobehub/chat
Version:
Lobe Chat - an open-source, high-performance chatbot framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.
59 lines (48 loc) • 1.67 kB
text/typescript
import type { ClientDispatchEvents } from '@lobechat/electron-client-ipc';
import type { ServerDispatchEvents } from '@lobechat/electron-server-ipc';
import type { App } from '@/core/App';
import { IoCContainer } from '@/core/IoCContainer';
import { ShortcutActionType } from '@/shortcuts';
const ipcDecorator =
(name: string, mode: 'client' | 'server') =>
(target: any, methodName: string, descriptor?: any) => {
const actions = IoCContainer.controllers.get(target.constructor) || [];
actions.push({
methodName,
mode,
name,
});
IoCContainer.controllers.set(target.constructor, actions);
return descriptor;
};
/**
* controller 用的 ipc client event 装饰器
*/
export const ipcClientEvent = (method: keyof ClientDispatchEvents) =>
ipcDecorator(method, 'client');
/**
* controller 用的 ipc server event 装饰器
*/
export const ipcServerEvent = (method: keyof ServerDispatchEvents) =>
ipcDecorator(method, 'server');
const shortcutDecorator = (name: string) => (target: any, methodName: string, descriptor?: any) => {
const actions = IoCContainer.shortcuts.get(target.constructor) || [];
actions.push({ methodName, name });
IoCContainer.shortcuts.set(target.constructor, actions);
return descriptor;
};
/**
* shortcut inject decorator
*/
export const shortcut = (method: ShortcutActionType) => shortcutDecorator(method);
interface IControllerModule {
afterAppReady?(): void;
app: App;
beforeAppReady?(): void;
}
export class ControllerModule implements IControllerModule {
constructor(public app: App) {
this.app = app;
}
}
export type IControlModule = typeof ControllerModule;