Add CORS warning messages and permission request buttons for OpenAI and Ollama APIs. see #330 and #331

This commit is contained in:
mic 2025-04-08 22:22:50 +02:00
parent c27d28829a
commit d7f420dd17
3 changed files with 51 additions and 0 deletions

View file

@ -1250,5 +1250,25 @@
"hyprland_warning": {
"message": "If you're having trouble opening the AI chat window, try setting the height and width values to 0. This issue can occur on linux in certain environments, for example, when using Hyprland.",
"description": ""
},
"remember_CORS": {
"message": "Remember, you need to set up the CORS settings!",
"description": ""
},
"maybe_CORS_openai_comp": {
"message": "Using OpenAI Compatible API may require setting up CORS settings.",
"description": ""
},
"CORS_alternative_1": {
"message": "Problems setting CORS?",
"description": ""
},
"CORS_alternative_2": {
"message": "Press the button below to give the <all_urls> permission to avoid any CORS problem.",
"description": ""
},
"CORS_give_allurls_perm": {
"message": "Give \"all URLs\" permission",
"description": ""
}
}

View file

@ -242,6 +242,14 @@
</label>
</td>
</tr>
<tr class="conntype_ollama_api" id="ollama_api_cors_warning">
<td colspan="2" style="text-align:center;">
__MSG_remember_CORS__ [<a href="https://micz.it/thunderbird-addon-thunderai/ollama-cors-information/">__MSG_customPrompts_managePrompts_help__</a>]
<br><br><b>__MSG_CORS_alternative_1__</b>
<br>__MSG_CORS_alternative_2__
<br><br><button id="btnGiveAllUrlsPermission_ollama_api">__MSG_CORS_give_allurls_perm__</button>
</td>
</tr>
<tr class="conntype_ollama_api">
<td>
<label>
@ -268,6 +276,14 @@
</label>
</td>
</tr>
<tr class="conntype_openai_comp_api" id="openai_comp_api_cors_warning">
<td colspan="2" style="text-align:center;">
__MSG_maybe_CORS_openai_comp__ [<a href="https://micz.it/thunderbird-addon-thunderai/ollama-cors-information/">__MSG_customPrompts_managePrompts_help__</a>]
<br><br><b>__MSG_CORS_alternative_1__</b>
<br>__MSG_CORS_alternative_2__
<br><br><button id="btnGiveAllUrlsPermission_openai_comp_api">__MSG_CORS_give_allurls_perm__</button>
</td>
</tr>
<tr class="conntype_openai_comp_api">
<td><label>
<span>__MSG_prefs_OptionText_openai_comp_use_v1__</span>

View file

@ -26,6 +26,7 @@ import { checkSparksPresence, isThunderbird128OrGreater } from '../js/mzta-utils
let taLog = new taLogger("mzta-options",true);
let _isThunderbird128OrGreater = true;
let permission_all_urls = false;
function saveOptions(e) {
e.preventDefault();
@ -155,6 +156,10 @@ function showConnectionOptions() {
document.querySelectorAll(".conntype_google_gemini_api").forEach(element => {
element.style.display = google_gemini_api_display;
});
if (permission_all_urls) {
document.getElementById('openai_comp_api_cors_warning').style.display = 'none';
document.getElementById('ollama_api_cors_warning').style.display = 'none';
}
}
function warn_ChatGPT_APIKeyEmpty() {
@ -307,6 +312,8 @@ async function disable_GetCalendarEvent(){
document.addEventListener('DOMContentLoaded', async () => {
await restoreOptions();
permission_all_urls = await messenger.permissions.contains({ origins: ["<all_urls>"] })
_isThunderbird128OrGreater = await isThunderbird128OrGreater();
// show Owl warning
@ -441,6 +448,14 @@ document.addEventListener('DOMContentLoaded', async () => {
}
});
document.getElementById('btnGiveAllUrlsPermission_ollama_api').addEventListener('click', async () => {
permission_all_urls = await messenger.permissions.request({ origins: ["<all_urls>"] });
});
document.getElementById('btnGiveAllUrlsPermission_openai_comp_api').addEventListener('click', async () => {
permission_all_urls = await messenger.permissions.request({ origins: ["<all_urls>"] });
});
let conntype_select = document.getElementById("connection_type");
conntype_select.addEventListener("change", showConnectionOptions);
conntype_select.addEventListener("change", warn_ChatGPT_APIKeyEmpty);