jan/web/app/_services/pluginService.ts
Louis b46042654c
chore: update core services and module export (#376)
* chore: update core services and module export

* Correct version of plugins (#374)

Co-authored-by: Hien To <tominhhien97@gmail.com>

* janhq/jan: Update tag build 1.0.2 for data-plugin

* janhq/jan: Update tag build 1.0.2 for inference-plugin

* janhq/jan: Update tag build 1.0.2 for model-management-plugin

* janhq/jan: Update tag build 1.0.2 for monitoring-plugin

* janhq/jan: Update tag build 1.0.2 for openai-plugin

* chore: update web to use @janhq/core module

---------

Co-authored-by: hiento09 <136591877+hiento09@users.noreply.github.com>
Co-authored-by: Hien To <tominhhien97@gmail.com>
Co-authored-by: Service Account <service@jan.ai>
2023-10-17 19:48:43 +07:00

50 lines
1.5 KiB
TypeScript

"use client";
import { extensionPoints, plugins } from "../../../electron/core/plugin-manager/execution/index";
import { CoreService, DataService, InferenceService, ModelManagementService } from "@janhq/core";
export const isCorePluginInstalled = () => {
if (!extensionPoints.get(DataService.GetConversations)) {
return false;
}
if (!extensionPoints.get(InferenceService.InitModel)) {
return false;
}
if (!extensionPoints.get(ModelManagementService.DownloadModel)) {
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.GetConversations) ||
!extensionPoints.get(InferenceService.InitModel) ||
!extensionPoints.get(ModelManagementService.DownloadModel)
) {
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);
};