Merge pull request #2494 from SillyTavern/continue-command-await-arg Added /continue "await" arg

8a154e7abf5a5ddc21973015ebd531eb7bc9e925

Cohee <18619528+Cohee1207@users.noreply.github.com>

Signed
1 files changed, +38 -9Ignore whitespace
public/scripts/slash-commands.js+38 -9
@@ -329,6 +329,16 @@ export function initDefaultSlashCommands() {
329329 name: 'continue',
330330 callback: continueChatCallback,
331331 aliases: ['cont'],
332+ namedArgumentList: [
333+ new SlashCommandNamedArgument(
334+ 'await',
335+ 'Whether to await for the continued generation before proceeding',
336+ [ARGUMENT_TYPE.BOOLEAN],
337+ false,
338+ false,
339+ 'false',
340+ ),
341+ ],
332342 unnamedArgumentList: [
333343 new SlashCommandArgument(
334344 'prompt', [ARGUMENT_TYPE.STRING], false,
@@ -339,15 +349,18 @@ export function initDefaultSlashCommands() {
339349 Continues the last message in the chat, with an optional additional prompt.
340350 </div>
341351 <div>
352+ If <code>await=true</code> named argument is passed, the command will await for the continued generation before proceeding.
353+ </div>
354+ <div>
342355 <strong>Example:</strong>
343356 <ul>
344357 <li>
345358 <pre><code>/continue</code></pre>
346359 Continues the chat with no additional prompt and immediately proceeds to the next command.
347360 </li>
348361 <li>
349362 <pre><code>/continue await=true Let's explore this further...</code></pre>
350363 Continues the chat with the provided prompt and waits for the generation to finish.
351364 </li>
352365 </ul>
353366 </div>
@@ -2623,19 +2636,35 @@ async function openChat(id) {
26232636 await reloadCurrentChat();
26242637}
26252638
26262639async function continueChatCallback(_args, prompt) {
2627- setTimeout(async () => {
2640+ const shouldAwait = isTrueBoolean(args?.await);
2641+
2642+ const outerPromise = new Promise(async (resolve, reject) => {
26282643 try {
26292644 await waitUntilCondition(() => !is_send_press && !is_group_generating, 10000, 100);
26302645 } catch {
26312646 console.warn('Timeout waiting for generation unlock');
26322647 toastr.warning('Cannot run /continue command while the reply is being generated.');
2648+ return reject();
26332649 }
26342650
2635- // Prevent infinite recursion
2651+ try {
2636- $('#send_textarea').val('')[0].dispatchEvent(new Event('input', { bubbles: true }));
2652+ // Prevent infinite recursion
26372653 $('#option_continuesend_textarea').triggerval('click')[0].dispatchEvent(new Event('input', { fromSlashCommandbubbles: true, additionalPrompt: prompt }));
2638- }, 1);
2654+
2655+ const options = prompt?.trim() ? { quiet_prompt: prompt.trim(), quietToLoud: true } : {};
2656+ await Generate('continue', options);
2657+
2658+ resolve();
2659+ } catch (error) {
2660+ console.error('Error running /continue command:', error);
2661+ reject();
2662+ }
2663+ });
2664+
2665+ if (shouldAwait) {
2666+ await outerPromise;
2667+ }
26392668
26402669 return '';
26412670}