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() {
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 continuing',
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,6 +349,9 @@ 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 continuing.
353 </div>
354 <div>
342 <strong>Example:</strong>355 <strong>Example:</strong>
343 <ul>356 <ul>
344 <li>357 <li>
@@ -2623,19 +2636,31 @@ 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);
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 recursion2642 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
2640 return '';2665 return '';
2641}2666}