all integration settings are saved separately for the special prompts

This commit is contained in:
mic 2025-12-29 12:09:31 +01:00
parent 3ef13eec9b
commit 39a4cab4e2

View file

@ -138,7 +138,7 @@ export async function injectConnectionUI({
<td>
<div class="api_key-container">
<label>
<input type="password" id="chatgpt_api_key" name="chatgpt_api_key" class="option-input"/>
<input type="password" id="${modelId_prefix ? `${modelId_prefix}` : ''}chatgpt_api_key" name="${modelId_prefix ? `${modelId_prefix}` : ''}chatgpt_api_key" class="option-input"/>
</label>
<span class="toggle-icon" id="toggle_chatgpt_api_key"><img src="/images/pwd-show.png" id="pwd-icon_chatgpt_api_key"></span>
</div>
@ -178,7 +178,7 @@ export async function injectConnectionUI({
</td>
<td>
<label>
<input type="checkbox" id="chatgpt_api_store" name="chatgpt_api_store" class="option-input" />
<input type="checkbox" id="${modelId_prefix ? `${modelId_prefix}` : ''}chatgpt_api_store" name="${modelId_prefix ? `${modelId_prefix}` : ''}chatgpt_api_store" class="option-input" />
&nbsp;<span>__MSG_ChatGPT_chatgpt_api_store_info__</span>
</label>
</td>
@ -191,7 +191,7 @@ export async function injectConnectionUI({
</td>
<td>
<label>
<textarea id="chatgpt_developer_messages" name="chatgpt_developer_messages" class="option-input option-textarea"></textarea>
<textarea id="${modelId_prefix ? `${modelId_prefix}` : ''}chatgpt_developer_messages" name="${modelId_prefix ? `${modelId_prefix}` : ''}chatgpt_developer_messages" class="option-input option-textarea"></textarea>
<br>__MSG_ChatGPT_Developer_Messages_Info__
</label>
</td>
@ -203,7 +203,7 @@ export async function injectConnectionUI({
<td>
<div class="api_key-container">
<label>
<input type="password" id="google_gemini_api_key" name="google_gemini_api_key" class="option-input"/>
<input type="password" id="${modelId_prefix ? `${modelId_prefix}` : ''}google_gemini_api_key" name="${modelId_prefix ? `${modelId_prefix}` : ''}google_gemini_api_key" class="option-input"/>
</label>
<span class="toggle-icon" id="toggle_google_gemini_api_key"><img src="/images/pwd-show.png" id="pwd-icon_google_gemini_api_key"></span>
</div>
@ -243,7 +243,7 @@ export async function injectConnectionUI({
</td>
<td>
<label>
<input type="text" id="google_gemini_thinking_budget" name="google_gemini_thinking_budget" class="option-input"/>
<input type="text" id="${modelId_prefix ? `${modelId_prefix}` : ''}google_gemini_thinking_budget" name="${modelId_prefix ? `${modelId_prefix}` : ''}google_gemini_thinking_budget" class="option-input"/>
<br>__MSG_prefs_google_gemini_thinking_budget_Info__
<br><a href="https://ai.google.dev/gemini-api/docs/thinking#set-budget">__MSG_more_info_string__</a>
</label>
@ -257,7 +257,7 @@ export async function injectConnectionUI({
</td>
<td>
<label>
<textarea id="google_gemini_system_instruction" name="google_gemini_system_instruction" class="option-input option-textarea"></textarea>
<textarea id="${modelId_prefix ? `${modelId_prefix}` : ''}google_gemini_system_instruction" name="${modelId_prefix ? `${modelId_prefix}` : ''}google_gemini_system_instruction" class="option-input option-textarea"></textarea>
<br>__MSG_GoogleGemini_SystemInstruction_Info__
</label>
</td>
@ -269,7 +269,7 @@ export async function injectConnectionUI({
</label></td>
<td>
<label>
<input type="text" id="ollama_host" name="ollama_host" class="option-input"/>
<input type="text" id="${modelId_prefix ? `${modelId_prefix}` : ''}ollama_host" name="${modelId_prefix ? `${modelId_prefix}` : ''}ollama_host" class="option-input"/>
</label>
</td>
</tr>
@ -313,7 +313,7 @@ export async function injectConnectionUI({
</label></td>
<td>
<label>
<input type="checkbox" id="ollama_think" name="ollama_think" class="option-input"/>
<input type="checkbox" id="${modelId_prefix ? `${modelId_prefix}` : ''}ollama_think" name="${modelId_prefix ? `${modelId_prefix}` : ''}ollama_think" class="option-input"/>
__MSG_prefs_ollama_think_Info__
</label>
</td>
@ -324,7 +324,7 @@ export async function injectConnectionUI({
</label></td>
<td>
<label>
<input type="number" id="ollama_num_ctx" name="ollama_num_ctx" class="option-input"/>
<input type="number" id="${modelId_prefix ? `${modelId_prefix}` : ''}ollama_num_ctx" name="${modelId_prefix ? `${modelId_prefix}` : ''}ollama_num_ctx" class="option-input"/>
<br>__MSG_prefs_ollama_num_ctx_Info__
</label>
</td>
@ -347,7 +347,7 @@ export async function injectConnectionUI({
</label></td>
<td>
<label>
<input type="text" id="openai_comp_host" name="openai_comp_host" class="option-input" />
<input type="text" id="${modelId_prefix ? `${modelId_prefix}` : ''}openai_comp_host" name="${modelId_prefix ? `${modelId_prefix}` : ''}openai_comp_host" class="option-input" />
<br>__MSG_prefs_OptionText_openai_comp_info_remote__
</label>
</td>
@ -366,7 +366,7 @@ export async function injectConnectionUI({
</label></td>
<td>
<label>
<input type="checkbox" id="openai_comp_use_v1" name="openai_comp_use_v1" class="option-input" />
<input type="checkbox" id="${modelId_prefix ? `${modelId_prefix}` : ''}openai_comp_use_v1" name="${modelId_prefix ? `${modelId_prefix}` : ''}openai_comp_use_v1" class="option-input" />
&nbsp;<span>__MSG_prefs_OptionText_openai_comp_use_v1_info__</span>
</label>
</td>
@ -379,7 +379,7 @@ export async function injectConnectionUI({
<td>
<div class="api_key-container">
<label>
<input type="password" id="openai_comp_api_key" name="openai_comp_api_key" class="option-input"/>
<input type="password" id="${modelId_prefix ? `${modelId_prefix}` : ''}openai_comp_api_key" name="${modelId_prefix ? `${modelId_prefix}` : ''}openai_comp_api_key" class="option-input"/>
</label>
<span class="toggle-icon" id="toggle_openai_comp_api_key"><img src="/images/pwd-show.png" id="pwd-icon_openai_comp_api_key"></span>
</div>
@ -406,7 +406,7 @@ export async function injectConnectionUI({
</label></td>
<td>
<label>
<input type="text" id="openai_comp_chat_name" name="openai_comp_chat_name" class="option-input" />
<input type="text" id="${modelId_prefix ? `${modelId_prefix}` : ''}openai_comp_chat_name" name="${modelId_prefix ? `${modelId_prefix}` : ''}openai_comp_chat_name" class="option-input" />
<br>__MSG_prefs_OpenAIComp_ChatName_Info__
</label>
</td>
@ -431,7 +431,7 @@ export async function injectConnectionUI({
<td>
<div class="api_key-container">
<label>
<input type="password" id="anthropic_api_key" name="anthropic_api_key" class="option-input"/>
<input type="password" id="${modelId_prefix ? `${modelId_prefix}` : ''}anthropic_api_key" name="${modelId_prefix ? `${modelId_prefix}` : ''}anthropic_api_key" class="option-input"/>
</label>
<span class="toggle-icon" id="toggle_anthropic_api_key"><img src="/images/pwd-show.png" id="pwd-icon_anthropic_api_key"></span>
</div>
@ -471,7 +471,7 @@ export async function injectConnectionUI({
</td>
<td>
<label>
<textarea id="anthropic_system_prompt" name="anthropic_system_prompt" class="option-input option-textarea"></textarea>
<textarea id="${modelId_prefix ? `${modelId_prefix}` : ''}anthropic_system_prompt" name="${modelId_prefix ? `${modelId_prefix}` : ''}anthropic_system_prompt" class="option-input option-textarea"></textarea>
<br>__MSG_Anthropic_System_Prompt_Info__
</label>
</td>
@ -484,7 +484,7 @@ export async function injectConnectionUI({
</td>
<td>
<label>
<input type="text" id="anthropic_version" name="anthropic_version" class="option-input" />
<input type="text" id="${modelId_prefix ? `${modelId_prefix}` : ''}anthropic_version" name="${modelId_prefix ? `${modelId_prefix}` : ''}anthropic_version" class="option-input" />
<br>__MSG_Anthropic_Version_Info__ <a href="https://docs.anthropic.com/en/api/versioning">https://docs.anthropic.com/en/api/versioning</a>
</label>
</td>
@ -493,7 +493,7 @@ export async function injectConnectionUI({
<td><span class="opt_title">__MSG_prefs_OptionText_anthropic_max_tokens__</span></td>
<td>
<label>
<input type="number" id="anthropic_max_tokens" name="anthropic_max_tokens" class="option-input" />
<input type="number" id="${modelId_prefix ? `${modelId_prefix}` : ''}anthropic_max_tokens" name="${modelId_prefix ? `${modelId_prefix}` : ''}anthropic_max_tokens" class="option-input" />
<br>__MSG_prefs_OptionText_anthropic_max_tokens_Info__
</label>
</td>
@ -514,6 +514,8 @@ export async function injectConnectionUI({
}
});
const getPrefixedId = (id) => `${modelId_prefix ? `${modelId_prefix}` : ''}${id}`;
// Bindings
// const bindClick = (id, cb) => { const el = document.getElementById(id); if (el && typeof cb === 'function') el.addEventListener('click', cb); };
// const bindChange = (id, cb) => { const el = document.getElementById(id); if (el && typeof cb === 'function') el.addEventListener('change', cb); };
@ -536,15 +538,15 @@ export async function injectConnectionUI({
conntype_select.addEventListener("change", (ev) => warn_Anthropic_VersionEmpty(modelId_prefix));
document.getElementById("chatgpt_web_project").addEventListener("input", validateCustomData_ChatGPTWeb);
document.getElementById("chatgpt_web_custom_gpt").addEventListener("input", validateCustomData_ChatGPTWeb);
document.getElementById("chatgpt_api_key").addEventListener("change", (ev) => warn_ChatGPT_APIKeyEmpty(modelId_prefix));
document.getElementById("ollama_host").addEventListener("change", (ev) => warn_Ollama_HostEmpty(modelId_prefix));
document.getElementById("openai_comp_host").addEventListener("change", (ev) => warn_OpenAIComp_HostEmpty(modelId_prefix));
document.getElementById("google_gemini_api_key").addEventListener("change", (ev) => warn_GoogleGemini_APIKeyEmpty(modelId_prefix));
document.getElementById("anthropic_api_key").addEventListener("change", (ev) => warn_Anthropic_APIKeyEmpty(modelId_prefix));
document.getElementById("anthropic_version").addEventListener("change", (ev) => warn_Anthropic_VersionEmpty(modelId_prefix));
document.getElementById("openai_comp_host").addEventListener("input", resetOpenAICompConfigs);
document.getElementById("openai_comp_chat_name").addEventListener("input", resetOpenAICompConfigs);
document.getElementById("openai_comp_use_v1").addEventListener("input", resetOpenAICompConfigs);
document.getElementById(getPrefixedId("chatgpt_api_key")).addEventListener("change", (ev) => warn_ChatGPT_APIKeyEmpty(modelId_prefix));
document.getElementById(getPrefixedId("ollama_host")).addEventListener("change", (ev) => warn_Ollama_HostEmpty(modelId_prefix));
document.getElementById(getPrefixedId("openai_comp_host")).addEventListener("change", (ev) => warn_OpenAIComp_HostEmpty(modelId_prefix));
document.getElementById(getPrefixedId("google_gemini_api_key")).addEventListener("change", (ev) => warn_GoogleGemini_APIKeyEmpty(modelId_prefix));
document.getElementById(getPrefixedId("anthropic_api_key")).addEventListener("change", (ev) => warn_Anthropic_APIKeyEmpty(modelId_prefix));
document.getElementById(getPrefixedId("anthropic_version")).addEventListener("change", (ev) => warn_Anthropic_VersionEmpty(modelId_prefix));
document.getElementById(getPrefixedId("openai_comp_host")).addEventListener("input", () => resetOpenAICompConfigs(modelId_prefix));
document.getElementById(getPrefixedId("openai_comp_chat_name")).addEventListener("input", () => resetOpenAICompConfigs(modelId_prefix));
document.getElementById(getPrefixedId("openai_comp_use_v1")).addEventListener("input", () => resetOpenAICompConfigs(modelId_prefix));
showConnectionOptions(conntype_select);
loadOpenAICompConfigs();
@ -555,7 +557,7 @@ export async function injectConnectionUI({
warn_Anthropic_APIKeyEmpty(modelId_prefix);
warn_Anthropic_VersionEmpty(modelId_prefix);
const passwordField_chatgpt_api_key = document.getElementById('chatgpt_api_key');
const passwordField_chatgpt_api_key = document.getElementById(getPrefixedId('chatgpt_api_key'));
const toggleIcon_chatgpt_api_key = document.getElementById('toggle_chatgpt_api_key');
const icon_img_chatgpt_api_key = document.getElementById('pwd-icon_chatgpt_api_key');
@ -566,7 +568,7 @@ export async function injectConnectionUI({
icon_img_chatgpt_api_key.src = type === 'password' ? "/images/pwd-show.png" : "/images/pwd-hide.png";
});
const passwordField_google_gemini_api_key = document.getElementById('google_gemini_api_key');
const passwordField_google_gemini_api_key = document.getElementById(getPrefixedId('google_gemini_api_key'));
const toggleIcon_google_gemini_api_key = document.getElementById('toggle_google_gemini_api_key');
const icon_img_google_gemini_api_key = document.getElementById('pwd-icon_google_gemini_api_key');
@ -577,7 +579,7 @@ export async function injectConnectionUI({
icon_img_google_gemini_api_key.src = type === 'password' ? "/images/pwd-show.png" : "/images/pwd-hide.png";
});
const passwordField_openai_comp_api_key = document.getElementById('openai_comp_api_key');
const passwordField_openai_comp_api_key = document.getElementById(getPrefixedId('openai_comp_api_key'));
const toggleIcon_openai_comp_api_key = document.getElementById('toggle_openai_comp_api_key');
const icon_img_openai_comp_api_key = document.getElementById('pwd-icon_openai_comp_api_key');
@ -588,7 +590,7 @@ export async function injectConnectionUI({
icon_img_openai_comp_api_key.src = type === 'password' ? "/images/pwd-show.png" : "/images/pwd-hide.png";
});
const passwordField_anthropic_api_key = document.getElementById('anthropic_api_key');
const passwordField_anthropic_api_key = document.getElementById(getPrefixedId('anthropic_api_key'));
const toggleIcon_anthropic_api_key = document.getElementById('toggle_anthropic_api_key');
const icon_img_anthropic_api_key = document.getElementById('pwd-icon_anthropic_api_key');
@ -632,20 +634,20 @@ export async function injectConnectionUI({
if (!confirm(browser.i18n.getMessage('OpenAIComp_Configs_ConfirmApply', config.name))) {
return;
}
document.getElementById('openai_comp_host').value = config.host || '';
document.getElementById(getPrefixedId('openai_comp_host')).value = config.host || '';
// Clear all options from the select except the first (placeholder) one
const openaiCompModelSelect = getModelEl('openai_comp_model', modelId_prefix);
openaiCompModelSelect.value = '';
while (openaiCompModelSelect.options.length > 0) {
openaiCompModelSelect.remove(0);
}
document.getElementById('openai_comp_use_v1').checked = !!config.use_v1;
document.getElementById('openai_comp_chat_name').value = config.chat_name || '';
document.getElementById(getPrefixedId('openai_comp_use_v1')).checked = !!config.use_v1;
document.getElementById(getPrefixedId('openai_comp_chat_name')).value = config.chat_name || '';
// Trigger change events if needed
document.getElementById('openai_comp_host').dispatchEvent(new Event('change', { bubbles: true }));
document.getElementById(getPrefixedId('openai_comp_host')).dispatchEvent(new Event('change', { bubbles: true }));
getModelEl('openai_comp_model', modelId_prefix).dispatchEvent(new Event('change', { bubbles: true }));
document.getElementById('openai_comp_use_v1').dispatchEvent(new Event('change', { bubbles: true }));
document.getElementById('openai_comp_chat_name').dispatchEvent(new Event('change', { bubbles: true }));
document.getElementById(getPrefixedId('openai_comp_use_v1')).dispatchEvent(new Event('change', { bubbles: true }));
document.getElementById(getPrefixedId('openai_comp_chat_name')).dispatchEvent(new Event('change', { bubbles: true }));
}
});
@ -662,7 +664,7 @@ export async function injectConnectionUI({
document.getElementById('btnUpdateChatGPTModels').addEventListener('click', async () => {
document.getElementById('chatgpt_model_fetch_loading').style.display = 'inline';
let openai = new OpenAI({
apiKey: document.getElementById("chatgpt_api_key").value,
apiKey: document.getElementById(getPrefixedId("chatgpt_api_key")).value,
});
let granted = await messenger.permissions.request({ origins: ["https://*.openai.com/*"] });
if(!granted){
@ -711,7 +713,7 @@ export async function injectConnectionUI({
document.getElementById('btnUpdateGoogleGeminiModels').addEventListener('click', async () => {
document.getElementById('google_gemini_model_fetch_loading').style.display = 'inline';
let google_gemini = new GoogleGemini({
apiKey: document.getElementById("google_gemini_api_key").value,
apiKey: document.getElementById(getPrefixedId("google_gemini_api_key")).value,
});
google_gemini.fetchModels().then((data) => {
if(!data.ok){
@ -753,7 +755,7 @@ export async function injectConnectionUI({
document.getElementById('btnUpdateOllamaModels').addEventListener('click', async () => {
document.getElementById('ollama_model_fetch_loading').style.display = 'inline';
let ollama = new Ollama({
host: document.getElementById("ollama_host").value,
host: document.getElementById(getPrefixedId("ollama_host")).value,
});
try {
let data = await ollama.fetchModels();
@ -812,9 +814,9 @@ export async function injectConnectionUI({
document.getElementById('btnUpdateOpenAICompModels').addEventListener('click', async () => {
document.getElementById('openai_comp_model_fetch_loading').style.display = 'inline';
let openai_comp = new OpenAIComp({
host: document.getElementById("openai_comp_host").value,
apiKey: document.getElementById("openai_comp_api_key").value,
use_v1: document.getElementById("openai_comp_use_v1").checked,
host: document.getElementById(getPrefixedId("openai_comp_host")).value,
apiKey: document.getElementById(getPrefixedId("openai_comp_api_key")).value,
use_v1: document.getElementById(getPrefixedId("openai_comp_use_v1")).checked,
});
openai_comp.fetchModels().then((data) => {
if(!data.ok){
@ -857,8 +859,8 @@ export async function injectConnectionUI({
document.getElementById('btnUpdateAnthropicModels').addEventListener('click', async () => {
document.getElementById('anthropic_model_fetch_loading').style.display = 'inline';
let anthropic = new Anthropic({
apiKey: document.getElementById("anthropic_api_key").value,
version: document.getElementById("anthropic_version").value,
apiKey: document.getElementById(getPrefixedId("anthropic_api_key")).value,
version: document.getElementById(getPrefixedId("anthropic_version")).value,
});
let granted = await messenger.permissions.request({ origins: ["https://*.anthropic.com/*"] });
if(!granted){
@ -1164,7 +1166,8 @@ function populateConnectionTypeOptions(selectId, no_chatgpt_web = false) {
}
function warn_ChatGPT_APIKeyEmpty(modelId_prefix) {
let apiKeyInput = document.getElementById('chatgpt_api_key');
const getPrefixedId = (id) => `${modelId_prefix ? `${modelId_prefix}` : ''}${id}`;
let apiKeyInput = document.getElementById(getPrefixedId('chatgpt_api_key'));
let btnFetchChatGPTModels = document.getElementById('btnUpdateChatGPTModels');
let modelChatGPT = getModelEl('chatgpt_model', modelId_prefix);
if(apiKeyInput.value === ''){
@ -1186,7 +1189,8 @@ function warn_ChatGPT_APIKeyEmpty(modelId_prefix) {
}
function warn_GoogleGemini_APIKeyEmpty(modelId_prefix) {
let apiKeyInput = document.getElementById('google_gemini_api_key');
const getPrefixedId = (id) => `${modelId_prefix ? `${modelId_prefix}` : ''}${id}`;
let apiKeyInput = document.getElementById(getPrefixedId('google_gemini_api_key'));
let btnFetchGoogleGeminiModels = document.getElementById('btnUpdateGoogleGeminiModels');
let modelGoogleGemini = getModelEl('google_gemini_model', modelId_prefix);
if(apiKeyInput.value === ''){
@ -1208,7 +1212,8 @@ function warn_GoogleGemini_APIKeyEmpty(modelId_prefix) {
}
function warn_Ollama_HostEmpty(modelId_prefix) {
let hostInput = document.getElementById('ollama_host');
const getPrefixedId = (id) => `${modelId_prefix ? `${modelId_prefix}` : ''}${id}`;
let hostInput = document.getElementById(getPrefixedId('ollama_host'));
let btnFetchOllamaModels = document.getElementById('btnUpdateOllamaModels');
let modelOllama = getModelEl('ollama_model', modelId_prefix);
if(hostInput.value === ''){
@ -1230,7 +1235,8 @@ function warn_Ollama_HostEmpty(modelId_prefix) {
}
function warn_OpenAIComp_HostEmpty(modelId_prefix) {
let hostInput = document.getElementById('openai_comp_host');
const getPrefixedId = (id) => `${modelId_prefix ? `${modelId_prefix}` : ''}${id}`;
let hostInput = document.getElementById(getPrefixedId('openai_comp_host'));
let btnUpdateOpenAICompModels = document.getElementById('btnUpdateOpenAICompModels');
let modelOpenAIComp = getModelEl('openai_comp_model', modelId_prefix);
if(hostInput.value === ''){
@ -1252,7 +1258,8 @@ function warn_OpenAIComp_HostEmpty(modelId_prefix) {
}
function warn_Anthropic_APIKeyEmpty(modelId_prefix) {
let apiKeyInput = document.getElementById('anthropic_api_key');
const getPrefixedId = (id) => `${modelId_prefix ? `${modelId_prefix}` : ''}${id}`;
let apiKeyInput = document.getElementById(getPrefixedId('anthropic_api_key'));
let btnFetchAnthropicModels = document.getElementById('btnUpdateAnthropicModels');
let modelAnthropic = getModelEl('anthropic_model', modelId_prefix);
if(apiKeyInput.value === ''){
@ -1274,7 +1281,8 @@ function warn_Anthropic_APIKeyEmpty(modelId_prefix) {
}
function warn_Anthropic_VersionEmpty(modelId_prefix) {
let versionInput = document.getElementById('anthropic_version');
const getPrefixedId = (id) => `${modelId_prefix ? `${modelId_prefix}` : ''}${id}`;
let versionInput = document.getElementById(getPrefixedId('anthropic_version'));
let btnFetchAnthropicModels = document.getElementById('btnUpdateAnthropicModels');
let modelAnthropic = getModelEl('anthropic_model', modelId_prefix);
if(versionInput.value === ''){