fix: prioritize UI memory content for {{summary}} macro resolution (#5268) * fix(extensions/Summarize): prioritize UI memory content for {{summary}} macro The {{summary}} macro previously relied solely on history-based metadata, causing it to return empty when starting a new chat if 'None (not injected)' was selected as the injection position. This change prioritizes the #memory_contents UI value to ensure the macro resolves immediately, even before the first history-based summary is generated. * Implement for legacy macro * Restore original trim call --------- Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>

8879272a6bdc453c6969b15a69e1a3361cf8b434

Pavdig <101715456+Pavdig@users.noreply.github.com>

Signed
1 files changed, +11 -2Showing whitespace changes
public/scripts/extensions/memory/index.js+11 -2
@@ -1107,16 +1107,25 @@ jQuery(async function () {
11071107 returns: ARGUMENT_TYPE.STRING,
11081108 }));
11091109
1110+ const summaryMacroHandler = () => {
1111+ // Checking content of the UI summary box first
1112+ const uiSummary = $('#memory_contents').val().toString();
1113+ if (uiSummary.trim().length > 0) {
1114+ return uiSummary;
1115+ }
1116+ // Fallback to scanning the chat for the latest summary if the UI summary box is empty
1117+ return getLatestMemoryFromChat(getContext().chat);
1118+ };
11101119 if (power_user.experimental_macro_engine) {
11111120 macros.register('summary', {
11121121 category: MacroCategory.CHAT,
11131122 description: 'Returns the latest memory/summary from the current chat.',
11141123 handler: () => getLatestMemoryFromChat(getContextsummaryMacroHandler().chat),
11151124 });
11161125 } else {
11171126 // TODO: Remove this when the experimental macro engine is replacing the old macro engine
11181127 MacrosParser.registerMacro('summary',
11191128 () => getLatestMemoryFromChat(getContextsummaryMacroHandler().chat),
11201129 'Returns the latest memory/summary from the current chat.');
11211130 }
11221131});