| 101 | 106 | }); |
| 102 | 107 | } |
| 103 | 108 | |
| 109 | +function registerReasoningSlashCommands() { |
| 110 | + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ |
| 111 | + name: 'reasoning-get', |
| 112 | + returns: ARGUMENT_TYPE.STRING, |
| 113 | + helpString: t`Get the contents of a reasoning block of a message. Returns an empty string if the message does not have a reasoning block.`, |
| 114 | + unnamedArgumentList: [ |
| 115 | + SlashCommandArgument.fromProps({ |
| 116 | + description: 'Message ID. If not provided, the message ID of the last message is used.', |
| 117 | + typeList: ARGUMENT_TYPE.NUMBER, |
| 118 | + enumProvider: commonEnumProviders.messages(), |
| 119 | + }), |
| 120 | + ], |
| 121 | + callback: (_args, value) => { |
| 122 | + const messageId = !isNaN(Number(value)) ? Number(value) : chat.length - 1; |
| 123 | + const message = chat[messageId]; |
| 124 | + const reasoning = message?.extra?.reasoning; |
| 125 | + return reasoning !== PromptReasoning.REASONING_PLACEHOLDER ? reasoning : ''; |
| 126 | + }, |
| 127 | + })); |
| 128 | + |
| 129 | + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ |
| 130 | + name: 'reasoning-set', |
| 131 | + returns: ARGUMENT_TYPE.STRING, |
| 132 | + helpString: t`Set the reasoning block of a message. Returns the reasoning block content.`, |
| 133 | + namedArgumentList: [ |
| 134 | + SlashCommandNamedArgument.fromProps({ |
| 135 | + name: 'at', |
| 136 | + description: 'Message ID. If not provided, the message ID of the last message is used.', |
| 137 | + typeList: ARGUMENT_TYPE.NUMBER, |
| 138 | + enumProvider: commonEnumProviders.messages(), |
| 139 | + }), |
| 140 | + ], |
| 141 | + unnamedArgumentList: [ |
| 142 | + SlashCommandArgument.fromProps({ |
| 143 | + description: 'Reasoning block content.', |
| 144 | + typeList: ARGUMENT_TYPE.STRING, |
| 145 | + }), |
| 146 | + ], |
| 147 | + callback: async (args, value) => { |
| 148 | + const messageId = !isNaN(Number(args[0])) ? Number(args[0]) : chat.length - 1; |
| 149 | + const message = chat[messageId]; |
| 150 | + if (!message?.extra) { |
| 151 | + return ''; |
| 152 | + } |
| 153 | + |
| 154 | + message.extra.reasoning = String(value); |
| 155 | + await saveChatConditional(); |
| 156 | + |
| 157 | + closeMessageEditor('reasoning'); |
| 158 | + updateMessageBlock(messageId, message); |
| 159 | + return message.extra.reasoning; |
| 160 | + }, |
| 161 | + })); |
| 162 | +} |
| 163 | + |
| 164 | +function registerReasoningMacros() { |
| 165 | + MacrosParser.registerMacro('reasoningPrefix', () => power_user.reasoning.prefix, t`Reasoning Prefix`); |
| 166 | + MacrosParser.registerMacro('reasoningSuffix', () => power_user.reasoning.suffix, t`Reasoning Suffix`); |
| 167 | + MacrosParser.registerMacro('reasoningSeparator', () => power_user.reasoning.separator, t`Reasoning Separator`); |
| 168 | +} |
| 169 | + |
| 104 | 170 | function setReasoningEventHandlers(){ |
| 105 | 171 | $(document).on('click', '.mes_reasoning_copy', (e) => { |
| 106 | 172 | e.stopPropagation(); |