| 2363 | helpString: 'Copies the provided text to the OS clipboard. Returns an empty string.', | 2364 | helpString: 'Copies the provided text to the OS clipboard. Returns an empty string.', |
| 2364 | })); | 2365 | })); |
| 2365 | | 2366 | |
| | 2367 | |
| | 2368 | const promptPostProcessingEnumProvider = () => Array |
| | 2369 | .from(document.getElementById('custom_prompt_post_processing').querySelectorAll('option')) |
| | 2370 | .map(option => new SlashCommandEnumValue(option.value || 'none', option.textContent, enumTypes.enum)); |
| | 2371 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ |
| | 2372 | name: 'prompt-post-processing', |
| | 2373 | aliases: ['ppp'], |
| | 2374 | helpString: ` |
| | 2375 | <div> |
| | 2376 | Sets a "Prompt Post-Processing" type. Gets the current selection if no value is provided. |
| | 2377 | </div> |
| | 2378 | <div> |
| | 2379 | <strong>Examples:</strong> |
| | 2380 | </div> |
| | 2381 | <ul> |
| | 2382 | <li><pre><code class="language-stscript">/prompt-post-processing | /echo</code></pre></li> |
| | 2383 | <li><pre><code class="language-stscript">/prompt-post-processing single</code></pre></li> |
| | 2384 | </ul> |
| | 2385 | `, |
| | 2386 | namedArgumentList: [], |
| | 2387 | unnamedArgumentList: [ |
| | 2388 | SlashCommandArgument.fromProps({ |
| | 2389 | description: 'value', |
| | 2390 | typeList: [ARGUMENT_TYPE.STRING], |
| | 2391 | acceptsMultiple: false, |
| | 2392 | isRequired: true, |
| | 2393 | forceEnum: true, |
| | 2394 | enumProvider: promptPostProcessingEnumProvider, |
| | 2395 | }), |
| | 2396 | ], |
| | 2397 | callback: (_args, value) => { |
| | 2398 | const stringValue = String(value ?? '').trim().toLowerCase(); |
| | 2399 | if (!stringValue) { |
| | 2400 | return oai_settings.custom_prompt_post_processing || 'none'; |
| | 2401 | } |
| | 2402 | |
| | 2403 | const validValues = promptPostProcessingEnumProvider().map(option => option.value); |
| | 2404 | if (!validValues.includes(stringValue)) { |
| | 2405 | throw new Error(`Invalid value "${stringValue}". Valid values are: ${validValues.join(', ')}`); |
| | 2406 | } |
| | 2407 | |
| | 2408 | // 'none' value must be coerced to an empty string |
| | 2409 | oai_settings.custom_prompt_post_processing = stringValue === 'none' ? '' : stringValue; |
| | 2410 | $('#custom_prompt_post_processing').val(oai_settings.custom_prompt_post_processing); |
| | 2411 | saveSettingsDebounced(); |
| | 2412 | |
| | 2413 | return oai_settings.custom_prompt_post_processing; |
| | 2414 | }, |
| | 2415 | })); |
| | 2416 | |
| 2366 | registerVariableCommands(); | 2417 | registerVariableCommands(); |
| 2367 | } | 2418 | } |
| 2368 | | 2419 | |