@librechat/data-schemas 0.0.35 → 0.0.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +325 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.es.js +326 -16
- package/dist/index.es.js.map +1 -1
- package/dist/types/methods/agentApiKey.d.ts +39 -0
- package/dist/types/methods/file.d.ts +8 -0
- package/dist/types/methods/index.d.ts +3 -2
- package/dist/types/models/agentApiKey.d.ts +27 -0
- package/dist/types/models/index.d.ts +1 -0
- package/dist/types/schema/agentApiKey.d.ts +38 -0
- package/dist/types/schema/defaults.d.ts +3 -0
- package/dist/types/schema/index.d.ts +1 -0
- package/dist/types/schema/preset.d.ts +1 -0
- package/dist/types/types/agent.d.ts +3 -1
- package/dist/types/types/agentApiKey.d.ts +65 -0
- package/dist/types/types/convo.d.ts +1 -0
- package/dist/types/types/file.d.ts +1 -0
- package/dist/types/types/index.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.es.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EModelEndpoint, agentsEndpointSchema, memorySchema, removeNullishValues, SafeSearchTypes, normalizeEndpointName, defaultAssistantsVersion, Capabilities, assistantEndpointSchema, validateAzureGroups, mapModelToAzureConfig, extractEnvVariable, envVarRegex, OCRStrategy, getConfigDefaults, PermissionBits, FileSources, Constants, PermissionTypes, Permissions, SystemRoles, parseTextParts, ResourceType, PrincipalType, PrincipalModel, roleDefaults, ErrorTypes, EToolResources,
|
|
1
|
+
import { EModelEndpoint, agentsEndpointSchema, memorySchema, removeNullishValues, SafeSearchTypes, normalizeEndpointName, defaultAssistantsVersion, Capabilities, assistantEndpointSchema, validateAzureGroups, mapModelToAzureConfig, extractEnvVariable, envVarRegex, OCRStrategy, getConfigDefaults, PermissionBits, FileSources, FileContext, Constants, PermissionTypes, Permissions, SystemRoles, parseTextParts, ResourceType, PrincipalType, PrincipalModel, roleDefaults, ErrorTypes, EToolResources, AccessRoleIds } from 'librechat-data-provider';
|
|
2
2
|
import winston from 'winston';
|
|
3
3
|
import 'winston-daily-rotate-file';
|
|
4
4
|
import { klona } from 'klona';
|
|
@@ -1460,12 +1460,57 @@ const agentSchema = new Schema({
|
|
|
1460
1460
|
default: [],
|
|
1461
1461
|
index: true,
|
|
1462
1462
|
},
|
|
1463
|
+
/** Per-tool configuration (defer_loading, allowed_callers) */
|
|
1464
|
+
tool_options: {
|
|
1465
|
+
type: Schema.Types.Mixed,
|
|
1466
|
+
default: undefined,
|
|
1467
|
+
},
|
|
1463
1468
|
}, {
|
|
1464
1469
|
timestamps: true,
|
|
1465
1470
|
});
|
|
1466
1471
|
agentSchema.index({ updatedAt: -1, _id: 1 });
|
|
1467
1472
|
agentSchema.index({ 'edges.to': 1 });
|
|
1468
1473
|
|
|
1474
|
+
const agentApiKeySchema = new Schema({
|
|
1475
|
+
userId: {
|
|
1476
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
1477
|
+
ref: 'User',
|
|
1478
|
+
required: true,
|
|
1479
|
+
index: true,
|
|
1480
|
+
},
|
|
1481
|
+
name: {
|
|
1482
|
+
type: String,
|
|
1483
|
+
required: true,
|
|
1484
|
+
trim: true,
|
|
1485
|
+
maxlength: 100,
|
|
1486
|
+
},
|
|
1487
|
+
keyHash: {
|
|
1488
|
+
type: String,
|
|
1489
|
+
required: true,
|
|
1490
|
+
select: false,
|
|
1491
|
+
index: true,
|
|
1492
|
+
},
|
|
1493
|
+
keyPrefix: {
|
|
1494
|
+
type: String,
|
|
1495
|
+
required: true,
|
|
1496
|
+
index: true,
|
|
1497
|
+
},
|
|
1498
|
+
lastUsedAt: {
|
|
1499
|
+
type: Date,
|
|
1500
|
+
},
|
|
1501
|
+
expiresAt: {
|
|
1502
|
+
type: Date,
|
|
1503
|
+
},
|
|
1504
|
+
}, { timestamps: true });
|
|
1505
|
+
agentApiKeySchema.index({ userId: 1, name: 1 });
|
|
1506
|
+
/**
|
|
1507
|
+
* TTL index for automatic cleanup of expired keys.
|
|
1508
|
+
* MongoDB deletes documents when expiresAt passes (expireAfterSeconds: 0 means immediate).
|
|
1509
|
+
* Note: Expired keys are permanently removed, not soft-deleted.
|
|
1510
|
+
* If audit trails are needed, remove this index and check expiration programmatically.
|
|
1511
|
+
*/
|
|
1512
|
+
agentApiKeySchema.index({ expiresAt: 1 }, { expireAfterSeconds: 0 });
|
|
1513
|
+
|
|
1469
1514
|
const agentCategorySchema = new Schema({
|
|
1470
1515
|
value: {
|
|
1471
1516
|
type: String,
|
|
@@ -1728,6 +1773,9 @@ const conversationPreset = {
|
|
|
1728
1773
|
thinkingBudget: {
|
|
1729
1774
|
type: Number,
|
|
1730
1775
|
},
|
|
1776
|
+
effort: {
|
|
1777
|
+
type: String,
|
|
1778
|
+
},
|
|
1731
1779
|
system: {
|
|
1732
1780
|
type: String,
|
|
1733
1781
|
},
|
|
@@ -1854,6 +1902,10 @@ const file = new Schema({
|
|
|
1854
1902
|
ref: 'Conversation',
|
|
1855
1903
|
index: true,
|
|
1856
1904
|
},
|
|
1905
|
+
messageId: {
|
|
1906
|
+
type: String,
|
|
1907
|
+
index: true,
|
|
1908
|
+
},
|
|
1857
1909
|
file_id: {
|
|
1858
1910
|
type: String,
|
|
1859
1911
|
index: true,
|
|
@@ -1917,6 +1969,7 @@ const file = new Schema({
|
|
|
1917
1969
|
timestamps: true,
|
|
1918
1970
|
});
|
|
1919
1971
|
file.index({ createdAt: 1, updatedAt: 1 });
|
|
1972
|
+
file.index({ filename: 1, conversationId: 1, context: 1 }, { unique: true, partialFilterExpression: { context: FileContext.execute_code } });
|
|
1920
1973
|
|
|
1921
1974
|
const keySchema = new Schema({
|
|
1922
1975
|
userId: {
|
|
@@ -2294,6 +2347,12 @@ const rolePermissionsSchema = new Schema({
|
|
|
2294
2347
|
[Permissions.SHARE]: { type: Boolean },
|
|
2295
2348
|
[Permissions.SHARE_PUBLIC]: { type: Boolean },
|
|
2296
2349
|
},
|
|
2350
|
+
[PermissionTypes.REMOTE_AGENTS]: {
|
|
2351
|
+
[Permissions.USE]: { type: Boolean },
|
|
2352
|
+
[Permissions.CREATE]: { type: Boolean },
|
|
2353
|
+
[Permissions.SHARE]: { type: Boolean },
|
|
2354
|
+
[Permissions.SHARE_PUBLIC]: { type: Boolean },
|
|
2355
|
+
},
|
|
2297
2356
|
}, { _id: false });
|
|
2298
2357
|
const roleSchema = new Schema({
|
|
2299
2358
|
name: { type: String, required: true, unique: true, index: true },
|
|
@@ -2868,8 +2927,8 @@ const createMeiliMongooseModel = ({ index, attributesToIndex, syncOptions, }) =>
|
|
|
2868
2927
|
}
|
|
2869
2928
|
/**
|
|
2870
2929
|
* Synchronizes data between the MongoDB collection and the MeiliSearch index by
|
|
2871
|
-
* incrementally indexing only documents where `expiredAt` is `null` and `_meiliIndex` is `
|
|
2872
|
-
* (i.e., non-expired documents that have not yet been indexed).
|
|
2930
|
+
* incrementally indexing only documents where `expiredAt` is `null` and `_meiliIndex` is not `true`
|
|
2931
|
+
* (i.e., non-expired documents that have not yet been indexed, including those with missing or null `_meiliIndex`).
|
|
2873
2932
|
* */
|
|
2874
2933
|
static async syncWithMeili() {
|
|
2875
2934
|
const startTime = Date.now();
|
|
@@ -2894,7 +2953,7 @@ const createMeiliMongooseModel = ({ index, attributesToIndex, syncOptions, }) =>
|
|
|
2894
2953
|
while (hasMore) {
|
|
2895
2954
|
const query = {
|
|
2896
2955
|
expiredAt: null,
|
|
2897
|
-
_meiliIndex:
|
|
2956
|
+
_meiliIndex: { $ne: true },
|
|
2898
2957
|
};
|
|
2899
2958
|
try {
|
|
2900
2959
|
const documents = await this.find(query)
|
|
@@ -3357,6 +3416,10 @@ function createAgentModel(mongoose) {
|
|
|
3357
3416
|
return mongoose.models.Agent || mongoose.model('Agent', agentSchema);
|
|
3358
3417
|
}
|
|
3359
3418
|
|
|
3419
|
+
function createAgentApiKeyModel(mongoose) {
|
|
3420
|
+
return (mongoose.models.AgentApiKey || mongoose.model('AgentApiKey', agentApiKeySchema));
|
|
3421
|
+
}
|
|
3422
|
+
|
|
3360
3423
|
/**
|
|
3361
3424
|
* Creates or returns the AgentCategory model using the provided mongoose instance and schema
|
|
3362
3425
|
*/
|
|
@@ -3520,7 +3583,7 @@ const accessRoleSchema = new Schema({
|
|
|
3520
3583
|
description: String,
|
|
3521
3584
|
resourceType: {
|
|
3522
3585
|
type: String,
|
|
3523
|
-
enum: ['agent', 'project', 'file', 'promptGroup', 'mcpServer'],
|
|
3586
|
+
enum: ['agent', 'project', 'file', 'promptGroup', 'mcpServer', 'remoteAgent'],
|
|
3524
3587
|
required: true,
|
|
3525
3588
|
default: 'agent',
|
|
3526
3589
|
},
|
|
@@ -3620,6 +3683,7 @@ function createModels(mongoose) {
|
|
|
3620
3683
|
Conversation: createConversationModel(mongoose),
|
|
3621
3684
|
Message: createMessageModel(mongoose),
|
|
3622
3685
|
Agent: createAgentModel(mongoose),
|
|
3686
|
+
AgentApiKey: createAgentApiKeyModel(mongoose),
|
|
3623
3687
|
AgentCategory: createAgentCategoryModel(mongoose),
|
|
3624
3688
|
MCPServer: createMCPServerModel(mongoose),
|
|
3625
3689
|
Role: createRoleModel(mongoose),
|
|
@@ -4433,30 +4497,33 @@ function createFileMethods(mongoose) {
|
|
|
4433
4497
|
return await query.sort(sortOptions).lean();
|
|
4434
4498
|
}
|
|
4435
4499
|
/**
|
|
4436
|
-
* Retrieves tool files (files that are embedded or have a fileIdentifier) from an array of file IDs
|
|
4500
|
+
* Retrieves tool files (files that are embedded or have a fileIdentifier) from an array of file IDs.
|
|
4501
|
+
* Note: execute_code files are handled separately by getCodeGeneratedFiles.
|
|
4437
4502
|
* @param fileIds - Array of file_id strings to search for
|
|
4438
4503
|
* @param toolResourceSet - Optional filter for tool resources
|
|
4439
4504
|
* @returns Files that match the criteria
|
|
4440
4505
|
*/
|
|
4441
4506
|
async function getToolFilesByIds(fileIds, toolResourceSet) {
|
|
4442
|
-
var _a, _b, _c;
|
|
4443
4507
|
if (!fileIds || !fileIds.length || !(toolResourceSet === null || toolResourceSet === void 0 ? void 0 : toolResourceSet.size)) {
|
|
4444
4508
|
return [];
|
|
4445
4509
|
}
|
|
4446
4510
|
try {
|
|
4447
|
-
const
|
|
4448
|
-
file_id: { $in: fileIds },
|
|
4449
|
-
$or: [],
|
|
4450
|
-
};
|
|
4511
|
+
const orConditions = [];
|
|
4451
4512
|
if (toolResourceSet.has(EToolResources.context)) {
|
|
4452
|
-
|
|
4513
|
+
orConditions.push({ text: { $exists: true, $ne: null }, context: FileContext.agents });
|
|
4453
4514
|
}
|
|
4454
4515
|
if (toolResourceSet.has(EToolResources.file_search)) {
|
|
4455
|
-
|
|
4516
|
+
orConditions.push({ embedded: true });
|
|
4456
4517
|
}
|
|
4457
|
-
|
|
4458
|
-
|
|
4518
|
+
// If no conditions to match, return empty
|
|
4519
|
+
if (orConditions.length === 0) {
|
|
4520
|
+
return [];
|
|
4459
4521
|
}
|
|
4522
|
+
const filter = {
|
|
4523
|
+
file_id: { $in: fileIds },
|
|
4524
|
+
context: { $ne: FileContext.execute_code },
|
|
4525
|
+
$or: orConditions,
|
|
4526
|
+
};
|
|
4460
4527
|
const selectFields = { text: 0 };
|
|
4461
4528
|
const sortOptions = { updatedAt: -1 };
|
|
4462
4529
|
const results = await getFiles(filter, sortOptions, selectFields);
|
|
@@ -4467,6 +4534,91 @@ function createFileMethods(mongoose) {
|
|
|
4467
4534
|
throw new Error('Error retrieving tool files');
|
|
4468
4535
|
}
|
|
4469
4536
|
}
|
|
4537
|
+
/**
|
|
4538
|
+
* Retrieves files generated by code execution for a given conversation.
|
|
4539
|
+
* These files are stored locally with fileIdentifier metadata for code env re-upload.
|
|
4540
|
+
*
|
|
4541
|
+
* @param conversationId - The conversation ID to search for
|
|
4542
|
+
* @param messageIds - Array of messageIds to filter by (for linear thread filtering).
|
|
4543
|
+
* While technically optional, this function returns empty if not provided.
|
|
4544
|
+
* This is intentional: code-generated files must be filtered by thread to avoid
|
|
4545
|
+
* including files from other branches of a conversation.
|
|
4546
|
+
* @returns Files generated by code execution in the conversation, filtered by messageIds
|
|
4547
|
+
*/
|
|
4548
|
+
async function getCodeGeneratedFiles(conversationId, messageIds) {
|
|
4549
|
+
if (!conversationId) {
|
|
4550
|
+
return [];
|
|
4551
|
+
}
|
|
4552
|
+
/**
|
|
4553
|
+
* Return early if messageIds not provided - this is intentional behavior.
|
|
4554
|
+
* Code-generated files must be filtered by thread messageIds to ensure we only
|
|
4555
|
+
* return files relevant to the current conversation branch, not orphaned files
|
|
4556
|
+
* from other branches or deleted messages.
|
|
4557
|
+
*/
|
|
4558
|
+
if (!messageIds || messageIds.length === 0) {
|
|
4559
|
+
return [];
|
|
4560
|
+
}
|
|
4561
|
+
try {
|
|
4562
|
+
const filter = {
|
|
4563
|
+
conversationId,
|
|
4564
|
+
context: FileContext.execute_code,
|
|
4565
|
+
messageId: { $exists: true, $in: messageIds },
|
|
4566
|
+
'metadata.fileIdentifier': { $exists: true },
|
|
4567
|
+
};
|
|
4568
|
+
const selectFields = { text: 0 };
|
|
4569
|
+
const sortOptions = { createdAt: 1 };
|
|
4570
|
+
const results = await getFiles(filter, sortOptions, selectFields);
|
|
4571
|
+
return results !== null && results !== void 0 ? results : [];
|
|
4572
|
+
}
|
|
4573
|
+
catch (error) {
|
|
4574
|
+
logger$1.error('[getCodeGeneratedFiles] Error retrieving code generated files:', error);
|
|
4575
|
+
return [];
|
|
4576
|
+
}
|
|
4577
|
+
}
|
|
4578
|
+
/**
|
|
4579
|
+
* Retrieves user-uploaded execute_code files (not code-generated) by their file IDs.
|
|
4580
|
+
* These are files with fileIdentifier metadata but context is NOT execute_code (e.g., agents or message_attachment).
|
|
4581
|
+
* File IDs should be collected from message.files arrays in the current thread.
|
|
4582
|
+
* @param fileIds - Array of file IDs to fetch (from message.files in the thread)
|
|
4583
|
+
* @returns User-uploaded execute_code files
|
|
4584
|
+
*/
|
|
4585
|
+
async function getUserCodeFiles(fileIds) {
|
|
4586
|
+
if (!fileIds || fileIds.length === 0) {
|
|
4587
|
+
return [];
|
|
4588
|
+
}
|
|
4589
|
+
try {
|
|
4590
|
+
const filter = {
|
|
4591
|
+
file_id: { $in: fileIds },
|
|
4592
|
+
context: { $ne: FileContext.execute_code },
|
|
4593
|
+
'metadata.fileIdentifier': { $exists: true },
|
|
4594
|
+
};
|
|
4595
|
+
const selectFields = { text: 0 };
|
|
4596
|
+
const sortOptions = { createdAt: 1 };
|
|
4597
|
+
const results = await getFiles(filter, sortOptions, selectFields);
|
|
4598
|
+
return results !== null && results !== void 0 ? results : [];
|
|
4599
|
+
}
|
|
4600
|
+
catch (error) {
|
|
4601
|
+
logger$1.error('[getUserCodeFiles] Error retrieving user code files:', error);
|
|
4602
|
+
return [];
|
|
4603
|
+
}
|
|
4604
|
+
}
|
|
4605
|
+
/**
|
|
4606
|
+
* Atomically claims a file_id for a code-execution output by compound key.
|
|
4607
|
+
* Uses $setOnInsert so concurrent calls for the same (filename, conversationId)
|
|
4608
|
+
* converge on a single record instead of creating duplicates.
|
|
4609
|
+
*/
|
|
4610
|
+
async function claimCodeFile(data) {
|
|
4611
|
+
const File = mongoose.models.File;
|
|
4612
|
+
const result = await File.findOneAndUpdate({
|
|
4613
|
+
filename: data.filename,
|
|
4614
|
+
conversationId: data.conversationId,
|
|
4615
|
+
context: FileContext.execute_code,
|
|
4616
|
+
}, { $setOnInsert: { file_id: data.file_id, user: data.user } }, { upsert: true, new: true }).lean();
|
|
4617
|
+
if (!result) {
|
|
4618
|
+
throw new Error(`[claimCodeFile] Failed to claim file "${data.filename}" for conversation ${data.conversationId}`);
|
|
4619
|
+
}
|
|
4620
|
+
return result;
|
|
4621
|
+
}
|
|
4470
4622
|
/**
|
|
4471
4623
|
* Creates a new file with a TTL of 1 hour.
|
|
4472
4624
|
* @param data - The file data to be created, must contain file_id
|
|
@@ -4606,6 +4758,9 @@ function createFileMethods(mongoose) {
|
|
|
4606
4758
|
findFileById,
|
|
4607
4759
|
getFiles,
|
|
4608
4760
|
getToolFilesByIds,
|
|
4761
|
+
getCodeGeneratedFiles,
|
|
4762
|
+
getUserCodeFiles,
|
|
4763
|
+
claimCodeFile,
|
|
4609
4764
|
createFile,
|
|
4610
4765
|
updateFile,
|
|
4611
4766
|
updateFileUsage,
|
|
@@ -4964,6 +5119,139 @@ function createAgentCategoryMethods(mongoose) {
|
|
|
4964
5119
|
};
|
|
4965
5120
|
}
|
|
4966
5121
|
|
|
5122
|
+
const API_KEY_PREFIX = 'sk-';
|
|
5123
|
+
const API_KEY_LENGTH = 32;
|
|
5124
|
+
function createAgentApiKeyMethods(mongoose) {
|
|
5125
|
+
async function generateApiKey() {
|
|
5126
|
+
const randomPart = await getRandomValues(API_KEY_LENGTH);
|
|
5127
|
+
const key = `${API_KEY_PREFIX}${randomPart}`;
|
|
5128
|
+
const keyHash = await hashToken(key);
|
|
5129
|
+
const keyPrefix = key.slice(0, 8);
|
|
5130
|
+
return { key, keyHash, keyPrefix };
|
|
5131
|
+
}
|
|
5132
|
+
async function createAgentApiKey(data) {
|
|
5133
|
+
try {
|
|
5134
|
+
const AgentApiKey = mongoose.models.AgentApiKey;
|
|
5135
|
+
const { key, keyHash, keyPrefix } = await generateApiKey();
|
|
5136
|
+
const apiKeyDoc = await AgentApiKey.create({
|
|
5137
|
+
userId: data.userId,
|
|
5138
|
+
name: data.name,
|
|
5139
|
+
keyHash,
|
|
5140
|
+
keyPrefix,
|
|
5141
|
+
expiresAt: data.expiresAt || undefined,
|
|
5142
|
+
});
|
|
5143
|
+
return {
|
|
5144
|
+
id: apiKeyDoc._id.toString(),
|
|
5145
|
+
name: apiKeyDoc.name,
|
|
5146
|
+
keyPrefix,
|
|
5147
|
+
key,
|
|
5148
|
+
createdAt: apiKeyDoc.createdAt,
|
|
5149
|
+
expiresAt: apiKeyDoc.expiresAt,
|
|
5150
|
+
};
|
|
5151
|
+
}
|
|
5152
|
+
catch (error) {
|
|
5153
|
+
logger$1.error('[createAgentApiKey] Error creating API key:', error);
|
|
5154
|
+
throw error;
|
|
5155
|
+
}
|
|
5156
|
+
}
|
|
5157
|
+
async function validateAgentApiKey(apiKey) {
|
|
5158
|
+
try {
|
|
5159
|
+
const AgentApiKey = mongoose.models.AgentApiKey;
|
|
5160
|
+
const keyHash = await hashToken(apiKey);
|
|
5161
|
+
const keyDoc = (await AgentApiKey.findOne({ keyHash }).lean());
|
|
5162
|
+
if (!keyDoc) {
|
|
5163
|
+
return null;
|
|
5164
|
+
}
|
|
5165
|
+
if (keyDoc.expiresAt && new Date(keyDoc.expiresAt) < new Date()) {
|
|
5166
|
+
return null;
|
|
5167
|
+
}
|
|
5168
|
+
await AgentApiKey.updateOne({ _id: keyDoc._id }, { $set: { lastUsedAt: new Date() } });
|
|
5169
|
+
return {
|
|
5170
|
+
userId: keyDoc.userId,
|
|
5171
|
+
keyId: keyDoc._id,
|
|
5172
|
+
};
|
|
5173
|
+
}
|
|
5174
|
+
catch (error) {
|
|
5175
|
+
logger$1.error('[validateAgentApiKey] Error validating API key:', error);
|
|
5176
|
+
return null;
|
|
5177
|
+
}
|
|
5178
|
+
}
|
|
5179
|
+
async function listAgentApiKeys(userId) {
|
|
5180
|
+
try {
|
|
5181
|
+
const AgentApiKey = mongoose.models.AgentApiKey;
|
|
5182
|
+
const keys = (await AgentApiKey.find({ userId })
|
|
5183
|
+
.sort({ createdAt: -1 })
|
|
5184
|
+
.lean());
|
|
5185
|
+
return keys.map((key) => ({
|
|
5186
|
+
id: key._id.toString(),
|
|
5187
|
+
name: key.name,
|
|
5188
|
+
keyPrefix: key.keyPrefix,
|
|
5189
|
+
lastUsedAt: key.lastUsedAt,
|
|
5190
|
+
expiresAt: key.expiresAt,
|
|
5191
|
+
createdAt: key.createdAt,
|
|
5192
|
+
}));
|
|
5193
|
+
}
|
|
5194
|
+
catch (error) {
|
|
5195
|
+
logger$1.error('[listAgentApiKeys] Error listing API keys:', error);
|
|
5196
|
+
throw error;
|
|
5197
|
+
}
|
|
5198
|
+
}
|
|
5199
|
+
async function deleteAgentApiKey(keyId, userId) {
|
|
5200
|
+
try {
|
|
5201
|
+
const AgentApiKey = mongoose.models.AgentApiKey;
|
|
5202
|
+
const result = await AgentApiKey.deleteOne({ _id: keyId, userId });
|
|
5203
|
+
return result.deletedCount > 0;
|
|
5204
|
+
}
|
|
5205
|
+
catch (error) {
|
|
5206
|
+
logger$1.error('[deleteAgentApiKey] Error deleting API key:', error);
|
|
5207
|
+
throw error;
|
|
5208
|
+
}
|
|
5209
|
+
}
|
|
5210
|
+
async function deleteAllAgentApiKeys(userId) {
|
|
5211
|
+
try {
|
|
5212
|
+
const AgentApiKey = mongoose.models.AgentApiKey;
|
|
5213
|
+
const result = await AgentApiKey.deleteMany({ userId });
|
|
5214
|
+
return result.deletedCount;
|
|
5215
|
+
}
|
|
5216
|
+
catch (error) {
|
|
5217
|
+
logger$1.error('[deleteAllAgentApiKeys] Error deleting all API keys:', error);
|
|
5218
|
+
throw error;
|
|
5219
|
+
}
|
|
5220
|
+
}
|
|
5221
|
+
async function getAgentApiKeyById(keyId, userId) {
|
|
5222
|
+
try {
|
|
5223
|
+
const AgentApiKey = mongoose.models.AgentApiKey;
|
|
5224
|
+
const keyDoc = (await AgentApiKey.findOne({
|
|
5225
|
+
_id: keyId,
|
|
5226
|
+
userId,
|
|
5227
|
+
}).lean());
|
|
5228
|
+
if (!keyDoc) {
|
|
5229
|
+
return null;
|
|
5230
|
+
}
|
|
5231
|
+
return {
|
|
5232
|
+
id: keyDoc._id.toString(),
|
|
5233
|
+
name: keyDoc.name,
|
|
5234
|
+
keyPrefix: keyDoc.keyPrefix,
|
|
5235
|
+
lastUsedAt: keyDoc.lastUsedAt,
|
|
5236
|
+
expiresAt: keyDoc.expiresAt,
|
|
5237
|
+
createdAt: keyDoc.createdAt,
|
|
5238
|
+
};
|
|
5239
|
+
}
|
|
5240
|
+
catch (error) {
|
|
5241
|
+
logger$1.error('[getAgentApiKeyById] Error getting API key:', error);
|
|
5242
|
+
throw error;
|
|
5243
|
+
}
|
|
5244
|
+
}
|
|
5245
|
+
return {
|
|
5246
|
+
createAgentApiKey,
|
|
5247
|
+
validateAgentApiKey,
|
|
5248
|
+
listAgentApiKeys,
|
|
5249
|
+
deleteAgentApiKey,
|
|
5250
|
+
deleteAllAgentApiKeys,
|
|
5251
|
+
getAgentApiKeyById,
|
|
5252
|
+
};
|
|
5253
|
+
}
|
|
5254
|
+
|
|
4967
5255
|
const NORMALIZED_LIMIT_DEFAULT = 20;
|
|
4968
5256
|
const MAX_CREATE_RETRIES = 5;
|
|
4969
5257
|
const RETRY_BASE_DELAY_MS = 25;
|
|
@@ -5464,6 +5752,27 @@ function createAccessRoleMethods(mongoose) {
|
|
|
5464
5752
|
resourceType: ResourceType.MCPSERVER,
|
|
5465
5753
|
permBits: RoleBits.OWNER,
|
|
5466
5754
|
},
|
|
5755
|
+
{
|
|
5756
|
+
accessRoleId: AccessRoleIds.REMOTE_AGENT_VIEWER,
|
|
5757
|
+
name: 'com_ui_remote_agent_role_viewer',
|
|
5758
|
+
description: 'com_ui_remote_agent_role_viewer_desc',
|
|
5759
|
+
resourceType: ResourceType.REMOTE_AGENT,
|
|
5760
|
+
permBits: RoleBits.VIEWER,
|
|
5761
|
+
},
|
|
5762
|
+
{
|
|
5763
|
+
accessRoleId: AccessRoleIds.REMOTE_AGENT_EDITOR,
|
|
5764
|
+
name: 'com_ui_remote_agent_role_editor',
|
|
5765
|
+
description: 'com_ui_remote_agent_role_editor_desc',
|
|
5766
|
+
resourceType: ResourceType.REMOTE_AGENT,
|
|
5767
|
+
permBits: RoleBits.EDITOR,
|
|
5768
|
+
},
|
|
5769
|
+
{
|
|
5770
|
+
accessRoleId: AccessRoleIds.REMOTE_AGENT_OWNER,
|
|
5771
|
+
name: 'com_ui_remote_agent_role_owner',
|
|
5772
|
+
description: 'com_ui_remote_agent_role_owner_desc',
|
|
5773
|
+
resourceType: ResourceType.REMOTE_AGENT,
|
|
5774
|
+
permBits: RoleBits.OWNER,
|
|
5775
|
+
},
|
|
5467
5776
|
];
|
|
5468
5777
|
const result = {};
|
|
5469
5778
|
for (const role of defaultRoles) {
|
|
@@ -6715,6 +7024,7 @@ function createMethods(mongoose) {
|
|
|
6715
7024
|
...createFileMethods(mongoose),
|
|
6716
7025
|
...createMemoryMethods(mongoose),
|
|
6717
7026
|
...createAgentCategoryMethods(mongoose),
|
|
7027
|
+
...createAgentApiKeyMethods(mongoose),
|
|
6718
7028
|
...createMCPServerMethods(mongoose),
|
|
6719
7029
|
...createAccessRoleMethods(mongoose),
|
|
6720
7030
|
...createUserGroupMethods(mongoose),
|
|
@@ -6724,5 +7034,5 @@ function createMethods(mongoose) {
|
|
|
6724
7034
|
};
|
|
6725
7035
|
}
|
|
6726
7036
|
|
|
6727
|
-
export { AppService, DEFAULT_REFRESH_TOKEN_EXPIRY, DEFAULT_SESSION_EXPIRY, RoleBits, Action as actionSchema, agentCategorySchema, agentSchema, agentsConfigSetup, assistantSchema, balanceSchema, bannerSchema, categoriesSchema, conversationTag as conversationTagSchema, convoSchema, createMethods, createModels, decrypt, decryptV2, decryptV3, defaultVertexModels, encrypt, encryptV2, encryptV3, file as fileSchema, getRandomValues, getTransactionSupport, getWebSearchKeys, groupSchema, hashBackupCode, hashToken, keySchema, loadDefaultInterface, loadTurnstileConfig, loadWebSearchConfig, logger$1 as logger, logger as meiliLogger, MemoryEntrySchema as memorySchema, messageSchema, pluginAuthSchema, presetSchema, processModelSpecs, projectSchema, promptGroupSchema, promptSchema, roleSchema, sessionSchema, shareSchema, signPayload, supportsTransactions, tokenSchema, toolCallSchema, transactionSchema, userSchema, validateVertexConfig, vertexConfigSetup, webSearchAuth, webSearchKeys };
|
|
7037
|
+
export { AppService, DEFAULT_REFRESH_TOKEN_EXPIRY, DEFAULT_SESSION_EXPIRY, RoleBits, Action as actionSchema, agentApiKeySchema, agentCategorySchema, agentSchema, agentsConfigSetup, assistantSchema, balanceSchema, bannerSchema, categoriesSchema, conversationTag as conversationTagSchema, convoSchema, createMethods, createModels, decrypt, decryptV2, decryptV3, defaultVertexModels, encrypt, encryptV2, encryptV3, file as fileSchema, getRandomValues, getTransactionSupport, getWebSearchKeys, groupSchema, hashBackupCode, hashToken, keySchema, loadDefaultInterface, loadTurnstileConfig, loadWebSearchConfig, logger$1 as logger, logger as meiliLogger, MemoryEntrySchema as memorySchema, messageSchema, pluginAuthSchema, presetSchema, processModelSpecs, projectSchema, promptGroupSchema, promptSchema, roleSchema, sessionSchema, shareSchema, signPayload, supportsTransactions, tokenSchema, toolCallSchema, transactionSchema, userSchema, validateVertexConfig, vertexConfigSetup, webSearchAuth, webSearchKeys };
|
|
6728
7038
|
//# sourceMappingURL=index.es.js.map
|