get_task has now the ability to specify a different API. see #498
This commit is contained in:
parent
f5dcebefb2
commit
d975e5c249
3 changed files with 128 additions and 41 deletions
|
|
@ -16,7 +16,7 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
const special_prompts_with_integration = ['add_tags', 'spamfilter', 'summarize', 'get_calendar_event']; //, 'get_task'];
|
||||
const special_prompts_with_integration = ['add_tags', 'spamfilter', 'summarize', 'get_calendar_event', 'get_task'];
|
||||
|
||||
export const integration_options_config = {
|
||||
chatgpt: {
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
<meta charset="UTF-8">
|
||||
<title>ThunderAI - __MSG_GetTask_PageTitle__</title>
|
||||
<link rel="stylesheet" href="mzta-get-task.css">
|
||||
<link rel="stylesheet" href="../_lib/connection-ui.css">
|
||||
<link rel="icon" href="../../images/icon-16px.png">
|
||||
</head>
|
||||
<body>
|
||||
|
|
@ -11,10 +12,20 @@
|
|||
<h1 class="page_title">__MSG_GetTask_PageTitle__</h1>
|
||||
<p>__MSG_GetTask_info_default__</p>
|
||||
</div>
|
||||
<div class="get_calendar_event_table_title section_title">__MSG_get_calendar_event_prompt_prefs_title__</div>
|
||||
<div class="get_task_table_title section_title">__MSG_get_task_prompt_prefs_title__</div>
|
||||
<table id="miczPrefs">
|
||||
<tr class="get_calendar_event_tr">
|
||||
<td><span>__MSG_prefs_OptionText_calendar_enforce_timezone__</span></td>
|
||||
<tr>
|
||||
<td><span class="opt_title">__MSG_prefs_OptionText_use_specific_integration__</span></td>
|
||||
<td>
|
||||
<label>
|
||||
<input type="checkbox" id="get_task_use_specific_integration" name="get_task_use_specific_integration" class="option-input" /> __MSG_prefs_OptionText_get_calendar_event_use_specific_integration_Info__
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="connection_ui_anchor" style="display:none"></tr>
|
||||
<tr id="connection_ui_end" style="display:none"></tr>
|
||||
<tr class="get_task_tr">
|
||||
<td><span class="opt_title">__MSG_prefs_OptionText_calendar_enforce_timezone__</span></td>
|
||||
<td>
|
||||
<label>
|
||||
<input type="checkbox" id="calendar_enforce_timezone" name="calendar_enforce_timezone" class="option-input" /> __MSG_prefs_OptionText_calendar_enforce_timezone_Info__
|
||||
|
|
|
|||
|
|
@ -16,68 +16,108 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { prefs_default } from '../../options/mzta-options-default.js';
|
||||
import {
|
||||
prefs_default,
|
||||
integration_options_config
|
||||
} from '../../options/mzta-options-default.js';
|
||||
import { taLogger } from '../../js/mzta-logger.js';
|
||||
import { getSpecialPrompts, setSpecialPrompts } from "../../js/mzta-prompts.js";
|
||||
import {
|
||||
getSpecialPrompts,
|
||||
setSpecialPrompts
|
||||
} from "../../js/mzta-prompts.js";
|
||||
import {
|
||||
getPlaceholders,
|
||||
mapPlaceholderToSuggestion
|
||||
} from "../../js/mzta-placeholders.js";
|
||||
import { textareaAutocomplete } from "../../js/mzta-placeholders-autocomplete.js";
|
||||
import { isAPIKeyValue } from "../../js/mzta-utils.js";
|
||||
import {
|
||||
isAPIKeyValue,
|
||||
setTomSelectBorder
|
||||
} from "../../js/mzta-utils.js";
|
||||
import {
|
||||
initializeSpecificIntegrationUI
|
||||
} from "../_lib/connection-ui.js";
|
||||
|
||||
let autocompleteSuggestions = [];
|
||||
let taLog = new taLogger("mzta-get-calendar-event-page",true);
|
||||
let taLog = new taLogger("mzta-get-task-page",true);
|
||||
|
||||
document.addEventListener('DOMContentLoaded', async () => {
|
||||
|
||||
let specialPrompts = await getSpecialPrompts();
|
||||
let get_task_prompt = specialPrompts.find(prompt => prompt.id === 'prompt_get_task');
|
||||
|
||||
if (get_task_prompt && get_task_prompt.api_type && get_task_prompt.api_type !== '') {
|
||||
let update_prefs = {};
|
||||
update_prefs['get_task_connection_type'] = get_task_prompt.api_type;
|
||||
|
||||
let integration = get_task_prompt.api_type.replace('_api', '');
|
||||
if (integration_options_config && integration_options_config[integration]) {
|
||||
for (const key of Object.keys(integration_options_config[integration])) {
|
||||
if (get_task_prompt[key] !== undefined) {
|
||||
update_prefs[`get_task_${integration}_${key}`] = get_task_prompt[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
await browser.storage.sync.set(update_prefs);
|
||||
}
|
||||
|
||||
await initializeSpecificIntegrationUI({
|
||||
prefix: 'get_task',
|
||||
promptId: 'prompt_get_task',
|
||||
taLog: taLog,
|
||||
restoreOptionsCallback: restoreOptions
|
||||
});
|
||||
|
||||
i18n.updateDocument();
|
||||
await restoreOptions();
|
||||
|
||||
document.querySelectorAll(".option-input").forEach(element => {
|
||||
element.addEventListener("change", saveOptions);
|
||||
});
|
||||
|
||||
let get_calendar_event_textarea = document.getElementById('get_task_prompt_text');
|
||||
let get_calendar_event_save_btn = document.getElementById('btn_save_prompt');
|
||||
let get_calendar_event_reset_btn = document.getElementById('btn_reset_prompt');
|
||||
let get_task_textarea = document.getElementById('get_task_prompt_text');
|
||||
let get_task_save_btn = document.getElementById('btn_save_prompt');
|
||||
let get_task_reset_btn = document.getElementById('btn_reset_prompt');
|
||||
let get_task_use_specific_integration = document.getElementById('get_task_use_specific_integration');
|
||||
|
||||
let specialPrompts = await getSpecialPrompts();
|
||||
let get_calendar_event_prompt = specialPrompts.find(prompt => prompt.id === 'prompt_get_task');
|
||||
|
||||
get_calendar_event_textarea.addEventListener('input', (event) => {
|
||||
get_calendar_event_reset_btn.disabled = (event.target.value === browser.i18n.getMessage('prompt_get_task_full_text'));
|
||||
get_calendar_event_save_btn.disabled = (event.target.value === get_calendar_event_prompt.text);
|
||||
if(get_calendar_event_save_btn.disabled){
|
||||
get_task_textarea.addEventListener('input', (event) => {
|
||||
get_task_reset_btn.disabled = (event.target.value === browser.i18n.getMessage('prompt_get_task_full_text'));
|
||||
get_task_save_btn.disabled = (event.target.value === get_task_prompt.text);
|
||||
if(get_task_save_btn.disabled){
|
||||
document.getElementById('get_task_prompt_unsaved').classList.add('hidden');
|
||||
} else {
|
||||
document.getElementById('get_task_prompt_unsaved').classList.remove('hidden');
|
||||
}
|
||||
});
|
||||
|
||||
get_calendar_event_reset_btn.addEventListener('click', () => {
|
||||
get_calendar_event_textarea.value = browser.i18n.getMessage('prompt_get_task_full_text');
|
||||
get_calendar_event_reset_btn.disabled = true;
|
||||
let event = new Event('input', { bubbles: true, cancelable: true });
|
||||
get_calendar_event_textarea.dispatchEvent(event);
|
||||
get_task_use_specific_integration.addEventListener('change', (event) => {
|
||||
if (!event.target.checked) {
|
||||
browser.storage.sync.set({ get_task_connection_type: '' });
|
||||
}
|
||||
});
|
||||
|
||||
get_calendar_event_save_btn.addEventListener('click', () => {
|
||||
specialPrompts.find(prompt => prompt.id === 'prompt_get_task').text = get_calendar_event_textarea.value;
|
||||
get_task_reset_btn.addEventListener('click', () => {
|
||||
get_task_textarea.value = browser.i18n.getMessage('prompt_get_task_full_text');
|
||||
get_task_reset_btn.disabled = true;
|
||||
let event = new Event('input', { bubbles: true, cancelable: true });
|
||||
get_task_textarea.dispatchEvent(event);
|
||||
});
|
||||
|
||||
get_task_save_btn.addEventListener('click', () => {
|
||||
specialPrompts.find(prompt => prompt.id === 'prompt_get_task').text = get_task_textarea.value;
|
||||
setSpecialPrompts(specialPrompts);
|
||||
get_calendar_event_save_btn.disabled = true;
|
||||
get_task_save_btn.disabled = true;
|
||||
document.getElementById('get_task_prompt_unsaved').classList.add('hidden');
|
||||
browser.runtime.sendMessage({command: "reload_menus"});
|
||||
});
|
||||
|
||||
if(get_calendar_event_prompt.text === 'prompt_get_task_full_text'){
|
||||
get_calendar_event_prompt.text = browser.i18n.getMessage(get_calendar_event_prompt.text);
|
||||
if(get_task_prompt.text === 'prompt_get_task_full_text'){
|
||||
get_task_prompt.text = browser.i18n.getMessage(get_task_prompt.text);
|
||||
}
|
||||
get_calendar_event_textarea.value = get_calendar_event_prompt.text;
|
||||
get_calendar_event_reset_btn.disabled = (get_calendar_event_textarea.value === browser.i18n.getMessage('prompt_get_task_full_text'));
|
||||
get_task_textarea.value = get_task_prompt.text;
|
||||
get_task_reset_btn.disabled = (get_task_textarea.value === browser.i18n.getMessage('prompt_get_task_full_text'));
|
||||
|
||||
autocompleteSuggestions = (await getPlaceholders(true)).filter(p => !(p.id === 'additional_text')).map(mapPlaceholderToSuggestion);
|
||||
textareaAutocomplete(get_calendar_event_textarea, autocompleteSuggestions, 1); // type_value = 1, only when reading an email
|
||||
textareaAutocomplete(get_task_textarea, autocompleteSuggestions, 1); // type_value = 1, only when reading an email
|
||||
|
||||
});
|
||||
|
||||
|
|
@ -97,8 +137,8 @@ function saveOptions(e) {
|
|||
case 'number':
|
||||
options[element.id] = element.valueAsNumber;
|
||||
break;
|
||||
case 'text':
|
||||
case 'password':
|
||||
case 'text':
|
||||
case 'password':
|
||||
options[element.id] = element.value.trim();
|
||||
break;
|
||||
case 'select-one':
|
||||
|
|
@ -114,6 +154,7 @@ function saveOptions(e) {
|
|||
async function restoreOptions() {
|
||||
function setCurrentChoice(result) {
|
||||
document.querySelectorAll(".option-input").forEach(element => {
|
||||
if(!element.id) return;
|
||||
taLog.log("Options restoring " + element.id + " = " + (isAPIKeyValue(element.id) ? "****************" : result[element.id]));
|
||||
switch (element.type) {
|
||||
case 'checkbox':
|
||||
|
|
@ -131,15 +172,28 @@ async function restoreOptions() {
|
|||
if(element.id == 'default_chatgpt_lang') default_text_value = prefs_default.default_chatgpt_lang;
|
||||
element.value = result[element.id] || default_text_value;
|
||||
break;
|
||||
case 'textarea':
|
||||
break;
|
||||
default:
|
||||
if (element.tagName === 'SELECT') {
|
||||
let default_select_value = '';
|
||||
if(element.id == 'reply_type') default_select_value = 'reply_all';
|
||||
if(element.id == 'connection_type') default_select_value = 'chatgpt_web';
|
||||
element.value = result[element.id] || default_select_value;
|
||||
if (element.value === '') {
|
||||
element.selectedIndex = -1;
|
||||
}
|
||||
let default_select_value = '';
|
||||
const restoreValue = result[element.id] || default_select_value;
|
||||
// Check if option exists
|
||||
let optionExists = Array.from(element.options).some(opt => opt.value === restoreValue);
|
||||
// If it doesn't exist and restoreValue is not empty, create it
|
||||
if (!optionExists && restoreValue !== '') {
|
||||
let newOption = new Option(restoreValue, restoreValue);
|
||||
element.add(newOption);
|
||||
}
|
||||
// Set value
|
||||
element.value = restoreValue;
|
||||
if (element.value === '') {
|
||||
element.selectedIndex = -1;
|
||||
}
|
||||
if (element.tomselect) {
|
||||
element.tomselect.setValue(element.value, true);
|
||||
setTomSelectBorder(element.tomselect);
|
||||
}
|
||||
}else{
|
||||
console.error("[ThunderAI] Unhandled input type:", element.type);
|
||||
}
|
||||
|
|
@ -148,5 +202,27 @@ async function restoreOptions() {
|
|||
}
|
||||
|
||||
let getting = await browser.storage.sync.get(prefs_default);
|
||||
|
||||
let specialPrompts = await getSpecialPrompts();
|
||||
let get_task_prompt = specialPrompts.find(prompt => prompt.id === 'prompt_get_task');
|
||||
|
||||
if (get_task_prompt) {
|
||||
if (get_task_prompt.api_type && get_task_prompt.api_type !== '') {
|
||||
getting['get_task_connection_type'] = get_task_prompt.api_type;
|
||||
} else {
|
||||
getting['get_task_connection_type'] = getting['connection_type'];
|
||||
}
|
||||
for (const [integration, options] of Object.entries(integration_options_config)) {
|
||||
for (const key of Object.keys(options)) {
|
||||
const propName = `${integration}_${key}`;
|
||||
if (get_task_prompt[propName] !== undefined && get_task_prompt[propName] !== '') {
|
||||
getting[`get_task_${propName}`] = get_task_prompt[propName];
|
||||
} else {
|
||||
getting[`get_task_${propName}`] = getting[propName];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setCurrentChoice(getting);
|
||||
}
|
||||
Loading…
Reference in a new issue