From 368df653378b6fa72924c5dd077998e5b52ec0bb Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sat, 6 Apr 2024 15:55:06 +0300 Subject: [PATCH 01/14] Update docker-publish.yml --- .github/workflows/docker-publish.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 588fcd80c..a87527778 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -12,7 +12,7 @@ on: env: # This should allow creation of docker images even in forked repositories - IMAGE_NAME: ${{ github.repository }} + REPO: ${{ github.repository }} REGISTRY: ghcr.io jobs: @@ -20,6 +20,11 @@ jobs: runs-on: ubuntu-latest steps: + ## Workaround for GitHub repo names containing uppercase characters + - name: set lowercase repo name + run: | + echo "IMAGE_NAME=${REPO,,}" >>${GITHUB_ENV} + # Using the following workaround because currently GitHub Actions # does not support logical AND/OR operations on triggers # It's currently not possible to have `branches` under the `schedule` trigger From 679a2496741d03185dba31a55e3b97a3d68b4c53 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sat, 6 Apr 2024 16:00:42 +0300 Subject: [PATCH 02/14] Update docker-publish.yml --- .github/workflows/docker-publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index a87527778..e6d1653df 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -21,7 +21,7 @@ jobs: steps: ## Workaround for GitHub repo names containing uppercase characters - - name: set lowercase repo name + - name: Set lowercase repo name run: | echo "IMAGE_NAME=${REPO,,}" >>${GITHUB_ENV} From b4fcfcd6d65ad0dc72a1e8b07516220b28c7ad71 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sat, 6 Apr 2024 16:01:58 +0300 Subject: [PATCH 03/14] Update docker-publish.yml --- .github/workflows/docker-publish.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index e6d1653df..81682466c 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -9,6 +9,10 @@ on: schedule: # Build the staging image everyday at 00:00 UTC - cron: "0 0 * * *" + push: + # Temporary workaround + branches: + - release env: # This should allow creation of docker images even in forked repositories From 48295bc3786767d4f646aaea70dbf08a15c0cb56 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sat, 6 Apr 2024 16:04:05 +0300 Subject: [PATCH 04/14] Update docker-publish.yml --- .github/workflows/docker-publish.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 81682466c..c4556c520 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -32,12 +32,18 @@ jobs: # Using the following workaround because currently GitHub Actions # does not support logical AND/OR operations on triggers # It's currently not possible to have `branches` under the `schedule` trigger - - name: Checkout the release branch + - name: Checkout the release branch (on release) if: ${{ github.event_name == 'release' }} uses: actions/checkout@v3 with: ref: "release" + - name: Checkout the release branch (on push) + if: ${{ github.event_name == 'push' }} + uses: actions/checkout@v3 + with: + ref: "release" + - name: Checkout the staging branch if: ${{ github.event_name == 'schedule' }} uses: actions/checkout@v3 From 299ee3ae90cfb9370c2a0f5459a1d51f9fb44fe2 Mon Sep 17 00:00:00 2001 From: caesarw Date: Sun, 7 Apr 2024 14:31:48 +0000 Subject: [PATCH 05/14] Fix the wrong tags for the scheduled nightly build * simplified the checkout process * fixed the wrong tags for the scheduled builds (used to be `release`, now it should be `staging`) * upgraded the `checkout` action to v4.1.2 (no warnings anymore) --- .github/workflows/docker-publish.yml | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index c4556c520..9bb3a2cc5 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -24,32 +24,34 @@ jobs: runs-on: ubuntu-latest steps: - ## Workaround for GitHub repo names containing uppercase characters + # Workaround for GitHub repo names containing uppercase characters - name: Set lowercase repo name run: | - echo "IMAGE_NAME=${REPO,,}" >>${GITHUB_ENV} + echo "IMAGE_NAME=${REPO,,}" >> ${GITHUB_ENV} # Using the following workaround because currently GitHub Actions # does not support logical AND/OR operations on triggers # It's currently not possible to have `branches` under the `schedule` trigger - name: Checkout the release branch (on release) - if: ${{ github.event_name == 'release' }} - uses: actions/checkout@v3 - with: - ref: "release" - - - name: Checkout the release branch (on push) - if: ${{ github.event_name == 'push' }} - uses: actions/checkout@v3 + if: ${{ github.event_name == 'release' || github.event_name == 'push' }} + uses: actions/checkout@v4.1.2 with: ref: "release" - name: Checkout the staging branch if: ${{ github.event_name == 'schedule' }} - uses: actions/checkout@v3 + uses: actions/checkout@v4.1.2 with: ref: "staging" + # Get current branch name + # This is also part of the workaround for Actions not allowing logical + # AND/OR operators on triggers + # Otherwise the action triggered by schedule always has ref_name = release + - name: Get the current branch name + run: | + echo "BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)" >> ${GITHUB_ENV} + # Setting up QEMU for multi-arch image build - name: Set up QEMU uses: docker/setup-qemu-action@v3 @@ -62,7 +64,7 @@ jobs: id: metadata with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - tags: ${{ github.ref_name }} + tags: ${{ env.BRANCH_NAME }} # Login into package repository as the person who created the release - name: Log in to the Container registry From 2411a7480e926a76275566d487345bec471ec02d Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Tue, 9 Apr 2024 16:20:38 +0300 Subject: [PATCH 06/14] Add deprecated endpoint redirection --- server.js | 1 + 1 file changed, 1 insertion(+) diff --git a/server.js b/server.js index b6f59f0a3..81c1a3119 100644 --- a/server.js +++ b/server.js @@ -341,6 +341,7 @@ redirect('/savequickreply', '/api/quick-replies/save'); // Redirect deprecated image endpoints redirect('/uploadimage', '/api/images/upload'); redirect('/listimgfiles/:folder', '/api/images/list/:folder'); +redirect('/api/content/import', '/api/content/importURL'); // Redirect deprecated moving UI endpoints redirect('/savemovingui', '/api/moving-ui/save'); From 4f83782430adca851faafc774b3edf7ed44f157d Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Tue, 9 Apr 2024 19:06:10 +0300 Subject: [PATCH 07/14] Fix double count of chat injects for message fitting logic --- public/script.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/public/script.js b/public/script.js index 18e15e8e2..c57d4c93b 100644 --- a/public/script.js +++ b/public/script.js @@ -3466,7 +3466,6 @@ async function Generate(type, { automatic_trigger, force_name2, quiet_prompt, qu // Add persona description to prompt addPersonaDescriptionExtensionPrompt(); // Call combined AN into Generate - let allAnchors = getAllExtensionPrompts(); const beforeScenarioAnchor = getExtensionPrompt(extension_prompt_types.BEFORE_PROMPT).trimStart(); const afterScenarioAnchor = getExtensionPrompt(extension_prompt_types.IN_PROMPT); @@ -3513,10 +3512,11 @@ async function Generate(type, { automatic_trigger, force_name2, quiet_prompt, qu function getMessagesTokenCount() { const encodeString = [ + beforeScenarioAnchor, storyString, + afterScenarioAnchor, examplesString, chatString, - allAnchors, quiet_prompt, cyclePrompt, userAlignmentMessage, @@ -3784,12 +3784,13 @@ async function Generate(type, { automatic_trigger, force_name2, quiet_prompt, qu console.debug('---checking Prompt size'); setPromptString(); const prompt = [ + beforeScenarioAnchor, storyString, + afterScenarioAnchor, mesExmString, mesSend.map((e) => `${e.extensionPrompts.join('')}${e.message}`).join(''), '\n', generatedPromptCache, - allAnchors, quiet_prompt, ].join('').replace(/\r/gm, ''); let thisPromptContextSize = getTokenCount(prompt, power_user.token_padding); @@ -4025,7 +4026,7 @@ async function Generate(type, { automatic_trigger, force_name2, quiet_prompt, qu ...thisPromptBits[currentArrayEntry], rawPrompt: generate_data.prompt || generate_data.input, mesId: getNextMessageId(type), - allAnchors: allAnchors, + allAnchors: '', summarizeString: (extension_prompts['1_memory']?.value || ''), authorsNoteString: (extension_prompts['2_floating_prompt']?.value || ''), smartContextString: (extension_prompts['chromadb']?.value || ''), From 91558ad9ea7c4a6c50eab73b53492965b9cc8fa4 Mon Sep 17 00:00:00 2001 From: LenAnderson Date: Fri, 12 Apr 2024 20:49:55 -0400 Subject: [PATCH 08/14] add enter to submit on input type --- public/scripts/popup.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/public/scripts/popup.js b/public/scripts/popup.js index b793f3a66..03ca81e8c 100644 --- a/public/scripts/popup.js +++ b/public/scripts/popup.js @@ -107,6 +107,13 @@ export class Popup { // illegal argument } + this.input.addEventListener('keydown', (evt)=>{ + if (evt.key != 'Enter' || evt.altKey || evt.ctrlKey || evt.shiftKey) return; + evt.preventDefault(); + evt.stopPropagation(); + this.completeAffirmative(); + }); + this.ok.addEventListener('click', ()=>this.completeAffirmative()); this.cancel.addEventListener('click', ()=>this.completeNegative()); const keyListener = (evt)=>{ From 278ec029f5afc123ea15d95a47fb2ed5cdaf5298 Mon Sep 17 00:00:00 2001 From: LenAnderson Date: Fri, 12 Apr 2024 20:50:14 -0400 Subject: [PATCH 09/14] add missing cancelButton setting to callGenericPopup --- public/scripts/popup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/scripts/popup.js b/public/scripts/popup.js index 03ca81e8c..217991611 100644 --- a/public/scripts/popup.js +++ b/public/scripts/popup.js @@ -226,7 +226,7 @@ export function callGenericPopup(text, type, inputValue = '', { okButton, cancel text, type, inputValue, - { okButton, rows, wide, large, allowHorizontalScrolling, allowVerticalScrolling }, + { okButton, cancelButton, rows, wide, large, allowHorizontalScrolling, allowVerticalScrolling }, ); return popup.show(); } From 792be63c5c89b6ae6ecf4808c1347866e2a87d53 Mon Sep 17 00:00:00 2001 From: Zhongyi Lu Date: Fri, 12 Apr 2024 22:03:36 -0700 Subject: [PATCH 10/14] fix: whitelist in real-ip --- src/middleware/whitelist.js | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/middleware/whitelist.js b/src/middleware/whitelist.js index 87d5ac5a5..2ebc5e48f 100644 --- a/src/middleware/whitelist.js +++ b/src/middleware/whitelist.js @@ -19,6 +19,22 @@ if (fs.existsSync(whitelistPath)) { } } +function getForwardedIp(req) { + // Check if X-Real-IP is available + if (req.headers['x-real-ip']) { + return req.headers['x-real-ip']; + } + + // Check for X-Forwarded-For and parse if available + if (req.headers['x-forwarded-for']) { + const ipList = req.headers['x-forwarded-for'].split(',').map(ip => ip.trim()); + return ipList[0]; + } + + // If none of the headers are available, return undefined + return undefined; +} + function getIpFromRequest(req) { let clientIp = req.connection.remoteAddress; let ip = ipaddr.parse(clientIp); @@ -41,6 +57,7 @@ function getIpFromRequest(req) { function whitelistMiddleware(listen) { return function (req, res, next) { const clientIp = getIpFromRequest(req); + const forwardedIp = getForwardedIp(req); if (listen && !knownIPs.has(clientIp)) { const userAgent = req.headers['user-agent']; @@ -58,9 +75,13 @@ function whitelistMiddleware(listen) { } //clientIp = req.connection.remoteAddress.split(':').pop(); - if (whitelistMode === true && !whitelist.some(x => ipMatching.matches(clientIp, ipMatching.getMatch(x)))) { - console.log(color.red('Forbidden: Connection attempt from ' + clientIp + '. If you are attempting to connect, please add your IP address in whitelist or disable whitelist mode in config.yaml in root of SillyTavern folder.\n')); - return res.status(403).send('Forbidden: Connection attempt from ' + clientIp + '. If you are attempting to connect, please add your IP address in whitelist or disable whitelist mode in config.yaml in root of SillyTavern folder.'); + if (whitelistMode === true && !whitelist.some(x => ipMatching.matches(clientIp, ipMatching.getMatch(x))) + || forwardedIp && whitelistMode === true && !whitelist.some(x => ipMatching.matches(forwardedIp, ipMatching.getMatch(x))) + ) { + // Log the connection attempt with real IP address + const ipDetails = forwardedIp ? `${clientIp} (forwarded from ${forwardedIp})` : clientIp; + console.log(color.red('Forbidden: Connection attempt from ' + ipDetails + '. If you are attempting to connect, please add your IP address in whitelist or disable whitelist mode in config.yaml in root of SillyTavern folder.\n')); + return res.status(403).send('Forbidden: Connection attempt from ' + ipDetails + '. If you are attempting to connect, please add your IP address in whitelist or disable whitelist mode in config.yaml in root of SillyTavern folder.'); } next(); }; From de8339f77bb3875bd133f2aa01ddb203425448f8 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sat, 13 Apr 2024 15:24:49 +0300 Subject: [PATCH 11/14] Fix ESLint --- public/scripts/popup.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/public/scripts/popup.js b/public/scripts/popup.js index 217991611..4e75431f4 100644 --- a/public/scripts/popup.js +++ b/public/scripts/popup.js @@ -71,7 +71,7 @@ export class Popup { this.ok.textContent = okButton ?? 'OK'; this.cancel.textContent = cancelButton ?? 'Cancel'; - switch(type) { + switch (type) { case POPUP_TYPE.TEXT: { this.input.style.display = 'none'; this.cancel.style.display = 'none'; @@ -107,16 +107,16 @@ export class Popup { // illegal argument } - this.input.addEventListener('keydown', (evt)=>{ + this.input.addEventListener('keydown', (evt) => { if (evt.key != 'Enter' || evt.altKey || evt.ctrlKey || evt.shiftKey) return; evt.preventDefault(); evt.stopPropagation(); this.completeAffirmative(); }); - this.ok.addEventListener('click', ()=>this.completeAffirmative()); - this.cancel.addEventListener('click', ()=>this.completeNegative()); - const keyListener = (evt)=>{ + this.ok.addEventListener('click', () => this.completeAffirmative()); + this.cancel.addEventListener('click', () => this.completeNegative()); + const keyListener = (evt) => { switch (evt.key) { case 'Escape': { evt.preventDefault(); @@ -134,7 +134,7 @@ export class Popup { async show() { document.body.append(this.dom); this.dom.style.display = 'block'; - switch(this.type) { + switch (this.type) { case POPUP_TYPE.INPUT: { this.input.focus(); break; @@ -203,7 +203,7 @@ export class Popup { duration: animation_duration, easing: animation_easing, }); - delay(animation_duration).then(()=>{ + delay(animation_duration).then(() => { this.dom.remove(); }); From 3a4405016cb676b62e02d9c83f65595e82bf432b Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sat, 13 Apr 2024 20:01:17 +0300 Subject: [PATCH 12/14] #2075 Fix Draw Things auth --- src/endpoints/stable-diffusion.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/endpoints/stable-diffusion.js b/src/endpoints/stable-diffusion.js index 3902fa3ce..52d2d2957 100644 --- a/src/endpoints/stable-diffusion.js +++ b/src/endpoints/stable-diffusion.js @@ -685,14 +685,16 @@ drawthings.post('/generate', jsonParser, async (request, response) => { url.pathname = '/sdapi/v1/txt2img'; const body = { ...request.body }; + const auth = getBasicAuthHeader(request.body.auth); delete body.url; + delete body.auth; const result = await fetch(url, { method: 'POST', body: JSON.stringify(body), headers: { 'Content-Type': 'application/json', - 'Authorization': getBasicAuthHeader(request.body.auth), + 'Authorization': auth, }, timeout: 0, }); From 8ae9212cc5778675cada764fb2ce30bc7d912318 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sat, 13 Apr 2024 20:01:17 +0300 Subject: [PATCH 13/14] #2075 Fix Draw Things auth --- src/endpoints/stable-diffusion.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/endpoints/stable-diffusion.js b/src/endpoints/stable-diffusion.js index e2168cd80..cc014f0e6 100644 --- a/src/endpoints/stable-diffusion.js +++ b/src/endpoints/stable-diffusion.js @@ -684,15 +684,17 @@ drawthings.post('/generate', jsonParser, async (request, response) => { const url = new URL(request.body.url); url.pathname = '/sdapi/v1/txt2img'; - const body = {...request.body}; + const body = { ...request.body }; + const auth = getBasicAuthHeader(request.body.auth); delete body.url; + delete body.auth; const result = await fetch(url, { method: 'POST', body: JSON.stringify(body), headers: { 'Content-Type': 'application/json', - 'Authorization': getBasicAuthHeader(request.body.auth), + 'Authorization': auth, }, timeout: 0, }); From ba397dd2a8ca2311a3e49cf8b37620c86dab442a Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sat, 13 Apr 2024 20:09:51 +0300 Subject: [PATCH 14/14] #2062 Extend unlock for MakerSuite models --- public/scripts/openai.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/scripts/openai.js b/public/scripts/openai.js index 7ce8c8c37..0e3a66c73 100644 --- a/public/scripts/openai.js +++ b/public/scripts/openai.js @@ -3566,7 +3566,7 @@ async function onModelChange() { if (oai_settings.chat_completion_source == chat_completion_sources.MAKERSUITE) { if (oai_settings.max_context_unlocked) { - $('#openai_max_context').attr('max', unlocked_max); + $('#openai_max_context').attr('max', max_1mil); } else if (value === 'gemini-1.5-pro-latest') { $('#openai_max_context').attr('max', max_1mil); } else if (value === 'gemini-ultra' || value === 'gemini-1.0-pro-latest' || value === 'gemini-pro' || value === 'gemini-1.0-ultra-latest') {