Merge pull request 'feature/reset-ai-config' (#35) from feature/reset-ai-config into release/v9.0.0

Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/server/pulls/35
This commit is contained in:
Oleg Korshul
2025-06-11 01:58:24 +00:00
3 changed files with 116 additions and 2 deletions

View File

@ -6,7 +6,7 @@
"pluginDir" : "/var/www/onlyoffice/documentserver/server/info/ai"
},
"runtimeConfig": {
"filePath": "/var/www/onlyoffice/documentserver/../Data/runtime.json"
"filePath": "/etc/onlyoffice/documentserver/runtime.json"
},
"storage": {
"fs": {

View File

@ -13,6 +13,8 @@ const AIIntegration = {
// Callback functions
onSave: null,
onOk: null,
onResetActions: null,
onResetAllSettings: null,
// Initialize the AI integration
init() {
@ -44,6 +46,8 @@ const AIIntegration = {
<div class="ai-controls" id="ai-controls">
<button class="ai-btn" id="ai-btn-back" style="display: none;">Back</button>
<button class="ai-btn" id="ai-btn-cancel" style="display: none;">Cancel</button>
<button class="ai-btn" id="ai-btn-reset-all-settings" style="display: none;">Reset All Settings</button>
<button class="ai-btn" id="ai-btn-reset-actions" style="display: none;">Reset Tasks</button>
<button class="ai-btn primary" id="ai-btn-save" style="display: none;">Save</button>
<button class="ai-btn primary" id="ai-btn-ok" style="display: none;">OK</button>
</div>
@ -60,6 +64,8 @@ const AIIntegration = {
const btnCancel = document.getElementById('ai-btn-cancel');
const btnSave = document.getElementById('ai-btn-save');
const btnOk = document.getElementById('ai-btn-ok');
const btnResetActions = document.getElementById('ai-btn-reset-actions');
const btnResetAllSettings = document.getElementById('ai-btn-reset-all-settings');
const iframeSettings = document.getElementById('ai-iframe-settings');
const iframeEdit = document.getElementById('ai-iframe-edit');
const iframeList = document.getElementById('ai-iframe-list');
@ -83,6 +89,14 @@ const AIIntegration = {
if (btnOk) {
btnOk.addEventListener('click', () => this.ok());
}
if (btnResetActions) {
btnResetActions.addEventListener('click', () => this.resetActions());
}
if (btnResetAllSettings) {
btnResetAllSettings.addEventListener('click', () => this.resetAllSettings());
}
if (iframeSettings) {
iframeSettings.addEventListener('load', () => this.onIframeLoad());
@ -164,9 +178,11 @@ const AIIntegration = {
const btnCancel = document.getElementById('ai-btn-cancel');
const btnSave = document.getElementById('ai-btn-save');
const btnOk = document.getElementById('ai-btn-ok');
const btnResetActions = document.getElementById('ai-btn-reset-actions');
const btnResetAllSettings = document.getElementById('ai-btn-reset-all-settings');
// Hide all buttons first
[btnBack, btnCancel, btnSave, btnOk].forEach(btn => {
[btnBack, btnCancel, btnSave, btnOk, btnResetActions, btnResetAllSettings].forEach(btn => {
if (btn) btn.style.display = 'none';
});
@ -174,6 +190,8 @@ const AIIntegration = {
switch (this.currentView) {
case 'settings':
if (btnSave) btnSave.style.display = 'inline-block';
if (btnResetActions) btnResetActions.style.display = 'inline-block';
if (btnResetAllSettings) btnResetAllSettings.style.display = 'inline-block';
break;
case 'aiModelEdit':
if (btnOk) btnOk.style.display = 'inline-block';
@ -245,6 +263,40 @@ const AIIntegration = {
cancel() {
this.navigateToView('aiModelsList');
},
resetActions() {
if (this.onResetActions) {
this.onResetActions().then((res) => {
const btnResetActions = document.getElementById('ai-btn-reset-actions');
if (btnResetActions) {
const originalText = btnResetActions.textContent;
btnResetActions.textContent = res ? 'Actions Reset!' : 'Reset Failed!';
btnResetActions.disabled = true;
setTimeout(() => {
btnResetActions.textContent = originalText;
btnResetActions.disabled = false;
}, 2000);
}
});
}
},
resetAllSettings() {
if (this.onResetAllSettings) {
this.onResetAllSettings().then((res) => {
const btnResetAllSettings = document.getElementById('ai-btn-reset-all-settings');
if (btnResetAllSettings) {
const originalText = btnResetAllSettings.textContent;
btnResetAllSettings.textContent = res ? 'Settings Reset!' : 'Reset Failed!';
btnResetAllSettings.disabled = true;
setTimeout(() => {
btnResetAllSettings.textContent = originalText;
btnResetAllSettings.disabled = false;
}, 2000);
}
});
}
}
};

View File

@ -61,6 +61,68 @@
return false;
});
};
AIIntegration.onResetActions = function() {
try {
if (settings && settings.actions) {
for (let id in settings.actions) {
if (settings.actions[id]) {
settings.actions[id].model = "";
}
}
}
var settingsWindow = findIframeBySrcPart('settings');
if (settingsWindow && settingsWindow.contentWindow) {
updateActions(settingsWindow.contentWindow);
}
updateModels();
return AIIntegration.onSave();
} catch (error) {
console.error('Reset actions error:', error);
}
return Promise.resolve(false);
};
AIIntegration.onResetAllSettings = function() {
try {
if (settings) {
// Reset actions models
if (settings.actions) {
for (let id in settings.actions) {
if (settings.actions[id]) {
settings.actions[id].model = "";
}
}
}
// Reset models array
settings.models = [];
// Reset custom providers
settings.customProviders = {};
// Reset providers
if (settings.providers) {
for (let id in settings.providers) {
if (settings.providers[id]) {
settings.providers[id].key = "";
settings.providers[id].models = [];
}
}
}
// Update UI
var settingsWindow = findIframeBySrcPart('settings');
if (settingsWindow && settingsWindow.contentWindow) {
updateActions(settingsWindow.contentWindow);
}
updateModels();
return AIIntegration.onSave();
}
} catch (error) {
console.error('Reset all settings error:', error);
}
return Promise.resolve(false);
};
AIIntegration.onOk = function() {
var aiModelEditWindow = findIframeBySrcPart('aiModelEdit');
if(aiModelEditWindow) {