mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
unvendor: Replace seedrandom
This commit is contained in:
7
package-lock.json
generated
7
package-lock.json
generated
@ -57,6 +57,7 @@
|
|||||||
"rate-limiter-flexible": "^5.0.0",
|
"rate-limiter-flexible": "^5.0.0",
|
||||||
"response-time": "^2.3.2",
|
"response-time": "^2.3.2",
|
||||||
"sanitize-filename": "^1.6.3",
|
"sanitize-filename": "^1.6.3",
|
||||||
|
"seedrandom": "^3.0.5",
|
||||||
"showdown": "^2.1.0",
|
"showdown": "^2.1.0",
|
||||||
"sillytavern-transformers": "2.14.6",
|
"sillytavern-transformers": "2.14.6",
|
||||||
"simple-git": "^3.19.1",
|
"simple-git": "^3.19.1",
|
||||||
@ -7015,6 +7016,12 @@
|
|||||||
"integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==",
|
"integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==",
|
||||||
"license": "MIT"
|
"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": {
|
"node_modules/semver": {
|
||||||
"version": "7.6.3",
|
"version": "7.6.3",
|
||||||
"resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz",
|
"resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz",
|
||||||
|
@ -47,6 +47,7 @@
|
|||||||
"rate-limiter-flexible": "^5.0.0",
|
"rate-limiter-flexible": "^5.0.0",
|
||||||
"response-time": "^2.3.2",
|
"response-time": "^2.3.2",
|
||||||
"sanitize-filename": "^1.6.3",
|
"sanitize-filename": "^1.6.3",
|
||||||
|
"seedrandom": "^3.0.5",
|
||||||
"showdown": "^2.1.0",
|
"showdown": "^2.1.0",
|
||||||
"sillytavern-transformers": "2.14.6",
|
"sillytavern-transformers": "2.14.6",
|
||||||
"simple-git": "^3.19.1",
|
"simple-git": "^3.19.1",
|
||||||
|
@ -6752,7 +6752,6 @@
|
|||||||
<script src="lib/toastr.min.js"></script>
|
<script src="lib/toastr.min.js"></script>
|
||||||
<script src="lib/select2.min.js"></script>
|
<script src="lib/select2.min.js"></script>
|
||||||
<script src="lib/select2-search-placeholder.js"></script>
|
<script src="lib/select2-search-placeholder.js"></script>
|
||||||
<script src="lib/seedrandom.min.js"></script>
|
|
||||||
<script src="lib/droll.js"></script>
|
<script src="lib/droll.js"></script>
|
||||||
<script src="lib/pagination.js"></script>
|
<script src="lib/pagination.js"></script>
|
||||||
<script src="lib/toolcool-color-picker.js"></script>
|
<script src="lib/toolcool-color-picker.js"></script>
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
"typeAcquisition": {
|
"typeAcquisition": {
|
||||||
"include": [
|
"include": [
|
||||||
"@popperjs/core",
|
"@popperjs/core",
|
||||||
"seedrandom",
|
|
||||||
"showdown-katex",
|
"showdown-katex",
|
||||||
"droll"
|
"droll"
|
||||||
]
|
]
|
||||||
|
@ -17,6 +17,7 @@ import { isProbablyReaderable, Readability } from '@mozilla/readability';
|
|||||||
import SVGInject from '@iconfu/svg-inject';
|
import SVGInject from '@iconfu/svg-inject';
|
||||||
import showdown from 'showdown';
|
import showdown from 'showdown';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
|
import seedrandom from 'seedrandom';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Expose the libraries to the 'window' object.
|
* Expose the libraries to the 'window' object.
|
||||||
@ -82,6 +83,7 @@ export default {
|
|||||||
SVGInject,
|
SVGInject,
|
||||||
showdown,
|
showdown,
|
||||||
moment,
|
moment,
|
||||||
|
seedrandom,
|
||||||
};
|
};
|
||||||
|
|
||||||
export {
|
export {
|
||||||
@ -101,4 +103,5 @@ export {
|
|||||||
SVGInject,
|
SVGInject,
|
||||||
showdown,
|
showdown,
|
||||||
moment,
|
moment,
|
||||||
|
seedrandom,
|
||||||
};
|
};
|
||||||
|
1
public/lib/seedrandom.min.js
vendored
1
public/lib/seedrandom.min.js
vendored
@ -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<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
public/lib/showdown-toc.min.js
vendored
1
public/lib/showdown-toc.min.js
vendored
@ -1 +0,0 @@
|
|||||||
!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"):""}))}}]}}}));
|
|
@ -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 { chat, chat_metadata, main_api, getMaxContextSize, getCurrentChatId, substituteParams } from '../script.js';
|
||||||
import { timestampToMoment, isDigitsOnly, getStringHash, escapeRegex, uuidv4 } from './utils.js';
|
import { timestampToMoment, isDigitsOnly, getStringHash, escapeRegex, uuidv4 } from './utils.js';
|
||||||
import { textgenerationwebui_banned_in_macros } from './textgen-settings.js';
|
import { textgenerationwebui_banned_in_macros } from './textgen-settings.js';
|
||||||
@ -330,7 +330,7 @@ function randomReplace(input, emptyListPlaceholder = '') {
|
|||||||
if (list.length === 0) {
|
if (list.length === 0) {
|
||||||
return emptyListPlaceholder;
|
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);
|
const randomIndex = Math.floor(rng() * list.length);
|
||||||
return list[randomIndex];
|
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
|
// 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
|
// This allows us to get unique but repeatable picks in nearly all cases
|
||||||
const combinedSeedString = `${chatIdHash}-${rawContentHash}-${offset}`;
|
const combinedSeedString = `${chatIdHash}-${rawContentHash}-${offset}`;
|
||||||
const finalSeed = getStringHash(combinedSeedString);
|
const finalSeed = getStringHash(combinedSeedString).toString();
|
||||||
const rng = new Math.seedrandom(finalSeed);
|
const rng = seedrandom(finalSeed);
|
||||||
const randomIndex = Math.floor(rng() * list.length);
|
const randomIndex = Math.floor(rng() * list.length);
|
||||||
return list[randomIndex];
|
return list[randomIndex];
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user