Allow running generate interceptors on quiet prompts
| @@ -3764,9 +3764,9 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro | |||
| 3764 | // Determine token limit | 3764 | // Determine token limit |
| 3765 | let this_max_context = getMaxContextSize(); | 3765 | let this_max_context = getMaxContextSize(); |
| 3766 | 3766 | ||
| 3767 | if (!dryRun && type !== 'quiet') { | 3767 | if (!dryRun) { |
| 3768 | console.debug('Running extension interceptors'); | 3768 | console.debug('Running extension interceptors'); |
| 3769 | const aborted = await runGenerationInterceptors(coreChat, this_max_context); | 3769 | const aborted = await runGenerationInterceptors(coreChat, this_max_context, type); |
| 3770 | 3770 | ||
| 3771 | if (aborted) { | 3771 | if (aborted) { |
| 3772 | console.debug('Generation aborted by extension interceptors'); | 3772 | console.debug('Generation aborted by extension interceptors'); |
| @@ -1209,9 +1209,10 @@ async function autoUpdateExtensions(forceAll) { | |||
| 1209 | * Runs the generate interceptors for all extensions. | 1209 | * Runs the generate interceptors for all extensions. |
| 1210 | * @param {any[]} chat Chat array | 1210 | * @param {any[]} chat Chat array |
| 1211 | * @param {number} contextSize Context size | 1211 | * @param {number} contextSize Context size |
| 1212 | * @param {string} type Generation type | ||
| 1212 | * @returns {Promise<boolean>} True if generation should be aborted | 1213 | * @returns {Promise<boolean>} True if generation should be aborted |
| 1213 | */ | 1214 | */ |
| 1214 | export async function runGenerationInterceptors(chat, contextSize) { | 1215 | export async function runGenerationInterceptors(chat, contextSize, type) { |
| 1215 | let aborted = false; | 1216 | let aborted = false; |
| 1216 | let exitImmediately = false; | 1217 | let exitImmediately = false; |
| 1217 | 1218 | ||
| @@ -1224,7 +1225,7 @@ export async function runGenerationInterceptors(chat, contextSize) { | |||
| 1224 | const interceptorKey = manifest.generate_interceptor; | 1225 | const interceptorKey = manifest.generate_interceptor; |
| 1225 | if (typeof globalThis[interceptorKey] === 'function') { | 1226 | if (typeof globalThis[interceptorKey] === 'function') { |
| 1226 | try { | 1227 | try { |
| 1227 | await globalThis[interceptorKey](chat, contextSize, abort); | 1228 | await globalThis[interceptorKey](chat, contextSize, abort, type); |
| 1228 | } catch (e) { | 1229 | } catch (e) { |
| 1229 | console.error(`Failed running interceptor for ${manifest.display_name}`, e); | 1230 | console.error(`Failed running interceptor for ${manifest.display_name}`, e); |
| 1230 | } | 1231 | } |
| @@ -330,7 +330,18 @@ const defaultSettings = { | |||
| 330 | 330 | ||
| 331 | const writePromptFieldsDebounced = debounce(writePromptFields, debounce_timeout.relaxed); | 331 | const writePromptFieldsDebounced = debounce(writePromptFields, debounce_timeout.relaxed); |
| 332 | 332 | ||
| 333 | function processTriggers(chat, _, abort) { | 333 | /** |
| 334 | * Generate interceptor for interactive mode triggers. | ||
| 335 | * @param {any[]} chat Chat messages | ||
| 336 | * @param {number} _ Context size (unused) | ||
| 337 | * @param {function(boolean): void} abort Abort generation function | ||
| 338 | * @param {string} type Type of the generation | ||
| 339 | */ | ||
| 340 | function processTriggers(chat, _, abort, type) { | ||
| 341 | if (type === 'quiet') { | ||
| 342 | return; | ||
| 343 | } | ||
| 344 | |||
| 334 | if (extension_settings.sd.function_tool && ToolManager.isToolCallingSupported()) { | 345 | if (extension_settings.sd.function_tool && ToolManager.isToolCallingSupported()) { |
| 335 | return; | 346 | return; |
| 336 | } | 347 | } |
| @@ -594,8 +594,11 @@ async function vectorizeFile(fileText, fileName, collectionId, chunkSize, overla | |||
| 594 | /** | 594 | /** |
| 595 | * Removes the most relevant messages from the chat and displays them in the extension prompt | 595 | * Removes the most relevant messages from the chat and displays them in the extension prompt |
| 596 | * @param {object[]} chat Array of chat messages | 596 | * @param {object[]} chat Array of chat messages |
| 597 | * @param {number} _contextSize Context size (unused) | ||
| 598 | * @param {function} _abort Abort function (unused) | ||
| 599 | * @param {string} type Generation type | ||
| 597 | */ | 600 | */ |
| 598 | async function rearrangeChat(chat) { | 601 | async function rearrangeChat(chat, _contextSize, _abort, type) { |
| 599 | try { | 602 | try { |
| 600 | // Clear the extension prompt | 603 | // Clear the extension prompt |
| 601 | setExtensionPrompt(EXTENSION_PROMPT_TAG, '', settings.position, settings.depth, settings.include_wi); | 604 | setExtensionPrompt(EXTENSION_PROMPT_TAG, '', settings.position, settings.depth, settings.include_wi); |
| @@ -609,7 +612,7 @@ async function rearrangeChat(chat) { | |||
| 609 | await activateWorldInfo(chat); | 612 | await activateWorldInfo(chat); |
| 610 | } | 613 | } |
| 611 | 614 | ||
| 612 | if (!settings.enabled_chats) { | 615 | if (!settings.enabled_chats || type === 'quiet') { |
| 613 | return; | 616 | return; |
| 614 | } | 617 | } |
| 615 | 618 | ||