mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-04-19 05:07:26 +02:00
First steps in slash command piping
This commit is contained in:
parent
1b4d955aec
commit
4b78ddbc8a
@ -84,7 +84,7 @@ class SlashCommandParser {
|
|||||||
const key = match[1];
|
const key = match[1];
|
||||||
const value = match[2];
|
const value = match[2];
|
||||||
// Remove the quotes around the value, if any
|
// Remove the quotes around the value, if any
|
||||||
argObj[key] = value.replace(/(^")|("$)/g, '');
|
argObj[key] = substituteParams(value.replace(/(^")|("$)/g, ''));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Match unnamed argument
|
// Match unnamed argument
|
||||||
@ -157,11 +157,36 @@ parser.addCommand('memberup', moveGroupMemberUpCallback, ['upmember'], '<span cl
|
|||||||
parser.addCommand('memberdown', moveGroupMemberDownCallback, ['downmember'], '<span class="monospace">(member index or name)</span> – moves a group member down in the group chat list', true, true);
|
parser.addCommand('memberdown', moveGroupMemberDownCallback, ['downmember'], '<span class="monospace">(member index or name)</span> – moves a group member down in the group chat list', true, true);
|
||||||
parser.addCommand('peek', peekCallback, [], '<span class="monospace">(message index or range)</span> – shows a group member character card without switching chats', true, true);
|
parser.addCommand('peek', peekCallback, [], '<span class="monospace">(message index or range)</span> – shows a group member character card without switching chats', true, true);
|
||||||
parser.addCommand('delswipe', deleteSwipeCallback, [], '<span class="monospace">(optional 1-based id)</span> – deletes a swipe from the last chat message. If swipe id not provided - deletes the current swipe.', true, true);
|
parser.addCommand('delswipe', deleteSwipeCallback, [], '<span class="monospace">(optional 1-based id)</span> – deletes a swipe from the last chat message. If swipe id not provided - deletes the current swipe.', true, true);
|
||||||
|
parser.addCommand('echo', echoCallback, [], '<span class="monospace">(text)</span> – echoes the text to toast message. Useful for pipes debugging.', true, true);
|
||||||
|
parser.addCommand('gen', generateCallback, [], '<span class="monospace">(prompt)</span> – generates text using the provided prompt and passes it to the next command through the pipe.', true, true);
|
||||||
|
|
||||||
const NARRATOR_NAME_KEY = 'narrator_name';
|
const NARRATOR_NAME_KEY = 'narrator_name';
|
||||||
const NARRATOR_NAME_DEFAULT = 'System';
|
const NARRATOR_NAME_DEFAULT = 'System';
|
||||||
export const COMMENT_NAME_DEFAULT = 'Note';
|
export const COMMENT_NAME_DEFAULT = 'Note';
|
||||||
|
|
||||||
|
async function generateCallback(_, arg) {
|
||||||
|
if (!arg) {
|
||||||
|
console.warn('WARN: No argument provided for /gen command');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prevent generate recursion
|
||||||
|
$('#send_textarea').val('');
|
||||||
|
|
||||||
|
const result = await generateQuietPrompt(arg, false, false, '');
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function echoCallback(_, arg) {
|
||||||
|
if (!arg) {
|
||||||
|
console.warn('WARN: No argument provided for /echo command');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
toastr.info(arg);
|
||||||
|
return arg;
|
||||||
|
}
|
||||||
|
|
||||||
async function deleteSwipeCallback(_, arg) {
|
async function deleteSwipeCallback(_, arg) {
|
||||||
const lastMessage = chat[chat.length - 1];
|
const lastMessage = chat[chat.length - 1];
|
||||||
|
|
||||||
@ -895,6 +920,7 @@ async function executeSlashCommands(text) {
|
|||||||
const linesToRemove = [];
|
const linesToRemove = [];
|
||||||
|
|
||||||
let interrupt = false;
|
let interrupt = false;
|
||||||
|
let pipeResult = '';
|
||||||
|
|
||||||
for (let index = 0; index < lines.length; index++) {
|
for (let index = 0; index < lines.length; index++) {
|
||||||
const trimmedLine = lines[index].trim();
|
const trimmedLine = lines[index].trim();
|
||||||
@ -914,7 +940,8 @@ async function executeSlashCommands(text) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
console.debug('Slash command executing:', result);
|
console.debug('Slash command executing:', result);
|
||||||
await result.command.callback(result.args, result.value);
|
const unnamedArg = pipeResult || result.value;
|
||||||
|
pipeResult = await result.command.callback(result.args, unnamedArg);
|
||||||
|
|
||||||
if (result.command.interruptsGeneration) {
|
if (result.command.interruptsGeneration) {
|
||||||
interrupt = true;
|
interrupt = true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user