Node: Migrate to ES Modules

This commit is contained in:
Cohee
2024-10-10 22:37:22 +03:00
parent 5a52196331
commit d52b4fbbde
74 changed files with 1291 additions and 1140 deletions

View File

@ -1,18 +1,18 @@
const PUBLIC_DIRECTORIES = {
export const PUBLIC_DIRECTORIES = {
images: 'public/img/',
backups: 'backups/',
sounds: 'public/sounds',
extensions: 'public/scripts/extensions',
};
const SETTINGS_FILE = 'settings.json';
export const SETTINGS_FILE = 'settings.json';
/**
* @type {import('./users').UserDirectoryList}
* @readonly
* @enum {string}
*/
const USER_DIRECTORY_TEMPLATE = Object.freeze({
export const USER_DIRECTORY_TEMPLATE = Object.freeze({
root: '',
thumbnails: 'thumbnails',
thumbnailsBg: 'thumbnails/bg',
@ -48,7 +48,7 @@ const USER_DIRECTORY_TEMPLATE = Object.freeze({
* @type {import('./users').User}
* @readonly
*/
const DEFAULT_USER = Object.freeze({
export const DEFAULT_USER = Object.freeze({
handle: 'default-user',
name: 'User',
created: Date.now(),
@ -58,7 +58,7 @@ const DEFAULT_USER = Object.freeze({
salt: '',
});
const UNSAFE_EXTENSIONS = [
export const UNSAFE_EXTENSIONS = [
'.php',
'.exe',
'.com',
@ -135,7 +135,7 @@ const UNSAFE_EXTENSIONS = [
'.ws',
];
const GEMINI_SAFETY = [
export const GEMINI_SAFETY = [
{
category: 'HARM_CATEGORY_HARASSMENT',
threshold: 'BLOCK_NONE',
@ -158,7 +158,7 @@ const GEMINI_SAFETY = [
},
];
const BISON_SAFETY = [
export const BISON_SAFETY = [
{
category: 'HARM_CATEGORY_DEROGATORY',
threshold: 'BLOCK_NONE',
@ -185,7 +185,7 @@ const BISON_SAFETY = [
},
];
const CHAT_COMPLETION_SOURCES = {
export const CHAT_COMPLETION_SOURCES = {
OPENAI: 'openai',
WINDOWAI: 'windowai',
CLAUDE: 'claude',
@ -205,10 +205,10 @@ const CHAT_COMPLETION_SOURCES = {
/**
* Path to multer file uploads under the data root.
*/
const UPLOADS_DIRECTORY = '_uploads';
export const UPLOADS_DIRECTORY = '_uploads';
// TODO: this is copied from the client code; there should be a way to de-duplicate it eventually
const TEXTGEN_TYPES = {
export const TEXTGEN_TYPES = {
OOBA: 'ooba',
MANCER: 'mancer',
VLLM: 'vllm',
@ -225,7 +225,7 @@ const TEXTGEN_TYPES = {
HUGGINGFACE: 'huggingface',
};
const INFERMATICAI_KEYS = [
export const INFERMATICAI_KEYS = [
'model',
'prompt',
'max_tokens',
@ -248,7 +248,7 @@ const INFERMATICAI_KEYS = [
'logprobs',
];
const FEATHERLESS_KEYS = [
export const FEATHERLESS_KEYS = [
'model',
'prompt',
'best_of',
@ -290,9 +290,8 @@ const FEATHERLESS_KEYS = [
'guided_whitespace_pattern',
];
// https://dreamgen.com/docs/api#openai-text
const DREAMGEN_KEYS = [
export const DREAMGEN_KEYS = [
'model',
'prompt',
'max_tokens',
@ -309,7 +308,7 @@ const DREAMGEN_KEYS = [
];
// https://docs.together.ai/reference/completions
const TOGETHERAI_KEYS = [
export const TOGETHERAI_KEYS = [
'model',
'prompt',
'max_tokens',
@ -325,7 +324,7 @@ const TOGETHERAI_KEYS = [
];
// https://github.com/jmorganca/ollama/blob/main/docs/api.md#request-with-options
const OLLAMA_KEYS = [
export const OLLAMA_KEYS = [
'num_predict',
'num_ctx',
'stop',
@ -345,20 +344,20 @@ const OLLAMA_KEYS = [
'min_p',
];
const AVATAR_WIDTH = 512;
const AVATAR_HEIGHT = 768;
export const AVATAR_WIDTH = 512;
export const AVATAR_HEIGHT = 768;
const OPENROUTER_HEADERS = {
export const OPENROUTER_HEADERS = {
'HTTP-Referer': 'https://sillytavern.app',
'X-Title': 'SillyTavern',
};
const FEATHERLESS_HEADERS = {
export const FEATHERLESS_HEADERS = {
'HTTP-Referer': 'https://sillytavern.app',
'X-Title': 'SillyTavern',
};
const OPENROUTER_KEYS = [
export const OPENROUTER_KEYS = [
'max_tokens',
'temperature',
'top_k',
@ -378,7 +377,7 @@ const OPENROUTER_KEYS = [
];
// https://github.com/vllm-project/vllm/blob/0f8a91401c89ac0a8018def3756829611b57727f/vllm/entrypoints/openai/protocol.py#L220
const VLLM_KEYS = [
export const VLLM_KEYS = [
'model',
'prompt',
'best_of',
@ -419,27 +418,3 @@ const VLLM_KEYS = [
'guided_decoding_backend',
'guided_whitespace_pattern',
];
module.exports = {
DEFAULT_USER,
SETTINGS_FILE,
PUBLIC_DIRECTORIES,
USER_DIRECTORY_TEMPLATE,
UNSAFE_EXTENSIONS,
UPLOADS_DIRECTORY,
GEMINI_SAFETY,
BISON_SAFETY,
TEXTGEN_TYPES,
CHAT_COMPLETION_SOURCES,
AVATAR_WIDTH,
AVATAR_HEIGHT,
TOGETHERAI_KEYS,
OLLAMA_KEYS,
INFERMATICAI_KEYS,
DREAMGEN_KEYS,
OPENROUTER_HEADERS,
OPENROUTER_KEYS,
VLLM_KEYS,
FEATHERLESS_KEYS,
FEATHERLESS_HEADERS,
};