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