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>
This commit is contained in:
Pavdig
2026-03-11 21:57:53 +01:00
committed by GitHub
parent e0ed67357c
commit 8879272a6b
+11 -2
View File
@@ -1107,16 +1107,25 @@ jQuery(async function () {
returns: ARGUMENT_TYPE.STRING,
}));
const summaryMacroHandler = () => {
// Checking content of the UI summary box first
const uiSummary = $('#memory_contents').val().toString();
if (uiSummary.trim().length > 0) {
return uiSummary;
}
// Fallback to scanning the chat for the latest summary if the UI summary box is empty
return getLatestMemoryFromChat(getContext().chat);
};
if (power_user.experimental_macro_engine) {
macros.register('summary', {
category: MacroCategory.CHAT,
description: 'Returns the latest memory/summary from the current chat.',
handler: () => getLatestMemoryFromChat(getContext().chat),
handler: () => summaryMacroHandler(),
});
} else {
// TODO: Remove this when the experimental macro engine is replacing the old macro engine
MacrosParser.registerMacro('summary',
() => getLatestMemoryFromChat(getContext().chat),
() => summaryMacroHandler(),
'Returns the latest memory/summary from the current chat.');
}
});