preparePromptsForExport method now can exclude the api settings. see #624

This commit is contained in:
mic 2026-02-05 23:24:41 +01:00
parent e105ead516
commit d0fe616e42

View file

@ -410,18 +410,55 @@ export async function getPrompts(onlyEnabled = false, includeSpecial = [], allSp
return output;
}
export function preparePromptsForExport(prompts){
let output = [...prompts];
export function preparePromptsForExport(prompts, include_api_settings = false){
let output = JSON.parse(JSON.stringify(prompts));
output.forEach(prompt => {
if(!include_api_settings){
delete prompt.api_type;
for (const [integration, options] of Object.entries(integration_options_config)) {
for (const key of Object.keys(options)) {
delete prompt[`${integration}_${key}`];
}
}
} else {
if(prompt.api_type && prompt.api_type !== ''){
const activeIntegration = prompt.api_type.replace('_api', '');
for (const [integration, options] of Object.entries(integration_options_config)) {
if(integration !== activeIntegration){
for (const key of Object.keys(options)) {
delete prompt[`${integration}_${key}`];
}
}
}
} else {
for (const [integration, options] of Object.entries(integration_options_config)) {
for (const key of Object.keys(options)) {
delete prompt[`${integration}_${key}`];
}
}
}
}
if(prompt.is_default == 1){
let allowedKeys = ['id', 'enabled', 'position_compose', 'position_display', 'need_custom_text'];
if(include_api_settings){
allowedKeys.push('api_type');
for (const [integration, options] of Object.entries(integration_options_config)) {
for (const key of Object.keys(options)) {
allowedKeys.push(`${integration}_${key}`);
}
}
}
Object.keys(prompt).forEach(key => {
if(!['id', 'enabled', 'position_compose', 'position_display', 'need_custom_text'].includes(key)){
if(!allowedKeys.includes(key)){
delete prompt[key];
}
})
}else{
delete prompt['idnum'];
}
});
return output;
}