diff --git a/package-lock.json b/package-lock.json index 92c2259c2..a9849315e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -57,6 +57,7 @@ "rate-limiter-flexible": "^5.0.0", "response-time": "^2.3.2", "sanitize-filename": "^1.6.3", + "seedrandom": "^3.0.5", "showdown": "^2.1.0", "sillytavern-transformers": "2.14.6", "simple-git": "^3.19.1", @@ -7015,6 +7016,12 @@ "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", "license": "MIT" }, + "node_modules/seedrandom": { + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/seedrandom/-/seedrandom-3.0.5.tgz", + "integrity": "sha512-8OwmbklUNzwezjGInmZ+2clQmExQPvomqjL7LFqOYqtmuxRgQYqOD3mHaU+MvZn5FLUeVxVfQjwLZW/n/JFuqg==", + "license": "MIT" + }, "node_modules/semver": { "version": "7.6.3", "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz", diff --git a/package.json b/package.json index 1a4445d96..d67b9b605 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ "rate-limiter-flexible": "^5.0.0", "response-time": "^2.3.2", "sanitize-filename": "^1.6.3", + "seedrandom": "^3.0.5", "showdown": "^2.1.0", "sillytavern-transformers": "2.14.6", "simple-git": "^3.19.1", diff --git a/public/index.html b/public/index.html index cb9e3af06..e838d4eae 100644 --- a/public/index.html +++ b/public/index.html @@ -6752,7 +6752,6 @@ - diff --git a/public/jsconfig.json b/public/jsconfig.json index 3e89dfd52..a38d4c9af 100644 --- a/public/jsconfig.json +++ b/public/jsconfig.json @@ -18,7 +18,6 @@ "typeAcquisition": { "include": [ "@popperjs/core", - "seedrandom", "showdown-katex", "droll" ] diff --git a/public/lib.js b/public/lib.js index 23b8afd3f..bc64c01b8 100644 --- a/public/lib.js +++ b/public/lib.js @@ -17,6 +17,7 @@ import { isProbablyReaderable, Readability } from '@mozilla/readability'; import SVGInject from '@iconfu/svg-inject'; import showdown from 'showdown'; import moment from 'moment'; +import seedrandom from 'seedrandom'; /** * Expose the libraries to the 'window' object. @@ -82,6 +83,7 @@ export default { SVGInject, showdown, moment, + seedrandom, }; export { @@ -101,4 +103,5 @@ export { SVGInject, showdown, moment, + seedrandom, }; diff --git a/public/lib/seedrandom.min.js b/public/lib/seedrandom.min.js deleted file mode 100644 index 56e1afcdc..000000000 --- a/public/lib/seedrandom.min.js +++ /dev/null @@ -1 +0,0 @@ -!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>>=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++]);e0&&void 0!==arguments[0]?arguments[0]:{}).toc;return function(){return[{type:"output",filter:function(n){var o=[];n.replace(/((.+?)<\/h[1-6]>)|(

\[toc\]<\/p>)/g,(function(n,c,u,i,p){if("

[toc]

"===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(/

\[toc\]<\/p>[\n]*/g,(function(){var e=c.shift();return e&&e.length?"

    ".concat(e.map((function(e){var t=e.text;return'
  1. ').concat(t,"
  2. ")})).join(""),"
\n"):""}))}}]}}})); diff --git a/public/scripts/macros.js b/public/scripts/macros.js index e68688fd5..503ae2553 100644 --- a/public/scripts/macros.js +++ b/public/scripts/macros.js @@ -1,4 +1,4 @@ -import { Handlebars, moment } from '../lib.js'; +import { Handlebars, moment, seedrandom } from '../lib.js'; import { chat, chat_metadata, main_api, getMaxContextSize, getCurrentChatId, substituteParams } from '../script.js'; import { timestampToMoment, isDigitsOnly, getStringHash, escapeRegex, uuidv4 } from './utils.js'; import { textgenerationwebui_banned_in_macros } from './textgen-settings.js'; @@ -330,7 +330,7 @@ function randomReplace(input, emptyListPlaceholder = '') { if (list.length === 0) { return emptyListPlaceholder; } - const rng = new Math.seedrandom('added entropy.', { entropy: true }); + const rng = seedrandom('added entropy.', { entropy: true }); const randomIndex = Math.floor(rng() * list.length); return list[randomIndex]; }); @@ -359,8 +359,8 @@ function pickReplace(input, rawContent, emptyListPlaceholder = '') { // We build a hash seed based on: unique chat file, raw content, and the placement inside this content // This allows us to get unique but repeatable picks in nearly all cases const combinedSeedString = `${chatIdHash}-${rawContentHash}-${offset}`; - const finalSeed = getStringHash(combinedSeedString); - const rng = new Math.seedrandom(finalSeed); + const finalSeed = getStringHash(combinedSeedString).toString(); + const rng = seedrandom(finalSeed); const randomIndex = Math.floor(rng() * list.length); return list[randomIndex]; });