diff --git a/api/models/Agent.js b/api/models/Agent.js index 61aa1c05cc..963b99196d 100644 --- a/api/models/Agent.js +++ b/api/models/Agent.js @@ -38,6 +38,15 @@ const createAgent = async (agentData) => { ], category: agentData.category || 'general', }; + + // Handle empty support_contact object + if (agentData.support_contact && Object.keys(agentData.support_contact).length === 0) { + initialAgentData.support_contact = { + name: '', + email: '', + }; + } + return (await Agent.create(initialAgentData)).toObject(); }; diff --git a/packages/api/src/agents/validation.ts b/packages/api/src/agents/validation.ts index 0e493e7921..4698d3869b 100644 --- a/packages/api/src/agents/validation.ts +++ b/packages/api/src/agents/validation.ts @@ -27,6 +27,14 @@ export const agentToolResourcesSchema = z }) .optional(); +/** Support contact schema for agent */ +export const agentSupportContactSchema = z + .object({ + name: z.string().optional(), + email: z.string().email().optional(), + }) + .optional(); + /** Base agent schema with all common fields */ export const agentBaseSchema = z.object({ name: z.string().nullable().optional(), @@ -42,6 +50,8 @@ export const agentBaseSchema = z.object({ recursion_limit: z.number().optional(), conversation_starters: z.array(z.string()).optional(), tool_resources: agentToolResourcesSchema, + support_contact: agentSupportContactSchema, + category: z.string().optional(), }); /** Create schema extends base with required fields for creation */ diff --git a/packages/data-schemas/src/schema/agent.ts b/packages/data-schemas/src/schema/agent.ts index 5d213b957a..90f629bd07 100644 --- a/packages/data-schemas/src/schema/agent.ts +++ b/packages/data-schemas/src/schema/agent.ts @@ -99,21 +99,11 @@ const agentSchema = new Schema( default: 'general', }, support_contact: { - type: { - name: { - type: String, - trim: true, - }, - email: { - type: String, - match: [ - /^\w+([.-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,3})+$/, - 'Please enter a valid email address.', - ], - trim: true, - }, + type: Schema.Types.Mixed, + default: { + name: '', + email: '', }, - default: {}, }, is_promoted: { type: Boolean,