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() {
329 name: 'continue',329 name: 'continue',
330 callback: continueChatCallback,330 callback: continueChatCallback,
331 aliases: ['cont'],331 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 ],
332 unnamedArgumentList: [342 unnamedArgumentList: [
333 new SlashCommandArgument(343 new SlashCommandArgument(
334 'prompt', [ARGUMENT_TYPE.STRING], false,344 'prompt', [ARGUMENT_TYPE.STRING], false,
@@ -339,15 +349,18 @@ export function initDefaultSlashCommands() {
339 Continues the last message in the chat, with an optional additional prompt.349 Continues the last message in the chat, with an optional additional prompt.
340 </div>350 </div>
341 <div>351 <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>
342 <strong>Example:</strong>355 <strong>Example:</strong>
343 <ul>356 <ul>
344 <li>357 <li>
345 <pre><code>/continue</code></pre>358 <pre><code>/continue</code></pre>
346 Continues the chat with no additional prompt.359 Continues the chat with no additional prompt and immediately proceeds to the next command.
347 </li>360 </li>
348 <li>361 <li>
349 <pre><code>/continue Let's explore this further...</code></pre>362 <pre><code>/continue await=true Let's explore this further...</code></pre>
350 Continues the chat with the provided prompt.363 Continues the chat with the provided prompt and waits for the generation to finish.
351 </li>364 </li>
352 </ul>365 </ul>
353 </div>366 </div>
@@ -2623,19 +2636,35 @@ async function openChat(id) {
2623 await reloadCurrentChat();2636 await reloadCurrentChat();
2624}2637}
26252638
2626function continueChatCallback(_, prompt) {2639async function continueChatCallback(args, prompt) {
2627 setTimeout(async () => {2640 const shouldAwait = isTrueBoolean(args?.await);
2641
2642 const outerPromise = new Promise(async (resolve, reject) => {
2628 try {2643 try {
2629 await waitUntilCondition(() => !is_send_press && !is_group_generating, 10000, 100);2644 await waitUntilCondition(() => !is_send_press && !is_group_generating, 10000, 100);
2630 } catch {2645 } catch {
2631 console.warn('Timeout waiting for generation unlock');2646 console.warn('Timeout waiting for generation unlock');
2632 toastr.warning('Cannot run /continue command while the reply is being generated.');2647 toastr.warning('Cannot run /continue command while the reply is being generated.');
2648 return reject();
2633 }2649 }
26342650
2635 // Prevent infinite recursion2651 try {
2636 $('#send_textarea').val('')[0].dispatchEvent(new Event('input', { bubbles: true }));2652 // Prevent infinite recursion
2637 $('#option_continue').trigger('click', { fromSlashCommand: true, additionalPrompt: prompt });2653 $('#send_textarea').val('')[0].dispatchEvent(new Event('input', { bubbles: true }));
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
2640 return '';2669 return '';
2641}2670}