mirror of
https://github.com/ONLYOFFICE/server.git
synced 2026-04-07 14:04:35 +08:00
[feature]Fix local.json replace; Change aiSettings.actions type
This commit is contained in:
@ -3483,13 +3483,6 @@ exports.install = function(server, callbackFunction) {
|
||||
|
||||
let [licenseInfo] = yield tenantManager.getTenantLicense(ctx);
|
||||
let pluginSettings = yield aiProxyHandler.getPluginSettings(ctx);
|
||||
if (pluginSettings.actions) {
|
||||
const tmp = pluginSettings.actions;
|
||||
pluginSettings.actions = {};
|
||||
for (let i = 0; i < tmp.length; i++) {
|
||||
pluginSettings.actions[tmp[i].id] = tmp[i];
|
||||
}
|
||||
}
|
||||
sendData(ctx, conn, {
|
||||
type: 'license',
|
||||
license: {
|
||||
@ -3987,6 +3980,8 @@ exports.install = function(server, callbackFunction) {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
void aiProxyHandler.getPluginSettings(operationContext.global);
|
||||
};
|
||||
exports.setLicenseInfo = async function(globalCtx, data, original) {
|
||||
tenantManager.setDefLicense(data, original);
|
||||
|
||||
@ -155,10 +155,10 @@ function loadInternalProviders() {
|
||||
*/
|
||||
function fillConfigObjects() {
|
||||
AI.Models = cfgAiApiModels;
|
||||
for(let i = 0; i < cfgAiApiActions.length; i++)
|
||||
{
|
||||
if (cfgAiApiActions[i].model && AI.Actions[cfgAiApiActions[i].id]) {
|
||||
AI.Actions[cfgAiApiActions[i].id].model = cfgAiApiActions[i].model;
|
||||
for(let id in cfgAiApiActions) {
|
||||
let action = cfgAiApiActions[id];
|
||||
if (action.model && AI.Actions[id]) {
|
||||
AI.Actions[id].model = action.model;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -282,43 +282,23 @@ async function getPluginSettings(ctx) {
|
||||
const aiApi = config.get('aiSettings');
|
||||
// Process providers and their models if configuration exists
|
||||
if (aiApi?.providers && typeof aiApi.providers === 'object') {
|
||||
// Create an array of promises for each provider
|
||||
// const providerPromises = aiApi.providers
|
||||
// .filter(provider => provider.enable !== false || !provider.key || !provider.url)
|
||||
// .map(provider => processProvider(ctx, provider));
|
||||
|
||||
// try {
|
||||
// let providers = await Promise.allSettled(providerPromises);
|
||||
// // providers = providers.filter(provider => provider.status === 'fulfilled' && provider.value && provider.value.name && provider.value.models?.length > 0);
|
||||
// providers = providers.filter(provider => provider.status === 'fulfilled' && provider.value && provider.value.name);
|
||||
|
||||
// const providerCount = providers.length;
|
||||
// let totalModels = 0;
|
||||
// // Convert providers array to object by provider name
|
||||
// result.providers = {};
|
||||
// for(let i = 0; i < providers.length; i++) {
|
||||
// const provider = providers[i].value;
|
||||
// totalModels += provider.models.length;
|
||||
// // result.models.push(...provider.modelsUI);
|
||||
// delete provider.modelsUI;//todo remove
|
||||
// //result.providers[provider.name] = provider;
|
||||
// }
|
||||
|
||||
// logger.info(`Successfully processed ${providerCount} providers with a total of ${totalModels} models`);
|
||||
// } catch (error) {
|
||||
// logger.error('Error resolving provider promises:', error);
|
||||
// }
|
||||
if (true) {
|
||||
const providers = AI.serializeProviders();
|
||||
for (let i = 0; i < providers.length; i++) {
|
||||
const provider = providers[i];
|
||||
const cfgProvider = aiApi.providers[provider.name];
|
||||
if (cfgProvider) {
|
||||
//todo clone
|
||||
provider.key = cfgProvider.key;
|
||||
}
|
||||
result.providers[provider.name] = provider;
|
||||
const providers = AI.serializeProviders();
|
||||
for (let i = 0; i < providers.length; i++) {
|
||||
const provider = providers[i];
|
||||
const cfgProvider = aiApi.providers[provider.name];
|
||||
if (cfgProvider) {
|
||||
//todo clone
|
||||
provider.key = cfgProvider.key;
|
||||
}
|
||||
|
||||
try {
|
||||
const providerProcessed = await processProvider(ctx, provider);
|
||||
provider.models.push(...providerProcessed.models);
|
||||
} catch (error) {
|
||||
logger.warn('Error processing provider:', error);
|
||||
}
|
||||
|
||||
result.providers[provider.name] = provider;
|
||||
}
|
||||
}
|
||||
// Process AI actions
|
||||
@ -330,10 +310,15 @@ async function getPluginSettings(ctx) {
|
||||
// Process AI actions
|
||||
if (aiApi?.actions && typeof aiApi.actions === 'object') {
|
||||
// result.actions = aiApi.actions;
|
||||
result.actions = AI.ActionsGetSorted();
|
||||
const actionSoted = AI.ActionsGetSorted();
|
||||
result.actions = {};
|
||||
for (let i = 0; i < actionSoted.length; i++) {
|
||||
const action = actionSoted[i];
|
||||
result.actions[action.id] = action;
|
||||
}
|
||||
}
|
||||
result.version = aiApi.version;
|
||||
// nodeCache.set(ctx.tenant, result);
|
||||
nodeCache.set(ctx.tenant, result);
|
||||
} catch (error) {
|
||||
logger.error('Error retrieving AI models from config:', error);
|
||||
}
|
||||
|
||||
@ -92,9 +92,13 @@ router.post('/', rawFileParser, async (req, res) => {
|
||||
ctx.logger.debug('Configuration backup not found: %s', backupError.stack);
|
||||
}
|
||||
if(!sampleFileStat){
|
||||
await cp(configPath, backupPath, {force: true, recursive: true});
|
||||
}
|
||||
try {
|
||||
const oldConfig = JSON.parse(await readFile(configPath, {encoding: 'utf8'}));
|
||||
newConfig = {...oldConfig, ...newConfig};
|
||||
await cp(configPath, backupPath, {force: true, recursive: true});
|
||||
} catch (error) {
|
||||
ctx.logger.debug('Configuration local.json not found: %s', error.stack);
|
||||
}
|
||||
const prettyConfig = JSON.stringify(newConfig, null, 2);
|
||||
await writeFile(configPath, prettyConfig, {encoding: 'utf8'});
|
||||
|
||||
@ -166,10 +166,8 @@
|
||||
}, event.source);
|
||||
break;
|
||||
case 'onChangeAction':
|
||||
for (let id in settings.actions) {
|
||||
if (settings.actions[id].id == message.data.id) {
|
||||
settings.actions[id].model = message.data.model;
|
||||
}
|
||||
if (settings.actions[message.data.id]) {
|
||||
settings.actions[message.data.id].model = message.data.model;
|
||||
}
|
||||
break;
|
||||
case 'onOpenEditModal':
|
||||
|
||||
Reference in New Issue
Block a user