mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-02-23 19:04:10 +01:00
💽 fix: Memory Permissions Handling (#9701)
This commit is contained in:
parent
81139046e5
commit
3fec63e597
2 changed files with 164 additions and 15 deletions
|
|
@ -69,8 +69,12 @@ export async function updateInterfacePermissions({
|
|||
const interfaceConfig = appConfig?.config?.interface;
|
||||
const memoryConfig = appConfig?.config?.memory;
|
||||
const memoryEnabled = isMemoryEnabled(memoryConfig);
|
||||
/** Check if memory is explicitly disabled */
|
||||
const isMemoryExplicitlyDisabled = memoryConfig && !memoryEnabled;
|
||||
/** Check if memory is explicitly disabled (memory.disabled === true) */
|
||||
const isMemoryExplicitlyDisabled = memoryConfig?.disabled === true;
|
||||
/** Check if memory should be enabled (explicitly enabled or valid config) */
|
||||
const shouldEnableMemory =
|
||||
memoryConfig?.disabled === false ||
|
||||
(memoryConfig && memoryEnabled && memoryConfig.disabled === undefined);
|
||||
/** Check if personalization is enabled (defaults to true if memory is configured and enabled) */
|
||||
const isPersonalizationEnabled =
|
||||
memoryConfig && memoryEnabled && memoryConfig.personalize !== false;
|
||||
|
|
@ -111,19 +115,24 @@ export async function updateInterfacePermissions({
|
|||
const permTypeExists = existingPermissions?.[permType];
|
||||
const isExplicitlyConfigured =
|
||||
interfaceConfig && hasExplicitConfig(interfaceConfig, permType);
|
||||
const isMemoryDisabled =
|
||||
permType === PermissionTypes.MEMORIES && isMemoryExplicitlyDisabled === true;
|
||||
const isMemoryDisabled = permType === PermissionTypes.MEMORIES && isMemoryExplicitlyDisabled;
|
||||
const isMemoryReenabling =
|
||||
permType === PermissionTypes.MEMORIES &&
|
||||
shouldEnableMemory &&
|
||||
existingPermissions?.[PermissionTypes.MEMORIES]?.[Permissions.USE] === false;
|
||||
|
||||
// Only update if: doesn't exist OR explicitly configured
|
||||
if (!permTypeExists || isExplicitlyConfigured || isMemoryDisabled) {
|
||||
// Only update if: doesn't exist OR explicitly configured OR memory state change
|
||||
if (!permTypeExists || isExplicitlyConfigured || isMemoryDisabled || isMemoryReenabling) {
|
||||
permissionsToUpdate[permType] = permissions;
|
||||
if (!permTypeExists) {
|
||||
logger.debug(`Role '${roleName}': Setting up default permissions for '${permType}'`);
|
||||
} else if (isExplicitlyConfigured) {
|
||||
logger.debug(`Role '${roleName}': Applying explicit config for '${permType}'`);
|
||||
} else if (isMemoryDisabled) {
|
||||
logger.debug(`Role '${roleName}': Disabling memories as memory.disabled is true`);
|
||||
} else if (isMemoryReenabling) {
|
||||
logger.debug(
|
||||
`Role '${roleName}': Disabling memories as it is explicitly disabled in config`,
|
||||
`Role '${roleName}': Re-enabling memories due to valid memory configuration`,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
|
|
@ -147,13 +156,15 @@ export async function updateInterfacePermissions({
|
|||
),
|
||||
},
|
||||
[PermissionTypes.MEMORIES]: {
|
||||
[Permissions.USE]: isMemoryExplicitlyDisabled
|
||||
? false
|
||||
: getPermissionValue(
|
||||
loadedInterface.memories,
|
||||
defaultPerms[PermissionTypes.MEMORIES]?.[Permissions.USE],
|
||||
defaults.memories,
|
||||
),
|
||||
[Permissions.USE]: (() => {
|
||||
if (isMemoryExplicitlyDisabled) return false;
|
||||
if (shouldEnableMemory) return true;
|
||||
return getPermissionValue(
|
||||
loadedInterface.memories,
|
||||
defaultPerms[PermissionTypes.MEMORIES]?.[Permissions.USE],
|
||||
defaults.memories,
|
||||
);
|
||||
})(),
|
||||
...(defaultPerms[PermissionTypes.MEMORIES]?.[Permissions.CREATE] !== undefined && {
|
||||
[Permissions.CREATE]: isMemoryExplicitlyDisabled
|
||||
? false
|
||||
|
|
@ -169,7 +180,9 @@ export async function updateInterfacePermissions({
|
|||
? false
|
||||
: defaultPerms[PermissionTypes.MEMORIES][Permissions.UPDATE],
|
||||
}),
|
||||
[Permissions.OPT_OUT]: isPersonalizationEnabled,
|
||||
[Permissions.OPT_OUT]: isMemoryExplicitlyDisabled
|
||||
? false
|
||||
: isPersonalizationEnabled || undefined,
|
||||
},
|
||||
[PermissionTypes.MULTI_CONVO]: {
|
||||
[Permissions.USE]: getPermissionValue(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue