Skip to content

Commit

Permalink
Merge branch 'main' into docs/label-api-reference
Browse files Browse the repository at this point in the history
  • Loading branch information
0xHieu01 authored Nov 30, 2023
2 parents 668078c + 07eafd8 commit a38901b
Show file tree
Hide file tree
Showing 102 changed files with 2,355 additions and 1,348 deletions.
18 changes: 3 additions & 15 deletions .github/workflows/jan-electron-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,22 +121,10 @@ jobs:
env:
VERSION_TAG: ${{ steps.tag.outputs.tag }}

- name: Build uikit
- name: Build app
shell: cmd
run: |
cd uikit
yarn config set network-timeout 300000
yarn install
yarn build
- name: Install yarn dependencies
shell: powershell
run: |
yarn config set network-timeout 300000
yarn build:core
yarn install
$env:NITRO_VERSION = Get-Content .\plugins\inference-plugin\nitro\version.txt; echo $env:NITRO_VERSION
yarn build:plugins
yarn build
make build
- name: Windows Code Sign with AzureSignTool
run: |
Expand Down
20 changes: 15 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@ endif
# Installs yarn dependencies and builds core and plugins
install-and-build: build-uikit
ifeq ($(OS),Windows_NT)
powershell -Command "yarn config set network-timeout 300000; \
$$env:NITRO_VERSION = Get-Content .\\plugins\\inference-plugin\\nitro\\version.txt; \
Write-Output \"Nitro version: $$env:NITRO_VERSION\"; yarn build:core; yarn install; yarn build:plugins"
else
yarn config set network-timeout 300000
endif
yarn build:core
yarn install
yarn build:plugins
endif

dev: install-and-build
yarn dev
Expand All @@ -47,8 +44,21 @@ build: install-and-build
clean:
ifeq ($(OS),Windows_NT)
powershell -Command "Get-ChildItem -Path . -Include node_modules, .next, dist -Recurse -Directory | Remove-Item -Recurse -Force"
rmdir /s /q "%USERPROFILE%\AppData\Roaming\jan"
rmdir /s /q "%USERPROFILE%\AppData\Roaming\jan-electron"
rmdir /s /q "%USERPROFILE%\AppData\Local\jan*"
else ifeq ($(shell uname -s),Linux)
find . -name "node_modules" -type d -prune -exec rm -rf '{}' +
find . -name ".next" -type d -exec rm -rf '{}' +
find . -name "dist" -type d -exec rm -rf '{}' +
rm -rf "~/.config/jan"
rm -rf "~/.config/jan-electron"
rm -rf "~/.cache/jan*"
else
find . -name "node_modules" -type d -prune -exec rm -rf '{}' +
find . -name ".next" -type d -exec rm -rf '{}' +
find . -name "dist" -type d -exec rm -rf '{}' +
rm -rf ~/Library/Application\ Support/jan
rm -rf ~/Library/Application\ Support/jan-electron
rm -rf ~/Library/Caches/jan*
endif
60 changes: 20 additions & 40 deletions core/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,7 @@ const executeOnMain: (
method: string,
...args: any[]
) => Promise<any> = (plugin, method, ...args) =>
window.coreAPI?.invokePluginFunc(plugin, method, ...args) ??
window.electronAPI?.invokePluginFunc(plugin, method, ...args);

/**
* @deprecated This object is deprecated and should not be used.
* Use individual functions instead.
*/
const invokePluginFunc: (
plugin: string,
method: string,
...args: any[]
) => Promise<any> = (plugin, method, ...args) =>
window.coreAPI?.invokePluginFunc(plugin, method, ...args) ??
window.electronAPI?.invokePluginFunc(plugin, method, ...args);
window.coreAPI?.invokePluginFunc(plugin, method, ...args)

/**
* Downloads a file from a URL and saves it to the local file system.
Expand All @@ -36,16 +23,15 @@ const invokePluginFunc: (
const downloadFile: (url: string, fileName: string) => Promise<any> = (
url,
fileName
) =>
window.coreAPI?.downloadFile(url, fileName) ??
window.electronAPI?.downloadFile(url, fileName);
) => window.coreAPI?.downloadFile(url, fileName);

/**
* @deprecated This object is deprecated and should not be used.
* Use fs module instead.
* Aborts the download of a specific file.
* @param {string} fileName - The name of the file whose download is to be aborted.
* @returns {Promise<any>} A promise that resolves when the download has been aborted.
*/
const deleteFile: (path: string) => Promise<any> = (path) =>
window.coreAPI?.deleteFile(path) ?? window.electronAPI?.deleteFile(path);
const abortDownload: (fileName: string) => Promise<any> = (fileName) =>
window.coreAPI?.abortDownload(fileName);

/**
* Retrieves the path to the app data directory using the `coreAPI` object.
Expand All @@ -58,11 +44,18 @@ const appDataPath: () => Promise<any> = () => window.coreAPI?.appDataPath();
* Gets the user space path.
* @returns {Promise<any>} A Promise that resolves with the user space path.
*/
const getUserSpace = (): Promise<string> =>
window.coreAPI?.getUserSpace() ?? window.electronAPI?.getUserSpace();
const getUserSpace = (): Promise<string> => window.coreAPI?.getUserSpace();

/** Register extension point function type definition
*
/**
* Opens the file explorer at a specific path.
* @param {string} path - The path to open in the file explorer.
* @returns {Promise<any>} A promise that resolves when the file explorer is opened.
*/
const openFileExplorer: (path: string) => Promise<any> = (path) =>
window.coreAPI?.openFileExplorer(path);

/**
* Register extension point function type definition
*/
export type RegisterExtensionPoint = (
extensionName: string,
Expand All @@ -71,27 +64,14 @@ export type RegisterExtensionPoint = (
priority?: number
) => void;

/**
* @deprecated This object is deprecated and should not be used.
* Use individual functions instead.
*/
export const core = {
invokePluginFunc,
executeOnMain,
downloadFile,
deleteFile,
appDataPath,
getUserSpace,
};

/**
* Functions exports
*/
export {
invokePluginFunc,
executeOnMain,
downloadFile,
deleteFile,
abortDownload,
appDataPath,
getUserSpace,
openFileExplorer,
};
33 changes: 25 additions & 8 deletions core/src/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,55 +5,70 @@
* @returns {Promise<any>} A Promise that resolves when the file is written successfully.
*/
const writeFile: (path: string, data: string) => Promise<any> = (path, data) =>
window.coreAPI?.writeFile(path, data) ??
window.electronAPI?.writeFile(path, data);
window.coreAPI?.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> =>
window.coreAPI?.isDirectory(path) ?? window.electronAPI?.isDirectory(path);
window.coreAPI?.isDirectory(path);

/**
* 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) =>
window.coreAPI?.readFile(path) ?? window.electronAPI?.readFile(path);
window.coreAPI?.readFile(path);

/**
* 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) =>
window.coreAPI?.listFiles(path) ?? window.electronAPI?.listFiles(path);
window.coreAPI?.listFiles(path);

/**
* 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) =>
window.coreAPI?.mkdir(path) ?? window.electronAPI?.mkdir(path);
window.coreAPI?.mkdir(path);

/**
* 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) =>
window.coreAPI?.rmdir(path) ?? window.electronAPI?.rmdir(path);
window.coreAPI?.rmdir(path);
/**
* 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) =>
window.coreAPI?.deleteFile(path) ?? window.electronAPI?.deleteFile(path);
window.coreAPI?.deleteFile(path);

/**
* 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) =>
window.coreAPI?.appendFile(path, data);

/**
* 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.
*/
const readLineByLine: (path: string) => Promise<any> = (path) =>
window.coreAPI?.readLineByLine(path);

export const fs = {
isDirectory,
Expand All @@ -63,4 +78,6 @@ export const fs = {
mkdir,
rmdir,
deleteFile,
appendFile,
readLineByLine,
};
16 changes: 4 additions & 12 deletions core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,26 @@
/**
* @deprecated This object is deprecated and should not be used.
* Use individual functions instead.
*/
export { core, deleteFile, invokePluginFunc } from "./core";

/**
* Core module exports.
* @module
*/
export { downloadFile, executeOnMain, appDataPath, getUserSpace } from "./core";
export * from "./core";

/**
* Events module exports.
* Events events exports.
* @module
*/
export { events } from "./events";
export * from "./events";

/**
* Events types exports.
* @module
*/
export * from "./events";

export * from "./types/index";

/**
* Filesystem module exports.
* @module
*/
export { fs } from "./fs";
export * from "./fs";

/**
* Plugin base module export.
Expand Down
1 change: 1 addition & 0 deletions core/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export enum PluginType {
Preference = "preference",
SystemMonitoring = "systemMonitoring",
Model = "model",
Assistant = "assistant",
}

export abstract class JanPlugin {
Expand Down
28 changes: 28 additions & 0 deletions core/src/plugins/assistant.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Assistant } from "../index";
import { JanPlugin } from "../plugin";

/**
* Abstract class for assistant plugins.
* @extends JanPlugin
*/
export abstract class AssistantPlugin extends JanPlugin {
/**
* Creates a new assistant.
* @param {Assistant} assistant - The assistant object to be created.
* @returns {Promise<void>} A promise that resolves when the assistant has been created.
*/
abstract createAssistant(assistant: Assistant): Promise<void>;

/**
* Deletes an existing assistant.
* @param {Assistant} assistant - The assistant object to be deleted.
* @returns {Promise<void>} A promise that resolves when the assistant has been deleted.
*/
abstract deleteAssistant(assistant: Assistant): Promise<void>;

/**
* Retrieves all existing assistants.
* @returns {Promise<Assistant[]>} A promise that resolves to an array of all assistants.
*/
abstract getAssistants(): Promise<Assistant[]>;
}
51 changes: 38 additions & 13 deletions core/src/plugins/conversational.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,57 @@
import { Thread } from "../index";
import { Thread, ThreadMessage } from "../index";
import { JanPlugin } from "../plugin";

/**
* Abstract class for conversational plugins.
* Abstract class for Thread plugins.
* @abstract
* @extends JanPlugin
*/
export abstract class ConversationalPlugin extends JanPlugin {
/**
* Returns a list of conversations.
* Returns a list of thread.
* @abstract
* @returns {Promise<any[]>} A promise that resolves to an array of conversations.
* @returns {Promise<Thread[]>} A promise that resolves to an array of threads.
*/
abstract getConversations(): Promise<any[]>;
abstract getThreads(): Promise<Thread[]>;

/**
* Saves a conversation.
* Saves a thread.
* @abstract
* @param {Thread} conversation - The conversation to save.
* @returns {Promise<void>} A promise that resolves when the conversation is saved.
* @param {Thread} thread - The thread to save.
* @returns {Promise<void>} A promise that resolves when the thread is saved.
*/
abstract saveConversation(conversation: Thread): Promise<void>;
abstract saveThread(thread: Thread): Promise<void>;

/**
* Deletes a conversation.
* Deletes a thread.
* @abstract
* @param {string} conversationId - The ID of the conversation to delete.
* @returns {Promise<void>} A promise that resolves when the conversation is deleted.
* @param {string} threadId - The ID of the thread to delete.
* @returns {Promise<void>} A promise that resolves when the thread is deleted.
*/
abstract deleteConversation(conversationId: string): Promise<void>;
abstract deleteThread(threadId: string): Promise<void>;

/**
* Adds a new message to the thread.
* @param {ThreadMessage} message - The message to be added.
* @returns {Promise<void>} A promise that resolves when the message has been added.
*/
abstract addNewMessage(message: ThreadMessage): Promise<void>;

/**
* Writes an array of messages to a specific thread.
* @param {string} threadId - The ID of the thread to write the messages to.
* @param {ThreadMessage[]} messages - The array of messages to be written.
* @returns {Promise<void>} A promise that resolves when the messages have been written.
*/
abstract writeMessages(
threadId: string,
messages: ThreadMessage[]
): Promise<void>;

/**
* Retrieves all messages from a specific thread.
* @param {string} threadId - The ID of the thread to retrieve the messages from.
* @returns {Promise<ThreadMessage[]>} A promise that resolves to an array of messages from the thread.
*/
abstract getAllMessages(threadId: string): Promise<ThreadMessage[]>;
}
Loading

0 comments on commit a38901b

Please sign in to comment.