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