Added /continue "await" arg

aad65c9273176a2bf3960bf655a23db1adf4ae7e

Wolfsblvt <wolfsblvt@gmail.com>

1 files changed, +37 -12Ignore whitespace
public/scripts/slash-commands.js+37 -12
@@ -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 continuing',
336+ [ARGUMENT_TYPE.BOOLEAN],
337+ false,
338+ false,
339+ 'false',
340+ ),
341+ ],
332342 unnamedArgumentList: [
333343 new SlashCommandArgument(
334344 'prompt', [ARGUMENT_TYPE.STRING], false,
@@ -339,6 +349,9 @@ 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 continuing.
353+ </div>
354+ <div>
342355 <strong>Example:</strong>
343356 <ul>
344357 <li>
@@ -2623,19 +2636,31 @@ async function openChat(id) {
26232636 await reloadCurrentChat();
26242637}
26252638
26262639async function continueChatCallback(_args, prompt) {
2627- setTimeout(async () => {
2640+ const shouldAwait = isTrueBoolean(args?.await);
2628- try {
2629- await waitUntilCondition(() => !is_send_press && !is_group_generating, 10000, 100);
2630- } catch {
2631- console.warn('Timeout waiting for generation unlock');
2632- toastr.warning('Cannot run /continue command while the reply is being generated.');
2633- }
26342641
2635- // Prevent infinite recursion
2642+ const outerPromise = new Promise((resolve) => {
2636- $('#send_textarea').val('')[0].dispatchEvent(new Event('input', { bubbles: true }));
2643+ setTimeout(async () => {
2637- $('#option_continue').trigger('click', { fromSlashCommand: true, additionalPrompt: prompt });
2644+ try {
2638- }, 1);
2645+ await waitUntilCondition(() => !is_send_press && !is_group_generating, 10000, 100);
2646+ } catch {
2647+ console.warn('Timeout waiting for generation unlock');
2648+ toastr.warning('Cannot run /continue command while the reply is being generated.');
2649+ }
2650+
2651+ // Prevent infinite recursion
2652+ $('#send_textarea').val('')[0].dispatchEvent(new Event('input', { bubbles: true }));
2653+
2654+ const options = prompt?.trim() ? { quiet_prompt: prompt.trim(), quietToLoud: true } : {};
2655+ await Generate('continue', options);
2656+
2657+ resolve();
2658+ }, 1);
2659+ });
2660+
2661+ if (shouldAwait) {
2662+ await outerPromise;
2663+ }
26392664
26402665 return '';
26412666}