Skip to content

Commit

Permalink
chore: janhq#371 - reference to plugin name and module path as variab…
Browse files Browse the repository at this point in the history
…les (janhq#372)

* chore: janhq#371 - plugin developer can reference to plugin name and module path as variables

* chore: display origin plugin name

* Switch from plugin-core to core

* Remove un-used command in ci test

---------

Co-authored-by: Hien To <[email protected]>
  • Loading branch information
louis-jan and hiento09 authored Oct 17, 2023
1 parent d5f2f1e commit 7812bf6
Show file tree
Hide file tree
Showing 34 changed files with 372 additions and 235 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/linter-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ jobs:
- name: Linter and test
run: |
yarn config set network-timeout 300000
yarn build:core
yarn install
yarn lint
yarn build:plugins
Expand All @@ -59,7 +58,12 @@ jobs:
- name: Clean workspace
run: |
Remove-Item -Path .\* -Force -Recurse
Remove-Item -Path "$Env:APPDATA\jan" -Force -Recurse
$path = "$Env:APPDATA\jan"
if (Test-Path $path) {
Remove-Item $path -Recurse -Force
} else {
Write-Output "Folder does not exist."
}
- name: Getting the repo
uses: actions/checkout@v3

Expand All @@ -71,7 +75,6 @@ jobs:
- name: Linter and test
run: |
yarn config set network-timeout 300000
yarn build:core
yarn install
yarn lint
yarn build:plugins
Expand Down Expand Up @@ -101,7 +104,6 @@ jobs:
export DISPLAY=$(w -h | awk 'NR==1 {print $2}')
echo -e "Display ID: $DISPLAY"
yarn config set network-timeout 300000
yarn build:core
yarn install
yarn lint
yarn build:plugins
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ To reset your installation:
1. Delete Jan Application from /Applications

1. Clear cache:
`rm -rf /Users/$(whoami)/Library/Application\ Support/jan`
`rm -rf /Users/$(whoami)/Library/Application\ Support/jan-electron`
OR
`rm -rf /Users/$(whoami)/Library/Application\ Support/jan`

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"dev:electron": "yarn workspace jan dev",
"dev:web": "yarn workspace jan-web dev",
"dev": "concurrently --kill-others \"yarn dev:web\" \"wait-on http://localhost:3000 && yarn dev:electron\"",
"build:core": "cd plugin-core && yarn install && yarn run build",
"build:core": "cd core && yarn install && yarn run build",
"build:web": "yarn workspace jan-web build && cpx \"web/out/**\" \"electron/renderer/\"",
"build:electron": "yarn workspace jan build",
"build:plugins": "rimraf ./electron/core/pre-install/*.tgz && concurrently --kill-others-on-fail \"cd ./plugins/data-plugin && npm install && npm run postinstall\" \"cd ./plugins/inference-plugin && npm install && npm run postinstall\" \"cd ./plugins/model-management-plugin && npm install && npm run postinstall\" \"cd ./plugins/monitoring-plugin && npm install && npm run postinstall\" && concurrently --kill-others-on-fail \"cd ./plugins/data-plugin && npm run build:publish\" \"cd ./plugins/inference-plugin && npm run build:publish\" \"cd ./plugins/model-management-plugin && npm run build:publish\" \"cd ./plugins/monitoring-plugin && npm run build:publish\"",
Expand Down
2 changes: 2 additions & 0 deletions plugins/data-plugin/@types/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare const PLUGIN_NAME: string;
declare const MODULE_PATH: string;
3 changes: 2 additions & 1 deletion plugins/data-plugin/config/tsconfig.esm.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"outDir": "./../dist/esm",
"module": "esnext"
},
"files": ["../index.ts"]
"include": ["@types/*"],
"files": ["../@types/global.d.ts", "../index.ts"]
}
7 changes: 2 additions & 5 deletions plugins/data-plugin/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import { core, store, RegisterExtensionPoint, StoreService, DataService, PluginService } from "@janhq/plugin-core";

const PluginName = "@janhq/data-plugin";
const MODULE_PATH = "@janhq/data-plugin/dist/cjs/module.js";
import { core, store, RegisterExtensionPoint, StoreService, DataService, PluginService } from "@janhq/core";

/**
* Create a collection on data store
Expand Down Expand Up @@ -136,7 +133,7 @@ function onStart() {

// Register all the above functions and objects with the relevant extension points
export function init({ register }: { register: RegisterExtensionPoint }) {
register(PluginService.OnStart, PluginName, onStart);
register(PluginService.OnStart, PLUGIN_NAME, onStart);
register(StoreService.CreateCollection, createCollection.name, createCollection);
register(StoreService.DeleteCollection, deleteCollection.name, deleteCollection);
register(StoreService.InsertOne, insertOne.name, insertOne);
Expand Down
10 changes: 5 additions & 5 deletions plugins/data-plugin/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions plugins/data-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
"description": "The Data Connector provides easy access to a data API using the PouchDB engine. It offers accessible data management capabilities.",
"icon": "https://raw.githubusercontent.com/tailwindlabs/heroicons/88e98b0c2b458553fbadccddc2d2f878edc0387b/src/20/solid/circle-stack.svg",
"main": "dist/esm/index.js",
"module": "dist/cjs/module.js",
"author": "Jan",
"license": "MIT",
"activationPoints": [
"init"
],
"scripts": {
"build": "tsc --project ./config/tsconfig.esm.json && tsc --project ./config/tsconfig.cjs.json && webpack --config webpack.config.js",
"build": "tsc -b ./config/tsconfig.esm.json && tsc -b ./config/tsconfig.cjs.json && webpack --config webpack.config.js",
"postinstall": "rimraf ./data-plugin*.tgz && npm run build",
"build:publish": "npm pack && cpx *.tgz ../../electron/core/pre-install"
},
Expand Down Expand Up @@ -39,7 +40,7 @@
"node_modules"
],
"dependencies": {
"@janhq/plugin-core": "^0.1.8",
"@janhq/core": "^0.1.1",
"pouchdb-find": "^8.0.1",
"pouchdb-node": "^8.0.1"
}
Expand Down
10 changes: 9 additions & 1 deletion plugins/data-plugin/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const path = require("path");
const webpack = require("webpack");
const packageJson = require("./package.json");

module.exports = {
experiments: { outputModule: true },
Expand All @@ -13,6 +15,12 @@ module.exports = {
},
],
},
plugins: [
new webpack.DefinePlugin({
PLUGIN_NAME: JSON.stringify(packageJson.name),
MODULE_PATH: JSON.stringify(`${packageJson.name}/${packageJson.module}`),
}),
],
output: {
filename: "esm/index.js", // Adjust the output file name as needed
path: path.resolve(__dirname, "dist"),
Expand All @@ -22,7 +30,7 @@ module.exports = {
extensions: [".ts", ".js"],
},
optimization: {
minimize: false
minimize: false,
},
// Add loaders and other configuration as needed for your project
};
2 changes: 2 additions & 0 deletions plugins/inference-plugin/@types/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare const PLUGIN_NAME: string;
declare const MODULE_PATH: string;
6 changes: 2 additions & 4 deletions plugins/inference-plugin/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { EventName, InferenceService, NewMessageRequest, PluginService, core, events, store } from "@janhq/plugin-core";
import { EventName, InferenceService, NewMessageRequest, PluginService, core, events, store } from "@janhq/core";

const PluginName = "@janhq/inference-plugin";
const MODULE_PATH = `${PluginName}/dist/module.js`;
const inferenceUrl = "http://localhost:3928/llama/chat_completion";

const initModel = async (product) => core.invokePluginFunc(MODULE_PATH, "initModel", product);
Expand Down Expand Up @@ -91,7 +89,7 @@ const onStart = async () => {
};
// Register all the above functions and objects with the relevant extension points
export function init({ register }) {
register(PluginService.OnStart, PluginName, onStart);
register(PluginService.OnStart, PLUGIN_NAME, onStart);
register(InferenceService.InitModel, initModel.name, initModel);
register(InferenceService.StopModel, stopModel.name, stopModel);
}
10 changes: 5 additions & 5 deletions plugins/inference-plugin/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion plugins/inference-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "Inference Plugin, powered by @janhq/nitro, bring a high-performance Llama model inference in pure C++.",
"icon": "https://raw.githubusercontent.com/tailwindlabs/heroicons/88e98b0c2b458553fbadccddc2d2f878edc0387b/src/20/solid/command-line.svg",
"main": "dist/index.js",
"module": "dist/module.js",
"author": "Jan",
"license": "MIT",
"activationPoints": [
Expand All @@ -25,7 +26,7 @@
"webpack-cli": "^5.1.4"
},
"dependencies": {
"@janhq/plugin-core": "^0.1.8",
"@janhq/core": "^0.1.1",
"kill-port-process": "^3.2.0",
"tcp-port-used": "^1.0.2",
"ts-loader": "^9.5.0"
Expand Down
8 changes: 8 additions & 0 deletions plugins/inference-plugin/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const path = require("path");
const webpack = require("webpack");
const packageJson = require("./package.json");

module.exports = {
experiments: { outputModule: true },
Expand All @@ -13,6 +15,12 @@ module.exports = {
},
],
},
plugins: [
new webpack.DefinePlugin({
PLUGIN_NAME: JSON.stringify(packageJson.name),
MODULE_PATH: JSON.stringify(`${packageJson.name}/${packageJson.module}`),
}),
],
output: {
filename: "index.js", // Adjust the output file name as needed
path: path.resolve(__dirname, "dist"),
Expand Down
2 changes: 2 additions & 0 deletions plugins/model-management-plugin/@types/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare const PLUGIN_NAME: string;
declare const MODULE_PATH: string;
7 changes: 2 additions & 5 deletions plugins/model-management-plugin/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import { ModelManagementService, PluginService, RegisterExtensionPoint, core, store } from "@janhq/plugin-core";

const PluginName = "@janhq/model-management-plugin";
const MODULE_PATH = "@janhq/model-management-plugin/dist/module.js";
import { ModelManagementService, PluginService, RegisterExtensionPoint, core, store } from "@janhq/core";

const getDownloadedModels = () => core.invokePluginFunc(MODULE_PATH, "getDownloadedModels");

Expand Down Expand Up @@ -83,7 +80,7 @@ function onStart() {

// Register all the above functions and objects with the relevant extension points
export function init({ register }: { register: RegisterExtensionPoint }) {
register(PluginService.OnStart, PluginName, onStart);
register(PluginService.OnStart, PLUGIN_NAME, onStart);

register(ModelManagementService.GetDownloadedModels, getDownloadedModels.name, getDownloadedModels);
register(ModelManagementService.GetAvailableModels, getAvailableModels.name, getAvailableModels);
Expand Down
10 changes: 5 additions & 5 deletions plugins/model-management-plugin/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion plugins/model-management-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "Model Management Plugin provides model exploration and seamless downloads",
"icon": "https://raw.githubusercontent.com/tailwindlabs/heroicons/88e98b0c2b458553fbadccddc2d2f878edc0387b/src/20/solid/queue-list.svg",
"main": "dist/index.js",
"module": "dist/module.js",
"author": "James",
"license": "MIT",
"activationPoints": [
Expand All @@ -27,7 +28,7 @@
],
"dependencies": {
"@huggingface/hub": "^0.8.5",
"@janhq/plugin-core": "^0.1.8",
"@janhq/core": "^0.1.1",
"ts-loader": "^9.5.0"
},
"bundledDependencies": [
Expand Down
8 changes: 8 additions & 0 deletions plugins/model-management-plugin/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const path = require("path");
const webpack = require("webpack");
const packageJson = require("./package.json");

module.exports = {
experiments: { outputModule: true },
Expand All @@ -13,6 +15,12 @@ module.exports = {
},
],
},
plugins: [
new webpack.DefinePlugin({
PLUGIN_NAME: JSON.stringify(packageJson.name),
MODULE_PATH: JSON.stringify(`${packageJson.name}/${packageJson.module}`),
}),
],
output: {
filename: "index.js", // Adjust the output file name as needed
path: path.resolve(__dirname, "dist"),
Expand Down
2 changes: 2 additions & 0 deletions plugins/monitoring-plugin/@types/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare const PLUGIN_NAME: string;
declare const MODULE_PATH: string;
36 changes: 0 additions & 36 deletions plugins/monitoring-plugin/index.js

This file was deleted.

12 changes: 12 additions & 0 deletions plugins/monitoring-plugin/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { core, SystemMonitoringService } from "@janhq/core";

// Provide an async method to manipulate the price provided by the extension point
const getResourcesInfo = () => core.invokePluginFunc(MODULE_PATH, "getResourcesInfo");

const getCurrentLoad = () => core.invokePluginFunc(MODULE_PATH, "getCurrentLoad");

// Register all the above functions and objects with the relevant extension points
export function init({ register }) {
register(SystemMonitoringService.GetResourcesInfo, getResourcesInfo.name, getResourcesInfo);
register(SystemMonitoringService.GetCurrentLoad, getCurrentLoad.name, getCurrentLoad);
}
File renamed without changes.
Loading

0 comments on commit 7812bf6

Please sign in to comment.