unvendor: Replace seedrandom

e1694ede9df77b0b40780e0052a3d9ec9c0f7537

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

8 files changed, +15 -8Ignore whitespace
package-lock.json+7 -0
@@ -57,6 +57,7 @@
57 "rate-limiter-flexible": "^5.0.0",57 "rate-limiter-flexible": "^5.0.0",
58 "response-time": "^2.3.2",58 "response-time": "^2.3.2",
59 "sanitize-filename": "^1.6.3",59 "sanitize-filename": "^1.6.3",
60 "seedrandom": "^3.0.5",
60 "showdown": "^2.1.0",61 "showdown": "^2.1.0",
61 "sillytavern-transformers": "2.14.6",62 "sillytavern-transformers": "2.14.6",
62 "simple-git": "^3.19.1",63 "simple-git": "^3.19.1",
@@ -7015,6 +7016,12 @@
7015 "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==",7016 "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==",
7016 "license": "MIT"7017 "license": "MIT"
7017 },7018 },
7019 "node_modules/seedrandom": {
7020 "version": "3.0.5",
7021 "resolved": "https://registry.npmjs.org/seedrandom/-/seedrandom-3.0.5.tgz",
7022 "integrity": "sha512-8OwmbklUNzwezjGInmZ+2clQmExQPvomqjL7LFqOYqtmuxRgQYqOD3mHaU+MvZn5FLUeVxVfQjwLZW/n/JFuqg==",
7023 "license": "MIT"
7024 },
7018 "node_modules/semver": {7025 "node_modules/semver": {
7019 "version": "7.6.3",7026 "version": "7.6.3",
7020 "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz",7027 "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz",
package.json+1 -0
@@ -47,6 +47,7 @@
47 "rate-limiter-flexible": "^5.0.0",47 "rate-limiter-flexible": "^5.0.0",
48 "response-time": "^2.3.2",48 "response-time": "^2.3.2",
49 "sanitize-filename": "^1.6.3",49 "sanitize-filename": "^1.6.3",
50 "seedrandom": "^3.0.5",
50 "showdown": "^2.1.0",51 "showdown": "^2.1.0",
51 "sillytavern-transformers": "2.14.6",52 "sillytavern-transformers": "2.14.6",
52 "simple-git": "^3.19.1",53 "simple-git": "^3.19.1",
public/index.html+0 -1
@@ -6752,7 +6752,6 @@
6752 <script src="lib/toastr.min.js"></script>6752 <script src="lib/toastr.min.js"></script>
6753 <script src="lib/select2.min.js"></script>6753 <script src="lib/select2.min.js"></script>
6754 <script src="lib/select2-search-placeholder.js"></script>6754 <script src="lib/select2-search-placeholder.js"></script>
6755 <script src="lib/seedrandom.min.js"></script>
6756 <script src="lib/droll.js"></script>6755 <script src="lib/droll.js"></script>
6757 <script src="lib/pagination.js"></script>6756 <script src="lib/pagination.js"></script>
6758 <script src="lib/toolcool-color-picker.js"></script>6757 <script src="lib/toolcool-color-picker.js"></script>
public/jsconfig.json+0 -1
@@ -18,7 +18,6 @@
18 "typeAcquisition": {18 "typeAcquisition": {
19 "include": [19 "include": [
20 "@popperjs/core",20 "@popperjs/core",
21 "seedrandom",
22 "showdown-katex",21 "showdown-katex",
23 "droll"22 "droll"
24 ]23 ]
public/lib.js+3 -0
@@ -17,6 +17,7 @@ import { isProbablyReaderable, Readability } from '@mozilla/readability';
17import SVGInject from '@iconfu/svg-inject';17import SVGInject from '@iconfu/svg-inject';
18import showdown from 'showdown';18import showdown from 'showdown';
19import moment from 'moment';19import moment from 'moment';
20import seedrandom from 'seedrandom';
2021
21/**22/**
22 * Expose the libraries to the 'window' object.23 * Expose the libraries to the 'window' object.
@@ -82,6 +83,7 @@ export default {
82 SVGInject,83 SVGInject,
83 showdown,84 showdown,
84 moment,85 moment,
86 seedrandom,
85};87};
8688
87export {89export {
@@ -101,4 +103,5 @@ export {
101 SVGInject,103 SVGInject,
102 showdown,104 showdown,
103 moment,105 moment,
106 seedrandom,
104};107};
public/lib/seedrandom.min.js+0 -1
@@ -1 +0,0 @@
1!function(f,a,c){var s,l=256,p="random",d=c.pow(l,6),g=c.pow(2,52),y=2*g,h=l-1;function n(n,t,r){function e(){for(var n=u.g(6),t=d,r=0;n<g;)n=(n+r)*l,t*=l,r=u.g(1);for(;y<=n;)n/=2,t/=2,r>>>=1;return(n+r)/t}var o=[],i=j(function n(t,r){var e,o=[],i=typeof t;if(r&&"object"==i)for(e in t)try{o.push(n(t[e],r-1))}catch(n){}return o.length?o:"string"==i?t:t+"\0"}((t=1==t?{entropy:!0}:t||{}).entropy?[n,S(a)]:null==n?function(){try{var n;return s&&(n=s.randomBytes)?n=n(l):(n=new Uint8Array(l),(f.crypto||f.msCrypto).getRandomValues(n)),S(n)}catch(n){var t=f.navigator,r=t&&t.plugins;return[+new Date,f,r,f.screen,S(a)]}}():n,3),o),u=new m(o);return e.int32=function(){return 0|u.g(4)},e.quick=function(){return u.g(4)/4294967296},e.double=e,j(S(u.S),a),(t.pass||r||function(n,t,r,e){return e&&(e.S&&v(e,u),n.state=function(){return v(u,{})}),r?(c[p]=n,t):n})(e,i,"global"in t?t.global:this==c,t.state)}function m(n){var t,r=n.length,u=this,e=0,o=u.i=u.j=0,i=u.S=[];for(r||(n=[r++]);e<l;)i[e]=e++;for(e=0;e<l;e++)i[e]=i[o=h&o+n[e%r]+(t=i[e])],i[o]=t;(u.g=function(n){for(var t,r=0,e=u.i,o=u.j,i=u.S;n--;)t=i[e=h&e+1],r=r*l+i[h&(i[e]=i[o=h&o+t])+(i[o]=t)];return u.i=e,u.j=o,r})(l)}function v(n,t){return t.i=n.i,t.j=n.j,t.S=n.S.slice(),t}function j(n,t){for(var r,e=n+"",o=0;o<e.length;)t[h&o]=h&(r^=19*t[h&o])+e.charCodeAt(o++);return S(t)}function S(n){return String.fromCharCode.apply(0,n)}if(j(c.random(),a),"object"==typeof module&&module.exports){module.exports=n;try{s=require("crypto")}catch(n){}}else"function"==typeof define&&define.amd?define(function(){return n}):c["seed"+p]=n}("undefined"!=typeof self?self:this,[],Math);
1 \ No newline at end of file \ No newline at end of file
public/lib/showdown-toc.min.js+0 -1
@@ -1 +0,0 @@
1!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).showdownToc=t()}(this,(function(){"use strict";function e(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function t(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}return function(){var r=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).toc;return function(){return[{type:"output",filter:function(n){var o=[];n.replace(/(<h([1-6]).*?id="([^"]*?)".*?>(.+?)<\/h[1-6]>)|(<p>\[toc\]<\/p>)/g,(function(n,c,u,i,p){if("<p>[toc]</p>"===n)o.push({type:"toc"});else{p=p.replace(/<[^>]+>/g,"");var f={anchor:i,level:Number(u),text:p};r&&r.push(f),o.push(function(r){for(var n=1;arguments.length>n;n++){var o=null!=arguments[n]?arguments[n]:{};n%2?t(o,!0).forEach((function(t){e(r,t,o[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(o)):t(o).forEach((function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(o,e))}))}return r}({type:"header"},f))}return""}));var c=[];return o.forEach((function(e,t){if("toc"===e.type)if(o[t+1]&&"header"===o[t+1].type){for(var r=[],n=o[t+1].level,u=t+1;o.length>u&&"toc"!==o[u].type;u++){o[u].level===n&&r.push(o[u])}c.push(r)}else c.push([])})),n=n.replace(/<p>\[toc\]<\/p>[\n]*/g,(function(){var e=c.shift();return e&&e.length?"<ol>".concat(e.map((function(e){var t=e.text;return'<li><a href="#'.concat(e.anchor,'">').concat(t,"</a></li>")})).join(""),"</ol>\n"):""}))}}]}}}));
public/scripts/macros.js+4 -4
@@ -1,4 +1,4 @@
1import { Handlebars, moment } from '../lib.js';1import { Handlebars, moment, seedrandom } from '../lib.js';
2import { chat, chat_metadata, main_api, getMaxContextSize, getCurrentChatId, substituteParams } from '../script.js';2import { chat, chat_metadata, main_api, getMaxContextSize, getCurrentChatId, substituteParams } from '../script.js';
3import { timestampToMoment, isDigitsOnly, getStringHash, escapeRegex, uuidv4 } from './utils.js';3import { timestampToMoment, isDigitsOnly, getStringHash, escapeRegex, uuidv4 } from './utils.js';
4import { textgenerationwebui_banned_in_macros } from './textgen-settings.js';4import { textgenerationwebui_banned_in_macros } from './textgen-settings.js';
@@ -330,7 +330,7 @@ function randomReplace(input, emptyListPlaceholder = '') {
330 if (list.length === 0) {330 if (list.length === 0) {
331 return emptyListPlaceholder;331 return emptyListPlaceholder;
332 }332 }
333 const rng = new Math.seedrandom('added entropy.', { entropy: true });333 const rng = seedrandom('added entropy.', { entropy: true });
334 const randomIndex = Math.floor(rng() * list.length);334 const randomIndex = Math.floor(rng() * list.length);
335 return list[randomIndex];335 return list[randomIndex];
336 });336 });
@@ -359,8 +359,8 @@ function pickReplace(input, rawContent, emptyListPlaceholder = '') {
359 // We build a hash seed based on: unique chat file, raw content, and the placement inside this content359 // We build a hash seed based on: unique chat file, raw content, and the placement inside this content
360 // This allows us to get unique but repeatable picks in nearly all cases360 // This allows us to get unique but repeatable picks in nearly all cases
361 const combinedSeedString = `${chatIdHash}-${rawContentHash}-${offset}`;361 const combinedSeedString = `${chatIdHash}-${rawContentHash}-${offset}`;
362 const finalSeed = getStringHash(combinedSeedString);362 const finalSeed = getStringHash(combinedSeedString).toString();
363 const rng = new Math.seedrandom(finalSeed);363 const rng = seedrandom(finalSeed);
364 const randomIndex = Math.floor(rng() * list.length);364 const randomIndex = Math.floor(rng() * list.length);
365 return list[randomIndex];365 return list[randomIndex];
366 });366 });