| 1107 | returns: ARGUMENT_TYPE.STRING, | 1107 | returns: ARGUMENT_TYPE.STRING, |
| 1108 | })); | 1108 | })); |
| 1109 | | 1109 | |
| | 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 | }; |
| 1110 | if (power_user.experimental_macro_engine) { | 1119 | if (power_user.experimental_macro_engine) { |
| 1111 | macros.register('summary', { | 1120 | macros.register('summary', { |
| 1112 | category: MacroCategory.CHAT, | 1121 | category: MacroCategory.CHAT, |
| 1113 | description: 'Returns the latest memory/summary from the current chat.', | 1122 | description: 'Returns the latest memory/summary from the current chat.', |
| 1114 | handler: () => getLatestMemoryFromChat(getContext().chat), | 1123 | handler: () => summaryMacroHandler(), |
| 1115 | }); | 1124 | }); |
| 1116 | } else { | 1125 | } else { |
| 1117 | // TODO: Remove this when the experimental macro engine is replacing the old macro engine | 1126 | // TODO: Remove this when the experimental macro engine is replacing the old macro engine |
| 1118 | MacrosParser.registerMacro('summary', | 1127 | MacrosParser.registerMacro('summary', |
| 1119 | () => getLatestMemoryFromChat(getContext().chat), | 1128 | () => summaryMacroHandler(), |
| 1120 | 'Returns the latest memory/summary from the current chat.'); | 1129 | 'Returns the latest memory/summary from the current chat.'); |
| 1121 | } | 1130 | } |
| 1122 | }); | 1131 | }); |