update the chat to use the new chat, fix file uploads, mentions, and message area scaling

This commit is contained in:
Ra
2025-08-20 15:26:23 -07:00
parent be2cab7c9e
commit 9c20073755
80 changed files with 1204 additions and 4338 deletions

View File

@@ -912,7 +912,7 @@ exports.chat = onRequest({ cors: true }, async (req, res) => {
return res.status(405).json({ error: "Method not allowed" });
}
const { message, employeeId, context } = req.body;
const { message, employeeId, context, mentions, attachments } = req.body;
if (!message) {
return res.status(400).json({ error: "Message is required" });
@@ -932,9 +932,44 @@ Current Context:
${JSON.stringify(context, null, 2)}
` : ''}
${mentions && mentions.length > 0 ? `
Mentioned Employees:
${mentions.map(emp => `- ${emp.name} (${emp.role || 'Employee'})`).join('\n')}
` : ''}
Provide helpful, actionable insights while maintaining professional confidentiality and focusing on constructive feedback.
`.trim();
// Build the user message content
let userContent = [
{
type: "text",
text: message
}
];
// Add image attachments if present
if (attachments && attachments.length > 0) {
attachments.forEach(attachment => {
if (attachment.type.startsWith('image/') && attachment.data) {
userContent.push({
type: "image_url",
image_url: {
url: attachment.data,
detail: "high"
}
});
}
// For non-image files, add them as text context
else if (attachment.data) {
userContent.push({
type: "text",
text: `[Attached file: ${attachment.name} (${attachment.type})]`
});
}
});
}
const completion = await openai.chat.completions.create({
model: "gpt-4o",
messages: [
@@ -944,21 +979,25 @@ Provide helpful, actionable insights while maintaining professional confidential
},
{
role: "user",
content: message
content: userContent
}
],
temperature: 0.7,
max_tokens: 500,
max_tokens: 1000, // Increased for more detailed responses when analyzing images
});
response = completion.choices[0].message.content;
} else {
// Fallback responses when OpenAI is not available
const attachmentText = attachments && attachments.length > 0
? ` I can see you've attached ${attachments.length} file(s), but I'm currently unable to process attachments.`
: '';
const responses = [
"That's an interesting point about performance metrics. Based on the data, I'd recommend focusing on...",
"I can see from the employee report that there are opportunities for growth in...",
"The company analysis suggests that this area needs attention. Here's what I would suggest...",
"Based on the performance data, this employee shows strong potential in...",
`That's an interesting point about performance metrics.${attachmentText} Based on the data, I'd recommend focusing on...`,
`I can see from the employee report that there are opportunities for growth in...${attachmentText}`,
`The company analysis suggests that this area needs attention.${attachmentText} Here's what I would suggest...`,
`Based on the performance data, this employee shows strong potential in...${attachmentText}`,
];
response = responses[Math.floor(Math.random() * responses.length)];