Explicitly import Buffer. Specify jsdoc local extensions
| @@ -4,7 +4,7 @@ import { getConfigValue } from './util.js'; | ||
| 4 | 4 | |
| 5 | 5 | /** |
| 6 | 6 | * Gets the headers for the Mancer API. |
| 7 | 7 | * @param {import('./users.js').UserDirectoryList} directories User directories |
| 8 | 8 | * @returns {object} Headers for the request |
| 9 | 9 | */ |
| 10 | 10 | function getMancerHeaders(directories) { |
| @@ -18,7 +18,7 @@ function getMancerHeaders(directories) { | ||
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | 20 | * Gets the headers for the TogetherAI API. |
| 21 | 21 | * @param {import('./users.js').UserDirectoryList} directories User directories |
| 22 | 22 | * @returns {object} Headers for the request |
| 23 | 23 | */ |
| 24 | 24 | function getTogetherAIHeaders(directories) { |
| @@ -31,7 +31,7 @@ function getTogetherAIHeaders(directories) { | ||
| 31 | 31 | |
| 32 | 32 | /** |
| 33 | 33 | * Gets the headers for the InfermaticAI API. |
| 34 | 34 | * @param {import('./users.js').UserDirectoryList} directories User directories |
| 35 | 35 | * @returns {object} Headers for the request |
| 36 | 36 | */ |
| 37 | 37 | function getInfermaticAIHeaders(directories) { |
| @@ -44,7 +44,7 @@ function getInfermaticAIHeaders(directories) { | ||
| 44 | 44 | |
| 45 | 45 | /** |
| 46 | 46 | * Gets the headers for the DreamGen API. |
| 47 | 47 | * @param {import('./users.js').UserDirectoryList} directories User directories |
| 48 | 48 | * @returns {object} Headers for the request |
| 49 | 49 | */ |
| 50 | 50 | function getDreamGenHeaders(directories) { |
| @@ -57,7 +57,7 @@ function getDreamGenHeaders(directories) { | ||
| 57 | 57 | |
| 58 | 58 | /** |
| 59 | 59 | * Gets the headers for the OpenRouter API. |
| 60 | 60 | * @param {import('./users.js').UserDirectoryList} directories User directories |
| 61 | 61 | * @returns {object} Headers for the request |
| 62 | 62 | */ |
| 63 | 63 | function getOpenRouterHeaders(directories) { |
| @@ -69,7 +69,7 @@ function getOpenRouterHeaders(directories) { | ||
| 69 | 69 | |
| 70 | 70 | /** |
| 71 | 71 | * Gets the headers for the vLLM API. |
| 72 | 72 | * @param {import('./users.js').UserDirectoryList} directories User directories |
| 73 | 73 | * @returns {object} Headers for the request |
| 74 | 74 | */ |
| 75 | 75 | function getVllmHeaders(directories) { |
| @@ -82,7 +82,7 @@ function getVllmHeaders(directories) { | ||
| 82 | 82 | |
| 83 | 83 | /** |
| 84 | 84 | * Gets the headers for the Aphrodite API. |
| 85 | 85 | * @param {import('./users.js').UserDirectoryList} directories User directories |
| 86 | 86 | * @returns {object} Headers for the request |
| 87 | 87 | */ |
| 88 | 88 | function getAphroditeHeaders(directories) { |
| @@ -96,7 +96,7 @@ function getAphroditeHeaders(directories) { | ||
| 96 | 96 | |
| 97 | 97 | /** |
| 98 | 98 | * Gets the headers for the Tabby API. |
| 99 | 99 | * @param {import('./users.js').UserDirectoryList} directories User directories |
| 100 | 100 | * @returns {object} Headers for the request |
| 101 | 101 | */ |
| 102 | 102 | function getTabbyHeaders(directories) { |
| @@ -110,7 +110,7 @@ function getTabbyHeaders(directories) { | ||
| 110 | 110 | |
| 111 | 111 | /** |
| 112 | 112 | * Gets the headers for the LlamaCPP API. |
| 113 | 113 | * @param {import('./users.js').UserDirectoryList} directories User directories |
| 114 | 114 | * @returns {object} Headers for the request |
| 115 | 115 | */ |
| 116 | 116 | function getLlamaCppHeaders(directories) { |
| @@ -123,7 +123,7 @@ function getLlamaCppHeaders(directories) { | ||
| 123 | 123 | |
| 124 | 124 | /** |
| 125 | 125 | * Gets the headers for the Ooba API. |
| 126 | 126 | * @param {import('./users.js').UserDirectoryList} directories |
| 127 | 127 | * @returns {object} Headers for the request |
| 128 | 128 | */ |
| 129 | 129 | function getOobaHeaders(directories) { |
| @@ -136,7 +136,7 @@ function getOobaHeaders(directories) { | ||
| 136 | 136 | |
| 137 | 137 | /** |
| 138 | 138 | * Gets the headers for the KoboldCpp API. |
| 139 | 139 | * @param {import('./users.js').UserDirectoryList} directories |
| 140 | 140 | * @returns {object} Headers for the request |
| 141 | 141 | */ |
| 142 | 142 | function getKoboldCppHeaders(directories) { |
| @@ -149,7 +149,7 @@ function getKoboldCppHeaders(directories) { | ||
| 149 | 149 | |
| 150 | 150 | /** |
| 151 | 151 | * Gets the headers for the Featherless API. |
| 152 | 152 | * @param {import('./users.js').UserDirectoryList} directories |
| 153 | 153 | * @returns {object} Headers for the request |
| 154 | 154 | */ |
| 155 | 155 | function getFeatherlessHeaders(directories) { |
| @@ -161,7 +161,7 @@ function getFeatherlessHeaders(directories) { | ||
| 161 | 161 | |
| 162 | 162 | /** |
| 163 | 163 | * Gets the headers for the HuggingFace API. |
| 164 | 164 | * @param {import('./users.js').UserDirectoryList} directories |
| 165 | 165 | * @returns {object} Headers for the request |
| 166 | 166 | */ |
| 167 | 167 | function getHuggingFaceHeaders(directories) { |
| @@ -197,7 +197,7 @@ export function setAdditionalHeaders(request, args, server) { | ||
| 197 | 197 | * @param {object} requestHeaders Request headers |
| 198 | 198 | * @param {string} type API type |
| 199 | 199 | * @param {string|null} server API server for new request |
| 200 | 200 | * @param {import('./users.js').UserDirectoryList} directories User directories |
| 201 | 201 | */ |
| 202 | 202 | export function setAdditionalHeadersByType(requestHeaders, type, server, directories) { |
| 203 | 203 | const headerGetters = { |
| @@ -1,4 +1,5 @@ | ||
| 1 | 1 | import fs from 'node:fs'; |
| 2 | +import { Buffer } from 'node:buffer'; | |
| 2 | 3 | |
| 3 | 4 | import encode from 'png-chunks-encode'; |
| 4 | 5 | import extract from 'png-chunks-extract'; |
| @@ -8,7 +8,7 @@ export const PUBLIC_DIRECTORIES = { | ||
| 8 | 8 | export const SETTINGS_FILE = 'settings.json'; |
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | 11 | * @type {import('./users.js').UserDirectoryList} |
| 12 | 12 | * @readonly |
| 13 | 13 | * @enum {string} |
| 14 | 14 | */ |
| @@ -45,7 +45,7 @@ export const USER_DIRECTORY_TEMPLATE = Object.freeze({ | ||
| 45 | 45 | }); |
| 46 | 46 | |
| 47 | 47 | /** |
| 48 | 48 | * @type {import('./users.js').User} |
| 49 | 49 | * @readonly |
| 50 | 50 | */ |
| 51 | 51 | export const DEFAULT_USER = Object.freeze({ |
| @@ -79,7 +79,7 @@ function getFiles(dir, files = []) { | ||
| 79 | 79 | |
| 80 | 80 | /** |
| 81 | 81 | * Ensure that the asset folders exist. |
| 82 | 82 | * @param {import('../users.js').UserDirectoryList} directories - The user's directories |
| 83 | 83 | */ |
| 84 | 84 | function ensureFoldersExist(directories) { |
| 85 | 85 | const folderPath = path.join(directories.assets); |
| @@ -2,6 +2,7 @@ import * as path from 'node:path'; | ||
| 2 | 2 | import * as fs from 'node:fs'; |
| 3 | 3 | import { promises as fsPromises } from 'node:fs'; |
| 4 | 4 | import * as readline from 'node:readline'; |
| 5 | +import { Buffer } from 'node:buffer'; | |
| 5 | 6 | |
| 6 | 7 | import express from 'express'; |
| 7 | 8 | import sanitize from 'sanitize-filename'; |
| @@ -188,7 +189,7 @@ const calculateDataSize = (data) => { | ||
| 188 | 189 | * processCharacter - Process a given character, read its data and calculate its statistics. |
| 189 | 190 | * |
| 190 | 191 | * @param {string} item The name of the character. |
| 191 | 192 | * @param {import('../users.js').UserDirectoryList} directories User directories |
| 192 | 193 | * @return {Promise<object>} A Promise that resolves when the character processing is done. |
| 193 | 194 | */ |
| 194 | 195 | const processCharacter = async (item, directories) => { |
| @@ -232,7 +233,7 @@ const processCharacter = async (item, directories) => { | ||
| 232 | 233 | /** |
| 233 | 234 | * Convert a character object to Spec V2 format. |
| 234 | 235 | * @param {object} jsonObject Character object |
| 235 | 236 | * @param {import('../users.js').UserDirectoryList} directories User directories |
| 236 | 237 | * @param {boolean} hoistDate Will set the chat and create_date fields to the current date if they are missing |
| 237 | 238 | * @returns {object} Character object in Spec V2 format |
| 238 | 239 | */ |
| @@ -252,7 +253,7 @@ function getCharaCardV2(jsonObject, directories, hoistDate = true) { | ||
| 252 | 253 | /** |
| 253 | 254 | * Convert a character object to Spec V2 format. |
| 254 | 255 | * @param {object} char Character object |
| 255 | 256 | * @param {import('../users.js').UserDirectoryList} directories User directories |
| 256 | 257 | * @returns {object} Character object in Spec V2 format |
| 257 | 258 | */ |
| 258 | 259 | function convertToV2(char, directories) { |
| @@ -342,7 +343,7 @@ function readFromV2(char) { | ||
| 342 | 343 | /** |
| 343 | 344 | * Format character data to Spec V2 format. |
| 344 | 345 | * @param {object} data Character data |
| 345 | 346 | * @param {import('../users.js').UserDirectoryList} directories User directories |
| 346 | 347 | * @returns |
| 347 | 348 | */ |
| 348 | 349 | function charaFormatData(data, directories) { |
| @@ -1081,7 +1082,7 @@ router.post('/chats', jsonParser, async function (request, response) { | ||
| 1081 | 1082 | /** |
| 1082 | 1083 | * Gets the name for the uploaded PNG file. |
| 1083 | 1084 | * @param {string} file File name |
| 1084 | 1085 | * @param {import('../users.js').UserDirectoryList} directories User directories |
| 1085 | 1086 | * @returns {string} - The name for the uploaded PNG file |
| 1086 | 1087 | */ |
| 1087 | 1088 | function getPngName(file, directories) { |
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | import * as fs from 'node:fs'; |
| 2 | 2 | import * as path from 'node:path'; |
| 3 | +import { Buffer } from 'node:buffer'; | |
| 3 | 4 | |
| 4 | 5 | import express from 'express'; |
| 5 | 6 | import fetch from 'node-fetch'; |
| @@ -50,7 +51,7 @@ export const CONTENT_TYPES = { | ||
| 50 | 51 | |
| 51 | 52 | /** |
| 52 | 53 | * Gets the default presets from the content directory. |
| 53 | 54 | * @param {import('../users.js').UserDirectoryList} directories User directories |
| 54 | 55 | * @returns {object[]} Array of default presets |
| 55 | 56 | */ |
| 56 | 57 | export function getDefaultPresets(directories) { |
| @@ -97,7 +98,7 @@ export function getDefaultPresetFile(filename) { | ||
| 97 | 98 | /** |
| 98 | 99 | * Seeds content for a user. |
| 99 | 100 | * @param {ContentItem[]} contentIndex Content index |
| 100 | 101 | * @param {import('../users.js').UserDirectoryList} directories User directories |
| 101 | 102 | * @param {string[]} forceCategories List of categories to force check (even if content check is skipped) |
| 102 | 103 | * @returns {Promise<boolean>} Whether any content was added |
| 103 | 104 | */ |
| @@ -156,7 +157,7 @@ async function seedContentForUser(contentIndex, directories, forceCategories) { | ||
| 156 | 157 | |
| 157 | 158 | /** |
| 158 | 159 | * Checks for new content and seeds it for all users. |
| 159 | 160 | * @param {import('../users.js').UserDirectoryList[]} directoriesList List of user directories |
| 160 | 161 | * @param {string[]} forceCategories List of categories to force check (even if content check is skipped) |
| 161 | 162 | * @returns {Promise<void>} |
| 162 | 163 | */ |
| @@ -258,7 +259,7 @@ export function getContentOfType(type, format) { | ||
| 258 | 259 | /** |
| 259 | 260 | * Gets the target directory for the specified asset type. |
| 260 | 261 | * @param {ContentType} type Asset type |
| 261 | 262 | * @param {import('../users.js').UserDirectoryList} directories User directories |
| 262 | 263 | * @returns {string | null} Target directory |
| 263 | 264 | */ |
| 264 | 265 | function getTargetByType(type, directories) { |
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | import * as fs from 'node:fs'; |
| 2 | 2 | import * as path from 'node:path'; |
| 3 | +import { Buffer } from 'node:buffer'; | |
| 3 | 4 | |
| 4 | 5 | import express from 'express'; |
| 5 | 6 | import sanitize from 'sanitize-filename'; |
| @@ -1,4 +1,5 @@ | ||
| 1 | 1 | import * as util from 'node:util'; |
| 2 | +import { Buffer } from 'node:buffer'; | |
| 2 | 3 | |
| 3 | 4 | import fetch from 'node-fetch'; |
| 4 | 5 | import express from 'express'; |
| @@ -1,4 +1,5 @@ | ||
| 1 | 1 | import * as fs from 'node:fs'; |
| 2 | +import { Buffer } from 'node:buffer'; | |
| 2 | 3 | |
| 3 | 4 | import fetch from 'node-fetch'; |
| 4 | 5 | import FormData from 'form-data'; |
| @@ -11,7 +11,7 @@ import { jsonParser } from '../express-common.js'; | ||
| 11 | 11 | /** |
| 12 | 12 | * Gets the folder and extension for the preset settings based on the API source ID. |
| 13 | 13 | * @param {string} apiId API source ID |
| 14 | 14 | * @param {import('../users.js').UserDirectoryList} directories User directories |
| 15 | 15 | * @returns {object} Object containing the folder and extension for the preset settings |
| 16 | 16 | */ |
| 17 | 17 | function getPresetSettingsByAPI(apiId, directories) { |
| @@ -59,7 +59,7 @@ const EXPORTABLE_KEYS = [ | ||
| 59 | 59 | |
| 60 | 60 | /** |
| 61 | 61 | * Writes a secret to the secrets file |
| 62 | 62 | * @param {import('../users.js').UserDirectoryList} directories User directories |
| 63 | 63 | * @param {string} key Secret key |
| 64 | 64 | * @param {string} value Secret value |
| 65 | 65 | */ |
| @@ -79,7 +79,7 @@ export function writeSecret(directories, key, value) { | ||
| 79 | 79 | |
| 80 | 80 | /** |
| 81 | 81 | * Deletes a secret from the secrets file |
| 82 | 82 | * @param {import('../users.js').UserDirectoryList} directories User directories |
| 83 | 83 | * @param {string} key Secret key |
| 84 | 84 | * @returns |
| 85 | 85 | */ |
| @@ -98,7 +98,7 @@ export function deleteSecret(directories, key) { | ||
| 98 | 98 | |
| 99 | 99 | /** |
| 100 | 100 | * Reads a secret from the secrets file |
| 101 | 101 | * @param {import('../users.js').UserDirectoryList} directories User directories |
| 102 | 102 | * @param {string} key Secret key |
| 103 | 103 | * @returns {string} Secret value |
| 104 | 104 | */ |
| @@ -116,7 +116,7 @@ export function readSecret(directories, key) { | ||
| 116 | 116 | |
| 117 | 117 | /** |
| 118 | 118 | * Reads the secret state from the secrets file |
| 119 | 119 | * @param {import('../users.js').UserDirectoryList} directories User directories |
| 120 | 120 | * @returns {object} Secret state |
| 121 | 121 | */ |
| 122 | 122 | export function readSecretState(directories) { |
| @@ -139,7 +139,7 @@ export function readSecretState(directories) { | ||
| 139 | 139 | |
| 140 | 140 | /** |
| 141 | 141 | * Reads all secrets from the secrets file |
| 142 | 142 | * @param {import('../users.js').UserDirectoryList} directories User directories |
| 143 | 143 | * @returns {Record<string, string> | undefined} Secrets |
| 144 | 144 | */ |
| 145 | 145 | export function getAllSecrets(directories) { |
| @@ -1,3 +1,4 @@ | ||
| 1 | +import { Buffer } from 'node:buffer'; | |
| 1 | 2 | import express from 'express'; |
| 2 | 3 | import wavefile from 'wavefile'; |
| 3 | 4 | import { jsonParser } from '../express-common.js'; |
| @@ -11,7 +11,7 @@ import { jsonParser, urlencodedParser } from '../express-common.js'; | ||
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | 13 | * Gets the path to the sprites folder for the provided character name |
| 14 | 14 | * @param {import('../users.js').UserDirectoryList} directories - User directories |
| 15 | 15 | * @param {string} name - The name of the character |
| 16 | 16 | * @param {boolean} isSubfolder - Whether the name contains a subfolder |
| 17 | 17 | * @returns {string | null} The path to the sprites folder. Null if the name is invalid. |
| @@ -42,7 +42,7 @@ function getSpritesPath(directories, name, isSubfolder) { | ||
| 42 | 42 | * Imports base64 encoded sprites from RisuAI character data. |
| 43 | 43 | * The sprites are saved in the character's sprites folder. |
| 44 | 44 | * The additionalAssets and emotions are removed from the data. |
| 45 | 45 | * @param {import('../users.js').UserDirectoryList} directories User directories |
| 46 | 46 | * @param {object} data RisuAI character data |
| 47 | 47 | * @returns {void} |
| 48 | 48 | */ |
| @@ -18,7 +18,7 @@ const pngFormat = getConfigValue('avatarThumbnailsPng', false); | ||
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | 20 | * Gets a path to thumbnail folder based on the type. |
| 21 | 21 | * @param {import('../users.js').UserDirectoryList} directories User directories |
| 22 | 22 | * @param {'bg' | 'avatar'} type Thumbnail type |
| 23 | 23 | * @returns {string} Path to the thumbnails folder |
| 24 | 24 | */ |
| @@ -39,7 +39,7 @@ function getThumbnailFolder(directories, type) { | ||
| 39 | 39 | |
| 40 | 40 | /** |
| 41 | 41 | * Gets a path to the original images folder based on the type. |
| 42 | 42 | * @param {import('../users.js').UserDirectoryList} directories User directories |
| 43 | 43 | * @param {'bg' | 'avatar'} type Thumbnail type |
| 44 | 44 | * @returns {string} Path to the original images folder |
| 45 | 45 | */ |
| @@ -60,7 +60,7 @@ function getOriginalFolder(directories, type) { | ||
| 60 | 60 | |
| 61 | 61 | /** |
| 62 | 62 | * Removes the generated thumbnail from the disk. |
| 63 | 63 | * @param {import('../users.js').UserDirectoryList} directories User directories |
| 64 | 64 | * @param {'bg' | 'avatar'} type Type of the thumbnail |
| 65 | 65 | * @param {string} file Name of the file |
| 66 | 66 | */ |
| @@ -77,7 +77,7 @@ export function invalidateThumbnail(directories, type, file) { | ||
| 77 | 77 | |
| 78 | 78 | /** |
| 79 | 79 | * Generates a thumbnail for the given file. |
| 80 | 80 | * @param {import('../users.js').UserDirectoryList} directories User directories |
| 81 | 81 | * @param {'bg' | 'avatar'} type Type of the thumbnail |
| 82 | 82 | * @param {string} file Name of the file |
| 83 | 83 | * @returns |
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | import * as fs from 'node:fs'; |
| 2 | 2 | import * as path from 'node:path'; |
| 3 | +import { Buffer } from 'node:buffer'; | |
| 3 | 4 | |
| 4 | 5 | import express from 'express'; |
| 5 | 6 | import { sync as writeFileAtomicSync } from 'write-file-atomic'; |
| @@ -1,5 +1,7 @@ | ||
| 1 | 1 | import * as https from 'node:https'; |
| 2 | 2 | import { createRequire } from 'node:module'; |
| 3 | +import { Buffer } from 'node:buffer'; | |
| 4 | + | |
| 3 | 5 | import fetch from 'node-fetch'; |
| 4 | 6 | import express from 'express'; |
| 5 | 7 | import iconv from 'iconv-lite'; |
| @@ -22,10 +22,10 @@ export const router = express.Router(); | ||
| 22 | 22 | |
| 23 | 23 | router.post('/get', requireAdminMiddleware, jsonParser, async (_request, response) => { |
| 24 | 24 | try { |
| 25 | 25 | /** @type {import('../users.js').User[]} */ |
| 26 | 26 | const users = await storage.values(x => x.key.startsWith(KEY_PREFIX)); |
| 27 | 27 | |
| 28 | 28 | /** @type {Promise<import('../users.js').UserViewModel>[]} */ |
| 29 | 29 | const viewModelPromises = users |
| 30 | 30 | .map(user => new Promise(resolve => { |
| 31 | 31 | getUserAvatar(user.handle).then(avatar => |
| @@ -62,7 +62,7 @@ router.post('/disable', requireAdminMiddleware, jsonParser, async (request, resp | ||
| 62 | 62 | return response.status(400).json({ error: 'Cannot disable yourself' }); |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | /** @type {import('../users.js').User} */ |
| 66 | 66 | const user = await storage.getItem(toKey(request.body.handle)); |
| 67 | 67 | |
| 68 | 68 | if (!user) { |
| @@ -86,7 +86,7 @@ router.post('/enable', requireAdminMiddleware, jsonParser, async (request, respo | ||
| 86 | 86 | return response.status(400).json({ error: 'Missing required fields' }); |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | /** @type {import('../users.js').User} */ |
| 90 | 90 | const user = await storage.getItem(toKey(request.body.handle)); |
| 91 | 91 | |
| 92 | 92 | if (!user) { |
| @@ -110,7 +110,7 @@ router.post('/promote', requireAdminMiddleware, jsonParser, async (request, resp | ||
| 110 | 110 | return response.status(400).json({ error: 'Missing required fields' }); |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | /** @type {import('../users.js').User} */ |
| 114 | 114 | const user = await storage.getItem(toKey(request.body.handle)); |
| 115 | 115 | |
| 116 | 116 | if (!user) { |
| @@ -139,7 +139,7 @@ router.post('/demote', requireAdminMiddleware, jsonParser, async (request, respo | ||
| 139 | 139 | return response.status(400).json({ error: 'Cannot demote yourself' }); |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | /** @type {import('../users.js').User} */ |
| 143 | 143 | const user = await storage.getItem(toKey(request.body.handle)); |
| 144 | 144 | |
| 145 | 145 | if (!user) { |
| @@ -72,7 +72,7 @@ router.post('/change-avatar', jsonParser, async (request, response) => { | ||
| 72 | 72 | return response.status(400).json({ error: 'Invalid data URL' }); |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | /** @type {import('../users.js').User} */ |
| 76 | 76 | const user = await storage.getItem(toKey(request.body.handle)); |
| 77 | 77 | |
| 78 | 78 | if (!user) { |
| @@ -101,7 +101,7 @@ router.post('/change-password', jsonParser, async (request, response) => { | ||
| 101 | 101 | return response.status(403).json({ error: 'Unauthorized' }); |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | /** @type {import('../users.js').User} */ |
| 105 | 105 | const user = await storage.getItem(toKey(request.body.handle)); |
| 106 | 106 | |
| 107 | 107 | if (!user) { |
| @@ -189,7 +189,7 @@ router.post('/change-name', jsonParser, async (request, response) => { | ||
| 189 | 189 | return response.status(403).json({ error: 'Unauthorized' }); |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | /** @type {import('../users.js').User} */ |
| 193 | 193 | const user = await storage.getItem(toKey(request.body.handle)); |
| 194 | 194 | |
| 195 | 195 | if (!user) { |
| @@ -26,10 +26,10 @@ router.post('/list', async (_request, response) => { | ||
| 26 | 26 | return response.sendStatus(204); |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | /** @type {import('../users.js').User[]} */ |
| 30 | 30 | const users = await storage.values(x => x.key.startsWith(KEY_PREFIX)); |
| 31 | 31 | |
| 32 | 32 | /** @type {Promise<import('../users.js').UserViewModel>[]} */ |
| 33 | 33 | const viewModelPromises = users |
| 34 | 34 | .filter(x => x.enabled) |
| 35 | 35 | .map(user => new Promise(async (resolve) => { |
| @@ -63,7 +63,7 @@ router.post('/login', jsonParser, async (request, response) => { | ||
| 63 | 63 | const ip = getIpFromRequest(request); |
| 64 | 64 | await loginLimiter.consume(ip); |
| 65 | 65 | |
| 66 | 66 | /** @type {import('../users.js').User} */ |
| 67 | 67 | const user = await storage.getItem(toKey(request.body.handle)); |
| 68 | 68 | |
| 69 | 69 | if (!user) { |
| @@ -111,7 +111,7 @@ router.post('/recover-step1', jsonParser, async (request, response) => { | ||
| 111 | 111 | const ip = getIpFromRequest(request); |
| 112 | 112 | await recoverLimiter.consume(ip); |
| 113 | 113 | |
| 114 | 114 | /** @type {import('../users.js').User} */ |
| 115 | 115 | const user = await storage.getItem(toKey(request.body.handle)); |
| 116 | 116 | |
| 117 | 117 | if (!user) { |
| @@ -148,7 +148,7 @@ router.post('/recover-step2', jsonParser, async (request, response) => { | ||
| 148 | 148 | return response.status(400).json({ error: 'Missing required fields' }); |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | /** @type {import('../users.js').User} */ |
| 152 | 152 | const user = await storage.getItem(toKey(request.body.handle)); |
| 153 | 153 | const ip = getIpFromRequest(request); |
| 154 | 154 | |
| @@ -39,7 +39,7 @@ const SOURCES = [ | ||
| 39 | 39 | * @param {Object} sourceSettings - Settings for the source, if it needs any |
| 40 | 40 | * @param {string} text - The text to get the vector for |
| 41 | 41 | * @param {boolean} isQuery - If the text is a query for embedding search |
| 42 | 42 | * @param {import('../users.js').UserDirectoryList} directories - The directories object for the user |
| 43 | 43 | * @returns {Promise<number[]>} - The vector for the text |
| 44 | 44 | */ |
| 45 | 45 | async function getVector(source, sourceSettings, text, isQuery, directories) { |
| @@ -75,7 +75,7 @@ async function getVector(source, sourceSettings, text, isQuery, directories) { | ||
| 75 | 75 | * @param {Object} sourceSettings - Settings for the source, if it needs any |
| 76 | 76 | * @param {string[]} texts - The array of texts to get the vector for |
| 77 | 77 | * @param {boolean} isQuery - If the text is a query for embedding search |
| 78 | 78 | * @param {import('../users.js').UserDirectoryList} directories - The directories object for the user |
| 79 | 79 | * @returns {Promise<number[][]>} - The array of vectors for the texts |
| 80 | 80 | */ |
| 81 | 81 | async function getBatchVector(source, sourceSettings, texts, isQuery, directories) { |
| @@ -195,7 +195,7 @@ function getModelScope(sourceSettings) { | ||
| 195 | 195 | |
| 196 | 196 | /** |
| 197 | 197 | * Gets the index for the vector collection |
| 198 | 198 | * @param {import('../users.js').UserDirectoryList} directories - User directories |
| 199 | 199 | * @param {string} collectionId - The collection ID |
| 200 | 200 | * @param {string} source - The source of the vector |
| 201 | 201 | * @param {object} sourceSettings - The model for the source |
| @@ -215,7 +215,7 @@ async function getIndex(directories, collectionId, source, sourceSettings) { | ||
| 215 | 215 | |
| 216 | 216 | /** |
| 217 | 217 | * Inserts items into the vector collection |
| 218 | 218 | * @param {import('../users.js').UserDirectoryList} directories - User directories |
| 219 | 219 | * @param {string} collectionId - The collection ID |
| 220 | 220 | * @param {string} source - The source of the vector |
| 221 | 221 | * @param {Object} sourceSettings - Settings for the source, if it needs any |
| @@ -239,7 +239,7 @@ async function insertVectorItems(directories, collectionId, source, sourceSettin | ||
| 239 | 239 | |
| 240 | 240 | /** |
| 241 | 241 | * Gets the hashes of the items in the vector collection |
| 242 | 242 | * @param {import('../users.js').UserDirectoryList} directories - User directories |
| 243 | 243 | * @param {string} collectionId - The collection ID |
| 244 | 244 | * @param {string} source - The source of the vector |
| 245 | 245 | * @param {Object} sourceSettings - Settings for the source, if it needs any |
| @@ -256,7 +256,7 @@ async function getSavedHashes(directories, collectionId, source, sourceSettings) | ||
| 256 | 256 | |
| 257 | 257 | /** |
| 258 | 258 | * Deletes items from the vector collection by hash |
| 259 | 259 | * @param {import('../users.js').UserDirectoryList} directories - User directories |
| 260 | 260 | * @param {string} collectionId - The collection ID |
| 261 | 261 | * @param {string} source - The source of the vector |
| 262 | 262 | * @param {Object} sourceSettings - Settings for the source, if it needs any |
| @@ -277,7 +277,7 @@ async function deleteVectorItems(directories, collectionId, source, sourceSettin | ||
| 277 | 277 | |
| 278 | 278 | /** |
| 279 | 279 | * Gets the hashes of the items in the vector collection that match the search text |
| 280 | 280 | * @param {import('../users.js').UserDirectoryList} directories - User directories |
| 281 | 281 | * @param {string} collectionId - The collection ID |
| 282 | 282 | * @param {string} source - The source of the vector |
| 283 | 283 | * @param {Object} sourceSettings - Settings for the source, if it needs any |
| @@ -298,7 +298,7 @@ async function queryCollection(directories, collectionId, source, sourceSettings | ||
| 298 | 298 | |
| 299 | 299 | /** |
| 300 | 300 | * Queries multiple collections for the given search queries. Returns the overall top K results. |
| 301 | 301 | * @param {import('../users.js').UserDirectoryList} directories - User directories |
| 302 | 302 | * @param {string[]} collectionIds - The collection IDs to query |
| 303 | 303 | * @param {string} source - The source of the vector |
| 304 | 304 | * @param {Object} sourceSettings - Settings for the source, if it needs any |
| @@ -9,7 +9,7 @@ import { jsonParser, urlencodedParser } from '../express-common.js'; | ||
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | 11 | * Reads a World Info file and returns its contents |
| 12 | 12 | * @param {import('../users.js').UserDirectoryList} directories User directories |
| 13 | 13 | * @param {string} worldInfoName Name of the World Info file |
| 14 | 14 | * @param {boolean} allowDummy If true, returns an empty object if the file doesn't exist |
| 15 | 15 | * @returns {object} World Info file contents |
| @@ -2,6 +2,7 @@ | ||
| 2 | 2 | * When applied, this middleware will ensure the request contains the required header for basic authentication and only |
| 3 | 3 | * allow access to the endpoint after successful authentication. |
| 4 | 4 | */ |
| 5 | +import { Buffer } from 'node:buffer'; | |
| 5 | 6 | import storage from 'node-persist'; |
| 6 | 7 | import { getAllUserHandles, toKey, getPasswordHash } from '../users.js'; |
| 7 | 8 | import { getConfig, getConfigValue } from '../util.js'; |
| @@ -1,3 +1,5 @@ | ||
| 1 | +import { Buffer } from 'node:buffer'; | |
| 2 | + | |
| 1 | 3 | /** |
| 2 | 4 | * Decodes a file name from Latin1 to UTF-8. |
| 3 | 5 | * @param {string} str Input string |
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | import path from 'node:path'; |
| 2 | 2 | import fs from 'node:fs'; |
| 3 | +import { Buffer } from 'node:buffer'; | |
| 3 | 4 | |
| 4 | 5 | import { pipeline, env, RawImage, Pipeline } from 'sillytavern-transformers'; |
| 5 | 6 | import { getConfigValue } from './util.js'; |
| @@ -3,6 +3,7 @@ import * as path from 'node:path'; | ||
| 3 | 3 | import * as fs from 'node:fs'; |
| 4 | 4 | import * as crypto from 'node:crypto'; |
| 5 | 5 | import * as os from 'node:os'; |
| 6 | +import { Buffer } from 'node:buffer'; | |
| 6 | 7 | |
| 7 | 8 | // Express and other dependencies |
| 8 | 9 | import storage from 'node-persist'; |
| @@ -93,7 +94,7 @@ const STORAGE_KEYS = { | ||
| 93 | 94 | |
| 94 | 95 | /** |
| 95 | 96 | * Ensures that the content directories exist. |
| 96 | 97 | * @returns {Promise<import('./users.js').UserDirectoryList[]>} - The list of user directories |
| 97 | 98 | */ |
| 98 | 99 | export async function ensurePublicDirectoriesExist() { |
| 99 | 100 | for (const dir of Object.values(PUBLIC_DIRECTORIES)) { |
| @@ -116,7 +117,7 @@ export async function ensurePublicDirectoriesExist() { | ||
| 116 | 117 | |
| 117 | 118 | /** |
| 118 | 119 | * Gets a list of all user directories. |
| 119 | 120 | * @returns {Promise<import('./users.js').UserDirectoryList[]>} - The list of user directories |
| 120 | 121 | */ |
| 121 | 122 | export async function getUserDirectoriesList() { |
| 122 | 123 | const userHandles = await getAllUserHandles(); |
| @@ -3,6 +3,7 @@ import * as fs from 'node:fs'; | ||
| 3 | 3 | import * as http2 from 'node:http2'; |
| 4 | 4 | import { Readable } from 'node:stream'; |
| 5 | 5 | import { createRequire } from 'node:module'; |
| 6 | +import { Buffer } from 'node:buffer'; | |
| 6 | 7 | |
| 7 | 8 | import yaml from 'yaml'; |
| 8 | 9 | import { sync as commandExistsSync } from 'command-exists'; |
| @@ -5,7 +5,7 @@ import { SECRET_KEYS, readSecret } from '../endpoints/secrets.js'; | ||
| 5 | 5 | * Gets the vector for the given text batch from an OpenAI compatible endpoint. |
| 6 | 6 | * @param {string[]} texts - The array of texts to get the vector for |
| 7 | 7 | * @param {boolean} isQuery - If the text is a query for embedding search |
| 8 | 8 | * @param {import('../users.js').UserDirectoryList} directories - The directories object for the user |
| 9 | 9 | * @param {string} model - The model to use for the embedding |
| 10 | 10 | * @returns {Promise<number[][]>} - The array of vectors for the texts |
| 11 | 11 | */ |
| @@ -51,7 +51,7 @@ export async function getCohereBatchVector(texts, isQuery, directories, model) { | ||
| 51 | 51 | * Gets the vector for the given text from an OpenAI compatible endpoint. |
| 52 | 52 | * @param {string} text - The text to get the vector for |
| 53 | 53 | * @param {boolean} isQuery - If the text is a query for embedding search |
| 54 | 54 | * @param {import('../users.js').UserDirectoryList} directories - The directories object for the user |
| 55 | 55 | * @param {string} model - The model to use for the embedding |
| 56 | 56 | * @returns {Promise<number[]>} - The vector for the text |
| 57 | 57 | */ |
| @@ -6,7 +6,7 @@ import { TEXTGEN_TYPES } from '../constants.js'; | ||
| 6 | 6 | * Gets the vector for the given text from LlamaCpp |
| 7 | 7 | * @param {string[]} texts - The array of texts to get the vectors for |
| 8 | 8 | * @param {string} apiUrl - The API URL |
| 9 | 9 | * @param {import('../users.js').UserDirectoryList} directories - The directories object for the user |
| 10 | 10 | * @returns {Promise<number[][]>} - The array of vectors for the texts |
| 11 | 11 | */ |
| 12 | 12 | export async function getLlamaCppBatchVector(texts, apiUrl, directories) { |
| @@ -47,7 +47,7 @@ export async function getLlamaCppBatchVector(texts, apiUrl, directories) { | ||
| 47 | 47 | * Gets the vector for the given text from LlamaCpp |
| 48 | 48 | * @param {string} text - The text to get the vector for |
| 49 | 49 | * @param {string} apiUrl - The API URL |
| 50 | 50 | * @param {import('../users.js').UserDirectoryList} directories - The directories object for the user |
| 51 | 51 | * @returns {Promise<number[]>} - The vector for the text |
| 52 | 52 | */ |
| 53 | 53 | export async function getLlamaCppVector(text, apiUrl, directories) { |
| @@ -5,7 +5,7 @@ const API_MAKERSUITE = 'https://generativelanguage.googleapis.com'; | ||
| 5 | 5 | /** |
| 6 | 6 | * Gets the vector for the given text from gecko model |
| 7 | 7 | * @param {string[]} texts - The array of texts to get the vector for |
| 8 | 8 | * @param {import('../users.js').UserDirectoryList} directories - The directories object for the user |
| 9 | 9 | * @returns {Promise<number[][]>} - The array of vectors for the texts |
| 10 | 10 | */ |
| 11 | 11 | export async function getMakerSuiteBatchVector(texts, directories) { |
| @@ -16,7 +16,7 @@ export async function getMakerSuiteBatchVector(texts, directories) { | ||
| 16 | 16 | /** |
| 17 | 17 | * Gets the vector for the given text from Gemini API text-embedding-004 model |
| 18 | 18 | * @param {string} text - The text to get the vector for |
| 19 | 19 | * @param {import('../users.js').UserDirectoryList} directories - The directories object for the user |
| 20 | 20 | * @returns {Promise<number[]>} - The vector for the text |
| 21 | 21 | */ |
| 22 | 22 | export async function getMakerSuiteVector(text, directories) { |
| @@ -13,7 +13,7 @@ const SOURCES = { | ||
| 13 | 13 | * Gets the vector for the given text batch from an OpenAI compatible endpoint. |
| 14 | 14 | * @param {string[]} texts - The array of texts to get the vector for |
| 15 | 15 | * @param {string} source - The source of the vector |
| 16 | 16 | * @param {import('../users.js').UserDirectoryList} directories - The directories object for the user |
| 17 | 17 | * @returns {Promise<number[][]>} - The array of vectors for the texts |
| 18 | 18 | */ |
| 19 | 19 | export async function getNomicAIBatchVector(texts, source, directories) { |
| @@ -64,7 +64,7 @@ export async function getNomicAIBatchVector(texts, source, directories) { | ||
| 64 | 64 | * Gets the vector for the given text from an OpenAI compatible endpoint. |
| 65 | 65 | * @param {string} text - The text to get the vector for |
| 66 | 66 | * @param {string} source - The source of the vector |
| 67 | 67 | * @param {import('../users.js').UserDirectoryList} directories - The directories object for the user |
| 68 | 68 | * @returns {Promise<number[]>} - The vector for the text |
| 69 | 69 | */ |
| 70 | 70 | export async function getNomicAIVector(text, source, directories) { |
| @@ -8,7 +8,7 @@ import { TEXTGEN_TYPES } from '../constants.js'; | ||
| 8 | 8 | * @param {string} apiUrl - The API URL |
| 9 | 9 | * @param {string} model - The model to use |
| 10 | 10 | * @param {boolean} keep - Keep the model loaded in memory |
| 11 | 11 | * @param {import('../users.js').UserDirectoryList} directories - The directories object for the user |
| 12 | 12 | * @returns {Promise<number[][]>} - The array of vectors for the texts |
| 13 | 13 | */ |
| 14 | 14 | export async function getOllamaBatchVector(texts, apiUrl, model, keep, directories) { |
| @@ -26,7 +26,7 @@ export async function getOllamaBatchVector(texts, apiUrl, model, keep, directori | ||
| 26 | 26 | * @param {string} apiUrl - The API URL |
| 27 | 27 | * @param {string} model - The model to use |
| 28 | 28 | * @param {boolean} keep - Keep the model loaded in memory |
| 29 | 29 | * @param {import('../users.js').UserDirectoryList} directories - The directories object for the user |
| 30 | 30 | * @returns {Promise<number[]>} - The vector for the text |
| 31 | 31 | */ |
| 32 | 32 | export async function getOllamaVector(text, apiUrl, model, keep, directories) { |
| @@ -23,7 +23,7 @@ const SOURCES = { | ||
| 23 | 23 | * Gets the vector for the given text batch from an OpenAI compatible endpoint. |
| 24 | 24 | * @param {string[]} texts - The array of texts to get the vector for |
| 25 | 25 | * @param {string} source - The source of the vector |
| 26 | 26 | * @param {import('../users.js').UserDirectoryList} directories - The directories object for the user |
| 27 | 27 | * @param {string} model - The model to use for the embedding |
| 28 | 28 | * @returns {Promise<number[][]>} - The array of vectors for the texts |
| 29 | 29 | */ |
| @@ -79,7 +79,7 @@ export async function getOpenAIBatchVector(texts, source, directories, model = ' | ||
| 79 | 79 | * Gets the vector for the given text from an OpenAI compatible endpoint. |
| 80 | 80 | * @param {string} text - The text to get the vector for |
| 81 | 81 | * @param {string} source - The source of the vector |
| 82 | 82 | * @param {import('../users.js').UserDirectoryList} directories - The directories object for the user |
| 83 | 83 | * @param {string} model - The model to use for the embedding |
| 84 | 84 | * @returns {Promise<number[]>} - The vector for the text |
| 85 | 85 | */ |
| @@ -7,7 +7,7 @@ import { TEXTGEN_TYPES } from '../constants.js'; | ||
| 7 | 7 | * @param {string[]} texts - The array of texts to get the vectors for |
| 8 | 8 | * @param {string} apiUrl - The API URL |
| 9 | 9 | * @param {string} model - The model to use |
| 10 | 10 | * @param {import('../users.js').UserDirectoryList} directories - The directories object for the user |
| 11 | 11 | * @returns {Promise<number[][]>} - The array of vectors for the texts |
| 12 | 12 | */ |
| 13 | 13 | export async function getVllmBatchVector(texts, apiUrl, model, directories) { |
| @@ -49,7 +49,7 @@ export async function getVllmBatchVector(texts, apiUrl, model, directories) { | ||
| 49 | 49 | * @param {string} text - The text to get the vector for |
| 50 | 50 | * @param {string} apiUrl - The API URL |
| 51 | 51 | * @param {string} model - The model to use |
| 52 | 52 | * @param {import('../users.js').UserDirectoryList} directories - The directories object for the user |
| 53 | 53 | * @returns {Promise<number[]>} - The vector for the text |
| 54 | 54 | */ |
| 55 | 55 | export async function getVllmVector(text, apiUrl, model, directories) { |