-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Jan Server, API and decoupled clients (janhq#948)
* chore: expose fs apis * chore: correct electron import path * update download api Signed-off-by: James <[email protected]> * update chat_completion Signed-off-by: James <[email protected]> * fix electron import Signed-off-by: James <[email protected]> * feat: adding API support at 1337 (janhq#991) Signed-off-by: James <[email protected]> Co-authored-by: James <[email protected]> * feat: Add /chat/completion api and handler * chore: add todo for modelList * chore: read engine.json for openai chat_completion (janhq#1030) Signed-off-by: James <[email protected]> Co-authored-by: James <[email protected]> * refactor: move routes to shared node module * refactor: exported modules from core with types (janhq#1172) * refactor: exported modules from core with types * fix: fix file reading args * refactor: fileManager handles * fix: app issues with server refactoring * refactor: shared server module (janhq#1210) * chore: resolve main * chore: update makefile --------- Signed-off-by: James <[email protected]> Co-authored-by: James <[email protected]> Co-authored-by: NamH <[email protected]> Co-authored-by: hiro <[email protected]>
- Loading branch information
1 parent
cfbc567
commit 5250061
Showing
71 changed files
with
1,258 additions
and
887 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,74 @@ | ||
/** | ||
* 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<any>} A Promise that resolves when the file is written successfully. | ||
*/ | ||
const writeFile: (path: string, data: string) => Promise<any> = (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<boolean> => 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<any>} A Promise that resolves with the contents of the file. | ||
*/ | ||
const readFile: (path: string) => Promise<any> = (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<boolean> => 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<any>} A Promise that resolves with the contents of the directory. | ||
*/ | ||
const listFiles: (path: string) => Promise<any> = (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<any>} A Promise that resolves when the directory is created successfully. | ||
*/ | ||
const mkdir: (path: string) => Promise<any> = (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<any>} A Promise that resolves when the directory is removed successfully. | ||
*/ | ||
const rmdir: (path: string) => Promise<any> = (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<any>} A Promise that resolves when the file is deleted. | ||
*/ | ||
const deleteFile: (path: string) => Promise<any> = (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<any> = (path, data) => | ||
global.core.api?.appendFile(path, data) | ||
|
||
const copyFile: (src: string, dest: string) => Promise<any> = (src, dest) => | ||
global.core.api?.copyFile(src, dest) | ||
const appendFileSync = (...args: any[]) => global.core.api?.appendFileSync(...args) | ||
|
||
/** | ||
* Synchronizes a file from a source path to a destination path. | ||
* @param {string} src - The source path of the file to be synchronized. | ||
* @param {string} dest - The destination path where the file will be synchronized to. | ||
* @returns {Promise<any>} - A promise that resolves when the file has been successfully synchronized. | ||
*/ | ||
const syncFile: (src: string, dest: string) => Promise<any> = (src, dest) => | ||
global.core.api?.syncFile(src, dest) | ||
|
||
/** | ||
* Reads a file line by line. | ||
* @param {string} path - The path of the file to read. | ||
* @returns {Promise<any>} A promise that resolves to the lines of the file. | ||
* Copy file sync. | ||
*/ | ||
const readLineByLine: (path: string) => Promise<any> = (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, | ||
syncFile, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export interface HttpServer { | ||
post: (route: string, handler: (req: any, res: any) => Promise<any>) => void | ||
get: (route: string, handler: (req: any, res: any) => Promise<any>) => void | ||
patch: (route: string, handler: (req: any, res: any) => Promise<any>) => void | ||
put: (route: string, handler: (req: any, res: any) => Promise<any>) => void | ||
delete: (route: string, handler: (req: any, res: any) => Promise<any>) => void | ||
register: (router: any, opts?: any) => void | ||
} |
Oops, something went wrong.