Compare commits

...

8 Commits

Author SHA1 Message Date
Cohee 199a9cef72
Merge 2e50d61590 into c52bdb9a4a 2024-05-17 17:59:32 +00:00
Cohee c52bdb9a4a Use new command names in examples 2024-05-17 20:59:00 +03:00
Cohee bbd9c89357 Add aliases for group member commands 2024-05-17 20:57:03 +03:00
Cohee fb2190ace1 #2254 Don't suppress abort in subcommands 2024-05-17 18:21:13 +03:00
Cohee deb09bf5bf Fix console errors on not found command autocomplete 2024-05-17 17:47:40 +03:00
Cohee d951beb626 #2260 Handle window resize in script editor 2024-05-17 17:47:18 +03:00
based 2e50d61590 include optional source saving 2024-02-01 17:39:37 +10:00
based 8430212474 completely decouple proxies from the chat completion preset file 2024-02-01 15:46:12 +10:00
6 changed files with 147 additions and 37 deletions

View File

@ -2361,6 +2361,15 @@
<input id="openai_proxy_password" type="password" class="text_pole flex1" placeholder="" maxlength="5000" form="openai_form" autocomplete="off" />
<div id="openai_proxy_password_show" title="Peek a password" class="menu_button fa-solid fa-eye-slash fa-fw"></div>
</div>
<div class="">
<div class="range-block-title justifyLeft" id="proxy_current_source" data-i18n="Current source: ">
Current source:
</div>
<label for="openai_show_external_models" class="checkbox_label">
<input id="proxy_save_completion_source" type="checkbox" />
<span data-i18n="Save Model/Completion Source?">Save Model/Completion Source?</span>
</label>
</div>
</div>
</div>
<form id="openai_form" data-source="openai" action="javascript:void(null);" method="post" enctype="multipart/form-data">

View File

@ -342,6 +342,16 @@ export class QuickReply {
message.addEventListener('scroll', (evt)=>{
updateScrollDebounced();
});
/** @type {any} */
const resizeListener = debounce((evt) => {
updateSyntax();
updateScrollDebounced(evt);
if (document.activeElement == message) {
message.blur();
message.focus();
}
});
window.addEventListener('resize', resizeListener);
message.style.color = 'transparent';
message.style.background = 'transparent';
message.style.setProperty('text-shadow', 'none', 'important');
@ -514,6 +524,8 @@ export class QuickReply {
});
await popupResult;
window.removeEventListener('resize', resizeListener);
} else {
warn('failed to fetch qrEditor template');
}

View File

@ -367,6 +367,9 @@ export let proxies = [
name: 'None',
url: '',
password: '',
save_source: false,
model: '',
source: '',
},
];
export let selected_proxy = proxies[0];
@ -2760,7 +2763,6 @@ function loadOpenAISettings(data, settings) {
oai_settings.chat_completion_source = settings.chat_completion_source ?? default_settings.chat_completion_source;
oai_settings.api_url_scale = settings.api_url_scale ?? default_settings.api_url_scale;
oai_settings.show_external_models = settings.show_external_models ?? default_settings.show_external_models;
oai_settings.proxy_password = settings.proxy_password ?? default_settings.proxy_password;
oai_settings.assistant_prefill = settings.assistant_prefill ?? default_settings.assistant_prefill;
oai_settings.assistant_impersonation = settings.assistant_impersonation ?? default_settings.assistant_impersonation;
oai_settings.human_sysprompt_message = settings.human_sysprompt_message ?? default_settings.human_sysprompt_message;
@ -2797,7 +2799,6 @@ function loadOpenAISettings(data, settings) {
$('#stream_toggle').prop('checked', oai_settings.stream_openai);
$('#websearch_toggle').prop('checked', oai_settings.websearch_cohere);
$('#api_url_scale').val(oai_settings.api_url_scale);
$('#openai_proxy_password').val(oai_settings.proxy_password);
$('#claude_assistant_prefill').val(oai_settings.assistant_prefill);
$('#claude_assistant_impersonation').val(oai_settings.assistant_impersonation);
$('#claude_human_sysprompt_textarea').val(oai_settings.human_sysprompt_message);
@ -2890,11 +2891,6 @@ function loadOpenAISettings(data, settings) {
$('#seed_openai').val(oai_settings.seed);
$('#n_openai').val(oai_settings.n);
if (settings.reverse_proxy !== undefined) oai_settings.reverse_proxy = settings.reverse_proxy;
$('#openai_reverse_proxy').val(oai_settings.reverse_proxy);
$('.reverse_proxy_warning').toggle(oai_settings.reverse_proxy !== '');
$('#openai_logit_bias_preset').empty();
for (const preset of Object.keys(oai_settings.bias_presets)) {
const option = document.createElement('option');
@ -3105,8 +3101,6 @@ async function saveOpenAIPreset(name, settings, triggerUi = true) {
new_example_chat_prompt: settings.new_example_chat_prompt,
continue_nudge_prompt: settings.continue_nudge_prompt,
bias_preset_selected: settings.bias_preset_selected,
reverse_proxy: settings.reverse_proxy,
proxy_password: settings.proxy_password,
max_context_unlocked: settings.max_context_unlocked,
wi_format: settings.wi_format,
scenario_format: settings.scenario_format,
@ -3493,7 +3487,6 @@ function onSettingsPresetChange() {
new_example_chat_prompt: ['#newexamplechat_prompt_textarea', 'new_example_chat_prompt', false],
continue_nudge_prompt: ['#continue_nudge_prompt_textarea', 'continue_nudge_prompt', false],
bias_preset_selected: ['#openai_logit_bias_preset', 'bias_preset_selected', false],
reverse_proxy: ['#openai_reverse_proxy', 'reverse_proxy', false],
wi_format: ['#wi_format_textarea', 'wi_format', false],
scenario_format: ['#scenario_format_textarea', 'scenario_format', false],
personality_format: ['#personality_format_textarea', 'personality_format', false],
@ -3504,7 +3497,6 @@ function onSettingsPresetChange() {
prompt_order: ['', 'prompt_order', false],
api_url_scale: ['#api_url_scale', 'api_url_scale', false],
show_external_models: ['#openai_show_external_models', 'show_external_models', true],
proxy_password: ['#openai_proxy_password', 'proxy_password', false],
assistant_prefill: ['#claude_assistant_prefill', 'assistant_prefill', false],
assistant_impersonation: ['#claude_assistant_impersonation', 'assistant_impersonation', false],
human_sysprompt_message: ['#claude_human_sysprompt_textarea', 'human_sysprompt_message', false],
@ -3955,6 +3947,7 @@ async function onModelChange() {
saveSettingsDebounced();
eventSource.emit(event_types.CHATCOMPLETION_MODEL_CHANGED, value);
$('#proxy_current_source').text(`Current source: ${oai_settings.chat_completion_source}/${retrieveModel()}`);
}
async function onOpenrouterModelSortChange() {
@ -4333,7 +4326,8 @@ export function loadProxyPresets(settings) {
} else {
proxies = proxyPresets;
}
//sort alphabetically
proxyPresets.sort((a, b) => a.name.localeCompare(b.name));
$('#openai_proxy_preset').empty();
for (const preset of proxyPresets) {
@ -4344,17 +4338,91 @@ export function loadProxyPresets(settings) {
$('#openai_proxy_preset').append(option);
}
$('#openai_proxy_preset').val(selected_proxy.name);
setProxyPreset(selected_proxy.name, selected_proxy.url, selected_proxy.password);
setProxyPreset(selected_proxy.name, selected_proxy.url, selected_proxy.password, selected_proxy.save_source, selected_proxy.model, selected_proxy.source);
}
function setProxyPreset(name, url, password) {
// two of the functions of all time
function retrieveModel() {
let model;
switch (oai_settings.chat_completion_source) {
case chat_completion_sources.OPENAI:
model = oai_settings.openai_model;
break;
case chat_completion_sources.CLAUDE:
model = oai_settings.claude_model;
break;
case chat_completion_sources.WINDOWAI:
model = oai_settings.windowai_model;
break;
case chat_completion_sources.OPENROUTER:
model = oai_settings.openrouter_model;
break;
case chat_completion_sources.AI21:
model = oai_settings.ai21_model;
break;
case chat_completion_sources.MISTRALAI:
model = oai_settings.mistralai_model;
break;
case chat_completion_sources.CUSTOM:
model = oai_settings.custom_model;
break;
default:
model = '';
}
return model;
}
function setModel(model) {
switch (oai_settings.chat_completion_source) {
case chat_completion_sources.OPENAI:
oai_settings.openai_model = model;
$('#model_openai_select').val(model);
break;
case chat_completion_sources.CLAUDE:
oai_settings.claude_model = model;
$('#model_claude_select').val(model);
break;
case chat_completion_sources.WINDOWAI:
oai_settings.windowai_model = model;
$('#model_windowai_select').val(model);
break;
case chat_completion_sources.MAKERSUITE:
oai_settings.google_model = model;
$('#model_google_select').val(model);
break;
case chat_completion_sources.OPENROUTER:
oai_settings.openrouter_model = model;
$('#model_openrouter_select').val(model);
break;
case chat_completion_sources.AI21:
oai_settings.ai21_model = model;
$('#model_ai21_select').val(model);
break;
case chat_completion_sources.MISTRALAI:
oai_settings.mistralai_model = model;
$('#model_mistralai_select').val(model);
break;
default:
console.log('Invalid chat completion source');
}
toggleChatCompletionForms();
}
function setProxyPreset(name, url, password, save_source, update) {
name = name.trim();
const preset = proxies.find(p => p.name === name);
const model = save_source ? (update ? retrieveModel() : preset.model) : '';
const source = save_source ? (update ? oai_settings.chat_completion_source : preset.source) : '';
if (preset) {
preset.url = url;
preset.password = password;
preset.save_source = save_source;
preset.model = model;
preset.source = source;
selected_proxy = preset;
} else {
let new_proxy = { name, url, password };
let new_proxy = { name, url, password, save_source, model, source };
proxies.push(new_proxy);
selected_proxy = new_proxy;
}
@ -4364,7 +4432,15 @@ function setProxyPreset(name, url, password) {
$('#openai_reverse_proxy').val(oai_settings.reverse_proxy);
oai_settings.proxy_password = password;
$('#openai_proxy_password').val(oai_settings.proxy_password);
$('#proxy_save_completion_source').prop('checked', save_source === undefined ? false : save_source);
if (save_source && model && source) {
oai_settings.chat_completion_source = source;
$('#chat_completion_source').val(oai_settings.chat_completion_source).trigger('change');
setModel(model);
}
reconnectOpenAi();
$('.reverse_proxy_warning').toggle(oai_settings.reverse_proxy !== '');
}
function onProxyPresetChange() {
@ -4372,7 +4448,7 @@ function onProxyPresetChange() {
const selectedPreset = proxies.find(preset => preset.name === value);
if (selectedPreset) {
setProxyPreset(selectedPreset.name, selectedPreset.url, selectedPreset.password);
setProxyPreset(selectedPreset.name, selectedPreset.url, selectedPreset.password, selectedPreset.save_source);
} else {
console.error(`Proxy preset "${value}" not found in proxies array.`);
}
@ -4380,11 +4456,12 @@ function onProxyPresetChange() {
}
$('#save_proxy').on('click', async function () {
const presetName = $('#openai_reverse_proxy_name').val();
const reverseProxy = $('#openai_reverse_proxy').val();
const proxyPassword = $('#openai_proxy_password').val();
const presetName = $('#openai_reverse_proxy_name').val().trim();
const reverseProxy = $('#openai_reverse_proxy').val().trim();
const proxyPassword = $('#openai_proxy_password').val().trim();
const saveSource = $('#proxy_save_completion_source').is(':checked');
setProxyPreset(presetName, reverseProxy, proxyPassword);
setProxyPreset(presetName, reverseProxy, proxyPassword, saveSource, saveSource);
saveSettingsDebounced();
toastr.success('Proxy Saved');
if ($('#openai_proxy_preset').val() !== presetName) {
@ -4398,7 +4475,7 @@ $('#save_proxy').on('click', async function () {
});
$('#delete_proxy').on('click', async function () {
const presetName = $('#openai_reverse_proxy_name').val();
const presetName = $('#openai_reverse_proxy_name').val().trim();
const index = proxies.findIndex(preset => preset.name === presetName);
if (index !== -1) {
@ -4409,7 +4486,7 @@ $('#delete_proxy').on('click', async function () {
const newIndex = Math.max(0, index - 1);
selected_proxy = proxies[newIndex];
} else {
selected_proxy = { name: 'None', url: '', password: '' };
selected_proxy = { name: 'None', url: '', password: '', save_source: false, model: '', source: '' };
}
$('#openai_reverse_proxy_name').val(selected_proxy.name);
@ -4417,7 +4494,11 @@ $('#delete_proxy').on('click', async function () {
$('#openai_reverse_proxy').val(selected_proxy.url);
oai_settings.proxy_password = selected_proxy.password;
$('#openai_proxy_password').val(selected_proxy.password);
if (selected_proxy.save_source) {
oai_settings.chat_completion_source = selected_proxy.source;
$('#chat_completion_source').val(oai_settings.chat_completion_source).trigger('change');
setModel(selected_proxy.model);
}
saveSettingsDebounced();
$('#openai_proxy_preset').val(selected_proxy.name);
toastr.success('Proxy Deleted');

View File

@ -447,8 +447,9 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'unhide',
],
helpString: 'Unhides a message from the prompt.',
}));
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'disable',
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'member-disable',
callback: disableGroupMemberCallback,
aliases: ['disable', 'disablemember', 'memberdisable'],
unnamedArgumentList: [
new SlashCommandArgument(
'member index or name', [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.STRING], true,
@ -456,7 +457,8 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'disable',
],
helpString: 'Disables a group member from being drafted for replies.',
}));
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'enable',
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'member-enable',
aliases: ['enable', 'enablemember', 'memberenable'],
callback: enableGroupMemberCallback,
unnamedArgumentList: [
new SlashCommandArgument(
@ -465,9 +467,9 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'enable',
],
helpString: 'Enables a group member to be drafted for replies.',
}));
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'memberadd',
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'member-add',
callback: addGroupMemberCallback,
aliases: ['addmember'],
aliases: ['addmember', 'memberadd'],
unnamedArgumentList: [
new SlashCommandArgument(
'character name', [ARGUMENT_TYPE.STRING], true,
@ -481,15 +483,15 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'memberadd',
<strong>Example:</strong>
<ul>
<li>
<pre><code>/memberadd John Doe</code></pre>
<pre><code>/member-add John Doe</code></pre>
</li>
</ul>
</div>
`,
}));
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'memberremove',
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'member-remove',
callback: removeGroupMemberCallback,
aliases: ['removemember'],
aliases: ['removemember', 'memberremove'],
unnamedArgumentList: [
new SlashCommandArgument(
'member index or name', [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.STRING], true,
@ -503,16 +505,16 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'memberremove
<strong>Example:</strong>
<ul>
<li>
<pre><code>/memberremove 2</code></pre>
<pre><code>/memberremove John Doe</code></pre>
<pre><code>/member-remove 2</code></pre>
<pre><code>/member-remove John Doe</code></pre>
</li>
</ul>
</div>
`,
}));
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'memberup',
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'member-up',
callback: moveGroupMemberUpCallback,
aliases: ['upmember'],
aliases: ['upmember', 'memberup'],
unnamedArgumentList: [
new SlashCommandArgument(
'member index or name', [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.STRING], true,
@ -520,9 +522,9 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'memberup',
],
helpString: 'Moves a group member up in the group chat list.',
}));
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'memberdown',
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'member-down',
callback: moveGroupMemberDownCallback,
aliases: ['downmember'],
aliases: ['downmember', 'memberdown'],
unnamedArgumentList: [
new SlashCommandArgument(
'member index or name', [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.STRING], true,

View File

@ -58,6 +58,9 @@ export class SlashCommandAutoCompleteNameResult extends AutoCompleteNameResult {
return new RegExp('=(.*)');
}
}
if (!Array.isArray(this.executor.command?.namedArgumentList)) {
return null;
}
const notProvidedNamedArguments = this.executor.command.namedArgumentList.filter(arg=>!this.executor.namedArgumentList.find(it=>it.name == arg.name));
let name;
let value;
@ -130,6 +133,9 @@ export class SlashCommandAutoCompleteNameResult extends AutoCompleteNameResult {
}
getUnnamedArgumentAt(text, index, isSelect) {
if (!Array.isArray(this.executor.command?.unnamedArgumentList)) {
return null;
}
const lastArgIsBlank = this.executor.unnamedArgumentList.slice(-1)[0]?.value == '';
const notProvidedArguments = this.executor.command.unnamedArgumentList.slice(this.executor.unnamedArgumentList.length - (lastArgIsBlank ? 1 : 0));
let value;

View File

@ -518,7 +518,7 @@ async function executeSubCommands(command, scope = null, parserFlags = null) {
command = command.slice(1, -1);
}
const result = await executeSlashCommands(command, true, scope, true, parserFlags);
const result = await executeSlashCommands(command, true, scope, false, parserFlags);
if (!result || typeof result !== 'object') {
return '';