mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-23 11:50:14 +01:00
feat: Add category and support contact fields to Agent schema and UI components
This commit is contained in:
parent
e86842fd19
commit
c43a52b4c9
15 changed files with 581 additions and 11 deletions
|
|
@ -12,6 +12,61 @@ const {
|
|||
} = require('./Project');
|
||||
const getLogStores = require('~/cache/getLogStores');
|
||||
|
||||
// Category values - must match the frontend values in client/src/constants/agentCategories.ts
|
||||
const CATEGORY_VALUES = {
|
||||
GENERAL: 'general',
|
||||
HR: 'hr',
|
||||
RD: 'rd',
|
||||
FINANCE: 'finance',
|
||||
IT: 'it',
|
||||
SALES: 'sales',
|
||||
AFTERSALES: 'aftersales',
|
||||
};
|
||||
|
||||
const VALID_CATEGORIES = Object.values(CATEGORY_VALUES);
|
||||
|
||||
// Add category field to the Agent schema if it doesn't already exist
|
||||
if (!agentSchema.paths.category) {
|
||||
agentSchema.add({
|
||||
category: {
|
||||
type: String,
|
||||
trim: true,
|
||||
enum: {
|
||||
values: VALID_CATEGORIES,
|
||||
message:
|
||||
'"{VALUE}" is not a supported agent category. Valid categories are: ' +
|
||||
VALID_CATEGORIES.join(', ') +
|
||||
'.',
|
||||
},
|
||||
index: true,
|
||||
default: CATEGORY_VALUES.GENERAL,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// Add support_contact field to the Agent schema if it doesn't already exist
|
||||
if (!agentSchema.paths.support_contact) {
|
||||
agentSchema.add({
|
||||
support_contact: {
|
||||
type: Object,
|
||||
default: {},
|
||||
name: {
|
||||
type: String,
|
||||
minlength: [3, 'Support contact name must be at least 3 characters.'],
|
||||
trim: true,
|
||||
},
|
||||
email: {
|
||||
type: String,
|
||||
match: [
|
||||
/^\w+([.-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,3})+$/,
|
||||
'Please enter a valid email address.',
|
||||
],
|
||||
trim: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const Agent = mongoose.model('agent', agentSchema);
|
||||
|
||||
/**
|
||||
|
|
@ -21,7 +76,12 @@ const Agent = mongoose.model('agent', agentSchema);
|
|||
* @throws {Error} If the agent creation fails.
|
||||
*/
|
||||
const createAgent = async (agentData) => {
|
||||
return (await Agent.create(agentData)).toObject();
|
||||
// Ensure the agent has a category (default to 'general' if none provided)
|
||||
const dataWithCategory = {
|
||||
...agentData,
|
||||
category: agentData.category || 'general',
|
||||
};
|
||||
return (await Agent.create(dataWithCategory)).toObject();
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -280,6 +340,7 @@ const getListAgents = async (searchParameter) => {
|
|||
projectIds: 1,
|
||||
description: 1,
|
||||
isCollaborative: 1,
|
||||
category: 1,
|
||||
}).lean()
|
||||
).map((agent) => {
|
||||
if (agent.author?.toString() !== author) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue