From e8742db40f92101bbe0fbc5c5e6c81e41d5dcf4e Mon Sep 17 00:00:00 2001 From: Louis Date: Mon, 11 Dec 2023 16:19:51 +0700 Subject: [PATCH] chore: expose fs apis --- core/rollup.config.ts | 76 ++++-- core/src/api/index.ts | 22 +- core/src/fs.ts | 66 ++---- .../src/node}/extension/extension.ts | 108 +++++---- .../src/node}/extension/index.ts | 46 ++-- core/src/node/extension/manager.ts | 60 +++++ .../src/node}/extension/store.ts | 66 +++--- core/src/node/index.ts | 4 + electron/handlers/app.ts | 2 +- electron/handlers/extension.ts | 8 +- electron/handlers/fs.ts | 219 +----------------- electron/main.ts | 2 +- electron/managers/extension.ts | 85 ------- electron/tsconfig.json | 2 +- electron/utils/migration.ts | 30 +++ extensions/assistant-extension/src/index.ts | 32 ++- .../conversational-extension/src/index.ts | 56 +++-- .../inference-nitro-extension/src/index.ts | 13 +- .../inference-openai-extension/src/index.ts | 23 +- extensions/model-extension/src/index.ts | 60 ++--- server/data/.gitkeep | 0 server/data/models/.gitkeep | 0 server/data/threads/.gitkeep | 0 server/icons/icon.png | Bin 38651 -> 0 bytes server/lib/.gitkeep | 0 server/main.ts | 41 ++-- server/package.json | 3 + server/tsconfig.json | 5 +- server/v1/assistants/index.ts | 8 - server/v1/chat/index.ts | 11 - server/v1/extension/index.ts | 38 +++ server/v1/fs/index.ts | 34 +++ server/v1/index.ts | 45 +--- server/v1/models/downloadModel.ts | 23 -- server/v1/models/index.ts | 61 ----- server/v1/models/modelOp.ts | 11 - server/v1/threads/index.ts | 8 - web/containers/Layout/index.tsx | 6 +- web/extension/ExtensionManager.ts | 5 +- web/next.config.js | 1 + web/package.json | 1 - .../Settings/Appearance/ToggleTheme.tsx | 6 +- web/screens/Settings/Models/index.tsx | 2 +- web/services/cloudNativeService.ts | 76 ------ web/services/coreService.ts | 6 +- web/services/extensionService.ts | 7 +- web/services/restService.ts | 59 +++++ web/types/index.d.ts | 1 + web/utils/json.ts | 9 + 49 files changed, 597 insertions(+), 850 deletions(-) rename {electron => core/src/node}/extension/extension.ts (70%) rename {electron => core/src/node}/extension/index.ts (73%) create mode 100644 core/src/node/extension/manager.ts rename {electron => core/src/node}/extension/store.ts (67%) create mode 100644 core/src/node/index.ts delete mode 100644 electron/managers/extension.ts create mode 100644 electron/utils/migration.ts delete mode 100644 server/data/.gitkeep delete mode 100644 server/data/models/.gitkeep delete mode 100644 server/data/threads/.gitkeep delete mode 100644 server/icons/icon.png delete mode 100644 server/lib/.gitkeep delete mode 100644 server/v1/assistants/index.ts delete mode 100644 server/v1/chat/index.ts create mode 100644 server/v1/extension/index.ts create mode 100644 server/v1/fs/index.ts delete mode 100644 server/v1/models/downloadModel.ts delete mode 100644 server/v1/models/index.ts delete mode 100644 server/v1/models/modelOp.ts delete mode 100644 server/v1/threads/index.ts delete mode 100644 web/services/cloudNativeService.ts create mode 100644 web/services/restService.ts create mode 100644 web/utils/json.ts diff --git a/core/rollup.config.ts b/core/rollup.config.ts index 5e1762c967..89f57e35ff 100644 --- a/core/rollup.config.ts +++ b/core/rollup.config.ts @@ -8,30 +8,56 @@ const pkg = require('./package.json') const libraryName = 'core' -export default { - input: `src/index.ts`, - output: [ - { file: pkg.main, name: libraryName, format: 'umd', sourcemap: true }, - { file: pkg.module, format: 'es', sourcemap: true }, - ], - // Indicate here external modules you don't wanna include in your bundle (i.e.: 'lodash') - external: [], - watch: { - include: 'src/**', +export default [ + { + input: `src/index.ts`, + output: [ + { file: pkg.main, name: libraryName, format: 'umd', sourcemap: true }, + { file: pkg.module, format: 'es', sourcemap: true }, + ], + // Indicate here external modules you don't wanna include in your bundle (i.e.: 'lodash') + external: ['path'], + watch: { + include: 'src/**', + }, + plugins: [ + // Allow json resolution + json(), + // Compile TypeScript files + typescript({ useTsconfigDeclarationDir: true }), + // Allow bundling cjs modules (unlike webpack, rollup doesn't understand cjs) + commonjs(), + // Allow node_modules resolution, so you can use 'external' to control + // which external modules to include in the bundle + // https://github.com/rollup/rollup-plugin-node-resolve#usage + resolve(), + + // Resolve source maps to the original source + sourceMaps(), + ], }, - plugins: [ - // Allow json resolution - json(), - // Compile TypeScript files - typescript({ useTsconfigDeclarationDir: true }), - // Allow bundling cjs modules (unlike webpack, rollup doesn't understand cjs) - commonjs(), - // Allow node_modules resolution, so you can use 'external' to control - // which external modules to include in the bundle - // https://github.com/rollup/rollup-plugin-node-resolve#usage - resolve(), + { + input: `src/node/index.ts`, + output: [{ file: 'dist/node/index.cjs', format: 'cjs', sourcemap: true }], + // Indicate here external modules you don't wanna include in your bundle (i.e.: 'lodash') + external: ['fs/promises', 'path', 'pacote', '@types/pacote', '@npmcli/arborist'], + watch: { + include: 'src/node/**', + }, + plugins: [ + // Allow json resolution + json(), + // Compile TypeScript files + typescript({ useTsconfigDeclarationDir: true }), + // Allow bundling cjs modules (unlike webpack, rollup doesn't understand cjs) + commonjs(), + // Allow node_modules resolution, so you can use 'external' to control + // which external modules to include in the bundle + // https://github.com/rollup/rollup-plugin-node-resolve#usage + resolve(), - // Resolve source maps to the original source - sourceMaps(), - ], -} + // Resolve source maps to the original source + sourceMaps(), + ], + }, +] diff --git a/core/src/api/index.ts b/core/src/api/index.ts index b45a41d0e3..77e4407147 100644 --- a/core/src/api/index.ts +++ b/core/src/api/index.ts @@ -43,19 +43,19 @@ export enum ExtensionRoute { uninstallExtension = 'uninstallExtension', } export enum FileSystemRoute { - appendFile = 'appendFile', - copyFile = 'copyFile', - deleteFile = 'deleteFile', - exists = 'exists', + appendFileSync = 'appendFileSync', + copyFileSync = 'copyFileSync', + unlinkSync = 'unlinkSync', + existsSync = 'existsSync', + readdirSync = 'readdirSync', + mkdirSync = 'mkdirSync', + readFileSync = 'readFileSync', + rmdirSync = 'rmdirSync', + writeFileSync = 'writeFileSync', + + isDirectory = 'isDirectory', getResourcePath = 'getResourcePath', getUserSpace = 'getUserSpace', - isDirectory = 'isDirectory', - listFiles = 'listFiles', - mkdir = 'mkdir', - readFile = 'readFile', - readLineByLine = 'readLineByLine', - rmdir = 'rmdir', - writeFile = 'writeFile', } export type ApiFunction = (...args: any[]) => any diff --git a/core/src/fs.ts b/core/src/fs.ts index d15bf62304..939333b293 100644 --- a/core/src/fs.ts +++ b/core/src/fs.ts @@ -1,86 +1,64 @@ /** * Writes data to a file at the specified path. - * @param {string} path - The path to the file. - * @param {string} data - The data to write to the file. * @returns {Promise} A Promise that resolves when the file is written successfully. */ -const writeFile: (path: string, data: string) => Promise = (path, data) => - global.core.api?.writeFile(path, data) - -/** - * Checks whether the path is a directory. - * @param path - The path to check. - * @returns {boolean} A boolean indicating whether the path is a directory. - */ -const isDirectory = (path: string): Promise => global.core.api?.isDirectory(path) +const writeFileSync = (...args: any[]) => global.core.api?.writeFileSync(...args) /** * Reads the contents of a file at the specified path. - * @param {string} path - The path of the file to read. * @returns {Promise} A Promise that resolves with the contents of the file. */ -const readFile: (path: string) => Promise = (path) => global.core.api?.readFile(path) +const readFileSync = (...args: any[]) => global.core.api?.readFileSync(...args) /** * Check whether the file exists * @param {string} path * @returns {boolean} A boolean indicating whether the path is a file. */ -const exists = (path: string): Promise => global.core.api?.exists(path) +const existsSync = (...args: any[]) => global.core.api?.existsSync(...args) /** * List the directory files - * @param {string} path - The path of the directory to list files. * @returns {Promise} A Promise that resolves with the contents of the directory. */ -const listFiles: (path: string) => Promise = (path) => global.core.api?.listFiles(path) +const readdirSync = (...args: any[]) => global.core.api?.readdirSync(...args) /** * Creates a directory at the specified path. - * @param {string} path - The path of the directory to create. * @returns {Promise} A Promise that resolves when the directory is created successfully. */ -const mkdir: (path: string) => Promise = (path) => global.core.api?.mkdir(path) +const mkdirSync = (...args: any[]) => global.core.api?.mkdirSync(...args) /** * Removes a directory at the specified path. - * @param {string} path - The path of the directory to remove. * @returns {Promise} A Promise that resolves when the directory is removed successfully. */ -const rmdir: (path: string) => Promise = (path) => global.core.api?.rmdir(path) +const rmdirSync = (...args: any[]) => + global.core.api?.rmdirSync(...args, { recursive: true, force: true }) /** * Deletes a file from the local file system. * @param {string} path - The path of the file to delete. * @returns {Promise} A Promise that resolves when the file is deleted. */ -const deleteFile: (path: string) => Promise = (path) => global.core.api?.deleteFile(path) +const unlinkSync = (...args: any[]) => global.core.api?.unlinkSync(...args) /** * Appends data to a file at the specified path. - * @param path path to the file - * @param data data to append */ -const appendFile: (path: string, data: string) => Promise = (path, data) => - global.core.api?.appendFile(path, data) - -const copyFile: (src: string, dest: string) => Promise = (src, dest) => - global.core.api?.copyFile(src, dest) +const appendFileSync = (...args: any[]) => global.core.api?.appendFileSync(...args) /** - * Reads a file line by line. - * @param {string} path - The path of the file to read. - * @returns {Promise} A promise that resolves to the lines of the file. + * Copy file sync. */ -const readLineByLine: (path: string) => Promise = (path) => - global.core.api?.readLineByLine(path) +const copyFileSync = (...args: any[]) => global.core.api?.copyFileSync(...args) +// TODO: Export `dummy` fs functions automatically +// Currently adding these manually export const fs = { - isDirectory, - writeFile, - readFile, - exists, - listFiles, - mkdir, - rmdir, - deleteFile, - appendFile, - readLineByLine, - copyFile, + writeFileSync, + readFileSync, + existsSync, + readdirSync, + mkdirSync, + rmdirSync, + unlinkSync, + appendFileSync, + copyFileSync, } diff --git a/electron/extension/extension.ts b/core/src/node/extension/extension.ts similarity index 70% rename from electron/extension/extension.ts rename to core/src/node/extension/extension.ts index 1bd11611da..9dbd74e880 100644 --- a/electron/extension/extension.ts +++ b/core/src/node/extension/extension.ts @@ -1,14 +1,14 @@ -import { rmdir } from 'fs/promises' -import { resolve, join } from 'path' -import { manifest, extract } from 'pacote' -import * as Arborist from '@npmcli/arborist' -import { ExtensionManager } from './../managers/extension' +import { rmdirSync } from "fs"; +import { resolve, join } from "path"; +import { manifest, extract } from "pacote"; +import * as Arborist from "@npmcli/arborist"; +import { ExtensionManager, userSpacePath } from "./manager"; /** * An NPM package that can be used as an extension. * Used to hold all the information and functions necessary to handle the extension lifecycle. */ -class Extension { +export default class Extension { /** * @property {string} origin Original specification provided to fetch the package. * @property {Object} installOptions Options provided to pacote when fetching the manifest. @@ -18,22 +18,22 @@ class Extension { * @property {string} main The entry point as defined in the main entry of the manifest. * @property {string} description The description of extension as defined in the manifest. */ - origin?: string - installOptions: any - name?: string - url?: string - version?: string - main?: string - description?: string + origin?: string; + installOptions: any; + name?: string; + url?: string; + version?: string; + main?: string; + description?: string; /** @private */ - _active = false + _active = false; /** * @private * @property {Object.} #listeners A list of callbacks to be executed when the Extension is updated. */ - listeners: Record void> = {} + listeners: Record void> = {}; /** * Set installOptions with defaults for options that have not been provided. @@ -45,10 +45,10 @@ class Extension { version: false, fullMetadata: false, Arborist, - } + }; - this.origin = origin - this.installOptions = { ...defaultOpts, ...options } + this.origin = origin; + this.installOptions = { ...defaultOpts, ...options }; } /** @@ -58,8 +58,8 @@ class Extension { get specifier() { return ( this.origin + - (this.installOptions.version ? '@' + this.installOptions.version : '') - ) + (this.installOptions.version ? "@" + this.installOptions.version : "") + ); } /** @@ -67,7 +67,7 @@ class Extension { * @type {boolean} */ get active() { - return this._active + return this._active; } /** @@ -77,20 +77,20 @@ class Extension { async getManifest() { // Get the package's manifest (package.json object) try { - const mnf = await manifest(this.specifier, this.installOptions) + const mnf = await manifest(this.specifier, this.installOptions); // set the Package properties based on the it's manifest - this.name = mnf.name - this.version = mnf.version - this.main = mnf.main - this.description = mnf.description + this.name = mnf.name; + this.version = mnf.version; + this.main = mnf.main; + this.description = mnf.description; } catch (error) { throw new Error( `Package ${this.origin} does not contain a valid manifest: ${error}` - ) + ); } - return true + return true; } /** @@ -101,26 +101,26 @@ class Extension { async _install() { try { // import the manifest details - await this.getManifest() + await this.getManifest(); // Install the package in a child folder of the given folder await extract( this.specifier, - join(ExtensionManager.instance.extensionsPath ?? '', this.name ?? ''), + join(ExtensionManager.instance.extensionsPath ?? "", this.name ?? ""), this.installOptions - ) + ); // Set the url using the custom extensions protocol - this.url = `extension://${this.name}/${this.main}` + this.url = `extension://${this.name}/${this.main}`; - this.emitUpdate() + this.emitUpdate(); } catch (err) { // Ensure the extension is not stored and the folder is removed if the installation fails - this.setActive(false) - throw err + this.setActive(false); + throw err; } - return [this] + return [this]; } /** @@ -129,7 +129,7 @@ class Extension { * @param {callback} cb The function to execute on update */ subscribe(name: string, cb: () => void) { - this.listeners[name] = cb + this.listeners[name] = cb; } /** @@ -137,7 +137,7 @@ class Extension { * @param {string} name name of the callback to remove */ unsubscribe(name: string) { - delete this.listeners[name] + delete this.listeners[name]; } /** @@ -145,7 +145,7 @@ class Extension { */ emitUpdate() { for (const cb in this.listeners) { - this.listeners[cb].call(null, this) + this.listeners[cb].call(null, this); } } @@ -156,12 +156,12 @@ class Extension { */ async update(version = false) { if (await this.isUpdateAvailable()) { - this.installOptions.version = version - await this._install() - return true + this.installOptions.version = version; + await this._install(); + return true; } - return false + return false; } /** @@ -170,8 +170,8 @@ class Extension { */ async isUpdateAvailable() { if (this.origin) { - const mnf = await manifest(this.origin) - return mnf.version !== this.version ? mnf.version : false + const mnf = await manifest(this.origin); + return mnf.version !== this.version ? mnf.version : false; } } @@ -181,12 +181,12 @@ class Extension { */ async uninstall() { const extPath = resolve( - ExtensionManager.instance.extensionsPath ?? '', - this.name ?? '' - ) - await rmdir(extPath, { recursive: true }) + ExtensionManager.instance.extensionsPath ?? "", + this.name ?? "" + ); + await rmdirSync(extPath, { recursive: true }); - this.emitUpdate() + this.emitUpdate(); } /** @@ -195,10 +195,8 @@ class Extension { * @returns {Extension} This extension */ setActive(active: boolean) { - this._active = active - this.emitUpdate() - return this + this._active = active; + this.emitUpdate(); + return this; } } - -export default Extension diff --git a/electron/extension/index.ts b/core/src/node/extension/index.ts similarity index 73% rename from electron/extension/index.ts rename to core/src/node/extension/index.ts index c6a6cc0c06..538a91f9fa 100644 --- a/electron/extension/index.ts +++ b/core/src/node/extension/index.ts @@ -1,5 +1,13 @@ import { readFileSync } from 'fs' -import { protocol } from 'electron' + +let electron: any = undefined + +try { + electron = require('electron') +} catch (err) { + console.error('Electron is not available') +} + import { normalize } from 'path' import Extension from './extension' @@ -12,18 +20,8 @@ import { getActiveExtensions, addExtension, } from './store' -import { ExtensionManager } from './../managers/extension' +import { ExtensionManager } from './manager' -/** - * Sets up the required communication between the main and renderer processes. - * Additionally sets the extensions up using {@link useExtensions} if a extensionsPath is provided. - * @param {Object} options configuration for setting up the renderer facade. - * @param {confirmInstall} [options.confirmInstall] Function to validate that a extension should be installed. - * @param {Boolean} [options.useFacade=true] Whether to make a facade to the extensions available in the renderer. - * @param {string} [options.extensionsPath] Optional path to the extensions folder. - * @returns {extensionManager|Object} A set of functions used to manage the extension lifecycle if useExtensions is provided. - * @function - */ export function init(options: any) { // Create extensions protocol to serve extensions to renderer registerExtensionProtocol() @@ -42,12 +40,14 @@ export function init(options: any) { * @returns {boolean} Whether the protocol registration was successful */ function registerExtensionProtocol() { - return protocol.registerFileProtocol('extension', (request, callback) => { - const entry = request.url.substr('extension://'.length - 1) + if (electron) { + return electron.protocol.registerFileProtocol('extension', (request: any, callback: any) => { + const entry = request.url.substr('extension://'.length - 1) - const url = normalize(ExtensionManager.instance.extensionsPath + entry) - callback({ path: url }) - }) + const url = normalize(ExtensionManager.instance.extensionsPath + entry) + callback({ path: url }) + }) + } } /** @@ -57,8 +57,7 @@ function registerExtensionProtocol() { * @returns {extensionManager} A set of functions used to manage the extension lifecycle. */ export function useExtensions(extensionsPath: string) { - if (!extensionsPath) - throw Error('A path to the extensions folder is required to use extensions') + if (!extensionsPath) throw Error('A path to the extensions folder is required to use extensions') // Store the path to the extensions folder ExtensionManager.instance.setExtensionsPath(extensionsPath) @@ -69,7 +68,7 @@ export function useExtensions(extensionsPath: string) { // Read extension list from extensions folder const extensions = JSON.parse( - readFileSync(ExtensionManager.instance.getExtensionsFile(), 'utf-8') + readFileSync(ExtensionManager.instance.getExtensionsFile(), 'utf-8'), ) try { // Create and store a Extension instance for each extension in list @@ -82,7 +81,7 @@ export function useExtensions(extensionsPath: string) { throw new Error( 'Could not successfully rebuild list of installed extensions.\n' + error + - '\nPlease check the extensions.json file in the extensions folder.' + '\nPlease check the extensions.json file in the extensions folder.', ) } @@ -111,7 +110,6 @@ function loadExtension(ext: any) { }) } } - addExtension(extension, false) extension.subscribe('pe-persist', persistExtensions) } @@ -123,7 +121,7 @@ function loadExtension(ext: any) { export function getStore() { if (!ExtensionManager.instance.extensionsPath) { throw new Error( - 'The extension path has not yet been set up. Please run useExtensions before accessing the store' + 'The extension path has not yet been set up. Please run useExtensions before accessing the store', ) } @@ -134,4 +132,4 @@ export function getStore() { getActiveExtensions, removeExtension, } -} +} \ No newline at end of file diff --git a/core/src/node/extension/manager.ts b/core/src/node/extension/manager.ts new file mode 100644 index 0000000000..ea4a6faf27 --- /dev/null +++ b/core/src/node/extension/manager.ts @@ -0,0 +1,60 @@ +import { join, resolve } from "path"; + +import { existsSync, mkdirSync, writeFileSync } from "fs"; +import { init } from "./index"; +/** + * Manages extension installation and migration. + */ + +export const userSpacePath = join(require("os").homedir(), "jan"); + +export class ExtensionManager { + public static instance: ExtensionManager = new ExtensionManager(); + + extensionsPath: string | undefined = join(userSpacePath, "extensions"); + + constructor() { + if (ExtensionManager.instance) { + return ExtensionManager.instance; + } + } + + /** + * Sets up the extensions by initializing the `extensions` module with the `confirmInstall` and `extensionsPath` options. + * The `confirmInstall` function always returns `true` to allow extension installation. + * The `extensionsPath` option specifies the path to install extensions to. + */ + setupExtensions() { + init({ + // Function to check from the main process that user wants to install a extension + confirmInstall: async (_extensions: string[]) => { + return true; + }, + // Path to install extension to + extensionsPath: join(userSpacePath, "extensions"), + }); + } + + setExtensionsPath(extPath: string) { + // Create folder if it does not exist + let extDir; + try { + extDir = resolve(extPath); + if (extDir.length < 2) throw new Error(); + + if (!existsSync(extDir)) mkdirSync(extDir); + + const extensionsJson = join(extDir, "extensions.json"); + if (!existsSync(extensionsJson)) + writeFileSync(extensionsJson, "{}", "utf8"); + + this.extensionsPath = extDir; + } catch (error) { + throw new Error("Invalid path provided to the extensions folder"); + } + } + + getExtensionsFile() { + return join(this.extensionsPath ?? "", "extensions.json"); + } +} diff --git a/electron/extension/store.ts b/core/src/node/extension/store.ts similarity index 67% rename from electron/extension/store.ts rename to core/src/node/extension/store.ts index 4857ef27a9..8e11c2bb24 100644 --- a/electron/extension/store.ts +++ b/core/src/node/extension/store.ts @@ -1,16 +1,6 @@ -/** - * Provides access to the extensions stored by Extension Store - * @typedef {Object} extensionManager - * @prop {getExtension} getExtension - * @prop {getAllExtensions} getAllExtensions - * @prop {getActiveExtensions} getActiveExtensions - * @prop {installExtensions} installExtensions - * @prop {removeExtension} removeExtension - */ - -import { writeFileSync } from 'fs' -import Extension from './extension' -import { ExtensionManager } from './../managers/extension' +import { writeFileSync } from "fs"; +import Extension from "./extension"; +import { ExtensionManager } from "./manager"; /** * @module store @@ -21,7 +11,7 @@ import { ExtensionManager } from './../managers/extension' * Register of installed extensions * @type {Object.} extension - List of installed extensions */ -const extensions: Record = {} +const extensions: Record = {}; /** * Get a extension from the stored extensions. @@ -31,10 +21,10 @@ const extensions: Record = {} */ export function getExtension(name: string) { if (!Object.prototype.hasOwnProperty.call(extensions, name)) { - throw new Error(`Extension ${name} does not exist`) + throw new Error(`Extension ${name} does not exist`); } - return extensions[name] + return extensions[name]; } /** @@ -43,7 +33,7 @@ export function getExtension(name: string) { * @alias extensionManager.getAllExtensions */ export function getAllExtensions() { - return Object.values(extensions) + return Object.values(extensions); } /** @@ -52,7 +42,7 @@ export function getAllExtensions() { * @alias extensionManager.getActiveExtensions */ export function getActiveExtensions() { - return Object.values(extensions).filter((extension) => extension.active) + return Object.values(extensions).filter((extension) => extension.active); } /** @@ -63,9 +53,9 @@ export function getActiveExtensions() { * @alias extensionManager.removeExtension */ export function removeExtension(name: string, persist = true) { - const del = delete extensions[name] - if (persist) persistExtensions() - return del + const del = delete extensions[name]; + if (persist) persistExtensions(); + return del; } /** @@ -75,10 +65,10 @@ export function removeExtension(name: string, persist = true) { * @returns {void} */ export function addExtension(extension: Extension, persist = true) { - if (extension.name) extensions[extension.name] = extension + if (extension.name) extensions[extension.name] = extension; if (persist) { - persistExtensions() - extension.subscribe('pe-persist', persistExtensions) + persistExtensions(); + extension.subscribe("pe-persist", persistExtensions); } } @@ -87,15 +77,15 @@ export function addExtension(extension: Extension, persist = true) { * @returns {void} */ export function persistExtensions() { - const persistData: Record = {} + const persistData: Record = {}; for (const name in extensions) { - persistData[name] = extensions[name] + persistData[name] = extensions[name]; } writeFileSync( ExtensionManager.instance.getExtensionsFile(), JSON.stringify(persistData), - 'utf8' - ) + "utf8" + ); } /** @@ -106,25 +96,25 @@ export function persistExtensions() { * @alias extensionManager.installExtensions */ export async function installExtensions(extensions: any, store = true) { - const installed: Extension[] = [] + const installed: Extension[] = []; for (const ext of extensions) { // Set install options and activation based on input type - const isObject = typeof ext === 'object' - const spec = isObject ? [ext.specifier, ext] : [ext] - const activate = isObject ? ext.activate !== false : true + const isObject = typeof ext === "object"; + const spec = isObject ? [ext.specifier, ext] : [ext]; + const activate = isObject ? ext.activate !== false : true; // Install and possibly activate extension - const extension = new Extension(...spec) - await extension._install() - if (activate) extension.setActive(true) + const extension = new Extension(...spec); + await extension._install(); + if (activate) extension.setActive(true); // Add extension to store if needed - if (store) addExtension(extension) - installed.push(extension) + if (store) addExtension(extension); + installed.push(extension); } // Return list of all installed extensions - return installed + return installed; } /** diff --git a/core/src/node/index.ts b/core/src/node/index.ts new file mode 100644 index 0000000000..0fdc821bcc --- /dev/null +++ b/core/src/node/index.ts @@ -0,0 +1,4 @@ +export * from './extension/index' +export * from './extension/extension' +export * from './extension/manager' +export * from './extension/store' diff --git a/electron/handlers/app.ts b/electron/handlers/app.ts index d2b3acda15..30a40b02a2 100644 --- a/electron/handlers/app.ts +++ b/electron/handlers/app.ts @@ -1,7 +1,7 @@ import { app, ipcMain, shell, nativeTheme } from 'electron' import { ModuleManager } from './../managers/module' import { join } from 'path' -import { ExtensionManager } from './../managers/extension' +import { ExtensionManager } from '../../common/extension' import { WindowManager } from './../managers/window' import { userSpacePath } from './../utils/path' import { AppRoute } from '@janhq/core' diff --git a/electron/handlers/extension.ts b/electron/handlers/extension.ts index f89206eac3..b1c1ef3145 100644 --- a/electron/handlers/extension.ts +++ b/electron/handlers/extension.ts @@ -6,10 +6,10 @@ import { getActiveExtensions, getAllExtensions, installExtensions, -} from './../extension/store' -import { getExtension } from './../extension/store' -import { removeExtension } from './../extension/store' -import Extension from './../extension/extension' +} from '../../common/extension/store' +import { getExtension } from '../../common/extension/store' +import { removeExtension } from '../../common/extension/store' +import Extension from '../../common/extension/extension' import { getResourcePath, userSpacePath } from './../utils/path' import { ExtensionRoute } from '@janhq/core' diff --git a/electron/handlers/fs.ts b/electron/handlers/fs.ts index 614461ef39..8bb7604919 100644 --- a/electron/handlers/fs.ts +++ b/electron/handlers/fs.ts @@ -1,217 +1,22 @@ import { ipcMain } from 'electron' -import * as fs from 'fs' -import fse from 'fs-extra' -import { join } from 'path' -import readline from 'readline' -import { userSpacePath } from './../utils/path' -import { FileSystemRoute } from '@janhq/core' +import { FileSystemRoute } from '@janhq/core' +import { userSpacePath } from '../utils/path' +import { join } from 'path' +const fs = require('fs') /** * Handles file system operations. */ export function handleFsIPCs() { - /** - * Gets the path to the user data directory. - * @param event - The event object. - * @returns A promise that resolves with the path to the user data directory. - */ - ipcMain.handle( - FileSystemRoute.getUserSpace, - (): Promise => Promise.resolve(userSpacePath) - ) - - /** - * Checks whether the path is a directory. - * @param event - The event object. - * @param path - The path to check. - * @returns A promise that resolves with a boolean indicating whether the path is a directory. - */ - ipcMain.handle( - FileSystemRoute.isDirectory, - (_event, path: string): Promise => { - const fullPath = join(userSpacePath, path) - return Promise.resolve( - fs.existsSync(fullPath) && fs.lstatSync(fullPath).isDirectory() + Object.values(FileSystemRoute).forEach((route) => { + ipcMain.handle(route, async (event, ...args) => { + return fs[route]( + ...args.map((arg) => + arg.includes('file:/') + ? join(userSpacePath, arg.replace('file:/', '')) + : arg + ) ) - } - ) - - /** - * Reads a file from the user data directory. - * @param event - The event object. - * @param path - The path of the file to read. - * @returns A promise that resolves with the contents of the file. - */ - ipcMain.handle( - FileSystemRoute.readFile, - async (event, path: string): Promise => { - return new Promise((resolve, reject) => { - fs.readFile(join(userSpacePath, path), 'utf8', (err, data) => { - if (err) { - reject(err) - } else { - resolve(data) - } - }) - }) - } - ) - - /** - * Checks whether a file exists in the user data directory. - * @param event - The event object. - * @param path - The path of the file to check. - * @returns A promise that resolves with a boolean indicating whether the file exists. - */ - ipcMain.handle(FileSystemRoute.exists, async (_event, path: string) => { - return new Promise((resolve, reject) => { - const fullPath = join(userSpacePath, path) - fs.existsSync(fullPath) ? resolve(true) : resolve(false) }) }) - - /** - * Writes data to a file in the user data directory. - * @param event - The event object. - * @param path - The path of the file to write to. - * @param data - The data to write to the file. - * @returns A promise that resolves when the file has been written. - */ - ipcMain.handle( - FileSystemRoute.writeFile, - async (event, path: string, data: string): Promise => { - try { - await fs.writeFileSync(join(userSpacePath, path), data, 'utf8') - } catch (err) { - console.error(`writeFile ${path} result: ${err}`) - } - } - ) - - /** - * Creates a directory in the user data directory. - * @param event - The event object. - * @param path - The path of the directory to create. - * @returns A promise that resolves when the directory has been created. - */ - ipcMain.handle( - FileSystemRoute.mkdir, - async (event, path: string): Promise => { - try { - fs.mkdirSync(join(userSpacePath, path), { recursive: true }) - } catch (err) { - console.error(`mkdir ${path} result: ${err}`) - } - } - ) - - /** - * Removes a directory in the user data directory. - * @param event - The event object. - * @param path - The path of the directory to remove. - * @returns A promise that resolves when the directory is removed successfully. - */ - ipcMain.handle( - FileSystemRoute.rmdir, - async (event, path: string): Promise => { - try { - await fs.rmSync(join(userSpacePath, path), { recursive: true }) - } catch (err) { - console.error(`rmdir ${path} result: ${err}`) - } - } - ) - - /** - * Lists the files in a directory in the user data directory. - * @param event - The event object. - * @param path - The path of the directory to list files from. - * @returns A promise that resolves with an array of file names. - */ - ipcMain.handle( - FileSystemRoute.listFiles, - async (event, path: string): Promise => { - return new Promise((resolve, reject) => { - fs.readdir(join(userSpacePath, path), (err, files) => { - if (err) { - reject(err) - } else { - resolve(files) - } - }) - }) - } - ) - - /** - * Deletes a file from the user data folder. - * @param _event - The IPC event object. - * @param filePath - The path to the file to delete. - * @returns A string indicating the result of the operation. - */ - ipcMain.handle(FileSystemRoute.deleteFile, async (_event, filePath) => { - try { - await fs.unlinkSync(join(userSpacePath, filePath)) - } catch (err) { - console.error(`unlink ${filePath} result: ${err}`) - } - }) - - /** - * Appends data to a file in the user data directory. - * @param event - The event object. - * @param path - The path of the file to append to. - * @param data - The data to append to the file. - * @returns A promise that resolves when the file has been written. - */ - ipcMain.handle( - FileSystemRoute.appendFile, - async (_event, path: string, data: string) => { - try { - await fs.appendFileSync(join(userSpacePath, path), data, 'utf8') - } catch (err) { - console.error(`appendFile ${path} result: ${err}`) - } - } - ) - - ipcMain.handle( - FileSystemRoute.copyFile, - async (_event, src: string, dest: string) => { - console.debug(`Copying file from ${src} to ${dest}`) - - return fse.copySync(src, dest, { overwrite: false }) - } - ) - - /** - * Reads a file line by line. - * @param event - The event object. - * @param path - The path of the file to read. - * @returns A promise that resolves with the contents of the file. - */ - ipcMain.handle( - FileSystemRoute.readLineByLine, - async (_event, path: string) => { - const fullPath = join(userSpacePath, path) - - return new Promise((res, rej) => { - try { - const readInterface = readline.createInterface({ - input: fs.createReadStream(fullPath), - }) - const lines: any = [] - readInterface - .on('line', function (line) { - lines.push(line) - }) - .on('close', function () { - res(lines) - }) - } catch (err) { - rej(err) - } - }) - } - ) } diff --git a/electron/main.ts b/electron/main.ts index 542875312b..e7a6d94f46 100644 --- a/electron/main.ts +++ b/electron/main.ts @@ -8,7 +8,7 @@ import { createUserSpace } from './utils/path' **/ import { WindowManager } from './managers/window' import { ModuleManager } from './managers/module' -import { ExtensionManager } from './managers/extension' +import { ExtensionManager } from '../common/extension' /** * IPC Handlers diff --git a/electron/managers/extension.ts b/electron/managers/extension.ts deleted file mode 100644 index 7eef24877e..0000000000 --- a/electron/managers/extension.ts +++ /dev/null @@ -1,85 +0,0 @@ -import { app } from 'electron' -import { init } from './../extension' -import { join, resolve } from 'path' -import { rmdir } from 'fs' -import Store from 'electron-store' -import { existsSync, mkdirSync, writeFileSync } from 'fs' -import { userSpacePath } from './../utils/path' -/** - * Manages extension installation and migration. - */ -export class ExtensionManager { - public static instance: ExtensionManager = new ExtensionManager() - - extensionsPath: string | undefined = undefined - - constructor() { - if (ExtensionManager.instance) { - return ExtensionManager.instance - } - } - - /** - * Sets up the extensions by initializing the `extensions` module with the `confirmInstall` and `extensionsPath` options. - * The `confirmInstall` function always returns `true` to allow extension installation. - * The `extensionsPath` option specifies the path to install extensions to. - */ - setupExtensions() { - init({ - // Function to check from the main process that user wants to install a extension - confirmInstall: async (_extensions: string[]) => { - return true - }, - // Path to install extension to - extensionsPath: join(userSpacePath, 'extensions'), - }) - } - - /** - * Migrates the extensions by deleting the `extensions` directory in the user data path. - * If the `migrated_version` key in the `Store` object does not match the current app version, - * the function deletes the `extensions` directory and sets the `migrated_version` key to the current app version. - * @returns A Promise that resolves when the migration is complete. - */ - migrateExtensions() { - return new Promise((resolve) => { - const store = new Store() - if (store.get('migrated_version') !== app.getVersion()) { - console.debug('start migration:', store.get('migrated_version')) - const fullPath = join(userSpacePath, 'extensions') - - rmdir(fullPath, { recursive: true }, function (err) { - if (err) console.error(err) - store.set('migrated_version', app.getVersion()) - console.debug('migrate extensions done') - resolve(undefined) - }) - } else { - resolve(undefined) - } - }) - } - - setExtensionsPath(extPath: string) { - // Create folder if it does not exist - let extDir - try { - extDir = resolve(extPath) - if (extDir.length < 2) throw new Error() - - if (!existsSync(extDir)) mkdirSync(extDir) - - const extensionsJson = join(extDir, 'extensions.json') - if (!existsSync(extensionsJson)) - writeFileSync(extensionsJson, '{}', 'utf8') - - this.extensionsPath = extDir - } catch (error) { - throw new Error('Invalid path provided to the extensions folder') - } - } - - getExtensionsFile() { - return join(this.extensionsPath ?? '', 'extensions.json') - } -} diff --git a/electron/tsconfig.json b/electron/tsconfig.json index 3cc218f93e..8c612de854 100644 --- a/electron/tsconfig.json +++ b/electron/tsconfig.json @@ -15,6 +15,6 @@ "paths": { "*": ["node_modules/*"] }, "typeRoots": ["node_modules/@types"] }, - "include": ["./**/*.ts"], + "include": ["./**/*.ts", "../common/extension/manager.ts"], "exclude": ["core", "build", "dist", "tests", "node_modules"] } diff --git a/electron/utils/migration.ts b/electron/utils/migration.ts new file mode 100644 index 0000000000..cf66270c6c --- /dev/null +++ b/electron/utils/migration.ts @@ -0,0 +1,30 @@ +import { app } from 'electron' +import { join } from 'path' + +import { rmdir } from 'fs' +import Store from 'electron-store' +import { userSpacePath } from './path' +/** + * Migrates the extensions by deleting the `extensions` directory in the user data path. + * If the `migrated_version` key in the `Store` object does not match the current app version, + * the function deletes the `extensions` directory and sets the `migrated_version` key to the current app version. + * @returns A Promise that resolves when the migration is complete. + */ +export function migrateExtensions() { + return new Promise((resolve) => { + const store = new Store() + if (store.get('migrated_version') !== app.getVersion()) { + console.debug('start migration:', store.get('migrated_version')) + const fullPath = join(userSpacePath, 'extensions') + + rmdir(fullPath, { recursive: true }, function (err) { + if (err) console.error(err) + store.set('migrated_version', app.getVersion()) + console.debug('migrate extensions done') + resolve(undefined) + }) + } else { + resolve(undefined) + } + }) +} diff --git a/extensions/assistant-extension/src/index.ts b/extensions/assistant-extension/src/index.ts index 3e1ab4898b..099c7c2971 100644 --- a/extensions/assistant-extension/src/index.ts +++ b/extensions/assistant-extension/src/index.ts @@ -3,17 +3,18 @@ import { AssistantExtension } from "@janhq/core"; import { join } from "path"; export default class JanAssistantExtension implements AssistantExtension { - private static readonly _homeDir = "assistants"; + private static readonly _homeDir = "file://assistants"; type(): ExtensionType { return ExtensionType.Assistant; } - onLoad(): void { + async onLoad() { // making the assistant directory - fs.mkdir(JanAssistantExtension._homeDir).then(() => { - this.createJanAssistant(); - }); + if (!(await fs.existsSync(JanAssistantExtension._homeDir))) + fs.mkdirSync(JanAssistantExtension._homeDir).then(() => { + this.createJanAssistant(); + }); } /** @@ -27,12 +28,12 @@ export default class JanAssistantExtension implements AssistantExtension { // TODO: check if the directory already exists, then ignore creation for now const assistantDir = join(JanAssistantExtension._homeDir, assistant.id); - await fs.mkdir(assistantDir); + if (!(await fs.existsSync(assistantDir))) await fs.mkdirSync(assistantDir); // store the assistant metadata json const assistantMetadataPath = join(assistantDir, "assistant.json"); try { - await fs.writeFile( + await fs.writeFileSync( assistantMetadataPath, JSON.stringify(assistant, null, 2) ); @@ -45,18 +46,13 @@ export default class JanAssistantExtension implements AssistantExtension { // get all the assistant directories // get all the assistant metadata json const results: Assistant[] = []; - const allFileName: string[] = await fs.listFiles( + const allFileName: string[] = await fs.readdirSync( JanAssistantExtension._homeDir ); for (const fileName of allFileName) { const filePath = join(JanAssistantExtension._homeDir, fileName); - const isDirectory = await fs.isDirectory(filePath); - if (!isDirectory) { - // if not a directory, ignore - continue; - } - const jsonFiles: string[] = (await fs.listFiles(filePath)).filter( + const jsonFiles: string[] = (await fs.readdirSync(filePath)).filter( (file: string) => file === "assistant.json" ); @@ -65,9 +61,9 @@ export default class JanAssistantExtension implements AssistantExtension { continue; } - const assistant: Assistant = JSON.parse( - await fs.readFile(join(filePath, jsonFiles[0])) - ); + const content = await fs.readFileSync(join(filePath, jsonFiles[0])); + const assistant: Assistant = + typeof content === "object" ? content : JSON.parse(content); results.push(assistant); } @@ -82,7 +78,7 @@ export default class JanAssistantExtension implements AssistantExtension { // remove the directory const assistantDir = join(JanAssistantExtension._homeDir, assistant.id); - await fs.rmdir(assistantDir); + await fs.rmdirSync(assistantDir); return Promise.resolve(); } diff --git a/extensions/conversational-extension/src/index.ts b/extensions/conversational-extension/src/index.ts index 2c2c7e47f6..13842086e4 100644 --- a/extensions/conversational-extension/src/index.ts +++ b/extensions/conversational-extension/src/index.ts @@ -10,7 +10,7 @@ import { join } from 'path' export default class JSONConversationalExtension implements ConversationalExtension { - private static readonly _homeDir = 'threads' + private static readonly _homeDir = 'file://threads' private static readonly _threadInfoFileName = 'thread.json' private static readonly _threadMessagesFileName = 'messages.jsonl' @@ -24,8 +24,9 @@ export default class JSONConversationalExtension /** * Called when the extension is loaded. */ - onLoad() { - fs.mkdir(JSONConversationalExtension._homeDir) + async onLoad() { + if (!(await fs.existsSync(JSONConversationalExtension._homeDir))) + fs.mkdirSync(JSONConversationalExtension._homeDir) console.debug('JSONConversationalExtension loaded') } @@ -48,7 +49,9 @@ export default class JSONConversationalExtension const convos = promiseResults .map((result) => { if (result.status === 'fulfilled') { - return JSON.parse(result.value) as Thread + return typeof result.value === 'object' + ? result.value + : JSON.parse(result.value) } }) .filter((convo) => convo != null) @@ -77,8 +80,11 @@ export default class JSONConversationalExtension threadDirPath, JSONConversationalExtension._threadInfoFileName ) - await fs.mkdir(threadDirPath) - await fs.writeFile(threadJsonPath, JSON.stringify(thread, null, 2)) + if (!(await fs.existsSync(threadDirPath))) { + await fs.mkdirSync(threadDirPath) + } + + await fs.writeFileSync(threadJsonPath, JSON.stringify(thread)) Promise.resolve() } catch (err) { Promise.reject(err) @@ -90,7 +96,9 @@ export default class JSONConversationalExtension * @param threadId The ID of the thread to delete. */ deleteThread(threadId: string): Promise { - return fs.rmdir(join(JSONConversationalExtension._homeDir, `${threadId}`)) + return fs.rmdirSync( + join(JSONConversationalExtension._homeDir, `${threadId}`) + ) } async addNewMessage(message: ThreadMessage): Promise { @@ -103,8 +111,9 @@ export default class JSONConversationalExtension threadDirPath, JSONConversationalExtension._threadMessagesFileName ) - await fs.mkdir(threadDirPath) - await fs.appendFile(threadMessagePath, JSON.stringify(message) + '\n') + if (!(await fs.existsSync(threadDirPath))) + await fs.mkdirSync(threadDirPath) + await fs.appendFileSync(threadMessagePath, JSON.stringify(message) + '\n') Promise.resolve() } catch (err) { Promise.reject(err) @@ -121,8 +130,9 @@ export default class JSONConversationalExtension threadDirPath, JSONConversationalExtension._threadMessagesFileName ) - await fs.mkdir(threadDirPath) - await fs.writeFile( + if (!(await fs.existsSync(threadDirPath))) + await fs.mkdirSync(threadDirPath) + await fs.writeFileSync( threadMessagePath, messages.map((msg) => JSON.stringify(msg)).join('\n') + '\n' ) @@ -138,7 +148,7 @@ export default class JSONConversationalExtension * @returns data of the thread */ private async readThread(threadDirName: string): Promise { - return fs.readFile( + return fs.readFileSync( join( JSONConversationalExtension._homeDir, threadDirName, @@ -152,7 +162,7 @@ export default class JSONConversationalExtension * @private */ private async getValidThreadDirs(): Promise { - const fileInsideThread: string[] = await fs.listFiles( + const fileInsideThread: string[] = await fs.readdirSync( JSONConversationalExtension._homeDir ) @@ -162,13 +172,8 @@ export default class JSONConversationalExtension JSONConversationalExtension._homeDir, fileInsideThread[i] ) - const isDirectory = await fs.isDirectory(path) - if (!isDirectory) { - console.debug(`Ignore ${path} because it is not a directory`) - continue - } - const isHavingThreadInfo = (await fs.listFiles(path)).includes( + const isHavingThreadInfo = (await fs.readdirSync(path)).includes( JSONConversationalExtension._threadInfoFileName ) if (!isHavingThreadInfo) { @@ -184,12 +189,8 @@ export default class JSONConversationalExtension async getAllMessages(threadId: string): Promise { try { const threadDirPath = join(JSONConversationalExtension._homeDir, threadId) - const isDir = await fs.isDirectory(threadDirPath) - if (!isDir) { - throw Error(`${threadDirPath} is not directory`) - } - const files: string[] = await fs.listFiles(threadDirPath) + const files: string[] = await fs.readdirSync(threadDirPath) if ( !files.includes(JSONConversationalExtension._threadMessagesFileName) ) { @@ -201,7 +202,12 @@ export default class JSONConversationalExtension JSONConversationalExtension._threadMessagesFileName ) - const result = await fs.readLineByLine(messageFilePath) + const result = await fs.readFileSync(messageFilePath).then((content) => + content + .toString() + .split('\n') + .filter((line) => line !== '') + ) const messages: ThreadMessage[] = [] result.forEach((line: string) => { diff --git a/extensions/inference-nitro-extension/src/index.ts b/extensions/inference-nitro-extension/src/index.ts index 975d94100a..650202653a 100644 --- a/extensions/inference-nitro-extension/src/index.ts +++ b/extensions/inference-nitro-extension/src/index.ts @@ -12,7 +12,6 @@ import { EventName, MessageRequest, MessageStatus, - ModelSettingParams, ExtensionType, ThreadContent, ThreadMessage, @@ -58,8 +57,9 @@ export default class JanInferenceNitroExtension implements InferenceExtension { /** * Subscribes to events emitted by the @janhq/core package. */ - onLoad(): void { - fs.mkdir(JanInferenceNitroExtension._homeDir); + async onLoad() { + if (!(await fs.existsSync(JanInferenceNitroExtension._homeDir))) + fs.mkdirSync(JanInferenceNitroExtension._homeDir); this.writeDefaultEngineSettings(); // Events subscription @@ -85,19 +85,18 @@ export default class JanInferenceNitroExtension implements InferenceExtension { */ onUnload(): void {} - private async writeDefaultEngineSettings() { try { const engineFile = join( JanInferenceNitroExtension._homeDir, JanInferenceNitroExtension._engineMetadataFileName ); - if (await fs.exists(engineFile)) { + if (await fs.existsSync(engineFile)) { JanInferenceNitroExtension._engineSettings = JSON.parse( - await fs.readFile(engineFile) + await fs.readFileSync(engineFile) ); } else { - await fs.writeFile( + await fs.writeFileSync( engineFile, JSON.stringify(JanInferenceNitroExtension._engineSettings, null, 2) ); diff --git a/extensions/inference-openai-extension/src/index.ts b/extensions/inference-openai-extension/src/index.ts index 7e3e6e71e8..71c03b1f60 100644 --- a/extensions/inference-openai-extension/src/index.ts +++ b/extensions/inference-openai-extension/src/index.ts @@ -12,7 +12,6 @@ import { EventName, MessageRequest, MessageStatus, - ModelSettingParams, ExtensionType, ThreadContent, ThreadMessage, @@ -31,7 +30,7 @@ import { EngineSettings, OpenAIModel } from "./@types/global"; * It also subscribes to events emitted by the @janhq/core package and handles new message requests. */ export default class JanInferenceOpenAIExtension implements InferenceExtension { - private static readonly _homeDir = "engines"; + private static readonly _homeDir = "file://engines"; private static readonly _engineMetadataFileName = "openai.json"; private static _currentModel: OpenAIModel; @@ -55,8 +54,9 @@ export default class JanInferenceOpenAIExtension implements InferenceExtension { /** * Subscribes to events emitted by the @janhq/core package. */ - onLoad(): void { - fs.mkdir(JanInferenceOpenAIExtension._homeDir); + async onLoad() { + if (!(await fs.existsSync(JanInferenceOpenAIExtension._homeDir))) + fs.mkdirSync(JanInferenceOpenAIExtension._homeDir); JanInferenceOpenAIExtension.writeDefaultEngineSettings(); // Events subscription @@ -87,12 +87,17 @@ export default class JanInferenceOpenAIExtension implements InferenceExtension { JanInferenceOpenAIExtension._homeDir, JanInferenceOpenAIExtension._engineMetadataFileName ); - if (await fs.exists(engineFile)) { - JanInferenceOpenAIExtension._engineSettings = JSON.parse( - await fs.readFile(engineFile) - ); + if (await fs.existsSync(engineFile)) { + try { + JanInferenceOpenAIExtension._engineSettings = JSON.parse( + await fs.readFileSync(engineFile) + ); + } catch { + JanInferenceOpenAIExtension._engineSettings = + await fs.readFileSync(engineFile); + } } else { - await fs.writeFile( + await fs.writeFileSync( engineFile, JSON.stringify(JanInferenceOpenAIExtension._engineSettings, null, 2) ); diff --git a/extensions/model-extension/src/index.ts b/extensions/model-extension/src/index.ts index d0267b84e6..777fdbedaf 100644 --- a/extensions/model-extension/src/index.ts +++ b/extensions/model-extension/src/index.ts @@ -13,7 +13,7 @@ import { join } from 'path' * A extension for models */ export default class JanModelExtension implements ModelExtension { - private static readonly _homeDir = 'models' + private static readonly _homeDir = 'file://models' private static readonly _modelMetadataFileName = 'model.json' /** @@ -42,11 +42,10 @@ export default class JanModelExtension implements ModelExtension { private async copyModelsToHomeDir() { try { // list all of the files under the home directory - const files = await fs.listFiles('') - if (files.includes(JanModelExtension._homeDir)) { + if (fs.existsSync(JanModelExtension._homeDir)) { // ignore if the model is already downloaded - console.debug('Model already downloaded') + console.debug('Models already persisted.') return } @@ -57,7 +56,7 @@ export default class JanModelExtension implements ModelExtension { const userSpace = await getUserSpace() const destPath = join(userSpace, JanModelExtension._homeDir) - await fs.copyFile(srcPath, destPath) + await fs.copyFileSync(srcPath, destPath) } catch (err) { console.error(err) } @@ -71,7 +70,7 @@ export default class JanModelExtension implements ModelExtension { async downloadModel(model: Model): Promise { // create corresponding directory const directoryPath = join(JanModelExtension._homeDir, model.id) - await fs.mkdir(directoryPath) + if (!(await fs.existsSync(directoryPath))) await fs.mkdirSync(directoryPath) // path to model binary const path = join(directoryPath, model.id) @@ -87,7 +86,7 @@ export default class JanModelExtension implements ModelExtension { return abortDownload( join(JanModelExtension._homeDir, modelId, modelId) ).then(() => { - fs.deleteFile(join(JanModelExtension._homeDir, modelId, modelId)) + fs.unlinkSync(join(JanModelExtension._homeDir, modelId, modelId)) }) } @@ -101,10 +100,10 @@ export default class JanModelExtension implements ModelExtension { const dirPath = join(JanModelExtension._homeDir, modelId) // remove all files under dirPath except model.json - const files = await fs.listFiles(dirPath) + const files = await fs.readdirSync(dirPath) const deletePromises = files.map((fileName: string) => { if (fileName !== JanModelExtension._modelMetadataFileName) { - return fs.deleteFile(join(dirPath, fileName)) + return fs.unlinkSync(join(dirPath, fileName)) } }) await Promise.allSettled(deletePromises) @@ -114,11 +113,11 @@ export default class JanModelExtension implements ModelExtension { dirPath, JanModelExtension._modelMetadataFileName ) - const json = await fs.readFile(jsonFilePath) + const json = await fs.readFileSync(jsonFilePath) const model = JSON.parse(json) as Model delete model.state - await fs.writeFile(jsonFilePath, JSON.stringify(model, null, 2)) + await fs.writeFileSync(jsonFilePath, JSON.stringify(model, null, 2)) } catch (err) { console.error(err) } @@ -137,7 +136,7 @@ export default class JanModelExtension implements ModelExtension { ) try { - await fs.writeFile( + await fs.writeFileSync( jsonFilePath, JSON.stringify( { @@ -164,22 +163,17 @@ export default class JanModelExtension implements ModelExtension { private async getModelsMetadata(): Promise { try { - const filesUnderJanRoot = await fs.listFiles('') - if (!filesUnderJanRoot.includes(JanModelExtension._homeDir)) { + if (!(await fs.existsSync(JanModelExtension._homeDir))) { console.debug('model folder not found') return [] } - const files: string[] = await fs.listFiles(JanModelExtension._homeDir) + const files: string[] = await fs.readdirSync(JanModelExtension._homeDir) const allDirectories: string[] = [] for (const file of files) { - const isDirectory = await fs.isDirectory( - join(JanModelExtension._homeDir, file) - ) - if (isDirectory) { - allDirectories.push(file) - } + //TODO: add back directory check + if (!file.includes('.')) allDirectories.push(file) } const readJsonPromises = allDirectories.map((dirName) => { @@ -191,13 +185,21 @@ export default class JanModelExtension implements ModelExtension { return this.readModelMetadata(jsonPath) }) const results = await Promise.allSettled(readJsonPromises) - const modelData = results.map((result) => { - if (result.status === 'fulfilled') { - return JSON.parse(result.value) as Model - } else { - console.error(result.reason) - } - }) + const modelData = results + .map((result) => { + if (result.status === 'fulfilled') { + try { + return JSON.parse(result.value) + } catch { + return result.value + } + } else { + console.error(result.reason) + return undefined + } + }) + .filter((e) => !!e) + return modelData } catch (err) { console.error(err) @@ -206,7 +208,7 @@ export default class JanModelExtension implements ModelExtension { } private readModelMetadata(path: string) { - return fs.readFile(join(path)) + return fs.readFileSync(join(path)) } /** diff --git a/server/data/.gitkeep b/server/data/.gitkeep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/server/data/models/.gitkeep b/server/data/models/.gitkeep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/server/data/threads/.gitkeep b/server/data/threads/.gitkeep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/server/icons/icon.png b/server/icons/icon.png deleted file mode 100644 index 289f99ded85e1e3cc91b17af6b607d2cafd97cd7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 38651 zcmd3NWmjCmwr%4Uf(Q5D5G=U6yL%EW1b4UK1a~L627 z(G9z*man;Hg()jap&}C?gFqlu8EJ7<5C|Ih6&i#H4?M2jW*>nElAW}UBM5ZD{q_T8 z&oB)90>XEa&~{R@HFI+P>R<|Tb#?t@VPolN{MF9%ldXe!`WZg~2t)>w5f@Q+%Q#te z|6-ugba#1PbBFJsSV(Qb%YvJuz(BFo1ShX2j&b1EkHYO==}_rWY1nlbu6yJML!SpN z0p?aUY0PXeiDi%p9zkhy>@K2P$52}Ci^a0nQ4;T{Jd^LkVYpPaz^!}BP2JZ zV_sR8MO7MZs*_}@1M>^Z88lMOI8qIsPy_)FMoUmN)_*=B@H>I+eESBTj1THB@GOTK z{Qu}rXg|DdyxjjJ3qdPVE0K;wH%N-zgfvs&C4oa_zxq)~Wv-ZAJINH4yW@wh!M=w_ z4PyNIHCkdvfZ@#Q3FG(gDJ%FQ{Fb1KHif4Tu{Nb%)b!j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7>L;#Dzw+D^}32T~s!qCJi3sM5p%O1toW{LThpsYB;x|ex_t#$8Sx1S$nyx#g0 zXo4&#vA5pxOC?MwkHE^jtz0nt&S;Zu9WrJi@5;h{cif?)CPxbC9Y80;&3{@T z+Hclh&OwF#AzFL%(nKJ>TEFi}pL13F45p0ikUz0q-Sj;vI>%)gZF`st{&UwEbQfVj zy@@>(%RKT0t-X}8mu*w)GffIEdfrnWKWj_a=8Mg_OL#kowq;ed?$l>QX+`-wIkEbt z&hm}FCx&lWLCcwW=0;ZclK+KkEzv!T&>G9^ik8^5 zjzRyHpKn}e`WaI-&Q}{E-LyVJ7>CvE`Clz@&D6JwF-s=IFBD&KY>7syw&h&CV!pU} zwEIUlo|1U06D%IV@V5_7d+47RwXMGCt7>`eRgKe|Ab~OE5oP~tCsD#a1UsR2^;92( zTcTBrLW7>%y|-SzNmYm5uNvZY { + childContext.register(require("@fastify/static"), { + root: process.env.EXTENSION_ROOT, // docs is a folder that contains `index.html` and `404.html` + wildcard: false, + }); -server.listen({ - port: JAN_API_PORT, - host: JAN_API_HOST -}).then(() => { - console.log(`JAN API listening at: http://${JAN_API_HOST}:${JAN_API_PORT}`); -}) + done(); + }, + { prefix: "extensions" } +); +server.register(v1API, { prefix: "/api/v1" }); +server + .listen({ + port: JAN_API_PORT, + host: JAN_API_HOST, + }) + .then(() => { + console.log(`JAN API listening at: http://${JAN_API_HOST}:${JAN_API_PORT}`); + }); diff --git a/server/package.json b/server/package.json index 1fd06a4826..3d8dd51f31 100644 --- a/server/package.json +++ b/server/package.json @@ -14,6 +14,9 @@ "build": "tsc" }, "dependencies": { + "@fastify/cors": "^8.4.2", + "@fastify/static": "^6.12.0", + "core": "link:./core" }, "devDependencies": { "@types/body-parser": "^1.19.5", diff --git a/server/tsconfig.json b/server/tsconfig.json index 3363fdba62..be5eb64055 100644 --- a/server/tsconfig.json +++ b/server/tsconfig.json @@ -13,10 +13,11 @@ "allowJs": true, "skipLibCheck": true, "paths": { "*": ["node_modules/*"] }, - "typeRoots": ["node_modules/@types"] + "typeRoots": ["node_modules/@types"], + "ignoreDeprecations": "5.0" }, // "sourceMap": true, - + "include": ["./**/*.ts"], "exclude": ["core", "build", "dist", "tests", "node_modules"] } diff --git a/server/v1/assistants/index.ts b/server/v1/assistants/index.ts deleted file mode 100644 index c722195d02..0000000000 --- a/server/v1/assistants/index.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { FastifyInstance, FastifyPluginAsync, FastifyPluginOptions } from 'fastify' - -const router: FastifyPluginAsync = async (app: FastifyInstance, opts: FastifyPluginOptions) => { - //TODO: Add controllers for assistants here - // app.get("/", controller) - // app.post("/", controller) -} -export default router; \ No newline at end of file diff --git a/server/v1/chat/index.ts b/server/v1/chat/index.ts deleted file mode 100644 index cb5fbf120a..0000000000 --- a/server/v1/chat/index.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { FastifyInstance, FastifyPluginAsync, FastifyPluginOptions } from 'fastify' - -const router: FastifyPluginAsync = async (app: FastifyInstance, opts: FastifyPluginOptions) => { - //TODO: Add controllers for here - // app.get("/", controller) - - app.post("/", (req, res) => { - req.body - }) -} -export default router; \ No newline at end of file diff --git a/server/v1/extension/index.ts b/server/v1/extension/index.ts new file mode 100644 index 0000000000..e4a8ca7cab --- /dev/null +++ b/server/v1/extension/index.ts @@ -0,0 +1,38 @@ +import { + FastifyInstance, + FastifyPluginAsync, + FastifyPluginOptions, +} from "fastify"; +import { join, extname } from "path"; +import { ExtensionRoute } from "@janhq/core"; + +import { readdirSync } from "fs"; + +const node = require("@janhq/core/dist/node/index.cjs"); + +const router: FastifyPluginAsync = async ( + app: FastifyInstance, + opts: FastifyPluginOptions +) => { + // TODO: Share code between node projects + app.post(`/${ExtensionRoute.getActiveExtensions}`, async (req, res) => { + const activeExtensions = await node.getActiveExtensions(); + res.status(200).send(activeExtensions); + }); + + app.post(`/${ExtensionRoute.baseExtensions}`, async (req, res) => { + const baseExtensionPath = join(__dirname, "..", "..", "..", "pre-install"); + const extensions = readdirSync(baseExtensionPath) + .filter((file) => extname(file) === ".tgz") + .map((file) => join(baseExtensionPath, file)); + + res.status(200).send(extensions); + }); + + app.post(`/${ExtensionRoute.installExtension}`, async (req, res) => { + const extensions = req.body as any; + const installed = await node.installExtensions(JSON.parse(extensions)[0]); + return JSON.parse(JSON.stringify(installed)); + }); +}; +export default router; diff --git a/server/v1/fs/index.ts b/server/v1/fs/index.ts new file mode 100644 index 0000000000..99f7de415e --- /dev/null +++ b/server/v1/fs/index.ts @@ -0,0 +1,34 @@ +import { + FastifyInstance, + FastifyPluginAsync, + FastifyPluginOptions, +} from "fastify"; +import { FileSystemRoute } from "@janhq/core"; +import { join } from "path"; +const { userSpacePath } = require("@janhq/core/dist/node/index.cjs"); +const fs = require("fs"); + +const router: FastifyPluginAsync = async ( + app: FastifyInstance, + opts: FastifyPluginOptions +) => { + // Generate handlers for each fs route + Object.values(FileSystemRoute).forEach((route) => { + app.post(`/${route}`, async (req, res) => { + const body = JSON.parse(req.body as any); + try { + const result = await fs[route]( + ...body.map((arg: any) => + arg.includes("file:/") + ? join(userSpacePath, arg.replace("file:/", "")) + : arg + ) + ); + res.status(200).send(result); + } catch (ex) { + console.log(ex); + } + }); + }); +}; +export default router; diff --git a/server/v1/index.ts b/server/v1/index.ts index 89d73200b1..e82855b2ff 100644 --- a/server/v1/index.ts +++ b/server/v1/index.ts @@ -1,37 +1,14 @@ -import assistantsAPI from './assistants' -import chatCompletionAPI from './chat' -import modelsAPI from './models' -import threadsAPI from './threads' +import fsAPI from "./fs"; +import extAPI from "./extension" -import { FastifyInstance, FastifyPluginAsync } from 'fastify' +import { FastifyInstance, FastifyPluginAsync } from "fastify"; const router: FastifyPluginAsync = async (app: FastifyInstance, opts) => { - app.register( - assistantsAPI, - { - prefix: "/assistants" - } - ) - - app.register( - chatCompletionAPI, - { - prefix: "/chat/completion" - } - ) - - app.register( - modelsAPI, - { - prefix: "/models" - } - ) - - app.register( - threadsAPI, - { - prefix: "/threads" - } - ) -} -export default router; \ No newline at end of file + app.register(fsAPI, { + prefix: "/fs", + }); + app.register(extAPI, { + prefix: "/extension", + }); +}; +export default router; diff --git a/server/v1/models/downloadModel.ts b/server/v1/models/downloadModel.ts deleted file mode 100644 index d564a22074..0000000000 --- a/server/v1/models/downloadModel.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { RouteHandlerMethod, FastifyRequest, FastifyReply } from 'fastify' -import { MODEL_FOLDER_PATH } from "./index" -import fs from 'fs/promises' - -const controller: RouteHandlerMethod = async (req: FastifyRequest, res: FastifyReply) => { - //TODO: download models impl - //Mirror logic from JanModelExtension.downloadModel? - let model = req.body.model; - - // Fetching logic - // const directoryPath = join(MODEL_FOLDER_PATH, model.id) - // await fs.mkdir(directoryPath) - - // const path = join(directoryPath, model.id) - // downloadFile(model.source_url, path) - // TODO: Different model downloader from different model vendor - - res.status(200).send({ - status: "Ok" - }) -} - -export default controller; \ No newline at end of file diff --git a/server/v1/models/index.ts b/server/v1/models/index.ts deleted file mode 100644 index 22c5513000..0000000000 --- a/server/v1/models/index.ts +++ /dev/null @@ -1,61 +0,0 @@ - -export const MODEL_FOLDER_PATH = "./data/models" -export const _modelMetadataFileName = 'model.json' - -import fs from 'fs/promises' -import { Model } from '@janhq/core' -import { join } from 'path' - -// map string => model object -let modelIndex = new Map(); -async function buildModelIndex(){ - let modelIds = await fs.readdir(MODEL_FOLDER_PATH); - // TODO: read modelFolders to get model info, mirror JanModelExtension? - try{ - for(let modelId in modelIds){ - let path = join(MODEL_FOLDER_PATH, modelId) - let fileData = await fs.readFile(join(path, _modelMetadataFileName)) - modelIndex.set(modelId, JSON.parse(fileData.toString("utf-8")) as Model) - } - } - catch(err){ - console.error("build model index failed. ", err); - } -} -buildModelIndex() - -import { FastifyInstance, FastifyPluginAsync, FastifyPluginOptions } from 'fastify' -import downloadModelController from './downloadModel' -import { startModel, stopModel } from './modelOp' - -const router: FastifyPluginAsync = async (app: FastifyInstance, opts: FastifyPluginOptions) => { - //TODO: Add controllers declaration here - - ///////////// CRUD //////////////// - // Model listing - app.get("/", async (req, res) => { - res.status(200).send( - modelIndex.values() - ) - }) - - // Retrieve model info - app.get("/:id", (req, res) => { - res.status(200).send( - modelIndex.get(req.params.id) - ) - }) - - // Delete model - app.delete("/:id", (req, res) => { - modelIndex.delete(req.params) - - // TODO: delete on disk - }) - - ///////////// Other ops //////////////// - app.post("/", downloadModelController) - app.put("/start", startModel) - app.put("/stop", stopModel) -} -export default router; \ No newline at end of file diff --git a/server/v1/models/modelOp.ts b/server/v1/models/modelOp.ts deleted file mode 100644 index f2c7ffe75b..0000000000 --- a/server/v1/models/modelOp.ts +++ /dev/null @@ -1,11 +0,0 @@ -import {FastifyRequest, FastifyReply} from 'fastify' - -export async function startModel(req: FastifyRequest, res: FastifyReply): Promise { - - -} - -export async function stopModel(req: FastifyRequest, res: FastifyReply): Promise { - - -} \ No newline at end of file diff --git a/server/v1/threads/index.ts b/server/v1/threads/index.ts deleted file mode 100644 index e63f9e8d8e..0000000000 --- a/server/v1/threads/index.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { FastifyInstance, FastifyPluginAsync, FastifyPluginOptions } from 'fastify' - -const router: FastifyPluginAsync = async (app: FastifyInstance, opts: FastifyPluginOptions) => { - //TODO: Add controllers declaration here - - // app.get() -} -export default router; \ No newline at end of file diff --git a/web/containers/Layout/index.tsx b/web/containers/Layout/index.tsx index 12f1192505..d0d22d24c5 100644 --- a/web/containers/Layout/index.tsx +++ b/web/containers/Layout/index.tsx @@ -22,11 +22,11 @@ const BaseLayout = (props: PropsWithChildren) => { async function setTheme() { switch (theme) { case 'light': - return await window?.electronAPI.setNativeThemeLight() + return await window?.electronAPI?.setNativeThemeLight() case 'dark': - return await window?.electronAPI.setNativeThemeDark() + return await window?.electronAPI?.setNativeThemeDark() default: - return await window?.electronAPI.setNativeThemeSystem() + return await window?.electronAPI?.setNativeThemeSystem() } } setTheme() diff --git a/web/extension/ExtensionManager.ts b/web/extension/ExtensionManager.ts index 4a53cb4915..43847f3447 100644 --- a/web/extension/ExtensionManager.ts +++ b/web/extension/ExtensionManager.ts @@ -81,7 +81,10 @@ export class ExtensionManager { */ async activateExtension(extension: Extension) { // Import class - await import(/* webpackIgnore: true */ extension.url).then( + const extensionUrl = window.electronAPI + ? extension.url + : extension.url.replace('extension://', `${API_BASE_URL}/extensions/`) + await import(/* webpackIgnore: true */ extensionUrl).then( (extensionClass) => { // Register class if it has a default export if ( diff --git a/web/next.config.js b/web/next.config.js index fd860aa5c7..c1350d9d58 100644 --- a/web/next.config.js +++ b/web/next.config.js @@ -28,6 +28,7 @@ const nextConfig = { 'https://cdn.jsdelivr.net/npm/@janhq/plugin-catalog@latest/dist/index.js' ), VERSION: JSON.stringify(packageJson.version), + API_BASE_URL: JSON.stringify('http://localhost:1337'), }), ] return config diff --git a/web/package.json b/web/package.json index dd7faeb1d5..15d2830b09 100644 --- a/web/package.json +++ b/web/package.json @@ -38,7 +38,6 @@ "sass": "^1.69.4", "tailwind-merge": "^2.0.0", "tailwindcss": "3.3.5", - "typescript": "5.2.2", "ulid": "^2.3.0", "uuid": "^9.0.1", "zod": "^3.22.4" diff --git a/web/screens/Settings/Appearance/ToggleTheme.tsx b/web/screens/Settings/Appearance/ToggleTheme.tsx index ff1c1c7ac2..47b9882441 100644 --- a/web/screens/Settings/Appearance/ToggleTheme.tsx +++ b/web/screens/Settings/Appearance/ToggleTheme.tsx @@ -11,11 +11,11 @@ export default function ToggleTheme() { const handeleNativeTheme = async (val: string) => { switch (val) { case 'light': - return await window?.electronAPI.setNativeThemeLight() + return await window?.electronAPI?.setNativeThemeLight() case 'dark': - return await window?.electronAPI.setNativeThemeDark() + return await window?.electronAPI?.setNativeThemeDark() default: - return await window?.electronAPI.setNativeThemeSystem() + return await window?.electronAPI?.setNativeThemeSystem() } } diff --git a/web/screens/Settings/Models/index.tsx b/web/screens/Settings/Models/index.tsx index 79859c2758..3c5a0c6e3f 100644 --- a/web/screens/Settings/Models/index.tsx +++ b/web/screens/Settings/Models/index.tsx @@ -15,7 +15,7 @@ export default function Models() { const [searchValue, setsearchValue] = useState('') const filteredDownloadedModels = downloadedModels.filter((x) => { - return x.name.toLowerCase().includes(searchValue.toLowerCase()) + return x.name?.toLowerCase().includes(searchValue.toLowerCase()) }) return ( diff --git a/web/services/cloudNativeService.ts b/web/services/cloudNativeService.ts deleted file mode 100644 index a300ac02d9..0000000000 --- a/web/services/cloudNativeService.ts +++ /dev/null @@ -1,76 +0,0 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ -import { toast } from 'react-toastify' -const API_BASE_PATH: string = '/api/v1' - -export function openExternalUrl(url: string) { - window?.open(url, '_blank') -} - -export async function appVersion() { - return Promise.resolve(VERSION) -} - -export function invokeExtensionFunc( - modulePath: string, - extensionFunc: string, - ...args: any -): Promise { - return fetchApi(modulePath, extensionFunc, args).catch((err: Error) => { - throw err - }) -} - -export async function downloadFile(downloadUrl: string, fileName: string) { - return fetchApi('', 'downloadFile', { - downloadUrl: downloadUrl, - fileName: fileName, - }).catch((err: Error) => { - throw err - }) -} - -export async function deleteFile(fileName: string) { - return fetchApi('', 'deleteFile', fileName).catch((err: Error) => { - throw err - }) -} - -export async function fetchApi( - modulePath: string, - extensionFunc: string, - args: any -): Promise { - const response = await fetch(API_BASE_PATH + '/invokeFunction', { - method: 'POST', - body: JSON.stringify({ - modulePath: modulePath, - method: extensionFunc, - args: args, - }), - headers: { contentType: 'application/json', Authorization: '' }, - }) - - if (!response.ok) { - const json = await response.json() - if (json && json.error) { - toast.error(json.error, { - position: 'bottom-left', - autoClose: 5000, - hideProgressBar: false, - closeOnClick: true, - pauseOnHover: true, - draggable: true, - progress: undefined, - theme: 'light', - }) - } - return null - } - const text = await response.text() - try { - const json = JSON.parse(text) - return Promise.resolve(json) - } catch (err) { - return Promise.resolve(text) - } -} diff --git a/web/services/coreService.ts b/web/services/coreService.ts index 89b6dcfd1e..c010c6cec5 100644 --- a/web/services/coreService.ts +++ b/web/services/coreService.ts @@ -1,5 +1,5 @@ -import * as restAPI from './cloudNativeService' import { EventEmitter } from './eventsService' +import { restAPI } from './restService' export const setupCoreServices = () => { if (typeof window === 'undefined') { console.debug('undefine', window) @@ -10,9 +10,7 @@ export const setupCoreServices = () => { if (!window.core) { window.core = { events: new EventEmitter(), - api: window.electronAPI ?? { - ...restAPI, - }, + api: window.electronAPI ?? restAPI, } } } diff --git a/web/services/extensionService.ts b/web/services/extensionService.ts index d79bda0655..b18fb3cc1e 100644 --- a/web/services/extensionService.ts +++ b/web/services/extensionService.ts @@ -15,13 +15,10 @@ export const isCoreExtensionInstalled = () => { return true } export const setupBaseExtensions = async () => { - if ( - typeof window === 'undefined' || - typeof window.electronAPI === 'undefined' - ) { + if (typeof window === 'undefined') { return } - const baseExtensions = await window.electronAPI.baseExtensions() + const baseExtensions = await window.core?.api.baseExtensions() if ( !extensionManager.get(ExtensionType.Conversational) || diff --git a/web/services/restService.ts b/web/services/restService.ts new file mode 100644 index 0000000000..9c78078add --- /dev/null +++ b/web/services/restService.ts @@ -0,0 +1,59 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +import { safeJsonParse } from '@/utils/json' +import { + AppRoute, + DownloadRoute, + ExtensionRoute, + FileSystemRoute, +} from '@janhq/core' + +// Function to open an external URL in a new browser window +export function openExternalUrl(url: string) { + window?.open(url, '_blank') +} + +// Async function to get the application version +export async function appVersion() { + return Promise.resolve(VERSION) +} + +// Define API routes based on different route types +export const APIRoutes = [ + ...Object.values(AppRoute).map((r) => ({ path: 'app', route: r })), + ...Object.values(DownloadRoute).map((r) => ({ path: `download`, route: r })), + ...Object.values(ExtensionRoute).map((r) => ({ + path: `extension`, + route: r, + })), + ...Object.values(FileSystemRoute).map((r) => ({ path: `fs`, route: r })), +] + +// Define the restAPI object with methods for each API route +export const restAPI = { + ...Object.values(APIRoutes).reduce((acc, proxy) => { + return { + ...acc, + [proxy.route]: (...args: any) => { + // For each route, define a function that sends a request to the API + return fetch(`${API_BASE_URL}/api/v1/${proxy.path}/${proxy.route}`, { + method: 'POST', + body: JSON.stringify(args), + headers: { contentType: 'application/json' }, + }).then(async (res) => { + try { + if (proxy.path === 'fs') { + const text = await res.text() + return safeJsonParse(text) ?? text + } + return await res.json() + } catch (err) { + console.debug('Op: ', proxy, args, err) + } + }) + }, + } + }, {}), + openExternalUrl, + appVersion, + invokeExtensionFunc: () => {}, +} diff --git a/web/types/index.d.ts b/web/types/index.d.ts index ddb608a7aa..499ae06482 100644 --- a/web/types/index.d.ts +++ b/web/types/index.d.ts @@ -6,6 +6,7 @@ export {} declare global { declare const PLUGIN_CATALOG: string declare const VERSION: string + declare const API_BASE_URL: string interface Core { api: APIFunctions events: EventEmitter diff --git a/web/utils/json.ts b/web/utils/json.ts new file mode 100644 index 0000000000..89115aa5fd --- /dev/null +++ b/web/utils/json.ts @@ -0,0 +1,9 @@ +export const safeJsonParse = (str: string) => { + try { + const jsonValue: T = JSON.parse(str) + + return jsonValue + } catch { + return undefined + } +}