Explicitly import Buffer. Specify jsdoc local extensions

1616e7e06760cdb593d269b56e37c7f6184099b8

Cohee <18619528+Cohee1207@users.noreply.github.com>

33 files changed, +93 -77Ignore whitespace
src/additional-headers.js+14 -14
@@ -4,7 +4,7 @@ import { getConfigValue } from './util.js';
44
55/**
66 * Gets the headers for the Mancer API.
77 * @param {import('./users.js').UserDirectoryList} directories User directories
88 * @returns {object} Headers for the request
99 */
1010function getMancerHeaders(directories) {
@@ -18,7 +18,7 @@ function getMancerHeaders(directories) {
1818
1919/**
2020 * Gets the headers for the TogetherAI API.
2121 * @param {import('./users.js').UserDirectoryList} directories User directories
2222 * @returns {object} Headers for the request
2323 */
2424function getTogetherAIHeaders(directories) {
@@ -31,7 +31,7 @@ function getTogetherAIHeaders(directories) {
3131
3232/**
3333 * Gets the headers for the InfermaticAI API.
3434 * @param {import('./users.js').UserDirectoryList} directories User directories
3535 * @returns {object} Headers for the request
3636 */
3737function getInfermaticAIHeaders(directories) {
@@ -44,7 +44,7 @@ function getInfermaticAIHeaders(directories) {
4444
4545/**
4646 * Gets the headers for the DreamGen API.
4747 * @param {import('./users.js').UserDirectoryList} directories User directories
4848 * @returns {object} Headers for the request
4949 */
5050function getDreamGenHeaders(directories) {
@@ -57,7 +57,7 @@ function getDreamGenHeaders(directories) {
5757
5858/**
5959 * Gets the headers for the OpenRouter API.
6060 * @param {import('./users.js').UserDirectoryList} directories User directories
6161 * @returns {object} Headers for the request
6262 */
6363function getOpenRouterHeaders(directories) {
@@ -69,7 +69,7 @@ function getOpenRouterHeaders(directories) {
6969
7070/**
7171 * Gets the headers for the vLLM API.
7272 * @param {import('./users.js').UserDirectoryList} directories User directories
7373 * @returns {object} Headers for the request
7474 */
7575function getVllmHeaders(directories) {
@@ -82,7 +82,7 @@ function getVllmHeaders(directories) {
8282
8383/**
8484 * Gets the headers for the Aphrodite API.
8585 * @param {import('./users.js').UserDirectoryList} directories User directories
8686 * @returns {object} Headers for the request
8787 */
8888function getAphroditeHeaders(directories) {
@@ -96,7 +96,7 @@ function getAphroditeHeaders(directories) {
9696
9797/**
9898 * Gets the headers for the Tabby API.
9999 * @param {import('./users.js').UserDirectoryList} directories User directories
100100 * @returns {object} Headers for the request
101101 */
102102function getTabbyHeaders(directories) {
@@ -110,7 +110,7 @@ function getTabbyHeaders(directories) {
110110
111111/**
112112 * Gets the headers for the LlamaCPP API.
113113 * @param {import('./users.js').UserDirectoryList} directories User directories
114114 * @returns {object} Headers for the request
115115 */
116116function getLlamaCppHeaders(directories) {
@@ -123,7 +123,7 @@ function getLlamaCppHeaders(directories) {
123123
124124/**
125125 * Gets the headers for the Ooba API.
126126 * @param {import('./users.js').UserDirectoryList} directories
127127 * @returns {object} Headers for the request
128128 */
129129function getOobaHeaders(directories) {
@@ -136,7 +136,7 @@ function getOobaHeaders(directories) {
136136
137137/**
138138 * Gets the headers for the KoboldCpp API.
139139 * @param {import('./users.js').UserDirectoryList} directories
140140 * @returns {object} Headers for the request
141141 */
142142function getKoboldCppHeaders(directories) {
@@ -149,7 +149,7 @@ function getKoboldCppHeaders(directories) {
149149
150150/**
151151 * Gets the headers for the Featherless API.
152152 * @param {import('./users.js').UserDirectoryList} directories
153153 * @returns {object} Headers for the request
154154 */
155155function getFeatherlessHeaders(directories) {
@@ -161,7 +161,7 @@ function getFeatherlessHeaders(directories) {
161161
162162/**
163163 * Gets the headers for the HuggingFace API.
164164 * @param {import('./users.js').UserDirectoryList} directories
165165 * @returns {object} Headers for the request
166166 */
167167function getHuggingFaceHeaders(directories) {
@@ -197,7 +197,7 @@ export function setAdditionalHeaders(request, args, server) {
197197 * @param {object} requestHeaders Request headers
198198 * @param {string} type API type
199199 * @param {string|null} server API server for new request
200200 * @param {import('./users.js').UserDirectoryList} directories User directories
201201 */
202202export function setAdditionalHeadersByType(requestHeaders, type, server, directories) {
203203 const headerGetters = {
src/character-card-parser.js+1 -0
@@ -1,4 +1,5 @@
11import fs from 'node:fs';
2+import { Buffer } from 'node:buffer';
23
34import encode from 'png-chunks-encode';
45import extract from 'png-chunks-extract';
src/constants.js+2 -2
@@ -8,7 +8,7 @@ export const PUBLIC_DIRECTORIES = {
88export const SETTINGS_FILE = 'settings.json';
99
1010/**
1111 * @type {import('./users.js').UserDirectoryList}
1212 * @readonly
1313 * @enum {string}
1414 */
@@ -45,7 +45,7 @@ export const USER_DIRECTORY_TEMPLATE = Object.freeze({
4545});
4646
4747/**
4848 * @type {import('./users.js').User}
4949 * @readonly
5050 */
5151export const DEFAULT_USER = Object.freeze({
src/endpoints/assets.js+1 -1
@@ -79,7 +79,7 @@ function getFiles(dir, files = []) {
7979
8080/**
8181 * Ensure that the asset folders exist.
8282 * @param {import('../users.js').UserDirectoryList} directories - The user's directories
8383 */
8484function ensureFoldersExist(directories) {
8585 const folderPath = path.join(directories.assets);
src/endpoints/characters.js+6 -5
@@ -2,6 +2,7 @@ import * as path from 'node:path';
22import * as fs from 'node:fs';
33import { promises as fsPromises } from 'node:fs';
44import * as readline from 'node:readline';
5+import { Buffer } from 'node:buffer';
56
67import express from 'express';
78import sanitize from 'sanitize-filename';
@@ -188,7 +189,7 @@ const calculateDataSize = (data) => {
188189 * processCharacter - Process a given character, read its data and calculate its statistics.
189190 *
190191 * @param {string} item The name of the character.
191192 * @param {import('../users.js').UserDirectoryList} directories User directories
192193 * @return {Promise<object>} A Promise that resolves when the character processing is done.
193194 */
194195const processCharacter = async (item, directories) => {
@@ -232,7 +233,7 @@ const processCharacter = async (item, directories) => {
232233/**
233234 * Convert a character object to Spec V2 format.
234235 * @param {object} jsonObject Character object
235236 * @param {import('../users.js').UserDirectoryList} directories User directories
236237 * @param {boolean} hoistDate Will set the chat and create_date fields to the current date if they are missing
237238 * @returns {object} Character object in Spec V2 format
238239 */
@@ -252,7 +253,7 @@ function getCharaCardV2(jsonObject, directories, hoistDate = true) {
252253/**
253254 * Convert a character object to Spec V2 format.
254255 * @param {object} char Character object
255256 * @param {import('../users.js').UserDirectoryList} directories User directories
256257 * @returns {object} Character object in Spec V2 format
257258 */
258259function convertToV2(char, directories) {
@@ -342,7 +343,7 @@ function readFromV2(char) {
342343/**
343344 * Format character data to Spec V2 format.
344345 * @param {object} data Character data
345346 * @param {import('../users.js').UserDirectoryList} directories User directories
346347 * @returns
347348 */
348349function charaFormatData(data, directories) {
@@ -1081,7 +1082,7 @@ router.post('/chats', jsonParser, async function (request, response) {
10811082/**
10821083 * Gets the name for the uploaded PNG file.
10831084 * @param {string} file File name
10841085 * @param {import('../users.js').UserDirectoryList} directories User directories
10851086 * @returns {string} - The name for the uploaded PNG file
10861087 */
10871088function getPngName(file, directories) {
src/endpoints/content-manager.js+5 -4
@@ -1,5 +1,6 @@
11import * as fs from 'node:fs';
22import * as path from 'node:path';
3+import { Buffer } from 'node:buffer';
34
45import express from 'express';
56import fetch from 'node-fetch';
@@ -50,7 +51,7 @@ export const CONTENT_TYPES = {
5051
5152/**
5253 * Gets the default presets from the content directory.
5354 * @param {import('../users.js').UserDirectoryList} directories User directories
5455 * @returns {object[]} Array of default presets
5556 */
5657export function getDefaultPresets(directories) {
@@ -97,7 +98,7 @@ export function getDefaultPresetFile(filename) {
9798/**
9899 * Seeds content for a user.
99100 * @param {ContentItem[]} contentIndex Content index
100101 * @param {import('../users.js').UserDirectoryList} directories User directories
101102 * @param {string[]} forceCategories List of categories to force check (even if content check is skipped)
102103 * @returns {Promise<boolean>} Whether any content was added
103104 */
@@ -156,7 +157,7 @@ async function seedContentForUser(contentIndex, directories, forceCategories) {
156157
157158/**
158159 * Checks for new content and seeds it for all users.
159160 * @param {import('../users.js').UserDirectoryList[]} directoriesList List of user directories
160161 * @param {string[]} forceCategories List of categories to force check (even if content check is skipped)
161162 * @returns {Promise<void>}
162163 */
@@ -258,7 +259,7 @@ export function getContentOfType(type, format) {
258259/**
259260 * Gets the target directory for the specified asset type.
260261 * @param {ContentType} type Asset type
261262 * @param {import('../users.js').UserDirectoryList} directories User directories
262263 * @returns {string | null} Target directory
263264 */
264265function getTargetByType(type, directories) {
src/endpoints/images.js+1 -0
@@ -1,5 +1,6 @@
11import * as fs from 'node:fs';
22import * as path from 'node:path';
3+import { Buffer } from 'node:buffer';
34
45import express from 'express';
56import sanitize from 'sanitize-filename';
src/endpoints/novelai.js+1 -0
@@ -1,4 +1,5 @@
11import * as util from 'node:util';
2+import { Buffer } from 'node:buffer';
23
34import fetch from 'node-fetch';
45import express from 'express';
src/endpoints/openai.js+1 -0
@@ -1,4 +1,5 @@
11import * as fs from 'node:fs';
2+import { Buffer } from 'node:buffer';
23
34import fetch from 'node-fetch';
45import FormData from 'form-data';
src/endpoints/presets.js+1 -1
@@ -11,7 +11,7 @@ import { jsonParser } from '../express-common.js';
1111/**
1212 * Gets the folder and extension for the preset settings based on the API source ID.
1313 * @param {string} apiId API source ID
1414 * @param {import('../users.js').UserDirectoryList} directories User directories
1515 * @returns {object} Object containing the folder and extension for the preset settings
1616 */
1717function getPresetSettingsByAPI(apiId, directories) {
src/endpoints/secrets.js+5 -5
@@ -59,7 +59,7 @@ const EXPORTABLE_KEYS = [
5959
6060/**
6161 * Writes a secret to the secrets file
6262 * @param {import('../users.js').UserDirectoryList} directories User directories
6363 * @param {string} key Secret key
6464 * @param {string} value Secret value
6565 */
@@ -79,7 +79,7 @@ export function writeSecret(directories, key, value) {
7979
8080/**
8181 * Deletes a secret from the secrets file
8282 * @param {import('../users.js').UserDirectoryList} directories User directories
8383 * @param {string} key Secret key
8484 * @returns
8585 */
@@ -98,7 +98,7 @@ export function deleteSecret(directories, key) {
9898
9999/**
100100 * Reads a secret from the secrets file
101101 * @param {import('../users.js').UserDirectoryList} directories User directories
102102 * @param {string} key Secret key
103103 * @returns {string} Secret value
104104 */
@@ -116,7 +116,7 @@ export function readSecret(directories, key) {
116116
117117/**
118118 * Reads the secret state from the secrets file
119119 * @param {import('../users.js').UserDirectoryList} directories User directories
120120 * @returns {object} Secret state
121121 */
122122export function readSecretState(directories) {
@@ -139,7 +139,7 @@ export function readSecretState(directories) {
139139
140140/**
141141 * Reads all secrets from the secrets file
142142 * @param {import('../users.js').UserDirectoryList} directories User directories
143143 * @returns {Record<string, string> | undefined} Secrets
144144 */
145145export function getAllSecrets(directories) {
src/endpoints/speech.js+1 -0
@@ -1,3 +1,4 @@
1+import { Buffer } from 'node:buffer';
12import express from 'express';
23import wavefile from 'wavefile';
34import { jsonParser } from '../express-common.js';
src/endpoints/sprites.js+2 -2
@@ -11,7 +11,7 @@ import { jsonParser, urlencodedParser } from '../express-common.js';
1111
1212/**
1313 * Gets the path to the sprites folder for the provided character name
1414 * @param {import('../users.js').UserDirectoryList} directories - User directories
1515 * @param {string} name - The name of the character
1616 * @param {boolean} isSubfolder - Whether the name contains a subfolder
1717 * @returns {string | null} The path to the sprites folder. Null if the name is invalid.
@@ -42,7 +42,7 @@ function getSpritesPath(directories, name, isSubfolder) {
4242 * Imports base64 encoded sprites from RisuAI character data.
4343 * The sprites are saved in the character's sprites folder.
4444 * The additionalAssets and emotions are removed from the data.
4545 * @param {import('../users.js').UserDirectoryList} directories User directories
4646 * @param {object} data RisuAI character data
4747 * @returns {void}
4848 */
src/endpoints/thumbnails.js+4 -4
@@ -18,7 +18,7 @@ const pngFormat = getConfigValue('avatarThumbnailsPng', false);
1818
1919/**
2020 * Gets a path to thumbnail folder based on the type.
2121 * @param {import('../users.js').UserDirectoryList} directories User directories
2222 * @param {'bg' | 'avatar'} type Thumbnail type
2323 * @returns {string} Path to the thumbnails folder
2424 */
@@ -39,7 +39,7 @@ function getThumbnailFolder(directories, type) {
3939
4040/**
4141 * Gets a path to the original images folder based on the type.
4242 * @param {import('../users.js').UserDirectoryList} directories User directories
4343 * @param {'bg' | 'avatar'} type Thumbnail type
4444 * @returns {string} Path to the original images folder
4545 */
@@ -60,7 +60,7 @@ function getOriginalFolder(directories, type) {
6060
6161/**
6262 * Removes the generated thumbnail from the disk.
6363 * @param {import('../users.js').UserDirectoryList} directories User directories
6464 * @param {'bg' | 'avatar'} type Type of the thumbnail
6565 * @param {string} file Name of the file
6666 */
@@ -77,7 +77,7 @@ export function invalidateThumbnail(directories, type, file) {
7777
7878/**
7979 * Generates a thumbnail for the given file.
8080 * @param {import('../users.js').UserDirectoryList} directories User directories
8181 * @param {'bg' | 'avatar'} type Type of the thumbnail
8282 * @param {string} file Name of the file
8383 * @returns
src/endpoints/tokenizers.js+1 -0
@@ -1,5 +1,6 @@
11import * as fs from 'node:fs';
22import * as path from 'node:path';
3+import { Buffer } from 'node:buffer';
34
45import express from 'express';
56import { sync as writeFileAtomicSync } from 'write-file-atomic';
src/endpoints/translate.js+2 -0
@@ -1,5 +1,7 @@
11import * as https from 'node:https';
22import { createRequire } from 'node:module';
3+import { Buffer } from 'node:buffer';
4+
35import fetch from 'node-fetch';
46import express from 'express';
57import iconv from 'iconv-lite';
src/endpoints/users-admin.js+6 -6
@@ -22,10 +22,10 @@ export const router = express.Router();
2222
2323router.post('/get', requireAdminMiddleware, jsonParser, async (_request, response) => {
2424 try {
2525 /** @type {import('../users.js').User[]} */
2626 const users = await storage.values(x => x.key.startsWith(KEY_PREFIX));
2727
2828 /** @type {Promise<import('../users.js').UserViewModel>[]} */
2929 const viewModelPromises = users
3030 .map(user => new Promise(resolve => {
3131 getUserAvatar(user.handle).then(avatar =>
@@ -62,7 +62,7 @@ router.post('/disable', requireAdminMiddleware, jsonParser, async (request, resp
6262 return response.status(400).json({ error: 'Cannot disable yourself' });
6363 }
6464
6565 /** @type {import('../users.js').User} */
6666 const user = await storage.getItem(toKey(request.body.handle));
6767
6868 if (!user) {
@@ -86,7 +86,7 @@ router.post('/enable', requireAdminMiddleware, jsonParser, async (request, respo
8686 return response.status(400).json({ error: 'Missing required fields' });
8787 }
8888
8989 /** @type {import('../users.js').User} */
9090 const user = await storage.getItem(toKey(request.body.handle));
9191
9292 if (!user) {
@@ -110,7 +110,7 @@ router.post('/promote', requireAdminMiddleware, jsonParser, async (request, resp
110110 return response.status(400).json({ error: 'Missing required fields' });
111111 }
112112
113113 /** @type {import('../users.js').User} */
114114 const user = await storage.getItem(toKey(request.body.handle));
115115
116116 if (!user) {
@@ -139,7 +139,7 @@ router.post('/demote', requireAdminMiddleware, jsonParser, async (request, respo
139139 return response.status(400).json({ error: 'Cannot demote yourself' });
140140 }
141141
142142 /** @type {import('../users.js').User} */
143143 const user = await storage.getItem(toKey(request.body.handle));
144144
145145 if (!user) {
src/endpoints/users-private.js+3 -3
@@ -72,7 +72,7 @@ router.post('/change-avatar', jsonParser, async (request, response) => {
7272 return response.status(400).json({ error: 'Invalid data URL' });
7373 }
7474
7575 /** @type {import('../users.js').User} */
7676 const user = await storage.getItem(toKey(request.body.handle));
7777
7878 if (!user) {
@@ -101,7 +101,7 @@ router.post('/change-password', jsonParser, async (request, response) => {
101101 return response.status(403).json({ error: 'Unauthorized' });
102102 }
103103
104104 /** @type {import('../users.js').User} */
105105 const user = await storage.getItem(toKey(request.body.handle));
106106
107107 if (!user) {
@@ -189,7 +189,7 @@ router.post('/change-name', jsonParser, async (request, response) => {
189189 return response.status(403).json({ error: 'Unauthorized' });
190190 }
191191
192192 /** @type {import('../users.js').User} */
193193 const user = await storage.getItem(toKey(request.body.handle));
194194
195195 if (!user) {
src/endpoints/users-public.js+5 -5
@@ -26,10 +26,10 @@ router.post('/list', async (_request, response) => {
2626 return response.sendStatus(204);
2727 }
2828
2929 /** @type {import('../users.js').User[]} */
3030 const users = await storage.values(x => x.key.startsWith(KEY_PREFIX));
3131
3232 /** @type {Promise<import('../users.js').UserViewModel>[]} */
3333 const viewModelPromises = users
3434 .filter(x => x.enabled)
3535 .map(user => new Promise(async (resolve) => {
@@ -63,7 +63,7 @@ router.post('/login', jsonParser, async (request, response) => {
6363 const ip = getIpFromRequest(request);
6464 await loginLimiter.consume(ip);
6565
6666 /** @type {import('../users.js').User} */
6767 const user = await storage.getItem(toKey(request.body.handle));
6868
6969 if (!user) {
@@ -111,7 +111,7 @@ router.post('/recover-step1', jsonParser, async (request, response) => {
111111 const ip = getIpFromRequest(request);
112112 await recoverLimiter.consume(ip);
113113
114114 /** @type {import('../users.js').User} */
115115 const user = await storage.getItem(toKey(request.body.handle));
116116
117117 if (!user) {
@@ -148,7 +148,7 @@ router.post('/recover-step2', jsonParser, async (request, response) => {
148148 return response.status(400).json({ error: 'Missing required fields' });
149149 }
150150
151151 /** @type {import('../users.js').User} */
152152 const user = await storage.getItem(toKey(request.body.handle));
153153 const ip = getIpFromRequest(request);
154154
src/endpoints/vectors.js+8 -8
@@ -39,7 +39,7 @@ const SOURCES = [
3939 * @param {Object} sourceSettings - Settings for the source, if it needs any
4040 * @param {string} text - The text to get the vector for
4141 * @param {boolean} isQuery - If the text is a query for embedding search
4242 * @param {import('../users.js').UserDirectoryList} directories - The directories object for the user
4343 * @returns {Promise<number[]>} - The vector for the text
4444 */
4545async function getVector(source, sourceSettings, text, isQuery, directories) {
@@ -75,7 +75,7 @@ async function getVector(source, sourceSettings, text, isQuery, directories) {
7575 * @param {Object} sourceSettings - Settings for the source, if it needs any
7676 * @param {string[]} texts - The array of texts to get the vector for
7777 * @param {boolean} isQuery - If the text is a query for embedding search
7878 * @param {import('../users.js').UserDirectoryList} directories - The directories object for the user
7979 * @returns {Promise<number[][]>} - The array of vectors for the texts
8080 */
8181async function getBatchVector(source, sourceSettings, texts, isQuery, directories) {
@@ -195,7 +195,7 @@ function getModelScope(sourceSettings) {
195195
196196/**
197197 * Gets the index for the vector collection
198198 * @param {import('../users.js').UserDirectoryList} directories - User directories
199199 * @param {string} collectionId - The collection ID
200200 * @param {string} source - The source of the vector
201201 * @param {object} sourceSettings - The model for the source
@@ -215,7 +215,7 @@ async function getIndex(directories, collectionId, source, sourceSettings) {
215215
216216/**
217217 * Inserts items into the vector collection
218218 * @param {import('../users.js').UserDirectoryList} directories - User directories
219219 * @param {string} collectionId - The collection ID
220220 * @param {string} source - The source of the vector
221221 * @param {Object} sourceSettings - Settings for the source, if it needs any
@@ -239,7 +239,7 @@ async function insertVectorItems(directories, collectionId, source, sourceSettin
239239
240240/**
241241 * Gets the hashes of the items in the vector collection
242242 * @param {import('../users.js').UserDirectoryList} directories - User directories
243243 * @param {string} collectionId - The collection ID
244244 * @param {string} source - The source of the vector
245245 * @param {Object} sourceSettings - Settings for the source, if it needs any
@@ -256,7 +256,7 @@ async function getSavedHashes(directories, collectionId, source, sourceSettings)
256256
257257/**
258258 * Deletes items from the vector collection by hash
259259 * @param {import('../users.js').UserDirectoryList} directories - User directories
260260 * @param {string} collectionId - The collection ID
261261 * @param {string} source - The source of the vector
262262 * @param {Object} sourceSettings - Settings for the source, if it needs any
@@ -277,7 +277,7 @@ async function deleteVectorItems(directories, collectionId, source, sourceSettin
277277
278278/**
279279 * Gets the hashes of the items in the vector collection that match the search text
280280 * @param {import('../users.js').UserDirectoryList} directories - User directories
281281 * @param {string} collectionId - The collection ID
282282 * @param {string} source - The source of the vector
283283 * @param {Object} sourceSettings - Settings for the source, if it needs any
@@ -298,7 +298,7 @@ async function queryCollection(directories, collectionId, source, sourceSettings
298298
299299/**
300300 * Queries multiple collections for the given search queries. Returns the overall top K results.
301301 * @param {import('../users.js').UserDirectoryList} directories - User directories
302302 * @param {string[]} collectionIds - The collection IDs to query
303303 * @param {string} source - The source of the vector
304304 * @param {Object} sourceSettings - Settings for the source, if it needs any
src/endpoints/worldinfo.js+1 -1
@@ -9,7 +9,7 @@ import { jsonParser, urlencodedParser } from '../express-common.js';
99
1010/**
1111 * Reads a World Info file and returns its contents
1212 * @param {import('../users.js').UserDirectoryList} directories User directories
1313 * @param {string} worldInfoName Name of the World Info file
1414 * @param {boolean} allowDummy If true, returns an empty object if the file doesn't exist
1515 * @returns {object} World Info file contents
src/middleware/basicAuth.js+1 -0
@@ -2,6 +2,7 @@
22 * When applied, this middleware will ensure the request contains the required header for basic authentication and only
33 * allow access to the endpoint after successful authentication.
44 */
5+import { Buffer } from 'node:buffer';
56import storage from 'node-persist';
67import { getAllUserHandles, toKey, getPasswordHash } from '../users.js';
78import { getConfig, getConfigValue } from '../util.js';
src/middleware/multerMonkeyPatch.js+2 -0
@@ -1,3 +1,5 @@
1+import { Buffer } from 'node:buffer';
2+
13/**
24 * Decodes a file name from Latin1 to UTF-8.
35 * @param {string} str Input string
src/transformers.mjs+1 -0
@@ -1,5 +1,6 @@
11import path from 'node:path';
22import fs from 'node:fs';
3+import { Buffer } from 'node:buffer';
34
45import { pipeline, env, RawImage, Pipeline } from 'sillytavern-transformers';
56import { getConfigValue } from './util.js';
src/users.js+3 -2
@@ -3,6 +3,7 @@ import * as path from 'node:path';
33import * as fs from 'node:fs';
44import * as crypto from 'node:crypto';
55import * as os from 'node:os';
6+import { Buffer } from 'node:buffer';
67
78// Express and other dependencies
89import storage from 'node-persist';
@@ -93,7 +94,7 @@ const STORAGE_KEYS = {
9394
9495/**
9596 * Ensures that the content directories exist.
9697 * @returns {Promise<import('./users.js').UserDirectoryList[]>} - The list of user directories
9798 */
9899export async function ensurePublicDirectoriesExist() {
99100 for (const dir of Object.values(PUBLIC_DIRECTORIES)) {
@@ -116,7 +117,7 @@ export async function ensurePublicDirectoriesExist() {
116117
117118/**
118119 * Gets a list of all user directories.
119120 * @returns {Promise<import('./users.js').UserDirectoryList[]>} - The list of user directories
120121 */
121122export async function getUserDirectoriesList() {
122123 const userHandles = await getAllUserHandles();
src/util.js+1 -0
@@ -3,6 +3,7 @@ import * as fs from 'node:fs';
33import * as http2 from 'node:http2';
44import { Readable } from 'node:stream';
55import { createRequire } from 'node:module';
6+import { Buffer } from 'node:buffer';
67
78import yaml from 'yaml';
89import { sync as commandExistsSync } from 'command-exists';
src/vectors/cohere-vectors.js+2 -2
@@ -5,7 +5,7 @@ import { SECRET_KEYS, readSecret } from '../endpoints/secrets.js';
55 * Gets the vector for the given text batch from an OpenAI compatible endpoint.
66 * @param {string[]} texts - The array of texts to get the vector for
77 * @param {boolean} isQuery - If the text is a query for embedding search
88 * @param {import('../users.js').UserDirectoryList} directories - The directories object for the user
99 * @param {string} model - The model to use for the embedding
1010 * @returns {Promise<number[][]>} - The array of vectors for the texts
1111 */
@@ -51,7 +51,7 @@ export async function getCohereBatchVector(texts, isQuery, directories, model) {
5151 * Gets the vector for the given text from an OpenAI compatible endpoint.
5252 * @param {string} text - The text to get the vector for
5353 * @param {boolean} isQuery - If the text is a query for embedding search
5454 * @param {import('../users.js').UserDirectoryList} directories - The directories object for the user
5555 * @param {string} model - The model to use for the embedding
5656 * @returns {Promise<number[]>} - The vector for the text
5757 */
src/vectors/llamacpp-vectors.js+2 -2
@@ -6,7 +6,7 @@ import { TEXTGEN_TYPES } from '../constants.js';
66 * Gets the vector for the given text from LlamaCpp
77 * @param {string[]} texts - The array of texts to get the vectors for
88 * @param {string} apiUrl - The API URL
99 * @param {import('../users.js').UserDirectoryList} directories - The directories object for the user
1010 * @returns {Promise<number[][]>} - The array of vectors for the texts
1111 */
1212export async function getLlamaCppBatchVector(texts, apiUrl, directories) {
@@ -47,7 +47,7 @@ export async function getLlamaCppBatchVector(texts, apiUrl, directories) {
4747 * Gets the vector for the given text from LlamaCpp
4848 * @param {string} text - The text to get the vector for
4949 * @param {string} apiUrl - The API URL
5050 * @param {import('../users.js').UserDirectoryList} directories - The directories object for the user
5151 * @returns {Promise<number[]>} - The vector for the text
5252 */
5353export async function getLlamaCppVector(text, apiUrl, directories) {
src/vectors/makersuite-vectors.js+2 -2
@@ -5,7 +5,7 @@ const API_MAKERSUITE = 'https://generativelanguage.googleapis.com';
55/**
66 * Gets the vector for the given text from gecko model
77 * @param {string[]} texts - The array of texts to get the vector for
88 * @param {import('../users.js').UserDirectoryList} directories - The directories object for the user
99 * @returns {Promise<number[][]>} - The array of vectors for the texts
1010 */
1111export async function getMakerSuiteBatchVector(texts, directories) {
@@ -16,7 +16,7 @@ export async function getMakerSuiteBatchVector(texts, directories) {
1616/**
1717 * Gets the vector for the given text from Gemini API text-embedding-004 model
1818 * @param {string} text - The text to get the vector for
1919 * @param {import('../users.js').UserDirectoryList} directories - The directories object for the user
2020 * @returns {Promise<number[]>} - The vector for the text
2121 */
2222export async function getMakerSuiteVector(text, directories) {
src/vectors/nomicai-vectors.js+2 -2
@@ -13,7 +13,7 @@ const SOURCES = {
1313 * Gets the vector for the given text batch from an OpenAI compatible endpoint.
1414 * @param {string[]} texts - The array of texts to get the vector for
1515 * @param {string} source - The source of the vector
1616 * @param {import('../users.js').UserDirectoryList} directories - The directories object for the user
1717 * @returns {Promise<number[][]>} - The array of vectors for the texts
1818 */
1919export async function getNomicAIBatchVector(texts, source, directories) {
@@ -64,7 +64,7 @@ export async function getNomicAIBatchVector(texts, source, directories) {
6464 * Gets the vector for the given text from an OpenAI compatible endpoint.
6565 * @param {string} text - The text to get the vector for
6666 * @param {string} source - The source of the vector
6767 * @param {import('../users.js').UserDirectoryList} directories - The directories object for the user
6868 * @returns {Promise<number[]>} - The vector for the text
6969 */
7070export async function getNomicAIVector(text, source, directories) {
src/vectors/ollama-vectors.js+2 -2
@@ -8,7 +8,7 @@ import { TEXTGEN_TYPES } from '../constants.js';
88 * @param {string} apiUrl - The API URL
99 * @param {string} model - The model to use
1010 * @param {boolean} keep - Keep the model loaded in memory
1111 * @param {import('../users.js').UserDirectoryList} directories - The directories object for the user
1212 * @returns {Promise<number[][]>} - The array of vectors for the texts
1313 */
1414export async function getOllamaBatchVector(texts, apiUrl, model, keep, directories) {
@@ -26,7 +26,7 @@ export async function getOllamaBatchVector(texts, apiUrl, model, keep, directori
2626 * @param {string} apiUrl - The API URL
2727 * @param {string} model - The model to use
2828 * @param {boolean} keep - Keep the model loaded in memory
2929 * @param {import('../users.js').UserDirectoryList} directories - The directories object for the user
3030 * @returns {Promise<number[]>} - The vector for the text
3131 */
3232export async function getOllamaVector(text, apiUrl, model, keep, directories) {
src/vectors/openai-vectors.js+2 -2
@@ -23,7 +23,7 @@ const SOURCES = {
2323 * Gets the vector for the given text batch from an OpenAI compatible endpoint.
2424 * @param {string[]} texts - The array of texts to get the vector for
2525 * @param {string} source - The source of the vector
2626 * @param {import('../users.js').UserDirectoryList} directories - The directories object for the user
2727 * @param {string} model - The model to use for the embedding
2828 * @returns {Promise<number[][]>} - The array of vectors for the texts
2929 */
@@ -79,7 +79,7 @@ export async function getOpenAIBatchVector(texts, source, directories, model = '
7979 * Gets the vector for the given text from an OpenAI compatible endpoint.
8080 * @param {string} text - The text to get the vector for
8181 * @param {string} source - The source of the vector
8282 * @param {import('../users.js').UserDirectoryList} directories - The directories object for the user
8383 * @param {string} model - The model to use for the embedding
8484 * @returns {Promise<number[]>} - The vector for the text
8585 */
src/vectors/vllm-vectors.js+2 -2
@@ -7,7 +7,7 @@ import { TEXTGEN_TYPES } from '../constants.js';
77 * @param {string[]} texts - The array of texts to get the vectors for
88 * @param {string} apiUrl - The API URL
99 * @param {string} model - The model to use
1010 * @param {import('../users.js').UserDirectoryList} directories - The directories object for the user
1111 * @returns {Promise<number[][]>} - The array of vectors for the texts
1212 */
1313export async function getVllmBatchVector(texts, apiUrl, model, directories) {
@@ -49,7 +49,7 @@ export async function getVllmBatchVector(texts, apiUrl, model, directories) {
4949 * @param {string} text - The text to get the vector for
5050 * @param {string} apiUrl - The API URL
5151 * @param {string} model - The model to use
5252 * @param {import('../users.js').UserDirectoryList} directories - The directories object for the user
5353 * @returns {Promise<number[]>} - The vector for the text
5454 */
5555export async function getVllmVector(text, apiUrl, model, directories) {