Fix chat session management and add floating widget

- Fix session sync: events now send complete ChatSession data instead of
  partial ChatSessionSummary, ensuring proper ticket/agent info display
- Add session-ended event detection to remove closed sessions from client
- Add ChatFloatingWidget component for in-app chat experience
- Restrict endSession to ADMIN/MANAGER/AGENT roles only
- Improve polling logic to detect new and ended sessions properly

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
esdrasrenan 2025-12-07 11:16:56 -03:00
parent e4f8f465de
commit 88a3b37f2f
5 changed files with 680 additions and 92 deletions

View file

@ -140,7 +140,7 @@ export const startSession = mutation({
},
})
// Agente encerra sessao de chat
// Agente encerra sessao de chat (somente ADMIN, MANAGER ou AGENT podem encerrar)
export const endSession = mutation({
args: {
sessionId: v.id("liveChatSessions"),
@ -152,12 +152,18 @@ export const endSession = mutation({
throw new ConvexError("Sessão não encontrada")
}
// Verificar permissao
const agent = await ctx.db.get(actorId)
if (!agent || agent.tenantId !== session.tenantId) {
// Verificar permissao do usuario
const actor = await ctx.db.get(actorId)
if (!actor || actor.tenantId !== session.tenantId) {
throw new ConvexError("Acesso negado")
}
// Somente ADMIN, MANAGER ou AGENT podem encerrar sessoes de chat
const role = actor.role?.toUpperCase() ?? ""
if (!["ADMIN", "MANAGER", "AGENT"].includes(role)) {
throw new ConvexError("Apenas agentes de suporte podem encerrar sessões de chat")
}
if (session.status !== "ACTIVE") {
throw new ConvexError("Sessão já encerrada")
}
@ -179,7 +185,7 @@ export const endSession = mutation({
payload: {
sessionId,
agentId: actorId,
agentName: agent.name,
agentName: actor.name,
durationMs,
startedAt: session.startedAt,
endedAt: now,