File size: 1,602 Bytes
f0634fb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | import { Event, type Emitter } from '#/_base/event';
import type { IPluginService } from '#/app/plugin/plugin';
import type {
EnabledPluginSessionStart,
PluginMutationSummary,
PluginReloadEvent,
ReloadSummary,
} from '#/app/plugin/types';
interface StubPluginServiceOptions {
readonly sessionStarts: readonly EnabledPluginSessionStart[];
readonly reloadEmitter?: Emitter<PluginReloadEvent>;
readonly mutateEmitter?: Emitter<PluginMutationSummary>;
}
export function stubPluginService(options: StubPluginServiceOptions): IPluginService {
return {
_serviceBrand: undefined,
onDidReload: options.reloadEmitter?.event ?? (Event.None as IPluginService['onDidReload']),
onDidMutate: options.mutateEmitter?.event ?? (Event.None as IPluginService['onDidMutate']),
listPlugins: async () => [],
installPlugin: async () => ({ id: '' }) as never,
setPluginEnabled: async () => {},
setPluginMcpServerEnabled: async () => {},
removePlugin: async () => {},
reloadPlugins: async (): Promise<ReloadSummary> => ({ added: [], removed: [], errors: [] }),
getPluginInfo: async () => {
throw new Error('getPluginInfo is not used by this stub');
},
listPluginCommands: async () => [],
checkUpdates: async () => [],
pluginSkillRoots: async () => [],
pluginAgentRoots: async () => [],
enabledSessionStarts: async () => options.sessionStarts,
enabledSystemPrompts: async () => [],
enabledMcpServers: async () => ({}),
mcpServerEntries: async () => [],
enabledHooks: async () => [],
hasLoadedSnapshot: () => true,
};
}
|