Refactor main slassh-commands into init func

cba2b54531293167424a7f4f17f3ba979cbe9a0a

Wolfsblvt <wolfsblvt@gmx.de>

2 files changed, +969 -967Ignore whitespace
public/script.js+2 -1
@@ -159,7 +159,7 @@ import {
159159import { debounce_timeout } from './scripts/constants.js';
160160
161161import { ModuleWorkerWrapper, doDailyExtensionUpdatesCheck, extension_settings, getContext, loadExtensionSettings, renderExtensionTemplate, renderExtensionTemplateAsync, runGenerationInterceptors, saveMetadataDebounced, writeExtensionField } from './scripts/extensions.js';
162162import { COMMENT_NAME_DEFAULT, executeSlashCommands, executeSlashCommandsOnChatInput, getSlashCommandsHelp, initDefaultSlashCommands, isExecutingCommandsFromChatInput, pauseScriptExecution, processChatSlashCommands, registerSlashCommand, stopScriptExecution } from './scripts/slash-commands.js';
163163import {
164164 tag_map,
165165 tags,
@@ -911,6 +911,7 @@ async function firstLoadInit() {
911911 initKeyboard();
912912 initDynamicStyles();
913913 initTags();
914+ initDefaultSlashCommands();
914915 await getUserAvatars(true, user_avatar);
915916 await getCharacters();
916917 await getBackgrounds();
public/scripts/slash-commands.js+967 -966
@@ -38,13 +38,13 @@ import {
3838 system_message_types,
3939 this_chid,
4040} from '../script.js';
4141import { PARSER_FLAG, SlashCommandParser } from './slash-commands/SlashCommandParser.js';
4242import { SlashCommandParserError } from './slash-commands/SlashCommandParserError.js';
4343import { getMessageTimeStamp } from './RossAscends-mods.js';
4444import { hideChatMessageRange } from './chats.js';
4545import { extension_settings, getContext, saveMetadataDebounced } from './extensions.js';
4646import { getRegexedString, regex_placement } from './extensions/regex/engine.js';
4747import { findGroupMemberId, getGroupMembers, groups, is_group_generating, openGroupById, resetSelectedGroup, saveGroupChat, selected_group } from './group-chats.js';
4848import { chat_completion_sources, oai_settings, setupChatCompletionPromptManager } from './openai.js';
4949import { autoSelectPersona, retriggerFirstMessageOnEmptyChat, setPersonaLockState, togglePersonaLock, user_avatar } from './personas.js';
5050import { addEphemeralStoppingString, chat_styles, flushEphemeralStoppingStrings, power_user } from './power-user.js';
@@ -53,7 +53,6 @@ import { decodeTextTokens, getFriendlyTokenizerName, getTextTokens, getTokenCoun
5353import { debounce, delay, isFalseBoolean, isTrueBoolean, stringToRange, trimToEndSentence, trimToStartSentence, waitUntilCondition } from './utils.js';
5454import { registerVariableCommands, resolveVariable } from './variables.js';
5555import { background_settings } from './backgrounds.js';
56-import { SlashCommandScope } from './slash-commands/SlashCommandScope.js';
5756import { SlashCommandClosure } from './slash-commands/SlashCommandClosure.js';
5857import { SlashCommandClosureResult } from './slash-commands/SlashCommandClosureResult.js';
5958import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from './slash-commands/SlashCommandArgument.js';
@@ -75,78 +74,79 @@ export const parser = new SlashCommandParser();
7574const registerSlashCommand = SlashCommandParser.addCommand.bind(SlashCommandParser);
7675const getSlashCommandsHelp = parser.getHelpString.bind(parser);
7776
78-SlashCommandParser.addCommandObject(SlashCommand.fromProps({
77+export function initDefaultSlashCommands() {
79- name: '?',
78+ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
80- callback: helpCommandCallback,
79+ name: '?',
81- aliases: ['help'],
80+ callback: helpCommandCallback,
82- unnamedArgumentList: [SlashCommandArgument.fromProps({
81+ aliases: ['help'],
83- description: 'help topic',
82+ unnamedArgumentList: [SlashCommandArgument.fromProps({
84- typeList: [ARGUMENT_TYPE.STRING],
83+ description: 'help topic',
85- enumList: [
86- new SlashCommandEnumValue('slash', 'slash commands (STscript)', enumTypes.command, '/'),
87- new SlashCommandEnumValue('macros', '{{macros}} (text replacement)', enumTypes.macro, enumIcons.macro),
88- new SlashCommandEnumValue('format', 'chat/text formatting', enumTypes.name, '★'),
89- new SlashCommandEnumValue('hotkeys', 'keyboard shortcuts', enumTypes.enum, '⏎'),
90- ],
91- })],
92- helpString: 'Get help on macros, chat formatting and commands.',
93-}));
94-SlashCommandParser.addCommandObject(SlashCommand.fromProps({
95- name: 'persona',
96- callback: setNameCallback,
97- namedArgumentList: [
98- new SlashCommandNamedArgument(
99- 'mode', 'The mode for persona selection. ("lookup" = search for existing persona, "temp" = create a temporary name, set a temporary name, "all" = allow both in the same command)',
100- [ARGUMENT_TYPE.STRING], false, false, 'all', ['lookup', 'temp', 'all'],
101- ),
102- ],
103- unnamedArgumentList: [
104- SlashCommandArgument.fromProps({
105- description: 'persona name',
10684 typeList: [ARGUMENT_TYPE.STRING],
10785 isRequiredenumList: true,[
108- enumProvider: commonEnumProviders.personas,
86+ new SlashCommandEnumValue('slash', 'slash commands (STscript)', enumTypes.command, '/'),
109- }),
87+ new SlashCommandEnumValue('macros', '{{macros}} (text replacement)', enumTypes.macro, enumIcons.macro),
110- ],
88+ new SlashCommandEnumValue('format', 'chat/text formatting', enumTypes.name, '★'),
111- helpString: 'Selects the given persona with its name and avatar (by name or avatar url). If no matching persona exists, applies a temporary name.',
89+ new SlashCommandEnumValue('hotkeys', 'keyboard shortcuts', enumTypes.enum, '⏎'),
112- aliases: ['name'],
90+ ],
113-}));
91+ })],
114-SlashCommandParser.addCommandObject(SlashCommand.fromProps({
92+ helpString: 'Get help on macros, chat formatting and commands.',
115- name: 'sync',
93+ }));
116- callback: syncCallback,
94+ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
117- helpString: 'Syncs the user persona in user-attributed messages in the current chat.',
95+ name: 'persona',
118-}));
96+ callback: setNameCallback,
119-SlashCommandParser.addCommandObject(SlashCommand.fromProps({
97+ namedArgumentList: [
120- name: 'lock',
98+ new SlashCommandNamedArgument(
121- callback: lockPersonaCallback,
99+ 'mode', 'The mode for persona selection. ("lookup" = search for existing persona, "temp" = create a temporary name, set a temporary name, "all" = allow both in the same command)',
122- aliases: ['bind'],
100+ [ARGUMENT_TYPE.STRING], false, false, 'all', ['lookup', 'temp', 'all'],
123- helpString: 'Locks/unlocks a persona (name and avatar) to the current chat',
101+ ),
124- unnamedArgumentList: [
102+ ],
125- SlashCommandArgument.fromProps({
103+ unnamedArgumentList: [
126- description: 'state',
104+ SlashCommandArgument.fromProps({
127- typeList: [ARGUMENT_TYPE.STRING],
105+ description: 'persona name',
128- isRequired: true,
106+ typeList: [ARGUMENT_TYPE.STRING],
129- defaultValue: 'toggle',
107+ isRequired: true,
130108 enumProvider: commonEnumProviders.boolean('onOffToggle')personas,
131109 }),
132110 ],
133-}));
111+ helpString: 'Selects the given persona with its name and avatar (by name or avatar url). If no matching persona exists, applies a temporary name.',
134-SlashCommandParser.addCommandObject(SlashCommand.fromProps({
112+ aliases: ['name'],
135- name: 'bg',
113+ }));
136- callback: setBackgroundCallback,
114+ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
137115 aliases name: ['backgroundsync'],
138- returns: 'the current background',
116+ callback: syncCallback,
139- unnamedArgumentList: [
117+ helpString: 'Syncs the user persona in user-attributed messages in the current chat.',
140- SlashCommandArgument.fromProps({
118+ }));
141- description: 'filename',
119+ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
142- typeList: [ARGUMENT_TYPE.STRING],
120+ name: 'lock',
143121 isRequired callback: truelockPersonaCallback,
144- enumProvider: () => [...document.querySelectorAll('.bg_example')]
122+ aliases: ['bind'],
145- .map(it => new SlashCommandEnumValue(it.getAttribute('bgfile')))
123+ helpString: 'Locks/unlocks a persona (name and avatar) to the current chat',
146- .filter(it => it.value?.length),
124+ unnamedArgumentList: [
147- }),
125+ SlashCommandArgument.fromProps({
148- ],
126+ description: 'state',
149- helpString: `
127+ typeList: [ARGUMENT_TYPE.STRING],
128+ isRequired: true,
129+ defaultValue: 'toggle',
130+ enumProvider: commonEnumProviders.boolean('onOffToggle'),
131+ }),
132+ ],
133+ }));
134+ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
135+ name: 'bg',
136+ callback: setBackgroundCallback,
137+ aliases: ['background'],
138+ returns: 'the current background',
139+ unnamedArgumentList: [
140+ SlashCommandArgument.fromProps({
141+ description: 'filename',
142+ typeList: [ARGUMENT_TYPE.STRING],
143+ isRequired: true,
144+ enumProvider: () => [...document.querySelectorAll('.bg_example')]
145+ .map(it => new SlashCommandEnumValue(it.getAttribute('bgfile')))
146+ .filter(it => it.value?.length),
147+ }),
148+ ],
149+ helpString: `
150150 <div>
151151 Sets a background according to the provided filename. Partial names allowed.
152152 </div>
@@ -159,35 +159,35 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
159159 </ul>
160160 </div>
161161 `,
162162 }));
163163 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
164164 name: 'sendas',
165165 callback: sendMessageAs,
166166 namedArgumentList: [
167167 SlashCommandNamedArgument.fromProps({
168168 name: 'name',
169169 description: 'Character name',
170170 typeList: [ARGUMENT_TYPE.STRING],
171171 isRequired: true,
172172 enumProvider: commonEnumProviders.characters('character'),
173173 forceEnum: false,
174174 }),
175175 new SlashCommandNamedArgument(
176176 'compact', 'Use compact layout', [ARGUMENT_TYPE.BOOLEAN], false, false, 'false',
177177 ),
178178 SlashCommandNamedArgument.fromProps({
179179 name: 'at',
180180 description: 'position to insert the message',
181181 typeList: [ARGUMENT_TYPE.NUMBER],
182182 enumProvider: commonEnumProviders.messages({ allowIdAfter: true }),
183183 }),
184184 ],
185185 unnamedArgumentList: [
186186 new SlashCommandArgument(
187187 'text', [ARGUMENT_TYPE.STRING], true,
188188 ),
189189 ],
190190 helpString: `
191191 <div>
192192 Sends a message as a specific character. Uses the character avatar if it exists in the characters list.
193193 </div>
@@ -204,33 +204,33 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
204204 If "compact" is set to true, the message is sent using a compact layout.
205205 </div>
206206 `,
207207 }));
208208 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
209209 name: 'sys',
210210 callback: sendNarratorMessage,
211211 aliases: ['nar'],
212212 namedArgumentList: [
213213 new SlashCommandNamedArgument(
214214 'compact',
215215 'compact layout',
216216 [ARGUMENT_TYPE.BOOLEAN],
217217 false,
218218 false,
219219 'false',
220220 ),
221221 SlashCommandNamedArgument.fromProps({
222222 name: 'at',
223223 description: 'position to insert the message',
224224 typeList: [ARGUMENT_TYPE.NUMBER],
225225 enumProvider: commonEnumProviders.messages({ allowIdAfter: true }),
226226 }),
227227 ],
228228 unnamedArgumentList: [
229229 new SlashCommandArgument(
230230 'text', [ARGUMENT_TYPE.STRING], true,
231231 ),
232232 ],
233233 helpString: `
234234 <div>
235235 Sends a message as a system narrator.
236236 </div>
@@ -249,44 +249,44 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
249249 </ul>
250250 </div>
251251 `,
252252 }));
253253 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
254254 name: 'sysname',
255255 callback: setNarratorName,
256256 unnamedArgumentList: [
257257 new SlashCommandArgument(
258258 'name', [ARGUMENT_TYPE.STRING], false,
259259 ),
260260 ],
261261 helpString: 'Sets a name for future system narrator messages in this chat (display only). Default: System. Leave empty to reset.',
262262 }));
263263 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
264264 name: 'comment',
265265 callback: sendCommentMessage,
266266 namedArgumentList: [
267267 new SlashCommandNamedArgument(
268268 'compact',
269269 'Whether to use a compact layout',
270270 [ARGUMENT_TYPE.BOOLEAN],
271271 false,
272272 false,
273273 'false',
274274 ),
275275 SlashCommandNamedArgument.fromProps({
276276 name: 'at',
277277 description: 'position to insert the message',
278278 typeList: [ARGUMENT_TYPE.NUMBER],
279279 enumProvider: commonEnumProviders.messages({ allowIdAfter: true }),
280280 }),
281281 ],
282282 unnamedArgumentList: [
283283 new SlashCommandArgument(
284284 'text',
285285 [ARGUMENT_TYPE.STRING],
286286 true,
287287 ),
288288 ],
289289 helpString: `
290290 <div>
291291 Adds a note/comment message not part of the chat.
292292 </div>
@@ -305,35 +305,35 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
305305 </ul>
306306 </div>
307307 `,
308308 }));
309309 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
310310 name: 'single',
311311 callback: setStoryModeCallback,
312312 aliases: ['story'],
313313 helpString: 'Sets the message style to single document mode without names or avatars visible.',
314314 }));
315315 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
316316 name: 'bubble',
317317 callback: setBubbleModeCallback,
318318 aliases: ['bubbles'],
319319 helpString: 'Sets the message style to bubble chat mode.',
320320 }));
321321 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
322322 name: 'flat',
323323 callback: setFlatModeCallback,
324324 aliases: ['default'],
325325 helpString: 'Sets the message style to flat chat mode.',
326326 }));
327327 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
328328 name: 'continue',
329329 callback: continueChatCallback,
330330 aliases: ['cont'],
331331 unnamedArgumentList: [
332332 new SlashCommandArgument(
333333 'prompt', [ARGUMENT_TYPE.STRING], false,
334334 ),
335335 ],
336336 helpString: `
337337 <div>
338338 Continues the last message in the chat, with an optional additional prompt.
339339 </div>
@@ -351,87 +351,87 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
351351 </ul>
352352 </div>
353353 `,
354354 }));
355355 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
356356 name: 'go',
357357 callback: goToCharacterCallback,
358358 unnamedArgumentList: [
359359 SlashCommandArgument.fromProps({
360360 description: 'name',
361361 typeList: [ARGUMENT_TYPE.STRING],
362362 isRequired: true,
363363 enumProvider: commonEnumProviders.characters('all'),
364364 }),
365365 ],
366366 helpString: 'Opens up a chat with the character or group by its name',
367367 aliases: ['char'],
368368 }));
369369 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
370370 name: 'rename-char',
371371 /** @param {{silent: string, chats: string}} options @param {string} name */
372372 callback: async ({ silent = 'true', chats = null }, name) => {
373373 const renamed = await renameCharacter(name, { silent: isTrueBoolean(silent), renameChats: chats !== null ? isTrueBoolean(chats) : null });
374374 return String(renamed);
375375 },
376376 returns: 'true/false - Whether the rename was successful',
377377 namedArgumentList: [
378378 new SlashCommandNamedArgument(
379379 'silent', 'Hide any blocking popups. (if false, the name is optional. If not supplied, a popup asking for it will appear)', [ARGUMENT_TYPE.BOOLEAN], false, false, 'true',
380380 ),
381381 new SlashCommandNamedArgument(
382382 'chats', 'Rename char in all previous chats', [ARGUMENT_TYPE.BOOLEAN], false, false, '<null>',
383383 ),
384384 ],
385385 unnamedArgumentList: [
386386 new SlashCommandArgument(
387387 'new char name', [ARGUMENT_TYPE.STRING], true,
388388 ),
389389 ],
390390 helpString: 'Renames the current character.',
391391 }));
392392 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
393393 name: 'sysgen',
394394 callback: generateSystemMessage,
395395 unnamedArgumentList: [
396396 new SlashCommandArgument(
397397 'prompt', [ARGUMENT_TYPE.STRING], true,
398398 ),
399399 ],
400400 helpString: 'Generates a system message using a specified prompt.',
401401 }));
402402 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
403403 name: 'ask',
404404 callback: askCharacter,
405405 namedArgumentList: [
406406 SlashCommandNamedArgument.fromProps({
407407 name: 'name',
408408 description: 'character name',
409409 typeList: [ARGUMENT_TYPE.STRING],
410410 isRequired: true,
411411 enumProvider: commonEnumProviders.characters('character'),
412412 }),
413413 ],
414414 unnamedArgumentList: [
415415 new SlashCommandArgument(
416416 'prompt', [ARGUMENT_TYPE.STRING], true, false,
417417 ),
418418 ],
419419 helpString: 'Asks a specified character card a prompt. Character name must be provided in a named argument.',
420420 }));
421421 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
422422 name: 'delname',
423423 callback: deleteMessagesByNameCallback,
424424 namedArgumentList: [],
425425 unnamedArgumentList: [
426426 SlashCommandArgument.fromProps({
427427 description: 'name',
428428 typeList: [ARGUMENT_TYPE.STRING],
429429 isRequired: true,
430430 enumProvider: commonEnumProviders.characters('character'),
431431 }),
432432 ],
433433 aliases: ['cancel'],
434434 helpString: `
435435 <div>
436436 Deletes all messages attributed to a specified name.
437437 </div>
@@ -444,41 +444,41 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
444444 </ul>
445445 </div>
446446 `,
447447 }));
448448 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
449449 name: 'send',
450450 callback: sendUserMessageCallback,
451451 namedArgumentList: [
452452 new SlashCommandNamedArgument(
453453 'compact',
454454 'whether to use a compact layout',
455455 [ARGUMENT_TYPE.BOOLEAN],
456456 false,
457457 false,
458458 'false',
459459 ),
460460 SlashCommandNamedArgument.fromProps({
461461 name: 'at',
462462 description: 'position to insert the message',
463463 typeList: [ARGUMENT_TYPE.NUMBER],
464464 enumProvider: commonEnumProviders.messages({ allowIdAfter: true }),
465465 }),
466466 SlashCommandNamedArgument.fromProps({
467467 name: 'name',
468468 description: 'display name',
469469 typeList: [ARGUMENT_TYPE.STRING],
470470 defaultValue: '{{user}}',
471471 enumProvider: commonEnumProviders.characters('character'),
472472 }),
473473 ],
474474 unnamedArgumentList: [
475475 new SlashCommandArgument(
476476 'text',
477477 [ARGUMENT_TYPE.STRING],
478478 true,
479479 ),
480480 ],
481481 helpString: `
482482 <div>
483483 Adds a user message to the chat log without triggering a generation.
484484 </div>
@@ -500,29 +500,29 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
500500 </ul>
501501 </div>
502502 `,
503503 }));
504504 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
505505 name: 'trigger',
506506 callback: triggerGenerationCallback,
507507 namedArgumentList: [
508508 new SlashCommandNamedArgument(
509509 'await',
510510 'Whether to await for the triggered generation before continuing',
511511 [ARGUMENT_TYPE.BOOLEAN],
512512 false,
513513 false,
514514 'false',
515515 ),
516516 ],
517517 unnamedArgumentList: [
518518 SlashCommandArgument.fromProps({
519519 description: 'group member index (starts with 0) or name',
520520 typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.STRING],
521521 isRequired: false,
522522 enumProvider: commonEnumProviders.groupMembers(),
523523 }),
524524 ],
525525 helpString: `
526526 <div>
527527 Triggers a message generation. If in group, can trigger a message for the specified group member index or name.
528528 </div>
@@ -530,74 +530,74 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
530530 If <code>await=true</code> named argument is passed, the command will await for the triggered generation before continuing.
531531 </div>
532532 `,
533533 }));
534534 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
535535 name: 'hide',
536536 callback: hideMessageCallback,
537537 unnamedArgumentList: [
538538 SlashCommandArgument.fromProps({
539539 description: 'message index (starts with 0) or range',
540540 typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.RANGE],
541541 isRequired: true,
542542 enumProvider: commonEnumProviders.messages(),
543543 }),
544544 ],
545545 helpString: 'Hides a chat message from the prompt.',
546546 }));
547547 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
548548 name: 'unhide',
549549 callback: unhideMessageCallback,
550550 unnamedArgumentList: [
551551 SlashCommandArgument.fromProps({
552552 description: 'message index (starts with 0) or range',
553553 typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.RANGE],
554554 isRequired: true,
555555 enumProvider: commonEnumProviders.messages(),
556556 }),
557557 ],
558558 helpString: 'Unhides a message from the prompt.',
559559 }));
560560 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
561561 name: 'member-disable',
562562 callback: disableGroupMemberCallback,
563563 aliases: ['disable', 'disablemember', 'memberdisable'],
564564 unnamedArgumentList: [
565565 SlashCommandArgument.fromProps({
566566 description: 'member index (starts with 0) or name',
567567 typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.STRING],
568568 isRequired: true,
569569 enumProvider: commonEnumProviders.groupMembers(),
570570 }),
571571 ],
572572 helpString: 'Disables a group member from being drafted for replies.',
573573 }));
574574 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
575575 name: 'member-enable',
576576 aliases: ['enable', 'enablemember', 'memberenable'],
577577 callback: enableGroupMemberCallback,
578578 unnamedArgumentList: [
579579 SlashCommandArgument.fromProps({
580580 description: 'member index (starts with 0) or name',
581581 typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.STRING],
582582 isRequired: true,
583583 enumProvider: commonEnumProviders.groupMembers(),
584584 }),
585585 ],
586586 helpString: 'Enables a group member to be drafted for replies.',
587587 }));
588588 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
589589 name: 'member-add',
590590 callback: addGroupMemberCallback,
591591 aliases: ['addmember', 'memberadd'],
592592 unnamedArgumentList: [
593593 SlashCommandArgument.fromProps({
594594 description: 'character name',
595595 typeList: [ARGUMENT_TYPE.STRING],
596596 isRequired: true,
597597 enumProvider: () => selected_group ? commonEnumProviders.characters('character')() : [],
598598 }),
599599 ],
600600 helpString: `
601601 <div>
602602 Adds a new group member to the group chat.
603603 </div>
@@ -610,20 +610,20 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
610610 </ul>
611611 </div>
612612 `,
613613 }));
614614 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
615615 name: 'member-remove',
616616 callback: removeGroupMemberCallback,
617617 aliases: ['removemember', 'memberremove'],
618618 unnamedArgumentList: [
619619 SlashCommandArgument.fromProps({
620620 description: 'member index (starts with 0) or name',
621621 typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.STRING],
622622 isRequired: true,
623623 enumProvider: commonEnumProviders.groupMembers(),
624624 }),
625625 ],
626626 helpString: `
627627 <div>
628628 Removes a group member from the group chat.
629629 </div>
@@ -637,47 +637,47 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
637637 </ul>
638638 </div>
639639 `,
640640 }));
641641 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
642642 name: 'member-up',
643643 callback: moveGroupMemberUpCallback,
644644 aliases: ['upmember', 'memberup'],
645645 unnamedArgumentList: [
646646 SlashCommandArgument.fromProps({
647647 description: 'member index (starts with 0) or name',
648648 typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.STRING],
649649 isRequired: true,
650650 enumProvider: commonEnumProviders.groupMembers(),
651651 }),
652652 ],
653653 helpString: 'Moves a group member up in the group chat list.',
654654 }));
655655 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
656656 name: 'member-down',
657657 callback: moveGroupMemberDownCallback,
658658 aliases: ['downmember', 'memberdown'],
659659 unnamedArgumentList: [
660660 SlashCommandArgument.fromProps({
661661 description: 'member index (starts with 0) or name',
662662 typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.STRING],
663663 isRequired: true,
664664 enumProvider: commonEnumProviders.groupMembers(),
665665 }),
666666 ],
667667 helpString: 'Moves a group member down in the group chat list.',
668668 }));
669669 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
670670 name: 'peek',
671671 callback: peekCallback,
672672 unnamedArgumentList: [
673673 SlashCommandArgument.fromProps({
674674 description: 'member index (starts with 0) or name',
675675 typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.STRING],
676676 isRequired: true,
677677 enumProvider: commonEnumProviders.groupMembers(),
678678 }),
679679 ],
680680 helpString: `
681681 <div>
682682 Shows a group member character card without switching chats.
683683 </div>
@@ -691,22 +691,22 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
691691 </ul>
692692 </div>
693693 `,
694694 }));
695695 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
696696 name: 'delswipe',
697697 callback: deleteSwipeCallback,
698698 aliases: ['swipedel'],
699699 unnamedArgumentList: [
700700 SlashCommandArgument.fromProps({
701701 description: '1-based swipe id',
702702 typeList: [ARGUMENT_TYPE.NUMBER],
703703 isRequired: true,
704704 enumProvider: () => Array.isArray(chat[chat.length - 1]?.swipes) ?
705705 chat[chat.length - 1].swipes.map((/** @type {string} */ swipe, /** @type {number} */ i) => new SlashCommandEnumValue(String(i + 1), swipe, enumTypes.enum, enumIcons.message))
706706 : [],
707707 }),
708708 ],
709709 helpString: `
710710 <div>
711711 Deletes a swipe from the last chat message. If swipe id is not provided, it deletes the current swipe.
712712 </div>
@@ -724,34 +724,34 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
724724 </ul>
725725 </div>
726726 `,
727727 }));
728728 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
729729 name: 'echo',
730730 callback: echoCallback,
731731 returns: 'the text',
732732 namedArgumentList: [
733733 new SlashCommandNamedArgument(
734734 'title', 'title of the toast message', [ARGUMENT_TYPE.STRING], false,
735735 ),
736736 SlashCommandNamedArgument.fromProps({
737737 name: 'severity',
738738 description: 'severity level of the toast message',
739739 typeList: [ARGUMENT_TYPE.STRING],
740740 defaultValue: 'info',
741741 enumProvider: () => [
742742 new SlashCommandEnumValue('info', 'info', enumTypes.macro, 'ℹ️'),
743743 new SlashCommandEnumValue('warning', 'warning', enumTypes.enum, '⚠️'),
744744 new SlashCommandEnumValue('error', 'error', enumTypes.enum, '❗'),
745745 new SlashCommandEnumValue('success', 'success', enumTypes.enum, '✅'),
746746 ],
747747 }),
748748 ],
749749 unnamedArgumentList: [
750750 new SlashCommandArgument(
751751 'text', [ARGUMENT_TYPE.STRING], true,
752752 ),
753753 ],
754754 helpString: `
755755 <div>
756756 Echoes the provided text to a toast message. Useful for pipes debugging.
757757 </div>
@@ -764,42 +764,42 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
764764 </ul>
765765 </div>
766766 `,
767767 }));
768768 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
769769 name: 'gen',
770770 callback: generateCallback,
771771 returns: 'generated text',
772772 namedArgumentList: [
773773 new SlashCommandNamedArgument(
774774 'lock', 'lock user input during generation', [ARGUMENT_TYPE.BOOLEAN], false, false, null, commonEnumProviders.boolean('onOff')(),
775775 ),
776776 SlashCommandNamedArgument.fromProps({
777777 name: 'name',
778778 description: 'in-prompt name for instruct mode',
779779 typeList: [ARGUMENT_TYPE.STRING],
780780 defaultValue: 'System',
781781 enumProvider: () => [...commonEnumProviders.characters('character')(), new SlashCommandEnumValue('System', null, enumTypes.enum, enumIcons.assistant)],
782782 forceEnum: false,
783783 }),
784784 new SlashCommandNamedArgument(
785785 'length', 'API response length in tokens', [ARGUMENT_TYPE.NUMBER], false,
786786 ),
787787 SlashCommandNamedArgument.fromProps({
788788 name: 'as',
789789 description: 'role of the output prompt',
790790 typeList: [ARGUMENT_TYPE.STRING],
791791 enumList: [
792792 new SlashCommandEnumValue('system', null, enumTypes.enum, enumIcons.assistant),
793793 new SlashCommandEnumValue('char', null, enumTypes.enum, enumIcons.character),
794794 ],
795795 }),
796796 ],
797797 unnamedArgumentList: [
798798 new SlashCommandArgument(
799799 'prompt', [ARGUMENT_TYPE.STRING], true,
800800 ),
801801 ],
802802 helpString: `
803803 <div>
804804 Generates text using the provided prompt and passes it to the next command through the pipe, optionally locking user input while generating and allowing to configure the in-prompt name for instruct mode (default = "System").
805805 </div>
@@ -807,43 +807,43 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
807807 "as" argument controls the role of the output prompt: system (default) or char. If "length" argument is provided as a number in tokens, allows to temporarily override an API response length.
808808 </div>
809809 `,
810810 }));
811811 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
812812 name: 'genraw',
813813 callback: generateRawCallback,
814814 returns: 'generated text',
815815 namedArgumentList: [
816816 new SlashCommandNamedArgument(
817817 'lock', 'lock user input during generation', [ARGUMENT_TYPE.BOOLEAN], false, false, null, commonEnumProviders.boolean('onOff')(),
818818 ),
819819 new SlashCommandNamedArgument(
820820 'instruct', 'use instruct mode', [ARGUMENT_TYPE.BOOLEAN], false, false, 'on', commonEnumProviders.boolean('onOff')(),
821821 ),
822822 new SlashCommandNamedArgument(
823823 'stop', 'one-time custom stop strings', [ARGUMENT_TYPE.LIST], false,
824824 ),
825825 SlashCommandNamedArgument.fromProps({
826826 name: 'as',
827827 description: 'role of the output prompt',
828828 typeList: [ARGUMENT_TYPE.STRING],
829829 enumList: [
830830 new SlashCommandEnumValue('system', null, enumTypes.enum, enumIcons.assistant),
831831 new SlashCommandEnumValue('char', null, enumTypes.enum, enumIcons.character),
832832 ],
833833 }),
834834 new SlashCommandNamedArgument(
835835 'system', 'system prompt at the start', [ARGUMENT_TYPE.STRING], false,
836836 ),
837837 new SlashCommandNamedArgument(
838838 'length', 'API response length in tokens', [ARGUMENT_TYPE.NUMBER], false,
839839 ),
840840 ],
841841 unnamedArgumentList: [
842842 new SlashCommandArgument(
843843 'prompt', [ARGUMENT_TYPE.STRING], true,
844844 ),
845845 ],
846846 helpString: `
847847 <div>
848848 Generates text using the provided prompt and passes it to the next command through the pipe, optionally locking user input while generating. Does not include chat history or character card.
849849 </div>
@@ -860,55 +860,55 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
860860 If "length" argument is provided as a number in tokens, allows to temporarily override an API response length.
861861 </div>
862862 `,
863863 }));
864864 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
865865 name: 'addswipe',
866866 callback: addSwipeCallback,
867867 aliases: ['swipeadd'],
868868 unnamedArgumentList: [
869869 new SlashCommandArgument(
870870 'text', [ARGUMENT_TYPE.STRING], true,
871871 ),
872872 ],
873873 helpString: 'Adds a swipe to the last chat message.',
874874 }));
875875 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
876876 name: 'abort',
877877 callback: abortCallback,
878878 namedArgumentList: [
879879 SlashCommandNamedArgument.fromProps({
880880 name: 'quiet',
881881 description: 'Whether to suppress the toast message notifying about the /abort call.',
882882 typeList: [ARGUMENT_TYPE.BOOLEAN],
883883 defaultValue: 'true',
884884 }),
885885 ],
886886 unnamedArgumentList: [
887887 SlashCommandArgument.fromProps({
888888 description: 'The reason for aborting command execution. Shown when quiet=false',
889889 typeList: [ARGUMENT_TYPE.STRING],
890890 }),
891891 ],
892892 helpString: 'Aborts the slash command batch execution.',
893893 }));
894894 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
895895 name: 'fuzzy',
896896 callback: fuzzyCallback,
897897 returns: 'first matching item',
898898 namedArgumentList: [
899899 new SlashCommandNamedArgument(
900900 'list', 'list of items to match against', [ARGUMENT_TYPE.LIST], true,
901901 ),
902902 new SlashCommandNamedArgument(
903903 'threshold', 'fuzzy match threshold (0.0 to 1.0)', [ARGUMENT_TYPE.NUMBER], false, false, '0.4',
904904 ),
905905 ],
906906 unnamedArgumentList: [
907907 new SlashCommandArgument(
908908 'text to search', [ARGUMENT_TYPE.STRING], true,
909909 ),
910910 ],
911911 helpString: `
912912 <div>
913913 Performs a fuzzy match of each item in the <code>list</code> against the <code>text to search</code>.
914914 If any item matches, then its name is returned. If no item matches the text, no value is returned.
@@ -930,23 +930,23 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
930930 </ul>
931931 </div>
932932 `,
933933 }));
934934 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
935935 name: 'pass',
936936 callback: (_, arg) => {
937937 // We do not support arrays of closures. Arrays of strings will be send as JSON
938938 if (Array.isArray(arg) && arg.some(x => x instanceof SlashCommandClosure)) throw new Error('Command /pass does not support multiple closures');
939939 if (Array.isArray(arg)) return JSON.stringify(arg);
940940 return arg;
941941 },
942942 returns: 'the provided value',
943943 unnamedArgumentList: [
944944 new SlashCommandArgument(
945945 'text', [ARGUMENT_TYPE.STRING, ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.BOOLEAN, ARGUMENT_TYPE.LIST, ARGUMENT_TYPE.DICTIONARY, ARGUMENT_TYPE.CLOSURE], true,
946946 ),
947947 ],
948948 aliases: ['return'],
949949 helpString: `
950950 <div>
951951 <pre><span class="monospace">/pass (text)</span> – passes the text to the next command through the pipe.</pre>
952952 </div>
@@ -957,17 +957,17 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
957957 </ul>
958958 </div>
959959 `,
960960 }));
961961 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
962962 name: 'delay',
963963 callback: delayCallback,
964964 aliases: ['wait', 'sleep'],
965965 unnamedArgumentList: [
966966 new SlashCommandArgument(
967967 'milliseconds', [ARGUMENT_TYPE.NUMBER], true,
968968 ),
969969 ],
970970 helpString: `
971971 <div>
972972 Delays the next command in the pipe by the specified number of milliseconds.
973973 </div>
@@ -980,101 +980,101 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
980980 </ul>
981981 </div>
982982 `,
983983 }));
984984 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
985985 name: 'input',
986986 aliases: ['prompt'],
987987 callback: inputCallback,
988988 returns: 'user input',
989989 namedArgumentList: [
990990 new SlashCommandNamedArgument(
991991 'default', 'default value of the input field', [ARGUMENT_TYPE.STRING], false, false, '"string"',
992992 ),
993993 new SlashCommandNamedArgument(
994994 'large', 'show large input field', [ARGUMENT_TYPE.BOOLEAN], false, false, 'off', commonEnumProviders.boolean('onOff')(),
995995 ),
996996 new SlashCommandNamedArgument(
997997 'wide', 'show wide input field', [ARGUMENT_TYPE.BOOLEAN], false, false, 'off', commonEnumProviders.boolean('onOff')(),
998998 ),
999999 new SlashCommandNamedArgument(
10001000 'okButton', 'text for the ok button', [ARGUMENT_TYPE.STRING], false,
10011001 ),
10021002 new SlashCommandNamedArgument(
10031003 'rows', 'number of rows for the input field', [ARGUMENT_TYPE.NUMBER], false,
10041004 ),
10051005 ],
10061006 unnamedArgumentList: [
10071007 new SlashCommandArgument(
10081008 'text to display', [ARGUMENT_TYPE.STRING], false,
10091009 ),
10101010 ],
10111011 helpString: `
10121012 <div>
10131013 Shows a popup with the provided text and an input field.
10141014 The <code>default</code> argument is the default value of the input field, and the text argument is the text to display.
10151015 </div>
10161016 `,
10171017 }));
10181018 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
10191019 name: 'run',
10201020 aliases: ['call', 'exec'],
10211021 callback: runCallback,
10221022 returns: 'result of the executed closure of QR',
10231023 namedArgumentList: [
10241024 new SlashCommandNamedArgument(
10251025 'args', 'named arguments', [ARGUMENT_TYPE.STRING, ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.BOOLEAN, ARGUMENT_TYPE.LIST, ARGUMENT_TYPE.DICTIONARY], false, true,
10261026 ),
10271027 ],
10281028 unnamedArgumentList: [
10291029 SlashCommandArgument.fromProps({
10301030 description: 'scoped variable or qr label',
10311031 typeList: [ARGUMENT_TYPE.VARIABLE_NAME, ARGUMENT_TYPE.STRING],
10321032 isRequired: true,
10331033 enumProvider: () => [
10341034 ...commonEnumProviders.variables('scope')(),
10351035 ...(typeof window['qrEnumProviderExecutables'] === 'function') ? window['qrEnumProviderExecutables']() : [],
10361036 ],
10371037 }),
10381038 ],
10391039 helpString: `
10401040 <div>
10411041 Runs a closure from a scoped variable, or a Quick Reply with the specified name from a currently active preset or from another preset.
10421042 Named arguments can be referenced in a QR with <code>{{arg::key}}</code>.
10431043 </div>
10441044 `,
10451045 }));
10461046 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
10471047 name: 'messages',
10481048 callback: getMessagesCallback,
10491049 aliases: ['message'],
10501050 namedArgumentList: [
10511051 new SlashCommandNamedArgument(
10521052 'names', 'show message author names', [ARGUMENT_TYPE.BOOLEAN], false, false, 'off', commonEnumProviders.boolean('onOff')(),
10531053 ),
10541054 new SlashCommandNamedArgument(
10551055 'hidden', 'include hidden messages', [ARGUMENT_TYPE.BOOLEAN], false, false, 'on', commonEnumProviders.boolean('onOff')(),
10561056 ),
10571057 SlashCommandNamedArgument.fromProps({
10581058 name: 'role',
10591059 description: 'filter messages by role',
10601060 typeList: [ARGUMENT_TYPE.STRING],
10611061 enumList: [
10621062 new SlashCommandEnumValue('system', null, enumTypes.enum, enumIcons.system),
10631063 new SlashCommandEnumValue('assistant', null, enumTypes.enum, enumIcons.assistant),
10641064 new SlashCommandEnumValue('user', null, enumTypes.enum, enumIcons.user),
10651065 ],
10661066 }),
10671067 ],
10681068 unnamedArgumentList: [
10691069 SlashCommandArgument.fromProps({
10701070 description: 'message index (starts with 0) or range',
10711071 typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.RANGE],
10721072 isRequired: true,
10731073 enumProvider: commonEnumProviders.messages(),
10741074 }),
10751075 ],
10761076 returns: 'the specified message or range of messages as a string',
10771077 helpString: `
10781078 <div>
10791079 Returns the specified message or range of messages as a string.
10801080 </div>
@@ -1098,16 +1098,16 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
10981098 </ul>
10991099 </div>
11001100 `,
11011101 }));
11021102 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
11031103 name: 'setinput',
11041104 callback: setInputCallback,
11051105 unnamedArgumentList: [
11061106 new SlashCommandArgument(
11071107 'text', [ARGUMENT_TYPE.STRING], true,
11081108 ),
11091109 ],
11101110 helpString: `
11111111 <div>
11121112 Sets the user input to the specified text and passes it to the next command through the pipe.
11131113 </div>
@@ -1120,28 +1120,28 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
11201120 </ul>
11211121 </div>
11221122 `,
11231123 }));
11241124 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
11251125 name: 'popup',
11261126 callback: popupCallback,
11271127 returns: 'popup text',
11281128 namedArgumentList: [
11291129 new SlashCommandNamedArgument(
11301130 'large', 'show large popup', [ARGUMENT_TYPE.BOOLEAN], false, false, null, commonEnumProviders.boolean('onOff')(),
11311131 ),
11321132 new SlashCommandNamedArgument(
11331133 'wide', 'show wide popup', [ARGUMENT_TYPE.BOOLEAN], false, false, null, commonEnumProviders.boolean('onOff')(),
11341134 ),
11351135 new SlashCommandNamedArgument(
11361136 'okButton', 'text for the OK button', [ARGUMENT_TYPE.STRING], false,
11371137 ),
11381138 ],
11391139 unnamedArgumentList: [
11401140 new SlashCommandArgument(
11411141 'text', [ARGUMENT_TYPE.STRING], true,
11421142 ),
11431143 ],
11441144 helpString: `
11451145 <div>
11461146 Shows a blocking popup with the specified text and buttons.
11471147 Returns the popup text.
@@ -1155,22 +1155,22 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
11551155 </ul>
11561156 </div>
11571157 `,
11581158 }));
11591159 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
11601160 name: 'buttons',
11611161 callback: buttonsCallback,
11621162 returns: 'clicked button label',
11631163 namedArgumentList: [
11641164 new SlashCommandNamedArgument(
11651165 'labels', 'button labels', [ARGUMENT_TYPE.LIST], true,
11661166 ),
11671167 ],
11681168 unnamedArgumentList: [
11691169 new SlashCommandArgument(
11701170 'text', [ARGUMENT_TYPE.STRING], true,
11711171 ),
11721172 ],
11731173 helpString: `
11741174 <div>
11751175 Shows a blocking popup with the specified text and buttons.
11761176 Returns the clicked button label into the pipe or empty string if canceled.
@@ -1184,32 +1184,32 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
11841184 </ul>
11851185 </div>
11861186 `,
11871187 }));
11881188 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
11891189 name: 'trimtokens',
11901190 callback: trimTokensCallback,
11911191 returns: 'trimmed text',
11921192 namedArgumentList: [
11931193 new SlashCommandNamedArgument(
11941194 'limit', 'number of tokens to keep', [ARGUMENT_TYPE.NUMBER], true,
11951195 ),
11961196 SlashCommandNamedArgument.fromProps({
11971197 name: 'direction',
11981198 description: 'trim direction',
11991199 typeList: [ARGUMENT_TYPE.STRING],
12001200 isRequired: true,
12011201 enumList: [
12021202 new SlashCommandEnumValue('start', null, enumTypes.enum, '⏪'),
12031203 new SlashCommandEnumValue('end', null, enumTypes.enum, '⏩'),
12041204 ],
12051205 }),
12061206 ],
12071207 unnamedArgumentList: [
12081208 new SlashCommandArgument(
12091209 'text', [ARGUMENT_TYPE.STRING], false,
12101210 ),
12111211 ],
12121212 helpString: `
12131213 <div>
12141214 Trims the start or end of text to the specified number of tokens.
12151215 </div>
@@ -1222,17 +1222,17 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
12221222 </ul>
12231223 </div>
12241224 `,
12251225 }));
12261226 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
12271227 name: 'trimstart',
12281228 callback: trimStartCallback,
12291229 returns: 'trimmed text',
12301230 unnamedArgumentList: [
12311231 new SlashCommandArgument(
12321232 'text', [ARGUMENT_TYPE.STRING], true,
12331233 ),
12341234 ],
12351235 helpString: `
12361236 <div>
12371237 Trims the text to the start of the first full sentence.
12381238 </div>
@@ -1245,148 +1245,149 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
12451245 </ul>
12461246 </div>
12471247 `,
12481248 }));
12491249 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
12501250 name: 'trimend',
12511251 callback: trimEndCallback,
12521252 returns: 'trimmed text',
12531253 unnamedArgumentList: [
12541254 new SlashCommandArgument(
12551255 'text', [ARGUMENT_TYPE.STRING], true,
12561256 ),
12571257 ],
12581258 helpString: 'Trims the text to the end of the last full sentence.',
12591259 }));
12601260 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
12611261 name: 'inject',
12621262 callback: injectCallback,
12631263 namedArgumentList: [
12641264 SlashCommandNamedArgument.fromProps({
12651265 name: 'id',
12661266 description: 'injection ID or variable name pointing to ID',
12671267 typeList: [ARGUMENT_TYPE.STRING],
12681268 isRequired: true,
12691269 enumProvider: commonEnumProviders.injects,
12701270 }),
12711271 new SlashCommandNamedArgument(
12721272 'position', 'injection position', [ARGUMENT_TYPE.STRING], false, false, 'after', ['before', 'after', 'chat'],
12731273 ),
12741274 new SlashCommandNamedArgument(
12751275 'depth', 'injection depth', [ARGUMENT_TYPE.NUMBER], false, false, '4',
12761276 ),
12771277 new SlashCommandNamedArgument(
12781278 'scan', 'include injection content into World Info scans', [ARGUMENT_TYPE.BOOLEAN], false, false, 'false',
12791279 ),
12801280 SlashCommandNamedArgument.fromProps({
12811281 name: 'role',
12821282 description: 'role for in-chat injections',
12831283 typeList: [ARGUMENT_TYPE.STRING],
12841284 isRequired: false,
12851285 enumList: [
12861286 new SlashCommandEnumValue('system', null, enumTypes.enum, enumIcons.system),
12871287 new SlashCommandEnumValue('assistant', null, enumTypes.enum, enumIcons.assistant),
12881288 new SlashCommandEnumValue('user', null, enumTypes.enum, enumIcons.user),
12891289 ],
12901290 }),
12911291 new SlashCommandNamedArgument(
12921292 'ephemeral', 'remove injection after generation', [ARGUMENT_TYPE.BOOLEAN], false, false, 'false',
12931293 ),
12941294 ],
12951295 unnamedArgumentList: [
12961296 new SlashCommandArgument(
12971297 'text', [ARGUMENT_TYPE.STRING], false,
12981298 ),
12991299 ],
13001300 helpString: 'Injects a text into the LLM prompt for the current chat. Requires a unique injection ID. Positions: "before" main prompt, "after" main prompt, in-"chat" (default: after). Depth: injection depth for the prompt (default: 4). Role: role for in-chat injections (default: system). Scan: include injection content into World Info scans (default: false).',
13011301 }));
13021302 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
13031303 name: 'listinjects',
13041304 callback: listInjectsCallback,
13051305 helpString: 'Lists all script injections for the current chat.',
13061306 }));
13071307 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
13081308 name: 'flushinject',
13091309 aliases: ['flushinjects'],
13101310 unnamedArgumentList: [
13111311 SlashCommandArgument.fromProps({
13121312 description: 'injection ID or a variable name pointing to ID',
13131313 typeList: [ARGUMENT_TYPE.STRING],
13141314 defaultValue: '',
13151315 enumProvider: commonEnumProviders.injects,
13161316 }),
13171317 ],
13181318 callback: flushInjectsCallback,
13191319 helpString: 'Removes a script injection for the current chat. If no ID is provided, removes all script injections.',
13201320 }));
13211321 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
13221322 name: 'tokens',
13231323 callback: (_, text) => {
13241324 if (text instanceof SlashCommandClosure || Array.isArray(text)) throw new Error('Unnamed argument cannot be a closure for command /tokens');
13251325 return getTokenCountAsync(text).then(count => String(count));
13261326 },
13271327 returns: 'number of tokens',
13281328 unnamedArgumentList: [
13291329 new SlashCommandArgument(
13301330 'text', [ARGUMENT_TYPE.STRING], true,
13311331 ),
13321332 ],
13331333 helpString: 'Counts the number of tokens in the provided text.',
13341334 }));
13351335 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
13361336 name: 'model',
13371337 callback: modelCallback,
13381338 returns: 'current model',
13391339 unnamedArgumentList: [
13401340 SlashCommandArgument.fromProps({
13411341 description: 'model name',
13421342 typeList: [ARGUMENT_TYPE.STRING],
13431343 enumProvider: () => getModelOptions()?.options.map(option => new SlashCommandEnumValue(option.value, option.value !== option.text ? option.text : null)),
13441344 }),
13451345 ],
13461346 helpString: 'Sets the model for the current API. Gets the current model name if no argument is provided.',
13471347 }));
13481348 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
13491349 name: 'setpromptentry',
13501350 aliases: ['setpromptentries'],
13511351 callback: setPromptEntryCallback,
13521352 namedArgumentList: [
13531353 SlashCommandNamedArgument.fromProps({
13541354 name: 'identifier',
13551355 description: 'Prompt entry identifier(s) to target',
13561356 typeList: [ARGUMENT_TYPE.STRING, ARGUMENT_TYPE.LIST],
13571357 acceptsMultiple: true,
13581358 enumProvider: () => {
13591359 const promptManager = setupChatCompletionPromptManager(oai_settings);
13601360 const prompts = promptManager.serviceSettings.prompts;
13611361 return prompts.map(prompt => new SlashCommandEnumValue(prompt.identifier, prompt.name, enumTypes.enum));
13621362 },
13631363 }),
13641364 SlashCommandNamedArgument.fromProps({
13651365 name: 'name',
13661366 description: 'Prompt entry name(s) to target',
13671367 typeList: [ARGUMENT_TYPE.STRING, ARGUMENT_TYPE.LIST],
13681368 acceptsMultiple: true,
13691369 enumProvider: () => {
13701370 const promptManager = setupChatCompletionPromptManager(oai_settings);
13711371 const prompts = promptManager.serviceSettings.prompts;
13721372 return prompts.map(prompt => new SlashCommandEnumValue(prompt.name, prompt.identifier, enumTypes.enum));
13731373 },
13741374 }),
13751375 ],
13761376 unnamedArgumentList: [
13771377 SlashCommandArgument.fromProps({
13781378 description: 'Set entry/entries on or off',
13791379 typeList: [ARGUMENT_TYPE.STRING],
13801380 isRequired: true,
13811381 acceptsMultiple: false,
13821382 defaultValue: 'toggle', // unnamed arguments don't support default values yet
13831383 enumList: commonEnumProviders.boolean('onOffToggle')(),
13841384 }),
13851385 ],
13861386 helpString: 'Sets the specified prompt manager entry/entries on or off.',
13871387 }));
13881388
13891389 registerVariableCommands();
1390+}
13901391
13911392const NARRATOR_NAME_KEY = 'narrator_name';
13921393const NARRATOR_NAME_DEFAULT = 'System';