Commit graph

209 commits

Author SHA1 Message Date
rever-tecnologia
3396e930d4 feat(frontend): implementar paginacao numerada em listagens de tickets
- Adiciona tickets.listPaginated no backend com paginacao nativa Convex
- Converte TicketsView para usePaginatedQuery com controles numerados
- Converte PortalTicketList para usePaginatedQuery com controles numerados
- Atualiza tauri e @tauri-apps/api para versao 2.9

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-09 20:17:22 -03:00
rever-tecnologia
91ac6c416c fix(convex): use collect+slice instead of take for test compatibility
The take() method isn't available in test mocks, so using
collect() followed by slice() to limit results.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-09 19:34:58 -03:00
rever-tecnologia
3a37892864 refactor(convex): replace collect() with take() to prevent OOM
- liveChat.ts: limit sessions/messages queries (take 50-500)
- tickets.ts: batch delete operations, limit playNext/reassign (take 100-2000)
- reports.ts: limit ticket/user/machine queries (take 500-2000)
- machines.ts: limit machine queries for registration/listing (take 500)
- metrics.ts: limit device health summary (take 200)
- users.ts: limit user search in claimInvite (take 5000)
- alerts.ts: limit company/alert queries (take 500-1000)
- migrations.ts: limit batch operations (take 1000-2000)

These changes prevent the Convex backend from loading entire tables
into memory, which was causing OOM kills at 16GB and WebSocket
disconnections (code 1006).

Expected RAM reduction: 60-80% at peak usage.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-09 19:23:10 -03:00
rever-tecnologia
d20ebf7416 fix(chat): ajustes de texto, layout e icone do menu
- Mudar texto 'Chat #' para 'Ticket #' no desktop
- Passar ticketRef via URL para exibir numero correto
- Ajustar tamanho da janela minimizada (240px)
- Incluir ticketRef no checkMachineUpdates (Convex)
- Ajustar padding dos botoes no chat web
- Mudar icone 'Todos os tickets' para ClipboardList

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-09 13:06:03 -03:00
rever-tecnologia
3c2d1824fb fix(chat): correções de SSE, inicialização e área de clique
- Substituir WebSocket por SSE para real-time (chat.rs)
- Corrigir inicialização do chat runtime em lib.rs
- Iniciar unreadByMachine em 0 ao criar sessão (liveChat.ts)
- Corrigir área de clique do chip minimizado (pointer-events)
- Corrigir roteamento SPA no Tauri (index.html?view=chat)
- Corrigir estado inicial isMinimized como true

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-09 11:51:33 -03:00
esdrasrenan
fe361ff4d8 livechat: inicializar sessão com não lidas prévias 2025-12-09 01:44:24 -03:00
esdrasrenan
53376fe5b0 fix: convert strings to Uint8Array for @noble/hashes v2
@noble/hashes v2 no longer accepts strings directly, only Uint8Array.
Added utf8() helper to encode strings before hashing.

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-07 16:34:28 -03:00
esdrasrenan
d01c37522f feat: SSE para chat desktop, rate limiting, retry, testes e atualizacao de stack
- Implementa Server-Sent Events (SSE) para chat no desktop com fallback HTTP
- Adiciona rate limiting nas APIs de chat (poll, messages, sessions)
- Adiciona retry com backoff exponencial para mutations
- Cria testes para modulo liveChat (20 testes)
- Corrige testes de SMTP (unit tests para extractEnvelopeAddress)
- Adiciona indice by_status_lastActivity para cron de sessoes inativas
- Atualiza stack: Bun 1.3.4, React 19, recharts 3, noble/hashes 2, etc

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-07 16:29:18 -03:00
esdrasrenan
0e0bd9a49c Otimizações de performance e correções no chat ao vivo
- Corrigir acentuações (sessão, sessões, duração)
- Auto-minimizar chat nativo quando sessão termina
- Corrigir race condition em markMachineMessagesRead (Promise.all)
- Adicionar paginação no cron autoEndInactiveSessions (.take(50))
- Otimizar listMachineMessages com limite de 100 mensagens
- Corrigir memory leak no ChatWidget (limite de 200 mensagens)
- Exibir estado offline quando não há sessão ativa

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-07 15:14:47 -03:00
esdrasrenan
115c5128a6 Consolidate chat timeline events + auto-end inactive sessions
Timeline consolidation:
- Replace multiple LIVE_CHAT_STARTED/ENDED events with single LIVE_CHAT_SUMMARY
- Show total duration accumulated across all sessions
- Display session count (e.g., "23min 15s total - 3 sessoes")
- Show "Ativo" badge when session is active

Auto-end inactive chat sessions:
- Add cron job running every minute to check inactive sessions
- Automatically end sessions after 5 minutes of client inactivity
- Mark auto-ended sessions with "(encerrado por inatividade)" flag

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-07 14:44:34 -03:00
esdrasrenan
c217a40030 feat(desktop): add file attachments and native chat window
- Add file upload support in chat (PDF, images, txt, docs, xlsx)
  - Limited to 10MB max file size
  - Only allowed extensions for security
- Use native Windows decorations for chat window
- Remove ChatFloatingWidget (replaced by native window)
- Simplify chat event listeners (window managed by Rust)
- Fix typo "sessao" -> "sessão"

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-07 13:09:55 -03:00
esdrasrenan
4f81f62429 Fix unread badge - increment unreadByMachine when agent sends message
The unreadByMachine counter was never being incremented when agents sent
chat messages, causing the badge to always show 0. Now when an agent
(ADMIN/MANAGER/AGENT) posts a message to a ticket with an active chat
session, the counter is incremented properly.

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-07 11:34:47 -03:00
esdrasrenan
88a3b37f2f 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>
2025-12-07 11:16:56 -03:00
esdrasrenan
9c6f19f9a5 Fix chat permission for machine-linked users
Allow COLLABORATOR users who are linked to the ticket's machine
(via assignedUserId or linkedUserIds) to access the chat, not
just the ticket requester.

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-07 03:49:09 -03:00
esdrasrenan
d766de4fda Add chat widget improvements and chat history component
Widget improvements:
- Pulsating badge with unread message count on floating button
- Clickable ticket reference link in chat header
- ExternalLink icon on hover

Desktop (Raven) improvements:
- Track previous unread count for new message detection
- Send native Windows notifications for new messages
- Focus chat window when new messages arrive

Chat history:
- New query getTicketChatHistory for fetching chat sessions and messages
- New component TicketChatHistory displaying chat sessions
- Sessions can be expanded/collapsed to view messages
- Pagination support for long conversations
- Added to both dashboard and portal ticket views

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-07 03:20:22 -03:00
esdrasrenan
f45ee91804 Fix chat widget UI and allow attachment-only messages
- Allow sending messages with only attachments (no text required)
- Change "Chat Ativo" header to just "Chat"
- Replace Headphones icon with MessageCircle for own messages
- Replace PhoneOff icon with XCircle for end chat button

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-07 03:09:51 -03:00
esdrasrenan
60e98dd47c Retorna status da maquina mesmo sem sessao de chat ativa
A query getTicketSession agora sempre retorna machineOnline,
permitindo que o botao de chat seja habilitado corretamente
quando a maquina esta online mas nao ha sessao ativa.

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-07 02:54:56 -03:00
esdrasrenan
3b1cde79df Melhora chat ao vivo com anexos e eventos de timeline
- Reestrutura visual do widget de chat (header branco, status emerald)
- Adiciona sistema de anexos com upload e drag-and-drop
- Substitui select nativo por componente Select do shadcn
- Adiciona eventos LIVE_CHAT_STARTED e LIVE_CHAT_ENDED na timeline
- Traduz labels de chat para portugues (Chat iniciado/finalizado)
- Filtra CHAT_MESSAGE_ADDED da timeline (apenas inicio/fim aparecem)
- Restringe inicio de chat a tickets com responsavel atribuido
- Exibe duracao da sessao ao finalizar chat

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-07 02:20:11 -03:00
esdrasrenan
8c465008bf Adiciona widget de chat flutuante global
- Widget no canto inferior direito em todas as paginas
- Mostra sessoes de chat ativas do agente
- Suporta multiplas sessoes com seletor
- Badge com contador de mensagens nao lidas
- Pode minimizar ou fechar
- Query listAgentSessions para buscar sessoes ativas

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-07 01:31:00 -03:00
esdrasrenan
ba91c1e0f5 Implementa sistema de chat em tempo real entre agente e cliente
- Adiciona tabela liveChatSessions no schema Convex
- Cria convex/liveChat.ts com mutations e queries para chat
- Adiciona API routes para maquinas (sessions, messages, poll)
- Cria modulo chat.rs no Tauri com ChatRuntime e polling
- Adiciona comandos de chat no lib.rs (start/stop polling, open/close window)
- Cria componentes React do chat widget (ChatWidget, types)
- Adiciona botao "Iniciar Chat" no dashboard (ticket-chat-panel)
- Implementa menu de chat no system tray
- Polling de 2 segundos para maior responsividade
- Janela de chat flutuante, frameless, always-on-top

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-07 01:00:27 -03:00
esdrasrenan
873305fa7f Improve USB policy history with filters and pagination
- Fix bug where APPLYING status would not transition to APPLIED
- Add status and date range filters to policy history
- Add cursor-based pagination with "Load more" button
- Use DateRangeButton component for date filtering
- Reset filters and pagination when switching filters

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-06 23:24:23 -03:00
esdrasrenan
5846c299ce Fix Convex validator to accept null for optional string fields
Rust serializes Option<String>::None as null, not undefined.
Updated reportUsbPolicyStatus mutation to accept both null and undefined
for error and currentPolicy fields.

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-06 23:00:16 -03:00
esdrasrenan
20b63f4ad6 Fix USB policy reporting and improve agent reliability
- Fix Zod schema to accept null values (nullable) for error/currentPolicy
- Add robust logging system writing to raven-agent.log file
- Rewrite auto-start using winreg with validation
- Auto-start agent on app setup if credentials exist
- Reduce retry attempts to 2 (1 + 1 retry after 2s)
- Replace provider's remote access on ID change (prevents duplicates)
- Update agent to v0.2.0

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-06 22:43:15 -03:00
esdrasrenan
b60255fe03 Improve USB policy responsiveness and reliability
- Reduce USB policy polling from 60s to 15s for faster response
- Add retry with exponential backoff (2s, 4s, 8s) on report failures
- Add APPLYING state for real-time progress bar feedback
- Check if policy is already applied locally before re-applying
- Fix API schema to accept APPLYING status
- Update agent to v0.1.9

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-06 17:51:57 -03:00
rever-tecnologia
cf31e78edb Add requester filter and improve error messages
- Add requester filter to device tickets history page
- Create listMachineRequesters query to list unique requesters
- Add friendly API error formatting in desktop agent
- Translate validation errors to user-friendly Portuguese messages

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-05 17:22:44 -03:00
rever-tecnologia
bb82efa9d3 Preserve machine identity based on hardware
- Add by_tenant_hostname index for hostname-based lookup
- Add third search in register mutation for hardware matching
- Search by hostname + MAC/serial when fingerprint/email differ
- Fallback to MAC/serial match across all tenant machines
- Preserves ticket history when user changes on same physical machine

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-05 17:00:19 -03:00
rever-tecnologia
7c5bc828cf Fix getById not returning USB policy fields
The getByIdHandler was missing usbPolicy, usbPolicyStatus,
and usbPolicyError fields, causing the chip to always show
"Permitido" instead of the actual policy value.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-05 10:06:18 -03:00
rever-tecnologia
6007cf6740 Fix USB policy token hash bug
The getPendingUsbPolicy and reportUsbPolicyStatus functions were
comparing the plain token against the tokenHash in the database,
which would never match. Now properly hashing the token before
database lookup.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-05 09:12:30 -03:00
rever-tecnologia
7469d3b5e6 Add USB policy improvements and emprestimos details modal
- Add cron job to cleanup stale pending USB policies every 30 min
- Add cleanupStalePendingPolicies mutation to usbPolicy.ts
- Add USB policy fields to machines listByTenant query
- Display USB status chip in device details and bulk control modal
- Add details modal for emprestimos with all loan information
- Add observacoesDevolucao field to preserve original observations
- Fix status text size in details modal title

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-05 08:24:56 -03:00
rever-tecnologia
063c5dfde7 Add equipment loan feature and USB bulk control
- Add emprestimos (equipment loan) module in Convex with queries/mutations
- Create emprestimos page with full CRUD and status tracking
- Add USB bulk control to admin devices overview
- Fix Portuguese accents in USB policy control component
- Fix dead code warnings in Rust agent
- Fix tiptap type error in rich text editor
2025-12-04 14:23:58 -03:00
rever-tecnologia
49aa143a80 Add USB storage device control feature
- Add USB policy fields to machines schema (policy, status, error)
- Create usbPolicyEvents table for audit logging
- Implement Convex mutations/queries for USB policy management
- Add REST API endpoints for desktop agent communication
- Create Rust usb_control module for Windows registry manipulation
- Integrate USB policy check in agent heartbeat loop
- Add USB policy control component in admin device overview
- Add localhost:3001 to auth trustedOrigins for dev

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-04 13:30:59 -03:00
Esdras Renan
f7ad7f6a17 Fix admin rename payload and harden RustDesk ID sync 2025-11-26 21:00:08 -03:00
Esdras Renan
bd1bd4bef1 Expose visit status and performedAt in ticket list 2025-11-26 16:54:25 -03:00
Esdras Renan
66559eafbf feat(visits): concluir/reabrir visita sem poluir agenda 2025-11-26 14:21:31 -03:00
Esdras Renan
e1ecf20346 fix: allow 90d analytics window 2025-11-19 16:02:37 -03:00
Esdras Renan
c79ba4638c Allow reassigning during active sessions 2025-11-19 09:57:04 -03:00
Esdras Renan
ff9d95746e Align report filters and update work session flows 2025-11-19 09:24:30 -03:00
Esdras Renan
4c25f3f83e fix: avoid multiple paginated queries in metrics 2025-11-18 20:08:30 -03:00
Esdras Renan
72a4748a81 feat: enforce visit scheduling ux 2025-11-18 19:59:27 -03:00
Esdras Renan
6473e8d40f feat: enhance visit scheduling and closing flow 2025-11-18 17:42:38 -03:00
Esdras Renan
b707b56ba1 fix: type pagination error metadata 2025-11-18 13:34:31 -03:00
Esdras Renan
499c7f335c Gate Convex crons behind env flags 2025-11-18 10:28:56 -03:00
Esdras Renan
674c62208f Remove hours usage cron/action 2025-11-18 09:34:56 -03:00
Esdras Renan
07a6f101b8 fix: handle Convex InvalidCursor and align backend config 2025-11-17 23:53:43 -03:00
Esdras Renan
36fe4a7943 chore: trigger convex deploy 2025-11-17 16:02:12 -03:00
Esdras Renan
dbee5c28c8 fix: stabilize convex pagination and ci fallback 2025-11-17 14:23:46 -03:00
Esdras Renan
3b0484a9ad feat: aggregate dashboard metrics server-side 2025-11-17 13:48:59 -03:00
Esdras Renan
c3ee23f967 Reduce Convex report memory footprint 2025-11-17 10:53:06 -03:00
Esdras Renan
b721348e19 feat: improve custom fields admin and date filters 2025-11-15 01:51:55 -03:00
Esdras Renan
15d11b6b12 feat: improve reports filters and ticket flows 2025-11-14 19:41:47 -03:00