jan/web/app/_services/pluginService.ts
James d982dce090 feat: allowing user to fetch models from github
Signed-off-by: James <james@jan.ai>
2023-10-12 07:30:29 -07:00

61 lines
1.5 KiB
TypeScript

"use client";
import {
extensionPoints,
plugins,
} from "../../../electron/core/plugin-manager/execution/index";
import {
CoreService,
DataService,
InferenceService,
ModelManagementService,
} from "../../shared/coreService";
export const isCorePluginInstalled = () => {
if (!extensionPoints.get(DataService.GET_CONVERSATIONS)) {
return false;
}
if (!extensionPoints.get(InferenceService.INIT_MODEL)) {
return false;
}
if (!extensionPoints.get(ModelManagementService.DOWNLOAD_MODEL)) {
return false;
}
return true;
};
export const setupBasePlugins = async () => {
if (
typeof window === "undefined" ||
typeof window.electronAPI === "undefined"
) {
return;
}
const basePlugins = await window.electronAPI.basePlugins();
if (
!extensionPoints.get(DataService.GET_CONVERSATIONS) ||
!extensionPoints.get(InferenceService.INIT_MODEL) ||
!extensionPoints.get(ModelManagementService.DOWNLOAD_MODEL)
) {
const installed = await plugins.install(basePlugins);
if (installed) {
window.location.reload();
}
}
};
export const execute = (name: CoreService, args?: any) => {
if (!extensionPoints.get(name)) {
alert("Missing extension for function: " + name);
return undefined;
}
return extensionPoints.execute(name, args);
};
export const executeSerial = (name: CoreService, args?: any) => {
if (!extensionPoints.get(name)) {
alert("Missing extension for function: " + name);
return Promise.resolve(undefined);
}
return extensionPoints.executeSerial(name, args);
};