From cab6f905192d67435d189e923cb209f072ab0534 Mon Sep 17 00:00:00 2001 From: LenAnderson Date: Fri, 9 Feb 2024 22:49:38 +0000 Subject: [PATCH 1/5] stop named args from nested commands bleeding into parent --- public/scripts/slash-commands.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/public/scripts/slash-commands.js b/public/scripts/slash-commands.js index fe8408b06..fe0c15d02 100644 --- a/public/scripts/slash-commands.js +++ b/public/scripts/slash-commands.js @@ -80,14 +80,23 @@ class SlashCommandParser { const excludedFromRegex = ['sendas']; const firstSpace = text.indexOf(' '); const command = firstSpace !== -1 ? text.substring(1, firstSpace) : text.substring(1); - const args = firstSpace !== -1 ? text.substring(firstSpace + 1) : ''; + let args = firstSpace !== -1 ? text.substring(firstSpace + 1) : ''; const argObj = {}; let unnamedArg; if (args.length > 0) { + let match; + + // Match unnamed argument + const unnamedArgPattern = /(?:\w+=(?:"(?:\\.|[^"\\])*"|\S+)\s*)*(.*)/s; + match = unnamedArgPattern.exec(args); + if (match !== null && match[1].length > 0) { + args = args.slice(0, -match[1].length); + unnamedArg = match[1].trim(); + } + // Match named arguments const namedArgPattern = /(\w+)=("(?:\\.|[^"\\])*"|\S+)/g; - let match; while ((match = namedArgPattern.exec(args)) !== null) { const key = match[1]; const value = match[2]; @@ -95,13 +104,6 @@ class SlashCommandParser { argObj[key] = value.replace(/(^")|("$)/g, ''); } - // Match unnamed argument - const unnamedArgPattern = /(?:\w+=(?:"(?:\\.|[^"\\])*"|\S+)\s*)*(.*)/s; - match = unnamedArgPattern.exec(args); - if (match !== null) { - unnamedArg = match[1].trim(); - } - // Excluded commands format in their own function if (!excludedFromRegex.includes(command)) { unnamedArg = getRegexedString( From 187ecc20467a8ce85caaf91707bd25c73899d03d Mon Sep 17 00:00:00 2001 From: berbant <33601955+berbant@users.noreply.github.com> Date: Thu, 15 Feb 2024 16:14:33 +0400 Subject: [PATCH 2/5] Update chat-completions.js This fix will let SillyTavern show up in the Activity List and App Showcase List (app rankings) on openrouter.ai with the right name and the correct link. Right now, all the requests from ST on their end look like 'http://127.0.0.1:'. --- src/endpoints/backends/chat-completions.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/endpoints/backends/chat-completions.js b/src/endpoints/backends/chat-completions.js index 30413aab5..2898400be 100644 --- a/src/endpoints/backends/chat-completions.js +++ b/src/endpoints/backends/chat-completions.js @@ -513,8 +513,11 @@ router.post('/status', jsonParser, async function (request, response_getstatus_o } else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.OPENROUTER) { api_url = 'https://openrouter.ai/api/v1'; api_key_openai = readSecret(SECRET_KEYS.OPENROUTER); - // OpenRouter needs to pass the referer: https://openrouter.ai/docs - headers = { 'HTTP-Referer': request.headers.referer }; + // OpenRouter needs to pass the Referer and X-Title: https://openrouter.ai/docs#requests + headers = { + 'HTTP-Referer': 'https://sillytavern.app', + 'X-Title': 'SillyTavern' + }; } else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.MISTRALAI) { api_url = new URL(request.body.reverse_proxy || API_MISTRAL).toString(); api_key_openai = request.body.reverse_proxy ? request.body.proxy_password : readSecret(SECRET_KEYS.MISTRALAI); @@ -700,8 +703,11 @@ router.post('/generate', jsonParser, function (request, response) { } else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.OPENROUTER) { apiUrl = 'https://openrouter.ai/api/v1'; apiKey = readSecret(SECRET_KEYS.OPENROUTER); - // OpenRouter needs to pass the referer: https://openrouter.ai/docs - headers = { 'HTTP-Referer': request.headers.referer }; + // OpenRouter needs to pass the Referer and X-Title: https://openrouter.ai/docs#requests + headers = { + 'HTTP-Referer': 'https://sillytavern.app', + 'X-Title': 'SillyTavern' + }; bodyParams = { 'transforms': ['middle-out'] }; if (request.body.min_p !== undefined) { From a8cd6c9fe78837aab56dec2ebf8182b4c2daec58 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Fri, 16 Feb 2024 20:24:47 +0200 Subject: [PATCH 3/5] Allow finding characters in slash commands by exact PNG name --- public/scripts/slash-commands.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/public/scripts/slash-commands.js b/public/scripts/slash-commands.js index fe8408b06..a6b3df533 100644 --- a/public/scripts/slash-commands.js +++ b/public/scripts/slash-commands.js @@ -1119,6 +1119,12 @@ function findCharacterIndex(name) { (a, b) => a.includes(b), ]; + const exactAvatarMatch = characters.findIndex(x => x.avatar === name); + + if (exactAvatarMatch !== -1) { + return exactAvatarMatch; + } + for (const matchType of matchTypes) { const index = characters.findIndex(x => matchType(x.name.toLowerCase(), name.toLowerCase())); if (index !== -1) { From c06fe6abfc694ec6cf010c384859cb1ed20938bf Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Fri, 16 Feb 2024 20:42:56 +0200 Subject: [PATCH 4/5] Add character asset type --- public/scripts/extensions/assets/index.js | 46 ++++++++++++++++------ public/scripts/extensions/assets/style.css | 25 ++++++++---- src/endpoints/assets.js | 9 ++++- 3 files changed, 61 insertions(+), 19 deletions(-) diff --git a/public/scripts/extensions/assets/index.js b/public/scripts/extensions/assets/index.js index d15af8687..b07fa7b32 100644 --- a/public/scripts/extensions/assets/index.js +++ b/public/scripts/extensions/assets/index.js @@ -3,8 +3,9 @@ TODO: */ //const DEBUG_TONY_SAMA_FORK_MODE = true -import { getRequestHeaders, callPopup } from '../../../script.js'; -import { deleteExtension, extensionNames, installExtension, renderExtensionTemplate } from '../../extensions.js'; +import { getRequestHeaders, callPopup, processDroppedFiles } from '../../../script.js'; +import { deleteExtension, extensionNames, getContext, installExtension, renderExtensionTemplate } from '../../extensions.js'; +import { executeSlashCommands } from '../../slash-commands.js'; import { getStringHash, isValidUrl } from '../../utils.js'; export { MODULE_NAME }; @@ -61,8 +62,8 @@ function downloadAssetsList(url) { for (const i in availableAssets[assetType]) { const asset = availableAssets[assetType][i]; const elemId = `assets_install_${assetType}_${i}`; - let element = $('