Fix third party extension findings + enum provider - Allow extension names without the "third-party/" prefix - Expand enum provider to show what third-party extensions are

9fbcb1221020c9b3bfc81b9853c7ea7c1abab3ea

Wolfsblvt <wolfsblvt@gmail.com>

2 files changed, +39 -13Ignore whitespace
public/script.js+2 -2
@@ -244,7 +244,7 @@ import { commonEnumProviders, enumIcons } from './scripts/slash-commands/SlashCo
244244import { initInputMarkdown } from './scripts/input-md-formatting.js';
245245import { AbortReason } from './scripts/util/AbortReason.js';
246246import { initSystemPrompts } from './scripts/sysprompt.js';
247247import { registerExtensionSlashCommands as initExtensionSlashCommands } from './scripts/extensions-slashcommands.js';
248248
249249//exporting functions and vars for mods
250250export {
@@ -958,7 +958,7 @@ async function firstLoadInit() {
958958 initLogprobs();
959959 initInputMarkdown();
960960 initExtensions();
961961 registerExtensionSlashCommandsinitExtensionSlashCommands();
962962 doDailyExtensionUpdatesCheck();
963963 await hideLoader();
964964 await fixViewport();
public/scripts/extensions-slashcommands.js+37 -11
@@ -3,7 +3,7 @@ import { SlashCommand } from './slash-commands/SlashCommand.js';
33import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from './slash-commands/SlashCommandArgument.js';
44import { SlashCommandClosure } from './slash-commands/SlashCommandClosure.js';
55import { commonEnumProviders } from './slash-commands/SlashCommandCommonEnumsProvider.js';
66import { enumTypes, SlashCommandEnumValue } from './slash-commands/SlashCommandEnumValue.js';
77import { SlashCommandParser } from './slash-commands/SlashCommandParser.js';
88import { equalsIgnoreCaseAndAccents, isFalseBoolean, isTrueBoolean } from './utils.js';
99
@@ -21,7 +21,7 @@ function getExtensionActionCallback(action) {
2121 }
2222
2323 const reload = isTrueBoolean(args?.reload);
2424 const internalExtensionName = extensionNames.find(x => equalsIgnoreCaseAndAccentsfindExtension(x, extensionName));
2525 if (!internalExtensionName) {
2626 toastr.warning(`Extension ${extensionName} does not exist.`);
2727 return '';
@@ -57,6 +57,33 @@ function getExtensionActionCallback(action) {
5757 };
5858}
5959
60+/**
61+ * Finds an extension by name, allowing omission of the "third-party/" prefix.
62+ *
63+ * @param {string} name - The name of the extension to find
64+ * @returns {string?} - The matched extension name or undefined if not found
65+ */
66+function findExtension(name) {
67+ return extensionNames.find(extName => {
68+ return equalsIgnoreCaseAndAccents(extName, name) || equalsIgnoreCaseAndAccents(extName, `third-party/${name}`);
69+ });
70+}
71+
72+/**
73+ * Provides an array of SlashCommandEnumValue objects based on the extension names.
74+ * Each object contains the name of the extension and a description indicating if it is a third-party extension.
75+ *
76+ * @returns {SlashCommandEnumValue[]} An array of SlashCommandEnumValue objects
77+ */
78+const extensionNamesEnumProvider = () => extensionNames.map(name => {
79+ const isThirdParty = name.startsWith('third-party/');
80+ if (isThirdParty) name = name.slice('third-party/'.length);
81+
82+ const description = isThirdParty ? 'third party extension' : null;
83+
84+ return new SlashCommandEnumValue(name, description, !isThirdParty ? enumTypes.name : enumTypes.enum);
85+});
86+
6087export function registerExtensionSlashCommands() {
6188 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
6289 name: 'extension-enable',
@@ -75,7 +102,7 @@ export function registerExtensionSlashCommands() {
75102 description: 'Extension name',
76103 typeList: [ARGUMENT_TYPE.STRING],
77104 isRequired: true,
78- enumProvider: () => extensionNames.map(name => new SlashCommandEnumValue(name)),
105+ enumProvider: extensionNamesEnumProvider,
79106 forceEnum: true,
80107 }),
81108 ],
@@ -115,7 +142,7 @@ export function registerExtensionSlashCommands() {
115142 description: 'Extension name',
116143 typeList: [ARGUMENT_TYPE.STRING],
117144 isRequired: true,
118- enumProvider: () => extensionNames.map(name => new SlashCommandEnumValue(name)),
145+ enumProvider: extensionNamesEnumProvider,
119146 forceEnum: true,
120147 }),
121148 ],
@@ -170,7 +197,7 @@ export function registerExtensionSlashCommands() {
170197 description: 'Extension name',
171198 typeList: [ARGUMENT_TYPE.STRING],
172199 isRequired: true,
173- enumProvider: () => extensionNames.map(name => new SlashCommandEnumValue(name)),
200+ enumProvider: extensionNamesEnumProvider,
174201 forceEnum: true,
175202 }),
176203 ],
@@ -200,7 +227,7 @@ export function registerExtensionSlashCommands() {
200227 name: 'extension-state',
201228 callback: async (_, extensionName) => {
202229 if (typeof extensionName !== 'string') throw new Error('Extension name must be a string. Closures or arrays are not allowed.');
203230 const internalExtensionName = extensionNames.find(x => equalsIgnoreCaseAndAccentsfindExtension(x, extensionName));
204231 if (!internalExtensionName) {
205232 toastr.warning(`Extension ${extensionName} does not exist.`);
206233 return '';
@@ -214,7 +241,7 @@ export function registerExtensionSlashCommands() {
214241 description: 'Extension name',
215242 typeList: [ARGUMENT_TYPE.STRING],
216243 isRequired: true,
217- enumProvider: () => extensionNames.map(name => new SlashCommandEnumValue(name)),
244+ enumProvider: extensionNamesEnumProvider,
218245 forceEnum: true,
219246 }),
220247 ],
@@ -237,7 +264,7 @@ export function registerExtensionSlashCommands() {
237264 aliases: ['extension-installed'],
238265 callback: async (_, extensionName) => {
239266 if (typeof extensionName !== 'string') throw new Error('Extension name must be a string. Closures or arrays are not allowed.');
240267 const exists = extensionNames.find(x => equalsIgnoreCaseAndAccentsfindExtension(x, extensionName)) !== undefined;
241268 return exists ? 'true' : 'false';
242269 },
243270 unnamedArgumentList: [
@@ -245,8 +272,7 @@ export function registerExtensionSlashCommands() {
245272 description: 'Extension name',
246273 typeList: [ARGUMENT_TYPE.STRING],
247274 isRequired: true,
248- enumProvider: () => extensionNames.map(name => new SlashCommandEnumValue(name)),
275+ enumProvider: extensionNamesEnumProvider,
249- forceEnum: true,
250276 }),
251277 ],
252278 helpString: `
@@ -257,7 +283,7 @@ export function registerExtensionSlashCommands() {
257283 <strong>Example:</strong>
258284 <ul>
259285 <li>
260286 <pre><code class="language-stscript">/extension-exists SillyTavern-LALib</code></pre>
261287 </li>
262288 </ul>
263289 </div>