elevenlabs-webhook-nodejs 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +27 -0
- package/.dockerignore +6 -0
- package/.env.example +43 -0
- package/BEFORE-PRODUCTION.md +32 -0
- package/Dockerfile +23 -0
- package/SYSTEM_OVERVIEW.md +942 -0
- package/SYSTEM_STATUS.md +332 -0
- package/backup_script/main.py +146 -0
- package/baileys/.dockerignore +7 -0
- package/baileys/Dockerfile +13 -0
- package/baileys/README.md +412 -0
- package/baileys/index.js +499 -0
- package/baileys/package-lock.json +2532 -0
- package/baileys/package.json +25 -0
- package/baileys/server.js +96 -0
- package/baileys/src/config.js +55 -0
- package/baileys/src/middleware/api-key.js +16 -0
- package/baileys/src/routes/accounts.js +51 -0
- package/baileys/src/routes/chats.js +103 -0
- package/baileys/src/routes/webhooks.js +34 -0
- package/baileys/src/services/account-store.js +259 -0
- package/baileys/src/services/webhook-dispatcher.js +161 -0
- package/baileys/src/services/worker-manager.js +597 -0
- package/baileys/src/utils/jid.js +79 -0
- package/baileys/src/utils/logger.js +16 -0
- package/baileys/src/utils/use-mongodb-auth-state.js +122 -0
- package/baileys/worker.js +721 -0
- package/dist/app.d.ts +1 -0
- package/dist/app.js +84 -0
- package/dist/app.js.map +1 -0
- package/dist/config/agentPrompts.json +19 -0
- package/dist/config/database.d.ts +1 -0
- package/dist/config/database.js +26 -0
- package/dist/config/database.js.map +1 -0
- package/dist/config/env.d.ts +41 -0
- package/dist/config/env.js +81 -0
- package/dist/config/env.js.map +1 -0
- package/dist/config/index.d.ts +3 -0
- package/dist/config/index.js +73 -0
- package/dist/config/index.js.map +1 -0
- package/dist/controllers/webhook.controller.d.ts +10 -0
- package/dist/controllers/webhook.controller.js +128 -0
- package/dist/controllers/webhook.controller.js.map +1 -0
- package/dist/errors/index.d.ts +4 -0
- package/dist/errors/index.js +13 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/hooks/webhookValidator.d.ts +2 -0
- package/dist/hooks/webhookValidator.js +47 -0
- package/dist/hooks/webhookValidator.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +55 -0
- package/dist/index.js.map +1 -0
- package/dist/migrations/001_session-architecture.d.ts +3 -0
- package/dist/migrations/001_session-architecture.js +119 -0
- package/dist/migrations/001_session-architecture.js.map +1 -0
- package/dist/migrations/002_agent-ref.d.ts +3 -0
- package/dist/migrations/002_agent-ref.js +55 -0
- package/dist/migrations/002_agent-ref.js.map +1 -0
- package/dist/migrations/003_shift-schedule.d.ts +3 -0
- package/dist/migrations/003_shift-schedule.js +48 -0
- package/dist/migrations/003_shift-schedule.js.map +1 -0
- package/dist/migrations/004_invert-shift-to-clinic-hours.d.ts +3 -0
- package/dist/migrations/004_invert-shift-to-clinic-hours.js +27 -0
- package/dist/migrations/004_invert-shift-to-clinic-hours.js.map +1 -0
- package/dist/migrations/005_composite-baileys-chat-ids.d.ts +3 -0
- package/dist/migrations/005_composite-baileys-chat-ids.js +47 -0
- package/dist/migrations/005_composite-baileys-chat-ids.js.map +1 -0
- package/dist/migrations/migration.model.d.ts +18 -0
- package/dist/migrations/migration.model.js +45 -0
- package/dist/migrations/migration.model.js.map +1 -0
- package/dist/migrations/migration.routes.d.ts +2 -0
- package/dist/migrations/migration.routes.js +37 -0
- package/dist/migrations/migration.routes.js.map +1 -0
- package/dist/migrations/migration.runner.d.ts +19 -0
- package/dist/migrations/migration.runner.js +74 -0
- package/dist/migrations/migration.runner.js.map +1 -0
- package/dist/models/ConversationClaim.d.ts +13 -0
- package/dist/models/ConversationClaim.js +44 -0
- package/dist/models/ConversationClaim.js.map +1 -0
- package/dist/models/ConversationEvaluation.d.ts +23 -0
- package/dist/models/ConversationEvaluation.js +92 -0
- package/dist/models/ConversationEvaluation.js.map +1 -0
- package/dist/models/Summary.d.ts +37 -0
- package/dist/models/Summary.js +78 -0
- package/dist/models/Summary.js.map +1 -0
- package/dist/models/Transcription.d.ts +34 -0
- package/dist/models/Transcription.js +71 -0
- package/dist/models/Transcription.js.map +1 -0
- package/dist/models/WhatsAppRecipient.d.ts +23 -0
- package/dist/models/WhatsAppRecipient.js +53 -0
- package/dist/models/WhatsAppRecipient.js.map +1 -0
- package/dist/modules/admin/admin.routes.d.ts +2 -0
- package/dist/modules/admin/admin.routes.js +1966 -0
- package/dist/modules/admin/admin.routes.js.map +1 -0
- package/dist/modules/admin/elevenlabs-test-chat.routes.d.ts +2 -0
- package/dist/modules/admin/elevenlabs-test-chat.routes.js +158 -0
- package/dist/modules/admin/elevenlabs-test-chat.routes.js.map +1 -0
- package/dist/modules/admin/whatsapp-test-chat.routes.d.ts +2 -0
- package/dist/modules/admin/whatsapp-test-chat.routes.js +204 -0
- package/dist/modules/admin/whatsapp-test-chat.routes.js.map +1 -0
- package/dist/modules/agents/agent.model.d.ts +38 -0
- package/dist/modules/agents/agent.model.js +92 -0
- package/dist/modules/agents/agent.model.js.map +1 -0
- package/dist/modules/agents/agent.routes.d.ts +2 -0
- package/dist/modules/agents/agent.routes.js +61 -0
- package/dist/modules/agents/agent.routes.js.map +1 -0
- package/dist/modules/appointment-validation/appointment-validation.model.d.ts +76 -0
- package/dist/modules/appointment-validation/appointment-validation.model.js +118 -0
- package/dist/modules/appointment-validation/appointment-validation.model.js.map +1 -0
- package/dist/modules/appointment-validation/appointment-validation.routes.d.ts +2 -0
- package/dist/modules/appointment-validation/appointment-validation.routes.js +202 -0
- package/dist/modules/appointment-validation/appointment-validation.routes.js.map +1 -0
- package/dist/modules/appointment-validation/appointment-validation.service.d.ts +53 -0
- package/dist/modules/appointment-validation/appointment-validation.service.js +827 -0
- package/dist/modules/appointment-validation/appointment-validation.service.js.map +1 -0
- package/dist/modules/auth/auth.model.d.ts +17 -0
- package/dist/modules/auth/auth.model.js +64 -0
- package/dist/modules/auth/auth.model.js.map +1 -0
- package/dist/modules/auth/auth.routes.d.ts +2 -0
- package/dist/modules/auth/auth.routes.js +202 -0
- package/dist/modules/auth/auth.routes.js.map +1 -0
- package/dist/modules/auth/auth.service.d.ts +28 -0
- package/dist/modules/auth/auth.service.js +183 -0
- package/dist/modules/auth/auth.service.js.map +1 -0
- package/dist/modules/auth/refresh-token.model.d.ts +13 -0
- package/dist/modules/auth/refresh-token.model.js +52 -0
- package/dist/modules/auth/refresh-token.model.js.map +1 -0
- package/dist/modules/billing/billing-alert.model.d.ts +16 -0
- package/dist/modules/billing/billing-alert.model.js +47 -0
- package/dist/modules/billing/billing-alert.model.js.map +1 -0
- package/dist/modules/billing/billing-period-snapshot.model.d.ts +35 -0
- package/dist/modules/billing/billing-period-snapshot.model.js +68 -0
- package/dist/modules/billing/billing-period-snapshot.model.js.map +1 -0
- package/dist/modules/billing/billing.model.d.ts +18 -0
- package/dist/modules/billing/billing.model.js +62 -0
- package/dist/modules/billing/billing.model.js.map +1 -0
- package/dist/modules/billing/billing.routes.d.ts +2 -0
- package/dist/modules/billing/billing.routes.js +63 -0
- package/dist/modules/billing/billing.routes.js.map +1 -0
- package/dist/modules/billing/billing.service.d.ts +69 -0
- package/dist/modules/billing/billing.service.js +498 -0
- package/dist/modules/billing/billing.service.js.map +1 -0
- package/dist/modules/billing/payment.model.d.ts +24 -0
- package/dist/modules/billing/payment.model.js +57 -0
- package/dist/modules/billing/payment.model.js.map +1 -0
- package/dist/modules/calls/call.model.d.ts +41 -0
- package/dist/modules/calls/call.model.js +97 -0
- package/dist/modules/calls/call.model.js.map +1 -0
- package/dist/modules/calls/call.routes.d.ts +2 -0
- package/dist/modules/calls/call.routes.js +103 -0
- package/dist/modules/calls/call.routes.js.map +1 -0
- package/dist/modules/campaigns/campaign.model.d.ts +45 -0
- package/dist/modules/campaigns/campaign.model.js +98 -0
- package/dist/modules/campaigns/campaign.model.js.map +1 -0
- package/dist/modules/campaigns/campaign.routes.d.ts +2 -0
- package/dist/modules/campaigns/campaign.routes.js +323 -0
- package/dist/modules/campaigns/campaign.routes.js.map +1 -0
- package/dist/modules/campaigns/campaign.service.d.ts +11 -0
- package/dist/modules/campaigns/campaign.service.js +86 -0
- package/dist/modules/campaigns/campaign.service.js.map +1 -0
- package/dist/modules/google-calendar/google-calendar.routes.d.ts +2 -0
- package/dist/modules/google-calendar/google-calendar.routes.js +32 -0
- package/dist/modules/google-calendar/google-calendar.routes.js.map +1 -0
- package/dist/modules/inbound-call/inbound-call-config.model.d.ts +20 -0
- package/dist/modules/inbound-call/inbound-call-config.model.js +68 -0
- package/dist/modules/inbound-call/inbound-call-config.model.js.map +1 -0
- package/dist/modules/inbound-call/inbound-call.routes.d.ts +2 -0
- package/dist/modules/inbound-call/inbound-call.routes.js +243 -0
- package/dist/modules/inbound-call/inbound-call.routes.js.map +1 -0
- package/dist/modules/leads/lead.model.d.ts +24 -0
- package/dist/modules/leads/lead.model.js +54 -0
- package/dist/modules/leads/lead.model.js.map +1 -0
- package/dist/modules/leads/lead.routes.d.ts +2 -0
- package/dist/modules/leads/lead.routes.js +201 -0
- package/dist/modules/leads/lead.routes.js.map +1 -0
- package/dist/modules/plans/plan.model.d.ts +25 -0
- package/dist/modules/plans/plan.model.js +59 -0
- package/dist/modules/plans/plan.model.js.map +1 -0
- package/dist/modules/surveys/survey.model.d.ts +30 -0
- package/dist/modules/surveys/survey.model.js +75 -0
- package/dist/modules/surveys/survey.model.js.map +1 -0
- package/dist/modules/surveys/survey.routes.d.ts +2 -0
- package/dist/modules/surveys/survey.routes.js +153 -0
- package/dist/modules/surveys/survey.routes.js.map +1 -0
- package/dist/modules/tenants/tenant.model.d.ts +86 -0
- package/dist/modules/tenants/tenant.model.js +127 -0
- package/dist/modules/tenants/tenant.model.js.map +1 -0
- package/dist/modules/tenants/tenant.routes.d.ts +2 -0
- package/dist/modules/tenants/tenant.routes.js +65 -0
- package/dist/modules/tenants/tenant.routes.js.map +1 -0
- package/dist/modules/users/user.routes.d.ts +2 -0
- package/dist/modules/users/user.routes.js +106 -0
- package/dist/modules/users/user.routes.js.map +1 -0
- package/dist/modules/webhooks/elevenlabs-tool.routes.d.ts +20 -0
- package/dist/modules/webhooks/elevenlabs-tool.routes.js +85 -0
- package/dist/modules/webhooks/elevenlabs-tool.routes.js.map +1 -0
- package/dist/modules/webhooks/elevenlabs-tool.service.d.ts +11 -0
- package/dist/modules/webhooks/elevenlabs-tool.service.js +360 -0
- package/dist/modules/webhooks/elevenlabs-tool.service.js.map +1 -0
- package/dist/modules/webhooks/elevenlabs.routes.d.ts +2 -0
- package/dist/modules/webhooks/elevenlabs.routes.js +34 -0
- package/dist/modules/webhooks/elevenlabs.routes.js.map +1 -0
- package/dist/modules/webhooks/elevenlabs.service.d.ts +6 -0
- package/dist/modules/webhooks/elevenlabs.service.js +512 -0
- package/dist/modules/webhooks/elevenlabs.service.js.map +1 -0
- package/dist/modules/webhooks/unipile.routes.d.ts +2 -0
- package/dist/modules/webhooks/unipile.routes.js +780 -0
- package/dist/modules/webhooks/unipile.routes.js.map +1 -0
- package/dist/modules/whatsapp/appointment.model.d.ts +27 -0
- package/dist/modules/whatsapp/appointment.model.js +58 -0
- package/dist/modules/whatsapp/appointment.model.js.map +1 -0
- package/dist/modules/whatsapp/operator-request.model.d.ts +29 -0
- package/dist/modules/whatsapp/operator-request.model.js +65 -0
- package/dist/modules/whatsapp/operator-request.model.js.map +1 -0
- package/dist/modules/whatsapp/stt-usage.model.d.ts +16 -0
- package/dist/modules/whatsapp/stt-usage.model.js +53 -0
- package/dist/modules/whatsapp/stt-usage.model.js.map +1 -0
- package/dist/modules/whatsapp/whatsapp-chat.model.d.ts +23 -0
- package/dist/modules/whatsapp/whatsapp-chat.model.js +55 -0
- package/dist/modules/whatsapp/whatsapp-chat.model.js.map +1 -0
- package/dist/modules/whatsapp/whatsapp-contact-profile.model.d.ts +23 -0
- package/dist/modules/whatsapp/whatsapp-contact-profile.model.js +54 -0
- package/dist/modules/whatsapp/whatsapp-contact-profile.model.js.map +1 -0
- package/dist/modules/whatsapp/whatsapp-message.model.d.ts +30 -0
- package/dist/modules/whatsapp/whatsapp-message.model.js +52 -0
- package/dist/modules/whatsapp/whatsapp-message.model.js.map +1 -0
- package/dist/modules/whatsapp/whatsapp-session.model.d.ts +33 -0
- package/dist/modules/whatsapp/whatsapp-session.model.js +65 -0
- package/dist/modules/whatsapp/whatsapp-session.model.js.map +1 -0
- package/dist/modules/whatsapp/whatsapp.routes.d.ts +2 -0
- package/dist/modules/whatsapp/whatsapp.routes.js +1237 -0
- package/dist/modules/whatsapp/whatsapp.routes.js.map +1 -0
- package/dist/plugins/cors.d.ts +3 -0
- package/dist/plugins/cors.js +11 -0
- package/dist/plugins/cors.js.map +1 -0
- package/dist/plugins/jwt.d.ts +3 -0
- package/dist/plugins/jwt.js +22 -0
- package/dist/plugins/jwt.js.map +1 -0
- package/dist/plugins/rawBody.d.ts +3 -0
- package/dist/plugins/rawBody.js +16 -0
- package/dist/plugins/rawBody.js.map +1 -0
- package/dist/plugins/rbac.d.ts +5 -0
- package/dist/plugins/rbac.js +29 -0
- package/dist/plugins/rbac.js.map +1 -0
- package/dist/routes/admin.routes.d.ts +2 -0
- package/dist/routes/admin.routes.js +169 -0
- package/dist/routes/admin.routes.js.map +1 -0
- package/dist/routes/health.routes.d.ts +2 -0
- package/dist/routes/health.routes.js +16 -0
- package/dist/routes/health.routes.js.map +1 -0
- package/dist/routes/webhook.routes.d.ts +2 -0
- package/dist/routes/webhook.routes.js +17 -0
- package/dist/routes/webhook.routes.js.map +1 -0
- package/dist/services/ai/base.ai.d.ts +19 -0
- package/dist/services/ai/base.ai.js +120 -0
- package/dist/services/ai/base.ai.js.map +1 -0
- package/dist/services/ai/gemini.service.d.ts +11 -0
- package/dist/services/ai/gemini.service.js +43 -0
- package/dist/services/ai/gemini.service.js.map +1 -0
- package/dist/services/ai/index.d.ts +2 -0
- package/dist/services/ai/index.js +26 -0
- package/dist/services/ai/index.js.map +1 -0
- package/dist/services/ai/openai.service.d.ts +11 -0
- package/dist/services/ai/openai.service.js +50 -0
- package/dist/services/ai/openai.service.js.map +1 -0
- package/dist/services/elevenlabs.service.d.ts +52 -0
- package/dist/services/elevenlabs.service.js +447 -0
- package/dist/services/elevenlabs.service.js.map +1 -0
- package/dist/services/google-calendar.service.d.ts +60 -0
- package/dist/services/google-calendar.service.js +494 -0
- package/dist/services/google-calendar.service.js.map +1 -0
- package/dist/services/inbound-call-schedule.service.d.ts +11 -0
- package/dist/services/inbound-call-schedule.service.js +162 -0
- package/dist/services/inbound-call-schedule.service.js.map +1 -0
- package/dist/services/netgsm.service.d.ts +41 -0
- package/dist/services/netgsm.service.js +89 -0
- package/dist/services/netgsm.service.js.map +1 -0
- package/dist/services/unipile.service.d.ts +41 -0
- package/dist/services/unipile.service.js +149 -0
- package/dist/services/unipile.service.js.map +1 -0
- package/dist/services/whatsapp-agent.service.d.ts +139 -0
- package/dist/services/whatsapp-agent.service.js +2055 -0
- package/dist/services/whatsapp-agent.service.js.map +1 -0
- package/dist/services/whatsapp.service.d.ts +26 -0
- package/dist/services/whatsapp.service.js +206 -0
- package/dist/services/whatsapp.service.js.map +1 -0
- package/dist/templates/index.d.ts +39 -0
- package/dist/templates/index.js +35 -0
- package/dist/templates/index.js.map +1 -0
- package/dist/templates/receptionist.d.ts +2 -0
- package/dist/templates/receptionist.js +39 -0
- package/dist/templates/receptionist.js.map +1 -0
- package/dist/templates/survey.d.ts +2 -0
- package/dist/templates/survey.js +41 -0
- package/dist/templates/survey.js.map +1 -0
- package/dist/types/index.d.ts +173 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/logger.d.ts +3 -0
- package/dist/utils/logger.js +105 -0
- package/dist/utils/logger.js.map +1 -0
- package/docker-compose.nestjs.yml +89 -0
- package/docker-compose.yml +78 -0
- package/docs/AI_AGENT_ENHANCEMENT_PLAN.md +164 -0
- package/docs/API.md +1193 -0
- package/docs/API_ENDPOINTS.md +344 -0
- package/docs/ARCHITECTURE.md +305 -0
- package/docs/AUTH_API.md +252 -0
- package/docs/BILLING_SMS_ALERTS.md +94 -0
- package/docs/CHAT_ASSIGNMENT_SYSTEM.md +118 -0
- package/docs/CLIENT_TOOLS_AND_FEATURES.md +337 -0
- package/docs/ELEVENLABS_WEBHOOK_TOOLS.md +644 -0
- package/docs/FRONTEND_CHECKLIST.md +227 -0
- package/docs/IMPLEMENTATION_STATUS.md +470 -0
- package/docs/MIGRATION_GUIDE.md +96 -0
- package/docs/MISSINGS_REPORT.md +507 -0
- package/docs/NESTJS_MIGRATION_REFERENCE.md +5136 -0
- package/docs/PROJECT_DESCRIPTION.md +1038 -0
- package/docs/SCALING.md +148 -0
- package/docs/SESSION_SUMMARY_2026_03_17.md +135 -0
- package/docs/WHATSAPP_AGENT.md +1086 -0
- package/docs/architecture/00-SYSTEM-OVERVIEW.md +318 -0
- package/docs/architecture/01-DATABASE-SCHEMA.md +2564 -0
- package/docs/architecture/02-AUTHENTICATION.md +1040 -0
- package/docs/architecture/03-MULTI-CLINIC.md +742 -0
- package/docs/architecture/04-WHATSAPP-AGENT.md +608 -0
- package/docs/architecture/05-OPERATOR-WORKFLOW.md +444 -0
- package/docs/architecture/06-BAILEYS-MICROSERVICE.md +616 -0
- package/docs/architecture/07-APPOINTMENTS.md +849 -0
- package/docs/architecture/08-VOICE-CALLS.md +470 -0
- package/docs/architecture/09-OUTBOUND-CAMPAIGNS.md +542 -0
- package/docs/architecture/10-CLIENT-TOOLS.md +665 -0
- package/docs/architecture/11-BILLING.md +458 -0
- package/docs/architecture/12-SECURITY.md +216 -0
- package/docs/architecture/13-LOGGING-AUDIT.md +549 -0
- package/docs/architecture/14-META-BUSINESS-API.md +454 -0
- package/docs/architecture/15-AI-MODULE.md +479 -0
- package/docs/architecture/16-BACKGROUND-JOBS.md +469 -0
- package/docs/architecture/17-REALTIME-LIVECHAT.md +447 -0
- package/docs/architecture/18-FILE-STORAGE.md +410 -0
- package/docs/architecture/19-PATIENTS.md +1034 -0
- package/docs/architecture/20-TREATMENTS-AND-PLANS.md +774 -0
- package/docs/architecture/21-BEFORE-AFTER-PHOTOS.md +519 -0
- package/docs/database.md +456 -0
- package/docs/ornek-randevu-onay.csv +3 -0
- package/ecosystem.config.js +16 -0
- package/elevenlabs-convai-api-reference.md +1171 -0
- package/frontend/.dockerignore +2 -0
- package/frontend/Dockerfile +24 -0
- package/frontend/README.md +75 -0
- package/frontend/components.json +25 -0
- package/frontend/eslint.config.js +23 -0
- package/frontend/index.html +13 -0
- package/frontend/nginx.conf +37 -0
- package/frontend/package-lock.json +8709 -0
- package/frontend/package.json +71 -0
- package/frontend/public/favicon.svg +1 -0
- package/frontend/public/icons.svg +24 -0
- package/frontend/src/App.tsx +125 -0
- package/frontend/src/components/error-boundary.tsx +50 -0
- package/frontend/src/components/shared/activity-timeline.tsx +66 -0
- package/frontend/src/components/shared/appointment-calendar.css +80 -0
- package/frontend/src/components/shared/appointment-calendar.tsx +245 -0
- package/frontend/src/components/shared/chat-bubble.tsx +72 -0
- package/frontend/src/components/shared/combobox.tsx +119 -0
- package/frontend/src/components/shared/confirm-dialog.tsx +57 -0
- package/frontend/src/components/shared/data-table-pagination.tsx +97 -0
- package/frontend/src/components/shared/data-table-toolbar.tsx +39 -0
- package/frontend/src/components/shared/empty-state.tsx +27 -0
- package/frontend/src/components/shared/file-upload.tsx +140 -0
- package/frontend/src/components/shared/index.ts +20 -0
- package/frontend/src/components/shared/language-switcher.tsx +29 -0
- package/frontend/src/components/shared/notification-dropdown.tsx +115 -0
- package/frontend/src/components/shared/page-header.tsx +23 -0
- package/frontend/src/components/shared/stat-card.tsx +37 -0
- package/frontend/src/components/shared/status-badge.tsx +70 -0
- package/frontend/src/components/shared/status-dot.tsx +43 -0
- package/frontend/src/components/ui/alert-dialog.tsx +187 -0
- package/frontend/src/components/ui/alert.tsx +76 -0
- package/frontend/src/components/ui/avatar.tsx +109 -0
- package/frontend/src/components/ui/badge.tsx +52 -0
- package/frontend/src/components/ui/breadcrumb.tsx +125 -0
- package/frontend/src/components/ui/button.tsx +60 -0
- package/frontend/src/components/ui/calendar.tsx +219 -0
- package/frontend/src/components/ui/card.tsx +103 -0
- package/frontend/src/components/ui/chart.tsx +371 -0
- package/frontend/src/components/ui/checkbox.tsx +29 -0
- package/frontend/src/components/ui/collapsible.tsx +19 -0
- package/frontend/src/components/ui/command.tsx +194 -0
- package/frontend/src/components/ui/dialog.tsx +158 -0
- package/frontend/src/components/ui/dropdown-menu.tsx +268 -0
- package/frontend/src/components/ui/input-group.tsx +156 -0
- package/frontend/src/components/ui/input.tsx +20 -0
- package/frontend/src/components/ui/label.tsx +20 -0
- package/frontend/src/components/ui/pagination.tsx +130 -0
- package/frontend/src/components/ui/popover.tsx +90 -0
- package/frontend/src/components/ui/progress.tsx +83 -0
- package/frontend/src/components/ui/radio-group.tsx +36 -0
- package/frontend/src/components/ui/scroll-area.tsx +54 -0
- package/frontend/src/components/ui/select.tsx +199 -0
- package/frontend/src/components/ui/separator.tsx +23 -0
- package/frontend/src/components/ui/sheet.tsx +138 -0
- package/frontend/src/components/ui/sidebar.tsx +723 -0
- package/frontend/src/components/ui/skeleton.tsx +13 -0
- package/frontend/src/components/ui/sonner.tsx +47 -0
- package/frontend/src/components/ui/switch.tsx +30 -0
- package/frontend/src/components/ui/table.tsx +114 -0
- package/frontend/src/components/ui/tabs.tsx +82 -0
- package/frontend/src/components/ui/textarea.tsx +18 -0
- package/frontend/src/components/ui/toggle-group.tsx +89 -0
- package/frontend/src/components/ui/toggle.tsx +43 -0
- package/frontend/src/components/ui/tooltip.tsx +64 -0
- package/frontend/src/hooks/use-mobile.ts +19 -0
- package/frontend/src/i18n/index.ts +20 -0
- package/frontend/src/i18n/locales/en.json +786 -0
- package/frontend/src/i18n/locales/tr.json +786 -0
- package/frontend/src/index.css +134 -0
- package/frontend/src/layouts/admin-layout.tsx +111 -0
- package/frontend/src/layouts/app-header.tsx +130 -0
- package/frontend/src/layouts/app-layout.tsx +19 -0
- package/frontend/src/layouts/app-sidebar.tsx +212 -0
- package/frontend/src/layouts/auth-guard.tsx +31 -0
- package/frontend/src/layouts/mobile-sidebar.tsx +120 -0
- package/frontend/src/lib/api.ts +68 -0
- package/frontend/src/lib/hooks/use-appointments.ts +224 -0
- package/frontend/src/lib/hooks/use-availability-blocks.ts +83 -0
- package/frontend/src/lib/hooks/use-chats.ts +236 -0
- package/frontend/src/lib/hooks/use-clinic-detail.ts +171 -0
- package/frontend/src/lib/hooks/use-clinics.ts +37 -0
- package/frontend/src/lib/hooks/use-doctor-calendar.ts +80 -0
- package/frontend/src/lib/hooks/use-examinations.ts +89 -0
- package/frontend/src/lib/hooks/use-medical-history.ts +52 -0
- package/frontend/src/lib/hooks/use-patients.ts +296 -0
- package/frontend/src/lib/hooks/use-photo-sets.ts +118 -0
- package/frontend/src/lib/hooks/use-treatment-plans.ts +152 -0
- package/frontend/src/lib/hooks/use-treatments.ts +125 -0
- package/frontend/src/lib/hooks/use-users.ts +172 -0
- package/frontend/src/lib/utils.ts +6 -0
- package/frontend/src/main.tsx +17 -0
- package/frontend/src/pages/admin/agents/detail.tsx +774 -0
- package/frontend/src/pages/admin/agents/import.tsx +280 -0
- package/frontend/src/pages/admin/agents/index.tsx +245 -0
- package/frontend/src/pages/admin/ai-playground.tsx +543 -0
- package/frontend/src/pages/appointments/create-appointment-dialog.tsx +390 -0
- package/frontend/src/pages/appointments/index.tsx +860 -0
- package/frontend/src/pages/audit/index.tsx +24 -0
- package/frontend/src/pages/auth/login.tsx +194 -0
- package/frontend/src/pages/billing/index.tsx +24 -0
- package/frontend/src/pages/calendar/index.tsx +704 -0
- package/frontend/src/pages/calendar-connections/index.tsx +295 -0
- package/frontend/src/pages/calls/index.tsx +24 -0
- package/frontend/src/pages/campaigns/index.tsx +24 -0
- package/frontend/src/pages/chats/index.tsx +981 -0
- package/frontend/src/pages/clinics/index.tsx +224 -0
- package/frontend/src/pages/clinics/settings.tsx +412 -0
- package/frontend/src/pages/components-showcase.tsx +773 -0
- package/frontend/src/pages/connections/index.tsx +328 -0
- package/frontend/src/pages/dashboard.tsx +50 -0
- package/frontend/src/pages/leads/index.tsx +24 -0
- package/frontend/src/pages/my-schedule/index.tsx +496 -0
- package/frontend/src/pages/patients/create-patient-dialog.tsx +358 -0
- package/frontend/src/pages/patients/detail.tsx +1195 -0
- package/frontend/src/pages/patients/edit-patient-dialog.tsx +387 -0
- package/frontend/src/pages/patients/examinations-tab.tsx +460 -0
- package/frontend/src/pages/patients/index.tsx +381 -0
- package/frontend/src/pages/patients/medical-history-dialog.tsx +207 -0
- package/frontend/src/pages/patients/photo-sets-tab.tsx +616 -0
- package/frontend/src/pages/patients/timeline-tab.tsx +164 -0
- package/frontend/src/pages/patients/treatment-plans-tab.tsx +598 -0
- package/frontend/src/pages/phone-numbers/detail.tsx +427 -0
- package/frontend/src/pages/phone-numbers/index.tsx +455 -0
- package/frontend/src/pages/platform/index.tsx +454 -0
- package/frontend/src/pages/settings/index.tsx +126 -0
- package/frontend/src/pages/treatments/index.tsx +487 -0
- package/frontend/src/pages/users/doctor-profile.tsx +672 -0
- package/frontend/src/pages/users/edit.tsx +329 -0
- package/frontend/src/pages/users/index.tsx +407 -0
- package/frontend/src/pages/validation/index.tsx +24 -0
- package/frontend/src/stores/auth.store.ts +108 -0
- package/frontend/src/stores/ui.store.ts +41 -0
- package/frontend/tsconfig.app.json +32 -0
- package/frontend/tsconfig.json +13 -0
- package/frontend/tsconfig.node.json +26 -0
- package/frontend/vite.config.ts +29 -0
- package/nestjs/.dockerignore +5 -0
- package/nestjs/.env.docker +64 -0
- package/nestjs/.prettierrc +4 -0
- package/nestjs/Dockerfile +36 -0
- package/nestjs/README.md +98 -0
- package/nestjs/eslint.config.mjs +35 -0
- package/nestjs/nest-cli.json +8 -0
- package/nestjs/package-lock.json +13390 -0
- package/nestjs/package.json +114 -0
- package/nestjs/prisma/migrations/20260409161536_add_message_metadata_fields/migration.sql +1746 -0
- package/nestjs/prisma/migrations/20260410140436_add_agent_ai_fields/migration.sql +36 -0
- package/nestjs/prisma/migrations/20260410175519_add_agent_clinic_assignments/migration.sql +21 -0
- package/nestjs/prisma/migrations/20260412094344_make_agent_tenant_optional/migration.sql +2 -0
- package/nestjs/prisma/migrations/20260412110008_add_admin_chat_sessions/migration.sql +47 -0
- package/nestjs/prisma/migrations/migration_lock.toml +3 -0
- package/nestjs/prisma/schema.prisma +1843 -0
- package/nestjs/prisma/seed.ts +375 -0
- package/nestjs/prisma.config.ts +14 -0
- package/nestjs/src/admin/admin.controller.ts +27 -0
- package/nestjs/src/admin/admin.module.ts +16 -0
- package/nestjs/src/admin/admin.service.ts +91 -0
- package/nestjs/src/admin/ai-chat-session.service.ts +454 -0
- package/nestjs/src/admin/ai-test.controller.ts +191 -0
- package/nestjs/src/admin/superadmin.controller.ts +106 -0
- package/nestjs/src/agents/agents.controller.ts +262 -0
- package/nestjs/src/agents/agents.module.ts +13 -0
- package/nestjs/src/agents/agents.service.ts +733 -0
- package/nestjs/src/agents/dto/create-agent.dto.ts +99 -0
- package/nestjs/src/agents/dto/index.ts +2 -0
- package/nestjs/src/agents/dto/update-agent.dto.ts +148 -0
- package/nestjs/src/app.module.ts +115 -0
- package/nestjs/src/appointment-validation/appointment-validation.controller.ts +194 -0
- package/nestjs/src/appointment-validation/appointment-validation.module.ts +16 -0
- package/nestjs/src/appointment-validation/appointment-validation.service.ts +450 -0
- package/nestjs/src/appointment-validation/dto/create-batch.dto.ts +105 -0
- package/nestjs/src/appointment-validation/dto/index.ts +1 -0
- package/nestjs/src/appointment-validation/processors/validation-dispatch.processor.ts +26 -0
- package/nestjs/src/appointment-validation/processors/validation-sync.processor.ts +23 -0
- package/nestjs/src/appointments/appointments.controller.ts +268 -0
- package/nestjs/src/appointments/appointments.module.ts +13 -0
- package/nestjs/src/appointments/appointments.service.ts +773 -0
- package/nestjs/src/appointments/dto/create-appointment.dto.ts +72 -0
- package/nestjs/src/appointments/dto/index.ts +4 -0
- package/nestjs/src/appointments/dto/query-appointments.dto.ts +60 -0
- package/nestjs/src/appointments/dto/update-appointment.dto.ts +43 -0
- package/nestjs/src/appointments/dto/update-status.dto.ts +18 -0
- package/nestjs/src/appointments/processors/reminder.processor.ts +243 -0
- package/nestjs/src/audit/audit.controller.ts +84 -0
- package/nestjs/src/audit/audit.decorator.ts +20 -0
- package/nestjs/src/audit/audit.interceptor.ts +67 -0
- package/nestjs/src/audit/audit.interfaces.ts +15 -0
- package/nestjs/src/audit/audit.module.ts +12 -0
- package/nestjs/src/audit/audit.service.ts +177 -0
- package/nestjs/src/auth/auth.controller.ts +116 -0
- package/nestjs/src/auth/auth.module.ts +25 -0
- package/nestjs/src/auth/auth.service.ts +612 -0
- package/nestjs/src/auth/dto/change-password.dto.ts +13 -0
- package/nestjs/src/auth/dto/forgot-password.dto.ts +8 -0
- package/nestjs/src/auth/dto/index.ts +6 -0
- package/nestjs/src/auth/dto/login.dto.ts +13 -0
- package/nestjs/src/auth/dto/refresh.dto.ts +8 -0
- package/nestjs/src/auth/dto/register.dto.ts +28 -0
- package/nestjs/src/auth/dto/reset-password.dto.ts +13 -0
- package/nestjs/src/auth/permissions.config.ts +85 -0
- package/nestjs/src/availability-blocks/availability-blocks.controller.ts +83 -0
- package/nestjs/src/availability-blocks/availability-blocks.module.ts +10 -0
- package/nestjs/src/availability-blocks/availability-blocks.service.ts +202 -0
- package/nestjs/src/billing/billing.controller.ts +104 -0
- package/nestjs/src/billing/billing.module.ts +12 -0
- package/nestjs/src/billing/billing.service.ts +398 -0
- package/nestjs/src/billing/dto/index.ts +2 -0
- package/nestjs/src/billing/dto/query-billing.dto.ts +29 -0
- package/nestjs/src/billing/dto/record-payment.dto.ts +60 -0
- package/nestjs/src/billing/processors/alerts.processor.ts +216 -0
- package/nestjs/src/billing/processors/snapshot.processor.ts +181 -0
- package/nestjs/src/calls/calls.controller.ts +92 -0
- package/nestjs/src/calls/calls.module.ts +10 -0
- package/nestjs/src/calls/calls.service.ts +359 -0
- package/nestjs/src/calls/dto/index.ts +1 -0
- package/nestjs/src/calls/dto/query-calls.dto.ts +46 -0
- package/nestjs/src/clinics/clinics.controller.ts +226 -0
- package/nestjs/src/clinics/clinics.module.ts +11 -0
- package/nestjs/src/clinics/clinics.service.ts +203 -0
- package/nestjs/src/clinics/dto/create-clinic.dto.ts +40 -0
- package/nestjs/src/clinics/dto/create-meta-connection.dto.ts +44 -0
- package/nestjs/src/clinics/dto/index.ts +4 -0
- package/nestjs/src/clinics/dto/update-clinic.dto.ts +133 -0
- package/nestjs/src/clinics/dto/update-meta-connection.dto.ts +22 -0
- package/nestjs/src/clinics/meta-connections.service.ts +210 -0
- package/nestjs/src/common/decorators/accessible-clinics.decorator.ts +9 -0
- package/nestjs/src/common/decorators/current-user.decorator.ts +10 -0
- package/nestjs/src/common/decorators/features.decorator.ts +7 -0
- package/nestjs/src/common/decorators/index.ts +4 -0
- package/nestjs/src/common/decorators/permissions.decorator.ts +13 -0
- package/nestjs/src/common/gateways/events.gateway.ts +157 -0
- package/nestjs/src/common/guards/clinic-access.guard.ts +40 -0
- package/nestjs/src/common/guards/features.guard.ts +38 -0
- package/nestjs/src/common/guards/index.ts +5 -0
- package/nestjs/src/common/guards/jwt-auth.guard.ts +54 -0
- package/nestjs/src/common/guards/permissions.guard.ts +50 -0
- package/nestjs/src/common/guards/superadmin.guard.ts +35 -0
- package/nestjs/src/common/interceptors/request-context.interceptor.ts +32 -0
- package/nestjs/src/common/interceptors/superadmin-tenant.interceptor.ts +42 -0
- package/nestjs/src/common/interfaces/jwt-payload.interface.ts +11 -0
- package/nestjs/src/config/config.module.ts +13 -0
- package/nestjs/src/database/database.module.ts +9 -0
- package/nestjs/src/database/prisma.service.ts +20 -0
- package/nestjs/src/database/tenant-context.ts +27 -0
- package/nestjs/src/google-calendar/google-calendar.controller.ts +259 -0
- package/nestjs/src/google-calendar/google-calendar.module.ts +10 -0
- package/nestjs/src/google-calendar/google-calendar.service.ts +811 -0
- package/nestjs/src/integrations/ai/ai.interface.ts +74 -0
- package/nestjs/src/integrations/ai/ai.module.ts +11 -0
- package/nestjs/src/integrations/ai/ai.service.ts +148 -0
- package/nestjs/src/integrations/ai/providers/anthropic.provider.ts +146 -0
- package/nestjs/src/integrations/ai/providers/openai.provider.ts +158 -0
- package/nestjs/src/integrations/elevenlabs/elevenlabs.module.ts +8 -0
- package/nestjs/src/integrations/elevenlabs/elevenlabs.service.ts +226 -0
- package/nestjs/src/integrations/encryption/encryption.module.ts +9 -0
- package/nestjs/src/integrations/encryption/encryption.service.ts +31 -0
- package/nestjs/src/integrations/image/image.module.ts +9 -0
- package/nestjs/src/integrations/image/image.service.ts +61 -0
- package/nestjs/src/integrations/meta-business/meta-business.module.ts +10 -0
- package/nestjs/src/integrations/meta-business/meta-instagram.service.ts +94 -0
- package/nestjs/src/integrations/meta-business/meta-webhook.service.ts +52 -0
- package/nestjs/src/integrations/meta-business/meta-whatsapp.service.ts +254 -0
- package/nestjs/src/integrations/minio/minio.module.ts +9 -0
- package/nestjs/src/integrations/minio/minio.service.ts +88 -0
- package/nestjs/src/integrations/netgsm/netgsm.module.ts +8 -0
- package/nestjs/src/integrations/netgsm/netgsm.service.ts +17 -0
- package/nestjs/src/integrations/tektippay/tektippay.module.ts +8 -0
- package/nestjs/src/integrations/tektippay/tektippay.service.ts +23 -0
- package/nestjs/src/leads/dto/index.ts +2 -0
- package/nestjs/src/leads/dto/query-leads.dto.ts +50 -0
- package/nestjs/src/leads/dto/update-lead.dto.ts +26 -0
- package/nestjs/src/leads/leads.controller.ts +184 -0
- package/nestjs/src/leads/leads.module.ts +10 -0
- package/nestjs/src/leads/leads.service.ts +375 -0
- package/nestjs/src/logging/logging.controller.ts +82 -0
- package/nestjs/src/logging/logging.module.ts +11 -0
- package/nestjs/src/logging/logging.service.ts +180 -0
- package/nestjs/src/main.ts +86 -0
- package/nestjs/src/outbound-campaigns/dto/create-campaign.dto.ts +47 -0
- package/nestjs/src/outbound-campaigns/dto/index.ts +3 -0
- package/nestjs/src/outbound-campaigns/dto/update-campaign.dto.ts +31 -0
- package/nestjs/src/outbound-campaigns/dto/upload-entries.dto.ts +35 -0
- package/nestjs/src/outbound-campaigns/outbound-campaigns.controller.ts +307 -0
- package/nestjs/src/outbound-campaigns/outbound-campaigns.module.ts +13 -0
- package/nestjs/src/outbound-campaigns/outbound-campaigns.service.ts +471 -0
- package/nestjs/src/outbound-campaigns/processors/campaign-dispatch.processor.ts +366 -0
- package/nestjs/src/patients/documents.service.ts +231 -0
- package/nestjs/src/patients/dto/create-examination.dto.ts +34 -0
- package/nestjs/src/patients/dto/create-note.dto.ts +14 -0
- package/nestjs/src/patients/dto/create-patient.dto.ts +86 -0
- package/nestjs/src/patients/dto/create-photo-set.dto.ts +32 -0
- package/nestjs/src/patients/dto/index.ts +10 -0
- package/nestjs/src/patients/dto/update-examination.dto.ts +29 -0
- package/nestjs/src/patients/dto/update-medical-history.dto.ts +47 -0
- package/nestjs/src/patients/dto/update-patient.dto.ts +87 -0
- package/nestjs/src/patients/dto/update-photo-set.dto.ts +28 -0
- package/nestjs/src/patients/dto/upload-document.dto.ts +31 -0
- package/nestjs/src/patients/dto/upload-photo.dto.ts +27 -0
- package/nestjs/src/patients/examinations.service.ts +271 -0
- package/nestjs/src/patients/medical-history.service.ts +149 -0
- package/nestjs/src/patients/notes.service.ts +172 -0
- package/nestjs/src/patients/patients.controller.ts +485 -0
- package/nestjs/src/patients/patients.module.ts +22 -0
- package/nestjs/src/patients/patients.service.ts +412 -0
- package/nestjs/src/patients/photo-sets.service.ts +389 -0
- package/nestjs/src/phone-numbers/dto/create-phone-number.dto.ts +57 -0
- package/nestjs/src/phone-numbers/dto/index.ts +3 -0
- package/nestjs/src/phone-numbers/dto/update-phone-number.dto.ts +38 -0
- package/nestjs/src/phone-numbers/dto/update-schedule.dto.ts +39 -0
- package/nestjs/src/phone-numbers/phone-numbers.controller.ts +125 -0
- package/nestjs/src/phone-numbers/phone-numbers.module.ts +10 -0
- package/nestjs/src/phone-numbers/phone-numbers.service.ts +209 -0
- package/nestjs/src/plans/dto/create-plan.dto.ts +70 -0
- package/nestjs/src/plans/dto/index.ts +2 -0
- package/nestjs/src/plans/dto/update-plan.dto.ts +80 -0
- package/nestjs/src/plans/plans.controller.ts +50 -0
- package/nestjs/src/plans/plans.module.ts +10 -0
- package/nestjs/src/plans/plans.service.ts +115 -0
- package/nestjs/src/platform/dto/create-tenant.dto.ts +36 -0
- package/nestjs/src/platform/dto/index.ts +2 -0
- package/nestjs/src/platform/dto/update-tenant-platform.dto.ts +44 -0
- package/nestjs/src/platform/platform.controller.ts +79 -0
- package/nestjs/src/platform/platform.module.ts +10 -0
- package/nestjs/src/platform/platform.service.ts +301 -0
- package/nestjs/src/queue/queue.module.ts +56 -0
- package/nestjs/src/redis/redis.module.ts +20 -0
- package/nestjs/src/tenants/dto/index.ts +1 -0
- package/nestjs/src/tenants/dto/update-tenant.dto.ts +15 -0
- package/nestjs/src/tenants/tenants.controller.ts +45 -0
- package/nestjs/src/tenants/tenants.module.ts +10 -0
- package/nestjs/src/tenants/tenants.service.ts +41 -0
- package/nestjs/src/tools/adapters/elevenlabs-http.adapter.ts +51 -0
- package/nestjs/src/tools/adapters/elevenlabs-ws.adapter.ts +59 -0
- package/nestjs/src/tools/handlers/calendar.tools.ts +441 -0
- package/nestjs/src/tools/handlers/notification.tools.ts +34 -0
- package/nestjs/src/tools/handlers/operator.tools.ts +303 -0
- package/nestjs/src/tools/handlers/patient.tools.ts +242 -0
- package/nestjs/src/tools/handlers/payment.tools.ts +43 -0
- package/nestjs/src/tools/handlers/validation.tools.ts +152 -0
- package/nestjs/src/tools/tool-registry.service.ts +221 -0
- package/nestjs/src/tools/tool.decorator.ts +16 -0
- package/nestjs/src/tools/tool.interfaces.ts +26 -0
- package/nestjs/src/tools/tools.module.ts +50 -0
- package/nestjs/src/treatments/dto/create-plan-item.dto.ts +27 -0
- package/nestjs/src/treatments/dto/create-treatment-plan.dto.ts +69 -0
- package/nestjs/src/treatments/dto/create-treatment.dto.ts +59 -0
- package/nestjs/src/treatments/dto/index.ts +6 -0
- package/nestjs/src/treatments/dto/update-plan-item.dto.ts +23 -0
- package/nestjs/src/treatments/dto/update-treatment-plan.dto.ts +22 -0
- package/nestjs/src/treatments/dto/update-treatment.dto.ts +70 -0
- package/nestjs/src/treatments/treatment-plans.service.ts +362 -0
- package/nestjs/src/treatments/treatments.controller.ts +265 -0
- package/nestjs/src/treatments/treatments.module.ts +14 -0
- package/nestjs/src/treatments/treatments.service.ts +165 -0
- package/nestjs/src/users/doctor-profiles.service.ts +202 -0
- package/nestjs/src/users/dto/index.ts +4 -0
- package/nestjs/src/users/dto/invite-user.dto.ts +52 -0
- package/nestjs/src/users/dto/update-clinic-assignments.dto.ts +9 -0
- package/nestjs/src/users/dto/update-doctor-profile.dto.ts +49 -0
- package/nestjs/src/users/dto/update-user.dto.ts +41 -0
- package/nestjs/src/users/users.controller.ts +142 -0
- package/nestjs/src/users/users.module.ts +11 -0
- package/nestjs/src/users/users.service.ts +250 -0
- package/nestjs/src/webhooks/elevenlabs-tool.controller.ts +66 -0
- package/nestjs/src/webhooks/elevenlabs-webhook.controller.ts +60 -0
- package/nestjs/src/webhooks/meta-webhook.controller.ts +178 -0
- package/nestjs/src/webhooks/processors/elevenlabs-webhook.processor.ts +28 -0
- package/nestjs/src/webhooks/webhooks.module.ts +17 -0
- package/nestjs/src/whatsapp/chat-context.service.ts +281 -0
- package/nestjs/src/whatsapp/dto/add-blacklist.dto.ts +13 -0
- package/nestjs/src/whatsapp/dto/index.ts +2 -0
- package/nestjs/src/whatsapp/dto/send-message.dto.ts +14 -0
- package/nestjs/src/whatsapp/listeners/meta-message.listener.ts +579 -0
- package/nestjs/src/whatsapp/meta-auth.controller.ts +268 -0
- package/nestjs/src/whatsapp/meta-instagram-auth.controller.ts +244 -0
- package/nestjs/src/whatsapp/operator.service.ts +692 -0
- package/nestjs/src/whatsapp/processors/cost-sweep.processor.ts +130 -0
- package/nestjs/src/whatsapp/processors/grace.processor.ts +191 -0
- package/nestjs/src/whatsapp/processors/message-buffer.processor.ts +138 -0
- package/nestjs/src/whatsapp/processors/message-cleanup.processor.ts +148 -0
- package/nestjs/src/whatsapp/processors/meta-token-refresh.processor.ts +114 -0
- package/nestjs/src/whatsapp/processors/operator-expiry.processor.ts +105 -0
- package/nestjs/src/whatsapp/processors/profile-update.processor.ts +234 -0
- package/nestjs/src/whatsapp/processors/session-cleanup.processor.ts +178 -0
- package/nestjs/src/whatsapp/processors/session-labels.processor.ts +248 -0
- package/nestjs/src/whatsapp/whatsapp-agent.service.ts +2506 -0
- package/nestjs/src/whatsapp/whatsapp-recovery.service.ts +117 -0
- package/nestjs/src/whatsapp/whatsapp.controller.ts +398 -0
- package/nestjs/src/whatsapp/whatsapp.module.ts +51 -0
- package/nestjs/src/whatsapp/whatsapp.service.ts +592 -0
- package/nestjs/test/app.e2e-spec.ts +25 -0
- package/nestjs/test/jest-e2e.json +9 -0
- package/nestjs/tsconfig.build.json +4 -0
- package/nestjs/tsconfig.json +25 -0
- package/nginx.example.conf +18 -0
- package/package.json +47 -0
- package/scripts/addRecipient.ts +48 -0
- package/scripts/listRecipients.ts +31 -0
- package/scripts/migrate-agent-ref.ts +86 -0
- package/scripts/migrate-sessions.ts +183 -0
- package/scripts/promote.ts +27 -0
- package/scripts/retrigger.ts +84 -0
- package/scripts/seed.ts +435 -0
- package/scripts/testSend.ts +63 -0
- package/src/app.ts +85 -0
- package/src/config/agentPrompts.json +19 -0
- package/src/config/database.ts +21 -0
- package/src/config/env.ts +94 -0
- package/src/config/index.ts +86 -0
- package/src/controllers/webhook.controller.ts +150 -0
- package/src/errors/index.ts +9 -0
- package/src/hooks/webhookValidator.ts +55 -0
- package/src/index.ts +68 -0
- package/src/migrations/001_session-architecture.ts +138 -0
- package/src/migrations/002_agent-ref.ts +65 -0
- package/src/migrations/003_shift-schedule.ts +55 -0
- package/src/migrations/004_invert-shift-to-clinic-hours.ts +30 -0
- package/src/migrations/005_composite-baileys-chat-ids.ts +60 -0
- package/src/migrations/migration.model.ts +27 -0
- package/src/migrations/migration.routes.ts +40 -0
- package/src/migrations/migration.runner.ts +112 -0
- package/src/models/ConversationClaim.ts +17 -0
- package/src/models/ConversationEvaluation.ts +91 -0
- package/src/models/Summary.ts +77 -0
- package/src/models/Transcription.ts +68 -0
- package/src/models/WhatsAppRecipient.ts +37 -0
- package/src/modules/admin/admin.routes.ts +2385 -0
- package/src/modules/admin/elevenlabs-test-chat.routes.ts +193 -0
- package/src/modules/admin/whatsapp-test-chat.routes.ts +244 -0
- package/src/modules/agents/agent.model.ts +93 -0
- package/src/modules/agents/agent.routes.ts +65 -0
- package/src/modules/appointment-validation/appointment-validation.model.ts +163 -0
- package/src/modules/appointment-validation/appointment-validation.routes.ts +275 -0
- package/src/modules/appointment-validation/appointment-validation.service.ts +1028 -0
- package/src/modules/auth/auth.model.ts +42 -0
- package/src/modules/auth/auth.routes.ts +199 -0
- package/src/modules/auth/auth.service.ts +210 -0
- package/src/modules/auth/refresh-token.model.ts +26 -0
- package/src/modules/billing/billing-alert.model.ts +28 -0
- package/src/modules/billing/billing-period-snapshot.model.ts +68 -0
- package/src/modules/billing/billing.model.ts +42 -0
- package/src/modules/billing/billing.routes.ts +67 -0
- package/src/modules/billing/billing.service.ts +562 -0
- package/src/modules/billing/payment.model.ts +42 -0
- package/src/modules/calls/call.model.ts +102 -0
- package/src/modules/calls/call.routes.ts +118 -0
- package/src/modules/campaigns/campaign.model.ts +111 -0
- package/src/modules/campaigns/campaign.routes.ts +402 -0
- package/src/modules/campaigns/campaign.service.ts +99 -0
- package/src/modules/google-calendar/google-calendar.routes.ts +31 -0
- package/src/modules/inbound-call/inbound-call-config.model.ts +49 -0
- package/src/modules/inbound-call/inbound-call.routes.ts +289 -0
- package/src/modules/leads/lead.model.ts +40 -0
- package/src/modules/leads/lead.routes.ts +246 -0
- package/src/modules/logs/log.model.ts +27 -0
- package/src/modules/logs/log.routes.ts +102 -0
- package/src/modules/plans/plan.model.ts +45 -0
- package/src/modules/surveys/survey.model.ts +70 -0
- package/src/modules/surveys/survey.routes.ts +187 -0
- package/src/modules/tenants/tenant.model.ts +181 -0
- package/src/modules/tenants/tenant.routes.ts +78 -0
- package/src/modules/users/user.routes.ts +126 -0
- package/src/modules/webhooks/elevenlabs-tool.routes.ts +94 -0
- package/src/modules/webhooks/elevenlabs-tool.service.ts +491 -0
- package/src/modules/webhooks/elevenlabs.routes.ts +34 -0
- package/src/modules/webhooks/elevenlabs.service.ts +565 -0
- package/src/modules/webhooks/unipile.routes.ts +917 -0
- package/src/modules/whatsapp/appointment.model.ts +47 -0
- package/src/modules/whatsapp/operator-request.model.ts +58 -0
- package/src/modules/whatsapp/stt-usage.model.ts +30 -0
- package/src/modules/whatsapp/whatsapp-chat.model.ts +39 -0
- package/src/modules/whatsapp/whatsapp-contact-profile.model.ts +41 -0
- package/src/modules/whatsapp/whatsapp-message.model.ts +41 -0
- package/src/modules/whatsapp/whatsapp-session.model.ts +60 -0
- package/src/modules/whatsapp/whatsapp.routes.ts +1435 -0
- package/src/plugins/cors.ts +7 -0
- package/src/plugins/jwt.ts +18 -0
- package/src/plugins/rawBody.ts +12 -0
- package/src/plugins/rbac.ts +24 -0
- package/src/routes/admin.routes.ts +208 -0
- package/src/routes/health.routes.ts +12 -0
- package/src/routes/webhook.routes.ts +12 -0
- package/src/services/ai/base.ai.ts +132 -0
- package/src/services/ai/gemini.service.ts +41 -0
- package/src/services/ai/index.ts +24 -0
- package/src/services/ai/openai.service.ts +48 -0
- package/src/services/elevenlabs.service.ts +532 -0
- package/src/services/google-calendar.service.ts +656 -0
- package/src/services/inbound-call-schedule.service.ts +174 -0
- package/src/services/netgsm.service.ts +128 -0
- package/src/services/unipile.service.ts +200 -0
- package/src/services/whatsapp-agent.service.ts +2479 -0
- package/src/services/whatsapp.service.ts +245 -0
- package/src/templates/index.ts +71 -0
- package/src/templates/receptionist.ts +44 -0
- package/src/templates/survey.ts +44 -0
- package/src/types/index.ts +218 -0
- package/src/utils/logger.ts +83 -0
- package/tsconfig.json +19 -0
- package/web/.dockerignore +4 -0
- package/web/Dockerfile +18 -0
- package/web/README.md +73 -0
- package/web/components.json +23 -0
- package/web/eslint.config.js +23 -0
- package/web/index.html +14 -0
- package/web/nginx.conf +18 -0
- package/web/package-lock.json +10292 -0
- package/web/package.json +48 -0
- package/web/public/favicon.ico +0 -0
- package/web/public/vite.svg +1 -0
- package/web/src/App.tsx +191 -0
- package/web/src/assets/react.svg +1 -0
- package/web/src/components/Layout.tsx +261 -0
- package/web/src/components/LeadConversation.tsx +251 -0
- package/web/src/components/ProtectedRoute.tsx +20 -0
- package/web/src/components/conversation-review/CardAudioPlayer.tsx +200 -0
- package/web/src/components/conversation-review/CardEvaluation.tsx +351 -0
- package/web/src/components/conversation-review/CardMetadata.tsx +44 -0
- package/web/src/components/conversation-review/ConversationCard.tsx +95 -0
- package/web/src/components/conversation-review/ReviewContainer.tsx +120 -0
- package/web/src/components/conversation-review/ReviewFilters.tsx +88 -0
- package/web/src/components/empty-state.tsx +15 -0
- package/web/src/components/page-header.tsx +19 -0
- package/web/src/components/page-loader.tsx +32 -0
- package/web/src/components/pagination.tsx +38 -0
- package/web/src/components/stat-card.tsx +27 -0
- package/web/src/components/status-badge.tsx +125 -0
- package/web/src/components/ui/alert.tsx +66 -0
- package/web/src/components/ui/badge.tsx +48 -0
- package/web/src/components/ui/button.tsx +64 -0
- package/web/src/components/ui/card.tsx +92 -0
- package/web/src/components/ui/checkbox.tsx +32 -0
- package/web/src/components/ui/dialog.tsx +158 -0
- package/web/src/components/ui/dropdown-menu.tsx +255 -0
- package/web/src/components/ui/input.tsx +21 -0
- package/web/src/components/ui/label.tsx +22 -0
- package/web/src/components/ui/progress.tsx +29 -0
- package/web/src/components/ui/select.tsx +188 -0
- package/web/src/components/ui/separator.tsx +28 -0
- package/web/src/components/ui/sheet.tsx +123 -0
- package/web/src/components/ui/skeleton.tsx +13 -0
- package/web/src/components/ui/sonner.tsx +35 -0
- package/web/src/components/ui/table.tsx +116 -0
- package/web/src/components/ui/tabs.tsx +89 -0
- package/web/src/components/ui/textarea.tsx +18 -0
- package/web/src/components/ui/tooltip.tsx +57 -0
- package/web/src/components/whatsapp/ChatDetail.tsx +417 -0
- package/web/src/components/whatsapp/ChatHeader.tsx +78 -0
- package/web/src/components/whatsapp/ChatList.tsx +107 -0
- package/web/src/components/whatsapp/ChatListItem.tsx +60 -0
- package/web/src/components/whatsapp/MessageBubble.tsx +46 -0
- package/web/src/components/whatsapp/MessageInput.tsx +63 -0
- package/web/src/components/whatsapp/MessageStream.tsx +135 -0
- package/web/src/components/whatsapp/SessionDivider.tsx +65 -0
- package/web/src/components/whatsapp/SessionHistory.tsx +119 -0
- package/web/src/components/whatsapp/settings/AiSettingsTab.tsx +268 -0
- package/web/src/components/whatsapp/settings/CalendarTab.tsx +339 -0
- package/web/src/components/whatsapp/settings/ConnectionTab.tsx +236 -0
- package/web/src/components/whatsapp/settings/NotificationsTab.tsx +109 -0
- package/web/src/components/whatsapp/settings/OperatorTab.tsx +303 -0
- package/web/src/contexts/AuthContext.tsx +103 -0
- package/web/src/index.css +130 -0
- package/web/src/lib/api.ts +92 -0
- package/web/src/lib/utils.ts +6 -0
- package/web/src/main.tsx +10 -0
- package/web/src/pages/AppointmentDetail.tsx +206 -0
- package/web/src/pages/AppointmentValidation.tsx +157 -0
- package/web/src/pages/AppointmentValidationDetail.tsx +617 -0
- package/web/src/pages/AppointmentValidationNew.tsx +1005 -0
- package/web/src/pages/Appointments.tsx +283 -0
- package/web/src/pages/Billing.tsx +126 -0
- package/web/src/pages/CallDetail.tsx +293 -0
- package/web/src/pages/CallSettings.tsx +313 -0
- package/web/src/pages/Calls.tsx +188 -0
- package/web/src/pages/CampaignDetail.tsx +216 -0
- package/web/src/pages/CampaignNew.tsx +277 -0
- package/web/src/pages/CampaignResults.tsx +185 -0
- package/web/src/pages/Campaigns.tsx +171 -0
- package/web/src/pages/Dashboard.tsx +336 -0
- package/web/src/pages/InboundSchedule.tsx +246 -0
- package/web/src/pages/LeadDetail.tsx +183 -0
- package/web/src/pages/Leads.tsx +258 -0
- package/web/src/pages/Login.tsx +99 -0
- package/web/src/pages/Register.tsx +129 -0
- package/web/src/pages/Settings.tsx +133 -0
- package/web/src/pages/SurveyDetail.tsx +232 -0
- package/web/src/pages/SurveyPreview.tsx +179 -0
- package/web/src/pages/Surveys.tsx +207 -0
- package/web/src/pages/Users.tsx +199 -0
- package/web/src/pages/WhatsApp.tsx +147 -0
- package/web/src/pages/WhatsAppSettings.tsx +215 -0
- package/web/src/pages/admin/AdminBaileysMessageLog.tsx +331 -0
- package/web/src/pages/admin/AdminBaileysRawMessages.tsx +318 -0
- package/web/src/pages/admin/AdminConversationReview.tsx +116 -0
- package/web/src/pages/admin/AdminCredits.tsx +467 -0
- package/web/src/pages/admin/AdminElevenLabsAgentDetail.tsx +332 -0
- package/web/src/pages/admin/AdminElevenLabsAgents.tsx +164 -0
- package/web/src/pages/admin/AdminElevenLabsBatchCallDetail.tsx +214 -0
- package/web/src/pages/admin/AdminElevenLabsBatchCalls.tsx +293 -0
- package/web/src/pages/admin/AdminElevenLabsConversationDetail.tsx +230 -0
- package/web/src/pages/admin/AdminElevenLabsConversations.tsx +228 -0
- package/web/src/pages/admin/AdminElevenLabsInboundCalls.tsx +293 -0
- package/web/src/pages/admin/AdminElevenLabsPhoneNumbers.tsx +506 -0
- package/web/src/pages/admin/AdminElevenLabsTestChat.tsx +258 -0
- package/web/src/pages/admin/AdminElevenLabsWebhooks.tsx +289 -0
- package/web/src/pages/admin/AdminEvaluationDashboard.tsx +520 -0
- package/web/src/pages/admin/AdminLeads.tsx +339 -0
- package/web/src/pages/admin/AdminLogs.tsx +283 -0
- package/web/src/pages/admin/AdminMigrations.tsx +247 -0
- package/web/src/pages/admin/AdminPlans.tsx +313 -0
- package/web/src/pages/admin/AdminSystem.tsx +391 -0
- package/web/src/pages/admin/AdminTenantBillableItems.tsx +464 -0
- package/web/src/pages/admin/AdminTenantDetail.tsx +1317 -0
- package/web/src/pages/admin/AdminTenants.tsx +274 -0
- package/web/src/pages/admin/AdminWhatsApp.tsx +618 -0
- package/web/src/pages/admin/AdminWhatsAppTestChat.tsx +328 -0
- package/web/src/types/index.ts +242 -0
- package/web/tsconfig.app.json +32 -0
- package/web/tsconfig.json +13 -0
- package/web/tsconfig.node.json +26 -0
- package/web/vite.config.ts +23 -0
|
@@ -0,0 +1,774 @@
|
|
|
1
|
+
import { useState, useEffect } from "react"
|
|
2
|
+
import { useParams, useNavigate } from "react-router-dom"
|
|
3
|
+
import { useTranslation } from "react-i18next"
|
|
4
|
+
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query"
|
|
5
|
+
import { toast } from "sonner"
|
|
6
|
+
import {
|
|
7
|
+
ArrowLeft,
|
|
8
|
+
Bot,
|
|
9
|
+
Building2,
|
|
10
|
+
Loader2,
|
|
11
|
+
Save,
|
|
12
|
+
Zap,
|
|
13
|
+
Brain,
|
|
14
|
+
MessageSquare,
|
|
15
|
+
Settings,
|
|
16
|
+
FileText,
|
|
17
|
+
History,
|
|
18
|
+
RefreshCw,
|
|
19
|
+
Radio,
|
|
20
|
+
Link,
|
|
21
|
+
Thermometer,
|
|
22
|
+
} from "lucide-react"
|
|
23
|
+
|
|
24
|
+
import { api } from "@/lib/api"
|
|
25
|
+
import { Button } from "@/components/ui/button"
|
|
26
|
+
import { Input } from "@/components/ui/input"
|
|
27
|
+
import { Label } from "@/components/ui/label"
|
|
28
|
+
import { Badge } from "@/components/ui/badge"
|
|
29
|
+
import { Skeleton } from "@/components/ui/skeleton"
|
|
30
|
+
import { Checkbox } from "@/components/ui/checkbox"
|
|
31
|
+
import { Separator } from "@/components/ui/separator"
|
|
32
|
+
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
|
|
33
|
+
import {
|
|
34
|
+
Select,
|
|
35
|
+
SelectContent,
|
|
36
|
+
SelectItem,
|
|
37
|
+
SelectTrigger,
|
|
38
|
+
SelectValue,
|
|
39
|
+
} from "@/components/ui/select"
|
|
40
|
+
import { cn } from "@/lib/utils"
|
|
41
|
+
|
|
42
|
+
// ─── Types ──────────────────────────────────────────────────
|
|
43
|
+
|
|
44
|
+
interface ProviderOption {
|
|
45
|
+
id: string; name: string; description: string; mode: string
|
|
46
|
+
models: { id: string; name: string; tier: string; contextWindow: number }[]
|
|
47
|
+
requiresExternalId: boolean
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
interface PromptVersion {
|
|
51
|
+
pv_version: number; pv_prompt: string; pv_change_note: string; pv_created_at: string
|
|
52
|
+
changed_by?: { user_first_name: string; user_last_name: string } | null
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// ─── Hooks ──────────────────────────────────────────────────
|
|
56
|
+
|
|
57
|
+
function useAgent(id: string | undefined) {
|
|
58
|
+
return useQuery({
|
|
59
|
+
queryKey: ["agent", id],
|
|
60
|
+
queryFn: async () => (await api.get(`/agents/${id}`)).data,
|
|
61
|
+
enabled: !!id,
|
|
62
|
+
})
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function useUpdateAgent() {
|
|
66
|
+
const qc = useQueryClient()
|
|
67
|
+
return useMutation({
|
|
68
|
+
mutationFn: async ({ id, ...dto }: any) => (await api.put(`/agents/${id}`, dto)).data,
|
|
69
|
+
onSuccess: (_d, v) => {
|
|
70
|
+
qc.invalidateQueries({ queryKey: ["agent", v.id] })
|
|
71
|
+
qc.invalidateQueries({ queryKey: ["agents"] })
|
|
72
|
+
},
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function useCreateAgent() {
|
|
77
|
+
const qc = useQueryClient()
|
|
78
|
+
return useMutation({
|
|
79
|
+
mutationFn: async (dto: any) => (await api.post("/agents", dto)).data,
|
|
80
|
+
onSuccess: () => { qc.invalidateQueries({ queryKey: ["agents"] }) },
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function useProviderOptions() {
|
|
85
|
+
return useQuery({
|
|
86
|
+
queryKey: ["agent-provider-options"],
|
|
87
|
+
queryFn: async () => (await api.get("/agents/provider-options")).data as ProviderOption[],
|
|
88
|
+
})
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function usePromptHistory(id: string | undefined) {
|
|
92
|
+
return useQuery({
|
|
93
|
+
queryKey: ["agent-prompt-history", id],
|
|
94
|
+
queryFn: async () => (await api.get(`/agents/${id}/prompt-history`)).data as PromptVersion[],
|
|
95
|
+
enabled: !!id,
|
|
96
|
+
})
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function useTenants() {
|
|
100
|
+
return useQuery({
|
|
101
|
+
queryKey: ["tenants-list"],
|
|
102
|
+
queryFn: async () => (await api.get("/admin/tenants")).data as { tenant_id: string; tenant_name: string }[],
|
|
103
|
+
})
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function useClinics(tenantId?: string) {
|
|
107
|
+
return useQuery({
|
|
108
|
+
queryKey: ["clinics-for-tenant", tenantId],
|
|
109
|
+
queryFn: async () =>
|
|
110
|
+
(await api.get(`/admin/tenants/${tenantId}/clinics`)).data as { clinic_id: string; clinic_name: string }[],
|
|
111
|
+
enabled: !!tenantId,
|
|
112
|
+
})
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function useAgentClinics(agentId: string | undefined) {
|
|
116
|
+
return useQuery({
|
|
117
|
+
queryKey: ["agent-clinics", agentId],
|
|
118
|
+
queryFn: async () => (await api.get(`/agents/${agentId}/clinics`)).data as { aca_id: string; clinic: { clinic_id: string; clinic_name: string } }[],
|
|
119
|
+
enabled: !!agentId,
|
|
120
|
+
})
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function useAssignClinics() {
|
|
124
|
+
const qc = useQueryClient()
|
|
125
|
+
return useMutation({
|
|
126
|
+
mutationFn: async ({ agentId, clinicIds }: { agentId: string; clinicIds: string[] }) =>
|
|
127
|
+
(await api.post(`/agents/${agentId}/clinics`, { clinicIds })).data,
|
|
128
|
+
onSuccess: (_d, v) => { qc.invalidateQueries({ queryKey: ["agent-clinics", v.agentId] }) },
|
|
129
|
+
})
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function useUnassignClinic() {
|
|
133
|
+
const qc = useQueryClient()
|
|
134
|
+
return useMutation({
|
|
135
|
+
mutationFn: async ({ agentId, clinicId }: { agentId: string; clinicId: string }) =>
|
|
136
|
+
(await api.delete(`/agents/${agentId}/clinics/${clinicId}`)).data,
|
|
137
|
+
onSuccess: (_d, v) => { qc.invalidateQueries({ queryKey: ["agent-clinics", v.agentId] }) },
|
|
138
|
+
})
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
interface ToolDef {
|
|
142
|
+
name: string
|
|
143
|
+
description: string
|
|
144
|
+
requiredFeatures?: string[]
|
|
145
|
+
channels?: string[]
|
|
146
|
+
parameters: Record<string, any>
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function useAllTools() {
|
|
150
|
+
return useQuery({
|
|
151
|
+
queryKey: ["all-tools-full"],
|
|
152
|
+
queryFn: async () => (await api.get("/agents/tools/all")).data as ToolDef[],
|
|
153
|
+
})
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Derive a category from the tool name for grouping
|
|
157
|
+
function toolCategory(name: string): string {
|
|
158
|
+
if (name.includes("availability") || name.includes("reservation") || name.includes("slot") || name.includes("reschedule")) return "Calendar"
|
|
159
|
+
if (name.includes("operator") || name.includes("forward") || name.includes("example_photo")) return "Operator"
|
|
160
|
+
if (name.includes("patient") || name.includes("call_patient")) return "Patient"
|
|
161
|
+
if (name.includes("validation")) return "Validation"
|
|
162
|
+
if (name.includes("payment")) return "Payment"
|
|
163
|
+
if (name.includes("sms") || name.includes("notification")) return "Notification"
|
|
164
|
+
return "Other"
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const CATEGORY_ORDER = ["Calendar", "Operator", "Patient", "Notification", "Payment", "Validation", "Other"]
|
|
168
|
+
|
|
169
|
+
// ─── Section Header ─────────────────────────────────────────
|
|
170
|
+
|
|
171
|
+
function SectionHeader({ icon: Icon, label }: { icon: typeof Settings; label: string }) {
|
|
172
|
+
return (
|
|
173
|
+
<div className="flex items-center gap-2 mb-4">
|
|
174
|
+
<div className="w-6 h-6 rounded-md bg-muted flex items-center justify-center">
|
|
175
|
+
<Icon className="w-3.5 h-3.5 text-muted-foreground" />
|
|
176
|
+
</div>
|
|
177
|
+
<h2 className="text-xs font-semibold uppercase tracking-wide text-muted-foreground">{label}</h2>
|
|
178
|
+
<Separator className="flex-1" />
|
|
179
|
+
</div>
|
|
180
|
+
)
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// ─── Main Page ──────────────────────────────────────────────
|
|
184
|
+
|
|
185
|
+
export default function AgentDetailPage() {
|
|
186
|
+
const { id } = useParams<{ id: string }>()
|
|
187
|
+
const isNew = !id
|
|
188
|
+
const { t } = useTranslation()
|
|
189
|
+
const navigate = useNavigate()
|
|
190
|
+
const qc = useQueryClient()
|
|
191
|
+
const { data: agent, isLoading } = useAgent(id)
|
|
192
|
+
const update = useUpdateAgent()
|
|
193
|
+
const create = useCreateAgent()
|
|
194
|
+
const { data: providerOptions } = useProviderOptions()
|
|
195
|
+
const { data: tenants } = useTenants()
|
|
196
|
+
const { data: allTools } = useAllTools()
|
|
197
|
+
const { data: promptHistory } = usePromptHistory(id)
|
|
198
|
+
const { data: agentClinics } = useAgentClinics(id)
|
|
199
|
+
const assignClinics = useAssignClinics()
|
|
200
|
+
const unassignClinic = useUnassignClinic()
|
|
201
|
+
|
|
202
|
+
// Form state
|
|
203
|
+
const [name, setName] = useState("")
|
|
204
|
+
const [description, setDescription] = useState("")
|
|
205
|
+
const [tenantId, setTenantId] = useState("")
|
|
206
|
+
const [language, setLanguage] = useState("tr")
|
|
207
|
+
const [greeting, setGreeting] = useState("")
|
|
208
|
+
const [systemPrompt, setSystemPrompt] = useState("")
|
|
209
|
+
const [aiProvider, setAiProvider] = useState("")
|
|
210
|
+
const [aiModel, setAiModel] = useState("")
|
|
211
|
+
const [elevenlabsId, setElevenlabsId] = useState("")
|
|
212
|
+
const [temperature, setTemperature] = useState(0.3)
|
|
213
|
+
const [maxTokens, setMaxTokens] = useState(4096)
|
|
214
|
+
const [channels, setChannels] = useState<string[]>([])
|
|
215
|
+
const [enabledTools, setEnabledTools] = useState<string[]>([])
|
|
216
|
+
const [initialized, setInitialized] = useState(false)
|
|
217
|
+
const [showHistory, setShowHistory] = useState(false)
|
|
218
|
+
const [syncing, setSyncing] = useState(false)
|
|
219
|
+
|
|
220
|
+
useEffect(() => {
|
|
221
|
+
if (agent && !initialized) {
|
|
222
|
+
setName(agent.agent_name ?? "")
|
|
223
|
+
setDescription(agent.agent_description ?? "")
|
|
224
|
+
setTenantId(agent.agent_tenant_id ?? "")
|
|
225
|
+
setLanguage(agent.agent_language ?? "tr")
|
|
226
|
+
setGreeting(agent.agent_greeting ?? "")
|
|
227
|
+
setSystemPrompt(agent.agent_system_prompt ?? "")
|
|
228
|
+
setAiProvider(agent.agent_ai_provider ?? "")
|
|
229
|
+
setAiModel(agent.agent_ai_model ?? "")
|
|
230
|
+
setElevenlabsId(agent.agent_elevenlabs_id ?? "")
|
|
231
|
+
setTemperature(agent.agent_temperature ?? 0.3)
|
|
232
|
+
setMaxTokens(agent.agent_max_tokens ?? 4096)
|
|
233
|
+
setChannels(agent.agent_channels ?? [])
|
|
234
|
+
setEnabledTools(agent.agent_enabled_tools ?? [])
|
|
235
|
+
setInitialized(true)
|
|
236
|
+
}
|
|
237
|
+
}, [agent, initialized])
|
|
238
|
+
|
|
239
|
+
const { data: clinics } = useClinics(tenantId)
|
|
240
|
+
const selectedProvider = providerOptions?.find((p) => p.id === aiProvider)
|
|
241
|
+
const models = selectedProvider?.models ?? []
|
|
242
|
+
|
|
243
|
+
const handleSave = async () => {
|
|
244
|
+
if (!name.trim()) {
|
|
245
|
+
toast.error(t("validation.required"))
|
|
246
|
+
return
|
|
247
|
+
}
|
|
248
|
+
const dto = {
|
|
249
|
+
name: name.trim(),
|
|
250
|
+
tenantId: tenantId || null,
|
|
251
|
+
description: description || undefined,
|
|
252
|
+
language,
|
|
253
|
+
greeting: greeting || undefined,
|
|
254
|
+
systemPrompt: systemPrompt || undefined,
|
|
255
|
+
aiProvider: aiProvider || undefined,
|
|
256
|
+
aiModel: aiModel || undefined,
|
|
257
|
+
elevenlabsId: elevenlabsId || undefined,
|
|
258
|
+
temperature,
|
|
259
|
+
maxTokens,
|
|
260
|
+
channels: channels.length > 0 ? channels : undefined,
|
|
261
|
+
enabledTools,
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
try {
|
|
265
|
+
if (isNew) {
|
|
266
|
+
const result = await create.mutateAsync(dto)
|
|
267
|
+
toast.success(t("agents.created"))
|
|
268
|
+
navigate(`/admin/agents/${result.agent_id}`, { replace: true })
|
|
269
|
+
} else {
|
|
270
|
+
await update.mutateAsync({ id, ...dto })
|
|
271
|
+
toast.success(t("agents.updated"))
|
|
272
|
+
}
|
|
273
|
+
} catch (err: any) {
|
|
274
|
+
toast.error(err?.response?.data?.message || t("agents.updateError"))
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
const isSaving = update.isPending || create.isPending
|
|
279
|
+
|
|
280
|
+
const handleSyncFromEL = async () => {
|
|
281
|
+
if (!id) return
|
|
282
|
+
setSyncing(true)
|
|
283
|
+
try {
|
|
284
|
+
const { data } = await api.post(`/agents/${id}/elevenlabs/sync-pull`)
|
|
285
|
+
const changed = Object.entries(data.synced ?? {}).filter(([, v]) => v).map(([k]) => k)
|
|
286
|
+
if (changed.length > 0) {
|
|
287
|
+
toast.success(`Synced: ${changed.join(", ")}`)
|
|
288
|
+
qc.invalidateQueries({ queryKey: ["agent", id] })
|
|
289
|
+
qc.invalidateQueries({ queryKey: ["agent-prompt-history", id] })
|
|
290
|
+
setInitialized(false)
|
|
291
|
+
} else {
|
|
292
|
+
toast.info("Already up to date")
|
|
293
|
+
}
|
|
294
|
+
} catch (err: any) {
|
|
295
|
+
toast.error(err?.response?.data?.message || "Sync failed")
|
|
296
|
+
}
|
|
297
|
+
setSyncing(false)
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// ─── Loading / Not Found ────────────────────────────────
|
|
301
|
+
|
|
302
|
+
if (!isNew && isLoading) {
|
|
303
|
+
return (
|
|
304
|
+
<div className="max-w-[960px] mx-auto space-y-6 py-2">
|
|
305
|
+
<Skeleton className="h-16 w-full rounded-2xl" />
|
|
306
|
+
<div className="grid grid-cols-2 gap-6">
|
|
307
|
+
<Skeleton className="h-72 rounded-2xl" />
|
|
308
|
+
<Skeleton className="h-72 rounded-2xl" />
|
|
309
|
+
</div>
|
|
310
|
+
</div>
|
|
311
|
+
)
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
if (!isNew && !agent) {
|
|
315
|
+
return (
|
|
316
|
+
<div className="max-w-[960px] mx-auto space-y-4 py-2">
|
|
317
|
+
<Button variant="ghost" size="sm" onClick={() => navigate("/admin/agents")}>
|
|
318
|
+
<ArrowLeft className="w-4 h-4 mr-1.5" />{t("common.back")}
|
|
319
|
+
</Button>
|
|
320
|
+
<p className="text-sm text-muted-foreground">{t("agents.noAgents")}</p>
|
|
321
|
+
</div>
|
|
322
|
+
)
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// ─── Render ─────────────────────────────────────────────
|
|
326
|
+
|
|
327
|
+
return (
|
|
328
|
+
<div className="max-w-[960px] mx-auto space-y-8 py-2">
|
|
329
|
+
|
|
330
|
+
{/* ── Header ────────────────────────────────────────── */}
|
|
331
|
+
<div className="rounded-2xl border bg-card overflow-hidden">
|
|
332
|
+
<div className={cn("h-1.5", isNew ? "bg-primary" : agent?.agent_is_active ? "bg-primary" : "bg-muted")} />
|
|
333
|
+
<div className="px-6 py-4 flex items-center justify-between">
|
|
334
|
+
<div className="flex items-center gap-4">
|
|
335
|
+
<button onClick={() => navigate("/admin/agents")} className="text-muted-foreground hover:text-foreground">
|
|
336
|
+
<ArrowLeft className="w-5 h-5" />
|
|
337
|
+
</button>
|
|
338
|
+
<div className="w-10 h-10 rounded-lg bg-primary/10 flex items-center justify-center">
|
|
339
|
+
<Bot className="w-5 h-5 text-primary" />
|
|
340
|
+
</div>
|
|
341
|
+
<div>
|
|
342
|
+
<h1 className="text-lg font-bold">{isNew ? t("agents.create") : (name || "Unnamed Agent")}</h1>
|
|
343
|
+
{!isNew && agent && (
|
|
344
|
+
<div className="flex items-center gap-2 mt-0.5">
|
|
345
|
+
<Badge variant={agent.agent_is_active ? "outline" : "secondary"} className="text-[9px]">
|
|
346
|
+
{agent.agent_is_active ? t("common.active") : t("common.inactive")}
|
|
347
|
+
</Badge>
|
|
348
|
+
{agent.agent_ai_provider && (
|
|
349
|
+
<Badge variant="outline" className="text-[9px]">{agent.agent_ai_provider}</Badge>
|
|
350
|
+
)}
|
|
351
|
+
{agent.agent_elevenlabs_id && (
|
|
352
|
+
<Badge variant="outline" className="text-[9px] font-mono">EL: {agent.agent_elevenlabs_id.substring(0, 8)}...</Badge>
|
|
353
|
+
)}
|
|
354
|
+
</div>
|
|
355
|
+
)}
|
|
356
|
+
</div>
|
|
357
|
+
</div>
|
|
358
|
+
<div className="flex items-center gap-2">
|
|
359
|
+
{!isNew && agent?.agent_elevenlabs_id && (
|
|
360
|
+
<Button variant="outline" size="sm" onClick={handleSyncFromEL} disabled={syncing}>
|
|
361
|
+
{syncing ? <Loader2 className="w-4 h-4 animate-spin" /> : <><RefreshCw className="w-4 h-4 mr-1.5" />Sync from EL</>}
|
|
362
|
+
</Button>
|
|
363
|
+
)}
|
|
364
|
+
<Button onClick={handleSave} disabled={isSaving}>
|
|
365
|
+
{isSaving
|
|
366
|
+
? <><Loader2 className="w-4 h-4 mr-1.5 animate-spin" />{t("common.loading")}</>
|
|
367
|
+
: <><Save className="w-4 h-4 mr-1.5" />{isNew ? t("common.create") : t("common.save")}</>}
|
|
368
|
+
</Button>
|
|
369
|
+
</div>
|
|
370
|
+
</div>
|
|
371
|
+
</div>
|
|
372
|
+
|
|
373
|
+
{/* ══════════════════════════════════════════════════════
|
|
374
|
+
SECTION 1: PLATFORM SETTINGS
|
|
375
|
+
Identity, ownership, routing — where the agent lives
|
|
376
|
+
══════════════════════════════════════════════════════ */}
|
|
377
|
+
|
|
378
|
+
<div>
|
|
379
|
+
<SectionHeader icon={Settings} label="Platform Settings" />
|
|
380
|
+
|
|
381
|
+
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
|
|
382
|
+
{/* Identity */}
|
|
383
|
+
<Card className="rounded-2xl">
|
|
384
|
+
<CardHeader className="pb-3">
|
|
385
|
+
<CardTitle className="text-xs font-medium text-muted-foreground">Identity</CardTitle>
|
|
386
|
+
</CardHeader>
|
|
387
|
+
<CardContent className="space-y-3">
|
|
388
|
+
<div className="space-y-1.5">
|
|
389
|
+
<Label className="text-xs">{t("common.name")}</Label>
|
|
390
|
+
<Input value={name} onChange={(e) => setName(e.target.value)} className="h-9" placeholder="e.g. Reception Agent" />
|
|
391
|
+
</div>
|
|
392
|
+
<div className="space-y-1.5">
|
|
393
|
+
<Label className="text-xs">{t("agents.description")}</Label>
|
|
394
|
+
<Input value={description} onChange={(e) => setDescription(e.target.value)} className="h-9" placeholder="Brief description of this agent's role" />
|
|
395
|
+
</div>
|
|
396
|
+
<div className="space-y-1.5">
|
|
397
|
+
<Label className="text-xs">Tenant</Label>
|
|
398
|
+
<Select value={tenantId || "__none__"} onValueChange={(v) => setTenantId(v === "__none__" ? "" : v)}>
|
|
399
|
+
<SelectTrigger className="h-9">
|
|
400
|
+
<SelectValue>{tenants?.find((t) => t.tenant_id === tenantId)?.tenant_name || "Unassigned (Draft)"}</SelectValue>
|
|
401
|
+
</SelectTrigger>
|
|
402
|
+
<SelectContent>
|
|
403
|
+
<SelectItem value="__none__">Unassigned (Draft)</SelectItem>
|
|
404
|
+
{(tenants ?? []).map((t) => (
|
|
405
|
+
<SelectItem key={t.tenant_id} value={t.tenant_id}>{t.tenant_name}</SelectItem>
|
|
406
|
+
))}
|
|
407
|
+
</SelectContent>
|
|
408
|
+
</Select>
|
|
409
|
+
</div>
|
|
410
|
+
</CardContent>
|
|
411
|
+
</Card>
|
|
412
|
+
|
|
413
|
+
{/* Routing & Channels */}
|
|
414
|
+
<Card className="rounded-2xl">
|
|
415
|
+
<CardHeader className="pb-3">
|
|
416
|
+
<CardTitle className="text-xs font-medium text-muted-foreground flex items-center gap-1.5">
|
|
417
|
+
<Radio className="w-3 h-3" /> Routing & Channels
|
|
418
|
+
</CardTitle>
|
|
419
|
+
</CardHeader>
|
|
420
|
+
<CardContent className="space-y-3">
|
|
421
|
+
<div className="space-y-1.5">
|
|
422
|
+
<Label className="text-xs">Channels</Label>
|
|
423
|
+
<div className="flex gap-3">
|
|
424
|
+
{["whatsapp", "instagram", "voice_call"].map((ch) => (
|
|
425
|
+
<label key={ch} className="flex items-center gap-1.5 text-xs cursor-pointer">
|
|
426
|
+
<Checkbox
|
|
427
|
+
checked={channels.includes(ch)}
|
|
428
|
+
onCheckedChange={(v) => setChannels(v ? [...channels, ch] : channels.filter((c) => c !== ch))}
|
|
429
|
+
/>
|
|
430
|
+
{ch === "whatsapp" ? "WhatsApp" : ch === "instagram" ? "Instagram" : "Voice"}
|
|
431
|
+
</label>
|
|
432
|
+
))}
|
|
433
|
+
</div>
|
|
434
|
+
<p className="text-[10px] text-muted-foreground">Leave empty for all channels</p>
|
|
435
|
+
</div>
|
|
436
|
+
|
|
437
|
+
{/* ElevenLabs link */}
|
|
438
|
+
<Separator />
|
|
439
|
+
<div className="space-y-1.5">
|
|
440
|
+
<Label className="text-xs flex items-center gap-1.5">
|
|
441
|
+
<Link className="w-3 h-3" /> ElevenLabs Agent ID
|
|
442
|
+
</Label>
|
|
443
|
+
<Input value={elevenlabsId} onChange={(e) => setElevenlabsId(e.target.value)} className="h-9 font-mono text-xs" placeholder="Leave empty if not using ElevenLabs" />
|
|
444
|
+
<p className="text-[10px] text-muted-foreground">Links this agent to an ElevenLabs conversational AI agent for voice calls</p>
|
|
445
|
+
</div>
|
|
446
|
+
</CardContent>
|
|
447
|
+
</Card>
|
|
448
|
+
</div>
|
|
449
|
+
|
|
450
|
+
{/* Clinic Assignments (only if tenant set) */}
|
|
451
|
+
{!isNew && tenantId && (
|
|
452
|
+
<Card className="rounded-2xl mt-6">
|
|
453
|
+
<CardHeader className="pb-3">
|
|
454
|
+
<CardTitle className="text-xs font-medium text-muted-foreground flex items-center gap-1.5">
|
|
455
|
+
<Building2 className="w-3 h-3" /> Clinic Assignments
|
|
456
|
+
</CardTitle>
|
|
457
|
+
</CardHeader>
|
|
458
|
+
<CardContent className="space-y-3">
|
|
459
|
+
{agentClinics && agentClinics.length > 0 ? (
|
|
460
|
+
<div className="flex flex-wrap gap-2">
|
|
461
|
+
{agentClinics.map((a: any) => (
|
|
462
|
+
<Badge key={a.aca_id} variant="secondary" className="text-xs gap-1 pr-1">
|
|
463
|
+
{a.clinic.clinic_name}
|
|
464
|
+
<button
|
|
465
|
+
onClick={() => unassignClinic.mutateAsync({ agentId: id!, clinicId: a.clinic.clinic_id })}
|
|
466
|
+
className="ml-0.5 rounded-full hover:bg-destructive/20 p-0.5 text-muted-foreground hover:text-destructive transition-colors"
|
|
467
|
+
>
|
|
468
|
+
×
|
|
469
|
+
</button>
|
|
470
|
+
</Badge>
|
|
471
|
+
))}
|
|
472
|
+
</div>
|
|
473
|
+
) : (
|
|
474
|
+
<p className="text-xs text-muted-foreground">No clinics assigned — agent available to all clinics in the tenant.</p>
|
|
475
|
+
)}
|
|
476
|
+
{(() => {
|
|
477
|
+
const available = (clinics ?? []).filter(
|
|
478
|
+
(c) => !agentClinics?.some((a: any) => a.clinic.clinic_id === c.clinic_id),
|
|
479
|
+
)
|
|
480
|
+
if (available.length === 0) return null
|
|
481
|
+
return (
|
|
482
|
+
<Select key={agentClinics?.length ?? 0} onValueChange={(clinicId) => {
|
|
483
|
+
if (clinicId && id) assignClinics.mutateAsync({ agentId: id, clinicIds: [clinicId] })
|
|
484
|
+
}}>
|
|
485
|
+
<SelectTrigger className="h-8 text-xs w-48">
|
|
486
|
+
<SelectValue>Add clinic...</SelectValue>
|
|
487
|
+
</SelectTrigger>
|
|
488
|
+
<SelectContent>
|
|
489
|
+
{available.map((c) => (
|
|
490
|
+
<SelectItem key={c.clinic_id} value={c.clinic_id}>{c.clinic_name}</SelectItem>
|
|
491
|
+
))}
|
|
492
|
+
</SelectContent>
|
|
493
|
+
</Select>
|
|
494
|
+
)
|
|
495
|
+
})()}
|
|
496
|
+
</CardContent>
|
|
497
|
+
</Card>
|
|
498
|
+
)}
|
|
499
|
+
</div>
|
|
500
|
+
|
|
501
|
+
{/* ══════════════════════════════════════════════════════
|
|
502
|
+
SECTION 2: AI CONFIGURATION
|
|
503
|
+
How the agent thinks — provider, model, parameters
|
|
504
|
+
══════════════════════════════════════════════════════ */}
|
|
505
|
+
|
|
506
|
+
<div>
|
|
507
|
+
<SectionHeader icon={Brain} label="AI Configuration" />
|
|
508
|
+
|
|
509
|
+
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
|
|
510
|
+
{/* Provider & Model */}
|
|
511
|
+
<Card className="rounded-2xl">
|
|
512
|
+
<CardHeader className="pb-3">
|
|
513
|
+
<CardTitle className="text-xs font-medium text-muted-foreground flex items-center gap-1.5">
|
|
514
|
+
<Zap className="w-3 h-3" /> Provider & Model
|
|
515
|
+
</CardTitle>
|
|
516
|
+
</CardHeader>
|
|
517
|
+
<CardContent className="space-y-3">
|
|
518
|
+
<div className="space-y-1.5">
|
|
519
|
+
<Label className="text-xs">Provider</Label>
|
|
520
|
+
<Select value={aiProvider} onValueChange={(v) => { setAiProvider(v); setAiModel("") }}>
|
|
521
|
+
<SelectTrigger className="h-9">
|
|
522
|
+
<SelectValue>{providerOptions?.find((p) => p.id === aiProvider)?.name || t("agents.defaultProvider")}</SelectValue>
|
|
523
|
+
</SelectTrigger>
|
|
524
|
+
<SelectContent>
|
|
525
|
+
<SelectItem value="">{t("agents.defaultProvider")}</SelectItem>
|
|
526
|
+
{(providerOptions ?? []).map((p) => (
|
|
527
|
+
<SelectItem key={p.id} value={p.id}>
|
|
528
|
+
<div className="flex items-center gap-2">
|
|
529
|
+
<span>{p.name}</span>
|
|
530
|
+
<Badge variant="outline" className="text-[8px] px-1 py-0 h-3.5">{p.mode}</Badge>
|
|
531
|
+
</div>
|
|
532
|
+
</SelectItem>
|
|
533
|
+
))}
|
|
534
|
+
</SelectContent>
|
|
535
|
+
</Select>
|
|
536
|
+
{selectedProvider && (
|
|
537
|
+
<p className="text-[10px] text-muted-foreground">{selectedProvider.description}</p>
|
|
538
|
+
)}
|
|
539
|
+
</div>
|
|
540
|
+
|
|
541
|
+
{models.length > 0 && (
|
|
542
|
+
<div className="space-y-1.5">
|
|
543
|
+
<Label className="text-xs">Model</Label>
|
|
544
|
+
<Select value={aiModel} onValueChange={setAiModel}>
|
|
545
|
+
<SelectTrigger className="h-9">
|
|
546
|
+
<SelectValue>{models.find((m) => m.id === aiModel)?.name || "Default"}</SelectValue>
|
|
547
|
+
</SelectTrigger>
|
|
548
|
+
<SelectContent>
|
|
549
|
+
<SelectItem value="">Default</SelectItem>
|
|
550
|
+
{models.map((m) => (
|
|
551
|
+
<SelectItem key={m.id} value={m.id}>
|
|
552
|
+
<div className="flex items-center gap-2">
|
|
553
|
+
<span>{m.name}</span>
|
|
554
|
+
<Badge variant="outline" className="text-[8px] px-1 py-0 h-3.5">{m.tier}</Badge>
|
|
555
|
+
<span className="text-[9px] text-muted-foreground">{(m.contextWindow / 1000).toFixed(0)}K ctx</span>
|
|
556
|
+
</div>
|
|
557
|
+
</SelectItem>
|
|
558
|
+
))}
|
|
559
|
+
</SelectContent>
|
|
560
|
+
</Select>
|
|
561
|
+
</div>
|
|
562
|
+
)}
|
|
563
|
+
</CardContent>
|
|
564
|
+
</Card>
|
|
565
|
+
|
|
566
|
+
{/* Parameters */}
|
|
567
|
+
<Card className="rounded-2xl">
|
|
568
|
+
<CardHeader className="pb-3">
|
|
569
|
+
<CardTitle className="text-xs font-medium text-muted-foreground flex items-center gap-1.5">
|
|
570
|
+
<Thermometer className="w-3 h-3" /> Parameters
|
|
571
|
+
</CardTitle>
|
|
572
|
+
</CardHeader>
|
|
573
|
+
<CardContent className="space-y-3">
|
|
574
|
+
<div className="space-y-1.5">
|
|
575
|
+
<Label className="text-xs">{t("agents.language")}</Label>
|
|
576
|
+
<Select value={language} onValueChange={setLanguage}>
|
|
577
|
+
<SelectTrigger className="h-9"><SelectValue>{language === "tr" ? "Turkce" : "English"}</SelectValue></SelectTrigger>
|
|
578
|
+
<SelectContent>
|
|
579
|
+
<SelectItem value="tr">Turkce</SelectItem>
|
|
580
|
+
<SelectItem value="en">English</SelectItem>
|
|
581
|
+
</SelectContent>
|
|
582
|
+
</Select>
|
|
583
|
+
</div>
|
|
584
|
+
<div className="space-y-1.5">
|
|
585
|
+
<Label className="text-xs">Greeting / First Message</Label>
|
|
586
|
+
<Input value={greeting} onChange={(e) => setGreeting(e.target.value)} className="h-9" placeholder="Merhaba! Size nasil yardimci olabilirim?" />
|
|
587
|
+
</div>
|
|
588
|
+
<Separator />
|
|
589
|
+
<div className="space-y-1.5">
|
|
590
|
+
<div className="flex items-center justify-between">
|
|
591
|
+
<Label className="text-xs">Temperature</Label>
|
|
592
|
+
<span className="text-[10px] font-mono text-muted-foreground bg-muted px-1.5 py-0.5 rounded">{temperature.toFixed(2)}</span>
|
|
593
|
+
</div>
|
|
594
|
+
<input
|
|
595
|
+
type="range" min="0" max="1" step="0.05"
|
|
596
|
+
value={temperature}
|
|
597
|
+
onChange={(e) => setTemperature(parseFloat(e.target.value))}
|
|
598
|
+
className="w-full h-1.5 bg-muted rounded-lg appearance-none cursor-pointer"
|
|
599
|
+
/>
|
|
600
|
+
<div className="flex justify-between text-[9px] text-muted-foreground">
|
|
601
|
+
<span>Precise</span>
|
|
602
|
+
<span>Creative</span>
|
|
603
|
+
</div>
|
|
604
|
+
</div>
|
|
605
|
+
<div className="space-y-1.5">
|
|
606
|
+
<Label className="text-xs">Max Tokens</Label>
|
|
607
|
+
<Input type="number" min={256} max={16384} value={maxTokens} onChange={(e) => setMaxTokens(Number(e.target.value))} className="h-9" />
|
|
608
|
+
</div>
|
|
609
|
+
</CardContent>
|
|
610
|
+
</Card>
|
|
611
|
+
</div>
|
|
612
|
+
</div>
|
|
613
|
+
|
|
614
|
+
{/* ══════════════════════════════════════════════════════
|
|
615
|
+
SECTION 3: SYSTEM PROMPT
|
|
616
|
+
══════════════════════════════════════════════════════ */}
|
|
617
|
+
|
|
618
|
+
<div>
|
|
619
|
+
<SectionHeader icon={MessageSquare} label="System Prompt" />
|
|
620
|
+
|
|
621
|
+
<Card className="rounded-2xl">
|
|
622
|
+
<CardHeader className="pb-3">
|
|
623
|
+
<div className="flex items-center justify-between">
|
|
624
|
+
<CardTitle className="text-xs font-medium text-muted-foreground">
|
|
625
|
+
Instructions that define the agent's behavior
|
|
626
|
+
</CardTitle>
|
|
627
|
+
{!isNew && (
|
|
628
|
+
<Button size="sm" variant="ghost" className="h-7 text-xs" onClick={() => setShowHistory(!showHistory)}>
|
|
629
|
+
<History className="w-3.5 h-3.5 mr-1" /> {showHistory ? "Hide history" : "History"}
|
|
630
|
+
</Button>
|
|
631
|
+
)}
|
|
632
|
+
</div>
|
|
633
|
+
</CardHeader>
|
|
634
|
+
<CardContent>
|
|
635
|
+
<textarea
|
|
636
|
+
className="w-full rounded-lg border bg-background px-4 py-3 text-sm min-h-[220px] resize-y focus:outline-none focus:ring-1 focus:ring-ring font-mono leading-relaxed"
|
|
637
|
+
value={systemPrompt}
|
|
638
|
+
onChange={(e) => setSystemPrompt(e.target.value)}
|
|
639
|
+
placeholder={t("agents.systemPromptPlaceholder")}
|
|
640
|
+
/>
|
|
641
|
+
<p className="text-[10px] text-muted-foreground mt-1.5">
|
|
642
|
+
{systemPrompt.length} characters
|
|
643
|
+
</p>
|
|
644
|
+
|
|
645
|
+
{showHistory && promptHistory && promptHistory.length > 0 && (
|
|
646
|
+
<div className="mt-4 space-y-2 border-t pt-4">
|
|
647
|
+
<p className="text-xs font-medium text-muted-foreground">Version History</p>
|
|
648
|
+
{promptHistory.map((v) => (
|
|
649
|
+
<div key={v.pv_version} className="rounded-lg border p-3 text-xs">
|
|
650
|
+
<div className="flex items-center justify-between mb-1">
|
|
651
|
+
<div className="flex items-center gap-2">
|
|
652
|
+
<Badge variant="outline" className="text-[9px]">v{v.pv_version}</Badge>
|
|
653
|
+
{v.pv_change_note && <span className="text-muted-foreground">{v.pv_change_note}</span>}
|
|
654
|
+
{v.changed_by && (
|
|
655
|
+
<span className="text-muted-foreground/60">{v.changed_by.user_first_name} {v.changed_by.user_last_name}</span>
|
|
656
|
+
)}
|
|
657
|
+
</div>
|
|
658
|
+
<Button size="sm" variant="ghost" className="h-6 text-[10px]" onClick={() => setSystemPrompt(v.pv_prompt)}>
|
|
659
|
+
Restore
|
|
660
|
+
</Button>
|
|
661
|
+
</div>
|
|
662
|
+
<p className="text-muted-foreground line-clamp-2 font-mono">{v.pv_prompt}</p>
|
|
663
|
+
</div>
|
|
664
|
+
))}
|
|
665
|
+
</div>
|
|
666
|
+
)}
|
|
667
|
+
</CardContent>
|
|
668
|
+
</Card>
|
|
669
|
+
</div>
|
|
670
|
+
|
|
671
|
+
{/* ══════════════════════════════════════════════════════
|
|
672
|
+
SECTION 4: CLIENT TOOLS
|
|
673
|
+
What the agent can do — toggleable per tool
|
|
674
|
+
══════════════════════════════════════════════════════ */}
|
|
675
|
+
|
|
676
|
+
{allTools && allTools.length > 0 && (() => {
|
|
677
|
+
const enabledCount = enabledTools.length
|
|
678
|
+
const isNoneEnabled = enabledCount === 0
|
|
679
|
+
const isAllEnabledExplicit = enabledCount === allTools.length
|
|
680
|
+
const grouped = new Map<string, ToolDef[]>()
|
|
681
|
+
for (const t of allTools) {
|
|
682
|
+
const cat = toolCategory(t.name)
|
|
683
|
+
if (!grouped.has(cat)) grouped.set(cat, [])
|
|
684
|
+
grouped.get(cat)!.push(t)
|
|
685
|
+
}
|
|
686
|
+
const categories = CATEGORY_ORDER.filter((c) => grouped.has(c))
|
|
687
|
+
|
|
688
|
+
const toggle = (toolName: string) => {
|
|
689
|
+
setEnabledTools((prev) =>
|
|
690
|
+
prev.includes(toolName) ? prev.filter((n) => n !== toolName) : [...prev, toolName],
|
|
691
|
+
)
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
const isToolEnabled = (name: string) => enabledTools.includes(name)
|
|
695
|
+
|
|
696
|
+
return (
|
|
697
|
+
<div>
|
|
698
|
+
<SectionHeader icon={FileText} label="Client Tools" />
|
|
699
|
+
|
|
700
|
+
<div className="flex items-center justify-between mb-4">
|
|
701
|
+
<p className="text-xs text-muted-foreground">
|
|
702
|
+
{isNoneEnabled
|
|
703
|
+
? "No tools enabled"
|
|
704
|
+
: `${enabledCount} of ${allTools.length} tools enabled`}
|
|
705
|
+
</p>
|
|
706
|
+
<div className="flex gap-1">
|
|
707
|
+
{!isNoneEnabled && (
|
|
708
|
+
<Button size="sm" variant="ghost" className="h-7 text-xs" onClick={() => setEnabledTools([])}>
|
|
709
|
+
Disable all
|
|
710
|
+
</Button>
|
|
711
|
+
)}
|
|
712
|
+
{!isAllEnabledExplicit && (
|
|
713
|
+
<Button size="sm" variant="ghost" className="h-7 text-xs" onClick={() => setEnabledTools(allTools.map((t) => t.name))}>
|
|
714
|
+
Enable all
|
|
715
|
+
</Button>
|
|
716
|
+
)}
|
|
717
|
+
</div>
|
|
718
|
+
</div>
|
|
719
|
+
|
|
720
|
+
<div className="space-y-6">
|
|
721
|
+
{categories.map((cat) => (
|
|
722
|
+
<div key={cat}>
|
|
723
|
+
<p className="text-[10px] font-semibold uppercase tracking-widest text-muted-foreground mb-2">{cat}</p>
|
|
724
|
+
<div className="grid grid-cols-1 md:grid-cols-2 gap-2">
|
|
725
|
+
{grouped.get(cat)!.map((tool) => {
|
|
726
|
+
const enabled = isToolEnabled(tool.name)
|
|
727
|
+
return (
|
|
728
|
+
<button
|
|
729
|
+
key={tool.name}
|
|
730
|
+
onClick={() => toggle(tool.name)}
|
|
731
|
+
className={cn(
|
|
732
|
+
"rounded-xl border p-3 text-left transition-all cursor-pointer",
|
|
733
|
+
enabled
|
|
734
|
+
? "bg-card border-primary/30 ring-1 ring-primary/10"
|
|
735
|
+
: "bg-muted/30 border-border opacity-60",
|
|
736
|
+
)}
|
|
737
|
+
>
|
|
738
|
+
<div className="flex items-start justify-between gap-2">
|
|
739
|
+
<div className="min-w-0 flex-1">
|
|
740
|
+
<p className="text-xs font-mono font-medium truncate">{tool.name}</p>
|
|
741
|
+
<p className="text-[10px] text-muted-foreground mt-0.5 line-clamp-2">{tool.description}</p>
|
|
742
|
+
</div>
|
|
743
|
+
<div className={cn(
|
|
744
|
+
"w-4 h-4 rounded-full border-2 shrink-0 mt-0.5 transition-colors",
|
|
745
|
+
enabled ? "bg-primary border-primary" : "border-muted-foreground/30",
|
|
746
|
+
)} />
|
|
747
|
+
</div>
|
|
748
|
+
{/* Metadata row */}
|
|
749
|
+
<div className="flex items-center gap-1.5 mt-2 flex-wrap">
|
|
750
|
+
{tool.requiredFeatures?.map((f) => (
|
|
751
|
+
<Badge key={f} variant="outline" className="text-[8px] px-1 py-0 h-3.5 font-mono">{f}</Badge>
|
|
752
|
+
))}
|
|
753
|
+
{tool.channels?.map((ch) => (
|
|
754
|
+
<Badge key={ch} variant="secondary" className="text-[8px] px-1 py-0 h-3.5">
|
|
755
|
+
{ch === "whatsapp" ? "WA" : ch === "voice_call" ? "Voice" : ch === "instagram" ? "IG" : ch}
|
|
756
|
+
</Badge>
|
|
757
|
+
))}
|
|
758
|
+
{!tool.channels?.length && (
|
|
759
|
+
<Badge variant="secondary" className="text-[8px] px-1 py-0 h-3.5">All channels</Badge>
|
|
760
|
+
)}
|
|
761
|
+
</div>
|
|
762
|
+
</button>
|
|
763
|
+
)
|
|
764
|
+
})}
|
|
765
|
+
</div>
|
|
766
|
+
</div>
|
|
767
|
+
))}
|
|
768
|
+
</div>
|
|
769
|
+
</div>
|
|
770
|
+
)
|
|
771
|
+
})()}
|
|
772
|
+
</div>
|
|
773
|
+
)
|
|
774
|
+
}
|