Fix support serverSettings

This commit is contained in:
Oleg Korshul
2025-06-09 23:14:04 +03:00
parent 5800f95954
commit 8ed31669dc
6 changed files with 37 additions and 9 deletions

View File

@ -46,7 +46,7 @@
"type" : "background",
"initDataType" : "none",
"buttons" : [],
"events" : ["onContextMenuShow", "onContextMenuClick", "onToolbarMenuClick"],
"events" : ["onAIPluginSettings", "onContextMenuShow", "onContextMenuClick", "onToolbarMenuClick"],
"store": {
"background": {

View File

@ -91,6 +91,16 @@ async function GetOldCustomFunctions() {
}
window.Asc.plugin.init = async function() {
// Check server settings
if (window.Asc.plugin.info.aiPluginSettings) {
try {
AI.serverSettings = JSON.parse(window.Asc.plugin.info.aiPluginSettings);
} catch (e) {
AI.serverSettings = null;
}
delete window.Asc.plugin.info.aiPluginSettings;
}
await initWithTranslate(1 << 1);
clearChatState();

View File

@ -86,7 +86,14 @@
"data" : request.body
})
}
message.url = AI.PROXY_URL;
if (AI.serverSettings){
message.url = AI.serverSettings.proxy;
request["headers"] = {
"Authorization" : "Bearer " + Asc.plugin.info.jwt,
}
} else {
message.url = AI.PROXY_URL;
}
}
}
@ -136,7 +143,7 @@
body[i] = bodyPr[i];
}
return provider.isUseProxy();
return provider.isUseProxy() || AI.serverSettings;
};
AI._getEndpointUrl = function(_provider, endpoint, model) {

View File

@ -58,7 +58,11 @@
AI.Storage.load = function() {
let obj = null;
try {
obj = JSON.parse(window.localStorage.getItem(localStorageKey));
if (AI.serverSettings) {
obj = AI.serverSettings;
} else {
obj = JSON.parse(window.localStorage.getItem(localStorageKey));
}
} catch (e) {
obj = AI.DEFAULT_SERVER_SETTINGS;

View File

@ -244,4 +244,6 @@
};
AI.serverSettings = null;
})();

View File

@ -1,5 +1,8 @@
function registerButtons(window, undefined)
{
window.AI = window.AI || {};
var AI = window.AI;
function getToolBarButtonIcons(icon) {
return "resources/icons/%theme-type%(light|dark)/big/" + icon + "%scale%(default).png";
}
@ -472,7 +475,7 @@ function registerButtons(window, undefined)
window.buttonMainToolbar = buttonMainToolbar;
window.getToolBarButtonIcons = getToolBarButtonIcons;
if (true)
if (!AI.serverSettings)
{
let button1 = new Asc.ButtonToolbar(buttonMainToolbar);
button1.text = "Settings";
@ -548,8 +551,6 @@ function registerButtons(window, undefined)
}
// register actions
window.AI = window.AI || {};
var AI = window.AI;
AI.ActionType = {
Chat : "Chat",
@ -629,7 +630,11 @@ function registerButtons(window, undefined)
let obj = null;
try
{
obj = JSON.parse(window.localStorage.getItem(actions_key));
if (AI.serverSettings) {
obj = AI.serverSettings.actions;
} else {
obj = JSON.parse(window.localStorage.getItem(actions_key));
}
}
catch (e)
{
@ -657,5 +662,5 @@ function registerButtons(window, undefined)
}
};
AI.ActionsLoad();
AI.ActionsLoad();
}