mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-18 01:10:14 +01:00
feat: enhance agent permissions migration with DocumentDB compatibility and add dry-run script
This commit is contained in:
parent
c62a23fafc
commit
f9994d1547
2 changed files with 23 additions and 16 deletions
|
|
@ -32,32 +32,36 @@ async function migrateAgentPermissionsEnhanced({ dryRun = true, batchSize = 100
|
||||||
|
|
||||||
logger.info(`Found ${globalAgentIds.size} agents in global project`);
|
logger.info(`Found ${globalAgentIds.size} agents in global project`);
|
||||||
|
|
||||||
// Find agents without ACL entries
|
// Find agents without ACL entries using DocumentDB-compatible approach
|
||||||
const agentsToMigrate = await Agent.aggregate([
|
const agentsToMigrate = await Agent.aggregate([
|
||||||
{
|
{
|
||||||
$lookup: {
|
$lookup: {
|
||||||
from: 'aclentries',
|
from: 'aclentries',
|
||||||
let: { agentId: '$_id' },
|
localField: '_id',
|
||||||
pipeline: [
|
foreignField: 'resourceId',
|
||||||
{
|
as: 'aclEntries',
|
||||||
$match: {
|
},
|
||||||
$expr: {
|
},
|
||||||
$and: [
|
{
|
||||||
{ $eq: ['$resourceType', 'agent'] },
|
$addFields: {
|
||||||
{ $eq: ['$resourceId', '$$agentId'] },
|
userAclEntries: {
|
||||||
{ $eq: ['$principalType', 'user'] },
|
$filter: {
|
||||||
],
|
input: '$aclEntries',
|
||||||
},
|
as: 'aclEntry',
|
||||||
|
cond: {
|
||||||
|
$and: [
|
||||||
|
{ $eq: ['$$aclEntry.resourceType', 'agent'] },
|
||||||
|
{ $eq: ['$$aclEntry.principalType', 'user'] },
|
||||||
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
as: 'aclEntries',
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
$match: {
|
$match: {
|
||||||
author: { $exists: true, $ne: null },
|
author: { $exists: true, $ne: null },
|
||||||
$expr: { $eq: [{ $size: '$aclEntries' }, 0] },
|
userAclEntries: { $size: 0 },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,10 @@
|
||||||
"b:test:api": "cd api && bun run b:test",
|
"b:test:api": "cd api && bun run b:test",
|
||||||
"b:balance": "bun config/add-balance.js",
|
"b:balance": "bun config/add-balance.js",
|
||||||
"b:list-balances": "bun config/list-balances.js",
|
"b:list-balances": "bun config/list-balances.js",
|
||||||
"reset-terms": "node config/reset-terms.js"
|
"reset-terms": "node config/reset-terms.js",
|
||||||
|
"migrate:agent-permissions:dry-run": "node config/migrate-agent-permissions.js --dry-run",
|
||||||
|
"migrate:agent-permissions": "node config/migrate-agent-permissions.js",
|
||||||
|
"migrate:agent-permissions:batch": "node config/migrate-agent-permissions.js --batch-size=50"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue