diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 9002ccb06..7e69ac482 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -52,7 +52,6 @@ module.exports = { globals: { droll: 'readonly', Handlebars: 'readonly', - localforage: 'readonly', moment: 'readonly', pdfjsLib: 'readonly', Popper: 'readonly', diff --git a/package-lock.json b/package-lock.json index d7f6dfd1b..a9a488905 100644 --- a/package-lock.json +++ b/package-lock.json @@ -34,6 +34,7 @@ "ip-matching": "^2.1.2", "ipaddr.js": "^2.0.1", "jimp": "^0.22.10", + "localforage": "^1.10.0", "lodash": "^4.17.21", "mime-types": "^2.1.35", "multer": "^1.4.5-lts.1", @@ -4504,6 +4505,12 @@ "integrity": "sha512-QpLcX9ZSsq3YYUUnD3nFDY8H7wctAhQj/TFKL8Ya8v5fMm3CFXxo8zStsLAl780ltoYoo1WvKUVGBQK+1ifr7g==", "license": "MIT" }, + "node_modules/immediate": { + "version": "3.0.6", + "resolved": "https://registry.npmjs.org/immediate/-/immediate-3.0.6.tgz", + "integrity": "sha512-XXOFtyqDjNDAQxVfYxuF7g9Il/IbWmmlQg2MYKOH8ExIT1qg6xc4zyS3HaEEATgs1btfzxq15ciUiY7gjSXRGQ==", + "license": "MIT" + }, "node_modules/import-fresh": { "version": "3.3.0", "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.3.0.tgz", @@ -4946,6 +4953,15 @@ "node": ">= 0.8.0" } }, + "node_modules/lie": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/lie/-/lie-3.1.1.tgz", + "integrity": "sha512-RiNhHysUjhrDQntfYSfY4MU24coXXdEOgw9WGcKHNeEwffDYbF//u87M1EWaMGzuFoSbqW0C9C6lEEhDOAswfw==", + "license": "MIT", + "dependencies": { + "immediate": "~3.0.5" + } + }, "node_modules/load-bmfont": { "version": "1.4.2", "resolved": "https://registry.npmjs.org/load-bmfont/-/load-bmfont-1.4.2.tgz", @@ -4971,6 +4987,15 @@ "node": ">=6.11.5" } }, + "node_modules/localforage": { + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/localforage/-/localforage-1.10.0.tgz", + "integrity": "sha512-14/H1aX7hzBBmmh7sGPd+AOMkkIrHM3Z1PAyGgZigA1H1p5O5ANnMyWzvpAETtG68/dC4pC0ncy3+PPGzXZHPg==", + "license": "Apache-2.0", + "dependencies": { + "lie": "3.1.1" + } + }, "node_modules/locate-path": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz", diff --git a/package.json b/package.json index 1a982faa9..292f29fb1 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "ip-matching": "^2.1.2", "ipaddr.js": "^2.0.1", "jimp": "^0.22.10", + "localforage": "^1.10.0", "lodash": "^4.17.21", "mime-types": "^2.1.35", "multer": "^1.4.5-lts.1", diff --git a/public/global.d.ts b/public/global.d.ts index 350cdfab7..9f475cffe 100644 --- a/public/global.d.ts +++ b/public/global.d.ts @@ -1,7 +1,6 @@ // Global namespace modules declare var droll; declare var Handlebars; -declare var localforage; declare var pdfjsLib; declare var Popper; declare var showdown; diff --git a/public/index.html b/public/index.html index a081f6490..a7ba21721 100644 --- a/public/index.html +++ b/public/index.html @@ -6758,7 +6758,6 @@ - diff --git a/public/jsconfig.json b/public/jsconfig.json index 4b6d97541..b0f6b5295 100644 --- a/public/jsconfig.json +++ b/public/jsconfig.json @@ -24,7 +24,6 @@ "droll", "handlebars", "highlight.js", - "localforage", "pdfjs-dist", "@mozilla/readability" ] diff --git a/public/lib.js b/public/lib.js index 2e4970b7d..2ee56f0d0 100644 --- a/public/lib.js +++ b/public/lib.js @@ -5,6 +5,7 @@ import Fuse from 'fuse.js'; import DOMPurify from 'dompurify'; import hljs from 'highlight.js'; +import localforage from 'localforage'; /** * Expose the libraries to the 'window' object. @@ -27,16 +28,22 @@ export function initLibraryShims() { // @ts-ignore window.hljs = hljs; } + if (!('localforage' in window)) { + // @ts-ignore + window.localforage = localforage; + } } export default { Fuse, DOMPurify, hljs, + localforage, }; export { Fuse, DOMPurify, hljs, + localforage, }; diff --git a/public/script.js b/public/script.js index 7a1eaeb2e..8e6595e30 100644 --- a/public/script.js +++ b/public/script.js @@ -2,6 +2,7 @@ import { Fuse, DOMPurify, hljs, + localforage, initLibraryShims, default as libs, } from './lib.js'; @@ -503,7 +504,7 @@ reloadMarkdownProcessor(); // array for prompt token calculations console.debug('initializing Prompt Itemization Array on Startup'); -const promptStorage = new localforage.createInstance({ name: 'SillyTavern_Prompts' }); +const promptStorage = localforage.createInstance({ name: 'SillyTavern_Prompts' }); export let itemizedPrompts = []; export const systemUserName = 'SillyTavern System'; diff --git a/public/scripts/tokenizers.js b/public/scripts/tokenizers.js index 60935f62a..846442895 100644 --- a/public/scripts/tokenizers.js +++ b/public/scripts/tokenizers.js @@ -1,3 +1,4 @@ +import { localforage } from '../lib.js'; import { characters, main_api, api_server, nai_settings, online_status, this_chid } from '../script.js'; import { power_user, registerDebugFunction } from './power-user.js'; import { chat_completion_sources, model_list, oai_settings } from './openai.js'; @@ -135,7 +136,7 @@ const TOKENIZER_URLS = { }, }; -const objectStore = new localforage.createInstance({ name: 'SillyTavern_ChatCompletions' }); +const objectStore = localforage.createInstance({ name: 'SillyTavern_ChatCompletions' }); let tokenCache = {};