Repository: EvolutionAPI/evolution-api Branch: main Commit: cd800f2976e1 Files: 346 Total size: 2.9 MB Directory structure: gitextract_y8izy66h/ ├── .cursor/ │ └── rules/ │ ├── README.md │ ├── core-development.mdc │ ├── cursor.json │ ├── project-context.mdc │ └── specialized-rules/ │ ├── controller-rules.mdc │ ├── dto-rules.mdc │ ├── guard-rules.mdc │ ├── integration-channel-rules.mdc │ ├── integration-chatbot-rules.mdc │ ├── integration-event-rules.mdc │ ├── integration-storage-rules.mdc │ ├── route-rules.mdc │ ├── service-rules.mdc │ ├── type-rules.mdc │ ├── util-rules.mdc │ └── validate-rules.mdc ├── .dockerignore ├── .eslintignore ├── .eslintrc.js ├── .github/ │ ├── ISSUE_TEMPLATE/ │ │ ├── -en--bug-report.yaml │ │ ├── -en--feature-request.yaml │ │ ├── -pt--reportar-bug.yaml │ │ ├── -pt--solicitar-recurso.yaml │ │ ├── bug_report.yml │ │ └── feature_request.yml │ ├── pull_request_template.md │ └── workflows/ │ ├── check_code_quality.yml │ ├── publish_docker_image.yml │ ├── publish_docker_image_homolog.yml │ ├── publish_docker_image_latest.yml │ └── security.yml ├── .gitignore ├── .gitmodules ├── .husky/ │ ├── README.md │ ├── commit-msg │ ├── pre-commit │ └── pre-push ├── .prettierrc.js ├── .vscode/ │ └── settings.json ├── AGENTS.md ├── CHANGELOG.md ├── CLAUDE.md ├── Docker/ │ ├── kafka/ │ │ └── docker-compose.yaml │ ├── minio/ │ │ └── docker-compose.yaml │ ├── mysql/ │ │ └── docker-compose.yaml │ ├── postgres/ │ │ └── docker-compose.yaml │ ├── rabbitmq/ │ │ └── docker-compose.yaml │ ├── redis/ │ │ └── docker-compose.yaml │ ├── scripts/ │ │ ├── deploy_database.sh │ │ ├── env_functions.sh │ │ └── generate_database.sh │ └── swarm/ │ └── evolution_api_v2.yaml ├── Dockerfile ├── Dockerfile.metrics ├── Extras/ │ └── chatwoot/ │ ├── configurar_admin.json │ ├── criador_de_empresas.json │ └── criador_de_inbox.json ├── LICENSE ├── README.md ├── SECURITY.md ├── commitlint.config.js ├── docker-compose.dev.yaml ├── docker-compose.yaml ├── env.example ├── grafana-dashboard.json.example ├── local_install.sh ├── manager/ │ └── dist/ │ ├── assets/ │ │ ├── index-CO3NSIFj.js │ │ └── index-DsIrum0U.css │ └── index.html ├── manager_install.sh ├── package.json ├── prisma/ │ ├── mysql-migrations/ │ │ ├── 20240809105427_init/ │ │ │ └── migration.sql │ │ ├── 20240813153900_add_unique_index_for_remoted_jid_and_instance_in_contacts/ │ │ │ └── migration.sql │ │ ├── 20240814173138_add_ignore_jids_chatwoot/ │ │ │ └── migration.sql │ │ ├── 20240814214314_integrations_unification/ │ │ │ └── migration.sql │ │ ├── 20240821203259_add_postgres_migrations/ │ │ │ └── migration.sql │ │ ├── 20240824162012_add_type_on_integration_sessions/ │ │ │ └── migration.sql │ │ ├── 20240825131301_change_to_evolution_bot/ │ │ │ └── migration.sql │ │ ├── 20241001172800_add_message_status/ │ │ │ └── migration.sql │ │ ├── 20241108101333_fix_message_status_as_string/ │ │ │ └── migration.sql │ │ ├── 20250214181954_add_wavoip_token_column/ │ │ │ └── migration.sql │ │ ├── 20250225180031_add_nats_integration/ │ │ │ └── migration.sql │ │ ├── 20250510035200_add_wavoip_token_to_settings_table/ │ │ │ └── migration.sql │ │ ├── 20250514232744_add_n8n_table/ │ │ │ └── migration.sql │ │ ├── 20250515211815_add_evoai_table/ │ │ │ └── migration.sql │ │ ├── 20250516012152_remove_unique_atribute_for_file_name_in_media/ │ │ │ └── migration.sql │ │ ├── 20250612155048_add_coluns_trypebot_tables/ │ │ │ └── migration.sql │ │ ├── 20250613143000_add_lid_column_to_is_onwhatsapp/ │ │ │ └── migration.sql │ │ ├── 20250918183910_add_kafka_integration/ │ │ │ └── migration.sql │ │ └── migration_lock.toml │ ├── mysql-schema.prisma │ ├── postgresql-migrations/ │ │ ├── 20240609181238_init/ │ │ │ └── migration.sql │ │ ├── 20240610144159_create_column_profile_name_instance/ │ │ │ └── migration.sql │ │ ├── 20240611125754_create_columns_whitelabel_chatwoot/ │ │ │ └── migration.sql │ │ ├── 20240611202817_create_columns_debounce_time_typebot/ │ │ │ └── migration.sql │ │ ├── 20240712144948_add_business_id_column_to_instances/ │ │ │ └── migration.sql │ │ ├── 20240712150256_create_templates_table/ │ │ │ └── migration.sql │ │ ├── 20240712155950_adjusts_in_templates_table/ │ │ │ └── migration.sql │ │ ├── 20240712162206_remove_templates_table/ │ │ │ └── migration.sql │ │ ├── 20240712223655_column_fallback_typebot/ │ │ │ └── migration.sql │ │ ├── 20240712230631_column_ignore_jids_typebot/ │ │ │ └── migration.sql │ │ ├── 20240713184337_add_media_table/ │ │ │ └── migration.sql │ │ ├── 20240718121437_add_openai_tables/ │ │ │ └── migration.sql │ │ ├── 20240718123923_adjusts_openai_tables/ │ │ │ └── migration.sql │ │ ├── 20240722173259_add_name_column_to_openai_creds/ │ │ │ └── migration.sql │ │ ├── 20240722173518_add_name_column_to_openai_creds/ │ │ │ └── migration.sql │ │ ├── 20240723152648_adjusts_in_column_openai_creds/ │ │ │ └── migration.sql │ │ ├── 20240723200254_add_webhookurl_on_message/ │ │ │ └── migration.sql │ │ ├── 20240725184147_create_template_table/ │ │ │ └── migration.sql │ │ ├── 20240725202651_add_webhook_url_template_table/ │ │ │ └── migration.sql │ │ ├── 20240725221646_modify_token_instance_table/ │ │ │ └── migration.sql │ │ ├── 20240729115127_modify_trigger_type_openai_typebot_table/ │ │ │ └── migration.sql │ │ ├── 20240729180347_modify_typebot_session_status_openai_typebot_table/ │ │ │ └── migration.sql │ │ ├── 20240730152156_create_dify_tables/ │ │ │ └── migration.sql │ │ ├── 20240801193907_add_column_speech_to_text_openai_setting_table/ │ │ │ └── migration.sql │ │ ├── 20240803163908_add_column_description_on_integrations_table/ │ │ │ └── migration.sql │ │ ├── 20240808210239_add_column_function_url_openaibot_table/ │ │ │ └── migration.sql │ │ ├── 20240811021156_add_chat_name_column/ │ │ │ └── migration.sql │ │ ├── 20240811183328_add_unique_index_for_remoted_jid_and_instance_in_contacts/ │ │ │ └── migration.sql │ │ ├── 20240813003116_make_label_unique_for_instance/ │ │ │ └── migration.sql │ │ ├── 20240814173033_add_ignore_jids_chatwoot/ │ │ │ └── migration.sql │ │ ├── 20240814202359_integrations_unification/ │ │ │ └── migration.sql │ │ ├── 20240817110155_add_trigger_type_advanced/ │ │ │ └── migration.sql │ │ ├── 20240819154941_add_context_to_integration_session/ │ │ │ └── migration.sql │ │ ├── 20240821120816_bot_id_integration_session/ │ │ │ └── migration.sql │ │ ├── 20240821171327_add_generic_bot_table/ │ │ │ └── migration.sql │ │ ├── 20240821194524_add_flowise_table/ │ │ │ └── migration.sql │ │ ├── 20240824161333_add_type_on_integration_sessions/ │ │ │ └── migration.sql │ │ ├── 20240825130616_change_to_evolution_bot/ │ │ │ └── migration.sql │ │ ├── 20240828140837_add_is_on_whatsapp_table/ │ │ │ └── migration.sql │ │ ├── 20240828141556_remove_name_column_from_on_whatsapp_table/ │ │ │ └── migration.sql │ │ ├── 20240830193533_changed_table_case/ │ │ │ └── migration.sql │ │ ├── 20240906202019_add_headers_on_webhook_config/ │ │ │ └── migration.sql │ │ ├── 20241001180457_add_message_status/ │ │ │ └── migration.sql │ │ ├── 20241006130306_alter_status_on_message_table/ │ │ │ └── migration.sql │ │ ├── 20241007164026_add_unread_messages_on_chat_table/ │ │ │ └── migration.sql │ │ ├── 20241011085129_create_pusher_table/ │ │ │ └── migration.sql │ │ ├── 20241011100803_split_messages_and_time_per_char_integrations/ │ │ │ └── migration.sql │ │ ├── 20241017144950_create_index/ │ │ │ └── migration.sql │ │ ├── 20250116001415_add_wavoip_token_to_settings_table/ │ │ │ └── migration.sql │ │ ├── 20250225180031_add_nats_integration/ │ │ │ └── migration.sql │ │ ├── 20250514232744_add_n8n_table/ │ │ │ └── migration.sql │ │ ├── 20250515211815_add_evoai_table/ │ │ │ └── migration.sql │ │ ├── 20250516012152_remove_unique_atribute_for_file_name_in_media/ │ │ │ └── migration.sql │ │ ├── 20250612155048_add_coluns_trypebot_tables/ │ │ │ └── migration.sql │ │ ├── 20250613143000_add_lid_column_to_is_onwhatsapp/ │ │ │ └── migration.sql │ │ ├── 20250918182355_add_kafka_integration/ │ │ │ └── migration.sql │ │ ├── 20251122003044_add_chat_instance_remotejid_unique/ │ │ │ └── migration.sql │ │ └── migration_lock.toml │ ├── postgresql-schema.prisma │ └── psql_bouncer-schema.prisma ├── prometheus.yml.example ├── runWithProvider.js ├── src/ │ ├── @types/ │ │ └── express.d.ts │ ├── api/ │ │ ├── abstract/ │ │ │ ├── abstract.cache.ts │ │ │ ├── abstract.repository.ts │ │ │ └── abstract.router.ts │ │ ├── controllers/ │ │ │ ├── business.controller.ts │ │ │ ├── call.controller.ts │ │ │ ├── chat.controller.ts │ │ │ ├── group.controller.ts │ │ │ ├── instance.controller.ts │ │ │ ├── label.controller.ts │ │ │ ├── proxy.controller.ts │ │ │ ├── sendMessage.controller.ts │ │ │ ├── settings.controller.ts │ │ │ └── template.controller.ts │ │ ├── dto/ │ │ │ ├── business.dto.ts │ │ │ ├── call.dto.ts │ │ │ ├── chat.dto.ts │ │ │ ├── chatbot.dto.ts │ │ │ ├── group.dto.ts │ │ │ ├── instance.dto.ts │ │ │ ├── label.dto.ts │ │ │ ├── proxy.dto.ts │ │ │ ├── sendMessage.dto.ts │ │ │ ├── settings.dto.ts │ │ │ └── template.dto.ts │ │ ├── guards/ │ │ │ ├── auth.guard.ts │ │ │ ├── instance.guard.ts │ │ │ └── telemetry.guard.ts │ │ ├── integrations/ │ │ │ ├── channel/ │ │ │ │ ├── channel.controller.ts │ │ │ │ ├── channel.router.ts │ │ │ │ ├── evolution/ │ │ │ │ │ ├── evolution.channel.service.ts │ │ │ │ │ ├── evolution.controller.ts │ │ │ │ │ └── evolution.router.ts │ │ │ │ ├── meta/ │ │ │ │ │ ├── meta.controller.ts │ │ │ │ │ ├── meta.router.ts │ │ │ │ │ └── whatsapp.business.service.ts │ │ │ │ └── whatsapp/ │ │ │ │ ├── baileys.controller.ts │ │ │ │ ├── baileys.router.ts │ │ │ │ ├── baileysMessage.processor.ts │ │ │ │ ├── voiceCalls/ │ │ │ │ │ ├── transport.type.ts │ │ │ │ │ └── useVoiceCallsBaileys.ts │ │ │ │ └── whatsapp.baileys.service.ts │ │ │ ├── chatbot/ │ │ │ │ ├── base-chatbot.controller.ts │ │ │ │ ├── base-chatbot.dto.ts │ │ │ │ ├── base-chatbot.service.ts │ │ │ │ ├── chatbot.controller.ts │ │ │ │ ├── chatbot.router.ts │ │ │ │ ├── chatbot.schema.ts │ │ │ │ ├── chatwoot/ │ │ │ │ │ ├── controllers/ │ │ │ │ │ │ └── chatwoot.controller.ts │ │ │ │ │ ├── dto/ │ │ │ │ │ │ └── chatwoot.dto.ts │ │ │ │ │ ├── libs/ │ │ │ │ │ │ └── postgres.client.ts │ │ │ │ │ ├── routes/ │ │ │ │ │ │ └── chatwoot.router.ts │ │ │ │ │ ├── services/ │ │ │ │ │ │ └── chatwoot.service.ts │ │ │ │ │ ├── utils/ │ │ │ │ │ │ └── chatwoot-import-helper.ts │ │ │ │ │ └── validate/ │ │ │ │ │ └── chatwoot.schema.ts │ │ │ │ ├── dify/ │ │ │ │ │ ├── controllers/ │ │ │ │ │ │ └── dify.controller.ts │ │ │ │ │ ├── dto/ │ │ │ │ │ │ └── dify.dto.ts │ │ │ │ │ ├── routes/ │ │ │ │ │ │ └── dify.router.ts │ │ │ │ │ ├── services/ │ │ │ │ │ │ └── dify.service.ts │ │ │ │ │ └── validate/ │ │ │ │ │ └── dify.schema.ts │ │ │ │ ├── evoai/ │ │ │ │ │ ├── controllers/ │ │ │ │ │ │ └── evoai.controller.ts │ │ │ │ │ ├── dto/ │ │ │ │ │ │ └── evoai.dto.ts │ │ │ │ │ ├── routes/ │ │ │ │ │ │ └── evoai.router.ts │ │ │ │ │ ├── services/ │ │ │ │ │ │ └── evoai.service.ts │ │ │ │ │ └── validate/ │ │ │ │ │ └── evoai.schema.ts │ │ │ │ ├── evolutionBot/ │ │ │ │ │ ├── controllers/ │ │ │ │ │ │ └── evolutionBot.controller.ts │ │ │ │ │ ├── dto/ │ │ │ │ │ │ └── evolutionBot.dto.ts │ │ │ │ │ ├── routes/ │ │ │ │ │ │ └── evolutionBot.router.ts │ │ │ │ │ ├── services/ │ │ │ │ │ │ └── evolutionBot.service.ts │ │ │ │ │ └── validate/ │ │ │ │ │ └── evolutionBot.schema.ts │ │ │ │ ├── flowise/ │ │ │ │ │ ├── controllers/ │ │ │ │ │ │ └── flowise.controller.ts │ │ │ │ │ ├── dto/ │ │ │ │ │ │ └── flowise.dto.ts │ │ │ │ │ ├── routes/ │ │ │ │ │ │ └── flowise.router.ts │ │ │ │ │ ├── services/ │ │ │ │ │ │ └── flowise.service.ts │ │ │ │ │ └── validate/ │ │ │ │ │ └── flowise.schema.ts │ │ │ │ ├── n8n/ │ │ │ │ │ ├── controllers/ │ │ │ │ │ │ └── n8n.controller.ts │ │ │ │ │ ├── dto/ │ │ │ │ │ │ └── n8n.dto.ts │ │ │ │ │ ├── routes/ │ │ │ │ │ │ └── n8n.router.ts │ │ │ │ │ ├── services/ │ │ │ │ │ │ └── n8n.service.ts │ │ │ │ │ └── validate/ │ │ │ │ │ └── n8n.schema.ts │ │ │ │ ├── openai/ │ │ │ │ │ ├── controllers/ │ │ │ │ │ │ └── openai.controller.ts │ │ │ │ │ ├── dto/ │ │ │ │ │ │ └── openai.dto.ts │ │ │ │ │ ├── routes/ │ │ │ │ │ │ └── openai.router.ts │ │ │ │ │ ├── services/ │ │ │ │ │ │ └── openai.service.ts │ │ │ │ │ └── validate/ │ │ │ │ │ └── openai.schema.ts │ │ │ │ └── typebot/ │ │ │ │ ├── controllers/ │ │ │ │ │ └── typebot.controller.ts │ │ │ │ ├── dto/ │ │ │ │ │ └── typebot.dto.ts │ │ │ │ ├── routes/ │ │ │ │ │ └── typebot.router.ts │ │ │ │ ├── services/ │ │ │ │ │ └── typebot.service.ts │ │ │ │ └── validate/ │ │ │ │ └── typebot.schema.ts │ │ │ ├── event/ │ │ │ │ ├── event.controller.ts │ │ │ │ ├── event.dto.ts │ │ │ │ ├── event.manager.ts │ │ │ │ ├── event.router.ts │ │ │ │ ├── event.schema.ts │ │ │ │ ├── kafka/ │ │ │ │ │ ├── kafka.controller.ts │ │ │ │ │ ├── kafka.router.ts │ │ │ │ │ └── kafka.schema.ts │ │ │ │ ├── nats/ │ │ │ │ │ ├── nats.controller.ts │ │ │ │ │ └── nats.router.ts │ │ │ │ ├── pusher/ │ │ │ │ │ ├── pusher.controller.ts │ │ │ │ │ ├── pusher.router.ts │ │ │ │ │ └── pusher.schema.ts │ │ │ │ ├── rabbitmq/ │ │ │ │ │ ├── rabbitmq.controller.ts │ │ │ │ │ └── rabbitmq.router.ts │ │ │ │ ├── sqs/ │ │ │ │ │ ├── sqs.controller.ts │ │ │ │ │ └── sqs.router.ts │ │ │ │ ├── webhook/ │ │ │ │ │ ├── webhook.controller.ts │ │ │ │ │ ├── webhook.router.ts │ │ │ │ │ └── webhook.schema.ts │ │ │ │ └── websocket/ │ │ │ │ ├── websocket.controller.ts │ │ │ │ └── websocket.router.ts │ │ │ ├── integration.dto.ts │ │ │ └── storage/ │ │ │ ├── s3/ │ │ │ │ ├── controllers/ │ │ │ │ │ └── s3.controller.ts │ │ │ │ ├── dto/ │ │ │ │ │ └── media.dto.ts │ │ │ │ ├── libs/ │ │ │ │ │ └── minio.server.ts │ │ │ │ ├── routes/ │ │ │ │ │ └── s3.router.ts │ │ │ │ ├── services/ │ │ │ │ │ └── s3.service.ts │ │ │ │ └── validate/ │ │ │ │ └── s3.schema.ts │ │ │ └── storage.router.ts │ │ ├── provider/ │ │ │ └── sessions.ts │ │ ├── repository/ │ │ │ └── repository.service.ts │ │ ├── routes/ │ │ │ ├── business.router.ts │ │ │ ├── call.router.ts │ │ │ ├── chat.router.ts │ │ │ ├── group.router.ts │ │ │ ├── index.router.ts │ │ │ ├── instance.router.ts │ │ │ ├── label.router.ts │ │ │ ├── proxy.router.ts │ │ │ ├── sendMessage.router.ts │ │ │ ├── settings.router.ts │ │ │ ├── template.router.ts │ │ │ └── view.router.ts │ │ ├── server.module.ts │ │ ├── services/ │ │ │ ├── auth.service.ts │ │ │ ├── cache.service.ts │ │ │ ├── channel.service.ts │ │ │ ├── monitor.service.ts │ │ │ ├── proxy.service.ts │ │ │ ├── settings.service.ts │ │ │ └── template.service.ts │ │ └── types/ │ │ └── wa.types.ts │ ├── cache/ │ │ ├── cacheengine.ts │ │ ├── localcache.ts │ │ ├── rediscache.client.ts │ │ └── rediscache.ts │ ├── config/ │ │ ├── env.config.ts │ │ ├── error.config.ts │ │ ├── event.config.ts │ │ ├── logger.config.ts │ │ └── path.config.ts │ ├── exceptions/ │ │ ├── 400.exception.ts │ │ ├── 401.exception.ts │ │ ├── 403.exception.ts │ │ ├── 404.exception.ts │ │ ├── 500.exception.ts │ │ └── index.ts │ ├── main.ts │ ├── railway.json │ ├── utils/ │ │ ├── advancedOperatorsSearch.ts │ │ ├── createJid.ts │ │ ├── errorResponse.ts │ │ ├── fetchLatestWaWebVersion.ts │ │ ├── findBotByTrigger.ts │ │ ├── getConversationMessage.ts │ │ ├── i18n.ts │ │ ├── instrumentSentry.ts │ │ ├── makeProxyAgent.ts │ │ ├── onWhatsappCache.ts │ │ ├── renderStatus.ts │ │ ├── sendTelemetry.ts │ │ ├── server-up.ts │ │ ├── translations/ │ │ │ ├── en.json │ │ │ ├── es.json │ │ │ └── pt-BR.json │ │ ├── use-multi-file-auth-state-prisma.ts │ │ ├── use-multi-file-auth-state-provider-files.ts │ │ └── use-multi-file-auth-state-redis-db.ts │ └── validate/ │ ├── business.schema.ts │ ├── chat.schema.ts │ ├── group.schema.ts │ ├── instance.schema.ts │ ├── label.schema.ts │ ├── message.schema.ts │ ├── proxy.schema.ts │ ├── settings.schema.ts │ ├── template.schema.ts │ ├── templateDelete.schema.ts │ ├── templateEdit.schema.ts │ └── validate.schema.ts ├── tsconfig.json └── tsup.config.ts ================================================ FILE CONTENTS ================================================ ================================================ FILE: .cursor/rules/README.md ================================================ # Evolution API Cursor Rules Este diretório contém as regras e configurações do Cursor IDE para o projeto Evolution API. ## Estrutura dos Arquivos ### Arquivos Principais (alwaysApply: true) - **`core-development.mdc`** - Princípios fundamentais de desenvolvimento - **`project-context.mdc`** - Contexto específico do projeto Evolution API - **`cursor.json`** - Configurações do Cursor IDE ### Regras Especializadas (alwaysApply: false) Estas regras são ativadas automaticamente quando você trabalha nos arquivos correspondentes: #### Camadas da Aplicação - **`specialized-rules/service-rules.mdc`** - Padrões para services (`src/api/services/`) - **`specialized-rules/controller-rules.mdc`** - Padrões para controllers (`src/api/controllers/`) - **`specialized-rules/dto-rules.mdc`** - Padrões para DTOs (`src/api/dto/`) - **`specialized-rules/guard-rules.mdc`** - Padrões para guards (`src/api/guards/`) - **`specialized-rules/route-rules.mdc`** - Padrões para routers (`src/api/routes/`) #### Tipos e Validação - **`specialized-rules/type-rules.mdc`** - Definições TypeScript (`src/api/types/`) - **`specialized-rules/validate-rules.mdc`** - Schemas de validação (`src/validate/`) #### Utilitários - **`specialized-rules/util-rules.mdc`** - Funções utilitárias (`src/utils/`) #### Integrações - **`specialized-rules/integration-channel-rules.mdc`** - Integrações de canal (`src/api/integrations/channel/`) - **`specialized-rules/integration-chatbot-rules.mdc`** - Integrações de chatbot (`src/api/integrations/chatbot/`) - **`specialized-rules/integration-storage-rules.mdc`** - Integrações de storage (`src/api/integrations/storage/`) - **`specialized-rules/integration-event-rules.mdc`** - Integrações de eventos (`src/api/integrations/event/`) ## Como Usar ### Referências Cruzadas Os arquivos principais fazem referência aos especializados usando a sintaxe `@specialized-rules/nome-do-arquivo.mdc`. Quando você trabalha em um arquivo específico, o Cursor automaticamente carrega as regras relevantes. ### Exemplo de Uso Quando você edita um arquivo em `src/api/services/`, o Cursor automaticamente: 1. Carrega `core-development.mdc` (sempre ativo) 2. Carrega `project-context.mdc` (sempre ativo) 3. Carrega `specialized-rules/service-rules.mdc` (ativado pelo glob pattern) ### Padrões de Código Cada arquivo de regras contém: - **Estruturas padrão** - Como organizar o código - **Padrões de nomenclatura** - Convenções de nomes - **Exemplos práticos** - Código de exemplo - **Anti-padrões** - O que evitar - **Testes** - Como testar o código - **Padrões de Commit** - Conventional Commits com commitlint ## Configuração do Cursor O arquivo `cursor.json` contém: - Configurações de formatação - Padrões de código específicos do Evolution API - Diretórios principais do projeto - Integrações e tecnologias utilizadas ## Manutenção Para manter as regras atualizadas: 1. Analise novos padrões no código 2. Atualize as regras especializadas correspondentes 3. Mantenha os exemplos sincronizados com o código real 4. Documente mudanças significativas ## Tecnologias Cobertas - **Backend**: Node.js 20+ + TypeScript 5+ + Express.js - **Database**: Prisma ORM (PostgreSQL/MySQL) - **Cache**: Redis + Node-cache - **Queue**: RabbitMQ + Amazon SQS - **Real-time**: Socket.io - **Storage**: AWS S3 + Minio - **Validation**: JSONSchema7 - **Logging**: Pino - **WhatsApp**: Baileys + Meta Business API - **Integrations**: Chatwoot, Typebot, OpenAI, Dify ## Estrutura do Projeto ``` src/ ├── api/ │ ├── controllers/ # Controllers (HTTP handlers) │ ├── services/ # Business logic │ ├── dto/ # Data Transfer Objects │ ├── guards/ # Authentication/Authorization │ ├── routes/ # Express routers │ ├── types/ # TypeScript definitions │ └── integrations/ # External integrations │ ├── channel/ # WhatsApp channels (Baileys, Business API) │ ├── chatbot/ # Chatbot integrations │ ├── event/ # Event integrations │ └── storage/ # Storage integrations ├── cache/ # Cache implementations ├── config/ # Configuration files ├── utils/ # Utility functions ├── validate/ # Validation schemas └── exceptions/ # Custom exceptions ``` Este sistema de regras garante consistência no código e facilita o desenvolvimento seguindo os padrões estabelecidos do Evolution API. ================================================ FILE: .cursor/rules/core-development.mdc ================================================ --- description: Core development principles and standards for Evolution API development globs: alwaysApply: true --- # Evolution API Development Standards ## Cross-References - **Project Context**: @project-context.mdc for Evolution API-specific patterns - **Specialized Rules**: - @specialized-rules/service-rules.mdc for service layer patterns - @specialized-rules/controller-rules.mdc for controller patterns - @specialized-rules/dto-rules.mdc for DTO validation patterns - @specialized-rules/guard-rules.mdc for authentication/authorization - @specialized-rules/route-rules.mdc for router patterns - @specialized-rules/type-rules.mdc for TypeScript definitions - @specialized-rules/util-rules.mdc for utility functions - @specialized-rules/validate-rules.mdc for validation schemas - @specialized-rules/integration-channel-rules.mdc for channel integrations - @specialized-rules/integration-chatbot-rules.mdc for chatbot integrations - @specialized-rules/integration-storage-rules.mdc for storage integrations - @specialized-rules/integration-event-rules.mdc for event integrations - **TypeScript/Node.js**: Node.js 20+ + TypeScript 5+ best practices - **Express/Prisma**: Express.js + Prisma ORM patterns - **WhatsApp Integrations**: Baileys + Meta Business API patterns ## Senior Engineer Context - Evolution API Platform - You are a senior software engineer working on a WhatsApp API platform - Focus on Node.js + TypeScript + Express.js full-stack development - Specialized in real-time messaging, WhatsApp integrations, and event-driven architecture - Apply scalable patterns for multi-tenant API platform - Consider WhatsApp integration workflow implications and performance at scale ## Fundamental Principles ### Code Quality Standards - **Simplicity First**: Always prefer simple solutions over complex ones - **DRY Principle**: Avoid code duplication - check for existing similar functionality before implementing - **Single Responsibility**: Each function/class should have one clear purpose - **Readable Code**: Write code that tells a story - clear naming and structure ### Problem Resolution Approach - **Follow Existing Patterns**: Use established Service patterns, DTOs, and Integration patterns - **Event-Driven First**: Leverage EventEmitter2 for event publishing when adding new features - **Integration Pattern**: Follow existing WhatsApp integration patterns for new channels - **Conservative Changes**: Prefer extending existing services over creating new architecture - **Clean Migration**: Remove deprecated patterns when introducing new ones - **Incremental Changes**: Break large changes into smaller, testable increments with proper migrations ### File and Function Organization - Node.js/TypeScript Structure - **Services**: Keep services focused and under 200 lines - **Controllers**: Keep controllers thin - only routing and validation - **DTOs**: Use JSONSchema7 for all input validation - **Integrations**: Follow `src/api/integrations/` structure for new integrations - **Utils**: Extract common functionality into well-named utilities - **Types**: Define clear TypeScript interfaces and types ### Code Analysis and Reflection - After writing code, deeply reflect on scalability and maintainability - Provide 1-2 paragraph analysis of code changes - Suggest improvements or next steps based on reflection - Consider performance, security, and maintenance implications ## Development Standards ### TypeScript Standards - **Strict Mode**: Always use TypeScript strict mode - **No Any**: Avoid `any` type - use proper typing - **Interfaces**: Define clear contracts with interfaces - **Enums**: Use enums for constants and status values - **Generics**: Use generics for reusable components ### Error Handling Standards - **HTTP Exceptions**: Use appropriate HTTP status codes - **Logging**: Structured logging with context - **Retry Logic**: Implement retry for external services - **Graceful Degradation**: Handle service failures gracefully ### Security Standards - **Input Validation**: Validate all inputs with JSONSchema7 - **Authentication**: Use API keys and JWT tokens - **Rate Limiting**: Implement rate limiting for APIs - **Data Sanitization**: Sanitize sensitive data in logs ### Performance Standards - **Caching**: Use Redis for frequently accessed data - **Database**: Optimize Prisma queries with proper indexing - **Memory**: Monitor memory usage and implement cleanup - **Async**: Use async/await properly with error handling ## Communication Standards ### Language Requirements - **User Communication**: Always respond in Portuguese (PT-BR) - **Code Comments**: English for technical documentation - **API Documentation**: English for consistency - **Error Messages**: Portuguese for user-facing errors ### Documentation Standards - **Code Comments**: Document complex business logic - **API Documentation**: Document all public endpoints - **README**: Keep project documentation updated - **Changelog**: Document breaking changes ## Quality Assurance ### Testing Standards - **Unit Tests**: Test business logic in services - **Integration Tests**: Test API endpoints - **Mocks**: Mock external dependencies - **Coverage**: Aim for 70%+ test coverage ### Code Review Standards - **Peer Review**: All code must be reviewed - **Automated Checks**: ESLint, Prettier, TypeScript - **Security Review**: Check for security vulnerabilities - **Performance Review**: Check for performance issues ### Commit Standards (Conventional Commits) - **Format**: `type(scope): subject` (max 100 characters) - **Types**: - `feat` - New feature - `fix` - Bug fix - `docs` - Documentation changes - `style` - Code style changes (formatting, etc) - `refactor` - Code refactoring - `perf` - Performance improvements - `test` - Adding or updating tests - `chore` - Maintenance tasks - `ci` - CI/CD changes - `build` - Build system changes - `revert` - Reverting changes - `security` - Security fixes - **Examples**: - `feat(api): add WhatsApp message status endpoint` - `fix(baileys): resolve connection timeout issue` - `docs(readme): update installation instructions` - `refactor(service): extract common message validation logic` - **Tools**: Use `npm run commit` (Commitizen) for guided commits - **Validation**: Enforced by commitlint on commit-msg hook ## Evolution API Specific Patterns ### WhatsApp Integration Patterns - **Connection Management**: One connection per instance - **Event Handling**: Proper event listeners for Baileys - **Message Processing**: Queue-based message processing - **Error Recovery**: Automatic reconnection logic ### Multi-Database Support - **Schema Compatibility**: Support PostgreSQL and MySQL - **Migration Sync**: Keep migrations synchronized - **Type Safety**: Use Prisma generated types - **Connection Pooling**: Proper database connection management ### Cache Strategy - **Redis Primary**: Use Redis for distributed caching - **Local Fallback**: Node-cache for local fallback - **TTL Strategy**: Appropriate TTL for different data types - **Cache Invalidation**: Proper cache invalidation patterns ### Event System - **EventEmitter2**: Use for internal events - **WebSocket**: Socket.io for real-time updates - **Queue Systems**: RabbitMQ/SQS for async processing - **Webhook Processing**: Proper webhook validation and processing ================================================ FILE: .cursor/rules/cursor.json ================================================ { "version": "1.0", "description": "Cursor IDE configuration for Evolution API project", "rules": { "general": { "max_line_length": 120, "indent_size": 2, "end_of_line": "lf", "charset": "utf-8", "trim_trailing_whitespace": true, "insert_final_newline": true }, "typescript": { "quotes": "single", "semi": true, "trailing_comma": "es5", "bracket_spacing": true, "arrow_parens": "avoid", "print_width": 120, "tab_width": 2, "use_tabs": false, "single_quote": true, "end_of_line": "lf", "strict": true, "no_implicit_any": true, "strict_null_checks": true }, "javascript": { "quotes": "single", "semi": true, "trailing_comma": "es5", "bracket_spacing": true, "arrow_parens": "avoid", "print_width": 120, "tab_width": 2, "use_tabs": false, "single_quote": true, "end_of_line": "lf", "style_guide": "eslint-airbnb" }, "json": { "tab_width": 2, "use_tabs": false, "parser": "json" }, "ignore": { "files": [ "node_modules/**", "dist/**", "build/**", ".git/**", "*.min.js", "*.min.css", ".env", ".env.*", ".env.example", "coverage/**", "*.log", "*.lock", "pnpm-lock.yaml", "package-lock.json", "yarn.lock", "log/**", "tmp/**", "instances/**", "public/uploads/**", "*.dump", "*.rdb", "*.mmdb", ".DS_Store", "*.swp", "*.swo", "*.un~", ".jest-cache", ".idea/**", ".vscode/**", ".yalc/**", "yalc.lock", "*.local", "prisma/migrations/**", "prisma/mysql-migrations/**", "prisma/postgresql-migrations/**" ] }, "search": { "exclude_patterns": [ "**/node_modules/**", "**/dist/**", "**/build/**", "**/.git/**", "**/coverage/**", "**/log/**", "**/tmp/**", "**/instances/**", "**/public/uploads/**", "**/*.min.js", "**/*.min.css", "**/*.log", "**/*.lock", "**/pnpm-lock.yaml", "**/package-lock.json", "**/yarn.lock", "**/*.dump", "**/*.rdb", "**/*.mmdb", "**/.DS_Store", "**/*.swp", "**/*.swo", "**/*.un~", "**/.jest-cache", "**/.idea/**", "**/.vscode/**", "**/.yalc/**", "**/yalc.lock", "**/*.local", "**/prisma/migrations/**", "**/prisma/mysql-migrations/**", "**/prisma/postgresql-migrations/**" ] }, "evolution_api": { "project_type": "nodejs_typescript_api", "backend_framework": "express_prisma", "database": ["postgresql", "mysql"], "cache": ["redis", "node_cache"], "queue": ["rabbitmq", "sqs"], "real_time": "socket_io", "file_storage": ["aws_s3", "minio"], "validation": "class_validator", "logging": "pino", "main_directories": { "source": "src/", "api": "src/api/", "controllers": "src/api/controllers/", "services": "src/api/services/", "integrations": "src/api/integrations/", "dto": "src/api/dto/", "types": "src/api/types/", "guards": "src/api/guards/", "routes": "src/api/routes/", "cache": "src/cache/", "config": "src/config/", "utils": "src/utils/", "exceptions": "src/exceptions/", "validate": "src/validate/", "prisma": "prisma/", "tests": "test/", "docs": "docs/" }, "key_patterns": [ "whatsapp_integration", "multi_database_support", "instance_management", "event_driven_architecture", "service_layer_pattern", "dto_validation", "webhook_processing", "message_queuing", "real_time_communication", "file_storage_integration" ], "whatsapp_integrations": [ "baileys", "meta_business_api", "whatsapp_cloud_api" ], "external_integrations": [ "chatwoot", "typebot", "openai", "dify", "rabbitmq", "sqs", "s3", "minio" ] } } } ================================================ FILE: .cursor/rules/project-context.mdc ================================================ --- description: Evolution API project-specific context and constraints globs: alwaysApply: true --- # Evolution API Project Context ## Cross-References - **Core Development**: @core-development.mdc for fundamental development principles - **Specialized Rules**: Reference specific specialized rules when working on: - Services: @specialized-rules/service-rules.mdc - Controllers: @specialized-rules/controller-rules.mdc - DTOs: @specialized-rules/dto-rules.mdc - Guards: @specialized-rules/guard-rules.mdc - Routes: @specialized-rules/route-rules.mdc - Types: @specialized-rules/type-rules.mdc - Utils: @specialized-rules/util-rules.mdc - Validation: @specialized-rules/validate-rules.mdc - Channel Integrations: @specialized-rules/integration-channel-rules.mdc - Chatbot Integrations: @specialized-rules/integration-chatbot-rules.mdc - Storage Integrations: @specialized-rules/integration-storage-rules.mdc - Event Integrations: @specialized-rules/integration-event-rules.mdc - **TypeScript/Node.js**: Node.js 20+ + TypeScript 5+ backend standards - **Express/Prisma**: Express.js + Prisma ORM patterns - **WhatsApp Integrations**: Baileys, Meta Business API, and other messaging platforms ## Technology Stack - **Backend**: Node.js 20+ + TypeScript 5+ + Express.js - **Database**: Prisma ORM (PostgreSQL/MySQL support) - **Cache**: Redis + Node-cache for local fallback - **Queue**: RabbitMQ + Amazon SQS for message processing - **Real-time**: Socket.io for WebSocket connections - **Storage**: AWS S3 + Minio for file storage - **Validation**: JSONSchema7 for input validation - **Logging**: Pino for structured logging - **Architecture**: Multi-tenant API with WhatsApp integrations ## Project-Specific Patterns ### WhatsApp Integration Architecture - **MANDATORY**: All WhatsApp integrations must follow established patterns - **BAILEYS**: Use `whatsapp.baileys.service.ts` patterns for WhatsApp Web - **META BUSINESS**: Use `whatsapp.business.service.ts` for official API - **CONNECTION MANAGEMENT**: One connection per instance with proper lifecycle - **EVENT HANDLING**: Proper event listeners and error handling ### Multi-Database Architecture - **CRITICAL**: Support both PostgreSQL and MySQL - **SCHEMAS**: Use appropriate schema files (postgresql-schema.prisma / mysql-schema.prisma) - **MIGRATIONS**: Keep migrations synchronized between databases - **TYPES**: Use database-specific types (@db.JsonB vs @db.Json) - **COMPATIBILITY**: Ensure feature parity between databases ### API Integration Workflow - **CORE FEATURE**: REST API for WhatsApp communication - **COMPLEXITY**: High - involves webhook processing, message routing, and instance management - **COMPONENTS**: Instance management, message handling, media processing - **INTEGRATIONS**: Baileys, Meta Business API, Chatwoot, Typebot, OpenAI, Dify ### Multi-Tenant Instance Architecture - **CRITICAL**: All operations must be scoped by instance - **ISOLATION**: Complete data isolation between instances - **SECURITY**: Validate instance ownership before operations - **SCALING**: Support thousands of concurrent instances - **AUTHENTICATION**: API key-based authentication per instance ## Documentation Requirements ### Implementation Documentation - **MANDATORY**: Document complex integration patterns - **LOCATION**: Use inline comments for business logic - **API DOCS**: Document all public endpoints - **WEBHOOK DOCS**: Document webhook payloads and signatures ### Change Documentation - **CHANGELOG**: Document breaking changes - **MIGRATION GUIDES**: Document database migrations - **INTEGRATION GUIDES**: Document new integration patterns ## Environment and Security ### Environment Variables - **CRITICAL**: Never hardcode sensitive values - **VALIDATION**: Validate required environment variables on startup - **SECURITY**: Use secure defaults and proper encryption - **DOCUMENTATION**: Document all environment variables ### File Organization - Node.js/TypeScript Structure - **CONTROLLERS**: Organized by feature (`api/controllers/`) - **SERVICES**: Business logic in service classes (`api/services/`) - **INTEGRATIONS**: External integrations (`api/integrations/`) - **DTOS**: Data transfer objects (`api/dto/`) - **TYPES**: TypeScript types (`api/types/`) - **UTILS**: Utility functions (`utils/`) ## Integration Points ### WhatsApp Providers - **BAILEYS**: WhatsApp Web integration with QR code - **META BUSINESS**: Official WhatsApp Business API - **CLOUD API**: WhatsApp Cloud API integration - **WEBHOOK PROCESSING**: Proper webhook validation and processing ### External Integrations - **CHATWOOT**: Customer support platform integration - **TYPEBOT**: Chatbot flow integration - **OPENAI**: AI-powered chat integration - **DIFY**: AI workflow integration - **STORAGE**: S3/Minio for media file storage ### Event-Driven Communication - **EVENTEMITTER2**: Internal event system - **SOCKET.IO**: Real-time WebSocket communication - **RABBITMQ**: Message queue for async processing - **SQS**: Amazon SQS for cloud-based queuing - **WEBHOOKS**: Outbound webhook system ## Development Constraints ### Language Requirements - **USER COMMUNICATION**: Always respond in Portuguese (PT-BR) - **CODE/COMMENTS**: English for code and technical documentation - **API RESPONSES**: English for consistency - **ERROR MESSAGES**: Portuguese for user-facing errors ### Performance Constraints - **MEMORY**: Efficient memory usage for multiple instances - **DATABASE**: Optimized queries with proper indexing - **CACHE**: Strategic caching for frequently accessed data - **CONNECTIONS**: Proper connection pooling and management ### Security Constraints - **AUTHENTICATION**: API key validation for all endpoints - **AUTHORIZATION**: Instance-based access control - **INPUT VALIDATION**: Validate all inputs with JSONSchema7 - **RATE LIMITING**: Prevent abuse with rate limiting - **WEBHOOK SECURITY**: Validate webhook signatures ## Quality Standards - **TYPE SAFETY**: Full TypeScript coverage with strict mode - **ERROR HANDLING**: Comprehensive error scenarios with proper logging - **TESTING**: Unit and integration tests for critical paths - **MONITORING**: Proper logging and error tracking - **DOCUMENTATION**: Clear API documentation and code comments - **PERFORMANCE**: Optimized for high-throughput message processing - **SECURITY**: Secure by default with proper validation - **SCALABILITY**: Design for horizontal scaling ## Evolution API Specific Development Patterns ### Instance Management - **LIFECYCLE**: Proper instance creation, connection, and cleanup - **STATE MANAGEMENT**: Track connection status and health - **RECOVERY**: Automatic reconnection and error recovery - **MONITORING**: Health checks and status reporting ### Message Processing - **QUEUE-BASED**: Use queues for message processing - **RETRY LOGIC**: Implement exponential backoff for failures - **MEDIA HANDLING**: Proper media upload and processing - **WEBHOOK DELIVERY**: Reliable webhook delivery with retries ### Integration Patterns - **SERVICE LAYER**: Business logic in service classes - **DTO VALIDATION**: Input validation with JSONSchema7 - **ERROR HANDLING**: Consistent error responses - **LOGGING**: Structured logging with correlation IDs ### Database Patterns - **PRISMA**: Use Prisma ORM for all database operations - **TRANSACTIONS**: Use transactions for multi-step operations - **MIGRATIONS**: Proper migration management - **INDEXING**: Optimize queries with appropriate indexes ================================================ FILE: .cursor/rules/specialized-rules/controller-rules.mdc ================================================ --- description: Controller patterns for Evolution API globs: - "src/api/controllers/**/*.ts" - "src/api/integrations/**/controllers/*.ts" alwaysApply: false --- # Evolution API Controller Rules ## Controller Structure Pattern ### Standard Controller Class ```typescript export class ExampleController { constructor(private readonly exampleService: ExampleService) {} public async createExample(instance: InstanceDto, data: ExampleDto) { return this.exampleService.create(instance, data); } public async findExample(instance: InstanceDto) { return this.exampleService.find(instance); } } ``` ## Dependency Injection Pattern ### Service Injection ```typescript // CORRECT - Evolution API pattern export class ChatController { constructor(private readonly waMonitor: WAMonitoringService) {} public async whatsappNumber({ instanceName }: InstanceDto, data: WhatsAppNumberDto) { return await this.waMonitor.waInstances[instanceName].getWhatsAppNumbers(data); } } // INCORRECT - Don't inject multiple services when waMonitor is sufficient export class ChatController { constructor( private readonly waMonitor: WAMonitoringService, private readonly prismaRepository: PrismaRepository, // ❌ Unnecessary if waMonitor has access private readonly configService: ConfigService, // ❌ Unnecessary if waMonitor has access ) {} } ``` ## Method Signature Pattern ### Instance Parameter Pattern ```typescript // CORRECT - Evolution API pattern (destructuring instanceName) public async fetchCatalog({ instanceName }: InstanceDto, data: getCatalogDto) { return await this.waMonitor.waInstances[instanceName].fetchCatalog(instanceName, data); } // CORRECT - Alternative pattern for full instance (when using services) public async createTemplate(instance: InstanceDto, data: TemplateDto) { return this.templateService.create(instance, data); } // INCORRECT - Don't use generic method names public async methodName(instance: InstanceDto, data: DataDto) { // ❌ Use specific names return this.service.performAction(instance, data); } ``` ## WAMonitor Access Pattern ### Direct WAMonitor Usage ```typescript // CORRECT - Standard pattern in controllers export class CallController { constructor(private readonly waMonitor: WAMonitoringService) {} public async offerCall({ instanceName }: InstanceDto, data: OfferCallDto) { return await this.waMonitor.waInstances[instanceName].offerCall(data); } } ``` ## Controller Registration Pattern ### Server Module Registration ```typescript // In server.module.ts export const templateController = new TemplateController(templateService); export const businessController = new BusinessController(waMonitor); export const chatController = new ChatController(waMonitor); export const callController = new CallController(waMonitor); ``` ## Error Handling in Controllers ### Let Services Handle Errors ```typescript // CORRECT - Let service handle errors public async fetchCatalog(instance: InstanceDto, data: getCatalogDto) { return await this.waMonitor.waInstances[instance.instanceName].fetchCatalog(instance.instanceName, data); } // INCORRECT - Don't add try-catch in controllers unless specific handling needed public async fetchCatalog(instance: InstanceDto, data: getCatalogDto) { try { return await this.waMonitor.waInstances[instance.instanceName].fetchCatalog(instance.instanceName, data); } catch (error) { throw error; // ❌ Unnecessary try-catch } } ``` ## Complex Controller Pattern ### Instance Controller Pattern ```typescript export class InstanceController { constructor( private readonly waMonitor: WAMonitoringService, private readonly configService: ConfigService, private readonly prismaRepository: PrismaRepository, private readonly eventEmitter: EventEmitter2, private readonly chatwootService: ChatwootService, private readonly settingsService: SettingsService, private readonly proxyService: ProxyController, private readonly cache: CacheService, private readonly chatwootCache: CacheService, private readonly baileysCache: CacheService, private readonly providerFiles: ProviderFiles, ) {} private readonly logger = new Logger('InstanceController'); // Multiple methods handling different aspects public async createInstance(data: InstanceDto) { // Complex instance creation logic } public async deleteInstance({ instanceName }: InstanceDto) { // Complex instance deletion logic } } ``` ## Channel Controller Pattern ### Base Channel Controller ```typescript export class ChannelController { public prismaRepository: PrismaRepository; public waMonitor: WAMonitoringService; constructor(prismaRepository: PrismaRepository, waMonitor: WAMonitoringService) { this.prisma = prismaRepository; this.monitor = waMonitor; } // Getters and setters for dependency access public set prisma(prisma: PrismaRepository) { this.prismaRepository = prisma; } public get prisma() { return this.prismaRepository; } public set monitor(waMonitor: WAMonitoringService) { this.waMonitor = waMonitor; } public get monitor() { return this.waMonitor; } } ``` ### Extended Channel Controller ```typescript export class EvolutionController extends ChannelController implements ChannelControllerInterface { private readonly logger = new Logger('EvolutionController'); constructor(prismaRepository: PrismaRepository, waMonitor: WAMonitoringService) { super(prismaRepository, waMonitor); } integrationEnabled: boolean; public async receiveWebhook(data: any) { const numberId = data.numberId; if (!numberId) { this.logger.error('WebhookService -> receiveWebhookEvolution -> numberId not found'); return; } const instance = await this.prismaRepository.instance.findFirst({ where: { number: numberId }, }); if (!instance) { this.logger.error('WebhookService -> receiveWebhook -> instance not found'); return; } await this.waMonitor.waInstances[instance.name].connectToWhatsapp(data); return { status: 'success', }; } } ``` ## Chatbot Controller Pattern ### Base Chatbot Controller ```typescript export abstract class BaseChatbotController extends ChatbotController implements ChatbotControllerInterface { public readonly logger: Logger; integrationEnabled: boolean; // Abstract methods to be implemented protected abstract readonly integrationName: string; protected abstract processBot(/* parameters */): Promise; protected abstract getFallbackBotId(settings: any): string | undefined; constructor(prismaRepository: PrismaRepository, waMonitor: WAMonitoringService) { super(prismaRepository, waMonitor); } // Base implementation methods public async createBot(instance: InstanceDto, data: BotData) { // Common bot creation logic } } ``` ## Method Naming Conventions ### Standard Method Names - `create*()` - Create operations - `find*()` - Find operations - `fetch*()` - Fetch from external APIs - `send*()` - Send operations - `receive*()` - Receive webhook/data - `handle*()` - Handle specific actions - `offer*()` - Offer services (like calls) ## Return Patterns ### Direct Return Pattern ```typescript // CORRECT - Direct return from service public async createTemplate(instance: InstanceDto, data: TemplateDto) { return this.templateService.create(instance, data); } // CORRECT - Direct return from waMonitor public async offerCall({ instanceName }: InstanceDto, data: OfferCallDto) { return await this.waMonitor.waInstances[instanceName].offerCall(data); } ``` ## Controller Testing Pattern ### Unit Test Structure ```typescript describe('ExampleController', () => { let controller: ExampleController; let service: jest.Mocked; beforeEach(() => { const mockService = { create: jest.fn(), find: jest.fn(), }; controller = new ExampleController(mockService as any); service = mockService as any; }); describe('createExample', () => { it('should call service create method', async () => { const instance = { instanceName: 'test' }; const data = { test: 'data' }; const expectedResult = { success: true }; service.create.mockResolvedValue(expectedResult); const result = await controller.createExample(instance, data); expect(service.create).toHaveBeenCalledWith(instance, data); expect(result).toEqual(expectedResult); }); }); }); ``` ## Interface Implementation ### Controller Interface Pattern ```typescript export interface ChannelControllerInterface { integrationEnabled: boolean; } export interface ChatbotControllerInterface { integrationEnabled: boolean; createBot(instance: InstanceDto, data: any): Promise; findBot(instance: InstanceDto): Promise; // ... other methods } ``` ## Controller Organization ### File Naming Convention - `*.controller.ts` - Main controllers - `*/*.controller.ts` - Integration-specific controllers ### Method Organization 1. Constructor 2. Public methods (alphabetical order) 3. Private methods (if any) ### Import Organization ```typescript // DTOs first import { InstanceDto } from '@api/dto/instance.dto'; import { ExampleDto } from '@api/dto/example.dto'; // Services import { ExampleService } from '@api/services/example.service'; // Types import { WAMonitoringService } from '@api/services/monitor.service'; ``` ================================================ FILE: .cursor/rules/specialized-rules/dto-rules.mdc ================================================ --- description: DTO patterns and validation for Evolution API globs: - "src/api/dto/**/*.ts" - "src/api/integrations/**/dto/*.ts" alwaysApply: false --- # Evolution API DTO Rules ## DTO Structure Pattern ### Basic DTO Class ```typescript export class ExampleDto { name: string; category: string; allowCategoryChange: boolean; language: string; components: any; webhookUrl?: string; } ``` ## Inheritance Pattern ### DTO Inheritance ```typescript // CORRECT - Evolution API pattern export class InstanceDto extends IntegrationDto { instanceName: string; instanceId?: string; qrcode?: boolean; businessId?: string; number?: string; integration?: string; token?: string; status?: string; ownerJid?: string; profileName?: string; profilePicUrl?: string; // Settings rejectCall?: boolean; msgCall?: string; groupsIgnore?: boolean; alwaysOnline?: boolean; readMessages?: boolean; readStatus?: boolean; syncFullHistory?: boolean; wavoipToken?: string; // Proxy settings proxyHost?: string; proxyPort?: string; proxyProtocol?: string; proxyUsername?: string; proxyPassword?: string; // Webhook configuration webhook?: { enabled?: boolean; events?: string[]; headers?: JsonValue; url?: string; byEvents?: boolean; base64?: boolean; }; // Chatwoot integration chatwootAccountId?: string; chatwootConversationPending?: boolean; chatwootAutoCreate?: boolean; chatwootDaysLimitImportMessages?: number; chatwootImportContacts?: boolean; chatwootImportMessages?: boolean; chatwootLogo?: string; chatwootMergeBrazilContacts?: boolean; chatwootNameInbox?: string; chatwootOrganization?: string; chatwootReopenConversation?: boolean; chatwootSignMsg?: boolean; chatwootToken?: string; chatwootUrl?: string; } ``` ## Base DTO Pattern ### Base Chatbot DTO ```typescript /** * Base DTO for all chatbot integrations * Contains common properties shared by all chatbot types */ export class BaseChatbotDto { enabled?: boolean; description: string; expire?: number; keywordFinish?: string; delayMessage?: number; unknownMessage?: string; listeningFromMe?: boolean; stopBotFromMe?: boolean; keepOpen?: boolean; debounceTime?: number; triggerType: TriggerType; triggerOperator?: TriggerOperator; triggerValue?: string; ignoreJids?: string[]; splitMessages?: boolean; timePerChar?: number; } /** * Base settings DTO for all chatbot integrations */ export class BaseChatbotSettingDto { expire?: number; keywordFinish?: string; delayMessage?: number; unknownMessage?: string; listeningFromMe?: boolean; stopBotFromMe?: boolean; keepOpen?: boolean; debounceTime?: number; ignoreJids?: string[]; splitMessages?: boolean; timePerChar?: number; } ``` ## Message DTO Patterns ### Send Message DTOs ```typescript export class Metadata { number: string; delay?: number; } export class SendTextDto extends Metadata { text: string; linkPreview?: boolean; mentionsEveryOne?: boolean; mentioned?: string[]; } export class SendListDto extends Metadata { title: string; description: string; buttonText: string; footerText?: string; sections: Section[]; } export class ContactMessage { fullName: string; wuid: string; phoneNumber: string; organization?: string; email?: string; url?: string; } export class SendTemplateDto extends Metadata { name: string; language: string; components: any; } ``` ## Simple DTO Patterns ### Basic DTOs ```typescript export class NumberDto { number: string; } export class LabelDto { id?: string; name: string; color: string; predefinedId?: string; } export class HandleLabelDto { number: string; labelId: string; } export class ProfileNameDto { name: string; } export class WhatsAppNumberDto { numbers: string[]; } ``` ## Complex DTO Patterns ### Business DTOs ```typescript export class getCatalogDto { number?: string; limit?: number; cursor?: string; } export class getCollectionsDto { number?: string; limit?: number; cursor?: string; } export class NumberBusiness { number: string; name?: string; description?: string; email?: string; websites?: string[]; latitude?: number; longitude?: number; address?: string; profilehandle?: string; } ``` ## Settings DTO Pattern ### Settings Configuration ```typescript export class SettingsDto { rejectCall?: boolean; msgCall?: string; groupsIgnore?: boolean; alwaysOnline?: boolean; readMessages?: boolean; readStatus?: boolean; syncFullHistory?: boolean; wavoipToken?: string; } export class ProxyDto { host?: string; port?: string; protocol?: string; username?: string; password?: string; } ``` ## Presence DTO Pattern ### WhatsApp Presence ```typescript export class SetPresenceDto { presence: WAPresence; } export class SendPresenceDto { number: string; presence: WAPresence; } ``` ## DTO Structure (No Decorators) ### Simple DTO Classes (Evolution API Pattern) ```typescript // CORRECT - Evolution API pattern (no decorators) export class ExampleDto { name: string; description?: string; enabled: boolean; items?: string[]; timeout?: number; } // INCORRECT - Don't use class-validator decorators export class ValidatedDto { @IsString() // ❌ Evolution API doesn't use decorators name: string; } ``` ## Type Safety Patterns ### Prisma Type Integration ```typescript import { JsonValue } from '@prisma/client/runtime/library'; import { WAPresence } from 'baileys'; import { TriggerOperator, TriggerType } from '@prisma/client'; export class TypeSafeDto { presence: WAPresence; triggerType: TriggerType; triggerOperator?: TriggerOperator; metadata?: JsonValue; } ``` ## DTO Documentation ### JSDoc Comments ```typescript /** * DTO for creating WhatsApp templates * Used by Meta Business API integration */ export class TemplateDto { /** Template name - must be unique */ name: string; /** Template category (MARKETING, UTILITY, AUTHENTICATION) */ category: string; /** Whether category can be changed after creation */ allowCategoryChange: boolean; /** Language code (e.g., 'pt_BR', 'en_US') */ language: string; /** Template components (header, body, footer, buttons) */ components: any; /** Optional webhook URL for template status updates */ webhookUrl?: string; } ``` ## DTO Naming Conventions ### Standard Naming Patterns - `*Dto` - Data transfer objects - `Create*Dto` - Creation DTOs - `Update*Dto` - Update DTOs - `Send*Dto` - Message sending DTOs - `Get*Dto` - Query DTOs - `Handle*Dto` - Action DTOs ## File Organization ### DTO File Structure ``` src/api/dto/ ├── instance.dto.ts # Main instance DTO ├── template.dto.ts # Template management ├── sendMessage.dto.ts # Message sending DTOs ├── chat.dto.ts # Chat operations ├── business.dto.ts # Business API DTOs ├── group.dto.ts # Group management ├── label.dto.ts # Label management ├── proxy.dto.ts # Proxy configuration ├── settings.dto.ts # Instance settings └── call.dto.ts # Call operations ``` ## Integration DTO Patterns ### Chatbot Integration DTOs ```typescript // Base for all chatbot DTOs export class BaseChatbotDto { enabled?: boolean; description: string; // ... common properties } // Specific chatbot DTOs extend base export class TypebotDto extends BaseChatbotDto { url: string; typebot: string; // ... typebot-specific properties } export class OpenaiDto extends BaseChatbotDto { apiKey: string; model: string; // ... openai-specific properties } ``` ## DTO Testing Pattern ### DTO Validation Tests ```typescript describe('ExampleDto', () => { it('should validate required fields', () => { const dto = new ExampleDto(); dto.name = 'test'; dto.category = 'MARKETING'; dto.allowCategoryChange = true; dto.language = 'pt_BR'; dto.components = {}; expect(dto.name).toBe('test'); expect(dto.category).toBe('MARKETING'); }); it('should handle optional fields', () => { const dto = new ExampleDto(); dto.name = 'test'; dto.category = 'MARKETING'; dto.allowCategoryChange = true; dto.language = 'pt_BR'; dto.components = {}; dto.webhookUrl = 'https://example.com/webhook'; expect(dto.webhookUrl).toBe('https://example.com/webhook'); }); }); ``` ## DTO Transformation ### Request to DTO Mapping (Evolution API Pattern) ```typescript // CORRECT - Evolution API uses RouterBroker dataValidate const response = await this.dataValidate({ request: req, schema: exampleSchema, // JSONSchema7 ClassRef: ExampleDto, execute: (instance, data) => controller.method(instance, data), }); // INCORRECT - Don't use class-validator const dto = plainToClass(ExampleDto, req.body); // ❌ Not used in Evolution API const errors = await validate(dto); // ❌ Not used in Evolution API ``` ================================================ FILE: .cursor/rules/specialized-rules/guard-rules.mdc ================================================ --- description: Guard patterns for authentication and authorization in Evolution API globs: - "src/api/guards/**/*.ts" alwaysApply: false --- # Evolution API Guard Rules ## Guard Structure Pattern ### Standard Guard Function ```typescript import { NextFunction, Request, Response } from 'express'; import { Logger } from '@config/logger.config'; import { UnauthorizedException, ForbiddenException } from '@exceptions'; const logger = new Logger('GUARD'); async function guardFunction(req: Request, _: Response, next: NextFunction) { // Guard logic here if (validationFails) { throw new UnauthorizedException(); } return next(); } export const guardName = { guardFunction }; ``` ## Authentication Guard Pattern ### API Key Authentication ```typescript async function apikey(req: Request, _: Response, next: NextFunction) { const env = configService.get('AUTHENTICATION').API_KEY; const key = req.get('apikey'); const db = configService.get('DATABASE'); if (!key) { throw new UnauthorizedException(); } // Global API key check if (env.KEY === key) { return next(); } // Special routes handling if ((req.originalUrl.includes('/instance/create') || req.originalUrl.includes('/instance/fetchInstances')) && !key) { throw new ForbiddenException('Missing global api key', 'The global api key must be set'); } const param = req.params as unknown as InstanceDto; try { if (param?.instanceName) { const instance = await prismaRepository.instance.findUnique({ where: { name: param.instanceName }, }); if (instance.token === key) { return next(); } } else { if (req.originalUrl.includes('/instance/fetchInstances') && db.SAVE_DATA.INSTANCE) { const instanceByKey = await prismaRepository.instance.findFirst({ where: { token: key }, }); if (instanceByKey) { return next(); } } } } catch (error) { logger.error(error); } throw new UnauthorizedException(); } export const authGuard = { apikey }; ``` ## Instance Validation Guards ### Instance Exists Guard ```typescript async function getInstance(instanceName: string) { try { const cacheConf = configService.get('CACHE'); const exists = !!waMonitor.waInstances[instanceName]; if (cacheConf.REDIS.ENABLED && cacheConf.REDIS.SAVE_INSTANCES) { const keyExists = await cache.has(instanceName); return exists || keyExists; } return exists || (await prismaRepository.instance.findMany({ where: { name: instanceName } })).length > 0; } catch (error) { throw new InternalServerErrorException(error?.toString()); } } export async function instanceExistsGuard(req: Request, _: Response, next: NextFunction) { if (req.originalUrl.includes('/instance/create')) { return next(); } const param = req.params as unknown as InstanceDto; if (!param?.instanceName) { throw new BadRequestException('"instanceName" not provided.'); } if (!(await getInstance(param.instanceName))) { throw new NotFoundException(`The "${param.instanceName}" instance does not exist`); } next(); } ``` ### Instance Logged Guard ```typescript export async function instanceLoggedGuard(req: Request, _: Response, next: NextFunction) { if (req.originalUrl.includes('/instance/create')) { const instance = req.body as InstanceDto; if (await getInstance(instance.instanceName)) { throw new ForbiddenException(`This name "${instance.instanceName}" is already in use.`); } if (waMonitor.waInstances[instance.instanceName]) { delete waMonitor.waInstances[instance.instanceName]; } } next(); } ``` ## Telemetry Guard Pattern ### Telemetry Collection ```typescript class Telemetry { public collectTelemetry(req: Request, res: Response, next: NextFunction): void { // Collect telemetry data const telemetryData = { route: req.originalUrl, method: req.method, timestamp: new Date(), userAgent: req.get('User-Agent'), }; // Send telemetry asynchronously (don't block request) setImmediate(() => { this.sendTelemetry(telemetryData); }); next(); } private async sendTelemetry(data: any): Promise { try { // Send telemetry data } catch (error) { // Silently fail - don't affect main request } } } export default Telemetry; ``` ## Guard Composition Pattern ### Multiple Guards Usage ```typescript // In router setup const guards = [instanceExistsGuard, instanceLoggedGuard, authGuard['apikey']]; router .use('/instance', new InstanceRouter(configService, ...guards).router) .use('/message', new MessageRouter(...guards).router) .use('/chat', new ChatRouter(...guards).router); ``` ## Error Handling in Guards ### Proper Exception Throwing ```typescript // CORRECT - Use proper HTTP exceptions if (!apiKey) { throw new UnauthorizedException('API key required'); } if (instanceExists) { throw new ForbiddenException('Instance already exists'); } if (!instanceFound) { throw new NotFoundException('Instance not found'); } if (validationFails) { throw new BadRequestException('Invalid request parameters'); } // INCORRECT - Don't use generic Error if (!apiKey) { throw new Error('API key required'); // ❌ Use specific exceptions } ``` ## Configuration Access in Guards ### Config Service Usage ```typescript async function configAwareGuard(req: Request, _: Response, next: NextFunction) { const authConfig = configService.get('AUTHENTICATION'); const cacheConfig = configService.get('CACHE'); const dbConfig = configService.get('DATABASE'); // Use configuration for guard logic if (authConfig.API_KEY.KEY === providedKey) { return next(); } throw new UnauthorizedException(); } ``` ## Database Access in Guards ### Prisma Repository Usage ```typescript async function databaseGuard(req: Request, _: Response, next: NextFunction) { try { const param = req.params as unknown as InstanceDto; const instance = await prismaRepository.instance.findUnique({ where: { name: param.instanceName }, }); if (!instance) { throw new NotFoundException('Instance not found'); } // Additional validation logic if (instance.status !== 'active') { throw new ForbiddenException('Instance not active'); } return next(); } catch (error) { logger.error('Database guard error:', error); throw new InternalServerErrorException('Database access failed'); } } ``` ## Cache Integration in Guards ### Cache Service Usage ```typescript async function cacheAwareGuard(req: Request, _: Response, next: NextFunction) { const cacheConf = configService.get('CACHE'); if (cacheConf.REDIS.ENABLED) { const cached = await cache.get(`guard:${req.params.instanceName}`); if (cached) { // Use cached validation result return next(); } } // Perform validation and cache result const isValid = await performValidation(req.params.instanceName); if (cacheConf.REDIS.ENABLED) { await cache.set(`guard:${req.params.instanceName}`, isValid, 300); // 5 min TTL } if (isValid) { return next(); } throw new UnauthorizedException(); } ``` ## Logging in Guards ### Structured Logging ```typescript const logger = new Logger('GUARD'); async function loggedGuard(req: Request, _: Response, next: NextFunction) { logger.log(`Guard validation started for ${req.originalUrl}`); try { // Guard logic const isValid = await validateRequest(req); if (isValid) { logger.log(`Guard validation successful for ${req.params.instanceName}`); return next(); } logger.warn(`Guard validation failed for ${req.params.instanceName}`); throw new UnauthorizedException(); } catch (error) { logger.error(`Guard validation error: ${error.message}`, error.stack); throw error; } } ``` ## Guard Testing Pattern ### Unit Test Structure ```typescript describe('authGuard', () => { let req: Partial; let res: Partial; let next: NextFunction; beforeEach(() => { req = { get: jest.fn(), params: {}, originalUrl: '/test', }; res = {}; next = jest.fn(); }); describe('apikey', () => { it('should pass with valid global API key', async () => { (req.get as jest.Mock).mockReturnValue('valid-global-key'); await authGuard.apikey(req as Request, res as Response, next); expect(next).toHaveBeenCalled(); }); it('should throw UnauthorizedException with no API key', async () => { (req.get as jest.Mock).mockReturnValue(undefined); await expect( authGuard.apikey(req as Request, res as Response, next) ).rejects.toThrow(UnauthorizedException); }); it('should pass with valid instance token', async () => { (req.get as jest.Mock).mockReturnValue('instance-token'); req.params = { instanceName: 'test-instance' }; // Mock prisma repository jest.spyOn(prismaRepository.instance, 'findUnique').mockResolvedValue({ token: 'instance-token', } as any); await authGuard.apikey(req as Request, res as Response, next); expect(next).toHaveBeenCalled(); }); }); }); ``` ## Guard Performance Considerations ### Efficient Validation ```typescript // CORRECT - Efficient guard with early returns async function efficientGuard(req: Request, _: Response, next: NextFunction) { // Quick checks first if (req.originalUrl.includes('/public')) { return next(); // Skip validation for public routes } const apiKey = req.get('apikey'); if (!apiKey) { throw new UnauthorizedException(); // Fail fast } // More expensive checks only if needed if (apiKey === globalKey) { return next(); // Skip database check } // Database check only as last resort const isValid = await validateInDatabase(apiKey); if (isValid) { return next(); } throw new UnauthorizedException(); } // INCORRECT - Inefficient guard async function inefficientGuard(req: Request, _: Response, next: NextFunction) { // Always do expensive database check first const dbResult = await expensiveDatabaseQuery(); // ❌ Expensive operation first const apiKey = req.get('apikey'); if (!apiKey && dbResult) { // ❌ Complex logic throw new UnauthorizedException(); } next(); } ``` ================================================ FILE: .cursor/rules/specialized-rules/integration-channel-rules.mdc ================================================ --- description: Channel integration patterns for Evolution API globs: - "src/api/integrations/channel/**/*.ts" alwaysApply: false --- # Evolution API Channel Integration Rules ## Channel Controller Pattern ### Base Channel Controller ```typescript export interface ChannelControllerInterface { integrationEnabled: boolean; } export class ChannelController { public prismaRepository: PrismaRepository; public waMonitor: WAMonitoringService; constructor(prismaRepository: PrismaRepository, waMonitor: WAMonitoringService) { this.prisma = prismaRepository; this.monitor = waMonitor; } public set prisma(prisma: PrismaRepository) { this.prismaRepository = prisma; } public get prisma() { return this.prismaRepository; } public set monitor(waMonitor: WAMonitoringService) { this.waMonitor = waMonitor; } public get monitor() { return this.waMonitor; } public init(instanceData: InstanceDto, data: ChannelDataType) { if (!instanceData.token && instanceData.integration === Integration.WHATSAPP_BUSINESS) { throw new BadRequestException('token is required'); } if (instanceData.integration === Integration.WHATSAPP_BUSINESS) { return new BusinessStartupService(/* dependencies */); } if (instanceData.integration === Integration.EVOLUTION) { return new EvolutionStartupService(/* dependencies */); } if (instanceData.integration === Integration.WHATSAPP_BAILEYS) { return new BaileysStartupService(/* dependencies */); } return null; } } ``` ### Extended Channel Controller ```typescript export class EvolutionController extends ChannelController implements ChannelControllerInterface { private readonly logger = new Logger('EvolutionController'); constructor(prismaRepository: PrismaRepository, waMonitor: WAMonitoringService) { super(prismaRepository, waMonitor); } integrationEnabled: boolean; public async receiveWebhook(data: any) { const numberId = data.numberId; if (!numberId) { this.logger.error('WebhookService -> receiveWebhookEvolution -> numberId not found'); return; } const instance = await this.prismaRepository.instance.findFirst({ where: { number: numberId }, }); if (!instance) { this.logger.error('WebhookService -> receiveWebhook -> instance not found'); return; } await this.waMonitor.waInstances[instance.name].connectToWhatsapp(data); return { status: 'success', }; } } ``` ## Channel Service Pattern ### Base Channel Service ```typescript export class ChannelStartupService { constructor( private readonly configService: ConfigService, private readonly eventEmitter: EventEmitter2, private readonly prismaRepository: PrismaRepository, public readonly cache: CacheService, public readonly chatwootCache: CacheService, ) {} public readonly logger = new Logger('ChannelStartupService'); public client: WASocket; public readonly instance: wa.Instance = {}; public readonly localChatwoot: wa.LocalChatwoot = {}; public readonly localProxy: wa.LocalProxy = {}; public readonly localSettings: wa.LocalSettings = {}; public readonly localWebhook: wa.LocalWebHook = {}; public setInstance(instance: InstanceDto) { this.logger.setInstance(instance.instanceName); this.instance.name = instance.instanceName; this.instance.id = instance.instanceId; this.instance.integration = instance.integration; this.instance.number = instance.number; this.instance.token = instance.token; this.instance.businessId = instance.businessId; if (this.configService.get('CHATWOOT').ENABLED && this.localChatwoot?.enabled) { this.chatwootService.eventWhatsapp( Events.STATUS_INSTANCE, { instanceName: this.instance.name }, { instance: this.instance.name, status: 'created', }, ); } } public set instanceName(name: string) { this.logger.setInstance(name); this.instance.name = name; } public get instanceName() { return this.instance.name; } } ``` ### Extended Channel Service ```typescript export class EvolutionStartupService extends ChannelStartupService { constructor( configService: ConfigService, eventEmitter: EventEmitter2, prismaRepository: PrismaRepository, cache: CacheService, chatwootCache: CacheService, ) { super(configService, eventEmitter, prismaRepository, cache, chatwootCache); } public async sendMessage(data: SendTextDto): Promise { // Evolution-specific message sending logic const response = await this.evolutionApiCall('/send-message', data); return response; } public async connectToWhatsapp(data: any): Promise { // Evolution-specific connection logic this.logger.log('Connecting to Evolution API'); // Set up webhook listeners this.setupWebhookHandlers(); // Initialize connection await this.initializeConnection(data); } private async evolutionApiCall(endpoint: string, data: any): Promise { const config = this.configService.get('EVOLUTION'); try { const response = await axios.post(`${config.API_URL}${endpoint}`, data, { headers: { 'Authorization': `Bearer ${this.instance.token}`, 'Content-Type': 'application/json', }, }); return response.data; } catch (error) { this.logger.error(`Evolution API call failed: ${error.message}`); throw new InternalServerErrorException('Evolution API call failed'); } } private setupWebhookHandlers(): void { // Set up webhook event handlers } private async initializeConnection(data: any): Promise { // Initialize connection with Evolution API } } ``` ## Business API Service Pattern ### Meta Business Service ```typescript export class BusinessStartupService extends ChannelStartupService { constructor( configService: ConfigService, eventEmitter: EventEmitter2, prismaRepository: PrismaRepository, cache: CacheService, chatwootCache: CacheService, baileysCache: CacheService, providerFiles: ProviderFiles, ) { super(configService, eventEmitter, prismaRepository, cache, chatwootCache); } public async sendMessage(data: SendTextDto): Promise { const businessConfig = this.configService.get('WA_BUSINESS'); const payload = { messaging_product: 'whatsapp', to: data.number, type: 'text', text: { body: data.text, }, }; try { const response = await axios.post( `${businessConfig.URL}/${businessConfig.VERSION}/${this.instance.businessId}/messages`, payload, { headers: { 'Authorization': `Bearer ${this.instance.token}`, 'Content-Type': 'application/json', }, } ); return response.data; } catch (error) { this.logger.error(`Business API call failed: ${error.message}`); throw new BadRequestException('Failed to send message via Business API'); } } public async receiveWebhook(data: any): Promise { // Process incoming webhook from Meta Business API const { entry } = data; for (const entryItem of entry) { const { changes } = entryItem; for (const change of changes) { if (change.field === 'messages') { await this.processMessage(change.value); } } } } private async processMessage(messageData: any): Promise { // Process incoming message from Business API const { messages, contacts } = messageData; if (messages) { for (const message of messages) { await this.handleIncomingMessage(message, contacts); } } } private async handleIncomingMessage(message: any, contacts: any[]): Promise { // Handle individual message const contact = contacts?.find(c => c.wa_id === message.from); // Emit event for message processing this.eventEmitter.emit(Events.MESSAGES_UPSERT, { instanceName: this.instance.name, message, contact, }); } } ``` ## Baileys Service Pattern ### Baileys Integration Service ```typescript export class BaileysStartupService extends ChannelStartupService { constructor( configService: ConfigService, eventEmitter: EventEmitter2, prismaRepository: PrismaRepository, cache: CacheService, chatwootCache: CacheService, baileysCache: CacheService, providerFiles: ProviderFiles, ) { super(configService, eventEmitter, prismaRepository, cache, chatwootCache); } public async connectToWhatsapp(): Promise { const authPath = path.join(INSTANCE_DIR, this.instance.name); const { state, saveCreds } = await useMultiFileAuthState(authPath); this.client = makeWASocket({ auth: state, logger: P({ level: 'error' }), printQRInTerminal: false, browser: ['Evolution API', 'Chrome', '4.0.0'], defaultQueryTimeoutMs: 60000, }); this.setupEventHandlers(); this.client.ev.on('creds.update', saveCreds); } private setupEventHandlers(): void { this.client.ev.on('connection.update', (update) => { this.handleConnectionUpdate(update); }); this.client.ev.on('messages.upsert', ({ messages, type }) => { this.handleIncomingMessages(messages, type); }); this.client.ev.on('messages.update', (updates) => { this.handleMessageUpdates(updates); }); this.client.ev.on('contacts.upsert', (contacts) => { this.handleContactsUpdate(contacts); }); this.client.ev.on('chats.upsert', (chats) => { this.handleChatsUpdate(chats); }); } private async handleConnectionUpdate(update: ConnectionUpdate): Promise { const { connection, lastDisconnect, qr } = update; if (qr) { this.instance.qrcode = { count: this.instance.qrcode?.count ? this.instance.qrcode.count + 1 : 1, base64: qr, }; this.eventEmitter.emit(Events.QRCODE_UPDATED, { instanceName: this.instance.name, qrcode: this.instance.qrcode, }); } if (connection === 'close') { const shouldReconnect = (lastDisconnect?.error as Boom)?.output?.statusCode !== DisconnectReason.loggedOut; if (shouldReconnect) { this.logger.log('Connection closed, reconnecting...'); await this.connectToWhatsapp(); } else { this.logger.log('Connection closed, logged out'); this.eventEmitter.emit(Events.LOGOUT_INSTANCE, { instanceName: this.instance.name, }); } } if (connection === 'open') { this.logger.log('Connection opened successfully'); this.instance.wuid = this.client.user?.id; this.eventEmitter.emit(Events.CONNECTION_UPDATE, { instanceName: this.instance.name, state: 'open', }); } } public async sendMessage(data: SendTextDto): Promise { const jid = createJid(data.number); const message = { text: data.text, }; if (data.linkPreview !== undefined) { message.linkPreview = data.linkPreview; } if (data.mentionsEveryOne) { // Handle mentions } try { const response = await this.client.sendMessage(jid, message); return response; } catch (error) { this.logger.error(`Failed to send message: ${error.message}`); throw new BadRequestException('Failed to send message'); } } } ``` ## Channel Router Pattern ### Channel Router Structure ```typescript export class ChannelRouter { public readonly router: Router; constructor(configService: any, ...guards: any[]) { this.router = Router(); this.router.use('/', new EvolutionRouter(configService).router); this.router.use('/', new MetaRouter(configService).router); this.router.use('/baileys', new BaileysRouter(...guards).router); } } ``` ### Specific Channel Router ```typescript export class EvolutionRouter extends RouterBroker { constructor(private readonly configService: ConfigService) { super(); this.router .post(this.routerPath('webhook'), async (req, res) => { const response = await evolutionController.receiveWebhook(req.body); return res.status(HttpStatus.OK).json(response); }); } public readonly router: Router = Router(); } ``` ## Integration Types ### Channel Data Types ```typescript type ChannelDataType = { configService: ConfigService; eventEmitter: EventEmitter2; prismaRepository: PrismaRepository; cache: CacheService; chatwootCache: CacheService; baileysCache: CacheService; providerFiles: ProviderFiles; }; export enum Integration { WHATSAPP_BUSINESS = 'WHATSAPP-BUSINESS', WHATSAPP_BAILEYS = 'WHATSAPP-BAILEYS', EVOLUTION = 'EVOLUTION', } ``` ## Error Handling in Channels ### Channel-Specific Error Handling ```typescript // CORRECT - Channel-specific error handling public async sendMessage(data: SendTextDto): Promise { try { const response = await this.channelSpecificSend(data); return response; } catch (error) { this.logger.error(`${this.constructor.name} send failed: ${error.message}`); if (error.response?.status === 401) { throw new UnauthorizedException('Invalid token for channel'); } if (error.response?.status === 429) { throw new BadRequestException('Rate limit exceeded'); } throw new InternalServerErrorException('Channel communication failed'); } } ``` ## Channel Testing Pattern ### Channel Service Testing ```typescript describe('EvolutionStartupService', () => { let service: EvolutionStartupService; let configService: jest.Mocked; let eventEmitter: jest.Mocked; beforeEach(() => { const mockConfig = { get: jest.fn().mockReturnValue({ API_URL: 'https://api.evolution.com', }), }; service = new EvolutionStartupService( mockConfig as any, eventEmitter, prismaRepository, cache, chatwootCache, ); }); describe('sendMessage', () => { it('should send message successfully', async () => { const data = { number: '5511999999999', text: 'Test message' }; // Mock axios response jest.spyOn(axios, 'post').mockResolvedValue({ data: { success: true, messageId: '123' }, }); const result = await service.sendMessage(data); expect(result.success).toBe(true); expect(axios.post).toHaveBeenCalledWith( expect.stringContaining('/send-message'), data, expect.objectContaining({ headers: expect.objectContaining({ 'Authorization': expect.stringContaining('Bearer'), }), }) ); }); }); }); ``` ================================================ FILE: .cursor/rules/specialized-rules/integration-chatbot-rules.mdc ================================================ --- description: Chatbot integration patterns for Evolution API globs: - "src/api/integrations/chatbot/**/*.ts" alwaysApply: false --- # Evolution API Chatbot Integration Rules ## Base Chatbot Pattern ### Base Chatbot DTO ```typescript /** * Base DTO for all chatbot integrations * Contains common properties shared by all chatbot types */ export class BaseChatbotDto { enabled?: boolean; description: string; expire?: number; keywordFinish?: string; delayMessage?: number; unknownMessage?: string; listeningFromMe?: boolean; stopBotFromMe?: boolean; keepOpen?: boolean; debounceTime?: number; triggerType: TriggerType; triggerOperator?: TriggerOperator; triggerValue?: string; ignoreJids?: string[]; splitMessages?: boolean; timePerChar?: number; } ``` ### Base Chatbot Controller ```typescript export abstract class BaseChatbotController extends ChatbotController implements ChatbotControllerInterface { public readonly logger: Logger; integrationEnabled: boolean; botRepository: any; settingsRepository: any; sessionRepository: any; userMessageDebounce: { [key: string]: { message: string; timeoutId: NodeJS.Timeout } } = {}; // Abstract methods to be implemented by specific chatbots protected abstract readonly integrationName: string; protected abstract processBot( waInstance: any, remoteJid: string, bot: BotType, session: any, settings: ChatbotSettings, content: string, pushName?: string, msg?: any, ): Promise; protected abstract getFallbackBotId(settings: any): string | undefined; constructor(prismaRepository: PrismaRepository, waMonitor: WAMonitoringService) { super(prismaRepository, waMonitor); this.sessionRepository = this.prismaRepository.integrationSession; } // Base implementation methods public async createBot(instance: InstanceDto, data: BotData) { if (!data.enabled) { throw new BadRequestException(`${this.integrationName} is disabled`); } // Common bot creation logic const bot = await this.botRepository.create({ data: { ...data, instanceId: instance.instanceId, }, }); return bot; } } ``` ### Base Chatbot Service ```typescript /** * Base class for all chatbot service implementations * Contains common methods shared across different chatbot integrations */ export abstract class BaseChatbotService { protected readonly logger: Logger; protected readonly waMonitor: WAMonitoringService; protected readonly prismaRepository: PrismaRepository; protected readonly configService?: ConfigService; constructor( waMonitor: WAMonitoringService, prismaRepository: PrismaRepository, loggerName: string, configService?: ConfigService, ) { this.waMonitor = waMonitor; this.prismaRepository = prismaRepository; this.logger = new Logger(loggerName); this.configService = configService; } /** * Check if a message contains an image */ protected isImageMessage(content: string): boolean { return content.includes('imageMessage'); } /** * Extract text content from message */ protected getMessageContent(msg: any): string { return getConversationMessage(msg); } /** * Send typing indicator */ protected async sendTyping(instanceName: string, remoteJid: string): Promise { await this.waMonitor.waInstances[instanceName].sendPresence(remoteJid, 'composing'); } } ``` ## Typebot Integration Pattern ### Typebot Service ```typescript export class TypebotService extends BaseChatbotService { constructor( waMonitor: WAMonitoringService, configService: ConfigService, prismaRepository: PrismaRepository, private readonly openaiService: OpenaiService, ) { super(waMonitor, prismaRepository, 'TypebotService', configService); } public async sendTypebotMessage( instanceName: string, remoteJid: string, typebot: TypebotModel, content: string, ): Promise { try { const response = await axios.post( `${typebot.url}/api/v1/typebots/${typebot.typebot}/startChat`, { message: content, sessionId: `${instanceName}-${remoteJid}`, }, { headers: { 'Content-Type': 'application/json', }, } ); const { messages } = response.data; for (const message of messages) { await this.processTypebotMessage(instanceName, remoteJid, message); } } catch (error) { this.logger.error(`Typebot API error: ${error.message}`); throw new InternalServerErrorException('Typebot communication failed'); } } private async processTypebotMessage( instanceName: string, remoteJid: string, message: any, ): Promise { const waInstance = this.waMonitor.waInstances[instanceName]; if (message.type === 'text') { await waInstance.sendMessage({ number: remoteJid.split('@')[0], text: message.content.richText[0].children[0].text, }); } if (message.type === 'image') { await waInstance.sendMessage({ number: remoteJid.split('@')[0], mediaMessage: { mediatype: 'image', media: message.content.url, }, }); } } } ``` ## OpenAI Integration Pattern ### OpenAI Service ```typescript export class OpenaiService extends BaseChatbotService { constructor( waMonitor: WAMonitoringService, prismaRepository: PrismaRepository, configService: ConfigService, ) { super(waMonitor, prismaRepository, 'OpenaiService', configService); } public async sendOpenaiMessage( instanceName: string, remoteJid: string, openai: OpenaiModel, content: string, pushName?: string, ): Promise { try { const openaiConfig = this.configService.get('OPENAI'); const response = await axios.post( 'https://api.openai.com/v1/chat/completions', { model: openai.model || 'gpt-3.5-turbo', messages: [ { role: 'system', content: openai.systemMessage || 'You are a helpful assistant.', }, { role: 'user', content: content, }, ], max_tokens: openai.maxTokens || 1000, temperature: openai.temperature || 0.7, }, { headers: { 'Authorization': `Bearer ${openai.apiKey || openaiConfig.API_KEY}`, 'Content-Type': 'application/json', }, } ); const aiResponse = response.data.choices[0].message.content; await this.waMonitor.waInstances[instanceName].sendMessage({ number: remoteJid.split('@')[0], text: aiResponse, }); } catch (error) { this.logger.error(`OpenAI API error: ${error.message}`); // Send fallback message await this.waMonitor.waInstances[instanceName].sendMessage({ number: remoteJid.split('@')[0], text: openai.unknownMessage || 'Desculpe, não consegui processar sua mensagem.', }); } } } ``` ## Chatwoot Integration Pattern ### Chatwoot Service ```typescript export class ChatwootService extends BaseChatbotService { constructor( waMonitor: WAMonitoringService, configService: ConfigService, prismaRepository: PrismaRepository, private readonly chatwootCache: CacheService, ) { super(waMonitor, prismaRepository, 'ChatwootService', configService); } public async eventWhatsapp( event: Events, instanceName: { instanceName: string }, data: any, ): Promise { const chatwootConfig = this.configService.get('CHATWOOT'); if (!chatwootConfig.ENABLED) { return; } try { const instance = await this.prismaRepository.instance.findUnique({ where: { name: instanceName.instanceName }, }); if (!instance?.chatwootAccountId) { return; } const webhook = { event, instance: instanceName.instanceName, data, timestamp: new Date().toISOString(), }; await axios.post( `${instance.chatwootUrl}/api/v1/accounts/${instance.chatwootAccountId}/webhooks`, webhook, { headers: { 'Authorization': `Bearer ${instance.chatwootToken}`, 'Content-Type': 'application/json', }, } ); } catch (error) { this.logger.error(`Chatwoot webhook error: ${error.message}`); } } public async createConversation( instanceName: string, contact: any, message: any, ): Promise { // Create conversation in Chatwoot const instance = await this.prismaRepository.instance.findUnique({ where: { name: instanceName }, }); if (!instance?.chatwootAccountId) { return; } try { const conversation = await axios.post( `${instance.chatwootUrl}/api/v1/accounts/${instance.chatwootAccountId}/conversations`, { source_id: contact.id, inbox_id: instance.chatwootInboxId, contact_id: contact.chatwootContactId, }, { headers: { 'Authorization': `Bearer ${instance.chatwootToken}`, 'Content-Type': 'application/json', }, } ); // Cache conversation await this.chatwootCache.set( `conversation:${instanceName}:${contact.id}`, conversation.data, 3600 ); } catch (error) { this.logger.error(`Chatwoot conversation creation error: ${error.message}`); } } } ``` ## Dify Integration Pattern ### Dify Service ```typescript export class DifyService extends BaseChatbotService { constructor( waMonitor: WAMonitoringService, prismaRepository: PrismaRepository, configService: ConfigService, private readonly openaiService: OpenaiService, ) { super(waMonitor, prismaRepository, 'DifyService', configService); } public async sendDifyMessage( instanceName: string, remoteJid: string, dify: DifyModel, content: string, ): Promise { try { const response = await axios.post( `${dify.apiUrl}/v1/chat-messages`, { inputs: {}, query: content, user: remoteJid, conversation_id: `${instanceName}-${remoteJid}`, response_mode: 'blocking', }, { headers: { 'Authorization': `Bearer ${dify.apiKey}`, 'Content-Type': 'application/json', }, } ); const aiResponse = response.data.answer; await this.waMonitor.waInstances[instanceName].sendMessage({ number: remoteJid.split('@')[0], text: aiResponse, }); } catch (error) { this.logger.error(`Dify API error: ${error.message}`); // Fallback to OpenAI if configured if (dify.fallbackOpenai && this.openaiService) { await this.openaiService.sendOpenaiMessage(instanceName, remoteJid, dify.openaiBot, content); } } } } ``` ## Chatbot Router Pattern ### Chatbot Router Structure (Evolution API Real Pattern) ```typescript export class ChatbotRouter { public readonly router: Router; constructor(...guards: any[]) { this.router = Router(); // Real Evolution API chatbot integrations this.router.use('/evolutionBot', new EvolutionBotRouter(...guards).router); this.router.use('/chatwoot', new ChatwootRouter(...guards).router); this.router.use('/typebot', new TypebotRouter(...guards).router); this.router.use('/openai', new OpenaiRouter(...guards).router); this.router.use('/dify', new DifyRouter(...guards).router); this.router.use('/flowise', new FlowiseRouter(...guards).router); this.router.use('/n8n', new N8nRouter(...guards).router); this.router.use('/evoai', new EvoaiRouter(...guards).router); } } ``` ## Chatbot Validation Patterns ### Chatbot Schema Validation (Evolution API Pattern) ```typescript import { JSONSchema7 } from 'json-schema'; import { v4 } from 'uuid'; const isNotEmpty = (...fields: string[]) => { const properties = {}; fields.forEach((field) => { properties[field] = { if: { properties: { [field]: { type: 'string' } } }, then: { properties: { [field]: { minLength: 1 } } }, }; }); return { allOf: Object.values(properties), }; }; export const evolutionBotSchema: JSONSchema7 = { $id: v4(), type: 'object', properties: { enabled: { type: 'boolean' }, description: { type: 'string' }, apiUrl: { type: 'string' }, apiKey: { type: 'string' }, triggerType: { type: 'string', enum: ['all', 'keyword', 'none', 'advanced'] }, triggerOperator: { type: 'string', enum: ['equals', 'contains', 'startsWith', 'endsWith', 'regex'] }, triggerValue: { type: 'string' }, expire: { type: 'integer' }, keywordFinish: { type: 'string' }, delayMessage: { type: 'integer' }, unknownMessage: { type: 'string' }, listeningFromMe: { type: 'boolean' }, stopBotFromMe: { type: 'boolean' }, keepOpen: { type: 'boolean' }, debounceTime: { type: 'integer' }, ignoreJids: { type: 'array', items: { type: 'string' } }, splitMessages: { type: 'boolean' }, timePerChar: { type: 'integer' }, }, required: ['enabled', 'apiUrl', 'triggerType'], ...isNotEmpty('enabled', 'apiUrl', 'triggerType'), }; function validateKeywordTrigger( content: string, operator: TriggerOperator, value: string, ): boolean { const normalizedContent = content.toLowerCase().trim(); const normalizedValue = value.toLowerCase().trim(); switch (operator) { case TriggerOperator.EQUALS: return normalizedContent === normalizedValue; case TriggerOperator.CONTAINS: return normalizedContent.includes(normalizedValue); case TriggerOperator.STARTS_WITH: return normalizedContent.startsWith(normalizedValue); case TriggerOperator.ENDS_WITH: return normalizedContent.endsWith(normalizedValue); default: return false; } } ``` ## Session Management Pattern ### Chatbot Session Handling ```typescript export class ChatbotSessionManager { constructor( private readonly prismaRepository: PrismaRepository, private readonly cache: CacheService, ) {} public async getSession( instanceName: string, remoteJid: string, botId: string, ): Promise { const cacheKey = `session:${instanceName}:${remoteJid}:${botId}`; // Try cache first let session = await this.cache.get(cacheKey); if (session) { return session; } // Query database session = await this.prismaRepository.integrationSession.findFirst({ where: { instanceId: instanceName, remoteJid, botId, status: 'opened', }, }); // Cache result if (session) { await this.cache.set(cacheKey, session, 300); // 5 min TTL } return session; } public async createSession( instanceName: string, remoteJid: string, botId: string, ): Promise { const session = await this.prismaRepository.integrationSession.create({ data: { instanceId: instanceName, remoteJid, botId, status: 'opened', createdAt: new Date(), }, }); // Cache new session const cacheKey = `session:${instanceName}:${remoteJid}:${botId}`; await this.cache.set(cacheKey, session, 300); return session; } public async closeSession(sessionId: string): Promise { await this.prismaRepository.integrationSession.update({ where: { id: sessionId }, data: { status: 'closed', updatedAt: new Date() }, }); // Invalidate cache // Note: In a real implementation, you'd need to track cache keys by session ID } } ``` ================================================ FILE: .cursor/rules/specialized-rules/integration-event-rules.mdc ================================================ --- description: Event integration patterns for Evolution API globs: - "src/api/integrations/event/**/*.ts" alwaysApply: false --- # Evolution API Event Integration Rules ## Event Manager Pattern ### Event Manager Structure ```typescript import { PrismaRepository } from '@api/repository/repository.service'; import { ConfigService } from '@config/env.config'; import { Logger } from '@config/logger.config'; import { Server } from 'http'; export class EventManager { private prismaRepository: PrismaRepository; private configService: ConfigService; private logger = new Logger('EventManager'); // Event integrations private webhook: WebhookController; private websocket: WebsocketController; private rabbitmq: RabbitmqController; private nats: NatsController; private sqs: SqsController; private pusher: PusherController; constructor( prismaRepository: PrismaRepository, configService: ConfigService, server?: Server, ) { this.prismaRepository = prismaRepository; this.configService = configService; // Initialize event controllers this.webhook = new WebhookController(prismaRepository, configService); this.websocket = new WebsocketController(prismaRepository, configService, server); this.rabbitmq = new RabbitmqController(prismaRepository, configService); this.nats = new NatsController(prismaRepository, configService); this.sqs = new SqsController(prismaRepository, configService); this.pusher = new PusherController(prismaRepository, configService); } public async emit(eventData: { instanceName: string; origin: string; event: string; data: Object; serverUrl: string; dateTime: string; sender: string; apiKey?: string; local?: boolean; integration?: string[]; }): Promise { this.logger.log(`Emitting event ${eventData.event} for instance ${eventData.instanceName}`); // Emit to all configured integrations await Promise.allSettled([ this.webhook.emit(eventData), this.websocket.emit(eventData), this.rabbitmq.emit(eventData), this.nats.emit(eventData), this.sqs.emit(eventData), this.pusher.emit(eventData), ]); } public async setInstance(instanceName: string, data: any): Promise { const promises = []; if (data.websocket) { promises.push( this.websocket.set(instanceName, { websocket: { enabled: true, events: data.websocket?.events, }, }) ); } if (data.rabbitmq) { promises.push( this.rabbitmq.set(instanceName, { rabbitmq: { enabled: true, events: data.rabbitmq?.events, }, }) ); } if (data.webhook) { promises.push( this.webhook.set(instanceName, { webhook: { enabled: true, events: data.webhook?.events, url: data.webhook?.url, headers: data.webhook?.headers, base64: data.webhook?.base64, byEvents: data.webhook?.byEvents, }, }) ); } // Set other integrations... await Promise.allSettled(promises); } } ``` ## Base Event Controller Pattern ### Abstract Event Controller ```typescript import { PrismaRepository } from '@api/repository/repository.service'; import { ConfigService } from '@config/env.config'; import { Logger } from '@config/logger.config'; export type EmitData = { instanceName: string; origin: string; event: string; data: Object; serverUrl: string; dateTime: string; sender: string; apiKey?: string; local?: boolean; integration?: string[]; }; export interface EventControllerInterface { integrationEnabled: boolean; emit(data: EmitData): Promise; set(instanceName: string, data: any): Promise; } export abstract class EventController implements EventControllerInterface { protected readonly logger: Logger; protected readonly prismaRepository: PrismaRepository; protected readonly configService: ConfigService; public integrationEnabled: boolean = false; // Available events for all integrations public static readonly events = [ 'APPLICATION_STARTUP', 'INSTANCE_CREATE', 'INSTANCE_DELETE', 'QRCODE_UPDATED', 'CONNECTION_UPDATE', 'STATUS_INSTANCE', 'MESSAGES_SET', 'MESSAGES_UPSERT', 'MESSAGES_EDITED', 'MESSAGES_UPDATE', 'MESSAGES_DELETE', 'SEND_MESSAGE', 'CONTACTS_SET', 'CONTACTS_UPSERT', 'CONTACTS_UPDATE', 'PRESENCE_UPDATE', 'CHATS_SET', 'CHATS_UPDATE', 'CHATS_UPSERT', 'CHATS_DELETE', 'GROUPS_UPSERT', 'GROUPS_UPDATE', 'GROUP_PARTICIPANTS_UPDATE', 'CALL', 'TYPEBOT_START', 'TYPEBOT_CHANGE_STATUS', 'LABELS_EDIT', 'LABELS_ASSOCIATION', 'CREDS_UPDATE', 'MESSAGING_HISTORY_SET', 'REMOVE_INSTANCE', 'LOGOUT_INSTANCE', ]; constructor( prismaRepository: PrismaRepository, configService: ConfigService, loggerName: string, ) { this.prismaRepository = prismaRepository; this.configService = configService; this.logger = new Logger(loggerName); } // Abstract methods to be implemented by specific integrations public abstract emit(data: EmitData): Promise; public abstract set(instanceName: string, data: any): Promise; // Helper method to check if event should be processed protected shouldProcessEvent(eventName: string, configuredEvents?: string[]): boolean { if (!configuredEvents || configuredEvents.length === 0) { return true; // Process all events if none specified } return configuredEvents.includes(eventName); } // Helper method to get instance configuration protected async getInstanceConfig(instanceName: string): Promise { try { const instance = await this.prismaRepository.instance.findUnique({ where: { name: instanceName }, }); return instance; } catch (error) { this.logger.error(`Failed to get instance config for ${instanceName}:`, error); return null; } } } ``` ## Webhook Integration Pattern ### Webhook Controller Implementation ```typescript export class WebhookController extends EventController { constructor( prismaRepository: PrismaRepository, configService: ConfigService, ) { super(prismaRepository, configService, 'WebhookController'); } public async emit(data: EmitData): Promise { try { const instance = await this.getInstanceConfig(data.instanceName); if (!instance?.webhook?.enabled) { return; } const webhookConfig = instance.webhook; if (!this.shouldProcessEvent(data.event, webhookConfig.events)) { return; } const payload = { event: data.event, instance: data.instanceName, data: data.data, timestamp: data.dateTime, sender: data.sender, server: { version: process.env.npm_package_version, url: data.serverUrl, }, }; // Encode data as base64 if configured if (webhookConfig.base64) { payload.data = Buffer.from(JSON.stringify(payload.data)).toString('base64'); } const headers = { 'Content-Type': 'application/json', 'User-Agent': 'Evolution-API-Webhook', ...webhookConfig.headers, }; if (webhookConfig.byEvents) { // Send to event-specific endpoint const eventUrl = `${webhookConfig.url}/${data.event.toLowerCase()}`; await this.sendWebhook(eventUrl, payload, headers); } else { // Send to main webhook URL await this.sendWebhook(webhookConfig.url, payload, headers); } this.logger.log(`Webhook sent for event ${data.event} to instance ${data.instanceName}`); } catch (error) { this.logger.error(`Webhook emission failed for ${data.instanceName}:`, error); } } public async set(instanceName: string, data: any): Promise { try { const webhookData = data.webhook; await this.prismaRepository.instance.update({ where: { name: instanceName }, data: { webhook: webhookData, }, }); this.logger.log(`Webhook configuration set for instance ${instanceName}`); return { webhook: webhookData }; } catch (error) { this.logger.error(`Failed to set webhook config for ${instanceName}:`, error); throw error; } } private async sendWebhook(url: string, payload: any, headers: any): Promise { try { const response = await axios.post(url, payload, { headers, timeout: 30000, maxRedirects: 3, }); if (response.status >= 200 && response.status < 300) { this.logger.log(`Webhook delivered successfully to ${url}`); } else { this.logger.warn(`Webhook returned status ${response.status} for ${url}`); } } catch (error) { this.logger.error(`Webhook delivery failed to ${url}:`, error.message); // Implement retry logic here if needed if (error.response?.status >= 500) { // Server error - might be worth retrying this.logger.log(`Server error detected, webhook might be retried later`); } } } } ``` ## WebSocket Integration Pattern ### WebSocket Controller Implementation ```typescript import { Server as SocketIOServer } from 'socket.io'; import { Server } from 'http'; export class WebsocketController extends EventController { private io: SocketIOServer; constructor( prismaRepository: PrismaRepository, configService: ConfigService, server?: Server, ) { super(prismaRepository, configService, 'WebsocketController'); if (server) { this.io = new SocketIOServer(server, { cors: { origin: "*", methods: ["GET", "POST"], }, }); this.setupSocketHandlers(); } } private setupSocketHandlers(): void { this.io.on('connection', (socket) => { this.logger.log(`WebSocket client connected: ${socket.id}`); socket.on('join-instance', (instanceName: string) => { socket.join(`instance:${instanceName}`); this.logger.log(`Client ${socket.id} joined instance ${instanceName}`); }); socket.on('leave-instance', (instanceName: string) => { socket.leave(`instance:${instanceName}`); this.logger.log(`Client ${socket.id} left instance ${instanceName}`); }); socket.on('disconnect', () => { this.logger.log(`WebSocket client disconnected: ${socket.id}`); }); }); } public async emit(data: EmitData): Promise { if (!this.io) { return; } try { const instance = await this.getInstanceConfig(data.instanceName); if (!instance?.websocket?.enabled) { return; } const websocketConfig = instance.websocket; if (!this.shouldProcessEvent(data.event, websocketConfig.events)) { return; } const payload = { event: data.event, instance: data.instanceName, data: data.data, timestamp: data.dateTime, sender: data.sender, }; // Emit to specific instance room this.io.to(`instance:${data.instanceName}`).emit('evolution-event', payload); // Also emit to global room for monitoring this.io.emit('global-event', payload); this.logger.log(`WebSocket event ${data.event} emitted for instance ${data.instanceName}`); } catch (error) { this.logger.error(`WebSocket emission failed for ${data.instanceName}:`, error); } } public async set(instanceName: string, data: any): Promise { try { const websocketData = data.websocket; await this.prismaRepository.instance.update({ where: { name: instanceName }, data: { websocket: websocketData, }, }); this.logger.log(`WebSocket configuration set for instance ${instanceName}`); return { websocket: websocketData }; } catch (error) { this.logger.error(`Failed to set WebSocket config for ${instanceName}:`, error); throw error; } } } ``` ## Queue Integration Patterns ### RabbitMQ Controller Implementation ```typescript import amqp from 'amqplib'; export class RabbitmqController extends EventController { private connection: amqp.Connection | null = null; private channel: amqp.Channel | null = null; constructor( prismaRepository: PrismaRepository, configService: ConfigService, ) { super(prismaRepository, configService, 'RabbitmqController'); this.initializeConnection(); } private async initializeConnection(): Promise { try { const rabbitmqConfig = this.configService.get('RABBITMQ'); if (!rabbitmqConfig?.ENABLED) { return; } this.connection = await amqp.connect(rabbitmqConfig.URI); this.channel = await this.connection.createChannel(); // Declare exchange for Evolution API events await this.channel.assertExchange('evolution-events', 'topic', { durable: true }); this.logger.log('RabbitMQ connection established'); } catch (error) { this.logger.error('Failed to initialize RabbitMQ connection:', error); } } public async emit(data: EmitData): Promise { if (!this.channel) { return; } try { const instance = await this.getInstanceConfig(data.instanceName); if (!instance?.rabbitmq?.enabled) { return; } const rabbitmqConfig = instance.rabbitmq; if (!this.shouldProcessEvent(data.event, rabbitmqConfig.events)) { return; } const payload = { event: data.event, instance: data.instanceName, data: data.data, timestamp: data.dateTime, sender: data.sender, }; const routingKey = `evolution.${data.instanceName}.${data.event.toLowerCase()}`; await this.channel.publish( 'evolution-events', routingKey, Buffer.from(JSON.stringify(payload)), { persistent: true, timestamp: Date.now(), messageId: `${data.instanceName}-${Date.now()}`, } ); this.logger.log(`RabbitMQ message published for event ${data.event} to instance ${data.instanceName}`); } catch (error) { this.logger.error(`RabbitMQ emission failed for ${data.instanceName}:`, error); } } public async set(instanceName: string, data: any): Promise { try { const rabbitmqData = data.rabbitmq; await this.prismaRepository.instance.update({ where: { name: instanceName }, data: { rabbitmq: rabbitmqData, }, }); this.logger.log(`RabbitMQ configuration set for instance ${instanceName}`); return { rabbitmq: rabbitmqData }; } catch (error) { this.logger.error(`Failed to set RabbitMQ config for ${instanceName}:`, error); throw error; } } } ``` ### SQS Controller Implementation ```typescript import { SQSClient, SendMessageCommand } from '@aws-sdk/client-sqs'; export class SqsController extends EventController { private sqsClient: SQSClient | null = null; constructor( prismaRepository: PrismaRepository, configService: ConfigService, ) { super(prismaRepository, configService, 'SqsController'); this.initializeSQSClient(); } private initializeSQSClient(): void { try { const sqsConfig = this.configService.get('SQS'); if (!sqsConfig?.ENABLED) { return; } this.sqsClient = new SQSClient({ region: sqsConfig.REGION, credentials: { accessKeyId: sqsConfig.ACCESS_KEY_ID, secretAccessKey: sqsConfig.SECRET_ACCESS_KEY, }, }); this.logger.log('SQS client initialized'); } catch (error) { this.logger.error('Failed to initialize SQS client:', error); } } public async emit(data: EmitData): Promise { if (!this.sqsClient) { return; } try { const instance = await this.getInstanceConfig(data.instanceName); if (!instance?.sqs?.enabled) { return; } const sqsConfig = instance.sqs; if (!this.shouldProcessEvent(data.event, sqsConfig.events)) { return; } const payload = { event: data.event, instance: data.instanceName, data: data.data, timestamp: data.dateTime, sender: data.sender, }; const command = new SendMessageCommand({ QueueUrl: sqsConfig.queueUrl, MessageBody: JSON.stringify(payload), MessageAttributes: { event: { DataType: 'String', StringValue: data.event, }, instance: { DataType: 'String', StringValue: data.instanceName, }, }, MessageGroupId: data.instanceName, // For FIFO queues MessageDeduplicationId: `${data.instanceName}-${Date.now()}`, // For FIFO queues }); await this.sqsClient.send(command); this.logger.log(`SQS message sent for event ${data.event} to instance ${data.instanceName}`); } catch (error) { this.logger.error(`SQS emission failed for ${data.instanceName}:`, error); } } public async set(instanceName: string, data: any): Promise { try { const sqsData = data.sqs; await this.prismaRepository.instance.update({ where: { name: instanceName }, data: { sqs: sqsData, }, }); this.logger.log(`SQS configuration set for instance ${instanceName}`); return { sqs: sqsData }; } catch (error) { this.logger.error(`Failed to set SQS config for ${instanceName}:`, error); throw error; } } } ``` ## Event DTO Pattern ### Event Configuration DTO ```typescript import { JsonValue } from '@prisma/client/runtime/library'; export class EventDto { webhook?: { enabled?: boolean; events?: string[]; url?: string; headers?: JsonValue; byEvents?: boolean; base64?: boolean; }; websocket?: { enabled?: boolean; events?: string[]; }; sqs?: { enabled?: boolean; events?: string[]; queueUrl?: string; }; rabbitmq?: { enabled?: boolean; events?: string[]; exchange?: string; }; nats?: { enabled?: boolean; events?: string[]; subject?: string; }; pusher?: { enabled?: boolean; appId?: string; key?: string; secret?: string; cluster?: string; useTLS?: boolean; events?: string[]; }; } ``` ## Event Router Pattern ### Event Router Structure ```typescript import { NatsRouter } from '@api/integrations/event/nats/nats.router'; import { PusherRouter } from '@api/integrations/event/pusher/pusher.router'; import { RabbitmqRouter } from '@api/integrations/event/rabbitmq/rabbitmq.router'; import { SqsRouter } from '@api/integrations/event/sqs/sqs.router'; import { WebhookRouter } from '@api/integrations/event/webhook/webhook.router'; import { WebsocketRouter } from '@api/integrations/event/websocket/websocket.router'; import { Router } from 'express'; export class EventRouter { public readonly router: Router; constructor(configService: any, ...guards: any[]) { this.router = Router(); this.router.use('/webhook', new WebhookRouter(configService, ...guards).router); this.router.use('/websocket', new WebsocketRouter(...guards).router); this.router.use('/rabbitmq', new RabbitmqRouter(...guards).router); this.router.use('/nats', new NatsRouter(...guards).router); this.router.use('/pusher', new PusherRouter(...guards).router); this.router.use('/sqs', new SqsRouter(...guards).router); } } ``` ## Event Validation Schema ### Event Configuration Validation ```typescript import Joi from 'joi'; import { EventController } from '@api/integrations/event/event.controller'; const eventListSchema = Joi.array().items( Joi.string().valid(...EventController.events) ).optional(); export const webhookSchema = Joi.object({ enabled: Joi.boolean().required(), url: Joi.string().when('enabled', { is: true, then: Joi.required().uri({ scheme: ['http', 'https'] }), otherwise: Joi.optional(), }), events: eventListSchema, headers: Joi.object().pattern(Joi.string(), Joi.string()).optional(), byEvents: Joi.boolean().optional().default(false), base64: Joi.boolean().optional().default(false), }).required(); export const websocketSchema = Joi.object({ enabled: Joi.boolean().required(), events: eventListSchema, }).required(); export const rabbitmqSchema = Joi.object({ enabled: Joi.boolean().required(), events: eventListSchema, exchange: Joi.string().optional().default('evolution-events'), }).required(); export const sqsSchema = Joi.object({ enabled: Joi.boolean().required(), events: eventListSchema, queueUrl: Joi.string().when('enabled', { is: true, then: Joi.required().uri(), otherwise: Joi.optional(), }), }).required(); export const eventSchema = Joi.object({ webhook: webhookSchema.optional(), websocket: websocketSchema.optional(), rabbitmq: rabbitmqSchema.optional(), sqs: sqsSchema.optional(), nats: Joi.object({ enabled: Joi.boolean().required(), events: eventListSchema, subject: Joi.string().optional().default('evolution.events'), }).optional(), pusher: Joi.object({ enabled: Joi.boolean().required(), appId: Joi.string().when('enabled', { is: true, then: Joi.required() }), key: Joi.string().when('enabled', { is: true, then: Joi.required() }), secret: Joi.string().when('enabled', { is: true, then: Joi.required() }), cluster: Joi.string().when('enabled', { is: true, then: Joi.required() }), useTLS: Joi.boolean().optional().default(true), events: eventListSchema, }).optional(), }).min(1).required(); ``` ## Event Testing Pattern ### Event Controller Testing ```typescript describe('WebhookController', () => { let controller: WebhookController; let prismaRepository: jest.Mocked; let configService: jest.Mocked; beforeEach(() => { controller = new WebhookController(prismaRepository, configService); }); describe('emit', () => { it('should send webhook when enabled', async () => { const mockInstance = { webhook: { enabled: true, url: 'https://example.com/webhook', events: ['MESSAGES_UPSERT'], }, }; prismaRepository.instance.findUnique.mockResolvedValue(mockInstance); jest.spyOn(axios, 'post').mockResolvedValue({ status: 200 }); const eventData = { instanceName: 'test-instance', event: 'MESSAGES_UPSERT', data: { message: 'test' }, origin: 'test', serverUrl: 'http://localhost', dateTime: new Date().toISOString(), sender: 'test', }; await controller.emit(eventData); expect(axios.post).toHaveBeenCalledWith( 'https://example.com/webhook', expect.objectContaining({ event: 'MESSAGES_UPSERT', instance: 'test-instance', }), expect.objectContaining({ headers: expect.objectContaining({ 'Content-Type': 'application/json', }), }) ); }); }); }); ``` ================================================ FILE: .cursor/rules/specialized-rules/integration-storage-rules.mdc ================================================ --- description: Storage integration patterns for Evolution API globs: - "src/api/integrations/storage/**/*.ts" alwaysApply: false --- # Evolution API Storage Integration Rules ## Storage Service Pattern ### Base Storage Service Structure ```typescript import { InstanceDto } from '@api/dto/instance.dto'; import { PrismaRepository } from '@api/repository/repository.service'; import { Logger } from '@config/logger.config'; import { BadRequestException } from '@exceptions'; export class StorageService { constructor(private readonly prismaRepository: PrismaRepository) {} private readonly logger = new Logger('StorageService'); public async getMedia(instance: InstanceDto, query?: MediaDto) { try { const where: any = { instanceId: instance.instanceId, ...query, }; const media = await this.prismaRepository.media.findMany({ where, select: { id: true, fileName: true, type: true, mimetype: true, createdAt: true, Message: true, }, }); if (!media || media.length === 0) { throw 'Media not found'; } return media; } catch (error) { throw new BadRequestException(error); } } public async getMediaUrl(instance: InstanceDto, data: MediaDto) { const media = (await this.getMedia(instance, { id: data.id }))[0]; const mediaUrl = await this.generateUrl(media.fileName, data.expiry); return { mediaUrl, ...media, }; } protected abstract generateUrl(fileName: string, expiry?: number): Promise; } ``` ## S3/MinIO Integration Pattern ### MinIO Client Setup ```typescript import { ConfigService, S3 } from '@config/env.config'; import { Logger } from '@config/logger.config'; import { BadRequestException } from '@exceptions'; import * as MinIo from 'minio'; import { join } from 'path'; import { Readable, Transform } from 'stream'; const logger = new Logger('S3 Service'); const BUCKET = new ConfigService().get('S3'); interface Metadata extends MinIo.ItemBucketMetadata { instanceId: string; messageId?: string; } const minioClient = (() => { if (BUCKET?.ENABLE) { return new MinIo.Client({ endPoint: BUCKET.ENDPOINT, port: BUCKET.PORT, useSSL: BUCKET.USE_SSL, accessKey: BUCKET.ACCESS_KEY, secretKey: BUCKET.SECRET_KEY, region: BUCKET.REGION, }); } })(); const bucketName = process.env.S3_BUCKET; ``` ### Bucket Management Functions ```typescript const bucketExists = async (): Promise => { if (minioClient) { try { const list = await minioClient.listBuckets(); return !!list.find((bucket) => bucket.name === bucketName); } catch (error) { logger.error('Error checking bucket existence:', error); return false; } } return false; }; const setBucketPolicy = async (): Promise => { if (minioClient && bucketName) { try { const policy = { Version: '2012-10-17', Statement: [ { Effect: 'Allow', Principal: { AWS: ['*'] }, Action: ['s3:GetObject'], Resource: [`arn:aws:s3:::${bucketName}/*`], }, ], }; await minioClient.setBucketPolicy(bucketName, JSON.stringify(policy)); logger.log('Bucket policy set successfully'); } catch (error) { logger.error('Error setting bucket policy:', error); } } }; const createBucket = async (): Promise => { if (minioClient && bucketName) { try { const exists = await bucketExists(); if (!exists) { await minioClient.makeBucket(bucketName, BUCKET.REGION || 'us-east-1'); await setBucketPolicy(); logger.log(`Bucket ${bucketName} created successfully`); } } catch (error) { logger.error('Error creating bucket:', error); } } }; ``` ### File Upload Functions ```typescript export const uploadFile = async ( fileName: string, buffer: Buffer, mimetype: string, metadata?: Metadata, ): Promise => { if (!minioClient || !bucketName) { throw new BadRequestException('S3 storage not configured'); } try { await createBucket(); const uploadMetadata = { 'Content-Type': mimetype, ...metadata, }; await minioClient.putObject(bucketName, fileName, buffer, buffer.length, uploadMetadata); logger.log(`File ${fileName} uploaded successfully`); return fileName; } catch (error) { logger.error(`Error uploading file ${fileName}:`, error); throw new BadRequestException(`Failed to upload file: ${error.message}`); } }; export const uploadStream = async ( fileName: string, stream: Readable, size: number, mimetype: string, metadata?: Metadata, ): Promise => { if (!minioClient || !bucketName) { throw new BadRequestException('S3 storage not configured'); } try { await createBucket(); const uploadMetadata = { 'Content-Type': mimetype, ...metadata, }; await minioClient.putObject(bucketName, fileName, stream, size, uploadMetadata); logger.log(`Stream ${fileName} uploaded successfully`); return fileName; } catch (error) { logger.error(`Error uploading stream ${fileName}:`, error); throw new BadRequestException(`Failed to upload stream: ${error.message}`); } }; ``` ### File Download Functions ```typescript export const getObject = async (fileName: string): Promise => { if (!minioClient || !bucketName) { throw new BadRequestException('S3 storage not configured'); } try { const stream = await minioClient.getObject(bucketName, fileName); const chunks: Buffer[] = []; return new Promise((resolve, reject) => { stream.on('data', (chunk) => chunks.push(chunk)); stream.on('end', () => resolve(Buffer.concat(chunks))); stream.on('error', reject); }); } catch (error) { logger.error(`Error getting object ${fileName}:`, error); throw new BadRequestException(`Failed to get object: ${error.message}`); } }; export const getObjectUrl = async (fileName: string, expiry: number = 3600): Promise => { if (!minioClient || !bucketName) { throw new BadRequestException('S3 storage not configured'); } try { const url = await minioClient.presignedGetObject(bucketName, fileName, expiry); logger.log(`Generated URL for ${fileName} with expiry ${expiry}s`); return url; } catch (error) { logger.error(`Error generating URL for ${fileName}:`, error); throw new BadRequestException(`Failed to generate URL: ${error.message}`); } }; export const getObjectStream = async (fileName: string): Promise => { if (!minioClient || !bucketName) { throw new BadRequestException('S3 storage not configured'); } try { const stream = await minioClient.getObject(bucketName, fileName); return stream; } catch (error) { logger.error(`Error getting object stream ${fileName}:`, error); throw new BadRequestException(`Failed to get object stream: ${error.message}`); } }; ``` ### File Management Functions ```typescript export const deleteObject = async (fileName: string): Promise => { if (!minioClient || !bucketName) { throw new BadRequestException('S3 storage not configured'); } try { await minioClient.removeObject(bucketName, fileName); logger.log(`File ${fileName} deleted successfully`); } catch (error) { logger.error(`Error deleting file ${fileName}:`, error); throw new BadRequestException(`Failed to delete file: ${error.message}`); } }; export const listObjects = async (prefix?: string): Promise => { if (!minioClient || !bucketName) { throw new BadRequestException('S3 storage not configured'); } try { const objects: MinIo.BucketItem[] = []; const stream = minioClient.listObjects(bucketName, prefix, true); return new Promise((resolve, reject) => { stream.on('data', (obj) => objects.push(obj)); stream.on('end', () => resolve(objects)); stream.on('error', reject); }); } catch (error) { logger.error('Error listing objects:', error); throw new BadRequestException(`Failed to list objects: ${error.message}`); } }; export const objectExists = async (fileName: string): Promise => { if (!minioClient || !bucketName) { return false; } try { await minioClient.statObject(bucketName, fileName); return true; } catch (error) { return false; } }; ``` ## Storage Controller Pattern ### S3 Controller Implementation ```typescript import { InstanceDto } from '@api/dto/instance.dto'; import { MediaDto } from '@api/integrations/storage/s3/dto/media.dto'; import { S3Service } from '@api/integrations/storage/s3/services/s3.service'; export class S3Controller { constructor(private readonly s3Service: S3Service) {} public async getMedia(instance: InstanceDto, data: MediaDto) { return this.s3Service.getMedia(instance, data); } public async getMediaUrl(instance: InstanceDto, data: MediaDto) { return this.s3Service.getMediaUrl(instance, data); } public async uploadMedia(instance: InstanceDto, data: UploadMediaDto) { return this.s3Service.uploadMedia(instance, data); } public async deleteMedia(instance: InstanceDto, data: MediaDto) { return this.s3Service.deleteMedia(instance, data); } } ``` ## Storage Router Pattern ### Storage Router Structure ```typescript import { S3Router } from '@api/integrations/storage/s3/routes/s3.router'; import { Router } from 'express'; export class StorageRouter { public readonly router: Router; constructor(...guards: any[]) { this.router = Router(); this.router.use('/s3', new S3Router(...guards).router); // Add other storage providers here // this.router.use('/gcs', new GCSRouter(...guards).router); // this.router.use('/azure', new AzureRouter(...guards).router); } } ``` ### S3 Specific Router ```typescript import { RouterBroker } from '@api/abstract/abstract.router'; import { MediaDto } from '@api/integrations/storage/s3/dto/media.dto'; import { s3Schema, s3UrlSchema } from '@api/integrations/storage/s3/validate/s3.schema'; import { HttpStatus } from '@api/routes/index.router'; import { s3Controller } from '@api/server.module'; import { RequestHandler, Router } from 'express'; export class S3Router extends RouterBroker { constructor(...guards: RequestHandler[]) { super(); this.router .post(this.routerPath('getMedia'), ...guards, async (req, res) => { const response = await this.dataValidate({ request: req, schema: s3Schema, ClassRef: MediaDto, execute: (instance, data) => s3Controller.getMedia(instance, data), }); res.status(HttpStatus.OK).json(response); }) .post(this.routerPath('getMediaUrl'), ...guards, async (req, res) => { const response = await this.dataValidate({ request: req, schema: s3UrlSchema, ClassRef: MediaDto, execute: (instance, data) => s3Controller.getMediaUrl(instance, data), }); res.status(HttpStatus.OK).json(response); }) .post(this.routerPath('uploadMedia'), ...guards, async (req, res) => { const response = await this.dataValidate({ request: req, schema: uploadSchema, ClassRef: UploadMediaDto, execute: (instance, data) => s3Controller.uploadMedia(instance, data), }); res.status(HttpStatus.CREATED).json(response); }) .delete(this.routerPath('deleteMedia'), ...guards, async (req, res) => { const response = await this.dataValidate({ request: req, schema: s3Schema, ClassRef: MediaDto, execute: (instance, data) => s3Controller.deleteMedia(instance, data), }); res.status(HttpStatus.OK).json(response); }); } public readonly router: Router = Router(); } ``` ## Storage DTO Pattern ### Media DTO ```typescript export class MediaDto { id?: string; fileName?: string; type?: string; mimetype?: string; expiry?: number; } export class UploadMediaDto { fileName: string; mimetype: string; buffer?: Buffer; base64?: string; url?: string; metadata?: { instanceId: string; messageId?: string; contactId?: string; [key: string]: any; }; } ``` ## Storage Validation Schema ### S3 Validation Schemas ```typescript import Joi from 'joi'; export const s3Schema = Joi.object({ id: Joi.string().optional(), fileName: Joi.string().optional(), type: Joi.string().optional().valid('image', 'video', 'audio', 'document'), mimetype: Joi.string().optional(), expiry: Joi.number().optional().min(60).max(604800).default(3600), // 1 min to 7 days }).min(1).required(); export const s3UrlSchema = Joi.object({ id: Joi.string().required(), expiry: Joi.number().optional().min(60).max(604800).default(3600), }).required(); export const uploadSchema = Joi.object({ fileName: Joi.string().required().max(255), mimetype: Joi.string().required(), buffer: Joi.binary().optional(), base64: Joi.string().base64().optional(), url: Joi.string().uri().optional(), metadata: Joi.object({ instanceId: Joi.string().required(), messageId: Joi.string().optional(), contactId: Joi.string().optional(), }).optional(), }).xor('buffer', 'base64', 'url').required(); // Exactly one of these must be present ``` ## Error Handling in Storage ### Storage-Specific Error Handling ```typescript // CORRECT - Storage-specific error handling public async uploadFile(fileName: string, buffer: Buffer): Promise { try { const result = await this.storageClient.upload(fileName, buffer); return result; } catch (error) { this.logger.error(`Storage upload failed: ${error.message}`); if (error.code === 'NoSuchBucket') { throw new BadRequestException('Storage bucket not found'); } if (error.code === 'AccessDenied') { throw new UnauthorizedException('Storage access denied'); } if (error.code === 'EntityTooLarge') { throw new BadRequestException('File too large'); } throw new InternalServerErrorException('Storage operation failed'); } } ``` ## Storage Configuration Pattern ### Environment Configuration ```typescript export interface S3Config { ENABLE: boolean; ENDPOINT: string; PORT: number; USE_SSL: boolean; ACCESS_KEY: string; SECRET_KEY: string; REGION: string; BUCKET: string; } // Usage in service const s3Config = this.configService.get('S3'); if (!s3Config.ENABLE) { throw new BadRequestException('S3 storage is disabled'); } ``` ## Storage Testing Pattern ### Storage Service Testing ```typescript describe('S3Service', () => { let service: S3Service; let prismaRepository: jest.Mocked; beforeEach(() => { service = new S3Service(prismaRepository); }); describe('getMedia', () => { it('should return media list', async () => { const instance = { instanceId: 'test-instance' }; const mockMedia = [ { id: '1', fileName: 'test.jpg', type: 'image', mimetype: 'image/jpeg' }, ]; prismaRepository.media.findMany.mockResolvedValue(mockMedia); const result = await service.getMedia(instance); expect(result).toEqual(mockMedia); expect(prismaRepository.media.findMany).toHaveBeenCalledWith({ where: { instanceId: 'test-instance' }, select: expect.objectContaining({ id: true, fileName: true, type: true, mimetype: true, }), }); }); it('should throw error when no media found', async () => { const instance = { instanceId: 'test-instance' }; prismaRepository.media.findMany.mockResolvedValue([]); await expect(service.getMedia(instance)).rejects.toThrow(BadRequestException); }); }); }); ``` ## Storage Performance Considerations ### Efficient File Handling ```typescript // CORRECT - Stream-based upload for large files public async uploadLargeFile(fileName: string, stream: Readable, size: number): Promise { const uploadStream = new Transform({ transform(chunk, encoding, callback) { // Optional: Add compression, encryption, etc. callback(null, chunk); }, }); return new Promise((resolve, reject) => { stream .pipe(uploadStream) .on('error', reject) .on('finish', () => resolve(fileName)); }); } // INCORRECT - Loading entire file into memory public async uploadLargeFile(fileName: string, filePath: string): Promise { const buffer = fs.readFileSync(filePath); // ❌ Memory intensive for large files return await this.uploadFile(fileName, buffer); } ``` ================================================ FILE: .cursor/rules/specialized-rules/route-rules.mdc ================================================ --- description: Router patterns for Evolution API globs: - "src/api/routes/**/*.ts" alwaysApply: false --- # Evolution API Route Rules ## Router Base Pattern ### RouterBroker Extension ```typescript import { RouterBroker } from '@api/abstract/abstract.router'; import { RequestHandler, Router } from 'express'; import { HttpStatus } from './index.router'; export class ExampleRouter extends RouterBroker { constructor(...guards: RequestHandler[]) { super(); this.router .get(this.routerPath('findExample'), ...guards, async (req, res) => { const response = await this.dataValidate({ request: req, schema: null, ClassRef: ExampleDto, execute: (instance) => exampleController.find(instance), }); return res.status(HttpStatus.OK).json(response); }) .post(this.routerPath('createExample'), ...guards, async (req, res) => { const response = await this.dataValidate({ request: req, schema: exampleSchema, ClassRef: ExampleDto, execute: (instance, data) => exampleController.create(instance, data), }); return res.status(HttpStatus.CREATED).json(response); }); } public readonly router: Router = Router(); } ``` ## Main Router Pattern ### Index Router Structure ```typescript import { Router } from 'express'; import { authGuard } from '@api/guards/auth.guard'; import { instanceExistsGuard, instanceLoggedGuard } from '@api/guards/instance.guard'; import Telemetry from '@api/guards/telemetry.guard'; enum HttpStatus { OK = 200, CREATED = 201, NOT_FOUND = 404, FORBIDDEN = 403, BAD_REQUEST = 400, UNAUTHORIZED = 401, INTERNAL_SERVER_ERROR = 500, } const router: Router = Router(); const guards = [instanceExistsGuard, instanceLoggedGuard, authGuard['apikey']]; const telemetry = new Telemetry(); router .use((req, res, next) => telemetry.collectTelemetry(req, res, next)) .get('/', async (req, res) => { res.status(HttpStatus.OK).json({ status: HttpStatus.OK, message: 'Welcome to the Evolution API, it is working!', version: packageJson.version, clientName: process.env.DATABASE_CONNECTION_CLIENT_NAME, manager: !serverConfig.DISABLE_MANAGER ? `${req.protocol}://${req.get('host')}/manager` : undefined, documentation: `https://doc.evolution-api.com`, whatsappWebVersion: (await fetchLatestWaWebVersion({})).version.join('.'), }); }) .use('/instance', new InstanceRouter(configService, ...guards).router) .use('/message', new MessageRouter(...guards).router) .use('/chat', new ChatRouter(...guards).router) .use('/business', new BusinessRouter(...guards).router); export { HttpStatus, router }; ``` ## Data Validation Pattern ### RouterBroker dataValidate Usage ```typescript // CORRECT - Standard validation pattern .post(this.routerPath('createTemplate'), ...guards, async (req, res) => { const response = await this.dataValidate({ request: req, schema: templateSchema, ClassRef: TemplateDto, execute: (instance, data) => templateController.create(instance, data), }); return res.status(HttpStatus.CREATED).json(response); }) // CORRECT - No schema validation (for simple DTOs) .get(this.routerPath('findTemplate'), ...guards, async (req, res) => { const response = await this.dataValidate({ request: req, schema: null, ClassRef: InstanceDto, execute: (instance) => templateController.find(instance), }); return res.status(HttpStatus.OK).json(response); }) ``` ## Error Handling in Routes ### Try-Catch Pattern ```typescript // CORRECT - Error handling with utility function .post(this.routerPath('getCatalog'), ...guards, async (req, res) => { try { const response = await this.dataValidate({ request: req, schema: catalogSchema, ClassRef: NumberDto, execute: (instance, data) => businessController.fetchCatalog(instance, data), }); return res.status(HttpStatus.OK).json(response); } catch (error) { // Log error for debugging console.error('Business catalog error:', error); // Use utility function to create standardized error response const errorResponse = createMetaErrorResponse(error, 'business_catalog'); return res.status(errorResponse.status).json(errorResponse); } }) // INCORRECT - Let RouterBroker handle errors (when possible) .post(this.routerPath('simpleOperation'), ...guards, async (req, res) => { try { const response = await this.dataValidate({ request: req, schema: simpleSchema, ClassRef: SimpleDto, execute: (instance, data) => controller.simpleOperation(instance, data), }); return res.status(HttpStatus.OK).json(response); } catch (error) { throw error; // ❌ Unnecessary - RouterBroker handles this } }) ``` ## Route Path Pattern ### routerPath Usage ```typescript // CORRECT - Use routerPath for consistent naming .get(this.routerPath('findLabels'), ...guards, async (req, res) => { // Implementation }) .post(this.routerPath('handleLabel'), ...guards, async (req, res) => { // Implementation }) // INCORRECT - Hardcoded paths .get('/labels', ...guards, async (req, res) => { // ❌ Use routerPath // Implementation }) ``` ## Guard Application Pattern ### Guards Usage ```typescript // CORRECT - Apply guards to protected routes export class ProtectedRouter extends RouterBroker { constructor(...guards: RequestHandler[]) { super(); this.router .get(this.routerPath('protectedAction'), ...guards, async (req, res) => { // Protected action }) .post(this.routerPath('anotherAction'), ...guards, async (req, res) => { // Another protected action }); } } // CORRECT - No guards for public routes export class PublicRouter extends RouterBroker { constructor() { super(); this.router .get('/health', async (req, res) => { res.status(HttpStatus.OK).json({ status: 'healthy' }); }) .get('/version', async (req, res) => { res.status(HttpStatus.OK).json({ version: packageJson.version }); }); } } ``` ## Static File Serving Pattern ### Static Assets Route ```typescript // CORRECT - Secure static file serving router.get('/assets/*', (req, res) => { const fileName = req.params[0]; // Security: Reject paths containing traversal patterns if (!fileName || fileName.includes('..') || fileName.includes('\\') || path.isAbsolute(fileName)) { return res.status(403).send('Forbidden'); } const basePath = path.join(process.cwd(), 'manager', 'dist'); const assetsPath = path.join(basePath, 'assets'); const filePath = path.join(assetsPath, fileName); // Security: Ensure the resolved path is within the assets directory const resolvedPath = path.resolve(filePath); const resolvedAssetsPath = path.resolve(assetsPath); if (!resolvedPath.startsWith(resolvedAssetsPath + path.sep) && resolvedPath !== resolvedAssetsPath) { return res.status(403).send('Forbidden'); } if (fs.existsSync(resolvedPath)) { res.set('Content-Type', mimeTypes.lookup(resolvedPath) || 'text/css'); res.send(fs.readFileSync(resolvedPath)); } else { res.status(404).send('File not found'); } }); ``` ## Special Route Patterns ### Manager Route Pattern ```typescript export class ViewsRouter extends RouterBroker { public readonly router: Router; constructor() { super(); this.router = Router(); const basePath = path.join(process.cwd(), 'manager', 'dist'); const indexPath = path.join(basePath, 'index.html'); this.router.use(express.static(basePath)); this.router.get('*', (req, res) => { res.sendFile(indexPath); }); } } ``` ### Webhook Route Pattern ```typescript // CORRECT - Webhook without guards .post('/webhook/evolution', async (req, res) => { const response = await evolutionController.receiveWebhook(req.body); return res.status(HttpStatus.OK).json(response); }) // CORRECT - Webhook with signature validation .post('/webhook/meta', validateWebhookSignature, async (req, res) => { const response = await metaController.receiveWebhook(req.body); return res.status(HttpStatus.OK).json(response); }) ``` ## Response Pattern ### Standard Response Format ```typescript // CORRECT - Standard success response return res.status(HttpStatus.OK).json(response); // CORRECT - Created response return res.status(HttpStatus.CREATED).json(response); // CORRECT - Custom response with additional data return res.status(HttpStatus.OK).json({ ...response, timestamp: new Date().toISOString(), instanceName: req.params.instanceName, }); ``` ## Route Organization ### File Structure ``` src/api/routes/ ├── index.router.ts # Main router with all route registrations ├── instance.router.ts # Instance management routes ├── sendMessage.router.ts # Message sending routes ├── chat.router.ts # Chat operations routes ├── business.router.ts # Business API routes ├── group.router.ts # Group management routes ├── label.router.ts # Label management routes ├── proxy.router.ts # Proxy configuration routes ├── settings.router.ts # Instance settings routes ├── template.router.ts # Template management routes ├── call.router.ts # Call operations routes └── view.router.ts # Frontend views routes ``` ## Route Testing Pattern ### Router Testing ```typescript describe('ExampleRouter', () => { let app: express.Application; let router: ExampleRouter; beforeEach(() => { app = express(); router = new ExampleRouter(); app.use('/api', router.router); app.use(express.json()); }); describe('GET /findExample', () => { it('should return example data', async () => { const response = await request(app) .get('/api/findExample/test-instance') .set('apikey', 'test-key') .expect(200); expect(response.body).toBeDefined(); expect(response.body.instanceName).toBe('test-instance'); }); it('should return 401 without API key', async () => { await request(app) .get('/api/findExample/test-instance') .expect(401); }); }); describe('POST /createExample', () => { it('should create example successfully', async () => { const data = { name: 'Test Example', description: 'Test Description', }; const response = await request(app) .post('/api/createExample/test-instance') .set('apikey', 'test-key') .send(data) .expect(201); expect(response.body.name).toBe(data.name); }); it('should validate required fields', async () => { const data = { description: 'Test Description', // Missing required 'name' field }; await request(app) .post('/api/createExample/test-instance') .set('apikey', 'test-key') .send(data) .expect(400); }); }); }); ``` ## Route Documentation ### JSDoc for Routes ```typescript /** * @route GET /api/template/findTemplate/:instanceName * @description Find template for instance * @param {string} instanceName - Instance name * @returns {TemplateDto} Template data * @throws {404} Template not found * @throws {401} Unauthorized */ .get(this.routerPath('findTemplate'), ...guards, async (req, res) => { // Implementation }) /** * @route POST /api/template/createTemplate/:instanceName * @description Create new template * @param {string} instanceName - Instance name * @body {TemplateDto} Template data * @returns {TemplateDto} Created template * @throws {400} Validation error * @throws {401} Unauthorized */ .post(this.routerPath('createTemplate'), ...guards, async (req, res) => { // Implementation }) ``` ================================================ FILE: .cursor/rules/specialized-rules/service-rules.mdc ================================================ --- description: Service layer patterns for Evolution API globs: - "src/api/services/**/*.ts" - "src/api/integrations/**/services/*.ts" alwaysApply: false --- # Evolution API Service Rules ## Service Structure Pattern ### Standard Service Class ```typescript export class ExampleService { constructor(private readonly waMonitor: WAMonitoringService) {} private readonly logger = new Logger('ExampleService'); public async create(instance: InstanceDto, data: ExampleDto) { await this.waMonitor.waInstances[instance.instanceName].setData(data); return { example: { ...instance, data } }; } public async find(instance: InstanceDto): Promise { try { const result = await this.waMonitor.waInstances[instance.instanceName].findData(); if (Object.keys(result).length === 0) { throw new Error('Data not found'); } return result; } catch (error) { return null; // Evolution pattern - return null on error } } } ``` ## Dependency Injection Pattern ### Constructor Pattern ```typescript // CORRECT - Evolution API pattern constructor( private readonly waMonitor: WAMonitoringService, private readonly prismaRepository: PrismaRepository, private readonly configService: ConfigService, ) {} // INCORRECT - Don't use constructor(waMonitor, prismaRepository, configService) {} // ❌ No types ``` ## Logger Pattern ### Standard Logger Usage ```typescript // CORRECT - Evolution API pattern private readonly logger = new Logger('ServiceName'); // Usage this.logger.log('Operation started'); this.logger.error('Operation failed', error); // INCORRECT console.log('Operation started'); // ❌ Use Logger ``` ## WAMonitor Integration Pattern ### Instance Access Pattern ```typescript // CORRECT - Standard pattern public async operation(instance: InstanceDto, data: DataDto) { await this.waMonitor.waInstances[instance.instanceName].performAction(data); return { result: { ...instance, data } }; } // Instance validation const waInstance = this.waMonitor.waInstances[instance.instanceName]; if (!waInstance) { throw new NotFoundException('Instance not found'); } ``` ## Error Handling Pattern ### Try-Catch Pattern ```typescript // CORRECT - Evolution API pattern public async find(instance: InstanceDto): Promise { try { const result = await this.waMonitor.waInstances[instance.instanceName].findData(); if (Object.keys(result).length === 0) { throw new Error('Data not found'); } return result; } catch (error) { this.logger.error('Find operation failed', error); return null; // Return null on error (Evolution pattern) } } ``` ## Cache Integration Pattern ### Cache Service Usage ```typescript export class CacheAwareService { constructor( private readonly cache: CacheService, private readonly chatwootCache: CacheService, private readonly baileysCache: CacheService, ) {} public async getCachedData(key: string): Promise { const cached = await this.cache.get(key); if (cached) return cached; const data = await this.fetchFromSource(key); await this.cache.set(key, data, 300); // 5 min TTL return data; } } ``` ## Integration Service Patterns ### Chatbot Service Base Pattern ```typescript export class ChatbotService extends BaseChatbotService { constructor( waMonitor: WAMonitoringService, prismaRepository: PrismaRepository, configService: ConfigService, ) { super(waMonitor, prismaRepository, 'ChatbotService', configService); } protected async processBot( waInstance: any, remoteJid: string, bot: BotType, session: any, settings: any, content: string, ): Promise { // Implementation } } ``` ### Channel Service Pattern ```typescript export class ChannelService extends ChannelStartupService { constructor( configService: ConfigService, eventEmitter: EventEmitter2, prismaRepository: PrismaRepository, cache: CacheService, chatwootCache: CacheService, baileysCache: CacheService, ) { super(configService, eventEmitter, prismaRepository, cache, chatwootCache, baileysCache); } public readonly logger = new Logger('ChannelService'); public client: WASocket; public readonly instance: wa.Instance = {}; } ``` ## Service Initialization Pattern ### Service Registration ```typescript // In server.module.ts pattern export const templateService = new TemplateService( waMonitor, prismaRepository, configService, ); export const settingsService = new SettingsService(waMonitor); ``` ## Async Operation Patterns ### Promise Handling ```typescript // CORRECT - Evolution API pattern public async sendMessage(instance: InstanceDto, data: MessageDto) { const waInstance = this.waMonitor.waInstances[instance.instanceName]; return await waInstance.sendMessage(data); } // INCORRECT - Don't use .then() public sendMessage(instance: InstanceDto, data: MessageDto) { return this.waMonitor.waInstances[instance.instanceName] .sendMessage(data) .then(result => result); // ❌ Use async/await } ``` ## Configuration Access Pattern ### Config Service Usage ```typescript // CORRECT - Evolution API pattern const serverConfig = this.configService.get('SERVER'); const authConfig = this.configService.get('AUTHENTICATION'); const dbConfig = this.configService.get('DATABASE'); // Type-safe configuration access if (this.configService.get('CHATWOOT').ENABLED) { // Chatwoot logic } ``` ## Event Emission Pattern ### EventEmitter2 Usage ```typescript // CORRECT - Evolution API pattern this.eventEmitter.emit(Events.INSTANCE_CREATE, { instanceName: instance.name, status: 'created', }); // Chatwoot event pattern if (this.configService.get('CHATWOOT').ENABLED && this.localChatwoot?.enabled) { this.chatwootService.eventWhatsapp( Events.STATUS_INSTANCE, { instanceName: this.instance.name }, { instance: this.instance.name, status: 'created', }, ); } ``` ## Service Method Naming ### Standard Method Names - `create()` - Create new resource - `find()` - Find single resource - `findAll()` - Find multiple resources - `update()` - Update resource - `delete()` - Delete resource - `fetch*()` - Fetch from external API - `send*()` - Send data/messages - `process*()` - Process data ## Service Testing Pattern ### Unit Test Structure ```typescript describe('ExampleService', () => { let service: ExampleService; let waMonitor: jest.Mocked; let prismaRepository: jest.Mocked; beforeEach(() => { const mockWaMonitor = { waInstances: { 'test-instance': { performAction: jest.fn(), }, }, }; service = new ExampleService( mockWaMonitor as any, prismaRepository, configService, ); }); it('should perform action successfully', async () => { const instance = { instanceName: 'test-instance' }; const data = { test: 'data' }; const result = await service.create(instance, data); expect(result).toBeDefined(); expect(waMonitor.waInstances['test-instance'].performAction).toHaveBeenCalledWith(data); }); }); ``` ================================================ FILE: .cursor/rules/specialized-rules/type-rules.mdc ================================================ --- description: Type definitions and interfaces for Evolution API globs: - "src/api/types/**/*.ts" - "src/@types/**/*.ts" alwaysApply: false --- # Evolution API Type Rules ## Namespace Pattern ### WhatsApp Types Namespace ```typescript /* eslint-disable @typescript-eslint/no-namespace */ import { JsonValue } from '@prisma/client/runtime/library'; import { AuthenticationState, WAConnectionState } from 'baileys'; export declare namespace wa { export type QrCode = { count?: number; pairingCode?: string; base64?: string; code?: string; }; export type Instance = { id?: string; qrcode?: QrCode; pairingCode?: string; authState?: { state: AuthenticationState; saveCreds: () => void }; name?: string; wuid?: string; profileName?: string; profilePictureUrl?: string; token?: string; number?: string; integration?: string; businessId?: string; }; export type LocalChatwoot = { enabled?: boolean; accountId?: string; token?: string; url?: string; nameInbox?: string; mergeBrazilContacts?: boolean; importContacts?: boolean; importMessages?: boolean; daysLimitImportMessages?: number; organization?: string; logo?: string; }; export type LocalProxy = { enabled?: boolean; host?: string; port?: string; protocol?: string; username?: string; password?: string; }; export type LocalSettings = { rejectCall?: boolean; msgCall?: string; groupsIgnore?: boolean; alwaysOnline?: boolean; readMessages?: boolean; readStatus?: boolean; syncFullHistory?: boolean; }; export type LocalWebHook = { enabled?: boolean; url?: string; events?: string[]; headers?: JsonValue; byEvents?: boolean; base64?: boolean; }; export type StatusMessage = 'ERROR' | 'PENDING' | 'SERVER_ACK' | 'DELIVERY_ACK' | 'READ' | 'DELETED' | 'PLAYED'; } ``` ## Enum Definitions ### Events Enum ```typescript export enum Events { APPLICATION_STARTUP = 'application.startup', INSTANCE_CREATE = 'instance.create', INSTANCE_DELETE = 'instance.delete', QRCODE_UPDATED = 'qrcode.updated', CONNECTION_UPDATE = 'connection.update', STATUS_INSTANCE = 'status.instance', MESSAGES_SET = 'messages.set', MESSAGES_UPSERT = 'messages.upsert', MESSAGES_EDITED = 'messages.edited', MESSAGES_UPDATE = 'messages.update', MESSAGES_DELETE = 'messages.delete', SEND_MESSAGE = 'send.message', SEND_MESSAGE_UPDATE = 'send.message.update', CONTACTS_SET = 'contacts.set', CONTACTS_UPSERT = 'contacts.upsert', CONTACTS_UPDATE = 'contacts.update', PRESENCE_UPDATE = 'presence.update', CHATS_SET = 'chats.set', CHATS_UPDATE = 'chats.update', CHATS_UPSERT = 'chats.upsert', CHATS_DELETE = 'chats.delete', GROUPS_UPSERT = 'groups.upsert', GROUPS_UPDATE = 'groups.update', GROUP_PARTICIPANTS_UPDATE = 'group-participants.update', CALL = 'call', TYPEBOT_START = 'typebot.start', TYPEBOT_CHANGE_STATUS = 'typebot.change-status', LABELS_EDIT = 'labels.edit', LABELS_ASSOCIATION = 'labels.association', CREDS_UPDATE = 'creds.update', MESSAGING_HISTORY_SET = 'messaging-history.set', REMOVE_INSTANCE = 'remove.instance', LOGOUT_INSTANCE = 'logout.instance', } ``` ### Integration Types ```typescript export const Integration = { WHATSAPP_BUSINESS: 'WHATSAPP-BUSINESS', WHATSAPP_BAILEYS: 'WHATSAPP-BAILEYS', EVOLUTION: 'EVOLUTION', } as const; export type IntegrationType = typeof Integration[keyof typeof Integration]; ``` ## Constant Arrays ### Message Type Constants ```typescript export const TypeMediaMessage = [ 'imageMessage', 'documentMessage', 'audioMessage', 'videoMessage', 'stickerMessage', 'ptvMessage', // Evolution API includes this ]; export const MessageSubtype = [ 'ephemeralMessage', 'documentWithCaptionMessage', 'viewOnceMessage', 'viewOnceMessageV2', ]; export type MediaMessageType = typeof TypeMediaMessage[number]; export type MessageSubtypeType = typeof MessageSubtype[number]; ``` ## Interface Definitions ### Service Interfaces ```typescript export interface ServiceInterface { create(instance: InstanceDto, data: any): Promise; find(instance: InstanceDto): Promise; update?(instance: InstanceDto, data: any): Promise; delete?(instance: InstanceDto): Promise; } export interface ChannelServiceInterface extends ServiceInterface { sendMessage(data: SendMessageDto): Promise; connectToWhatsapp(data?: any): Promise; receiveWebhook?(data: any): Promise; } export interface ChatbotServiceInterface extends ServiceInterface { processMessage( instanceName: string, remoteJid: string, message: any, pushName?: string, ): Promise; } ``` ## Configuration Types ### Environment Configuration Types ```typescript export interface DatabaseConfig { CONNECTION: { URI: string; DB_PREFIX_NAME: string; CLIENT_NAME?: string; }; ENABLED: boolean; SAVE_DATA: { INSTANCE: boolean; NEW_MESSAGE: boolean; MESSAGE_UPDATE: boolean; CONTACTS: boolean; CHATS: boolean; }; } export interface AuthConfig { TYPE: 'apikey' | 'jwt'; API_KEY: { KEY: string; }; JWT?: { EXPIRIN_IN: number; SECRET: string; }; } export interface CacheConfig { REDIS: { ENABLED: boolean; URI: string; PREFIX_KEY: string; SAVE_INSTANCES: boolean; }; LOCAL: { ENABLED: boolean; TTL: number; }; } ``` ## Message Types ### Message Structure Types ```typescript export interface MessageContent { text?: string; caption?: string; media?: Buffer | string; mediatype?: 'image' | 'video' | 'audio' | 'document' | 'sticker'; fileName?: string; mimetype?: string; } export interface MessageOptions { delay?: number; presence?: 'unavailable' | 'available' | 'composing' | 'recording' | 'paused'; linkPreview?: boolean; mentionsEveryOne?: boolean; mentioned?: string[]; quoted?: { key: { remoteJid: string; fromMe: boolean; id: string; }; message: any; }; } export interface SendMessageRequest { number: string; content: MessageContent; options?: MessageOptions; } ``` ## Webhook Types ### Webhook Payload Types ```typescript export interface WebhookPayload { event: Events; instance: string; data: any; timestamp: string; server?: { version: string; host: string; }; } export interface WebhookConfig { enabled: boolean; url: string; events: Events[]; headers?: Record; byEvents?: boolean; base64?: boolean; } ``` ## Error Types ### Custom Error Types ```typescript export interface ApiError { status: number; message: string; error?: string; details?: any; timestamp: string; path: string; } export interface ValidationError extends ApiError { status: 400; validationErrors: Array<{ field: string; message: string; value?: any; }>; } export interface AuthenticationError extends ApiError { status: 401; message: 'Unauthorized' | 'Invalid API Key' | 'Token Expired'; } ``` ## Utility Types ### Generic Utility Types ```typescript export type Optional = Omit & Partial>; export type RequiredFields = T & Required>; export type DeepPartial = { [P in keyof T]?: T[P] extends object ? DeepPartial : T[P]; }; export type NonEmptyArray = [T, ...T[]]; export type StringKeys = { [K in keyof T]: T[K] extends string ? K : never; }[keyof T]; ``` ## Response Types ### API Response Types ```typescript export interface ApiResponse { success: boolean; data?: T; message?: string; error?: string; timestamp: string; } export interface PaginatedResponse extends ApiResponse { pagination: { page: number; limit: number; total: number; totalPages: number; hasNext: boolean; hasPrev: boolean; }; } export interface InstanceResponse extends ApiResponse { instance: { instanceName: string; status: 'connecting' | 'open' | 'close' | 'qr'; qrcode?: string; profileName?: string; profilePicUrl?: string; }; } ``` ## Integration-Specific Types ### Baileys Types Extension ```typescript import { WASocket, ConnectionState, DisconnectReason } from 'baileys'; export interface BaileysInstance { client: WASocket; state: ConnectionState; qrRetry: number; authPath: string; } export interface BaileysConfig { qrTimeout: number; maxQrRetries: number; authTimeout: number; reconnectInterval: number; } ``` ### Business API Types ```typescript export interface BusinessApiConfig { version: string; baseUrl: string; timeout: number; retries: number; } export interface BusinessApiMessage { messaging_product: 'whatsapp'; to: string; type: 'text' | 'image' | 'document' | 'audio' | 'video' | 'template'; text?: { body: string; preview_url?: boolean; }; image?: { link?: string; id?: string; caption?: string; }; template?: { name: string; language: { code: string; }; components?: any[]; }; } ``` ## Type Guards ### Type Guard Functions ```typescript export function isMediaMessage(message: any): message is MediaMessage { return message && TypeMediaMessage.some(type => message[type]); } export function isTextMessage(message: any): message is TextMessage { return message && message.conversation; } export function isValidIntegration(integration: string): integration is IntegrationType { return Object.values(Integration).includes(integration as IntegrationType); } export function isValidEvent(event: string): event is Events { return Object.values(Events).includes(event as Events); } ``` ## Module Augmentation ### Express Request Extension ```typescript declare global { namespace Express { interface Request { instanceName?: string; instanceData?: InstanceDto; user?: { id: string; apiKey: string; }; } } } ``` ## Type Documentation ### JSDoc Type Documentation ```typescript /** * WhatsApp instance configuration * @interface InstanceConfig * @property {string} name - Unique instance name * @property {IntegrationType} integration - Integration type * @property {string} [token] - API token for business integrations * @property {WebhookConfig} [webhook] - Webhook configuration * @property {ProxyConfig} [proxy] - Proxy configuration */ export interface InstanceConfig { name: string; integration: IntegrationType; token?: string; webhook?: WebhookConfig; proxy?: ProxyConfig; } ``` ================================================ FILE: .cursor/rules/specialized-rules/util-rules.mdc ================================================ --- description: Utility functions and helpers for Evolution API globs: - "src/utils/**/*.ts" alwaysApply: false --- # Evolution API Utility Rules ## Utility Function Structure ### Standard Utility Pattern ```typescript import { Logger } from '@config/logger.config'; const logger = new Logger('UtilityName'); export function utilityFunction(param: ParamType): ReturnType { try { // Utility logic return result; } catch (error) { logger.error(`Utility function failed: ${error.message}`); throw error; } } export default utilityFunction; ``` ## Authentication Utilities ### Multi-File Auth State Pattern ```typescript import { AuthenticationState } from 'baileys'; import { CacheService } from '@api/services/cache.service'; import fs from 'fs/promises'; import path from 'path'; export default async function useMultiFileAuthStatePrisma( sessionId: string, cache: CacheService, ): Promise<{ state: AuthenticationState; saveCreds: () => Promise; }> { const localFolder = path.join(INSTANCE_DIR, sessionId); const localFile = (key: string) => path.join(localFolder, fixFileName(key) + '.json'); await fs.mkdir(localFolder, { recursive: true }); async function writeData(data: any, key: string): Promise { const dataString = JSON.stringify(data, BufferJSON.replacer); if (key !== 'creds') { if (process.env.CACHE_REDIS_ENABLED === 'true') { return await cache.hSet(sessionId, key, data); } else { await fs.writeFile(localFile(key), dataString); return; } } await saveKey(sessionId, dataString); return; } async function readData(key: string): Promise { try { let rawData; if (key !== 'creds') { if (process.env.CACHE_REDIS_ENABLED === 'true') { return await cache.hGet(sessionId, key); } else { if (!(await fileExists(localFile(key)))) return null; rawData = await fs.readFile(localFile(key), { encoding: 'utf-8' }); return JSON.parse(rawData, BufferJSON.reviver); } } else { rawData = await getAuthKey(sessionId); } const parsedData = JSON.parse(rawData, BufferJSON.reviver); return parsedData; } catch (error) { return null; } } async function removeData(key: string): Promise { try { if (key !== 'creds') { if (process.env.CACHE_REDIS_ENABLED === 'true') { return await cache.hDelete(sessionId, key); } else { await fs.unlink(localFile(key)); } } else { await deleteAuthKey(sessionId); } } catch (error) { return; } } let creds = await readData('creds'); if (!creds) { creds = initAuthCreds(); await writeData(creds, 'creds'); } return { state: { creds, keys: { get: async (type, ids) => { const data = {}; await Promise.all( ids.map(async (id) => { let value = await readData(`${type}-${id}`); if (type === 'app-state-sync-key' && value) { value = proto.Message.AppStateSyncKeyData.fromObject(value); } data[id] = value; }) ); return data; }, set: async (data) => { const tasks = []; for (const category in data) { for (const id in data[category]) { const value = data[category][id]; const key = `${category}-${id}`; tasks.push(value ? writeData(value, key) : removeData(key)); } } await Promise.all(tasks); }, }, }, saveCreds: () => writeData(creds, 'creds'), }; } ``` ## Message Processing Utilities ### Message Content Extraction ```typescript export const getConversationMessage = (msg: any): string => { const types = getTypeMessage(msg); const messageContent = getMessageContent(types); return messageContent; }; const getTypeMessage = (msg: any): any => { return Object.keys(msg?.message || msg || {})[0]; }; const getMessageContent = (type: string, msg?: any): string => { const typeKey = type?.replace('Message', ''); const types = { conversation: msg?.message?.conversation, extendedTextMessage: msg?.message?.extendedTextMessage?.text, imageMessage: msg?.message?.imageMessage?.caption || 'Image', videoMessage: msg?.message?.videoMessage?.caption || 'Video', audioMessage: 'Audio', documentMessage: msg?.message?.documentMessage?.caption || 'Document', stickerMessage: 'Sticker', contactMessage: 'Contact', locationMessage: 'Location', liveLocationMessage: 'Live Location', viewOnceMessage: 'View Once', reactionMessage: 'Reaction', pollCreationMessage: 'Poll', pollUpdateMessage: 'Poll Update', }; let result = types[typeKey] || types[type] || 'Unknown'; if (!result || result === 'Unknown') { result = JSON.stringify(msg); } return result; }; ``` ### JID Creation Utility ```typescript export const createJid = (number: string): string => { if (number.includes('@')) { return number; } // Remove any non-numeric characters except + let cleanNumber = number.replace(/[^\d+]/g, ''); // Remove + if present if (cleanNumber.startsWith('+')) { cleanNumber = cleanNumber.substring(1); } // Add country code if missing (assuming Brazil as default) if (cleanNumber.length === 11 && cleanNumber.startsWith('11')) { cleanNumber = '55' + cleanNumber; } else if (cleanNumber.length === 10) { cleanNumber = '5511' + cleanNumber; } // Determine if it's a group or individual const isGroup = cleanNumber.includes('-'); const domain = isGroup ? 'g.us' : 's.whatsapp.net'; return `${cleanNumber}@${domain}`; }; ``` ## Cache Utilities ### WhatsApp Number Cache ```typescript interface ISaveOnWhatsappCacheParams { remoteJid: string; lid?: string; } function getAvailableNumbers(remoteJid: string): string[] { const numbersAvailable: string[] = []; if (remoteJid.startsWith('+')) { remoteJid = remoteJid.slice(1); } const [number, domain] = remoteJid.split('@'); // Brazilian numbers if (remoteJid.startsWith('55')) { const numberWithDigit = number.slice(4, 5) === '9' && number.length === 13 ? number : `${number.slice(0, 4)}9${number.slice(4)}`; const numberWithoutDigit = number.length === 12 ? number : number.slice(0, 4) + number.slice(5); numbersAvailable.push(numberWithDigit); numbersAvailable.push(numberWithoutDigit); } // Mexican/Argentina numbers else if (number.startsWith('52') || number.startsWith('54')) { let prefix = ''; if (number.startsWith('52')) { prefix = '1'; } if (number.startsWith('54')) { prefix = '9'; } const numberWithDigit = number.slice(2, 3) === prefix && number.length === 13 ? number : `${number.slice(0, 2)}${prefix}${number.slice(2)}`; const numberWithoutDigit = number.length === 12 ? number : number.slice(0, 2) + number.slice(3); numbersAvailable.push(numberWithDigit); numbersAvailable.push(numberWithoutDigit); } // Other countries else { numbersAvailable.push(remoteJid); } return numbersAvailable.map((number) => `${number}@${domain}`); } export async function saveOnWhatsappCache(params: ISaveOnWhatsappCacheParams): Promise { const { remoteJid, lid } = params; const db = configService.get('DATABASE'); if (!db.SAVE_DATA.CONTACTS) { return; } try { const numbersAvailable = getAvailableNumbers(remoteJid); const existingContact = await prismaRepository.contact.findFirst({ where: { OR: numbersAvailable.map(number => ({ id: number })), }, }); if (!existingContact) { await prismaRepository.contact.create({ data: { id: remoteJid, pushName: '', profilePicUrl: '', isOnWhatsapp: true, lid: lid || null, createdAt: new Date(), updatedAt: new Date(), }, }); } else { await prismaRepository.contact.update({ where: { id: existingContact.id }, data: { isOnWhatsapp: true, lid: lid || existingContact.lid, updatedAt: new Date(), }, }); } } catch (error) { console.error('Error saving WhatsApp cache:', error); } } ``` ## Search Utilities ### Advanced Search Operators ```typescript function normalizeString(str: string): string { return str .toLowerCase() .normalize('NFD') .replace(/[\u0300-\u036f]/g, ''); } export function advancedOperatorsSearch(data: string, query: string): boolean { const normalizedData = normalizeString(data); const normalizedQuery = normalizeString(query); // Exact phrase search with quotes if (normalizedQuery.startsWith('"') && normalizedQuery.endsWith('"')) { const phrase = normalizedQuery.slice(1, -1); return normalizedData.includes(phrase); } // OR operator if (normalizedQuery.includes(' OR ')) { const terms = normalizedQuery.split(' OR '); return terms.some(term => normalizedData.includes(term.trim())); } // AND operator (default behavior) if (normalizedQuery.includes(' AND ')) { const terms = normalizedQuery.split(' AND '); return terms.every(term => normalizedData.includes(term.trim())); } // NOT operator if (normalizedQuery.startsWith('NOT ')) { const term = normalizedQuery.slice(4); return !normalizedData.includes(term); } // Wildcard search if (normalizedQuery.includes('*')) { const regex = new RegExp(normalizedQuery.replace(/\*/g, '.*'), 'i'); return regex.test(normalizedData); } // Default: simple contains search return normalizedData.includes(normalizedQuery); } ``` ## Proxy Utilities ### Proxy Agent Creation ```typescript import { HttpsProxyAgent } from 'https-proxy-agent'; import { SocksProxyAgent } from 'socks-proxy-agent'; type Proxy = { host: string; port: string; protocol: 'http' | 'https' | 'socks4' | 'socks5'; username?: string; password?: string; }; function selectProxyAgent(proxyUrl: string): HttpsProxyAgent | SocksProxyAgent { const url = new URL(proxyUrl); if (url.protocol === 'socks4:' || url.protocol === 'socks5:') { return new SocksProxyAgent(proxyUrl); } else { return new HttpsProxyAgent(proxyUrl); } } export function makeProxyAgent(proxy: Proxy): HttpsProxyAgent | SocksProxyAgent | null { if (!proxy.host || !proxy.port) { return null; } let proxyUrl = `${proxy.protocol}://`; if (proxy.username && proxy.password) { proxyUrl += `${proxy.username}:${proxy.password}@`; } proxyUrl += `${proxy.host}:${proxy.port}`; try { return selectProxyAgent(proxyUrl); } catch (error) { console.error('Failed to create proxy agent:', error); return null; } } ``` ## Telemetry Utilities ### Telemetry Data Collection ```typescript export interface TelemetryData { route: string; apiVersion: string; timestamp: Date; method?: string; statusCode?: number; responseTime?: number; userAgent?: string; instanceName?: string; } export const sendTelemetry = async (route: string): Promise => { try { const telemetryData: TelemetryData = { route, apiVersion: packageJson.version, timestamp: new Date(), }; // Only send telemetry if enabled if (process.env.DISABLE_TELEMETRY === 'true') { return; } // Send to telemetry service (implement as needed) await axios.post('https://telemetry.evolution-api.com/collect', telemetryData, { timeout: 5000, }); } catch (error) { // Silently fail - don't affect main application console.debug('Telemetry failed:', error.message); } }; ``` ## Internationalization Utilities ### i18n Setup ```typescript import { ConfigService, Language } from '@config/env.config'; import fs from 'fs'; import i18next from 'i18next'; import path from 'path'; const __dirname = path.resolve(process.cwd(), 'src', 'utils'); const languages = ['en', 'pt-BR', 'es']; const translationsPath = path.join(__dirname, 'translations'); const configService: ConfigService = new ConfigService(); const resources: any = {}; languages.forEach((language) => { const languagePath = path.join(translationsPath, `${language}.json`); if (fs.existsSync(languagePath)) { const translationContent = fs.readFileSync(languagePath, 'utf8'); resources[language] = { translation: JSON.parse(translationContent), }; } }); i18next.init({ resources, fallbackLng: 'en', lng: configService.get('LANGUAGE') || 'pt-BR', interpolation: { escapeValue: false, }, }); export const t = i18next.t.bind(i18next); export default i18next; ``` ## Bot Trigger Utilities ### Bot Trigger Matching ```typescript import { TriggerOperator, TriggerType } from '@prisma/client'; export function findBotByTrigger( bots: any[], content: string, remoteJid: string, ): any | null { for (const bot of bots) { if (!bot.enabled) continue; // Check ignore list if (bot.ignoreJids && bot.ignoreJids.includes(remoteJid)) { continue; } // Check trigger if (matchesTrigger(content, bot.triggerType, bot.triggerOperator, bot.triggerValue)) { return bot; } } return null; } function matchesTrigger( content: string, triggerType: TriggerType, triggerOperator: TriggerOperator, triggerValue: string, ): boolean { const normalizedContent = content.toLowerCase().trim(); const normalizedValue = triggerValue.toLowerCase().trim(); switch (triggerType) { case TriggerType.ALL: return true; case TriggerType.KEYWORD: return matchesKeyword(normalizedContent, triggerOperator, normalizedValue); case TriggerType.REGEX: try { const regex = new RegExp(triggerValue, 'i'); return regex.test(content); } catch { return false; } default: return false; } } function matchesKeyword( content: string, operator: TriggerOperator, value: string, ): boolean { switch (operator) { case TriggerOperator.EQUALS: return content === value; case TriggerOperator.CONTAINS: return content.includes(value); case TriggerOperator.STARTS_WITH: return content.startsWith(value); case TriggerOperator.ENDS_WITH: return content.endsWith(value); default: return false; } } ``` ## Server Utilities ### Server Status Check ```typescript export class ServerUP { private static instance: ServerUP; private isServerUp: boolean = false; private constructor() {} public static getInstance(): ServerUP { if (!ServerUP.instance) { ServerUP.instance = new ServerUP(); } return ServerUP.instance; } public setServerStatus(status: boolean): void { this.isServerUp = status; } public getServerStatus(): boolean { return this.isServerUp; } public async waitForServer(timeout: number = 30000): Promise { const startTime = Date.now(); while (!this.isServerUp && (Date.now() - startTime) < timeout) { await new Promise(resolve => setTimeout(resolve, 100)); } return this.isServerUp; } } ``` ## Error Response Utilities ### Standardized Error Responses ```typescript export function createMetaErrorResponse(error: any, context: string) { const timestamp = new Date().toISOString(); if (error.response?.data) { return { status: error.response.status || 500, error: { message: error.response.data.error?.message || 'External API error', type: error.response.data.error?.type || 'api_error', code: error.response.data.error?.code || 'unknown_error', context, timestamp, }, }; } return { status: 500, error: { message: error.message || 'Internal server error', type: 'internal_error', code: 'server_error', context, timestamp, }, }; } export function createValidationErrorResponse(errors: any[], context: string) { return { status: 400, error: { message: 'Validation failed', type: 'validation_error', code: 'invalid_input', context, details: errors, timestamp: new Date().toISOString(), }, }; } ``` ================================================ FILE: .cursor/rules/specialized-rules/validate-rules.mdc ================================================ --- description: Validation schemas and patterns for Evolution API globs: - "src/validate/**/*.ts" alwaysApply: false --- # Evolution API Validation Rules ## Validation Schema Structure ### JSONSchema7 Pattern (Evolution API Standard) ```typescript import { JSONSchema7 } from 'json-schema'; import { v4 } from 'uuid'; const isNotEmpty = (...fields: string[]) => { const properties = {}; fields.forEach((field) => { properties[field] = { if: { properties: { [field]: { type: 'string' } } }, then: { properties: { [field]: { minLength: 1 } } }, }; }); return { allOf: Object.values(properties), }; }; export const exampleSchema: JSONSchema7 = { $id: v4(), type: 'object', properties: { name: { type: 'string' }, description: { type: 'string' }, enabled: { type: 'boolean' }, settings: { type: 'object', properties: { timeout: { type: 'number', minimum: 1000, maximum: 60000 }, retries: { type: 'number', minimum: 0, maximum: 5 }, }, }, tags: { type: 'array', items: { type: 'string' }, }, }, required: ['name', 'enabled'], ...isNotEmpty('name'), }; ``` ## Message Validation Schemas ### Send Message Validation ```typescript const numberDefinition = { type: 'string', pattern: '^\\d+[\\.@\\w-]+', description: 'Invalid number', }; export const sendTextSchema: JSONSchema7 = { $id: v4(), type: 'object', properties: { number: numberDefinition, text: { type: 'string', minLength: 1, maxLength: 4096 }, delay: { type: 'number', minimum: 0, maximum: 60000 }, linkPreview: { type: 'boolean' }, mentionsEveryOne: { type: 'boolean' }, mentioned: { type: 'array', items: { type: 'string' }, }, }, required: ['number', 'text'], ...isNotEmpty('number', 'text'), }; export const sendMediaSchema = Joi.object({ number: Joi.string().required().pattern(/^\d+$/), mediatype: Joi.string().required().valid('image', 'video', 'audio', 'document'), media: Joi.alternatives().try( Joi.string().uri(), Joi.string().base64(), ).required(), caption: Joi.string().optional().max(1024), fileName: Joi.string().optional().max(255), delay: Joi.number().optional().min(0).max(60000), }).required(); export const sendButtonsSchema = Joi.object({ number: Joi.string().required().pattern(/^\d+$/), title: Joi.string().required().max(1024), description: Joi.string().optional().max(1024), footer: Joi.string().optional().max(60), buttons: Joi.array().items( Joi.object({ type: Joi.string().required().valid('replyButton', 'urlButton', 'callButton'), displayText: Joi.string().required().max(20), id: Joi.string().when('type', { is: 'replyButton', then: Joi.required().max(256), otherwise: Joi.optional(), }), url: Joi.string().when('type', { is: 'urlButton', then: Joi.required().uri(), otherwise: Joi.optional(), }), phoneNumber: Joi.string().when('type', { is: 'callButton', then: Joi.required().pattern(/^\+?\d+$/), otherwise: Joi.optional(), }), }) ).min(1).max(3).required(), }).required(); ``` ## Instance Validation Schemas ### Instance Creation Validation ```typescript export const instanceSchema = Joi.object({ instanceName: Joi.string().required().min(1).max(100).pattern(/^[a-zA-Z0-9_-]+$/), integration: Joi.string().required().valid('WHATSAPP-BAILEYS', 'WHATSAPP-BUSINESS', 'EVOLUTION'), token: Joi.string().when('integration', { is: Joi.valid('WHATSAPP-BUSINESS', 'EVOLUTION'), then: Joi.required().min(10), otherwise: Joi.optional(), }), qrcode: Joi.boolean().optional().default(false), number: Joi.string().optional().pattern(/^\d+$/), businessId: Joi.string().when('integration', { is: 'WHATSAPP-BUSINESS', then: Joi.required(), otherwise: Joi.optional(), }), }).required(); export const settingsSchema = Joi.object({ rejectCall: Joi.boolean().optional(), msgCall: Joi.string().optional().max(500), groupsIgnore: Joi.boolean().optional(), alwaysOnline: Joi.boolean().optional(), readMessages: Joi.boolean().optional(), readStatus: Joi.boolean().optional(), syncFullHistory: Joi.boolean().optional(), wavoipToken: Joi.string().optional(), }).optional(); export const proxySchema = Joi.object({ host: Joi.string().required().hostname(), port: Joi.string().required().pattern(/^\d+$/).custom((value) => { const port = parseInt(value); if (port < 1 || port > 65535) { throw new Error('Port must be between 1 and 65535'); } return value; }), protocol: Joi.string().required().valid('http', 'https', 'socks4', 'socks5'), username: Joi.string().optional(), password: Joi.string().optional(), }).optional(); ``` ## Webhook Validation Schemas ### Webhook Configuration Validation ```typescript export const webhookSchema = Joi.object({ enabled: Joi.boolean().required(), url: Joi.string().when('enabled', { is: true, then: Joi.required().uri({ scheme: ['http', 'https'] }), otherwise: Joi.optional(), }), events: Joi.array().items( Joi.string().valid( 'APPLICATION_STARTUP', 'INSTANCE_CREATE', 'INSTANCE_DELETE', 'QRCODE_UPDATED', 'CONNECTION_UPDATE', 'STATUS_INSTANCE', 'MESSAGES_SET', 'MESSAGES_UPSERT', 'MESSAGES_UPDATE', 'MESSAGES_DELETE', 'CONTACTS_SET', 'CONTACTS_UPSERT', 'CONTACTS_UPDATE', 'CHATS_SET', 'CHATS_UPDATE', 'CHATS_UPSERT', 'CHATS_DELETE', 'GROUPS_UPSERT', 'GROUPS_UPDATE', 'GROUP_PARTICIPANTS_UPDATE', 'CALL' ) ).min(1).when('enabled', { is: true, then: Joi.required(), otherwise: Joi.optional(), }), headers: Joi.object().pattern( Joi.string(), Joi.string() ).optional(), byEvents: Joi.boolean().optional().default(false), base64: Joi.boolean().optional().default(false), }).required(); ``` ## Chatbot Validation Schemas ### Base Chatbot Validation ```typescript export const baseChatbotSchema = Joi.object({ enabled: Joi.boolean().required(), description: Joi.string().required().min(1).max(500), expire: Joi.number().optional().min(0).max(86400), // 24 hours in seconds keywordFinish: Joi.string().optional().max(100), delayMessage: Joi.number().optional().min(0).max(10000), unknownMessage: Joi.string().optional().max(1000), listeningFromMe: Joi.boolean().optional().default(false), stopBotFromMe: Joi.boolean().optional().default(false), keepOpen: Joi.boolean().optional().default(false), debounceTime: Joi.number().optional().min(0).max(60000), triggerType: Joi.string().required().valid('ALL', 'KEYWORD', 'REGEX'), triggerOperator: Joi.string().when('triggerType', { is: 'KEYWORD', then: Joi.required().valid('EQUALS', 'CONTAINS', 'STARTS_WITH', 'ENDS_WITH'), otherwise: Joi.optional(), }), triggerValue: Joi.string().when('triggerType', { is: Joi.valid('KEYWORD', 'REGEX'), then: Joi.required().min(1).max(500), otherwise: Joi.optional(), }), ignoreJids: Joi.array().items(Joi.string()).optional(), splitMessages: Joi.boolean().optional().default(false), timePerChar: Joi.number().optional().min(10).max(1000).default(100), }).required(); export const typebotSchema = baseChatbotSchema.keys({ url: Joi.string().required().uri({ scheme: ['http', 'https'] }), typebot: Joi.string().required().min(1).max(100), apiVersion: Joi.string().optional().valid('v1', 'v2').default('v1'), }).required(); export const openaiSchema = baseChatbotSchema.keys({ apiKey: Joi.string().required().min(10), model: Joi.string().optional().valid( 'gpt-3.5-turbo', 'gpt-3.5-turbo-16k', 'gpt-4', 'gpt-4-32k', 'gpt-4-turbo-preview' ).default('gpt-3.5-turbo'), systemMessage: Joi.string().optional().max(2000), maxTokens: Joi.number().optional().min(1).max(4000).default(1000), temperature: Joi.number().optional().min(0).max(2).default(0.7), }).required(); ``` ## Business API Validation Schemas ### Template Validation ```typescript export const templateSchema = Joi.object({ name: Joi.string().required().min(1).max(512).pattern(/^[a-z0-9_]+$/), category: Joi.string().required().valid('MARKETING', 'UTILITY', 'AUTHENTICATION'), allowCategoryChange: Joi.boolean().required(), language: Joi.string().required().pattern(/^[a-z]{2}_[A-Z]{2}$/), // e.g., pt_BR, en_US components: Joi.array().items( Joi.object({ type: Joi.string().required().valid('HEADER', 'BODY', 'FOOTER', 'BUTTONS'), format: Joi.string().when('type', { is: 'HEADER', then: Joi.valid('TEXT', 'IMAGE', 'VIDEO', 'DOCUMENT'), otherwise: Joi.optional(), }), text: Joi.string().when('type', { is: Joi.valid('HEADER', 'BODY', 'FOOTER'), then: Joi.required().min(1).max(1024), otherwise: Joi.optional(), }), buttons: Joi.array().when('type', { is: 'BUTTONS', then: Joi.items( Joi.object({ type: Joi.string().required().valid('QUICK_REPLY', 'URL', 'PHONE_NUMBER'), text: Joi.string().required().min(1).max(25), url: Joi.string().when('type', { is: 'URL', then: Joi.required().uri(), otherwise: Joi.optional(), }), phone_number: Joi.string().when('type', { is: 'PHONE_NUMBER', then: Joi.required().pattern(/^\+?\d+$/), otherwise: Joi.optional(), }), }) ).min(1).max(10), otherwise: Joi.optional(), }), }) ).min(1).required(), webhookUrl: Joi.string().optional().uri({ scheme: ['http', 'https'] }), }).required(); export const catalogSchema = Joi.object({ number: Joi.string().optional().pattern(/^\d+$/), limit: Joi.number().optional().min(1).max(1000).default(10), cursor: Joi.string().optional(), }).optional(); ``` ## Group Validation Schemas ### Group Management Validation ```typescript export const createGroupSchema = Joi.object({ subject: Joi.string().required().min(1).max(100), description: Joi.string().optional().max(500), participants: Joi.array().items( Joi.string().pattern(/^\d+$/) ).min(1).max(256).required(), promoteParticipants: Joi.boolean().optional().default(false), }).required(); export const updateGroupSchema = Joi.object({ subject: Joi.string().optional().min(1).max(100), description: Joi.string().optional().max(500), }).min(1).required(); export const groupParticipantsSchema = Joi.object({ participants: Joi.array().items( Joi.string().pattern(/^\d+$/) ).min(1).max(50).required(), action: Joi.string().required().valid('add', 'remove', 'promote', 'demote'), }).required(); ``` ## Label Validation Schemas ### Label Management Validation ```typescript export const labelSchema = Joi.object({ name: Joi.string().required().min(1).max(100), color: Joi.string().required().pattern(/^#[0-9A-Fa-f]{6}$/), // Hex color predefinedId: Joi.string().optional(), }).required(); export const handleLabelSchema = Joi.object({ number: Joi.string().required().pattern(/^\d+$/), labelId: Joi.string().required(), action: Joi.string().required().valid('add', 'remove'), }).required(); ``` ## Custom Validation Functions ### Phone Number Validation ```typescript export function validatePhoneNumber(number: string): boolean { // Remove any non-digit characters const cleaned = number.replace(/\D/g, ''); // Check minimum and maximum length if (cleaned.length < 10 || cleaned.length > 15) { return false; } // Check for valid country codes (basic validation) const validCountryCodes = ['1', '7', '20', '27', '30', '31', '32', '33', '34', '36', '39', '40', '41', '43', '44', '45', '46', '47', '48', '49', '51', '52', '53', '54', '55', '56', '57', '58', '60', '61', '62', '63', '64', '65', '66', '81', '82', '84', '86', '90', '91', '92', '93', '94', '95', '98']; // Check if starts with valid country code const startsWithValidCode = validCountryCodes.some(code => cleaned.startsWith(code)); return startsWithValidCode; } export const phoneNumberValidator = Joi.string().custom((value, helpers) => { if (!validatePhoneNumber(value)) { return helpers.error('any.invalid'); } return value; }, 'Phone number validation'); ``` ### Base64 Validation ```typescript export function validateBase64(base64: string): boolean { try { // Check if it's a valid base64 string const decoded = Buffer.from(base64, 'base64').toString('base64'); return decoded === base64; } catch { return false; } } export const base64Validator = Joi.string().custom((value, helpers) => { if (!validateBase64(value)) { return helpers.error('any.invalid'); } return value; }, 'Base64 validation'); ``` ### URL Validation with Protocol Check ```typescript export function validateWebhookUrl(url: string): boolean { try { const parsed = new URL(url); return ['http:', 'https:'].includes(parsed.protocol); } catch { return false; } } export const webhookUrlValidator = Joi.string().custom((value, helpers) => { if (!validateWebhookUrl(value)) { return helpers.error('any.invalid'); } return value; }, 'Webhook URL validation'); ``` ## Validation Error Handling ### Error Message Customization ```typescript export const validationMessages = { 'any.required': 'O campo {#label} é obrigatório', 'string.empty': 'O campo {#label} não pode estar vazio', 'string.min': 'O campo {#label} deve ter pelo menos {#limit} caracteres', 'string.max': 'O campo {#label} deve ter no máximo {#limit} caracteres', 'string.pattern.base': 'O campo {#label} possui formato inválido', 'number.min': 'O campo {#label} deve ser maior ou igual a {#limit}', 'number.max': 'O campo {#label} deve ser menor ou igual a {#limit}', 'array.min': 'O campo {#label} deve ter pelo menos {#limit} itens', 'array.max': 'O campo {#label} deve ter no máximo {#limit} itens', 'any.only': 'O campo {#label} deve ser um dos valores: {#valids}', }; export function formatValidationError(error: Joi.ValidationError): any { return { message: 'Dados de entrada inválidos', details: error.details.map(detail => ({ field: detail.path.join('.'), message: detail.message, value: detail.context?.value, })), }; } ``` ## Schema Composition ### Reusable Schema Components ```typescript export const commonFields = { instanceName: Joi.string().required().min(1).max(100).pattern(/^[a-zA-Z0-9_-]+$/), number: phoneNumberValidator.required(), delay: Joi.number().optional().min(0).max(60000), enabled: Joi.boolean().optional().default(true), }; export const mediaFields = { mediatype: Joi.string().required().valid('image', 'video', 'audio', 'document'), media: Joi.alternatives().try( Joi.string().uri(), base64Validator, ).required(), caption: Joi.string().optional().max(1024), fileName: Joi.string().optional().max(255), }; // Compose schemas using common fields export const quickMessageSchema = Joi.object({ ...commonFields, text: Joi.string().required().min(1).max(4096), }).required(); export const quickMediaSchema = Joi.object({ ...commonFields, ...mediaFields, }).required(); ``` ================================================ FILE: .dockerignore ================================================ .git *Dockerfile* *docker-compose* .env node_modules dist ================================================ FILE: .eslintignore ================================================ /node-modules /dist ================================================ FILE: .eslintrc.js ================================================ module.exports = { parser: '@typescript-eslint/parser', parserOptions: { project: 'tsconfig.json', tsconfigRootDir: __dirname, sourceType: 'module', warnOnUnsupportedTypeScriptVersion: false, EXPERIMENTAL_useSourceOfProjectReferenceRedirect: true, }, plugins: ['@typescript-eslint', 'simple-import-sort', 'import'], extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended'], globals: { Atomics: 'readonly', SharedArrayBuffer: 'readonly', }, root: true, env: { node: true, jest: true, }, ignorePatterns: ['.eslintrc.js'], rules: { '@typescript-eslint/interface-name-prefix': 'off', '@typescript-eslint/explicit-function-return-type': 'off', '@typescript-eslint/explicit-module-boundary-types': 'off', '@typescript-eslint/no-explicit-any': 'off', '@typescript-eslint/no-empty-function': 'off', '@typescript-eslint/no-non-null-assertion': 'off', '@typescript-eslint/no-unused-vars': 'error', 'import/first': 'error', 'import/no-duplicates': 'error', 'simple-import-sort/imports': 'error', 'simple-import-sort/exports': 'error', '@typescript-eslint/no-empty-object-type': 'off', '@typescript-eslint/no-wrapper-object-types': 'off', '@typescript-eslint/no-unused-expressions': 'off', 'prettier/prettier': ['error', { endOfLine: 'auto' }], }, }; ================================================ FILE: .github/ISSUE_TEMPLATE/-en--bug-report.yaml ================================================ name: Bug Report description: Create a report to help us improve. labels: - bug - en # - help wanted # Automatically assign the issue to: # assignees: DavidsonGomes body: - type: checkboxes id: terms attributes: label: Welcome! description: | The issue tracker is only for reporting bugs and feature requests. For user-related support questions, please visit: - [Discord](https://evolution-api.com/discord) - [WhatsApp Group](https://evolution-api.com/whatsapp)
**DO NOT OPEN AN ISSUE FOR GENERAL SUPPORT QUESTIONS.** options: - label: Yes, I have searched for similar issues on [GitHub](https://github.com/EvolutionAPI/evolution-api/issues) and found none. required: true - type: textarea attributes: label: What did you do? description: | How to write a good bug report? - Respect the issue template as much as possible. - The title should be short and descriptive. - Explain the conditions that led you to report this issue: the context. - The context should lead to something, an idea or problem you are facing. - Be clear and concise. - Format your messages to help the reader focus on what matters and understand the structure of your message, use [Markdown syntax](https://help.github.com/articles/github-flavored-markdown) placeholder: Describe the problem you encountered in detail. validations: required: true - type: textarea attributes: label: What did you expect? placeholder: Describe what you expected to happen. validations: required: true - type: textarea attributes: label: What did you observe instead of what you expected? placeholder: Explain what actually happens when you follow the steps above. validations: required: true - type: textarea attributes: label: Screenshots/Videos placeholder: | If possible, add screenshots or videos that illustrate the problem. This can be extremely helpful in understanding the issue better. - type: textarea attributes: label: Which version of the API are you using? description: | Enter the version number found in the `version` property of the **package.json**. placeholder: Paste the version here. validations: required: true - type: dropdown id: select attributes: label: What is your environment? options: - Windows - Linux - Mac - Docker - Other validations: required: true - type: textarea attributes: label: Other environment specifications placeholder: 'Hardware/Software: [e.g., CPU, GPU]' validations: required: false - type: textarea attributes: label: If applicable, paste the log output description: | Please attach any logs that might be related to the issue. If the logs contain sensitive information, consider sending them privately to one of the project maintainers. placeholder: Paste the application log here. validations: required: false - type: textarea attributes: label: Additional Notes description: Include any other information you think might be useful to understand or resolve the bug. validations: required: false ================================================ FILE: .github/ISSUE_TEMPLATE/-en--feature-request.yaml ================================================ name: Feature Request description: Suggest ideas for the project. labels: - enhancement - en # Automatically assign the issue to: # assignees: DavidsonGomes body: - type: checkboxes id: terms attributes: label: Welcome! description: '**DO NOT OPEN FOR GENERAL SUPPORT QUESTIONS.**' options: - label: Yes, I have searched for similar requests on [GitHub](https://github.com/code-chat-br/whatsapp-api/issues) and found none. required: true - type: dropdown attributes: label: What type of feature? description: | How to write a good feature request? - Respect the issue template as much as possible. - The title should be short and descriptive. - Explain the conditions that led you to suggest this feature: the context. - The context should lead to something, an idea or problem you are facing. - Be clear and concise. - Format your messages to help the reader focus on what matters and understand the structure of your message, use [Markdown syntax](https://help.github.com/articles/github-flavored-markdown) options: - Integration - Functionality - Endpoint - Database adjustment - Other validations: required: true - type: textarea attributes: label: What is the motivation for the request? description: | What problem does the feature seek to solve? Clearly and in detail describe the functionality you want to be implemented. Explain how it fits into the context of the project. placeholder: Detailed description validations: required: true - type: textarea attributes: label: Usage Examples description: | Provide specific examples of how this functionality could be used. This can include scenarios or use cases where the feature would be particularly beneficial. placeholder: text - image - video - flowcharts validations: required: false - type: textarea attributes: label: How should the feature be developed? description: | Should it be inserted directly into the code? Should it be built as a different application that acts as an extension of the API? For example: a `worker`? Discuss how this new functionality could impact other parts of the project, if applicable. --- If you have ideas on how this functionality could be implemented, please share them here. This is not mandatory, but it can be helpful for the development team. placeholder: Insert feature ideas here validations: required: false - type: textarea attributes: label: Additional Notes description: Any other information you believe is relevant to your request. placeholder: Insert your observations here. validations: required: false ================================================ FILE: .github/ISSUE_TEMPLATE/-pt--reportar-bug.yaml ================================================ name: Relatório de bug description: Crie um relatório para nos ajudar a melhorar. labels: - bug - pt-br # - help wanted # Atrubuir automaticamente a issue a: # assignees: DavidsonGomes body: - type: checkboxes id: termos attributes: label: Bem-vido! description: | O rastreador de problemas é apenas para relatar bugs e solicitações de recursos. Para perguntas de suporte relacionadas ao usuário final, acesse: - [Discord](https://evolution-api.com/discord) - [Grupo do WhatsApp](https://evolution-api.com/whatsapp)
**NÃO ABRA UM PROBLEMA PARA PERGUNTAS GERAIS DE SUPORTE.** options: - label: Sim, pesquisei problemas semelhantes no [GitHub](https://github.com/EvolutionAPI/evolution-api/issues) e não encontrei nenhum. required: true - type: textarea attributes: label: O que você fez? description: | Como escrever um bom relatório de bug? - Respeite o modelo de problema tanto quanto possível. - O título deve ser curto e descritivo. - Explique as condições que o levaram a reportar este problema: o contexto. - O contexto deve levar a algo, ideia ou problema que você está enfrentando. - Seja claro e conciso. - Formate suas mensagens para ajudar o leitor a se concentrar no que importa e entender a estrutura da sua mensagem, use [sintaxe Markdown](https://help.github.com/articles/github-flavored-markdown) placeholder: Descreva detalhadamente o problema que você encontrou. validations: required: true - type: textarea attributes: label: O que você esperava? placeholder: Descreva o que você esperava que acontecesse. validations: required: true - type: textarea attributes: label: O que vc observou ao invés do que esperava? placeholder: Explique o que realmente acontece quando você segue os passos acima. validations: required: true - type: textarea attributes: label: Capturas de Tela/Vídeos placeholder: | Se possível, adicione capturas de tela ou vídeos que ilustrem o problema. Isso pode ser extremamente útil para entender melhor o problema. - type: textarea attributes: label: Qual versão da API você está usando? description: | Insira o número da sua versão que está na propriedade `version` do **package.json**. placeholder: Cole aqui a versão. validations: required: true - type: dropdown id: select attributes: label: Qual é o seu ambiente? options: - Windows - Linux - Mac - Docker - Outro validations: required: true - type: textarea attributes: label: Outras expecificações do ambiente placeholder: 'Hardware/Software: [ex: CPU, GPU]' validations: required: false - type: textarea attributes: label: Se aplicável, cole a saída do log description: | Por favor, anexe os logs que possam estar relacionados ao problema. Se os logs contiverem informações sensíveis, considere enviá-los de forma privada para um dos mantenedores do projeto. placeholder: Cole aqui o log da aplicação validations: required: false - type: textarea attributes: label: Notas Adicionais description: Inclua aqui qualquer outra informação que você ache que possa ser útil para entender ou resolver o bug. validations: required: false ================================================ FILE: .github/ISSUE_TEMPLATE/-pt--solicitar-recurso.yaml ================================================ name: Solicitação de recursos description: Sugira ideias para o projeto. labels: - enhancement - pt-br # Automatically assign the issue to: # assignees: DavidsonGomes body: - type: checkboxes id: termos attributes: label: Bem-vindo! description: '**NÃO ABRA PARA PERGUNTAS GERAIS DE SUPORTE.**' options: - label: Sim, pesquisei solicitações semelhantes no [GitHub](https://github.com/code-chat-br/whatsapp-api/issues) e não encontrei nenhum. required: true - type: dropdown attributes: label: Qual tipo de recurso? description: | Como escrever uma boa solicitação de bug? - Respeite o modelo de problema tanto quanto possível. - O título deve ser curto e descritivo. - Explique as condições que o levaram a reportar este problema: o contexto. - O contexto deve levar a algo, ideia ou problema que você está enfrentando. - Seja claro e conciso. - Formate suas mensagens para ajudar o leitor a se concentrar no que importa e entender a estrutura da sua mensagem, use [sintaxe Markdown](https://help.github.com/articles/github-flavored-markdown) options: - Integração - Funcionalidade - Endpoint - Ajuste de banco de dados - Outro validations: required: true - type: textarea attributes: label: Qual a motivação para a solicitação? description: | Qual problema o recurso busca resolver? Descreva claramente e em detalhes a funcionalidade que você deseja que seja implementada. Explique como isso se encaixa no contexto do projeto. placeholder: Descrição detalhada validations: required: true - type: textarea attributes: label: Exemplos de Uso description: | Forneça exemplos específicos de como essa funcionalidade poderia ser utilizada. Isso pode incluir cenários ou casos de uso onde a funcionalidade seria particularmente benéfica. placeholder: texto - imagem - video - fluxogramas validations: required: false - type: textarea attributes: label: Como o recurso deve ser desenvolvido? description: | Deve ser inserido diretamente no código? Deve ser construído uma aplicação diferente que atuará como uma extenção da api? Por exemplo: um `worker`? Discuta como essa nova funcionalidade poderia impactar outras partes do projeto, se aplicável. --- Se você tem ideias sobre como essa funcionalidade pode ser implementada, por favor, compartilhe-as aqui. Isso não é obrigatório, mas pode ser útil para a equipe de desenvolvimento. placeholder: Insira ideias para o recurso validations: required: false - type: textarea attributes: label: Notas Adicionais description: Qualquer outra informação que você acredita ser relevante para a sua solicitação. placeholder: Insira aqui as sua observções. validations: required: false ================================================ FILE: .github/ISSUE_TEMPLATE/bug_report.yml ================================================ name: 🐛 Bug Report description: Report a bug or unexpected behavior title: "[BUG] " labels: ["bug", "needs-triage"] assignees: [] body: - type: markdown attributes: value: | Thanks for taking the time to fill out this bug report! Please search existing issues before creating a new one. - type: textarea id: description attributes: label: 📋 Bug Description description: A clear and concise description of what the bug is. placeholder: Describe the bug... validations: required: true - type: textarea id: reproduction attributes: label: 🔄 Steps to Reproduce description: Steps to reproduce the behavior placeholder: | 1. Go to '...' 2. Click on '....' 3. Scroll down to '....' 4. See error validations: required: true - type: textarea id: expected attributes: label: ✅ Expected Behavior description: A clear and concise description of what you expected to happen. placeholder: What should happen? validations: required: true - type: textarea id: actual attributes: label: ❌ Actual Behavior description: A clear and concise description of what actually happened. placeholder: What actually happened? validations: required: true - type: textarea id: environment attributes: label: 🌍 Environment description: Please provide information about your environment value: | - OS: [e.g. Ubuntu 20.04, Windows 10, macOS 12.0] - Node.js version: [e.g. 18.17.0] - Evolution API version: [e.g. 2.3.7] - Database: [e.g. PostgreSQL 14, MySQL 8.0] - Connection type: [e.g. Baileys, WhatsApp Business API] validations: required: true - type: textarea id: logs attributes: label: 📋 Logs description: If applicable, add logs to help explain your problem. placeholder: Paste relevant logs here... render: shell - type: textarea id: additional attributes: label: 📝 Additional Context description: Add any other context about the problem here. placeholder: Any additional information... ================================================ FILE: .github/ISSUE_TEMPLATE/feature_request.yml ================================================ name: ✨ Feature Request description: Suggest a new feature or enhancement title: "[FEATURE] " labels: ["enhancement", "needs-triage"] assignees: [] body: - type: markdown attributes: value: | Thanks for suggesting a new feature! Please check our [Feature Requests on Canny](https://evolutionapi.canny.io/feature-requests) first. - type: textarea id: problem attributes: label: 🎯 Problem Statement description: Is your feature request related to a problem? Please describe. placeholder: A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] validations: required: true - type: textarea id: solution attributes: label: 💡 Proposed Solution description: Describe the solution you'd like placeholder: A clear and concise description of what you want to happen. validations: required: true - type: textarea id: alternatives attributes: label: 🔄 Alternatives Considered description: Describe alternatives you've considered placeholder: A clear and concise description of any alternative solutions or features you've considered. - type: dropdown id: priority attributes: label: 📊 Priority description: How important is this feature to you? options: - Low - Nice to have - Medium - Would be helpful - High - Important for my use case - Critical - Blocking my work validations: required: true - type: dropdown id: component attributes: label: 🧩 Component description: Which component does this feature relate to? options: - WhatsApp Integration (Baileys) - WhatsApp Business API - Chatwoot Integration - Typebot Integration - OpenAI Integration - Dify Integration - API Endpoints - Database - Authentication - Webhooks - File Storage - Other - type: textarea id: use_case attributes: label: 🎯 Use Case description: Describe your specific use case for this feature placeholder: How would you use this feature? What problem does it solve for you? validations: required: true - type: textarea id: additional attributes: label: 📝 Additional Context description: Add any other context, screenshots, or examples about the feature request here. placeholder: Any additional information, mockups, or examples... ================================================ FILE: .github/pull_request_template.md ================================================ ## 📋 Description ## 🔗 Related Issue Closes #(issue_number) ## 🧪 Type of Change - [ ] 🐛 Bug fix (non-breaking change which fixes an issue) - [ ] ✨ New feature (non-breaking change which adds functionality) - [ ] 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] 📚 Documentation update - [ ] 🔧 Refactoring (no functional changes) - [ ] ⚡ Performance improvement - [ ] 🧹 Code cleanup - [ ] 🔒 Security fix ## 🧪 Testing - [ ] Manual testing completed - [ ] Functionality verified in development environment - [ ] No breaking changes introduced - [ ] Tested with different connection types (if applicable) ## 📸 Screenshots (if applicable) ## ✅ Checklist - [ ] My code follows the project's style guidelines - [ ] I have performed a self-review of my code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have manually tested my changes thoroughly - [ ] I have verified the changes work with different scenarios - [ ] Any dependent changes have been merged and published ## 📝 Additional Notes ================================================ FILE: .github/workflows/check_code_quality.yml ================================================ name: Check Code Quality on: pull_request: branches: [ main, develop ] push: branches: [ main, develop ] jobs: check-lint-and-build: runs-on: ubuntu-latest timeout-minutes: 10 steps: - uses: actions/checkout@v5 with: submodules: recursive - name: Install Node uses: actions/setup-node@v5 with: node-version: 20.x - name: Cache node modules uses: actions/cache@v4 with: path: ~/.npm key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} restore-keys: | ${{ runner.os }}-node- - name: Install packages run: npm ci - name: Check linting run: npm run lint:check - name: Generate Prisma client run: npm run db:generate - name: Check build run: npm run build ================================================ FILE: .github/workflows/publish_docker_image.yml ================================================ name: Build Docker image on: push: tags: - "*.*.*" jobs: build_deploy: name: Build and Deploy runs-on: ubuntu-latest permissions: contents: read packages: write steps: - name: Checkout uses: actions/checkout@v5 with: submodules: recursive - name: Docker meta id: meta uses: docker/metadata-action@v5 with: images: evoapicloud/evolution-api tags: type=semver,pattern=v{{version}} - name: Set up QEMU uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Login to GitHub Container Registry uses: docker/login-action@v3 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - name: Build and push id: docker_build uses: docker/build-push-action@v6 with: platforms: linux/amd64,linux/arm64 push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - name: Image digest run: echo ${{ steps.docker_build.outputs.digest }} ================================================ FILE: .github/workflows/publish_docker_image_homolog.yml ================================================ name: Build Docker image on: push: branches: - develop jobs: build_deploy: name: Build and Deploy runs-on: ubuntu-latest permissions: contents: read packages: write steps: - name: Checkout uses: actions/checkout@v5 with: submodules: recursive - name: Docker meta id: meta uses: docker/metadata-action@v5 with: images: evoapicloud/evolution-api tags: homolog - name: Set up QEMU uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Login to Docker Hub uses: docker/login-action@v3 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - name: Build and push id: docker_build uses: docker/build-push-action@v6 with: platforms: linux/amd64,linux/arm64 push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - name: Image digest run: echo ${{ steps.docker_build.outputs.digest }} ================================================ FILE: .github/workflows/publish_docker_image_latest.yml ================================================ name: Build Docker image on: push: branches: - main jobs: build_deploy: name: Build and Deploy runs-on: ubuntu-latest permissions: contents: read packages: write steps: - name: Checkout uses: actions/checkout@v5 with: submodules: recursive - name: Docker meta id: meta uses: docker/metadata-action@v5 with: images: evoapicloud/evolution-api tags: latest - name: Set up QEMU uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Login to Docker Hub uses: docker/login-action@v3 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - name: Build and push id: docker_build uses: docker/build-push-action@v6 with: platforms: linux/amd64,linux/arm64 push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - name: Image digest run: echo ${{ steps.docker_build.outputs.digest }} ================================================ FILE: .github/workflows/security.yml ================================================ name: Security Scan on: push: branches: [ main, develop ] pull_request: branches: [ main, develop ] schedule: - cron: '0 0 * * 1' # Weekly on Mondays jobs: codeql: name: CodeQL Analysis runs-on: ubuntu-latest timeout-minutes: 15 permissions: actions: read contents: read security-events: write strategy: fail-fast: false matrix: language: [ 'javascript' ] steps: - name: Checkout repository uses: actions/checkout@v5 with: submodules: recursive - name: Initialize CodeQL uses: github/codeql-action/init@v3 with: languages: ${{ matrix.language }} - name: Autobuild uses: github/codeql-action/autobuild@v3 - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v3 with: category: "/language:${{matrix.language}}" dependency-review: name: Dependency Review runs-on: ubuntu-latest if: github.event_name == 'pull_request' steps: - name: Checkout Repository uses: actions/checkout@v5 with: submodules: recursive - name: Dependency Review uses: actions/dependency-review-action@v4 ================================================ FILE: .gitignore ================================================ # Repo Baileys # compiled output /dist /node_modules /Docker/.env # Logs logs/**.json *.log npm-debug.log* pnpm-debug.log* yarn-debug.log* yarn-error.log* lerna-debug.log* /docker-compose-data /docker-data # Package /yarn.lock /pnpm-lock.yaml # IDEs .vscode/* !.vscode/settings.json !.vscode/tasks.json !.vscode/launch.json !.vscode/extensions.json .nova/* .idea/* # Project related /instances/* !/instances/.gitkeep /test/ /src/env.yml /store *.env /temp/* .DS_Store *.DS_Store .tool-versions /prisma/migrations/* ================================================ FILE: .gitmodules ================================================ [submodule "evolution-manager-v2"] path = evolution-manager-v2 url = https://github.com/EvolutionAPI/evolution-manager-v2.git ================================================ FILE: .husky/README.md ================================================ # Git Hooks Configuration Este projeto usa [Husky](https://typicode.github.io/husky/) para automatizar verificações de qualidade de código. ## Hooks Configurados ### Pre-commit - **Arquivo**: `.husky/pre-commit` - **Executa**: `npx lint-staged` - **Função**: Executa lint e correções automáticas apenas nos arquivos modificados ### Pre-push - **Arquivo**: `.husky/pre-push` - **Executa**: `npm run build` + `npm run lint:check` - **Função**: Verifica se o projeto compila e não tem erros de lint antes do push ## Lint-staged Configuration Configurado no `package.json`: ```json "lint-staged": { "src/**/*.{ts,js}": [ "eslint --fix", "git add" ], "src/**/*.ts": [ "npm run build" ] } ``` ## Como funciona 1. **Ao fazer commit**: Executa lint apenas nos arquivos modificados 2. **Ao fazer push**: Executa build completo e verificação de lint 3. **Se houver erros**: O commit/push é bloqueado até correção ## Comandos úteis ```bash # Pular hooks (não recomendado) git commit --no-verify git push --no-verify # Executar lint manualmente npm run lint # Executar build manualmente npm run build ``` ================================================ FILE: .husky/commit-msg ================================================ npx --no -- commitlint --edit $1 ================================================ FILE: .husky/pre-commit ================================================ npx lint-staged ================================================ FILE: .husky/pre-push ================================================ npm run build npm run lint:check ================================================ FILE: .prettierrc.js ================================================ module.exports = { semi: true, trailingComma: 'all', singleQuote: true, printWidth: 120, arrowParens: 'always', tabWidth: 2, useTabs: false, bracketSameLine: false, bracketSpacing: true, parser: 'typescript' } ================================================ FILE: .vscode/settings.json ================================================ { "editor.fontSize": 13, "editor.fontLigatures": true, "editor.letterSpacing": 0.5, "editor.smoothScrolling": true, "editor.tabSize": 2, "editor.codeActionsOnSave": { "source.fixAll.eslint": "explicit", "source.fixAll": "explicit" }, "prisma-smart-formatter.typescript.defaultFormatter": "esbenp.prettier-vscode", "prisma-smart-formatter.prisma.defaultFormatter": "Prisma.prisma", "i18n-ally.localesPaths": [ "store/messages" ] } ================================================ FILE: AGENTS.md ================================================ # Evolution API - AI Agent Guidelines This document provides comprehensive guidelines for AI agents (Claude, GPT, Cursor, etc.) working with the Evolution API codebase. ## Project Overview **Evolution API** is a production-ready, multi-tenant WhatsApp API platform built with Node.js, TypeScript, and Express.js. It supports multiple WhatsApp providers and extensive integrations with chatbots, CRM systems, and messaging platforms. ## Project Structure & Module Organization ### Core Directories - **`src/`** – TypeScript source code with modular architecture - `api/controllers/` – HTTP route handlers (thin layer) - `api/services/` – Business logic (core functionality) - `api/routes/` – Express route definitions (RouterBroker pattern) - `api/integrations/` – External service integrations - `channel/` – WhatsApp providers (Baileys, Business API, Evolution) - `chatbot/` – AI/Bot integrations (OpenAI, Dify, Typebot, Chatwoot) - `event/` – Event systems (WebSocket, RabbitMQ, SQS, NATS, Pusher) - `storage/` – File storage (S3, MinIO) - `dto/` – Data Transfer Objects (simple classes, no decorators) - `guards/` – Authentication/authorization middleware - `types/` – TypeScript type definitions - `repository/` – Data access layer (Prisma) - **`prisma/`** – Database schemas and migrations - `postgresql-schema.prisma` / `mysql-schema.prisma` – Provider-specific schemas - `postgresql-migrations/` / `mysql-migrations/` – Provider-specific migrations - **`config/`** – Environment and application configuration - **`utils/`** – Shared utilities and helper functions - **`validate/`** – JSONSchema7 validation schemas - **`exceptions/`** – Custom HTTP exception classes - **`cache/`** – Redis and local cache implementations ### Build & Deployment - **`dist/`** – Build output (do not edit directly) - **`public/`** – Static assets and media files - **`Docker*`**, **`docker-compose*.yaml`** – Containerization and local development stack ## Build, Test, and Development Commands ### Development Workflow ```bash # Development server with hot reload npm run dev:server # Direct execution for testing npm start # Production build and run npm run build npm run start:prod ``` ### Code Quality ```bash # Linting and formatting npm run lint # ESLint with auto-fix npm run lint:check # ESLint check only # Commit with conventional commits npm run commit # Interactive commit with Commitizen ``` ### Database Management ```bash # Set database provider first (CRITICAL) export DATABASE_PROVIDER=postgresql # or mysql # Generate Prisma client npm run db:generate # Development migrations (with provider sync) npm run db:migrate:dev # Unix/Mac npm run db:migrate:dev:win # Windows # Production deployment npm run db:deploy # Unix/Mac npm run db:deploy:win # Windows # Database tools npm run db:studio # Open Prisma Studio ``` ### Docker Development ```bash # Start local services (Redis, PostgreSQL, etc.) docker-compose up -d # Full development stack docker-compose -f docker-compose.dev.yaml up -d ``` ## Coding Standards & Architecture Patterns ### Code Style (Enforced by ESLint + Prettier) - **TypeScript strict mode** with full type coverage - **2-space indentation**, single quotes, trailing commas - **120-character line limit** - **Import order** via `simple-import-sort` - **File naming**: `feature.kind.ts` (e.g., `whatsapp.baileys.service.ts`) - **Naming conventions**: - Classes: `PascalCase` - Functions/variables: `camelCase` - Constants: `UPPER_SNAKE_CASE` - Files: `kebab-case.type.ts` ### Architecture Patterns #### Service Layer Pattern ```typescript export class ExampleService { constructor(private readonly waMonitor: WAMonitoringService) {} private readonly logger = new Logger('ExampleService'); public async create(instance: InstanceDto, data: ExampleDto) { // Business logic here return { example: { ...instance, data } }; } public async find(instance: InstanceDto): Promise { try { const result = await this.waMonitor.waInstances[instance.instanceName].findData(); return result || null; // Return null on not found (Evolution pattern) } catch (error) { this.logger.error('Error finding data:', error); return null; // Return null on error (Evolution pattern) } } } ``` #### Controller Pattern (Thin Layer) ```typescript export class ExampleController { constructor(private readonly exampleService: ExampleService) {} public async createExample(instance: InstanceDto, data: ExampleDto) { return this.exampleService.create(instance, data); } } ``` #### RouterBroker Pattern ```typescript export class ExampleRouter extends RouterBroker { constructor(...guards: any[]) { super(); this.router.post(this.routerPath('create'), ...guards, async (req, res) => { const response = await this.dataValidate({ request: req, schema: exampleSchema, // JSONSchema7 ClassRef: ExampleDto, execute: (instance, data) => controller.createExample(instance, data), }); res.status(201).json(response); }); } } ``` #### DTO Pattern (Simple Classes) ```typescript // CORRECT - Evolution API pattern (no decorators) export class ExampleDto { name: string; description?: string; enabled: boolean; } // INCORRECT - Don't use class-validator decorators export class BadExampleDto { @IsString() // ❌ Evolution API doesn't use decorators name: string; } ``` #### Validation Pattern (JSONSchema7) ```typescript import { JSONSchema7 } from 'json-schema'; import { v4 } from 'uuid'; export const exampleSchema: JSONSchema7 = { $id: v4(), type: 'object', properties: { name: { type: 'string' }, description: { type: 'string' }, enabled: { type: 'boolean' }, }, required: ['name', 'enabled'], }; ``` ## Multi-Tenant Architecture ### Instance Isolation - **CRITICAL**: All operations must be scoped by `instanceName` or `instanceId` - **Database queries**: Always include `where: { instanceId: ... }` - **Authentication**: Validate instance ownership before operations - **Data isolation**: Complete separation between tenant instances ### WhatsApp Instance Management ```typescript // Access instance via WAMonitoringService const waInstance = this.waMonitor.waInstances[instance.instanceName]; if (!waInstance) { throw new NotFoundException(`Instance ${instance.instanceName} not found`); } ``` ## Database Patterns ### Multi-Provider Support - **PostgreSQL**: Uses `@db.Integer`, `@db.JsonB`, `@default(now())` - **MySQL**: Uses `@db.Int`, `@db.Json`, `@default(now())` - **Environment**: Set `DATABASE_PROVIDER=postgresql` or `mysql` - **Migrations**: Provider-specific folders auto-selected ### Prisma Repository Pattern ```typescript // Always use PrismaRepository for database operations const result = await this.prismaRepository.instance.findUnique({ where: { name: instanceName }, }); ``` ## Integration Patterns ### Channel Integration (WhatsApp Providers) - **Baileys**: WhatsApp Web with QR code authentication - **Business API**: Official Meta WhatsApp Business API - **Evolution API**: Custom WhatsApp integration - **Pattern**: Extend base channel service classes ### Chatbot Integration - **Base classes**: Extend `BaseChatbotService` and `BaseChatbotController` - **Trigger system**: Support keyword, regex, and advanced triggers - **Session management**: Handle conversation state per user - **Available integrations**: EvolutionBot, OpenAI, Dify, Typebot, Chatwoot, Flowise, N8N, EvoAI ### Event Integration - **Internal events**: EventEmitter2 for application events - **External events**: WebSocket, RabbitMQ, SQS, NATS, Pusher - **Webhook delivery**: Reliable delivery with retry logic ## Testing Guidelines ### Current State - **No formal test suite** currently implemented - **Manual testing** is the primary approach - **Integration testing** in development environment ### Testing Strategy ```typescript // Place tests in test/ directory as *.test.ts // Run: npm test (watches test/all.test.ts) describe('ExampleService', () => { it('should create example', async () => { // Mock external dependencies // Test business logic // Assert expected behavior }); }); ``` ### Recommended Approach - Focus on **critical business logic** in services - **Mock external dependencies** (WhatsApp APIs, databases) - **Integration tests** for API endpoints - **Manual testing** for WhatsApp connection flows ## Commit & Pull Request Guidelines ### Conventional Commits (Enforced by commitlint) ```bash # Use interactive commit tool npm run commit # Commit format: type(scope): subject (max 100 chars) # Types: feat, fix, docs, style, refactor, perf, test, chore, ci, build, revert, security ``` ### Examples - `feat(api): add WhatsApp message status endpoint` - `fix(baileys): resolve connection timeout issue` - `docs(readme): update installation instructions` - `refactor(service): extract common message validation logic` ### Pull Request Requirements - **Clear description** of changes and motivation - **Linked issues** if applicable - **Migration impact** (specify database provider) - **Local testing steps** with screenshots/logs - **Breaking changes** clearly documented ## Security & Configuration ### Environment Setup ```bash # Copy example environment file cp .env.example .env # NEVER commit secrets to version control # Set DATABASE_PROVIDER before database commands export DATABASE_PROVIDER=postgresql # or mysql ``` ### Security Best Practices - **API key authentication** via `apikey` header - **Input validation** with JSONSchema7 - **Rate limiting** on all endpoints - **Webhook signature validation** - **Instance-based access control** - **Secure defaults** for all configurations ### Vulnerability Reporting - See `SECURITY.md` for security vulnerability reporting process - Contact: `contato@evolution-api.com` ## Communication Standards ### Language Requirements - **User communication**: Always respond in Portuguese (PT-BR) - **Code/comments**: English for technical documentation - **API responses**: English for consistency - **Error messages**: Portuguese for user-facing errors ### Documentation Standards - **Inline comments**: Document complex business logic - **API documentation**: Document all public endpoints - **Integration guides**: Document new integration patterns - **Migration guides**: Document database schema changes ## Performance & Scalability ### Caching Strategy - **Redis primary**: Distributed caching for production - **Node-cache fallback**: Local caching when Redis unavailable - **TTL strategy**: Appropriate cache expiration per data type - **Cache invalidation**: Proper invalidation on data changes ### Connection Management - **Database**: Prisma connection pooling - **WhatsApp**: One connection per instance with lifecycle management - **Redis**: Connection pooling and retry logic - **External APIs**: Rate limiting and retry with exponential backoff ### Monitoring & Observability - **Structured logging**: Pino logger with correlation IDs - **Error tracking**: Comprehensive error scenarios - **Health checks**: Instance status and connection monitoring - **Telemetry**: Usage analytics (non-sensitive data only) ================================================ FILE: CHANGELOG.md ================================================ # 2.3.7 (2025-12-05) ### Features * **WhatsApp Business Meta Templates**: Add update and delete endpoints for Meta templates - New endpoints to edit and delete WhatsApp Business templates - Added DTOs and validation schemas for template management - Enhanced template lifecycle management capabilities * **Events API**: Add isLatest and progress to messages.set event - Allows consumers to know when history sync is complete (isLatest=true) - Track sync progress percentage through webhooks - Added extra field to EmitData type for additional payload properties - Updated all event controllers (webhook, rabbitmq, sqs, websocket, pusher, kafka, nats) * **N8N Integration**: Add quotedMessage to payload in sendMessageToBot - Support for quoted messages in N8N chatbot integration - Enhanced message context information * **WebSocket**: Add wildcard "*" to allow all hosts to connect via websocket - More flexible host configuration for WebSocket connections - Improved host validation logic in WebsocketController * **Pix Support**: Handle interactive button message for pix - Support for interactive Pix button messages - Enhanced payment flow integration ### Fixed * **Baileys Message Processor**: Fix incoming message events not working after reconnection - Added cleanup logic in mount() to prevent memory leaks from multiple subscriptions - Recreate messageSubject if it was completed during logout - Remount messageProcessor in connectToWhatsapp() to ensure subscription is active - Fixed issue where onDestroy() calls complete() on RxJS Subject, making it permanently closed - Ensures old subscriptions are properly cleaned up before creating new ones * **Baileys Authentication**: Resolve "waiting for message" state after reconnection - Fixed Redis keys not being properly removed during instance logout - Prevented loading of old/invalid cryptographic keys on reconnection - Fixed blocking state where instances authenticate but cannot send messages - Ensures new credentials (creds) are properly used after reconnection * **OnWhatsapp Cache**: Prevent unique constraint errors and optimize database writes - Fixed `Unique constraint failed on the fields: (remoteJid)` error when sending to groups - Refactored query to use OR condition finding by jidOptions or remoteJid - Added deep comparison to skip unnecessary database updates - Replaced sequential processing with Promise.allSettled for parallel execution - Sorted JIDs alphabetically in jidOptions for accurate change detection - Added normalizeJid helper function for cleaner code * **Proxy Integration**: Fix "Media upload failed on all hosts" error when using proxy - Created makeProxyAgentUndici() for Undici-compatible proxy agents - Fixed compatibility with Node.js 18+ native fetch() implementation - Replaced traditional HttpsProxyAgent/SocksProxyAgent with Undici ProxyAgent - Maintained legacy makeProxyAgent() for Axios compatibility - Fixed protocol handling in makeProxyAgent to prevent undefined errors * **WhatsApp Business API**: Fix base64, filename and caption handling - Corrected base64 media conversion in Business API - Fixed filename handling for document messages - Improved caption processing for media messages - Enhanced remoteJid validation and processing * **Chat Service**: Fix fetchChats and message panel errors - Fixed cleanMessageData errors in Manager message panel - Improved chat fetching reliability - Enhanced message data sanitization * **Contact Filtering**: Apply where filters correctly in findContacts endpoint - Fixed endpoint to process all where clause fields (id, remoteJid, pushName) - Previously only processed remoteJid field, ignoring other filters - Added remoteJid field to contactValidateSchema for proper validation - Maintained multi-tenant isolation with instanceId filtering - Allows filtering contacts by any supported field instead of returning all contacts * **Chatwoot and Baileys Integration**: Multiple integration improvements - Enhanced code formatting and consistency - Fixed integration issues between Chatwoot and Baileys services - Improved message handling and delivery * **Baileys Message Loss**: Prevent message loss from WhatsApp stub placeholders - Fixed messages being lost and not saved to database, especially for channels/newsletters (@lid) - Detects WhatsApp stubs through messageStubParameters containing 'Message absent from node' - Prevents adding stubs to duplicate message cache - Allows real message to be processed when it arrives after decryption - Maintains stub discard to avoid saving empty placeholders * **Database Contacts**: Respect DATABASE_SAVE_DATA_CONTACTS in contact updates - Added missing conditional checks for DATABASE_SAVE_DATA_CONTACTS configuration - Fixed profile picture updates attempting to save when database save is disabled - Fixed unawaited promise in contacts.upsert handler * **Prisma/PostgreSQL**: Add unique constraint to Chat model - Generated migration to add unique index on instanceId and remoteJid - Added deduplication step before creating index to prevent constraint violations - Prevents chat duplication in database * **MinIO Upload**: Handle messageContextInfo in media upload to prevent MinIO errors - Prevents errors when uploading media with messageContextInfo metadata - Improved error handling for media storage operations * **Typebot**: Fix message routing for @lid JIDs - Typebot now responds to messages from JIDs ending with @lid - Maintains complete JID for @lid instead of extracting only number - Fixed condition: `remoteJid.includes('@lid') ? remoteJid : remoteJid.split('@')[0]` - Handles both @s.whatsapp.net and @lid message formats * **Message Filtering**: Unify remoteJid filtering using OR with remoteJidAlt - Improved message filtering with alternative JID support - Better handling of messages with different JID formats * **@lid Integration**: Multiple fixes for @lid problems, message events and chatwoot errors - Reorganized imports and improved message handling in BaileysStartupService - Enhanced remoteJid processing to handle @lid cases - Improved jid normalization and type safety in Chatwoot integration - Streamlined message handling logic and cache management - Refactored message handling and polling updates with decryption logic for poll votes - Improved event processing flow for various message types * **Chatwoot Contacts**: Fix contact duplication error on import - Resolved 'ON CONFLICT DO UPDATE command cannot affect row a second time' error - Removed attempt to update identifier field in conflict (part of constraint) - Changed to update only updated_at field: `updated_at = NOW()` - Allows duplicate contacts to be updated correctly without errors * **Chatwoot Service**: Fix async handling in update_last_seen method - Added missing await for chatwootRequest in read message processing - Prevents service failure when processing read messages * **Metrics Access**: Fix IP validation including x-forwarded-for - Uses all IPs including x-forwarded-for header when checking metrics access - Improved security and access control for metrics endpoint ### Dependencies * **Baileys**: Updated to version 7.0.0-rc.9 - Latest release candidate with multiple improvements and bug fixes * **AWS SDK**: Updated packages to version 3.936.0 - Enhanced functionality and compatibility - Performance improvements ### Code Quality & Refactoring * **Template Management**: Remove unused template edit/delete DTOs after refactoring * **Proxy Utilities**: Improve makeProxyAgent for Undici compatibility * **Code Formatting**: Enhance code formatting and consistency across services * **BaileysStartupService**: Fix indentation and remove unnecessary blank lines * **Event Controllers**: Guard extra spread and prevent core field override in all event controllers * **Import Organization**: Reorganize imports for better code structure and maintainability # 2.3.6 (2025-10-21) ### Features * **Baileys, Chatwoot, OnWhatsapp Cache**: Multiple implementations and fixes - Fixed cache for PN, LID and g.us numbers to send correct number - Fixed audio and document sending via Chatwoot in Baileys channel - Multiple fixes in Chatwoot integration - Fixed ignored messages when receiving leads ### Fixed * **Baileys**: Fix buffer storage in database - Correctly save Uint8Array values to database * **Baileys**: Simplify logging of messageSent object - Fixed "this.isZero not is function" error ### Chore * **Version**: Bump version to 2.3.6 and update Baileys dependency to 7.0.0-rc.6 * **Workflows**: Update checkout step to include submodules - Added 'submodules: recursive' option to checkout step in multiple workflow files to ensure submodules are properly initialized during CI/CD processes * **Manager**: Update asset files and install process - Updated subproject reference in evolution-manager-v2 to the latest commit - Enhanced the manager_install.sh script to include npm install and build steps - Replaced old JavaScript asset file with a new version for improved performance - Added a new CSS file for consistent styling across the application # 2.3.5 (2025-10-15) ### Features * **Chatwoot Enhancements**: Comprehensive improvements to message handling, editing, deletion and i18n * **Participants Data**: Add participantsData field maintaining backward compatibility for group participants * **LID to Phone Number**: Convert LID to phoneNumber on group participants * **Docker Configurations**: Add Kafka and frontend services to Docker configurations ### Fixed * **Kafka Migration**: Fixed PostgreSQL migration error for Kafka integration - Corrected table reference from `"public"."Instance"` to `"Instance"` in foreign key constraint - Fixed `ERROR: relation "public.Instance" does not exist` issue in migration `20250918182355_add_kafka_integration` - Aligned table naming convention with other Evolution API migrations for consistency - Resolved database migration failure that prevented Kafka integration setup * **Update Baileys Version**: v7.0.0-rc.5 with compatibility fixes - Fixed assertSessions signature compatibility using type assertion - Fixed incompatibility in voice call (wavoip) with new Baileys version - Handle undefined status in update by defaulting to 'DELETED' * **Chatwoot Improvements**: Multiple fixes for enhanced reliability - Correct chatId extraction for non-group JIDs - Resolve webhook timeout on deletion with 5+ images - Improve error handling in Chatwoot messages - Adjust conversation verification logic and cache - Optimize conversation reopening logic and connection notification - Fix conversation reopening and connection loop * **Baileys Message Handling**: Enhanced message processing - Add warning log for messages not found - Fix message verification in Baileys service - Simplify linkPreview handling in BaileysStartupService * **Media Validation**: Fix media content validation * **PostgreSQL Connection**: Refactor connection with PostgreSQL and improve message handling ### Code Quality & Refactoring * **Exponential Backoff**: Implement exponential backoff patterns and extract magic numbers to constants * **TypeScript Build**: Update TypeScript build process and dependencies ### # 2.3.4 (2025-09-23) ### Features * **Kafka Integration**: Added Apache Kafka event integration for real-time event streaming - New Kafka controller, router, and schema for event publishing - Support for instance-specific and global event topics - Configurable SASL/SSL authentication and connection settings - Auto-creation of topics with configurable partitions and replication - Consumer group management for reliable event processing - Integration with existing event manager for seamless event distribution * **Evolution Manager v2 Open Source**: Evolution Manager v2 is now available as open source - Added as git submodule with HTTPS URL for easy access - Complete open source setup with Apache 2.0 license + Evolution API custom conditions - GitHub templates for issues, pull requests, and workflows - Comprehensive documentation and contribution guidelines - Docker support for development and production environments - CI/CD workflows for code quality, security audits, and automated builds - Multi-language support (English, Portuguese, Spanish, French) - Modern React + TypeScript + Vite frontend with Tailwind CSS * **EvolutionBot Enhancements**: Improved EvolutionBot functionality and message handling - Implemented splitMessages functionality for better message segmentation - Added linkPreview support for enhanced message presentation - Centralized split logic across chatbot services for consistency - Enhanced message formatting and delivery capabilities ### Fixed * **MySQL Schema**: Fixed invalid default value errors for `createdAt` fields in `Evoai` and `EvoaiSetting` models - Changed `@default(now())` to `@default(dbgenerated("CURRENT_TIMESTAMP"))` for MySQL compatibility - Added missing relation fields (`N8n`, `N8nSetting`, `Evoai`, `EvoaiSetting`) in Instance model - Resolved Prisma schema validation errors for MySQL provider * **Prisma Schema Validation**: Fixed `instanceName` field error in message creation - Removed invalid `instanceName` field from message objects before database insertion - Resolved `Unknown argument 'instanceName'` Prisma validation error - Streamlined message data structure to match Prisma schema requirements * **Media Message Processing**: Enhanced media handling across chatbot services - Fixed base64 conversion in EvoAI service for proper image processing - Converted ArrayBuffer to base64 string using `Buffer.from().toString('base64')` - Improved media URL handling and base64 encoding for better chatbot integration - Enhanced image message detection and processing workflow * **Evolution Manager v2 Linting**: Resolved ESLint configuration conflicts - Disabled conflicting Prettier rules in ESLint configuration - Added comprehensive rule overrides for TypeScript and React patterns - Fixed import ordering and code formatting issues - Updated security vulnerabilities in dependencies (Vite, esbuild) ### Code Quality & Refactoring * **Chatbot Services**: Streamlined media message handling across all chatbot integrations - Standardized base64 and mediaUrl processing patterns - Improved code readability and maintainability in media handling logic - Enhanced error handling for media download and conversion processes - Unified image message detection across different chatbot services * **Database Operations**: Improved data consistency and validation - Enhanced Prisma schema compliance across all message operations - Removed redundant instance name references for better data integrity - Optimized message creation workflow with proper field validation ### Environment Variables * Added comprehensive Kafka configuration options: - `KAFKA_ENABLED`, `KAFKA_CLIENT_ID`, `KAFKA_BROKERS` - `KAFKA_CONSUMER_GROUP_ID`, `KAFKA_TOPIC_PREFIX` - `KAFKA_SASL_*` and `KAFKA_SSL_*` for authentication - `KAFKA_EVENTS_*` for event type configuration # 2.3.3 (2025-09-18) ### Features * Add extra fields to object sent to Flowise bot * Add Prometheus-compatible /metrics endpoint (gated by PROMETHEUS_METRICS) * Implement linkPreview support for Evolution Bot ### Fixed * Address Path Traversal vulnerability in /assets endpoint by implementing security checks * Configure Husky and lint-staged for automated code quality checks on commits and pushes * Convert mediaKey from media messages to avoid bad decrypt errors * Improve code formatting for better readability in WhatsApp service files * Format messageGroupId assignment for improved readability * Improve linkPreview implementation based on PR feedback * Clean up code formatting for linkPreview implementation * Use 'unknown' as fallback for clientName label * Remove abort process when status is paused, allowing the chatbot return after the time expires and after being paused due to human interaction (stopBotFromMe) * Enhance message content sanitization in Baileys service and improve message retrieval logic in Chatwoot service * Integrate Typebot status change events for webhook in chatbot controller and service * Mimetype of videos video ### Security * **CRITICAL**: Fixed Path Traversal vulnerability in /assets endpoint that allowed unauthenticated local file read * Customizable Websockets Security ### Testing * Baileys Updates: v7.0.0-rc.3 ([Link](https://github.com/WhiskeySockets/Baileys/releases/tag/v7.0.0-rc.3)) # 2.3.2 (2025-09-02) ### Features * Add support to socks proxy ### Fixed * Added key id into webhook payload in n8n service * Enhance RabbitMQ controller with improved connection management and shutdown procedures * Convert outgoing images to JPEG before sending with Chatwoot * Update baileys dependency to version 6.7.19 # 2.3.1 (2025-07-29) ### Feature * Add BaileysMessageProcessor for improved message handling and integrate rxjs for asynchronous processing * Enhance message processing with retry logic for error handling ### Fixed * Update Baileys Version * Update Dockerhub Repository and Delete Config Session Variable * Fixed sending variables in typebot * Add unreadMessages in the response * Phone number as message ID for Evo AI * Fix upload to s3 when media message * Simplify edited message check in BaileysStartupService * Avoid corrupting URLs with query strings * Removed CONFIG_SESSION_PHONE_VERSION environment variable # 2.3.0 (2025-06-17 09:19) ### Feature * Add support to get Catalogs and Collections with new routes: '{{baseUrl}}/chat/fetchCatalogs' and '{{baseUrl}}/chat/fetchCollections' * Add NATS integration support to the event system * Add message location support meta * Add S3_SKIP_POLICY env variable to disable setBucketPolicy for incompatible providers * Add EvoAI integration with models, services, and routes * Add N8n integration with models, services, and routes ### Fixed * Shell injection vulnerability * Update Baileys Version v6.7.18 * Audio send duplicate from chatwoot * Chatwoot csat creating new conversation in another language * Refactor SQS controller to correct bug in sqs events by instance * Adjustin cloud api send audio and video * Preserve animation in GIF and WebP stickers * Preventing use conversation from other inbox for the same user * Ensure full WhatsApp compatibility for audio conversion (libopus, 48kHz, mono) * Enhance message fetching and processing logic * Added lid on whatsapp numbers router * Now if the CONFIG_SESSION_PHONE_VERSION variable is not filled in it automatically searches for the most updated version ### Security * Change execSync to execFileSync * Enhance WebSocket authentication and connection handling # 2.2.3 (2025-02-03 11:52) ### Fixed * Fix cache in local file system * Update Baileys Version # 2.2.2 (2025-01-31 06:55) ### Features * Added prefix key to queue name in RabbitMQ ### Fixed * Update Baileys Version # 2.2.1 (2025-01-22 14:37) ### Features * Retry system for send webhooks * Message filtering to support timestamp range queries * Chats filtering to support timestamp range queries ### Fixed * Correction of webhook global * Fixed send audio with whatsapp cloud api * Refactor on fetch chats * Refactor on Evolution Channel # 2.2.0 (2024-10-18 10:00) ### Features * Fake Call function * Send List with Baileys * Send Buttons with Baileys * Added unreadMessages to chats * Pusher event integration * Add support for splitMessages and timePerChar in Integrations * Audio Converter via API * Send PTV messages with Baileys ### Fixed * Fixed prefilledVariables in startTypebot * Fix duplicate file upload * Mark as read from me and groups * Fetch chats query * Ads messages in chatwoot * Add indexes to improve performance in Evolution * Add logical or permanent message deletion based on env config * Add support for fetching multiple instances by key * Update instance.controller.ts to filter by instanceName * Receive template button reply message # 2.1.2 (2024-10-06 10:09) ### Features * Sync lost messages on chatwoot * Set the maximum number of listeners that can be registered for events * Now is possible send medias with form-data ### Fixed * Fetch status message * Adjusts in migrations * Update pushName in chatwoot * Validate message before sending chatwoot * Adds the message status to the return of the "prepareMessage" function * Fixed openai setting when send a message with chatwoot * Fix buildkey function in hSet and hDelete * Fix mexico number * Update baileys version * Update in Baileys version that fixes timeout when updating profile picture * Adjusts for fix timeout error on send status message * Chatwoot verbose logs * Adjusts on prisma connections * License terms updated * Fixed send message to group without no cache (local or redis) * Fixed startTypebot with startSession = true * Fixed issue of always creating a new label when saving chatwoot * Fixed getBase64FromMediaMessage with convertToMp4 * Fixed bug when send message when don't have mentionsEveryOne on payload * Does not search message without chatwoot Message Id for reply * Fixed bot fallback not working on integrations # 2.1.1 (2024-09-22 10:31) ### Features * Define a global proxy to be used if the instance does not have one * Save is on whatsapp on the database * Add headers to the instance's webhook registration * Debounce message break is now "\n" instead of white space * Single view messages are now supported in chatwoot * Chatbots can now send any type of media ### Fixed * Validate if cache exists before accessing it * Missing autoCreate chatwoot in instance create * Fixed bugs in the frontend, on the event screens * Fixed use chatwoot with evolution channel * Fix chatwoot reply quote with Cloud API * Use exchange name from .env on RabbitMQ * Fixed chatwoot screen * It is now possible to send images via the Evolution Channel * Removed "version" from docker-compose as it is obsolete (https://dev.to/ajeetraina/do-we-still-use-version-in-compose-3inp) * Fixed typebot ignoreJids being used only from default settings * Fixed Chatwoot inbox creation on save * Changed axios timeout for manager requests for 30s * Update in Baileys version that fixes timeout when updating profile picture * Fixed issue when sending links in markdown by chatbots like Dify * Fixed issue with chatbots not respecting settings # 2.1.0 (2024-08-26 15:33) ### Features * Improved layout manager * Translation in manager: English, Portuguese, Spanish and French * Evolution Bot Integration * Option to disable chatwoot bot contact with CHATWOOT_BOT_CONTACT * Added flowise integration * Added evolution channel on instance create * Change in license to Apache-2.0 * Mark All in events ### Fixed * Refactor integrations structure for modular system * Fixed dify agent integration * Update Baileys Version * Fixed proxy config in manager * Fixed send messages in groups * S3 saving media sent from me * Fixed duplication bot when use startTypebot ### Break Changes * Payloads for events changed (create Instance and set events). Check postman to understand # 2.0.10 (2024-08-16 16:23) ### Features * OpenAI send images when markdown * Dify send images when markdown * Sentry implemented ### Fixed * Fix on get profilePicture * Added S3_REGION on minio settings # 2.0.9 (2024-08-15 12:31) ### Features * Added ignoreJids in chatwoot settings * Dify now identifies images * Openai now identifies images ### Fixed * Path mapping & deps fix & bundler changed to tsup * Improve database scripts to retrieve the provider from env file * Update contacts database with unique index * Save chat name * Correction of media as attachments in chatwoot when using a Meta API Instance and not Baileys * Update Baileys version 6.7.6 * Deprecate buttons and list in new Baileys version * Changed labels to be unique on the same instance * Remove instance from redis even if using database * Unified integration session system so they don't overlap * Temporary fix for pictureUrl bug in groups * Fix on migrations # 2.0.9-rc (2024-08-09 18:00) ### Features * Added general session button in typebot, dify and openai in manager * Added compatibility with mysql through prisma ### Fixed * Import contacts with image in chatwoot * Fix conversationId when is dify agent * Fixed loading of selects in the manager * Add restart button to sessions screen * Adjustments to docker files * StopBotFromMe working with chatwoot # 2.0.8-rc (2024-08-08 20:23) ### Features * Variables passed to the input in dify * OwnerJid passed to typebot * Function for openai assistant added ### Fixed * Adjusts in telemetry # 2.0.7-rc (2024-08-03 14:04) ### Fixed * BusinessId added on create instances in manager * Adjusts in restart instance * Resolve issue with connecting to instance * Session is now individual per instance and remoteJid * Credentials verify on manager login * Added description column on typebot, dify and openai * Fixed dify agent integration # 2.0.6-rc (2024-08-02 19:23) ### Features * Get models for OpenAI ### Fixed * fetchInstances with clientName parameter * fixed update typebot, openai and dify # 2.0.5-rc (2024-08-01 18:01) ### Features * Speech to Text with Openai ### Fixed * ClientName on infos * Instance screen scroll bar in manager # 2.0.4-rc (2024-07-30 14:13) ### Features * New manager v2.0 * Dify integration ### Fixed * Update Baileys Version * Adjusts for new manager * Corrected openai trigger validation * Corrected typebot trigger validation # 2.0.3-beta (2024-07-29 09:03) ### Features * Webhook url by submitted template to send status updates * Sending template approval status webhook ### Fixed * Equations and adjustments for the new manager * Adjust TriggerType for OpenAI and Typebot integrations * Fixed Typebot start call with active session # 2.0.2-beta (2024-07-18 21:33) ### Feature * Open AI implemented ### Fixed * Fixed the function of saving or not saving data in the database * Resolve not find name * Removed DEL_TEMP_INSTANCES as it is not being used * Fixed global exchange name * Add apiKey and serverUrl to prefilledVariables in typebot service * Correction in start typebot, if it doesn't exist, create it # 2.0.1-beta (2024-07-17 17:01) ### Fixed * Resolved issue with Chatwoot not receiving messages sent by Typebot # 2.0.0-beta (2024-07-14 17:00) ### Feature * Added prisma orm, connection to postgres and mysql * Added chatwoot integration activation * Added typebot integration activation * Now you can register several typebots with triggers * Media sent to typebot now goes as a template string, example: imageMessage|MESSAGE_ID * Organization configuration and logo in chatwoot bot contact * Added debounce time for typebot messages * Tagging in chatwoot contact by instance * Add support for managing WhatsApp templates via official API * Fixes and implementation of regex and fallback in typebot * Ignore jids configuration added to typebot (will be used for both groups and contacts) * Minio and S3 integration * When S3 integration enabled, the media sent to typebot now goes as a template string, example: imageMessage|MEDIA_URL ### Fixed * Removed excessive verbose logs * Optimization in instance registration * Now in typebot we wait until the terminal block to accept the user's message, if it arrives before the block is sent, it is ignored * Correction of audio sending, now we can speed it up and have the audio wireframe * Reply with media message on Chatwoot * improvements in sending status and groups * Correction in response returns from buttons, lists and templates * EvolutionAPI/Baileys implemented ### Break changes * jwt authentication removed * Connection to mongodb removed * Standardized all request bodies to use camelCase * Change in webhook information from owner to instanceId * Changed the .env file configuration, removed the yml version and added .env to the repository root * Removed the mobile type connection with Baileys * Simplified payloads and endpoints * Improved Typebot - Now you can register several typebots - Start configuration by trigger or for all - Session search by typebot or remoteJid - KeepOpen configuration (keeps the session even when the bot ends, to run once per contact) - StopBotFromMe configuration, allows me to stop the bot if I send a chat message. * Changed the way the goal webhook is configured # 1.8.2 (2024-07-03 13:50) ### Fixed * Corretion in globall rabbitmq queue name * Improvement in the use of mongodb database for credentials * Fixed base64 in webhook for documentWithCaption * Fixed Generate pairing code # 1.8.1 (2024-06-08 21:32) ### Feature * New method of saving sessions to a file using worker, made in partnership with [codechat](https://github.com/code-chat-br/whatsapp-api) ### Fixed * Correction of variables breaking lines in typebot ### Fixed * Correction of variables breaking lines in typebot # 1.8.0 (2024-05-27 16:10) ### Feature * Now in the manager, when logging in with the client's apikey, the listing only shows the instance corresponding to the provided apikey (only with MongoDB) * New global mode for rabbitmq events * Build in docker for linux/amd64, linux/arm64 platforms ### Fixed * Correction in message formatting when generated by AI as markdown in typebot * Security fix in fetch instance with client key when not connected to mongodb # 1.7.5 (2024-05-21 08:50) ### Fixed * Add merge_brazil_contacts function to solve nine digit in brazilian numbers * Optimize ChatwootService method for updating contact * Fix swagger auth * Update aws sdk v3 * Fix getOpenConversationByContact and init queries error * Method to mark chat as unread * Added environment variable to manually select the WhatsApp web version for the baileys lib (optional) # 1.7.4 (2024-04-28 09:46) ### Fixed * Adjusts in proxy on fetchAgent * Recovering messages lost with redis cache * Log when init redis cache service * Recovering messages lost with redis cache * Chatwoot inbox name * Update Baileys version # 1.7.3 (2024-04-18 12:07) ### Fixed * Revert fix audio encoding * Recovering messages lost with redis cache * Adjusts in redis for save instances * Adjusts in proxy * Revert pull request #523 * Added instance name on logs * Added support for Spanish * Fix error: invalid operator. The allowed operators for identifier are equal_to,not_equal_to in chatwoot # 1.7.2 (2024-04-12 17:31) ### Feature * Mobile connection via sms (test) ### Fixed * Adjusts in redis * Send global event in websocket * Adjusts in proxy * Fix audio encoding * Fix conversation read on chatwoot version 3.7 * Fix when receiving/sending messages from whatsapp desktop with ephemeral messages enabled * Changed returned sessions on typebot status change * Reorganization of files and folders # 1.7.1 (2024-04-03 10:19) ### Fixed * Correction when sending files with captions on Whatsapp Business * Correction in receiving messages with response on WhatsApp Business * Correction when sending a reaction to a message on WhatsApp Business * Correction of receiving reactions on WhatsApp business * Removed mandatory description of rows from sendList * Feature to collect message type in typebot # 1.7.0 (2024-03-11 18:23) ### Feature * Added update message endpoint * Add translate capabilities to QRMessages in CW * Join in Group by Invite Code * Read messages from whatsapp in chatwoot * Add support to use use redis in cacheservice * Add support for labels * Command to clearcache from chatwoot inbox * Whatsapp Cloud API Oficial ### Fixed * Proxy configuration improvements * Correction in sending lists * Adjust in webhook_base64 * Correction in typebot text formatting * Correction in chatwoot text formatting and render list message * Only use a axios request to get file mimetype if necessary * When possible use the original file extension * When receiving a file from whatsapp, use the original filename in chatwoot if possible * Remove message ids cache in chatwoot to use chatwoot's api itself * Adjusts the quoted message, now has contextInfo in the message Raw * Collecting responses with text or numbers in Typebot * Added sendList endpoint to swagger documentation * Implemented a function to synchronize message deletions on WhatsApp, automatically reflecting in Chatwoot. * Improvement on numbers validation * Fix polls in message sending * Sending status message * Message 'connection successfully' spamming * Invalidate the conversation cache if reopen_conversation is false and the conversation was resolved * Fix looping when deleting a message in chatwoot * When receiving a file from whatsapp, use the original filename in chatwoot if possible * Correction in the sendList Function * Implement contact upsert in messaging-history.set * Improve proxy error handling * Refactor fetching participants for group in WhatsApp service * Fixed problem where the typebot final keyword did not work * Typebot's wait now pauses the flow and composing is defined by the delay_message parameter in set typebot * Composing over 20s now loops until finished # 1.6.1 (2023-12-22 11:43) ### Fixed * Fixed Lid Messages * Fixed sending variables to typebot * Fixed sending variables from typebot * Correction sending s3/minio media to chatwoot and typebot * Fixed the problem with typebot closing at the end of the flow, now this is optional with the TYPEBOT_KEEP_OPEN variable * Fixed chatwoot Bold, Italic and Underline formatting using Regex * Added the sign_delimiter property to the Chatwoot configuration, allowing you to set a different delimiter for the signature. Default when not defined \n * Include instance Id field in the instance configuration * Fixed the pairing code * Adjusts in typebot * Fix the problem when disconnecting the instance and connecting again using mongodb * Options to disable docs and manager * When deleting a message in whatsapp, delete the message in chatwoot too # 1.6.0 (2023-12-12 17:24) ### Feature * Added AWS SQS Integration * Added support for new typebot API * Added endpoint sendPresence * New Instance Manager * Added auto_create to the chatwoot set to create the inbox automatically or not * Added reply, delete and message reaction in chatwoot v3.3.1 ### Fixed * Adjusts in proxy * Adjusts in start session for Typebot * Added mimetype field when sending media * Ajusts in validations to messages.upsert * Fixed messages not received: error handling when updating contact in chatwoot * Fix workaround to manage param data as an array in mongodb * Removed await from webhook when sending a message * Update typebot.service.ts - element.underline change ~ for * * Removed api restart on receiving an error * Fixes in mongodb and chatwoot * Adjusted return from queries in mongodb * Added restart instance when update profile picture * Correction of chatwoot functioning with admin flows * Fixed problem that did not generate qrcode with the chatwoot_conversation_pending option enabled * Fixed issue where CSAT opened a new ticket when reopen_conversation was disabled * Fixed issue sending contact to Chatwoot via iOS ### Integrations * Chatwoot: v3.3.1 * Typebot: v2.20.0 # 1.5.4 (2023-10-09 20:43) ### Fixed * Baileys logger typing issue resolved * Solved problem with duplicate messages in chatwoot # 1.5.3 (2023-10-06 18:55) ### Feature * Swagger documentation * Added base 64 sending option via webhook ### Fixed * Remove rabbitmq queues when delete instances * Improvement in restart instance to completely redo the connection * Update node version: v20 * Correction of messages sent by the api and typebot not appearing in chatwoot * Adjustment to start typebot, added startSession parameter * Chatwoot now receives messages sent via api and typebot * Fixed problem with starting with an input in typebot * Added check to ensure variables are not empty before executing foreach in start typebot # 1.5.2 (2023-09-28 17:56) ### Fixed * Fix chatwootSchema in chatwoot model to store reopen_conversation and conversation_pending options * Problem resolved when sending files from minio to typebot * Improvement in the "startTypebot" method to create persistent session when triggered * New manager for Evo 1.5.2 - Set Typebot update * Resolved problems when reading/querying instances # 1.5.1 (2023-09-17 13:50) ### Feature * Added listening_from_me option in Set Typebot * Added variables options in Start Typebot * Added webhooks for typebot events * Added ChamaAI integration * Added webhook to send errors * Added support for messaging with ads on chatwoot ### Fixed * Fix looping connection messages in chatwoot * Improved performance of fetch instances # 1.5.0 (2023-08-18 12:47) ### Feature * New instance manager in /manager route * Added extra files for chatwoot and appsmith * Added Get Last Message and Archive for Chat * Added env var QRCODE_COLOR * Added websocket to send events * Added rabbitmq to send events * Added Typebot integration * Added proxy endpoint * Added send and date_time in webhook data ### Fixed * Solved problem when disconnecting from the instance the instance was deleted * Encoded spaces in chatwoot webhook * Adjustment in the saving of contacts, saving the information of the number and Jid * Update Dockerfile * If you pass empty events in create instance and set webhook it is understood as all * Fixed issue that did not output base64 averages * Messages sent by the api now arrive in chatwoot ### Integrations * Chatwoot: v2.18.0 - v3.0.0 * Typebot: v2.16.0 * Manager Evolution API # 1.4.8 (2023-07-27 10:27) ### Fixed * Fixed error return bug # 1.4.7 (2023-07-27 08:47) ### Fixed * Fixed error return bug * Fixed problem of getting message when deleting message in chatwoot * Change in error return pattern # 1.4.6 (2023-07-26 17:54) ### Fixed * Fixed bug of creating new inbox by chatwoot * When conversation reopens is pending when conversation pending is true * Added docker-compose file with dockerhub image # 1.4.5 (2023-07-26 09:32) ### Fixed * Fixed problems in localization template in chatwoot * Fix mids going duplicated in chatwoot # 1.4.4 (2023-07-25 15:24) ### Fixed * Fixed chatwoot line wrap issue * Solved receive location in chatwoot * When requesting the pairing code, it also brings the qr code * Option reopen_conversation in chatwoot endpoint * Option conversation_pending in chatwoot endpoint # 1.4.3 (2023-07-25 10:51) ### Fixed * Adjusts in settings with options always_online, read_messages and read_status * Fixed send webhook for event CALL * Create instance with settings # 1.4.2 (2023-07-24 20:52) ### Fixed * Fixed validation is set settings * Adjusts in group validations * Ajusts in sticker message to chatwoot # 1.4.1 (2023-07-24 18:28) ### Fixed * Fixed reconnect with pairing code or qrcode * Fixed problem in createJid # 1.4.0 (2023-07-24 17:03) ### Features * Added connection functionality via pairing code * Added fetch profile endpoint in chat controller * Created settings controller * Added reject call and send text message when receiving a call * Added setting to ignore group messages * Added connection with pairing code in chatwoot with command /init:{NUMBER} * Added encoding option in endpoint sendWhatsAppAudio ### Fixed * Added link preview option in send text message * Fixed problem with fileSha256 appearing when sending a sticker in chatwoot * Fixed issue where it was not possible to open a conversation when sent at first by me on my cell phone in chatwoot * Now it only updates the contact name if it is the same as the phone number in chatwoot * Now accepts all chatwoot inbox templates * Command to create new instances set to /new_instance:{NAME}:{NUMBER} * Fix in chatwoot set, sign msg can now be disabled ### Integrations * Chatwoot: v2.18.0 - v3.0.0 (Beta) # 1.3.2 (2023-07-21 17:19) ### Fixed * Fix in update settings that needed to restart after updated * Correction in the use of the api with mongodb * Adjustments to search endpoint for contacts, chats, messages and Status messages * Now when deleting the instance, the data referring to it in mongodb is also deleted * It is now validated if the instance name contains uppercase and special characters * For compatibility reasons, container mode has been removed * Added docker-compose files example ### Integrations * Chatwoot: v2.18.0 # 1.3.1 (2023-07-20 07:48) ### Fixed * Adjust in create store files ### Integrations * Chatwoot: v2.18.0 # 1.3.0 (2023-07-19 11:33) ### Features * Added messages.delete event * Added restart instance endpoint * Created automation for creating instances in the chatwoot bot with the command '#inbox_whatsapp:{INSTANCE_NAME} * Change Baileys version to: 6.4.0 * Send contact in chatwoot * Send contact array in chatwoot * Added apiKey in webhook and serverUrl in fetchInstance if EXPOSE_IN_FETCH_INSTANCES: true * Translation set to default (english) in chatwoot ### Fixed * Fixed error to send message in large groups * Docker files adjusted * Fixed in the postman collection the webhookByEvent parameter by webhook_by_events * Added validations in create instance * Removed link preview endpoint, now it's done automatically from sending conventional text * Added group membership validation before sending message to groups * Adjusts in docker files * Adjusts in returns in endpoints chatwoot and webhook * Fixed ghost mentions in send text message * Fixed bug that saved contacts from groups came without number in chatwoot * Fixed problem to receive csat in chatwoot * Fixed require fileName for document only in base64 for send media message * Bug fix when sending mobile message change contact name to number in chatwoot * Bug fix when connecting whatsapp does not send confirmation message * Fixed quoted message with id or message directly * Adjust in validation for mexican and argentine numbers * Adjust in create store files ### Integrations * Chatwoot: v2.18.0 # 1.2.2 (2023-07-15 09:36) ### Fixed * Tweak in route "/" with version info * Adjusts chatwoot version ### Integrations * Chatwoot: v2.18.0 # 1.2.1 (2023-07-14 19:04) ### Fixed * Adjusts in docker files * Save picture url groups in chatwoot # 1.2.0 (2023-07-14 15:28) ### Features * Native integration with chatwoot * Added returning or non-returning participants option in fetchAllGroups * Added group integration to chatwoot * Added automation on create instance to chatwoot * Added verbose logs and format chatwoot service ### Fixed * Adjusts in docker-compose files * Adjusts in number validation for AR and MX numbers * Adjusts in env files, removed save old_messages * Fix when sending a message to a group I don't belong returns a bad request * Fits the format on return from the fetchAllGroups endpoint * Adjust in send document with caption from chatwoot * Fixed message with undefind in chatwoot * Changed message in path / * Test duplicate message media in groups chatwoot * Optimize send message from group with mentions * Fixed name of the profile status in fetchInstances * Fixed error 500 when logout in instance with status = close # 1.1.5 (2023-07-12 07:17) ### Fixed * Adjusts in temp folder * Return with event send_message # 1.1.4 (2023-07-08 11:01) ### Features * Route to send status broadcast * Added verbose logs * Insert allContacts in payload of endpoint sendStatus ### Fixed * Adjusted set in webhook to go empty when enabled false * Adjust in store files * Fixed the problem when do not save contacts when receive messages * Changed owner of the jid for instanceName * Create .env for installation in docker # 1.1.3 (2023-07-06 11:43) ### Features * Added configuration for Baileys log level in env * Added audio to mp4 converter in optionally get Base64 From MediaMessage * Added organization name in vcard * Added email in vcard * Added url in vcard * Added verbose logs ### Fixed * Added timestamp internally in urls to avoid caching * Correction in decryption of poll votes * Change in the way the api sent and saved the sent messages, now it goes in the messages.upsert event * Fixed cash when sending stickers via url * Improved how Redis works for instances * Fixed problem when disconnecting the instance it removes the instance * Fixed problem sending ack when preview is done by me * Adjust in store files # 1.1.2 (2023-06-28 13:43) ### Fixed * Fixed baileys version in package.json * Fixed problem that did not validate if the token passed in create instance already existed * Fixed problem that does not delete instance files in server mode # 1.1.1 (2023-06-28 10:27) ### Features * Added group invitation sending * Added webhook configuration per event in the individual instance registration ### Fixed * Adjust dockerfile variables # 1.1.0 (2023-06-21 11:17) ### Features * Improved fetch instances endpoint, now it also fetch other instances even if they are not connected * Added conversion of audios for sending recorded audio, now it is possible to send mp3 audios and not just ogg * Route to fetch all groups that the connection is part of * Route to fetch all privacy settings * Route to update the privacy settings * Route to update group subject * Route to update group description * Route to accept invite code * Added configuration of events by webhook of instances * Now the api key can be exposed in fetch instances if the EXPOSE_IN_FETCH_INSTANCES variable is set to true * Added option to generate qrcode as soon as the instance is created * The created instance token can now also be optionally defined manually in the creation endpoint * Route to send Sticker ### Fixed * Adjust dockerfile variables * tweaks in docker-compose to pass variables * Adjust the route getProfileBusiness to fetchProfileBusiness * fix error after logout and try to get status or to connect again * fix sending narrated audio on whatsapp android and ios * fixed the problem of not disabling the global webhook by the variable * Adjustment in the recording of temporary files and periodic cleaning * Fix for container mode also work only with files * Remove recording of old messages on sync # 1.0.9 (2023-06-10) ### Fixed * Adjust dockerfile variables # 1.0.8 (2023-06-09) ### Features * Added Docker compose file * Added ChangeLog file # 1.0.7 (2023-06-08) ### Features * Ghost mention * Mention in reply * Profile photo change * Profile name change * Profile status change * Sending a poll * Creation of LinkPreview if message contains URL * New webhooks system, which can be separated into a url per event * Sending the local webhook url as destination in the webhook data for webhook redirection * Startup modes, server or container * Server Mode works normally as everyone is used to * Container mode made to use one instance per container, when starting the application an instance is already created and the qrcode is generated and it starts sending webhook without having to call it manually, it only allows one instance at a time. ================================================ FILE: CLAUDE.md ================================================ # CLAUDE.md This file provides comprehensive guidance to Claude AI when working with the Evolution API codebase. ## Project Overview **Evolution API** is a powerful, production-ready REST API for WhatsApp communication that supports multiple WhatsApp providers: - **Baileys** (WhatsApp Web) - Open-source WhatsApp Web client - **Meta Business API** - Official WhatsApp Business API - **Evolution API** - Custom WhatsApp integration Built with **Node.js 20+**, **TypeScript 5+**, and **Express.js**, it provides extensive integrations with chatbots, CRM systems, and messaging platforms in a **multi-tenant architecture**. ## Common Development Commands ### Build and Run ```bash # Development npm run dev:server # Run in development with hot reload (tsx watch) # Production npm run build # TypeScript check + tsup build npm run start:prod # Run production build # Direct execution npm start # Run with tsx ``` ### Code Quality ```bash npm run lint # ESLint with auto-fix npm run lint:check # ESLint check only npm run commit # Interactive commit with commitizen ``` ### Database Management ```bash # Set database provider first export DATABASE_PROVIDER=postgresql # or mysql # Generate Prisma client (automatically uses DATABASE_PROVIDER env) npm run db:generate # Deploy migrations (production) npm run db:deploy # Unix/Mac npm run db:deploy:win # Windows # Development migrations (with sync to provider folder) npm run db:migrate:dev # Unix/Mac npm run db:migrate:dev:win # Windows # Open Prisma Studio npm run db:studio # Development migrations npm run db:migrate:dev # Unix/Mac npm run db:migrate:dev:win # Windows ``` ### Testing ```bash npm test # Run tests with watch mode ``` ## Architecture Overview ### Core Structure - **Multi-tenant SaaS**: Complete instance isolation with per-tenant authentication - **Multi-provider database**: PostgreSQL and MySQL via Prisma ORM with provider-specific schemas and migrations - **WhatsApp integrations**: Baileys, Meta Business API, and Evolution API with unified interface - **Event-driven architecture**: EventEmitter2 for internal events + WebSocket, RabbitMQ, SQS, NATS, Pusher for external events - **Microservices pattern**: Modular integrations for chatbots, storage, and external services ### Directory Layout ``` src/ ├── api/ │ ├── controllers/ # HTTP route handlers (thin layer) │ ├── services/ # Business logic (core functionality) │ ├── repository/ # Data access layer (Prisma) │ ├── dto/ # Data Transfer Objects (simple classes) │ ├── guards/ # Authentication/authorization middleware │ ├── integrations/ # External service integrations │ │ ├── channel/ # WhatsApp providers (Baileys, Business API, Evolution) │ │ ├── chatbot/ # AI/Bot integrations (OpenAI, Dify, Typebot, Chatwoot) │ │ ├── event/ # Event systems (WebSocket, RabbitMQ, SQS, NATS, Pusher) │ │ └── storage/ # File storage (S3, MinIO) │ ├── routes/ # Express route definitions (RouterBroker pattern) │ └── types/ # TypeScript type definitions ├── config/ # Environment and app configuration ├── cache/ # Redis and local cache implementations ├── exceptions/ # Custom HTTP exception classes ├── utils/ # Shared utilities and helpers └── validate/ # JSONSchema7 validation schemas ``` ### Key Integration Points **Channel Integrations** (`src/api/integrations/channel/`): - **Baileys**: WhatsApp Web client with QR code authentication - **Business API**: Official Meta WhatsApp Business API - **Evolution API**: Custom WhatsApp integration - Connection lifecycle management per instance with automatic reconnection **Chatbot Integrations** (`src/api/integrations/chatbot/`): - **EvolutionBot**: Native chatbot with trigger system - **Chatwoot**: Customer service platform integration - **Typebot**: Visual chatbot flow builder - **OpenAI**: AI capabilities including GPT and Whisper (audio transcription) - **Dify**: AI agent workflow platform - **Flowise**: LangChain visual builder - **N8N**: Workflow automation platform - **EvoAI**: Custom AI integration **Event Integrations** (`src/api/integrations/event/`): - **WebSocket**: Real-time Socket.io connections - **RabbitMQ**: Message queue for async processing - **Amazon SQS**: Cloud-based message queuing - **NATS**: High-performance messaging system - **Pusher**: Real-time push notifications **Storage Integrations** (`src/api/integrations/storage/`): - **AWS S3**: Cloud object storage - **MinIO**: Self-hosted S3-compatible storage - Media file management and URL generation ### Database Schema Management - Separate schema files: `postgresql-schema.prisma` and `mysql-schema.prisma` - Environment variable `DATABASE_PROVIDER` determines active database - Migration folders are provider-specific and auto-selected during deployment ### Authentication & Security - **API key-based authentication** via `apikey` header (global or per-instance) - **Instance-specific tokens** for WhatsApp connection authentication - **Guards system** for route protection and authorization - **Input validation** using JSONSchema7 with RouterBroker `dataValidate` - **Rate limiting** and security middleware - **Webhook signature validation** for external integrations ## Important Implementation Details ### WhatsApp Instance Management - Each WhatsApp connection is an "instance" with unique name - Instance data stored in database with connection state - Session persistence in database or file system (configurable) - Automatic reconnection handling with exponential backoff ### Message Queue Architecture - Supports RabbitMQ, Amazon SQS, and WebSocket for events - Event types: message.received, message.sent, connection.update, etc. - Configurable per instance which events to send ### Media Handling - Local storage or S3/Minio for media files - Automatic media download from WhatsApp - Media URL generation for external access - Support for audio transcription via OpenAI ### Multi-tenancy Support - Instance isolation at database level - Separate webhook configurations per instance - Independent integration settings per instance ## Environment Configuration Key environment variables are defined in `.env.example`. The system uses a strongly-typed configuration system via `src/config/env.config.ts`. Critical configurations: - `DATABASE_PROVIDER`: postgresql or mysql - `DATABASE_CONNECTION_URI`: Database connection string - `AUTHENTICATION_API_KEY`: Global API authentication - `REDIS_ENABLED`: Enable Redis cache - `RABBITMQ_ENABLED`/`SQS_ENABLED`: Message queue options ## Development Guidelines The project follows comprehensive development standards defined in `.cursor/rules/`: ### Core Principles - **Always respond in Portuguese (PT-BR)** for user communication - **Follow established architecture patterns** (Service Layer, RouterBroker, etc.) - **Robust error handling** with retry logic and graceful degradation - **Multi-database compatibility** (PostgreSQL and MySQL) - **Security-first approach** with input validation and rate limiting - **Performance optimizations** with Redis caching and connection pooling ### Code Standards - **TypeScript strict mode** with full type coverage - **JSONSchema7** for input validation (not class-validator) - **Conventional Commits** enforced by commitlint - **ESLint + Prettier** for code formatting - **Service Object pattern** for business logic - **RouterBroker pattern** for route handling with `dataValidate` ### Architecture Patterns - **Multi-tenant isolation** at database and instance level - **Event-driven communication** with EventEmitter2 - **Microservices integration** pattern for external services - **Connection pooling** and lifecycle management - **Caching strategy** with Redis primary and Node-cache fallback ## Testing Approach Currently, the project has minimal formal testing infrastructure: - **Manual testing** is the primary approach - **Integration testing** in development environment - **No unit test suite** currently implemented - Test files can be placed in `test/` directory as `*.test.ts` - Run `npm test` for watch mode development testing ### Recommended Testing Strategy - Focus on **critical business logic** in services - **Mock external dependencies** (WhatsApp APIs, databases) - **Integration tests** for API endpoints - **Manual testing** for WhatsApp connection flows ## Deployment Considerations - Docker support with `Dockerfile` and `docker-compose.yaml` - Graceful shutdown handling for connections - Health check endpoints for monitoring - Sentry integration for error tracking - Telemetry for usage analytics (non-sensitive data only) ================================================ FILE: Docker/kafka/docker-compose.yaml ================================================ version: '3.3' services: zookeeper: container_name: zookeeper image: confluentinc/cp-zookeeper:7.5.0 environment: - ZOOKEEPER_CLIENT_PORT=2181 - ZOOKEEPER_TICK_TIME=2000 - ZOOKEEPER_SYNC_LIMIT=2 volumes: - zookeeper_data:/var/lib/zookeeper/ ports: - 2181:2181 kafka: container_name: kafka image: confluentinc/cp-kafka:7.5.0 depends_on: - zookeeper environment: - KAFKA_BROKER_ID=1 - KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181 - KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT,OUTSIDE:PLAINTEXT - KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka:29092,PLAINTEXT_HOST://localhost:9092,OUTSIDE://host.docker.internal:9094 - KAFKA_INTER_BROKER_LISTENER_NAME=PLAINTEXT - KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1 - KAFKA_TRANSACTION_STATE_LOG_MIN_ISR=1 - KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR=1 - KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS=0 - KAFKA_AUTO_CREATE_TOPICS_ENABLE=true - KAFKA_LOG_RETENTION_HOURS=168 - KAFKA_LOG_SEGMENT_BYTES=1073741824 - KAFKA_LOG_RETENTION_CHECK_INTERVAL_MS=300000 - KAFKA_COMPRESSION_TYPE=gzip ports: - 29092:29092 - 9092:9092 - 9094:9094 volumes: - kafka_data:/var/lib/kafka/data volumes: zookeeper_data: kafka_data: networks: evolution-net: name: evolution-net driver: bridge ================================================ FILE: Docker/minio/docker-compose.yaml ================================================ version: '3.3' services: minio: container_name: minio image: quay.io/minio/minio networks: - evolution-net command: server /data --console-address ":9001" restart: always ports: - 5432:5432 environment: - MINIO_ROOT_USER=USER - MINIO_ROOT_PASSWORD=PASSWORD - MINIO_BROWSER_REDIRECT_URL=http:/localhost:9001 - MINIO_SERVER_URL=http://localhost:9000 volumes: - minio_data:/data expose: - 9000 - 9001 volumes: minio_data: networks: evolution-net: name: evolution-net driver: bridge ================================================ FILE: Docker/mysql/docker-compose.yaml ================================================ version: '3.3' services: mysql: container_name: mysql image: percona/percona-server:8.0 networks: - evolution-net restart: always ports: - 3306:3306 environment: - MYSQL_ROOT_PASSWORD=root - TZ=America/Bahia volumes: - mysql_data:/var/lib/mysql expose: - 3306 volumes: mysql_data: networks: evolution-net: name: evolution-net driver: bridge ================================================ FILE: Docker/postgres/docker-compose.yaml ================================================ version: '3.3' services: postgres: container_name: postgres image: postgres:15 networks: - evolution-net command: ["postgres", "-c", "max_connections=1000"] restart: always ports: - 5432:5432 environment: - POSTGRES_PASSWORD=PASSWORD volumes: - postgres_data:/var/lib/postgresql/data expose: - 5432 pgadmin: image: dpage/pgadmin4:latest networks: - evolution-net environment: - PGADMIN_DEFAULT_EMAIL=EMAIL - PGADMIN_DEFAULT_PASSWORD=PASSWORD volumes: - pgadmin_data:/var/lib/pgadmin ports: - 4000:80 links: - postgres volumes: postgres_data: pgadmin_data: networks: evolution-net: name: evolution-net driver: bridge ================================================ FILE: Docker/rabbitmq/docker-compose.yaml ================================================ version: '3.3' services: rabbitmq: container_name: rabbitmq image: rabbitmq:management environment: - RABBITMQ_ERLANG_COOKIE=33H2CdkzF5WrnJ4ud6nkUdRTKXvbCHeFjvVL71p - RABBITMQ_DEFAULT_VHOST=default - RABBITMQ_DEFAULT_USER=USER - RABBITMQ_DEFAULT_PASS=PASSWORD volumes: - rabbitmq_data:/var/lib/rabbitmq/ ports: - 5672:5672 - 15672:15672 volumes: rabbitmq_data: networks: evolution-net: name: evolution-net driver: bridge ================================================ FILE: Docker/redis/docker-compose.yaml ================================================ version: '3.3' services: redis: image: redis:latest networks: - evolution-net container_name: redis command: > redis-server --port 6379 --appendonly yes volumes: - evolution_redis:/data ports: - 6379:6379 volumes: evolution_redis: networks: evolution-net: name: evolution-net driver: bridge ================================================ FILE: Docker/scripts/deploy_database.sh ================================================ #!/bin/bash source ./Docker/scripts/env_functions.sh if [ "$DOCKER_ENV" != "true" ]; then export_env_vars fi if [[ "$DATABASE_PROVIDER" == "postgresql" || "$DATABASE_PROVIDER" == "mysql" || "$DATABASE_PROVIDER" == "psql_bouncer" ]]; then export DATABASE_URL echo "Deploying migrations for $DATABASE_PROVIDER" echo "Database URL: $DATABASE_URL" # rm -rf ./prisma/migrations # cp -r ./prisma/$DATABASE_PROVIDER-migrations ./prisma/migrations npm run db:deploy if [ $? -ne 0 ]; then echo "Migration failed" exit 1 else echo "Migration succeeded" fi npm run db:generate if [ $? -ne 0 ]; then echo "Prisma generate failed" exit 1 else echo "Prisma generate succeeded" fi else echo "Error: Database provider $DATABASE_PROVIDER invalid." exit 1 fi ================================================ FILE: Docker/scripts/env_functions.sh ================================================ export_env_vars() { if [ -f .env ]; then while IFS='=' read -r key value; do if [[ -z "$key" || "$key" =~ ^\s*# || -z "$value" ]]; then continue fi key=$(echo "$key" | tr -d '[:space:]') value=$(echo "$value" | tr -d '[:space:]') value=$(echo "$value" | tr -d "'" | tr -d "\"") export "$key=$value" done < .env else echo ".env file not found" exit 1 fi } ================================================ FILE: Docker/scripts/generate_database.sh ================================================ #!/bin/bash source ./Docker/scripts/env_functions.sh if [ "$DOCKER_ENV" != "true" ]; then export_env_vars fi if [[ "$DATABASE_PROVIDER" == "postgresql" || "$DATABASE_PROVIDER" == "mysql" || "$DATABASE_PROVIDER" == "psql_bouncer" ]]; then export DATABASE_URL echo "Generating database for $DATABASE_PROVIDER" echo "Database URL: $DATABASE_URL" npm run db:generate if [ $? -ne 0 ]; then echo "Prisma generate failed" exit 1 else echo "Prisma generate succeeded" fi else echo "Error: Database provider $DATABASE_PROVIDER invalid." exit 1 fi ================================================ FILE: Docker/swarm/evolution_api_v2.yaml ================================================ version: "3.7" services: evolution_v2: image: evoapicloud/evolution-api:v2.3.7 volumes: - evolution_instances:/evolution/instances networks: - network_public environment: - SERVER_URL=https://evo2.site.com - DEL_INSTANCE=false - DATABASE_PROVIDER=postgresql - DATABASE_CONNECTION_URI=postgresql://postgres:SENHA@postgres:5432/evolution - DATABASE_SAVE_DATA_INSTANCE=true - DATABASE_SAVE_DATA_NEW_MESSAGE=true - DATABASE_SAVE_MESSAGE_UPDATE=true - DATABASE_SAVE_DATA_CONTACTS=true - DATABASE_SAVE_DATA_CHATS=true - DATABASE_SAVE_DATA_LABELS=true - DATABASE_SAVE_DATA_HISTORIC=true - DATABASE_CONNECTION_CLIENT_NAME=evolution_v2 - RABBITMQ_ENABLED=false - RABBITMQ_URI=amqp://admin:admin@rabbitmq:5672/default - RABBITMQ_EXCHANGE_NAME=evolution_v2 - RABBITMQ_GLOBAL_ENABLED=false - RABBITMQ_EVENTS_APPLICATION_STARTUP=false - RABBITMQ_EVENTS_INSTANCE_CREATE=false - RABBITMQ_EVENTS_INSTANCE_DELETE=false - RABBITMQ_EVENTS_QRCODE_UPDATED=false - RABBITMQ_EVENTS_MESSAGES_SET=false - RABBITMQ_EVENTS_MESSAGES_UPSERT=true - RABBITMQ_EVENTS_MESSAGES_EDITED=false - RABBITMQ_EVENTS_MESSAGES_UPDATE=false - RABBITMQ_EVENTS_MESSAGES_DELETE=false - RABBITMQ_EVENTS_SEND_MESSAGE=false - RABBITMQ_EVENTS_SEND_MESSAGE_UPDATE=false - RABBITMQ_EVENTS_CONTACTS_SET=false - RABBITMQ_EVENTS_CONTACTS_UPSERT=false - RABBITMQ_EVENTS_CONTACTS_UPDATE=false - RABBITMQ_EVENTS_PRESENCE_UPDATE=false - RABBITMQ_EVENTS_CHATS_SET=false - RABBITMQ_EVENTS_CHATS_UPSERT=false - RABBITMQ_EVENTS_CHATS_UPDATE=false - RABBITMQ_EVENTS_CHATS_DELETE=false - RABBITMQ_EVENTS_GROUPS_UPSERT=false - RABBITMQ_EVENTS_GROUP_UPDATE=false - RABBITMQ_EVENTS_GROUP_PARTICIPANTS_UPDATE=false - RABBITMQ_EVENTS_CONNECTION_UPDATE=true - RABBITMQ_EVENTS_CALL=false - RABBITMQ_EVENTS_TYPEBOT_START=false - RABBITMQ_EVENTS_TYPEBOT_CHANGE_STATUS=false - SQS_ENABLED=false - SQS_ACCESS_KEY_ID= - SQS_SECRET_ACCESS_KEY= - SQS_ACCOUNT_ID= - SQS_REGION= - WEBSOCKET_ENABLED=false - WEBSOCKET_GLOBAL_EVENTS=false - WA_BUSINESS_TOKEN_WEBHOOK=evolution - WA_BUSINESS_URL=https://graph.facebook.com - WA_BUSINESS_VERSION=v20.0 - WA_BUSINESS_LANGUAGE=pt_BR - WEBHOOK_GLOBAL_URL='' - WEBHOOK_GLOBAL_ENABLED=false - WEBHOOK_GLOBAL_WEBHOOK_BY_EVENTS=false - WEBHOOK_EVENTS_APPLICATION_STARTUP=false - WEBHOOK_EVENTS_QRCODE_UPDATED=true - WEBHOOK_EVENTS_MESSAGES_SET=true - WEBHOOK_EVENTS_MESSAGES_UPSERT=true - WEBHOOK_EVENTS_MESSAGES_EDITED=true - WEBHOOK_EVENTS_MESSAGES_UPDATE=true - WEBHOOK_EVENTS_MESSAGES_DELETE=true - WEBHOOK_EVENTS_SEND_MESSAGE=true - WEBHOOK_EVENTS_SEND_MESSAGE_UPDATE=true - WEBHOOK_EVENTS_CONTACTS_SET=true - WEBHOOK_EVENTS_CONTACTS_UPSERT=true - WEBHOOK_EVENTS_CONTACTS_UPDATE=true - WEBHOOK_EVENTS_PRESENCE_UPDATE=true - WEBHOOK_EVENTS_CHATS_SET=true - WEBHOOK_EVENTS_CHATS_UPSERT=true - WEBHOOK_EVENTS_CHATS_UPDATE=true - WEBHOOK_EVENTS_CHATS_DELETE=true - WEBHOOK_EVENTS_GROUPS_UPSERT=true - WEBHOOK_EVENTS_GROUPS_UPDATE=true - WEBHOOK_EVENTS_GROUP_PARTICIPANTS_UPDATE=true - WEBHOOK_EVENTS_CONNECTION_UPDATE=true - WEBHOOK_EVENTS_LABELS_EDIT=true - WEBHOOK_EVENTS_LABELS_ASSOCIATION=true - WEBHOOK_EVENTS_CALL=true - WEBHOOK_EVENTS_TYPEBOT_START=false - WEBHOOK_EVENTS_TYPEBOT_CHANGE_STATUS=false - WEBHOOK_EVENTS_ERRORS=false - WEBHOOK_EVENTS_ERRORS_WEBHOOK= - CONFIG_SESSION_PHONE_CLIENT=Evolution API V2 - CONFIG_SESSION_PHONE_NAME=Chrome - QRCODE_LIMIT=30 - OPENAI_ENABLED=true - DIFY_ENABLED=true - TYPEBOT_ENABLED=true - TYPEBOT_API_VERSION=latest - CHATWOOT_ENABLED=true - CHATWOOT_MESSAGE_READ=true - CHATWOOT_MESSAGE_DELETE=true - CHATWOOT_IMPORT_DATABASE_CONNECTION_URI=postgresql://postgres:PASSWORD@postgres:5432/chatwoot?sslmode=disable - CHATWOOT_IMPORT_PLACEHOLDER_MEDIA_MESSAGE=true - CACHE_REDIS_ENABLED=true - CACHE_REDIS_URI=redis://evo_redis:6379/1 - CACHE_REDIS_PREFIX_KEY=evolution_v2 - CACHE_REDIS_SAVE_INSTANCES=false - CACHE_LOCAL_ENABLED=false - S3_ENABLED=true - S3_ACCESS_KEY= - S3_SECRET_KEY= - S3_BUCKET=evolution - S3_PORT=443 - S3_ENDPOINT=files.site.com - S3_USE_SSL=true - AUTHENTICATION_API_KEY=429683C4C977415CAAFCCE10F7D57E11 - AUTHENTICATION_EXPOSE_IN_FETCH_INSTANCES=true - LANGUAGE=en deploy: mode: replicated replicas: 1 placement: constraints: - node.hostname == evolution-manager labels: - traefik.enable=true - traefik.http.routers.evolution_v2.rule=Host(`evo2.site.com`) - traefik.http.routers.evolution_v2.entrypoints=websecure - traefik.http.routers.evolution_v2.tls.certresolver=letsencryptresolver - traefik.http.routers.evolution_v2.priority=1 - traefik.http.routers.evolution_v2.service=evolution_v2 - traefik.http.services.evolution_v2.loadbalancer.server.port=8080 - traefik.http.services.evolution_v2.loadbalancer.passHostHeader=true volumes: evolution_instances: external: true name: evolution_v2_data networks: network_public: external: true name: network_public ================================================ FILE: Dockerfile ================================================ FROM node:24-alpine AS builder RUN apk update && \ apk add --no-cache git ffmpeg wget curl bash openssl LABEL version="2.3.1" description="Api to control whatsapp features through http requests." LABEL maintainer="Davidson Gomes" git="https://github.com/DavidsonGomes" LABEL contact="contato@evolution-api.com" WORKDIR /evolution COPY ./package*.json ./ COPY ./tsconfig.json ./ COPY ./tsup.config.ts ./ RUN npm ci --silent COPY ./src ./src COPY ./public ./public COPY ./prisma ./prisma COPY ./manager ./manager COPY ./.env.example ./.env COPY ./runWithProvider.js ./ COPY ./Docker ./Docker RUN chmod +x ./Docker/scripts/* && dos2unix ./Docker/scripts/* RUN ./Docker/scripts/generate_database.sh RUN npm run build FROM node:24-alpine AS final RUN apk update && \ apk add tzdata ffmpeg bash openssl ENV TZ=America/Sao_Paulo ENV DOCKER_ENV=true WORKDIR /evolution COPY --from=builder /evolution/package.json ./package.json COPY --from=builder /evolution/package-lock.json ./package-lock.json COPY --from=builder /evolution/node_modules ./node_modules COPY --from=builder /evolution/dist ./dist COPY --from=builder /evolution/prisma ./prisma COPY --from=builder /evolution/manager ./manager COPY --from=builder /evolution/public ./public COPY --from=builder /evolution/.env ./.env COPY --from=builder /evolution/Docker ./Docker COPY --from=builder /evolution/runWithProvider.js ./runWithProvider.js COPY --from=builder /evolution/tsup.config.ts ./tsup.config.ts ENV DOCKER_ENV=true EXPOSE 8080 ENTRYPOINT ["/bin/bash", "-c", ". ./Docker/scripts/deploy_database.sh && npm run start:prod" ] ================================================ FILE: Dockerfile.metrics ================================================ FROM evoapicloud/evolution-api:latest AS base WORKDIR /evolution # Copiamos apenas o necessário para recompilar o dist com as mudanças locais COPY tsconfig.json tsup.config.ts package.json ./ COPY src ./src # Recompila usando os node_modules já presentes na imagem base RUN npm run build # Runtime final: reaproveita a imagem oficial e apenas sobrepõe o dist FROM evoapicloud/evolution-api:latest AS final WORKDIR /evolution COPY --from=base /evolution/dist ./dist ENV PROMETHEUS_METRICS=true # Entrada original da imagem oficial já sobe o app em /evolution ================================================ FILE: Extras/chatwoot/configurar_admin.json ================================================ { "name": "[Evolution] Configurar Admin", "nodes": [ { "parameters": { "values": { "string": [ { "name": "api_access_token", "value": "CHATWOOT_ADMIN_USER_TOKEN" }, { "name": "chatwoot_url", "value": "https://CHATWOOT_URL" }, { "name": "n8n_url", "value": "https://N8N_URL" }, { "name": "organization", "value": "ORGANIZATION_NAME" }, { "name": "logo", "value": "ORGANIZATION_LOGO" } ] }, "options": {} }, "id": "7a89a538-2cae-4032-8896-09627c07bc68", "name": "Info Base", "type": "n8n-nodes-base.set", "typeVersion": 2, "position": [ 620, 480 ] }, { "parameters": { "method": "POST", "url": "={{ $('Info Base').item.json[\"chatwoot_url\"] }}/api/v1/accounts/1/contacts/", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "api_access_token", "value": "={{ $('Info Base').item.json[\"api_access_token\"] }}" } ] }, "sendBody": true, "specifyBody": "json", "jsonBody": "={\n \"inbox_id\": {{ $('Cria Inbox Start').item.json[\"id\"] }},\n \"name\": \"Bot {{ $('Info Base').item.json[\"organization\"] }}\",\n \"phone_number\": \"+123456\",\n \"avatar_url\": \"{{ $('Info Base').item.json[\"logo\"] }}\"\n}", "options": {} }, "id": "12a39df3-6b95-4f83-a0bc-50b25adaca7f", "name": "Cria Contato Bot", "type": "n8n-nodes-base.httpRequest", "typeVersion": 3, "position": [ 1020, 480 ] }, { "parameters": { "method": "POST", "url": "={{ $('Info Base').item.json[\"chatwoot_url\"] }}/api/v1/accounts/1/inboxes/", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "api_access_token", "value": "={{ $('Info Base').item.json[\"api_access_token\"] }}" } ] }, "sendBody": true, "specifyBody": "json", "jsonBody": "={\n \"name\": \"Start {{ $('Info Base').item.json[\"organization\"] }}\",\n \"channel\": {\n \"type\": \"api\",\n \"website_url\": \"\"\n }\n}", "options": {} }, "id": "bed7c54d-e232-4fe4-9584-0515e9679868", "name": "Cria Inbox Start", "type": "n8n-nodes-base.httpRequest", "typeVersion": 3, "position": [ 820, 480 ] }, { "parameters": {}, "id": "36ada769-a757-4193-989b-0cc4ea504b80", "name": "When clicking \"Execute Workflow\"", "type": "n8n-nodes-base.manualTrigger", "typeVersion": 1, "position": [ 420, 480 ] }, { "parameters": { "method": "POST", "url": "={{ $('Info Base').item.json[\"chatwoot_url\"] }}/api/v1/accounts/1/automation_rules/", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "api_access_token", "value": "={{ $('Info Base').item.json[\"api_access_token\"] }}" } ] }, "sendBody": true, "specifyBody": "json", "jsonBody": "={\n \"name\": \"Create Company Chatwoot\",\n \"description\": \"Create Company Chatwoot\",\n \"event_name\": \"message_created\",\n \"active\": true,\n \"actions\": \n [\n {\n \"action_name\": \"send_webhook_event\",\n \"action_params\": [\"{{ $('Info Base').item.json[\"n8n_url\"] }}/webhook/criadorchatwoot\"]\n }\n ],\n \"conditions\": \n [\n {\n \"attribute_key\": \"content\",\n \"filter_operator\": \"contains\",\n \"query_operator\": \"and\",\n \"values\": [\"Tema Criador de Empresa:\"]\n },\n {\n \"attribute_key\": \"phone_number\",\n \"filter_operator\": \"equal_to\",\n \"values\": [\"+123456\"]\n }\n ]\n}", "options": {} }, "id": "f5bbb285-71a8-4c58-a4d7-e56002d697f0", "name": "Cria Automação Empresas", "type": "n8n-nodes-base.httpRequest", "typeVersion": 3, "position": [ 1220, 480 ] }, { "parameters": { "method": "POST", "url": "={{ $('Info Base').item.json[\"chatwoot_url\"] }}/api/v1/accounts/1/automation_rules/", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "api_access_token", "value": "={{ $('Info Base').item.json[\"api_access_token\"] }}" } ] }, "sendBody": true, "specifyBody": "json", "jsonBody": "={\n \"name\": \"Create Inbox {{ $('Info Base').item.json[\"organization\"] }}\",\n \"description\": \"Create Inbox {{ $('Info Base').item.json[\"organization\"] }}\",\n \"event_name\": \"message_created\",\n \"active\": true,\n \"actions\": \n [\n {\n \"action_name\": \"send_webhook_event\",\n \"action_params\": [\"{{ $('Info Base').item.json[\"n8n_url\"] }}/webhook/inbox_whatsapp?utoken={{ $('Info Base').item.json[\"api_access_token\"] }}&organization={{ $('Info Base').item.json[\"organization\"] }}\"]\n }\n ],\n \"conditions\": \n [\n {\n \"attribute_key\": \"content\",\n \"filter_operator\": \"contains\",\n \"query_operator\": \"and\",\n \"values\": [\"start:\"]\n },\n \n {\n \"attribute_key\": \"phone_number\",\n \"filter_operator\": \"equal_to\",\n \"query_operator\": \"or\",\n \"values\": [\"+123456\"]\n },\n\n\n {\n \"attribute_key\": \"content\",\n \"filter_operator\": \"contains\",\n \"query_operator\": \"and\",\n \"values\": [\"new_instance:\"]\n },\n {\n \"attribute_key\": \"phone_number\",\n \"filter_operator\": \"equal_to\",\n \"values\": [\"+123456\"]\n }\n ]\n}", "options": {} }, "id": "a36bebdc-a318-40a2-8532-c7f476f8adb7", "name": "Cria Automação Inboxes", "type": "n8n-nodes-base.httpRequest", "typeVersion": 3, "position": [ 1420, 480 ] }, { "parameters": { "content": "## Workflow Para Configurar admin\n**Aqui você prepara o Chatwoot Principal com um usuário (Superadmin) que poderá criar empresas e caixas de entrada**\n**Instruções**\n**No node Info Base, configure as variáveis de seu Chatwoot e N8N**\n**Obs: A variável api_access_token é o token do usuário que irá poder criar as empresas**", "width": 894.6435495898575 }, "id": "db66e867-e9f4-452d-b521-725eeac652c8", "name": "Sticky Note", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ 420, 280 ] } ], "pinData": {}, "connections": { "Info Base": { "main": [ [ { "node": "Cria Inbox Start", "type": "main", "index": 0 } ] ] }, "Cria Contato Bot": { "main": [ [ { "node": "Cria Automação Empresas", "type": "main", "index": 0 } ] ] }, "Cria Inbox Start": { "main": [ [ { "node": "Cria Contato Bot", "type": "main", "index": 0 } ] ] }, "When clicking \"Execute Workflow\"": { "main": [ [ { "node": "Info Base", "type": "main", "index": 0 } ] ] }, "Cria Automação Empresas": { "main": [ [ { "node": "Cria Automação Inboxes", "type": "main", "index": 0 } ] ] } }, "active": false, "settings": {}, "versionId": "78f155dc-7809-4bfc-9282-63f49b07fc4d", "id": "BSATyGpGWLR4ZwNm", "meta": { "instanceId": "4ff16e963c7f5197d7e99e6239192860914312fea0ce2a9a7fd14d74a0a0e906" }, "tags": [] } ================================================ FILE: Extras/chatwoot/criador_de_empresas.json ================================================ { "name": "[Evolution] Criador de Empresas", "nodes": [ { "parameters": { "httpMethod": "POST", "path": "criadorchatwoot", "options": {} }, "id": "5a47c10a-e43c-4fa5-baad-4b6cc511bfcd", "name": "Webhook", "type": "n8n-nodes-base.webhook", "typeVersion": 1, "position": [ 1420, 860 ], "webhookId": "6fe428e3-1752-453c-9358-abf18b793387" }, { "parameters": { "method": "POST", "url": "={{ $('Info Base').item.json[\"chatwoot_url\"] }}/platform/api/v1/accounts", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "api_access_token", "value": "={{ $('Info Base').item.json[\"api_access_token\"] }}" } ] }, "sendBody": true, "bodyParameters": { "parameters": [ { "name": "name", "value": "={{ $json.name_company }}" }, { "name": "locale", "value": "pt_BR" } ] }, "options": {} }, "id": "8295c119-3a96-424e-9386-43d75f6816f5", "name": "Cria Conta", "type": "n8n-nodes-base.httpRequest", "typeVersion": 3, "position": [ 2020, 860 ] }, { "parameters": { "method": "POST", "url": "={{ $('Info Base').item.json[\"chatwoot_url\"] }}/platform/api/v1/users", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "api_access_token", "value": "={{ $('Info Base').item.json[\"api_access_token\"] }}" } ] }, "sendBody": true, "bodyParameters": { "parameters": [ { "name": "name", "value": "={{ $('Info Base').item.json.name_admin }}" }, { "name": "email", "value": "={{ $('Info Base').item.json[\"email\"] }}" }, { "name": "password", "value": "={{ $('Info Base').item.json[\"password\"] }}" } ] }, "options": {} }, "id": "4fe5007a-3a6b-490a-a446-e45cc168189f", "name": "Cria Usuario", "type": "n8n-nodes-base.httpRequest", "typeVersion": 3, "position": [ 2220, 860 ] }, { "parameters": { "method": "POST", "url": "={{ $('Info Base').item.json[\"chatwoot_url\"] }}/platform/api/v1/accounts/{{ $node[\"Cria Conta\"].json[\"id\"] }}/account_users", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "api_access_token", "value": "={{ $('Info Base').item.json[\"api_access_token\"] }}" } ] }, "sendBody": true, "bodyParameters": { "parameters": [ { "name": "user_id", "value": "={{ $node[\"Cria Usuario\"].json[\"id\"] }}" }, { "name": "role", "value": "administrator" } ] }, "options": {} }, "id": "848c55e2-5678-4291-9602-c94d994da95b", "name": "Add Usuario a Conta", "type": "n8n-nodes-base.httpRequest", "typeVersion": 3, "position": [ 2420, 860 ] }, { "parameters": { "fromEmail": "={{ $('Info Base').item.json[\"from_email\"] }}", "toEmail": "={{ $('LimpaDados').item.json.email }}", "subject": "=Bem vindo à {{ $('Info Base').item.json[\"organization\"] }}", "text": "=Olá seja bem vindo:\n\nAbaixo segue seus dados de acesso:\n\nURL: {{ $('Info Base').item.json[\"chatwoot_url\"] }}\n\nuser: {{ $('LimpaDados').item.json[\"email\"] }}\n\nSenha: {{ $('LimpaDados').item.json[\"password\"] }}", "options": {} }, "id": "27f3b24f-1cf2-4d0d-a354-ecba066059f6", "name": "Send Email", "type": "n8n-nodes-base.emailSend", "typeVersion": 2, "position": [ 3220, 860 ], "credentials": { "smtp": { "id": "6BxluEUV8zrXKoVG", "name": "[Dgcode] SMTP" } } }, { "parameters": { "values": { "string": [ { "name": "api_access_token", "value": "CHATWOOT_PLATFORM_TOKEN" }, { "name": "chatwoot_url", "value": "https://CHATWOOT_URL" }, { "name": "n8n_url", "value": "https://N8N_URL" }, { "name": "organization", "value": "ORGANIZATION_NAME" }, { "name": "logo", "value": "ORGANIZATION_LOGO" }, { "name": "from_email", "value": "FROM_EMAIL" }, { "name": "name", "value": "={{ $json.name_company }}" }, { "name": "email", "value": "={{ $json.email }}" }, { "name": "password", "value": "={{ $json.password }}" }, { "name": "name_company", "value": "={{ $json.name_company }}" } ] }, "options": {} }, "id": "38b4069d-e51e-4db7-933f-941b1be6d124", "name": "Info Base", "type": "n8n-nodes-base.set", "typeVersion": 2, "position": [ 1820, 860 ] }, { "parameters": { "keepOnlySet": true, "values": { "string": [ { "name": "name_admin", "value": "={{$node[\"Webhook\"].json[\"body\"][\"messages\"][0][\"content\"].match(/Nome Usuario Administrador: ([^\\n]+)/)[1];}}" }, { "name": "name_company", "value": "={{$node[\"Webhook\"].json[\"body\"][\"messages\"][0][\"content\"].match(/Nome da Empresa: ([^\\n]+)/)[1];}}" }, { "name": "email", "value": "={{$node[\"Webhook\"].json[\"body\"][\"messages\"][0][\"content\"].match(/Email: ([^\\s]+)/)[1];}}" }, { "name": "password", "value": "={{$node[\"Webhook\"].json[\"body\"][\"messages\"][0][\"content\"].match(/Senha: ([^\\s]+)/)[1];}}" } ] }, "options": {} }, "id": "28e29e73-aadc-49ca-bd6d-b57ee0160a21", "name": "LimpaDados", "type": "n8n-nodes-base.set", "typeVersion": 2, "position": [ 1620, 860 ] }, { "parameters": { "method": "POST", "url": "={{ $('Info Base').item.json[\"chatwoot_url\"] }}/api/v1/accounts/{{ $('Add Usuario a Conta').item.json.account_id }}/contacts/", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "api_access_token", "value": "={{ $('Cria Usuario').item.json.access_token }}" } ] }, "sendBody": true, "specifyBody": "json", "jsonBody": "={\n \"inbox_id\": {{ $('Cria Inbox Start').item.json[\"id\"] }},\n \"name\": \"Bot {{ $('Info Base').item.json[\"organization\"] }}\",\n \"phone_number\": \"+123456\",\n \"avatar_url\": \"{{ $('Info Base').item.json[\"logo\"] }}\"\n}", "options": {} }, "id": "bb671443-bdb4-4f56-99af-f0baef246a3e", "name": "Cria Contato Bot", "type": "n8n-nodes-base.httpRequest", "typeVersion": 3, "position": [ 2820, 860 ] }, { "parameters": { "method": "POST", "url": "={{ $('Info Base').item.json[\"chatwoot_url\"] }}/api/v1/accounts/{{ $('Add Usuario a Conta').item.json.account_id }}/automation_rules/", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "api_access_token", "value": "={{ $('Cria Usuario').item.json.access_token }}" } ] }, "sendBody": true, "specifyBody": "json", "jsonBody": "={\n \"name\": \"Create Inbox {{ $('Info Base').item.json[\"organization\"] }}\",\n \"description\": \"Create Inbox {{ $('Info Base').item.json[\"organization\"] }}\",\n \"event_name\": \"message_created\",\n \"active\": true,\n \"actions\": \n [\n {\n \"action_name\": \"send_webhook_event\",\n \"action_params\": [\"{{ $('Info Base').item.json[\"n8n_url\"] }}/webhook/inbox_whatsapp?utoken={{ $('Cria Usuario').item.json.access_token }}&organization={{ $('Info Base').item.json[\"organization\"] }}\"]\n }\n ],\n \"conditions\": \n [\n {\n \"attribute_key\": \"content\",\n \"filter_operator\": \"contains\",\n \"query_operator\": \"and\",\n \"values\": [\"start:\"]\n },\n {\n \"attribute_key\": \"phone_number\",\n \"filter_operator\": \"equal_to\",\n \"query_operator\": \"or\",\n \"values\": [\"+123456\"]\n },\n {\n \"attribute_key\": \"content\",\n \"filter_operator\": \"contains\",\n \"query_operator\": \"and\",\n \"values\": [\"new_instance:\"]\n },\n {\n \"attribute_key\": \"phone_number\",\n \"filter_operator\": \"equal_to\",\n \"values\": [\"+123456\"]\n }\n ]\n}", "options": {} }, "id": "e016a2af-b212-4e00-a3ff-8cd03530aa06", "name": "Cria Automação", "type": "n8n-nodes-base.httpRequest", "typeVersion": 3, "position": [ 3020, 860 ] }, { "parameters": { "method": "POST", "url": "={{ $('Info Base').item.json[\"chatwoot_url\"] }}/api/v1/accounts/{{ $json.account_id }}/inboxes/", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "api_access_token", "value": "={{ $('Cria Usuario').item.json.access_token }}" } ] }, "sendBody": true, "specifyBody": "json", "jsonBody": "={\n \"name\": \"Start {{ $('Info Base').item.json[\"organization\"] }}\",\n \"channel\": {\n \"type\": \"api\",\n \"website_url\": \"\"\n }\n}", "options": {} }, "id": "d3c42148-8920-4c98-a874-eb7113f2dd22", "name": "Cria Inbox Start", "type": "n8n-nodes-base.httpRequest", "typeVersion": 3, "position": [ 2620, 860 ] }, { "parameters": { "content": "## Workflow Criador de Empresas\n**Cria Contas (Empresas) e Usuários através de tema**\n**Instruções**\n**No node Info Base, configure as variáveis de seu Chatwoot e N8N**\n**Obs: A variável api_access_token é o token PlatformApp encontrado no acesso ao Super Admin**\n**Tema para criar novas empresa:**\n\nTema Criador de Empresa:\n\nNome Usuario Administrador: Joao Linhares\nNome da Empresa: Oficina Linhates\nEmail: machineteste24@gmail.com\nSenha: Mfcd62!!", "height": 304.02684563758396, "width": 1129.7777777777778 }, "id": "d07516c0-4c8e-43ab-ba86-c8d063b09be5", "name": "Sticky Note", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ 1420, 520 ] } ], "pinData": {}, "connections": { "Webhook": { "main": [ [ { "node": "LimpaDados", "type": "main", "index": 0 } ] ] }, "Cria Conta": { "main": [ [ { "node": "Cria Usuario", "type": "main", "index": 0 } ] ] }, "Cria Usuario": { "main": [ [ { "node": "Add Usuario a Conta", "type": "main", "index": 0 } ] ] }, "Add Usuario a Conta": { "main": [ [ { "node": "Cria Inbox Start", "type": "main", "index": 0 } ] ] }, "Info Base": { "main": [ [ { "node": "Cria Conta", "type": "main", "index": 0 } ] ] }, "LimpaDados": { "main": [ [ { "node": "Info Base", "type": "main", "index": 0 } ] ] }, "Cria Contato Bot": { "main": [ [ { "node": "Cria Automação", "type": "main", "index": 0 } ] ] }, "Cria Automação": { "main": [ [ { "node": "Send Email", "type": "main", "index": 0 } ] ] }, "Cria Inbox Start": { "main": [ [ { "node": "Cria Contato Bot", "type": "main", "index": 0 } ] ] } }, "active": true, "settings": {}, "versionId": "3ffd6d3f-6966-4de4-af8f-1fda464bc1b8", "id": "79R6qQDtfyCwgYjJ", "meta": { "instanceId": "4ff16e963c7f5197d7e99e6239192860914312fea0ce2a9a7fd14d74a0a0e906" }, "tags": [] } ================================================ FILE: Extras/chatwoot/criador_de_inbox.json ================================================ { "name": "criador_de_inbox_evo_v2.0", "nodes": [ { "parameters": { "method": "POST", "url": "={{ $json.evolution_url }}/instance/create", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "Content-Type", "value": "application/json" }, { "name": "apikey", "value": "={{ $json.global_api_key }}" } ] }, "sendBody": true, "bodyParameters": { "parameters": [ { "name": "instanceName", "value": "={{ $json.instanceName }}" }, { "name": "qrcode", "value": "={{ $json.qrcode }}" }, { "name": "chatwootAccountId", "value": "={{ $json.chatwootAccountId }}" }, { "name": "chatwootToken", "value": "={{ $json.chatwootToken }}" }, { "name": "chatwootUrl", "value": "={{ $json.chatwootUrl }}" }, { "name": "chatwootSignMsg", "value": "={{ $json.chatwootSignMsg }}" }, { "name": "chatwootReopenConversation", "value": "={{ $json.chatwootReopenConversation }}" }, { "name": "chatwootConversationPending", "value": "={{ $json.chatwootConversationPending }}" }, { "name": "rejectCall", "value": "={{ $json.rejectCall }}" }, { "name": "msgCall", "value": "={{ $json.msgCall }}" }, { "name": "groupsIgnore", "value": "={{ $json.groupsIgnore }}" }, { "name": "alwaysOnline", "value": "={{ $json.alwaysOnline }}" }, { "name": "readMessages", "value": "={{ $json.readMessages }}" }, { "name": "readStatus", "value": "={{ $json.readStatus }}" }, { "name": "chatwootImportContacts", "value": "={{ $json.chatwootImportContacts }}" }, { "name": "chatwootImportMessages", "value": "={{ $json.chatwootImportMessages }}" }, { "name": "chatwootDaysLimitImportMessages", "value": "={{ $json.chatwootDaysLimitImportMessages }}" }, { "name": "syncFullHistory", "value": "={{ $json.syncFullHistory }}" }, { "name": "chatwootMergeBrazilContacts", "value": "={{ $json.chatwootMergeBrazilContacts }}" }, { "name": "integration", "value": "={{ $json.integration }}" }, { "name": "chatwootNameInbox", "value": "={{ $json.chatwootNameInbox }}" }, { "name": "token", "value": "={{ $json.token }}" } ] }, "options": {} }, "id": "7da41431-cc8e-4eb4-9894-7bf413819fe3", "name": "Cria Instancia", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.1, "position": [ 900, 680 ] }, { "parameters": { "url": "={{ $('Info Base').item.json[\"chatwootUrl\"] }}/api/v1/accounts/{{ $('Info Base').item.json[\"chatwootAccountId\"] }}/inboxes/", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "api_access_token", "value": "={{ $('Info Base').item.json.chatwootToken }}" } ] }, "options": {} }, "id": "d51fbbfe-4579-4fba-949f-c29e0b806feb", "name": "Lista Inboxes", "type": "n8n-nodes-base.httpRequest", "typeVersion": 3, "position": [ 1120, 680 ] }, { "parameters": { "content": "## Workflow Para Criar Inbox - Evolution 2.0 ou superior\n**Aqui você configura a comunicação entre o chatwoot e a Evolution API para criar novas instâncias a partir do chatwoot**\n**Instruções**\n**No node Info Base, configure as variáveis de seu Chatwoot e Evolution API**", "width": 1129.7777777777778 }, "id": "7c66af51-b01e-4b76-8a8c-0193e87ec9d5", "name": "Sticky Note", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ 460, 460 ] }, { "parameters": { "keepOnlySet": true, "values": { "string": [ { "name": "chatwootUrl", "value": "https://chatwootUrl - preencha" }, { "name": "evolution_url", "value": "https://evolution_url - preencha" }, { "name": "global_api_key", "value": "global_api_key - preencha" }, { "name": "organization", "value": "={{ $json.query.organization }}" }, { "name": "instanceName", "value": "={{ $json.body.messages[0].content.split(':')[1] }}-cwId-{{ $json.body.messages[0].account_id }}" }, { "name": "chatwootToken", "value": "={{ $json.query.utoken }}" }, { "name": "msgCall", "value": "Não aceitamos chamadas, por favor deixe uma mensagem!" }, { "name": "integration", "value": "WHATSAPP-BAILEYS" }, { "name": "chatwootNameInbox", "value": "={{ $json.body.messages[0].content.split(':')[1] }}" }, { "name": "chatwootAccountId", "value": "={{ $json.body.messages[0].account_id.toString() }}" }, { "name": "token", "value": "=AfRw{{ Date.now() }}BeH4" } ], "boolean": [ { "name": "qrcode", "value": true }, { "name": "chatwootSignMsg", "value": true }, { "name": "chatwootReopenConversation", "value": true }, { "name": "chatwootConversationPending" }, { "name": "rejectCall" }, { "name": "groupsIgnore" }, { "name": "alwaysOnline", "value": true }, { "name": "readMessages", "value": true }, { "name": "readStatus" }, { "name": "chatwootImportMessages", "value": true }, { "name": "chatwootImportContacts", "value": true }, { "name": "syncFullHistory" }, { "name": "chatwootMergeBrazilContacts", "value": true } ], "number": [ { "name": "chatwootDaysLimitImportMessages", "value": 60 } ] }, "options": { "dotNotation": false } }, "id": "eaffbc44-3701-4f8d-b923-92061cfb995f", "name": "Info Base", "type": "n8n-nodes-base.set", "typeVersion": 2, "position": [ 680, 680 ] }, { "parameters": { "conditions": { "string": [ { "value1": "={{ $json.name }}", "value2": "=Start {{ $('Info Base').item.json[\"organization\"] }}" } ] } }, "id": "82eb24c8-2269-4622-b012-d6f6ad35c149", "name": "é Start Inbox?", "type": "n8n-nodes-base.if", "typeVersion": 1, "position": [ 1800, 600 ] }, { "parameters": { "batchSize": 1, "options": {} }, "id": "b9de1318-ab0b-4529-b30a-2daea64dbcfe", "name": "Split In Batches", "type": "n8n-nodes-base.splitInBatches", "typeVersion": 2, "position": [ 1560, 680 ] }, { "parameters": { "method": "DELETE", "url": "={{ $('Info Base').item.json[\"chatwootUrl\"] }}/api/v1/accounts/{{ $('Info Base').item.json[\"chatwootAccountId\"] }}/inboxes/{{ $json.id }}", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "api_access_token", "value": "={{ $('Info Base').item.json.chatwootToken }}" } ] }, "options": {} }, "id": "db2ad958-7642-41eb-8e9a-e8b1668230d1", "name": "Deleta Inbox Start", "type": "n8n-nodes-base.httpRequest", "typeVersion": 3, "position": [ 2040, 480 ] }, { "parameters": {}, "id": "6d68d3a7-d613-471f-8492-9ec473481521", "name": "No Operation, do nothing", "type": "n8n-nodes-base.noOp", "typeVersion": 1, "position": [ 1800, 780 ] }, { "parameters": { "fieldToSplitOut": "payload", "options": {} }, "id": "be833e77-b2ae-44c6-b4fc-ad24ffc8ad9a", "name": "Ajusta lista", "type": "n8n-nodes-base.itemLists", "typeVersion": 2.2, "position": [ 1340, 680 ] }, { "parameters": { "httpMethod": "POST", "path": "inbox_whatsapp", "options": {} }, "id": "faae80e0-9070-4a0c-83bc-d47643a64653", "name": "Webhook", "type": "n8n-nodes-base.webhook", "typeVersion": 1, "position": [ 460, 680 ], "webhookId": "85cb0c27-4223-4339-b7b4-35a16c0a04b8" }, { "parameters": { "conditions": { "string": [ { "value1": "={{ $json.name }}", "value2": "={{ $('Webhook').item.json[\"body\"][\"messages\"][0][\"content\"].split(':')[1] }}" } ] } }, "id": "4ea7b74f-bdc5-4619-8e99-1f5d33c7e28e", "name": "é_pre-existente?", "type": "n8n-nodes-base.if", "typeVersion": 1, "position": [ 1980, 700 ] }, { "parameters": { "method": "PATCH", "url": "={{ $('Info Base').item.json[\"chatwootUrl\"] }}/api/v1/accounts/{{ $('Info Base').item.json[\"chatwootAccountId\"] }}/inboxes/{{ $json.id }}", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "api_access_token", "value": "={{ $('Info Base').item.json.chatwootToken }}" }, { "name": "Content-Type", "value": "application/json" } ] }, "sendBody": true, "specifyBody": "json", "jsonBody": "={\n\"channel\": {\n\"webhook_url\": \"{{ $('Info Base').item.json[\"evolution_url\"] }}/chatwoot/webhook/{{ encodeURIComponent($('Info Base').item.json[\"instanceName\"]) }}\"\n}\n}", "options": {} }, "id": "74d6db21-d49e-48d6-b1a8-ff8bddca67d1", "name": "Update_webhook_url", "type": "n8n-nodes-base.httpRequest", "typeVersion": 3, "position": [ 2200, 700 ] } ], "pinData": {}, "connections": { "Cria Instancia": { "main": [ [ { "node": "Lista Inboxes", "type": "main", "index": 0 } ] ] }, "Lista Inboxes": { "main": [ [ { "node": "Ajusta lista", "type": "main", "index": 0 } ] ] }, "Info Base": { "main": [ [ { "node": "Cria Instancia", "type": "main", "index": 0 } ] ] }, "é Start Inbox?": { "main": [ [ { "node": "Deleta Inbox Start", "type": "main", "index": 0 } ], [ { "node": "é_pre-existente?", "type": "main", "index": 0 } ] ] }, "Split In Batches": { "main": [ [ { "node": "é Start Inbox?", "type": "main", "index": 0 } ], [ { "node": "No Operation, do nothing", "type": "main", "index": 0 } ] ] }, "Deleta Inbox Start": { "main": [ [ { "node": "Split In Batches", "type": "main", "index": 0 } ] ] }, "Ajusta lista": { "main": [ [ { "node": "Split In Batches", "type": "main", "index": 0 } ] ] }, "Webhook": { "main": [ [ { "node": "Info Base", "type": "main", "index": 0 } ] ] }, "é_pre-existente?": { "main": [ [ { "node": "Update_webhook_url", "type": "main", "index": 0 } ], [ { "node": "Split In Batches", "type": "main", "index": 0 } ] ] }, "Update_webhook_url": { "main": [ [ { "node": "Split In Batches", "type": "main", "index": 0 } ] ] } }, "active": false, "settings": { "executionOrder": "v1" }, "versionId": "68f9fa60-e295-4b74-8cb3-c4723d6cb2b2", "meta": { "templateCredsSetupCompleted": true, "instanceId": "8ed3edb9203bfe03a4b94f63390235285fbb1c230430fdae73a456b9fae762d5" }, "id": "f6dLbF7I7nrjcDc4", "tags": [] } ================================================ FILE: LICENSE ================================================ # Evolution API License Evolution API is licensed under the Apache License 2.0, with the following additional conditions: 1. Evolution API may be utilized commercially, including as a backend service for other applications or as an application development platform for enterprises. Should the conditions below be met, a commercial license must be obtained from the producer: a. LOGO and copyright information: In the process of using Evolution API's frontend components, you may not remove or modify the LOGO or copyright information in the Evolution API console or applications. This restriction is inapplicable to uses of Evolution API that do not involve its frontend components. b. Usage Notification Requirement: If Evolution API is used as part of any project, including closed-source systems (e.g., proprietary software), the user is required to display a clear notification within the system that Evolution API is being utilized. This notification should be visible to system administrators and accessible from the system's documentation or settings page. Failure to comply with this requirement may result in the necessity for a commercial license, as determined by the producer. Please contact contato@evolution-api.com to inquire about licensing matters. 2. As a contributor, you should agree that: a. The producer can adjust the open-source agreement to be more strict or relaxed as deemed necessary. b. Your contributed code may be used for commercial purposes, including but not limited to its cloud business operations. Apart from the specific conditions mentioned above, all other rights and restrictions follow the Apache License 2.0. Detailed information about the Apache License 2.0 can be found at http://www.apache.org/licenses/LICENSE-2.0. © 2025 Evolution API ================================================ FILE: README.md ================================================

Evolution Api

[![Docker Image](https://img.shields.io/badge/Docker-image-blue)](https://hub.docker.com/r/evoapicloud/evolution-api) [![Whatsapp Group](https://img.shields.io/badge/Group-WhatsApp-%2322BC18)](https://evolution-api.com/whatsapp) [![Discord Community](https://img.shields.io/badge/Discord-Community-blue)](https://evolution-api.com/discord) [![Postman Collection](https://img.shields.io/badge/Postman-Collection-orange)](https://evolution-api.com/postman) [![Documentation](https://img.shields.io/badge/Documentation-Official-green)](https://doc.evolution-api.com) [![Feature Requests](https://img.shields.io/badge/Feature-Requests-purple)](https://evolutionapi.canny.io/feature-requests) [![Roadmap](https://img.shields.io/badge/Roadmap-Community-blue)](https://evolutionapi.canny.io/feature-requests) [![Changelog](https://img.shields.io/badge/Changelog-Updates-green)](https://evolutionapi.canny.io/changelog) [![License](https://img.shields.io/badge/license-Apache--2.0-blue)](./LICENSE) [![Support](https://img.shields.io/badge/Donation-picpay-green)](https://app.picpay.com/user/davidsongomes1998) [![Sponsors](https://img.shields.io/badge/Github-sponsor-orange)](https://github.com/sponsors/EvolutionAPI)
## Evolution API Evolution API began as a WhatsApp controller API based on [CodeChat](https://github.com/code-chat-br/whatsapp-api), which in turn implemented the [Baileys](https://github.com/WhiskeySockets/Baileys) library. While originally focused on WhatsApp, Evolution API has grown into a comprehensive platform supporting multiple messaging services and integrations. We continue to acknowledge CodeChat for laying the groundwork. Today, Evolution API is not limited to WhatsApp. It integrates with various platforms such as Typebot, Chatwoot, Dify, and OpenAI, offering a broad array of functionalities beyond messaging. Evolution API supports both the Baileys-based WhatsApp API and the official WhatsApp Business API, with upcoming support for Instagram and Messenger. ## Looking for a Lightweight Version? For those who need a more streamlined and performance-optimized version, check out [Evolution API Lite](https://github.com/EvolutionAPI/evolution-api-lite). It's designed specifically for microservices, focusing solely on connectivity without integrations or audio conversion features. Ideal for environments that prioritize simplicity and efficiency. ## Types of Connections Evolution API supports multiple types of connections to WhatsApp, enabling flexible and powerful integration options: - *WhatsApp API - Baileys*: - A free API based on WhatsApp Web, leveraging the [Baileys library](https://github.com/WhiskeySockets/Baileys). - This connection type allows control over WhatsApp Web functionalities through a RESTful API, suitable for multi-service chats, service bots, and other WhatsApp-integrated systems. - Note: This method relies on the web version of WhatsApp and may have limitations compared to official APIs. - *WhatsApp Cloud API*: - The official API provided by Meta (formerly Facebook). - This connection type offers a robust and reliable solution designed for businesses needing higher volumes of messaging and better integration support. - The Cloud API supports features such as end-to-end encryption, advanced analytics, and more comprehensive customer service tools. - To use this API, you must comply with Meta's policies and potentially pay for usage based on message volume and other factors. ## Integrations Evolution API supports various integrations to enhance its functionality. Below is a list of available integrations and their uses: - [Typebot](https://typebot.io/): - Build conversational bots using Typebot, integrated directly into Evolution with trigger management. - [Chatwoot](https://www.chatwoot.com/): - Direct integration with Chatwoot for handling customer service for your business. - [RabbitMQ](https://www.rabbitmq.com/): - Receive events from the Evolution API via RabbitMQ. - [Apache Kafka](https://kafka.apache.org/): - Receive events from the Evolution API via Apache Kafka for real-time event streaming and processing. - [Amazon SQS](https://aws.amazon.com/pt/sqs/): - Receive events from the Evolution API via Amazon SQS. - [Socket.io](https://socket.io/): - Receive events from the Evolution API via WebSocket. - [Dify](https://dify.ai/): - Integrate your Evolution API directly with Dify AI for seamless trigger management and multiple agents. - [OpenAI](https://openai.com/): - Integrate your Evolution API with OpenAI for AI capabilities, including audio-to-text conversion, available across all Evolution integrations. - Amazon S3 / Minio: - Store media files received in [Amazon S3](https://aws.amazon.com/pt/s3/) or [Minio](https://min.io/). ## Community & Feedback We value community input and feedback to continuously improve Evolution API: ### 🚀 Feature Requests & Roadmap - **[Feature Requests](https://evolutionapi.canny.io/feature-requests)**: Submit new feature ideas and vote on community proposals - **[Roadmap](https://evolutionapi.canny.io/feature-requests)**: View planned features and development progress - **[Changelog](https://evolutionapi.canny.io/changelog)**: Stay updated with the latest releases and improvements ### 💬 Community Support - **[WhatsApp Group](https://evolution-api.com/whatsapp)**: Join our community for support and discussions - **[Discord Community](https://evolution-api.com/discord)**: Real-time chat with developers and users - **[GitHub Issues](https://github.com/EvolutionAPI/evolution-api/issues)**: Report bugs and technical issues ### 🔒 Security - **[Security Policy](./SECURITY.md)**: Guidelines for reporting security vulnerabilities - **Security Contact**: contato@evolution-api.com ## Telemetry Notice To continuously improve our services, we have implemented telemetry that collects data on the routes used, the most accessed routes, and the version of the API in use. We would like to assure you that no sensitive or personal data is collected during this process. The telemetry helps us identify improvements and provide a better experience for users. ## Evolution Support Premium Join our Evolution Pro community for expert support and a weekly call to answer questions. Visit the link below to learn more and subscribe: [Click here to learn more](https://evolution-api.com/suporte-pro) # Donate to the project. #### Github Sponsors https://github.com/sponsors/EvolutionAPI # Content Creator Partners We are proud to collaborate with the following content creators who have contributed valuable insights and tutorials about Evolution API: - [Promovaweb](https://www.youtube.com/@promovaweb) - [Sandeco](https://www.youtube.com/@canalsandeco) - [Comunidade ZDG](https://www.youtube.com/@ComunidadeZDG) - [Francis MNO](https://www.youtube.com/@FrancisMNO) - [Pablo Cabral](https://youtube.com/@pablocabral) - [XPop Digital](https://www.youtube.com/@xpopdigital) - [Costar Wagner Dev](https://www.youtube.com/@costarwagnerdev) - [Dante Testa](https://youtube.com/@dantetesta_) - [Rubén Salazar](https://youtube.com/channel/UCnYGZIE2riiLqaN9sI6riig) - [OrionDesign](youtube.com/OrionDesign_Oficial) - [IMPA 365](youtube.com/@impa365_ofc) - [Comunidade Hub Connect](https://youtube.com/@comunidadehubconnect) - [dSantana Automações](https://www.youtube.com/channel/UCG7DjUmAxtYyURlOGAIryNQ?view_as=subscriber) - [Edison Martins](https://www.youtube.com/@edisonmartinsmkt) - [Astra Online](https://www.youtube.com/@astraonlineweb) - [MKT Seven Automações](https://www.youtube.com/@sevenautomacoes) - [Vamos automatizar](https://www.youtube.com/vamosautomatizar) ## License Evolution API is licensed under the Apache License 2.0, with the following additional conditions: 1. **LOGO and copyright information**: In the process of using Evolution API's frontend components, you may not remove or modify the LOGO or copyright information in the Evolution API console or applications. This restriction is inapplicable to uses of Evolution API that do not involve its frontend components. 2. **Usage Notification Requirement**: If Evolution API is used as part of any project, including closed-source systems (e.g., proprietary software), the user is required to display a clear notification within the system that Evolution API is being utilized. This notification should be visible to system administrators and accessible from the system's documentation or settings page. Failure to comply with this requirement may result in the necessity for a commercial license, as determined by the producer. Please contact contato@evolution-api.com to inquire about licensing matters. Apart from the specific conditions mentioned above, all other rights and restrictions follow the Apache License 2.0. Detailed information about the Apache License 2.0 can be found at [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0). © 2025 Evolution API ================================================ FILE: SECURITY.md ================================================ # Security Policy ## Supported Versions We actively support the following versions of Evolution API with security updates: | Version | Supported | | ------- | ------------------ | | 2.3.x | ✅ Yes | | 2.2.x | ✅ Yes | | 2.1.x | ⚠️ Critical fixes only | | < 2.1 | ❌ No | ## Reporting a Vulnerability We take security vulnerabilities seriously. If you discover a security vulnerability in Evolution API, please help us by reporting it responsibly. ### 🔒 Private Disclosure Process **Please DO NOT create a public GitHub issue for security vulnerabilities.** Instead, please report security vulnerabilities via email to: **📧 contato@evolution-api.com** ### 📋 What to Include When reporting a vulnerability, please include: - **Description**: A clear description of the vulnerability - **Impact**: What an attacker could achieve by exploiting this vulnerability - **Steps to Reproduce**: Detailed steps to reproduce the issue - **Proof of Concept**: If possible, include a minimal proof of concept - **Environment**: Version of Evolution API, OS, Node.js version, etc. - **Suggested Fix**: If you have ideas for how to fix the issue ### 🕐 Response Timeline We will acknowledge receipt of your vulnerability report within **48 hours** and will send you regular updates about our progress. - **Initial Response**: Within 48 hours - **Status Update**: Within 7 days - **Resolution Timeline**: Varies based on complexity, typically 30-90 days ### 🎯 Scope This security policy applies to: - Evolution API core application - Official Docker images - Documentation that could lead to security issues ### 🚫 Out of Scope The following are generally considered out of scope: - Third-party integrations (Chatwoot, Typebot, etc.) - please report to respective projects - Issues in dependencies - please report to the dependency maintainers - Social engineering attacks - Physical attacks - Denial of Service attacks ### 🏆 Recognition We believe in recognizing security researchers who help us keep Evolution API secure: - We will acknowledge your contribution in our security advisories (unless you prefer to remain anonymous) - For significant vulnerabilities, we may feature you in our Hall of Fame - We will work with you on coordinated disclosure timing ### 📚 Security Best Practices For users deploying Evolution API: - Always use the latest supported version - Keep your dependencies up to date - Use strong authentication methods - Implement proper network security - Monitor your logs for suspicious activity - Follow the principle of least privilege ### 🔄 Security Updates Security updates will be: - Released as patch versions (e.g., 2.3.1 → 2.3.2) - Documented in our [CHANGELOG.md](./CHANGELOG.md) - Announced in our community channels - Tagged with security labels in GitHub releases ## Contact For any questions about this security policy, please contact: - **Email**: contato@evolution-api.com --- Thank you for helping keep Evolution API and our community safe! 🛡️ ================================================ FILE: commitlint.config.js ================================================ module.exports = { extends: ['@commitlint/config-conventional'], rules: { 'type-enum': [ 2, 'always', [ 'feat', // New feature 'fix', // Bug fix 'docs', // Documentation changes 'style', // Code style changes (formatting, etc) 'refactor', // Code refactoring 'perf', // Performance improvements 'test', // Adding or updating tests 'chore', // Maintenance tasks 'ci', // CI/CD changes 'build', // Build system changes 'revert', // Reverting changes 'security', // Security fixes ], ], 'type-case': [2, 'always', 'lower-case'], 'type-empty': [2, 'never'], 'scope-case': [2, 'always', 'lower-case'], 'subject-case': [2, 'never', ['sentence-case', 'start-case', 'pascal-case', 'upper-case']], 'subject-empty': [2, 'never'], 'subject-full-stop': [2, 'never', '.'], 'header-max-length': [2, 'always', 100], 'body-leading-blank': [1, 'always'], 'body-max-line-length': [0, 'always', 150], 'footer-leading-blank': [1, 'always'], 'footer-max-line-length': [0, 'always', 150], }, }; ================================================ FILE: docker-compose.dev.yaml ================================================ services: api: container_name: evolution_api image: evolution/api:local build: . restart: always ports: - 8080:8080 volumes: - evolution_instances:/evolution/instances networks: - evolution-net env_file: - .env expose: - 8080 frontend: container_name: evolution_frontend image: evolution/manager:local build: ./evolution-manager-v2 restart: always ports: - "3000:80" networks: - evolution-net volumes: evolution_instances: networks: evolution-net: name: evolution-net driver: bridge ================================================ FILE: docker-compose.yaml ================================================ version: "3.8" services: api: container_name: evolution_api image: evoapicloud/evolution-api:latest restart: always depends_on: - redis - evolution-postgres ports: - "127.0.0.1:8080:8080" volumes: - evolution_instances:/evolution/instances networks: - evolution-net - dokploy-network env_file: - .env expose: - "8080" frontend: container_name: evolution_frontend image: evoapicloud/evolution-manager:latest restart: always ports: - "3000:80" networks: - evolution-net redis: container_name: evolution_redis image: redis:latest restart: always command: > redis-server --port 6379 --appendonly yes volumes: - evolution_redis:/data networks: evolution-net: aliases: - evolution-redis dokploy-network: aliases: - evolution-redis expose: - "6379" evolution-postgres: container_name: evolution_postgres image: postgres:15 restart: always env_file: - .env command: - postgres - -c - max_connections=1000 - -c - listen_addresses=* environment: - POSTGRES_DB=${POSTGRES_DATABASE} - POSTGRES_USER=${POSTGRES_USERNAME} - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} volumes: - postgres_data:/var/lib/postgresql/data networks: - evolution-net - dokploy-network expose: - "5432" volumes: evolution_instances: evolution_redis: postgres_data: networks: evolution-net: name: evolution-net driver: bridge dokploy-network: external: true ================================================ FILE: env.example ================================================ # =========================================== # EVOLUTION API - CONFIGURAÇÃO DE AMBIENTE # =========================================== # =========================================== # SERVIDOR # =========================================== SERVER_NAME=evolution SERVER_TYPE=http SERVER_PORT=8080 SERVER_URL=http://localhost:8080 SERVER_DISABLE_DOCS=false SERVER_DISABLE_MANAGER=false # =========================================== # CORS # =========================================== CORS_ORIGIN=* CORS_METHODS=POST,GET,PUT,DELETE CORS_CREDENTIALS=true # =========================================== # SSL (opcional) # =========================================== SSL_CONF_PRIVKEY= SSL_CONF_FULLCHAIN= # =========================================== # BANCO DE DADOS # =========================================== DATABASE_PROVIDER=postgresql DATABASE_CONNECTION_URI=postgresql://username:password@localhost:5432/evolution_api DATABASE_CONNECTION_CLIENT_NAME=evolution # Configurações de salvamento de dados DATABASE_SAVE_DATA_INSTANCE=true DATABASE_SAVE_DATA_NEW_MESSAGE=true DATABASE_SAVE_MESSAGE_UPDATE=true DATABASE_SAVE_DATA_CONTACTS=true DATABASE_SAVE_DATA_CHATS=true DATABASE_SAVE_DATA_HISTORIC=true DATABASE_SAVE_DATA_LABELS=true DATABASE_SAVE_IS_ON_WHATSAPP=true DATABASE_SAVE_IS_ON_WHATSAPP_DAYS=7 DATABASE_DELETE_MESSAGE=false # =========================================== # REDIS # =========================================== CACHE_REDIS_ENABLED=true CACHE_REDIS_URI=redis://localhost:6379 CACHE_REDIS_PREFIX_KEY=evolution-cache CACHE_REDIS_TTL=604800 CACHE_REDIS_SAVE_INSTANCES=true # Cache local (fallback) CACHE_LOCAL_ENABLED=true CACHE_LOCAL_TTL=86400 # =========================================== # AUTENTICAÇÃO # =========================================== AUTHENTICATION_API_KEY=BQYHJGJHJ AUTHENTICATION_EXPOSE_IN_FETCH_INSTANCES=false # =========================================== # LOGS # =========================================== LOG_LEVEL=ERROR,WARN,DEBUG,INFO,LOG,VERBOSE,DARK,WEBHOOKS,WEBSOCKET LOG_COLOR=true LOG_BAILEYS=error # =========================================== # INSTÂNCIAS # =========================================== DEL_INSTANCE=false DEL_TEMP_INSTANCES=true # =========================================== # IDIOMA # =========================================== LANGUAGE=pt-BR # =========================================== # WEBHOOK # =========================================== WEBHOOK_GLOBAL_URL= WEBHOOK_GLOBAL_ENABLED=false WEBHOOK_GLOBAL_WEBHOOK_BY_EVENTS=false # Eventos de webhook WEBHOOK_EVENTS_APPLICATION_STARTUP=false WEBHOOK_EVENTS_INSTANCE_CREATE=false WEBHOOK_EVENTS_INSTANCE_DELETE=false WEBHOOK_EVENTS_QRCODE_UPDATED=false WEBHOOK_EVENTS_MESSAGES_SET=false WEBHOOK_EVENTS_MESSAGES_UPSERT=false WEBHOOK_EVENTS_MESSAGES_EDITED=false WEBHOOK_EVENTS_MESSAGES_UPDATE=false WEBHOOK_EVENTS_MESSAGES_DELETE=false WEBHOOK_EVENTS_SEND_MESSAGE=false WEBHOOK_EVENTS_SEND_MESSAGE_UPDATE=false WEBHOOK_EVENTS_CONTACTS_SET=false WEBHOOK_EVENTS_CONTACTS_UPDATE=false WEBHOOK_EVENTS_CONTACTS_UPSERT=false WEBHOOK_EVENTS_PRESENCE_UPDATE=false WEBHOOK_EVENTS_CHATS_SET=false WEBHOOK_EVENTS_CHATS_UPDATE=false WEBHOOK_EVENTS_CHATS_UPSERT=false WEBHOOK_EVENTS_CHATS_DELETE=false WEBHOOK_EVENTS_CONNECTION_UPDATE=false WEBHOOK_EVENTS_LABELS_EDIT=false WEBHOOK_EVENTS_LABELS_ASSOCIATION=false WEBHOOK_EVENTS_GROUPS_UPSERT=false WEBHOOK_EVENTS_GROUPS_UPDATE=false WEBHOOK_EVENTS_GROUP_PARTICIPANTS_UPDATE=false WEBHOOK_EVENTS_CALL=false WEBHOOK_EVENTS_TYPEBOT_START=false WEBHOOK_EVENTS_TYPEBOT_CHANGE_STATUS=false WEBHOOK_EVENTS_ERRORS=false WEBHOOK_EVENTS_ERRORS_WEBHOOK= # Configurações de webhook WEBHOOK_REQUEST_TIMEOUT_MS=30000 WEBHOOK_RETRY_MAX_ATTEMPTS=10 WEBHOOK_RETRY_INITIAL_DELAY_SECONDS=5 WEBHOOK_RETRY_USE_EXPONENTIAL_BACKOFF=true WEBHOOK_RETRY_MAX_DELAY_SECONDS=300 WEBHOOK_RETRY_JITTER_FACTOR=0.2 WEBHOOK_RETRY_NON_RETRYABLE_STATUS_CODES=400,401,403,404,422 # =========================================== # WEBSOCKET # =========================================== WEBSOCKET_ENABLED=true WEBSOCKET_GLOBAL_EVENTS=true WEBSOCKET_ALLOWED_HOSTS= # =========================================== # RABBITMQ # =========================================== RABBITMQ_ENABLED=false RABBITMQ_GLOBAL_ENABLED=false RABBITMQ_PREFIX_KEY= RABBITMQ_EXCHANGE_NAME=evolution_exchange RABBITMQ_URI= RABBITMQ_FRAME_MAX=8192 # =========================================== # NATS # =========================================== NATS_ENABLED=false NATS_GLOBAL_ENABLED=false NATS_PREFIX_KEY= NATS_EXCHANGE_NAME=evolution_exchange NATS_URI= # =========================================== # SQS # =========================================== SQS_ENABLED=false SQS_GLOBAL_ENABLED=false SQS_GLOBAL_FORCE_SINGLE_QUEUE=false SQS_GLOBAL_PREFIX_NAME=global SQS_ACCESS_KEY_ID= SQS_SECRET_ACCESS_KEY= SQS_ACCOUNT_ID= SQS_REGION= SQS_MAX_PAYLOAD_SIZE=1048576 # =========================================== # PUSHER # =========================================== PUSHER_ENABLED=false PUSHER_GLOBAL_ENABLED=false PUSHER_GLOBAL_APP_ID= PUSHER_GLOBAL_KEY= PUSHER_GLOBAL_SECRET= PUSHER_GLOBAL_CLUSTER= PUSHER_GLOBAL_USE_TLS=false # =========================================== # WHATSAPP BUSINESS # =========================================== WA_BUSINESS_TOKEN_WEBHOOK=evolution WA_BUSINESS_URL=https://graph.facebook.com WA_BUSINESS_VERSION=v18.0 WA_BUSINESS_LANGUAGE=en # =========================================== # CONFIGURAÇÕES DE SESSÃO # =========================================== CONFIG_SESSION_PHONE_CLIENT=Evolution API CONFIG_SESSION_PHONE_NAME=Chrome # =========================================== # QR CODE # =========================================== QRCODE_LIMIT=30 QRCODE_COLOR=#198754 # =========================================== # INTEGRAÇÕES # =========================================== # Typebot TYPEBOT_ENABLED=false TYPEBOT_API_VERSION=old TYPEBOT_SEND_MEDIA_BASE64=false # Chatwoot CHATWOOT_ENABLED=false CHATWOOT_MESSAGE_DELETE=false CHATWOOT_MESSAGE_READ=false CHATWOOT_BOT_CONTACT=true CHATWOOT_IMPORT_DATABASE_CONNECTION_URI= CHATWOOT_IMPORT_PLACEHOLDER_MEDIA_MESSAGE=false # OpenAI OPENAI_ENABLED=false OPENAI_API_KEY_GLOBAL= # Dify DIFY_ENABLED=false # N8N N8N_ENABLED=false # EvoAI EVOAI_ENABLED=false # Flowise FLOWISE_ENABLED=false # =========================================== # S3 / MINIO # =========================================== S3_ENABLED=false S3_ACCESS_KEY= S3_SECRET_KEY= S3_ENDPOINT= S3_BUCKET= S3_PORT=9000 S3_USE_SSL=false S3_REGION= S3_SKIP_POLICY=false S3_SAVE_VIDEO=false # =========================================== # MÉTRICAS # =========================================== PROMETHEUS_METRICS=false METRICS_AUTH_REQUIRED=false METRICS_USER= METRICS_PASSWORD= METRICS_ALLOWED_IPS= # =========================================== # TELEMETRIA # =========================================== TELEMETRY_ENABLED=true TELEMETRY_URL= # =========================================== # PROXY # =========================================== PROXY_HOST= PROXY_PORT= PROXY_PROTOCOL= PROXY_USERNAME= PROXY_PASSWORD= # =========================================== # CONVERSOR DE ÁUDIO # =========================================== API_AUDIO_CONVERTER= API_AUDIO_CONVERTER_KEY= # =========================================== # FACEBOOK # =========================================== FACEBOOK_APP_ID= FACEBOOK_CONFIG_ID= FACEBOOK_USER_TOKEN= # =========================================== # SENTRY # =========================================== SENTRY_DSN= # =========================================== # EVENT EMITTER # =========================================== EVENT_EMITTER_MAX_LISTENERS=50 # =========================================== # PROVIDER # =========================================== PROVIDER_ENABLED=false PROVIDER_HOST= PROVIDER_PORT=5656 PROVIDER_PREFIX=evolution ================================================ FILE: grafana-dashboard.json.example ================================================ { "dashboard": { "id": null, "title": "Evolution API Monitoring", "tags": ["evolution-api", "whatsapp", "monitoring"], "style": "dark", "timezone": "browser", "panels": [ { "id": 1, "title": "API Status", "type": "stat", "targets": [ { "expr": "up{job=\"evolution-api\"}", "legendFormat": "API Status" } ], "fieldConfig": { "defaults": { "mappings": [ { "options": { "0": { "text": "DOWN", "color": "red" }, "1": { "text": "UP", "color": "green" } }, "type": "value" } ] } }, "gridPos": { "h": 8, "w": 12, "x": 0, "y": 0 } }, { "id": 2, "title": "Total Instances", "type": "stat", "targets": [ { "expr": "evolution_instances_total", "legendFormat": "Total Instances" } ], "gridPos": { "h": 8, "w": 12, "x": 12, "y": 0 } }, { "id": 3, "title": "Instance Status Overview", "type": "piechart", "targets": [ { "expr": "sum by (state) (evolution_instance_state)", "legendFormat": "{{ state }}" } ], "gridPos": { "h": 9, "w": 12, "x": 0, "y": 8 } }, { "id": 4, "title": "Instances by Integration Type", "type": "piechart", "targets": [ { "expr": "sum by (integration) (evolution_instance_up)", "legendFormat": "{{ integration }}" } ], "gridPos": { "h": 9, "w": 12, "x": 12, "y": 8 } }, { "id": 5, "title": "Instance Uptime", "type": "table", "targets": [ { "expr": "evolution_instance_up", "format": "table", "instant": true } ], "transformations": [ { "id": "organize", "options": { "excludeByName": { "Time": true, "__name__": true }, "renameByName": { "instance": "Instance Name", "integration": "Integration Type", "Value": "Status" } } } ], "fieldConfig": { "overrides": [ { "matcher": { "id": "byName", "options": "Status" }, "properties": [ { "id": "mappings", "value": [ { "options": { "0": { "text": "DOWN", "color": "red" }, "1": { "text": "UP", "color": "green" } }, "type": "value" } ] } ] } ] }, "gridPos": { "h": 9, "w": 24, "x": 0, "y": 17 } }, { "id": 6, "title": "Instance Status Timeline", "type": "timeseries", "targets": [ { "expr": "evolution_instance_up", "legendFormat": "{{ instance }} ({{ integration }})" } ], "fieldConfig": { "defaults": { "custom": { "drawStyle": "line", "lineInterpolation": "stepAfter", "lineWidth": 2, "fillOpacity": 10, "gradientMode": "none", "spanNulls": false, "insertNulls": false, "showPoints": "never", "pointSize": 5, "stacking": { "mode": "none", "group": "A" }, "axisPlacement": "auto", "axisLabel": "", "scaleDistribution": { "type": "linear" }, "hideFrom": { "legend": false, "tooltip": false, "vis": false }, "thresholdsStyle": { "mode": "off" } }, "min": 0, "max": 1 } }, "gridPos": { "h": 8, "w": 24, "x": 0, "y": 26 } } ], "time": { "from": "now-1h", "to": "now" }, "timepicker": {}, "templating": { "list": [] }, "annotations": { "list": [ { "builtIn": 1, "datasource": "-- Grafana --", "enable": true, "hide": true, "iconColor": "rgba(0, 211, 255, 1)", "name": "Annotations & Alerts", "type": "dashboard" } ] }, "refresh": "30s", "schemaVersion": 27, "version": 0, "links": [] } } ================================================ FILE: local_install.sh ================================================ #!/bin/bash # Definir cores para melhor legibilidade RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color # Função para log log() { echo -e "${GREEN}[INFO]${NC} $1" } log_error() { echo -e "${RED}[ERROR]${NC} $1" } log_warning() { echo -e "${YELLOW}[WARNING]${NC} $1" } # Verificar se está rodando como root if [ "$(id -u)" = "0" ]; then log_error "Este script não deve ser executado como root" exit 1 fi # Verificar sistema operacional OS="$(uname -s)" case "${OS}" in Linux*) if [ ! -x "$(command -v curl)" ]; then log_warning "Curl não está instalado. Tentando instalar..." if [ -x "$(command -v apt-get)" ]; then sudo apt-get update && sudo apt-get install -y curl elif [ -x "$(command -v yum)" ]; then sudo yum install -y curl else log_error "Não foi possível instalar curl automaticamente. Por favor, instale manualmente." exit 1 fi fi ;; Darwin*) if [ ! -x "$(command -v curl)" ]; then log_error "Curl não está instalado. Por favor, instale o Xcode Command Line Tools." exit 1 fi ;; *) log_error "Sistema operacional não suportado: ${OS}" exit 1 ;; esac # Verificar conexão com a internet antes de prosseguir if ! ping -c 1 8.8.8.8 &> /dev/null; then log_error "Sem conexão com a internet. Por favor, verifique sua conexão." exit 1 fi # Adicionar verificação de espaço em disco REQUIRED_SPACE=1000000 # 1GB em KB AVAILABLE_SPACE=$(df -k . | awk 'NR==2 {print $4}') if [ $AVAILABLE_SPACE -lt $REQUIRED_SPACE ]; then log_error "Espaço em disco insuficiente. Necessário pelo menos 1GB livre." exit 1 fi # Adicionar tratamento de erro para comandos npm npm_install_with_retry() { local max_attempts=3 local attempt=1 while [ $attempt -le $max_attempts ]; do log "Tentativa $attempt de $max_attempts para npm install" if npm install; then return 0 fi attempt=$((attempt + 1)) [ $attempt -le $max_attempts ] && log_warning "Falha na instalação. Tentando novamente em 5 segundos..." && sleep 5 done log_error "Falha ao executar npm install após $max_attempts tentativas" return 1 } # Adicionar timeout para comandos execute_with_timeout() { timeout 300 $@ || log_error "Comando excedeu o tempo limite de 5 minutos: $@" } # Verificar se o NVM já está instalado if [ -d "$HOME/.nvm" ]; then log "NVM já está instalado." else log "Instalando NVM..." curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash fi # Carregar o NVM no ambiente atual export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # Verificar se a versão do Node.js já está instalada if command -v node >/dev/null 2>&1 && [ "$(node -v)" = "v20.10.0" ]; then log "Node.js v20.10.0 já está instalado." else log "Instalando Node.js v20.10.0..." nvm install v20.10.0 fi nvm use v20.10.0 # Verificar as versões instaladas log "Verificando as versões instaladas:" log "Node.js: $(node -v)" log "npm: $(npm -v)" # Instala dependências do projeto log "Instalando dependências do projeto..." rm -rf node_modules npm install # Deploy do banco de dados log "Deploy do banco de dados..." npm run db:generate npm run db:deploy # Iniciar o projeto log "Iniciando o projeto..." if [ "$1" = "-dev" ]; then npm run dev:server else npm run build npm run start:prod fi log "Instalação concluída com sucesso!" # Criar arquivo de log LOGFILE="./installation_log_$(date +%Y%m%d_%H%M%S).log" exec 1> >(tee -a "$LOGFILE") exec 2>&1 # Adicionar trap para limpeza em caso de interrupção cleanup() { log "Limpando recursos temporários..." # Adicione comandos de limpeza aqui } trap cleanup EXIT ================================================ FILE: manager/dist/assets/index-CO3NSIFj.js ================================================ var TD=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var tie=TD((ko,jo)=>{function Bk(e,t){for(var n=0;nr[s]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))r(s);new MutationObserver(s=>{for(const o of s)if(o.type==="childList")for(const l of o.addedNodes)l.tagName==="LINK"&&l.rel==="modulepreload"&&r(l)}).observe(document,{childList:!0,subtree:!0});function n(s){const o={};return s.integrity&&(o.integrity=s.integrity),s.referrerPolicy&&(o.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?o.credentials="include":s.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function r(s){if(s.ep)return;s.ep=!0;const o=n(s);fetch(s.href,o)}})();function fd(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var av={exports:{}},Xc={},iv={exports:{}},Et={};/** * @license React * react.production.min.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var A0;function ND(){if(A0)return Et;A0=1;var e=Symbol.for("react.element"),t=Symbol.for("react.portal"),n=Symbol.for("react.fragment"),r=Symbol.for("react.strict_mode"),s=Symbol.for("react.profiler"),o=Symbol.for("react.provider"),l=Symbol.for("react.context"),u=Symbol.for("react.forward_ref"),d=Symbol.for("react.suspense"),f=Symbol.for("react.memo"),h=Symbol.for("react.lazy"),m=Symbol.iterator;function g(A){return A===null||typeof A!="object"?null:(A=m&&A[m]||A["@@iterator"],typeof A=="function"?A:null)}var x={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},b=Object.assign,w={};function C(A,F,fe){this.props=A,this.context=F,this.refs=w,this.updater=fe||x}C.prototype.isReactComponent={},C.prototype.setState=function(A,F){if(typeof A!="object"&&typeof A!="function"&&A!=null)throw Error("setState(...): takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,A,F,"setState")},C.prototype.forceUpdate=function(A){this.updater.enqueueForceUpdate(this,A,"forceUpdate")};function k(){}k.prototype=C.prototype;function j(A,F,fe){this.props=A,this.context=F,this.refs=w,this.updater=fe||x}var M=j.prototype=new k;M.constructor=j,b(M,C.prototype),M.isPureReactComponent=!0;var _=Array.isArray,R=Object.prototype.hasOwnProperty,N={current:null},O={key:!0,ref:!0,__self:!0,__source:!0};function D(A,F,fe){var te,de={},ge=null,Z=null;if(F!=null)for(te in F.ref!==void 0&&(Z=F.ref),F.key!==void 0&&(ge=""+F.key),F)R.call(F,te)&&!O.hasOwnProperty(te)&&(de[te]=F[te]);var ye=arguments.length-2;if(ye===1)de.children=fe;else if(1{this.listeners.delete(e),this.onUnsubscribe()}}hasListeners(){return this.listeners.size>0}onSubscribe(){}onUnsubscribe(){}},Fl=typeof window>"u"||"Deno"in globalThis;function ss(){}function RD(e,t){return typeof e=="function"?e(t):e}function Sy(e){return typeof e=="number"&&e>=0&&e!==1/0}function zk(e,t){return Math.max(e+(t||0)-Date.now(),0)}function _l(e,t){return typeof e=="function"?e(t):e}function ws(e,t){return typeof e=="function"?e(t):e}function $0(e,t){const{type:n="all",exact:r,fetchStatus:s,predicate:o,queryKey:l,stale:u}=e;if(l){if(r){if(t.queryHash!==_b(l,t.options))return!1}else if(!Ou(t.queryKey,l))return!1}if(n!=="all"){const d=t.isActive();if(n==="active"&&!d||n==="inactive"&&d)return!1}return!(typeof u=="boolean"&&t.isStale()!==u||s&&s!==t.state.fetchStatus||o&&!o(t))}function B0(e,t){const{exact:n,status:r,predicate:s,mutationKey:o}=e;if(o){if(!t.options.mutationKey)return!1;if(n){if(xi(t.options.mutationKey)!==xi(o))return!1}else if(!Ou(t.options.mutationKey,o))return!1}return!(r&&t.state.status!==r||s&&!s(t))}function _b(e,t){return(t?.queryKeyHashFn||xi)(e)}function xi(e){return JSON.stringify(e,(t,n)=>Cy(n)?Object.keys(n).sort().reduce((r,s)=>(r[s]=n[s],r),{}):n)}function Ou(e,t){return e===t?!0:typeof e!=typeof t?!1:e&&t&&typeof e=="object"&&typeof t=="object"?!Object.keys(t).some(n=>!Ou(e[n],t[n])):!1}function Uk(e,t){if(e===t)return e;const n=z0(e)&&z0(t);if(n||Cy(e)&&Cy(t)){const r=n?e:Object.keys(e),s=r.length,o=n?t:Object.keys(t),l=o.length,u=n?[]:{};let d=0;for(let f=0;f{setTimeout(t,e)})}function Ey(e,t,n){return typeof n.structuralSharing=="function"?n.structuralSharing(e,t):n.structuralSharing!==!1?Uk(e,t):t}function OD(e,t,n=0){const r=[...e,t];return n&&r.length>n?r.slice(1):r}function ID(e,t,n=0){const r=[t,...e];return n&&r.length>n?r.slice(0,-1):r}var Vk=Symbol();function Hk(e,t){return!e.queryFn&&t?.initialPromise?()=>t.initialPromise:!e.queryFn||e.queryFn===Vk?()=>Promise.reject(new Error(`Missing queryFn: '${e.queryHash}'`)):e.queryFn}var AD=class extends Zl{#e;#t;#r;constructor(){super(),this.#r=e=>{if(!Fl&&window.addEventListener){const t=()=>e();return window.addEventListener("visibilitychange",t,!1),()=>{window.removeEventListener("visibilitychange",t)}}}}onSubscribe(){this.#t||this.setEventListener(this.#r)}onUnsubscribe(){this.hasListeners()||(this.#t?.(),this.#t=void 0)}setEventListener(e){this.#r=e,this.#t?.(),this.#t=e(t=>{typeof t=="boolean"?this.setFocused(t):this.onFocus()})}setFocused(e){this.#e!==e&&(this.#e=e,this.onFocus())}onFocus(){const e=this.isFocused();this.listeners.forEach(t=>{t(e)})}isFocused(){return typeof this.#e=="boolean"?this.#e:globalThis.document?.visibilityState!=="hidden"}},Rb=new AD,DD=class extends Zl{#e=!0;#t;#r;constructor(){super(),this.#r=e=>{if(!Fl&&window.addEventListener){const t=()=>e(!0),n=()=>e(!1);return window.addEventListener("online",t,!1),window.addEventListener("offline",n,!1),()=>{window.removeEventListener("online",t),window.removeEventListener("offline",n)}}}}onSubscribe(){this.#t||this.setEventListener(this.#r)}onUnsubscribe(){this.hasListeners()||(this.#t?.(),this.#t=void 0)}setEventListener(e){this.#r=e,this.#t?.(),this.#t=e(this.setOnline.bind(this))}setOnline(e){this.#e!==e&&(this.#e=e,this.listeners.forEach(n=>{n(e)}))}isOnline(){return this.#e}},_p=new DD;function FD(e){return Math.min(1e3*2**e,3e4)}function qk(e){return(e??"online")==="online"?_p.isOnline():!0}var Kk=class extends Error{constructor(e){super("CancelledError"),this.revert=e?.revert,this.silent=e?.silent}};function lv(e){return e instanceof Kk}function Wk(e){let t=!1,n=0,r=!1,s,o,l;const u=new Promise((k,j)=>{o=k,l=j}),d=k=>{r||(b(new Kk(k)),e.abort?.())},f=()=>{t=!0},h=()=>{t=!1},m=()=>Rb.isFocused()&&(e.networkMode==="always"||_p.isOnline())&&e.canRun(),g=()=>qk(e.networkMode)&&e.canRun(),x=k=>{r||(r=!0,e.onSuccess?.(k),s?.(),o(k))},b=k=>{r||(r=!0,e.onError?.(k),s?.(),l(k))},w=()=>new Promise(k=>{s=j=>{(r||m())&&k(j)},e.onPause?.()}).then(()=>{s=void 0,r||e.onContinue?.()}),C=()=>{if(r)return;let k;const j=n===0?e.initialPromise:void 0;try{k=j??e.fn()}catch(M){k=Promise.reject(M)}Promise.resolve(k).then(x).catch(M=>{if(r)return;const _=e.retry??(Fl?0:3),R=e.retryDelay??FD,N=typeof R=="function"?R(n,M):R,O=_===!0||typeof _=="number"&&n<_||typeof _=="function"&&_(n,M);if(t||!O){b(M);return}n++,e.onFail?.(n,M),PD(N).then(()=>m()?void 0:w()).then(()=>{t?b(M):C()})})};return{promise:u,cancel:d,continue:()=>(s?.(),u),cancelRetry:f,continueRetry:h,canStart:g,start:()=>(g()?C():w().then(C),u)}}function LD(){let e=[],t=0,n=g=>{g()},r=g=>{g()},s=g=>setTimeout(g,0);const o=g=>{s=g},l=g=>{let x;t++;try{x=g()}finally{t--,t||f()}return x},u=g=>{t?e.push(g):s(()=>{n(g)})},d=g=>(...x)=>{u(()=>{g(...x)})},f=()=>{const g=e;e=[],g.length&&s(()=>{r(()=>{g.forEach(x=>{n(x)})})})};return{batch:l,batchCalls:d,schedule:u,setNotifyFunction:g=>{n=g},setBatchNotifyFunction:g=>{r=g},setScheduler:o}}var Fn=LD(),Gk=class{#e;destroy(){this.clearGcTimeout()}scheduleGc(){this.clearGcTimeout(),Sy(this.gcTime)&&(this.#e=setTimeout(()=>{this.optionalRemove()},this.gcTime))}updateGcTime(e){this.gcTime=Math.max(this.gcTime||0,e??(Fl?1/0:300*1e3))}clearGcTimeout(){this.#e&&(clearTimeout(this.#e),this.#e=void 0)}},$D=class extends Gk{#e;#t;#r;#n;#a;#o;constructor(e){super(),this.#o=!1,this.#a=e.defaultOptions,this.setOptions(e.options),this.observers=[],this.#r=e.cache,this.queryKey=e.queryKey,this.queryHash=e.queryHash,this.#e=BD(this.options),this.state=e.state??this.#e,this.scheduleGc()}get meta(){return this.options.meta}get promise(){return this.#n?.promise}setOptions(e){this.options={...this.#a,...e},this.updateGcTime(this.options.gcTime)}optionalRemove(){!this.observers.length&&this.state.fetchStatus==="idle"&&this.#r.remove(this)}setData(e,t){const n=Ey(this.state.data,e,this.options);return this.#s({data:n,type:"success",dataUpdatedAt:t?.updatedAt,manual:t?.manual}),n}setState(e,t){this.#s({type:"setState",state:e,setStateOptions:t})}cancel(e){const t=this.#n?.promise;return this.#n?.cancel(e),t?t.then(ss).catch(ss):Promise.resolve()}destroy(){super.destroy(),this.cancel({silent:!0})}reset(){this.destroy(),this.setState(this.#e)}isActive(){return this.observers.some(e=>ws(e.options.enabled,this)!==!1)}isDisabled(){return this.getObserversCount()>0&&!this.isActive()}isStale(){return this.state.isInvalidated?!0:this.getObserversCount()>0?this.observers.some(e=>e.getCurrentResult().isStale):this.state.data===void 0}isStaleByTime(e=0){return this.state.isInvalidated||this.state.data===void 0||!zk(this.state.dataUpdatedAt,e)}onFocus(){this.observers.find(t=>t.shouldFetchOnWindowFocus())?.refetch({cancelRefetch:!1}),this.#n?.continue()}onOnline(){this.observers.find(t=>t.shouldFetchOnReconnect())?.refetch({cancelRefetch:!1}),this.#n?.continue()}addObserver(e){this.observers.includes(e)||(this.observers.push(e),this.clearGcTimeout(),this.#r.notify({type:"observerAdded",query:this,observer:e}))}removeObserver(e){this.observers.includes(e)&&(this.observers=this.observers.filter(t=>t!==e),this.observers.length||(this.#n&&(this.#o?this.#n.cancel({revert:!0}):this.#n.cancelRetry()),this.scheduleGc()),this.#r.notify({type:"observerRemoved",query:this,observer:e}))}getObserversCount(){return this.observers.length}invalidate(){this.state.isInvalidated||this.#s({type:"invalidate"})}fetch(e,t){if(this.state.fetchStatus!=="idle"){if(this.state.data!==void 0&&t?.cancelRefetch)this.cancel({silent:!0});else if(this.#n)return this.#n.continueRetry(),this.#n.promise}if(e&&this.setOptions(e),!this.options.queryFn){const u=this.observers.find(d=>d.options.queryFn);u&&this.setOptions(u.options)}const n=new AbortController,r=u=>{Object.defineProperty(u,"signal",{enumerable:!0,get:()=>(this.#o=!0,n.signal)})},s=()=>{const u=Hk(this.options,t),d={queryKey:this.queryKey,meta:this.meta};return r(d),this.#o=!1,this.options.persister?this.options.persister(u,d,this):u(d)},o={fetchOptions:t,options:this.options,queryKey:this.queryKey,state:this.state,fetchFn:s};r(o),this.options.behavior?.onFetch(o,this),this.#t=this.state,(this.state.fetchStatus==="idle"||this.state.fetchMeta!==o.fetchOptions?.meta)&&this.#s({type:"fetch",meta:o.fetchOptions?.meta});const l=u=>{lv(u)&&u.silent||this.#s({type:"error",error:u}),lv(u)||(this.#r.config.onError?.(u,this),this.#r.config.onSettled?.(this.state.data,u,this)),this.isFetchingOptimistic||this.scheduleGc(),this.isFetchingOptimistic=!1};return this.#n=Wk({initialPromise:t?.initialPromise,fn:o.fetchFn,abort:n.abort.bind(n),onSuccess:u=>{if(u===void 0){l(new Error(`${this.queryHash} data is undefined`));return}try{this.setData(u)}catch(d){l(d);return}this.#r.config.onSuccess?.(u,this),this.#r.config.onSettled?.(u,this.state.error,this),this.isFetchingOptimistic||this.scheduleGc(),this.isFetchingOptimistic=!1},onError:l,onFail:(u,d)=>{this.#s({type:"failed",failureCount:u,error:d})},onPause:()=>{this.#s({type:"pause"})},onContinue:()=>{this.#s({type:"continue"})},retry:o.options.retry,retryDelay:o.options.retryDelay,networkMode:o.options.networkMode,canRun:()=>!0}),this.#n.start()}#s(e){const t=n=>{switch(e.type){case"failed":return{...n,fetchFailureCount:e.failureCount,fetchFailureReason:e.error};case"pause":return{...n,fetchStatus:"paused"};case"continue":return{...n,fetchStatus:"fetching"};case"fetch":return{...n,...Jk(n.data,this.options),fetchMeta:e.meta??null};case"success":return{...n,data:e.data,dataUpdateCount:n.dataUpdateCount+1,dataUpdatedAt:e.dataUpdatedAt??Date.now(),error:null,isInvalidated:!1,status:"success",...!e.manual&&{fetchStatus:"idle",fetchFailureCount:0,fetchFailureReason:null}};case"error":const r=e.error;return lv(r)&&r.revert&&this.#t?{...this.#t,fetchStatus:"idle"}:{...n,error:r,errorUpdateCount:n.errorUpdateCount+1,errorUpdatedAt:Date.now(),fetchFailureCount:n.fetchFailureCount+1,fetchFailureReason:r,fetchStatus:"idle",status:"error"};case"invalidate":return{...n,isInvalidated:!0};case"setState":return{...n,...e.state}}};this.state=t(this.state),Fn.batch(()=>{this.observers.forEach(n=>{n.onQueryUpdate()}),this.#r.notify({query:this,type:"updated",action:e})})}};function Jk(e,t){return{fetchFailureCount:0,fetchFailureReason:null,fetchStatus:qk(t.networkMode)?"fetching":"paused",...e===void 0&&{error:null,status:"pending"}}}function BD(e){const t=typeof e.initialData=="function"?e.initialData():e.initialData,n=t!==void 0,r=n?typeof e.initialDataUpdatedAt=="function"?e.initialDataUpdatedAt():e.initialDataUpdatedAt:0;return{data:t,dataUpdateCount:0,dataUpdatedAt:n?r??Date.now():0,error:null,errorUpdateCount:0,errorUpdatedAt:0,fetchFailureCount:0,fetchFailureReason:null,fetchMeta:null,isInvalidated:!1,status:n?"success":"pending",fetchStatus:"idle"}}var zD=class extends Zl{constructor(e={}){super(),this.config=e,this.#e=new Map}#e;build(e,t,n){const r=t.queryKey,s=t.queryHash??_b(r,t);let o=this.get(s);return o||(o=new $D({cache:this,queryKey:r,queryHash:s,options:e.defaultQueryOptions(t),state:n,defaultOptions:e.getQueryDefaults(r)}),this.add(o)),o}add(e){this.#e.has(e.queryHash)||(this.#e.set(e.queryHash,e),this.notify({type:"added",query:e}))}remove(e){const t=this.#e.get(e.queryHash);t&&(e.destroy(),t===e&&this.#e.delete(e.queryHash),this.notify({type:"removed",query:e}))}clear(){Fn.batch(()=>{this.getAll().forEach(e=>{this.remove(e)})})}get(e){return this.#e.get(e)}getAll(){return[...this.#e.values()]}find(e){const t={exact:!0,...e};return this.getAll().find(n=>$0(t,n))}findAll(e={}){const t=this.getAll();return Object.keys(e).length>0?t.filter(n=>$0(e,n)):t}notify(e){Fn.batch(()=>{this.listeners.forEach(t=>{t(e)})})}onFocus(){Fn.batch(()=>{this.getAll().forEach(e=>{e.onFocus()})})}onOnline(){Fn.batch(()=>{this.getAll().forEach(e=>{e.onOnline()})})}},UD=class extends Gk{#e;#t;#r;constructor(e){super(),this.mutationId=e.mutationId,this.#t=e.mutationCache,this.#e=[],this.state=e.state||Qk(),this.setOptions(e.options),this.scheduleGc()}setOptions(e){this.options=e,this.updateGcTime(this.options.gcTime)}get meta(){return this.options.meta}addObserver(e){this.#e.includes(e)||(this.#e.push(e),this.clearGcTimeout(),this.#t.notify({type:"observerAdded",mutation:this,observer:e}))}removeObserver(e){this.#e=this.#e.filter(t=>t!==e),this.scheduleGc(),this.#t.notify({type:"observerRemoved",mutation:this,observer:e})}optionalRemove(){this.#e.length||(this.state.status==="pending"?this.scheduleGc():this.#t.remove(this))}continue(){return this.#r?.continue()??this.execute(this.state.variables)}async execute(e){this.#r=Wk({fn:()=>this.options.mutationFn?this.options.mutationFn(e):Promise.reject(new Error("No mutationFn found")),onFail:(r,s)=>{this.#n({type:"failed",failureCount:r,error:s})},onPause:()=>{this.#n({type:"pause"})},onContinue:()=>{this.#n({type:"continue"})},retry:this.options.retry??0,retryDelay:this.options.retryDelay,networkMode:this.options.networkMode,canRun:()=>this.#t.canRun(this)});const t=this.state.status==="pending",n=!this.#r.canStart();try{if(!t){this.#n({type:"pending",variables:e,isPaused:n}),await this.#t.config.onMutate?.(e,this);const s=await this.options.onMutate?.(e);s!==this.state.context&&this.#n({type:"pending",context:s,variables:e,isPaused:n})}const r=await this.#r.start();return await this.#t.config.onSuccess?.(r,e,this.state.context,this),await this.options.onSuccess?.(r,e,this.state.context),await this.#t.config.onSettled?.(r,null,this.state.variables,this.state.context,this),await this.options.onSettled?.(r,null,e,this.state.context),this.#n({type:"success",data:r}),r}catch(r){try{throw await this.#t.config.onError?.(r,e,this.state.context,this),await this.options.onError?.(r,e,this.state.context),await this.#t.config.onSettled?.(void 0,r,this.state.variables,this.state.context,this),await this.options.onSettled?.(void 0,r,e,this.state.context),r}finally{this.#n({type:"error",error:r})}}finally{this.#t.runNext(this)}}#n(e){const t=n=>{switch(e.type){case"failed":return{...n,failureCount:e.failureCount,failureReason:e.error};case"pause":return{...n,isPaused:!0};case"continue":return{...n,isPaused:!1};case"pending":return{...n,context:e.context,data:void 0,failureCount:0,failureReason:null,error:null,isPaused:e.isPaused,status:"pending",variables:e.variables,submittedAt:Date.now()};case"success":return{...n,data:e.data,failureCount:0,failureReason:null,error:null,status:"success",isPaused:!1};case"error":return{...n,data:void 0,error:e.error,failureCount:n.failureCount+1,failureReason:e.error,isPaused:!1,status:"error"}}};this.state=t(this.state),Fn.batch(()=>{this.#e.forEach(n=>{n.onMutationUpdate(e)}),this.#t.notify({mutation:this,type:"updated",action:e})})}};function Qk(){return{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:"idle",variables:void 0,submittedAt:0}}var VD=class extends Zl{constructor(e={}){super(),this.config=e,this.#e=new Map,this.#t=Date.now()}#e;#t;build(e,t,n){const r=new UD({mutationCache:this,mutationId:++this.#t,options:e.defaultMutationOptions(t),state:n});return this.add(r),r}add(e){const t=Df(e),n=this.#e.get(t)??[];n.push(e),this.#e.set(t,n),this.notify({type:"added",mutation:e})}remove(e){const t=Df(e);if(this.#e.has(t)){const n=this.#e.get(t)?.filter(r=>r!==e);n&&(n.length===0?this.#e.delete(t):this.#e.set(t,n))}this.notify({type:"removed",mutation:e})}canRun(e){const t=this.#e.get(Df(e))?.find(n=>n.state.status==="pending");return!t||t===e}runNext(e){return this.#e.get(Df(e))?.find(n=>n!==e&&n.state.isPaused)?.continue()??Promise.resolve()}clear(){Fn.batch(()=>{this.getAll().forEach(e=>{this.remove(e)})})}getAll(){return[...this.#e.values()].flat()}find(e){const t={exact:!0,...e};return this.getAll().find(n=>B0(t,n))}findAll(e={}){return this.getAll().filter(t=>B0(e,t))}notify(e){Fn.batch(()=>{this.listeners.forEach(t=>{t(e)})})}resumePausedMutations(){const e=this.getAll().filter(t=>t.state.isPaused);return Fn.batch(()=>Promise.all(e.map(t=>t.continue().catch(ss))))}};function Df(e){return e.options.scope?.id??String(e.mutationId)}function HD(e){return{onFetch:(t,n)=>{const r=async()=>{const s=t.options,o=t.fetchOptions?.meta?.fetchMore?.direction,l=t.state.data?.pages||[],u=t.state.data?.pageParams||[],d={pages:[],pageParams:[]};let f=!1;const h=b=>{Object.defineProperty(b,"signal",{enumerable:!0,get:()=>(t.signal.aborted?f=!0:t.signal.addEventListener("abort",()=>{f=!0}),t.signal)})},m=Hk(t.options,t.fetchOptions),g=async(b,w,C)=>{if(f)return Promise.reject();if(w==null&&b.pages.length)return Promise.resolve(b);const k={queryKey:t.queryKey,pageParam:w,direction:C?"backward":"forward",meta:t.options.meta};h(k);const j=await m(k),{maxPages:M}=t.options,_=C?ID:OD;return{pages:_(b.pages,j,M),pageParams:_(b.pageParams,w,M)}};let x;if(o&&l.length){const b=o==="backward",w=b?qD:V0,C={pages:l,pageParams:u},k=w(s,C);x=await g(C,k,b)}else{x=await g(d,u[0]??s.initialPageParam);const b=e??l.length;for(let w=1;wt.options.persister?.(r,{queryKey:t.queryKey,meta:t.options.meta,signal:t.signal},n):t.fetchFn=r}}}function V0(e,{pages:t,pageParams:n}){const r=t.length-1;return t.length>0?e.getNextPageParam(t[r],t,n[r],n):void 0}function qD(e,{pages:t,pageParams:n}){return t.length>0?e.getPreviousPageParam?.(t[0],t,n[0],n):void 0}var KD=class{#e;#t;#r;#n;#a;#o;#s;#i;constructor(e={}){this.#e=e.queryCache||new zD,this.#t=e.mutationCache||new VD,this.#r=e.defaultOptions||{},this.#n=new Map,this.#a=new Map,this.#o=0}mount(){this.#o++,this.#o===1&&(this.#s=Rb.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#e.onFocus())}),this.#i=_p.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#e.onOnline())}))}unmount(){this.#o--,this.#o===0&&(this.#s?.(),this.#s=void 0,this.#i?.(),this.#i=void 0)}isFetching(e){return this.#e.findAll({...e,fetchStatus:"fetching"}).length}isMutating(e){return this.#t.findAll({...e,status:"pending"}).length}getQueryData(e){const t=this.defaultQueryOptions({queryKey:e});return this.#e.get(t.queryHash)?.state.data}ensureQueryData(e){const t=this.getQueryData(e.queryKey);if(t===void 0)return this.fetchQuery(e);{const n=this.defaultQueryOptions(e),r=this.#e.build(this,n);return e.revalidateIfStale&&r.isStaleByTime(_l(n.staleTime,r))&&this.prefetchQuery(n),Promise.resolve(t)}}getQueriesData(e){return this.#e.findAll(e).map(({queryKey:t,state:n})=>{const r=n.data;return[t,r]})}setQueryData(e,t,n){const r=this.defaultQueryOptions({queryKey:e}),o=this.#e.get(r.queryHash)?.state.data,l=RD(t,o);if(l!==void 0)return this.#e.build(this,r).setData(l,{...n,manual:!0})}setQueriesData(e,t,n){return Fn.batch(()=>this.#e.findAll(e).map(({queryKey:r})=>[r,this.setQueryData(r,t,n)]))}getQueryState(e){const t=this.defaultQueryOptions({queryKey:e});return this.#e.get(t.queryHash)?.state}removeQueries(e){const t=this.#e;Fn.batch(()=>{t.findAll(e).forEach(n=>{t.remove(n)})})}resetQueries(e,t){const n=this.#e,r={type:"active",...e};return Fn.batch(()=>(n.findAll(e).forEach(s=>{s.reset()}),this.refetchQueries(r,t)))}cancelQueries(e={},t={}){const n={revert:!0,...t},r=Fn.batch(()=>this.#e.findAll(e).map(s=>s.cancel(n)));return Promise.all(r).then(ss).catch(ss)}invalidateQueries(e={},t={}){return Fn.batch(()=>{if(this.#e.findAll(e).forEach(r=>{r.invalidate()}),e.refetchType==="none")return Promise.resolve();const n={...e,type:e.refetchType??e.type??"active"};return this.refetchQueries(n,t)})}refetchQueries(e={},t){const n={...t,cancelRefetch:t?.cancelRefetch??!0},r=Fn.batch(()=>this.#e.findAll(e).filter(s=>!s.isDisabled()).map(s=>{let o=s.fetch(void 0,n);return n.throwOnError||(o=o.catch(ss)),s.state.fetchStatus==="paused"?Promise.resolve():o}));return Promise.all(r).then(ss)}fetchQuery(e){const t=this.defaultQueryOptions(e);t.retry===void 0&&(t.retry=!1);const n=this.#e.build(this,t);return n.isStaleByTime(_l(t.staleTime,n))?n.fetch(t):Promise.resolve(n.state.data)}prefetchQuery(e){return this.fetchQuery(e).then(ss).catch(ss)}fetchInfiniteQuery(e){return e.behavior=HD(e.pages),this.fetchQuery(e)}prefetchInfiniteQuery(e){return this.fetchInfiniteQuery(e).then(ss).catch(ss)}resumePausedMutations(){return _p.isOnline()?this.#t.resumePausedMutations():Promise.resolve()}getQueryCache(){return this.#e}getMutationCache(){return this.#t}getDefaultOptions(){return this.#r}setDefaultOptions(e){this.#r=e}setQueryDefaults(e,t){this.#n.set(xi(e),{queryKey:e,defaultOptions:t})}getQueryDefaults(e){const t=[...this.#n.values()];let n={};return t.forEach(r=>{Ou(e,r.queryKey)&&(n={...n,...r.defaultOptions})}),n}setMutationDefaults(e,t){this.#a.set(xi(e),{mutationKey:e,defaultOptions:t})}getMutationDefaults(e){const t=[...this.#a.values()];let n={};return t.forEach(r=>{Ou(e,r.mutationKey)&&(n={...n,...r.defaultOptions})}),n}defaultQueryOptions(e){if(e._defaulted)return e;const t={...this.#r.queries,...this.getQueryDefaults(e.queryKey),...e,_defaulted:!0};return t.queryHash||(t.queryHash=_b(t.queryKey,t)),t.refetchOnReconnect===void 0&&(t.refetchOnReconnect=t.networkMode!=="always"),t.throwOnError===void 0&&(t.throwOnError=!!t.suspense),!t.networkMode&&t.persister&&(t.networkMode="offlineFirst"),t.enabled!==!0&&t.queryFn===Vk&&(t.enabled=!1),t}defaultMutationOptions(e){return e?._defaulted?e:{...this.#r.mutations,...e?.mutationKey&&this.getMutationDefaults(e.mutationKey),...e,_defaulted:!0}}clear(){this.#e.clear(),this.#t.clear()}},WD=class extends Zl{constructor(e,t){super(),this.options=t,this.#e=e,this.#s=null,this.bindMethods(),this.setOptions(t)}#e;#t=void 0;#r=void 0;#n=void 0;#a;#o;#s;#i;#f;#p;#c;#u;#l;#h=new Set;bindMethods(){this.refetch=this.refetch.bind(this)}onSubscribe(){this.listeners.size===1&&(this.#t.addObserver(this),H0(this.#t,this.options)?this.#d():this.updateResult(),this.#y())}onUnsubscribe(){this.hasListeners()||this.destroy()}shouldFetchOnReconnect(){return ky(this.#t,this.options,this.options.refetchOnReconnect)}shouldFetchOnWindowFocus(){return ky(this.#t,this.options,this.options.refetchOnWindowFocus)}destroy(){this.listeners=new Set,this.#b(),this.#x(),this.#t.removeObserver(this)}setOptions(e,t){const n=this.options,r=this.#t;if(this.options=this.#e.defaultQueryOptions(e),this.options.enabled!==void 0&&typeof this.options.enabled!="boolean"&&typeof this.options.enabled!="function"&&typeof ws(this.options.enabled,this.#t)!="boolean")throw new Error("Expected enabled to be a boolean or a callback that returns a boolean");this.#w(),this.#t.setOptions(this.options),n._defaulted&&!Mp(this.options,n)&&this.#e.getQueryCache().notify({type:"observerOptionsUpdated",query:this.#t,observer:this});const s=this.hasListeners();s&&q0(this.#t,r,this.options,n)&&this.#d(),this.updateResult(t),s&&(this.#t!==r||ws(this.options.enabled,this.#t)!==ws(n.enabled,this.#t)||_l(this.options.staleTime,this.#t)!==_l(n.staleTime,this.#t))&&this.#g();const o=this.#m();s&&(this.#t!==r||ws(this.options.enabled,this.#t)!==ws(n.enabled,this.#t)||o!==this.#l)&&this.#v(o)}getOptimisticResult(e){const t=this.#e.getQueryCache().build(this.#e,e),n=this.createResult(t,e);return JD(this,n)&&(this.#n=n,this.#o=this.options,this.#a=this.#t.state),n}getCurrentResult(){return this.#n}trackResult(e,t){const n={};return Object.keys(e).forEach(r=>{Object.defineProperty(n,r,{configurable:!1,enumerable:!0,get:()=>(this.trackProp(r),t?.(r),e[r])})}),n}trackProp(e){this.#h.add(e)}getCurrentQuery(){return this.#t}refetch({...e}={}){return this.fetch({...e})}fetchOptimistic(e){const t=this.#e.defaultQueryOptions(e),n=this.#e.getQueryCache().build(this.#e,t);return n.isFetchingOptimistic=!0,n.fetch().then(()=>this.createResult(n,t))}fetch(e){return this.#d({...e,cancelRefetch:e.cancelRefetch??!0}).then(()=>(this.updateResult(),this.#n))}#d(e){this.#w();let t=this.#t.fetch(this.options,e);return e?.throwOnError||(t=t.catch(ss)),t}#g(){this.#b();const e=_l(this.options.staleTime,this.#t);if(Fl||this.#n.isStale||!Sy(e))return;const n=zk(this.#n.dataUpdatedAt,e)+1;this.#c=setTimeout(()=>{this.#n.isStale||this.updateResult()},n)}#m(){return(typeof this.options.refetchInterval=="function"?this.options.refetchInterval(this.#t):this.options.refetchInterval)??!1}#v(e){this.#x(),this.#l=e,!(Fl||ws(this.options.enabled,this.#t)===!1||!Sy(this.#l)||this.#l===0)&&(this.#u=setInterval(()=>{(this.options.refetchIntervalInBackground||Rb.isFocused())&&this.#d()},this.#l))}#y(){this.#g(),this.#v(this.#m())}#b(){this.#c&&(clearTimeout(this.#c),this.#c=void 0)}#x(){this.#u&&(clearInterval(this.#u),this.#u=void 0)}createResult(e,t){const n=this.#t,r=this.options,s=this.#n,o=this.#a,l=this.#o,d=e!==n?e.state:this.#r,{state:f}=e;let h={...f},m=!1,g;if(t._optimisticResults){const N=this.hasListeners(),O=!N&&H0(e,t),D=N&&q0(e,n,t,r);(O||D)&&(h={...h,...Jk(f.data,e.options)}),t._optimisticResults==="isRestoring"&&(h.fetchStatus="idle")}let{error:x,errorUpdatedAt:b,status:w}=h;if(t.select&&h.data!==void 0)if(s&&h.data===o?.data&&t.select===this.#i)g=this.#f;else try{this.#i=t.select,g=t.select(h.data),g=Ey(s?.data,g,t),this.#f=g,this.#s=null}catch(N){this.#s=N}else g=h.data;if(t.placeholderData!==void 0&&g===void 0&&w==="pending"){let N;if(s?.isPlaceholderData&&t.placeholderData===l?.placeholderData)N=s.data;else if(N=typeof t.placeholderData=="function"?t.placeholderData(this.#p?.state.data,this.#p):t.placeholderData,t.select&&N!==void 0)try{N=t.select(N),this.#s=null}catch(O){this.#s=O}N!==void 0&&(w="success",g=Ey(s?.data,N,t),m=!0)}this.#s&&(x=this.#s,g=this.#f,b=Date.now(),w="error");const C=h.fetchStatus==="fetching",k=w==="pending",j=w==="error",M=k&&C,_=g!==void 0;return{status:w,fetchStatus:h.fetchStatus,isPending:k,isSuccess:w==="success",isError:j,isInitialLoading:M,isLoading:M,data:g,dataUpdatedAt:h.dataUpdatedAt,error:x,errorUpdatedAt:b,failureCount:h.fetchFailureCount,failureReason:h.fetchFailureReason,errorUpdateCount:h.errorUpdateCount,isFetched:h.dataUpdateCount>0||h.errorUpdateCount>0,isFetchedAfterMount:h.dataUpdateCount>d.dataUpdateCount||h.errorUpdateCount>d.errorUpdateCount,isFetching:C,isRefetching:C&&!k,isLoadingError:j&&!_,isPaused:h.fetchStatus==="paused",isPlaceholderData:m,isRefetchError:j&&_,isStale:Pb(e,t),refetch:this.refetch}}updateResult(e){const t=this.#n,n=this.createResult(this.#t,this.options);if(this.#a=this.#t.state,this.#o=this.options,this.#a.data!==void 0&&(this.#p=this.#t),Mp(n,t))return;this.#n=n;const r={},s=()=>{if(!t)return!0;const{notifyOnChangeProps:o}=this.options,l=typeof o=="function"?o():o;if(l==="all"||!l&&!this.#h.size)return!0;const u=new Set(l??this.#h);return this.options.throwOnError&&u.add("error"),Object.keys(this.#n).some(d=>{const f=d;return this.#n[f]!==t[f]&&u.has(f)})};e?.listeners!==!1&&s()&&(r.listeners=!0),this.#S({...r,...e})}#w(){const e=this.#e.getQueryCache().build(this.#e,this.options);if(e===this.#t)return;const t=this.#t;this.#t=e,this.#r=e.state,this.hasListeners()&&(t?.removeObserver(this),e.addObserver(this))}onQueryUpdate(){this.updateResult(),this.hasListeners()&&this.#y()}#S(e){Fn.batch(()=>{e.listeners&&this.listeners.forEach(t=>{t(this.#n)}),this.#e.getQueryCache().notify({query:this.#t,type:"observerResultsUpdated"})})}};function GD(e,t){return ws(t.enabled,e)!==!1&&e.state.data===void 0&&!(e.state.status==="error"&&t.retryOnMount===!1)}function H0(e,t){return GD(e,t)||e.state.data!==void 0&&ky(e,t,t.refetchOnMount)}function ky(e,t,n){if(ws(t.enabled,e)!==!1){const r=typeof n=="function"?n(e):n;return r==="always"||r!==!1&&Pb(e,t)}return!1}function q0(e,t,n,r){return(e!==t||ws(r.enabled,e)===!1)&&(!n.suspense||e.state.status!=="error")&&Pb(e,n)}function Pb(e,t){return ws(t.enabled,e)!==!1&&e.isStaleByTime(_l(t.staleTime,e))}function JD(e,t){return!Mp(e.getCurrentResult(),t)}var QD=class extends Zl{#e;#t=void 0;#r;#n;constructor(t,n){super(),this.#e=t,this.setOptions(n),this.bindMethods(),this.#a()}bindMethods(){this.mutate=this.mutate.bind(this),this.reset=this.reset.bind(this)}setOptions(t){const n=this.options;this.options=this.#e.defaultMutationOptions(t),Mp(this.options,n)||this.#e.getMutationCache().notify({type:"observerOptionsUpdated",mutation:this.#r,observer:this}),n?.mutationKey&&this.options.mutationKey&&xi(n.mutationKey)!==xi(this.options.mutationKey)?this.reset():this.#r?.state.status==="pending"&&this.#r.setOptions(this.options)}onUnsubscribe(){this.hasListeners()||this.#r?.removeObserver(this)}onMutationUpdate(t){this.#a(),this.#o(t)}getCurrentResult(){return this.#t}reset(){this.#r?.removeObserver(this),this.#r=void 0,this.#a(),this.#o()}mutate(t,n){return this.#n=n,this.#r?.removeObserver(this),this.#r=this.#e.getMutationCache().build(this.#e,this.options),this.#r.addObserver(this),this.#r.execute(t)}#a(){const t=this.#r?.state??Qk();this.#t={...t,isPending:t.status==="pending",isSuccess:t.status==="success",isError:t.status==="error",isIdle:t.status==="idle",mutate:this.mutate,reset:this.reset}}#o(t){Fn.batch(()=>{if(this.#n&&this.hasListeners()){const n=this.#t.variables,r=this.#t.context;t?.type==="success"?(this.#n.onSuccess?.(t.data,n,r),this.#n.onSettled?.(t.data,null,n,r)):t?.type==="error"&&(this.#n.onError?.(t.error,n,r),this.#n.onSettled?.(void 0,t.error,n,r))}this.listeners.forEach(n=>{n(this.#t)})})}},y=pd();const qe=fd(y),Yl=Bk({__proto__:null,default:qe},[y]);var Zk=y.createContext(void 0),Ob=e=>{const t=y.useContext(Zk);if(!t)throw new Error("No QueryClient set, use QueryClientProvider to set one");return t},Yk=({client:e,children:t})=>(y.useEffect(()=>(e.mount(),()=>{e.unmount()}),[e]),i.jsx(Zk.Provider,{value:e,children:t})),Xk=y.createContext(!1),ZD=()=>y.useContext(Xk);Xk.Provider;function YD(){let e=!1;return{clearReset:()=>{e=!1},reset:()=>{e=!0},isReset:()=>e}}var XD=y.createContext(YD()),eF=()=>y.useContext(XD);function ej(e,t){return typeof e=="function"?e(...t):!!e}function tF(){}var nF=(e,t)=>{(e.suspense||e.throwOnError)&&(t.isReset()||(e.retryOnMount=!1))},rF=e=>{y.useEffect(()=>{e.clearReset()},[e])},sF=({result:e,errorResetBoundary:t,throwOnError:n,query:r})=>e.isError&&!t.isReset()&&!e.isFetching&&r&&ej(n,[e.error,r]),oF=e=>{e.suspense&&(typeof e.staleTime!="number"&&(e.staleTime=1e3),typeof e.gcTime=="number"&&(e.gcTime=Math.max(e.gcTime,1e3)))},aF=(e,t)=>e?.suspense&&t.isPending,iF=(e,t,n)=>t.fetchOptimistic(e).catch(()=>{n.clearReset()});function lF(e,t,n){const r=Ob(),s=ZD(),o=eF(),l=r.defaultQueryOptions(e);r.getDefaultOptions().queries?._experimental_beforeQuery?.(l),l._optimisticResults=s?"isRestoring":"optimistic",oF(l),nF(l,o),rF(o);const[u]=y.useState(()=>new t(r,l)),d=u.getOptimisticResult(l);if(y.useSyncExternalStore(y.useCallback(f=>{const h=s?()=>{}:u.subscribe(Fn.batchCalls(f));return u.updateResult(),h},[u,s]),()=>u.getCurrentResult(),()=>u.getCurrentResult()),y.useEffect(()=>{u.setOptions(l,{listeners:!1})},[l,u]),aF(l,d))throw iF(l,u,o);if(sF({result:d,errorResetBoundary:o,throwOnError:l.throwOnError,query:r.getQueryCache().get(l.queryHash)}))throw d.error;return r.getDefaultOptions().queries?._experimental_afterQuery?.(l,d),l.notifyOnChangeProps?d:u.trackResult(d)}function mt(e,t){return lF(e,WD)}function cF(e,t){const n=Ob(),[r]=y.useState(()=>new QD(n,e));y.useEffect(()=>{r.setOptions(e)},[r,e]);const s=y.useSyncExternalStore(y.useCallback(l=>r.subscribe(Fn.batchCalls(l)),[r]),()=>r.getCurrentResult(),()=>r.getCurrentResult()),o=y.useCallback((l,u)=>{r.mutate(l,u).catch(tF)},[r]);if(s.error&&ej(r.options.throwOnError,[s.error]))throw s.error;return{...s,mutate:o,mutateAsync:s.mutate}}var Ff={},cv={exports:{}},Cr={},uv={exports:{}},dv={};/** * @license React * scheduler.production.min.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var K0;function uF(){return K0||(K0=1,(function(e){function t(H,q){var he=H.length;H.push(q);e:for(;0>>1,F=H[A];if(0>>1;As(de,he))ges(Z,de)?(H[A]=Z,H[ge]=he,A=ge):(H[A]=de,H[te]=he,A=te);else if(ges(Z,he))H[A]=Z,H[ge]=he,A=ge;else break e}}return q}function s(H,q){var he=H.sortIndex-q.sortIndex;return he!==0?he:H.id-q.id}if(typeof performance=="object"&&typeof performance.now=="function"){var o=performance;e.unstable_now=function(){return o.now()}}else{var l=Date,u=l.now();e.unstable_now=function(){return l.now()-u}}var d=[],f=[],h=1,m=null,g=3,x=!1,b=!1,w=!1,C=typeof setTimeout=="function"?setTimeout:null,k=typeof clearTimeout=="function"?clearTimeout:null,j=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function M(H){for(var q=n(f);q!==null;){if(q.callback===null)r(f);else if(q.startTime<=H)r(f),q.sortIndex=q.expirationTime,t(d,q);else break;q=n(f)}}function _(H){if(w=!1,M(H),!b)if(n(d)!==null)b=!0,re(R);else{var q=n(f);q!==null&&Y(_,q.startTime-H)}}function R(H,q){b=!1,w&&(w=!1,k(D),D=-1),x=!0;var he=g;try{for(M(q),m=n(d);m!==null&&(!(m.expirationTime>q)||H&&!pe());){var A=m.callback;if(typeof A=="function"){m.callback=null,g=m.priorityLevel;var F=A(m.expirationTime<=q);q=e.unstable_now(),typeof F=="function"?m.callback=F:m===n(d)&&r(d),M(q)}else r(d);m=n(d)}if(m!==null)var fe=!0;else{var te=n(f);te!==null&&Y(_,te.startTime-q),fe=!1}return fe}finally{m=null,g=he,x=!1}}var N=!1,O=null,D=-1,z=5,Q=-1;function pe(){return!(e.unstable_now()-QH||125A?(H.sortIndex=he,t(f,H),n(d)===null&&H===n(f)&&(w?(k(D),D=-1):w=!0,Y(_,he-A))):(H.sortIndex=F,t(d,H),b||x||(b=!0,re(R))),H},e.unstable_shouldYield=pe,e.unstable_wrapCallback=function(H){var q=g;return function(){var he=g;g=q;try{return H.apply(this,arguments)}finally{g=he}}}})(dv)),dv}var W0;function dF(){return W0||(W0=1,uv.exports=uF()),uv.exports}/** * @license React * react-dom.production.min.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var G0;function fF(){if(G0)return Cr;G0=1;var e=pd(),t=dF();function n(a){for(var c="https://reactjs.org/docs/error-decoder.html?invariant="+a,p=1;p"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),d=Object.prototype.hasOwnProperty,f=/^[:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD][:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\-.0-9\u00B7\u0300-\u036F\u203F-\u2040]*$/,h={},m={};function g(a){return d.call(m,a)?!0:d.call(h,a)?!1:f.test(a)?m[a]=!0:(h[a]=!0,!1)}function x(a,c,p,v){if(p!==null&&p.type===0)return!1;switch(typeof c){case"function":case"symbol":return!0;case"boolean":return v?!1:p!==null?!p.acceptsBooleans:(a=a.toLowerCase().slice(0,5),a!=="data-"&&a!=="aria-");default:return!1}}function b(a,c,p,v){if(c===null||typeof c>"u"||x(a,c,p,v))return!0;if(v)return!1;if(p!==null)switch(p.type){case 3:return!c;case 4:return c===!1;case 5:return isNaN(c);case 6:return isNaN(c)||1>c}return!1}function w(a,c,p,v,S,E,T){this.acceptsBooleans=c===2||c===3||c===4,this.attributeName=v,this.attributeNamespace=S,this.mustUseProperty=p,this.propertyName=a,this.type=c,this.sanitizeURL=E,this.removeEmptyString=T}var C={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(a){C[a]=new w(a,0,!1,a,null,!1,!1)}),[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(a){var c=a[0];C[c]=new w(c,1,!1,a[1],null,!1,!1)}),["contentEditable","draggable","spellCheck","value"].forEach(function(a){C[a]=new w(a,2,!1,a.toLowerCase(),null,!1,!1)}),["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(a){C[a]=new w(a,2,!1,a,null,!1,!1)}),"allowFullScreen async autoFocus autoPlay controls default defer disabled disablePictureInPicture disableRemotePlayback formNoValidate hidden loop noModule noValidate open playsInline readOnly required reversed scoped seamless itemScope".split(" ").forEach(function(a){C[a]=new w(a,3,!1,a.toLowerCase(),null,!1,!1)}),["checked","multiple","muted","selected"].forEach(function(a){C[a]=new w(a,3,!0,a,null,!1,!1)}),["capture","download"].forEach(function(a){C[a]=new w(a,4,!1,a,null,!1,!1)}),["cols","rows","size","span"].forEach(function(a){C[a]=new w(a,6,!1,a,null,!1,!1)}),["rowSpan","start"].forEach(function(a){C[a]=new w(a,5,!1,a.toLowerCase(),null,!1,!1)});var k=/[\-:]([a-z])/g;function j(a){return a[1].toUpperCase()}"accent-height alignment-baseline arabic-form baseline-shift cap-height clip-path clip-rule color-interpolation color-interpolation-filters color-profile color-rendering dominant-baseline enable-background fill-opacity fill-rule flood-color flood-opacity font-family font-size font-size-adjust font-stretch font-style font-variant font-weight glyph-name glyph-orientation-horizontal glyph-orientation-vertical horiz-adv-x horiz-origin-x image-rendering letter-spacing lighting-color marker-end marker-mid marker-start overline-position overline-thickness paint-order panose-1 pointer-events rendering-intent shape-rendering stop-color stop-opacity strikethrough-position strikethrough-thickness stroke-dasharray stroke-dashoffset stroke-linecap stroke-linejoin stroke-miterlimit stroke-opacity stroke-width text-anchor text-decoration text-rendering underline-position underline-thickness unicode-bidi unicode-range units-per-em v-alphabetic v-hanging v-ideographic v-mathematical vector-effect vert-adv-y vert-origin-x vert-origin-y word-spacing writing-mode xmlns:xlink x-height".split(" ").forEach(function(a){var c=a.replace(k,j);C[c]=new w(c,1,!1,a,null,!1,!1)}),"xlink:actuate xlink:arcrole xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function(a){var c=a.replace(k,j);C[c]=new w(c,1,!1,a,"http://www.w3.org/1999/xlink",!1,!1)}),["xml:base","xml:lang","xml:space"].forEach(function(a){var c=a.replace(k,j);C[c]=new w(c,1,!1,a,"http://www.w3.org/XML/1998/namespace",!1,!1)}),["tabIndex","crossOrigin"].forEach(function(a){C[a]=new w(a,1,!1,a.toLowerCase(),null,!1,!1)}),C.xlinkHref=new w("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1),["src","href","action","formAction"].forEach(function(a){C[a]=new w(a,1,!1,a.toLowerCase(),null,!0,!0)});function M(a,c,p,v){var S=C.hasOwnProperty(c)?C[c]:null;(S!==null?S.type!==0:v||!(2I||S[T]!==E[I]){var $=` `+S[T].replace(" at new "," at ");return a.displayName&&$.includes("")&&($=$.replace("",a.displayName)),$}while(1<=T&&0<=I);break}}}finally{fe=!1,Error.prepareStackTrace=p}return(a=a?a.displayName||a.name:"")?F(a):""}function de(a){switch(a.tag){case 5:return F(a.type);case 16:return F("Lazy");case 13:return F("Suspense");case 19:return F("SuspenseList");case 0:case 2:case 15:return a=te(a.type,!1),a;case 11:return a=te(a.type.render,!1),a;case 1:return a=te(a.type,!0),a;default:return""}}function ge(a){if(a==null)return null;if(typeof a=="function")return a.displayName||a.name||null;if(typeof a=="string")return a;switch(a){case O:return"Fragment";case N:return"Portal";case z:return"Profiler";case D:return"StrictMode";case G:return"Suspense";case W:return"SuspenseList"}if(typeof a=="object")switch(a.$$typeof){case pe:return(a.displayName||"Context")+".Consumer";case Q:return(a._context.displayName||"Context")+".Provider";case V:var c=a.render;return a=a.displayName,a||(a=c.displayName||c.name||"",a=a!==""?"ForwardRef("+a+")":"ForwardRef"),a;case ie:return c=a.displayName||null,c!==null?c:ge(a.type)||"Memo";case re:c=a._payload,a=a._init;try{return ge(a(c))}catch{}}return null}function Z(a){var c=a.type;switch(a.tag){case 24:return"Cache";case 9:return(c.displayName||"Context")+".Consumer";case 10:return(c._context.displayName||"Context")+".Provider";case 18:return"DehydratedFragment";case 11:return a=c.render,a=a.displayName||a.name||"",c.displayName||(a!==""?"ForwardRef("+a+")":"ForwardRef");case 7:return"Fragment";case 5:return c;case 4:return"Portal";case 3:return"Root";case 6:return"Text";case 16:return ge(c);case 8:return c===D?"StrictMode":"Mode";case 22:return"Offscreen";case 12:return"Profiler";case 21:return"Scope";case 13:return"Suspense";case 19:return"SuspenseList";case 25:return"TracingMarker";case 1:case 0:case 17:case 2:case 14:case 15:if(typeof c=="function")return c.displayName||c.name||null;if(typeof c=="string")return c}return null}function ye(a){switch(typeof a){case"boolean":case"number":case"string":case"undefined":return a;case"object":return a;default:return""}}function Re(a){var c=a.type;return(a=a.nodeName)&&a.toLowerCase()==="input"&&(c==="checkbox"||c==="radio")}function $e(a){var c=Re(a)?"checked":"value",p=Object.getOwnPropertyDescriptor(a.constructor.prototype,c),v=""+a[c];if(!a.hasOwnProperty(c)&&typeof p<"u"&&typeof p.get=="function"&&typeof p.set=="function"){var S=p.get,E=p.set;return Object.defineProperty(a,c,{configurable:!0,get:function(){return S.call(this)},set:function(T){v=""+T,E.call(this,T)}}),Object.defineProperty(a,c,{enumerable:p.enumerable}),{getValue:function(){return v},setValue:function(T){v=""+T},stopTracking:function(){a._valueTracker=null,delete a[c]}}}}function Ye(a){a._valueTracker||(a._valueTracker=$e(a))}function Fe(a){if(!a)return!1;var c=a._valueTracker;if(!c)return!0;var p=c.getValue(),v="";return a&&(v=Re(a)?a.checked?"true":"false":a.value),a=v,a!==p?(c.setValue(a),!0):!1}function ft(a){if(a=a||(typeof document<"u"?document:void 0),typeof a>"u")return null;try{return a.activeElement||a.body}catch{return a.body}}function ln(a,c){var p=c.checked;return he({},c,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:p??a._wrapperState.initialChecked})}function Sn(a,c){var p=c.defaultValue==null?"":c.defaultValue,v=c.checked!=null?c.checked:c.defaultChecked;p=ye(c.value!=null?c.value:p),a._wrapperState={initialChecked:v,initialValue:p,controlled:c.type==="checkbox"||c.type==="radio"?c.checked!=null:c.value!=null}}function vn(a,c){c=c.checked,c!=null&&M(a,"checked",c,!1)}function Cn(a,c){vn(a,c);var p=ye(c.value),v=c.type;if(p!=null)v==="number"?(p===0&&a.value===""||a.value!=p)&&(a.value=""+p):a.value!==""+p&&(a.value=""+p);else if(v==="submit"||v==="reset"){a.removeAttribute("value");return}c.hasOwnProperty("value")?X(a,c.type,p):c.hasOwnProperty("defaultValue")&&X(a,c.type,ye(c.defaultValue)),c.checked==null&&c.defaultChecked!=null&&(a.defaultChecked=!!c.defaultChecked)}function L(a,c,p){if(c.hasOwnProperty("value")||c.hasOwnProperty("defaultValue")){var v=c.type;if(!(v!=="submit"&&v!=="reset"||c.value!==void 0&&c.value!==null))return;c=""+a._wrapperState.initialValue,p||c===a.value||(a.value=c),a.defaultValue=c}p=a.name,p!==""&&(a.name=""),a.defaultChecked=!!a._wrapperState.initialChecked,p!==""&&(a.name=p)}function X(a,c,p){(c!=="number"||ft(a.ownerDocument)!==a)&&(p==null?a.defaultValue=""+a._wrapperState.initialValue:a.defaultValue!==""+p&&(a.defaultValue=""+p))}var ue=Array.isArray;function Ne(a,c,p,v){if(a=a.options,c){c={};for(var S=0;S"+c.valueOf().toString()+"",c=bn.firstChild;a.firstChild;)a.removeChild(a.firstChild);for(;c.firstChild;)a.appendChild(c.firstChild)}});function gr(a,c){if(c){var p=a.firstChild;if(p&&p===a.lastChild&&p.nodeType===3){p.nodeValue=c;return}}a.textContent=c}var Qn={animationIterationCount:!0,aspectRatio:!0,borderImageOutset:!0,borderImageSlice:!0,borderImageWidth:!0,boxFlex:!0,boxFlexGroup:!0,boxOrdinalGroup:!0,columnCount:!0,columns:!0,flex:!0,flexGrow:!0,flexPositive:!0,flexShrink:!0,flexNegative:!0,flexOrder:!0,gridArea:!0,gridRow:!0,gridRowEnd:!0,gridRowSpan:!0,gridRowStart:!0,gridColumn:!0,gridColumnEnd:!0,gridColumnSpan:!0,gridColumnStart:!0,fontWeight:!0,lineClamp:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,tabSize:!0,widows:!0,zIndex:!0,zoom:!0,fillOpacity:!0,floodOpacity:!0,stopOpacity:!0,strokeDasharray:!0,strokeDashoffset:!0,strokeMiterlimit:!0,strokeOpacity:!0,strokeWidth:!0},ro=["Webkit","ms","Moz","O"];Object.keys(Qn).forEach(function(a){ro.forEach(function(c){c=c+a.charAt(0).toUpperCase()+a.substring(1),Qn[c]=Qn[a]})});function Bn(a,c,p){return c==null||typeof c=="boolean"||c===""?"":p||typeof c!="number"||c===0||Qn.hasOwnProperty(a)&&Qn[a]?(""+c).trim():c+"px"}function Te(a,c){a=a.style;for(var p in c)if(c.hasOwnProperty(p)){var v=p.indexOf("--")===0,S=Bn(p,c[p],v);p==="float"&&(p="cssFloat"),v?a.setProperty(p,S):a[p]=S}}var ut=he({menuitem:!0},{area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0});function It(a,c){if(c){if(ut[a]&&(c.children!=null||c.dangerouslySetInnerHTML!=null))throw Error(n(137,a));if(c.dangerouslySetInnerHTML!=null){if(c.children!=null)throw Error(n(60));if(typeof c.dangerouslySetInnerHTML!="object"||!("__html"in c.dangerouslySetInnerHTML))throw Error(n(61))}if(c.style!=null&&typeof c.style!="object")throw Error(n(62))}}function Tn(a,c){if(a.indexOf("-")===-1)return typeof c.is=="string";switch(a){case"annotation-xml":case"color-profile":case"font-face":case"font-face-src":case"font-face-uri":case"font-face-format":case"font-face-name":case"missing-glyph":return!1;default:return!0}}var mr=null;function vr(a){return a=a.target||a.srcElement||window,a.correspondingUseElement&&(a=a.correspondingUseElement),a.nodeType===3?a.parentNode:a}var Gr=null,Jr=null,_r=null;function Rr(a){if(a=Lc(a)){if(typeof Gr!="function")throw Error(n(280));var c=a.stateNode;c&&(c=Qd(c),Gr(a.stateNode,a.type,c))}}function Uo(a){Jr?_r?_r.push(a):_r=[a]:Jr=a}function vc(){if(Jr){var a=Jr,c=_r;if(_r=Jr=null,Rr(a),c)for(a=0;a>>=0,a===0?32:31-(fs(a)/Rd|0)|0}var Pd=64,Od=4194304;function xc(a){switch(a&-a){case 1:return 1;case 2:return 2;case 4:return 4;case 8:return 8;case 16:return 16;case 32:return 32;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return a&4194240;case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:return a&130023424;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 1073741824;default:return a}}function Id(a,c){var p=a.pendingLanes;if(p===0)return 0;var v=0,S=a.suspendedLanes,E=a.pingedLanes,T=p&268435455;if(T!==0){var I=T&~S;I!==0?v=xc(I):(E&=T,E!==0&&(v=xc(E)))}else T=p&~S,T!==0?v=xc(T):E!==0&&(v=xc(E));if(v===0)return 0;if(c!==0&&c!==v&&(c&S)===0&&(S=v&-v,E=c&-c,S>=E||S===16&&(E&4194240)!==0))return c;if((v&4)!==0&&(v|=p&16),c=a.entangledLanes,c!==0)for(a=a.entanglements,c&=v;0p;p++)c.push(a);return c}function wc(a,c,p){a.pendingLanes|=c,c!==536870912&&(a.suspendedLanes=0,a.pingedLanes=0),a=a.eventTimes,c=31-Tt(c),a[c]=p}function GI(a,c){var p=a.pendingLanes&~c;a.pendingLanes=c,a.suspendedLanes=0,a.pingedLanes=0,a.expiredLanes&=c,a.mutableReadLanes&=c,a.entangledLanes&=c,c=a.entanglements;var v=a.eventTimes;for(a=a.expirationTimes;0=Mc),Nw=" ",Mw=!1;function _w(a,c){switch(a){case"keyup":return SA.indexOf(c.keyCode)!==-1;case"keydown":return c.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function Rw(a){return a=a.detail,typeof a=="object"&&"data"in a?a.data:null}var Ki=!1;function EA(a,c){switch(a){case"compositionend":return Rw(c);case"keypress":return c.which!==32?null:(Mw=!0,Nw);case"textInput":return a=c.data,a===Nw&&Mw?null:a;default:return null}}function kA(a,c){if(Ki)return a==="compositionend"||!Bg&&_w(a,c)?(a=Sw(),$d=Ig=Go=null,Ki=!1,a):null;switch(a){case"paste":return null;case"keypress":if(!(c.ctrlKey||c.altKey||c.metaKey)||c.ctrlKey&&c.altKey){if(c.char&&1=c)return{node:p,offset:c-a};a=v}e:{for(;p;){if(p.nextSibling){p=p.nextSibling;break e}p=p.parentNode}p=void 0}p=Lw(p)}}function Bw(a,c){return a&&c?a===c?!0:a&&a.nodeType===3?!1:c&&c.nodeType===3?Bw(a,c.parentNode):"contains"in a?a.contains(c):a.compareDocumentPosition?!!(a.compareDocumentPosition(c)&16):!1:!1}function zw(){for(var a=window,c=ft();c instanceof a.HTMLIFrameElement;){try{var p=typeof c.contentWindow.location.href=="string"}catch{p=!1}if(p)a=c.contentWindow;else break;c=ft(a.document)}return c}function Vg(a){var c=a&&a.nodeName&&a.nodeName.toLowerCase();return c&&(c==="input"&&(a.type==="text"||a.type==="search"||a.type==="tel"||a.type==="url"||a.type==="password")||c==="textarea"||a.contentEditable==="true")}function IA(a){var c=zw(),p=a.focusedElem,v=a.selectionRange;if(c!==p&&p&&p.ownerDocument&&Bw(p.ownerDocument.documentElement,p)){if(v!==null&&Vg(p)){if(c=v.start,a=v.end,a===void 0&&(a=c),"selectionStart"in p)p.selectionStart=c,p.selectionEnd=Math.min(a,p.value.length);else if(a=(c=p.ownerDocument||document)&&c.defaultView||window,a.getSelection){a=a.getSelection();var S=p.textContent.length,E=Math.min(v.start,S);v=v.end===void 0?E:Math.min(v.end,S),!a.extend&&E>v&&(S=v,v=E,E=S),S=$w(p,E);var T=$w(p,v);S&&T&&(a.rangeCount!==1||a.anchorNode!==S.node||a.anchorOffset!==S.offset||a.focusNode!==T.node||a.focusOffset!==T.offset)&&(c=c.createRange(),c.setStart(S.node,S.offset),a.removeAllRanges(),E>v?(a.addRange(c),a.extend(T.node,T.offset)):(c.setEnd(T.node,T.offset),a.addRange(c)))}}for(c=[],a=p;a=a.parentNode;)a.nodeType===1&&c.push({element:a,left:a.scrollLeft,top:a.scrollTop});for(typeof p.focus=="function"&&p.focus(),p=0;p=document.documentMode,Wi=null,Hg=null,Oc=null,qg=!1;function Uw(a,c,p){var v=p.window===p?p.document:p.nodeType===9?p:p.ownerDocument;qg||Wi==null||Wi!==ft(v)||(v=Wi,"selectionStart"in v&&Vg(v)?v={start:v.selectionStart,end:v.selectionEnd}:(v=(v.ownerDocument&&v.ownerDocument.defaultView||window).getSelection(),v={anchorNode:v.anchorNode,anchorOffset:v.anchorOffset,focusNode:v.focusNode,focusOffset:v.focusOffset}),Oc&&Pc(Oc,v)||(Oc=v,v=Wd(Hg,"onSelect"),0Yi||(a.current=rm[Yi],rm[Yi]=null,Yi--)}function Qt(a,c){Yi++,rm[Yi]=a.current,a.current=c}var Yo={},Zn=Zo(Yo),yr=Zo(!1),Ka=Yo;function Xi(a,c){var p=a.type.contextTypes;if(!p)return Yo;var v=a.stateNode;if(v&&v.__reactInternalMemoizedUnmaskedChildContext===c)return v.__reactInternalMemoizedMaskedChildContext;var S={},E;for(E in p)S[E]=c[E];return v&&(a=a.stateNode,a.__reactInternalMemoizedUnmaskedChildContext=c,a.__reactInternalMemoizedMaskedChildContext=S),S}function br(a){return a=a.childContextTypes,a!=null}function Zd(){en(yr),en(Zn)}function rS(a,c,p){if(Zn.current!==Yo)throw Error(n(168));Qt(Zn,c),Qt(yr,p)}function sS(a,c,p){var v=a.stateNode;if(c=c.childContextTypes,typeof v.getChildContext!="function")return p;v=v.getChildContext();for(var S in v)if(!(S in c))throw Error(n(108,Z(a)||"Unknown",S));return he({},p,v)}function Yd(a){return a=(a=a.stateNode)&&a.__reactInternalMemoizedMergedChildContext||Yo,Ka=Zn.current,Qt(Zn,a),Qt(yr,yr.current),!0}function oS(a,c,p){var v=a.stateNode;if(!v)throw Error(n(169));p?(a=sS(a,c,Ka),v.__reactInternalMemoizedMergedChildContext=a,en(yr),en(Zn),Qt(Zn,a)):en(yr),Qt(yr,p)}var ao=null,Xd=!1,sm=!1;function aS(a){ao===null?ao=[a]:ao.push(a)}function KA(a){Xd=!0,aS(a)}function Xo(){if(!sm&&ao!==null){sm=!0;var a=0,c=Kt;try{var p=ao;for(Kt=1;a>=T,S-=T,io=1<<32-Tt(c)+S|p<dt?(Vn=tt,tt=null):Vn=tt.sibling;var Lt=be(J,tt,ee[dt],ke);if(Lt===null){tt===null&&(tt=Vn);break}a&&tt&&Lt.alternate===null&&c(J,tt),U=E(Lt,U,dt),et===null?Je=Lt:et.sibling=Lt,et=Lt,tt=Vn}if(dt===ee.length)return p(J,tt),cn&&Ga(J,dt),Je;if(tt===null){for(;dtdt?(Vn=tt,tt=null):Vn=tt.sibling;var la=be(J,tt,Lt.value,ke);if(la===null){tt===null&&(tt=Vn);break}a&&tt&&la.alternate===null&&c(J,tt),U=E(la,U,dt),et===null?Je=la:et.sibling=la,et=la,tt=Vn}if(Lt.done)return p(J,tt),cn&&Ga(J,dt),Je;if(tt===null){for(;!Lt.done;dt++,Lt=ee.next())Lt=we(J,Lt.value,ke),Lt!==null&&(U=E(Lt,U,dt),et===null?Je=Lt:et.sibling=Lt,et=Lt);return cn&&Ga(J,dt),Je}for(tt=v(J,tt);!Lt.done;dt++,Lt=ee.next())Lt=De(tt,J,dt,Lt.value,ke),Lt!==null&&(a&&Lt.alternate!==null&&tt.delete(Lt.key===null?dt:Lt.key),U=E(Lt,U,dt),et===null?Je=Lt:et.sibling=Lt,et=Lt);return a&&tt.forEach(function(jD){return c(J,jD)}),cn&&Ga(J,dt),Je}function kn(J,U,ee,ke){if(typeof ee=="object"&&ee!==null&&ee.type===O&&ee.key===null&&(ee=ee.props.children),typeof ee=="object"&&ee!==null){switch(ee.$$typeof){case R:e:{for(var Je=ee.key,et=U;et!==null;){if(et.key===Je){if(Je=ee.type,Je===O){if(et.tag===7){p(J,et.sibling),U=S(et,ee.props.children),U.return=J,J=U;break e}}else if(et.elementType===Je||typeof Je=="object"&&Je!==null&&Je.$$typeof===re&&fS(Je)===et.type){p(J,et.sibling),U=S(et,ee.props),U.ref=$c(J,et,ee),U.return=J,J=U;break e}p(J,et);break}else c(J,et);et=et.sibling}ee.type===O?(U=ni(ee.props.children,J.mode,ke,ee.key),U.return=J,J=U):(ke=Nf(ee.type,ee.key,ee.props,null,J.mode,ke),ke.ref=$c(J,U,ee),ke.return=J,J=ke)}return T(J);case N:e:{for(et=ee.key;U!==null;){if(U.key===et)if(U.tag===4&&U.stateNode.containerInfo===ee.containerInfo&&U.stateNode.implementation===ee.implementation){p(J,U.sibling),U=S(U,ee.children||[]),U.return=J,J=U;break e}else{p(J,U);break}else c(J,U);U=U.sibling}U=tv(ee,J.mode,ke),U.return=J,J=U}return T(J);case re:return et=ee._init,kn(J,U,et(ee._payload),ke)}if(ue(ee))return He(J,U,ee,ke);if(q(ee))return Ke(J,U,ee,ke);rf(J,ee)}return typeof ee=="string"&&ee!==""||typeof ee=="number"?(ee=""+ee,U!==null&&U.tag===6?(p(J,U.sibling),U=S(U,ee),U.return=J,J=U):(p(J,U),U=ev(ee,J.mode,ke),U.return=J,J=U),T(J)):p(J,U)}return kn}var rl=pS(!0),hS=pS(!1),sf=Zo(null),of=null,sl=null,um=null;function dm(){um=sl=of=null}function fm(a){var c=sf.current;en(sf),a._currentValue=c}function pm(a,c,p){for(;a!==null;){var v=a.alternate;if((a.childLanes&c)!==c?(a.childLanes|=c,v!==null&&(v.childLanes|=c)):v!==null&&(v.childLanes&c)!==c&&(v.childLanes|=c),a===p)break;a=a.return}}function ol(a,c){of=a,um=sl=null,a=a.dependencies,a!==null&&a.firstContext!==null&&((a.lanes&c)!==0&&(xr=!0),a.firstContext=null)}function Yr(a){var c=a._currentValue;if(um!==a)if(a={context:a,memoizedValue:c,next:null},sl===null){if(of===null)throw Error(n(308));sl=a,of.dependencies={lanes:0,firstContext:a}}else sl=sl.next=a;return c}var Ja=null;function hm(a){Ja===null?Ja=[a]:Ja.push(a)}function gS(a,c,p,v){var S=c.interleaved;return S===null?(p.next=p,hm(c)):(p.next=S.next,S.next=p),c.interleaved=p,co(a,v)}function co(a,c){a.lanes|=c;var p=a.alternate;for(p!==null&&(p.lanes|=c),p=a,a=a.return;a!==null;)a.childLanes|=c,p=a.alternate,p!==null&&(p.childLanes|=c),p=a,a=a.return;return p.tag===3?p.stateNode:null}var ea=!1;function gm(a){a.updateQueue={baseState:a.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function mS(a,c){a=a.updateQueue,c.updateQueue===a&&(c.updateQueue={baseState:a.baseState,firstBaseUpdate:a.firstBaseUpdate,lastBaseUpdate:a.lastBaseUpdate,shared:a.shared,effects:a.effects})}function uo(a,c){return{eventTime:a,lane:c,tag:0,payload:null,callback:null,next:null}}function ta(a,c,p){var v=a.updateQueue;if(v===null)return null;if(v=v.shared,(Ft&2)!==0){var S=v.pending;return S===null?c.next=c:(c.next=S.next,S.next=c),v.pending=c,co(a,p)}return S=v.interleaved,S===null?(c.next=c,hm(v)):(c.next=S.next,S.next=c),v.interleaved=c,co(a,p)}function af(a,c,p){if(c=c.updateQueue,c!==null&&(c=c.shared,(p&4194240)!==0)){var v=c.lanes;v&=a.pendingLanes,p|=v,c.lanes=p,Mg(a,p)}}function vS(a,c){var p=a.updateQueue,v=a.alternate;if(v!==null&&(v=v.updateQueue,p===v)){var S=null,E=null;if(p=p.firstBaseUpdate,p!==null){do{var T={eventTime:p.eventTime,lane:p.lane,tag:p.tag,payload:p.payload,callback:p.callback,next:null};E===null?S=E=T:E=E.next=T,p=p.next}while(p!==null);E===null?S=E=c:E=E.next=c}else S=E=c;p={baseState:v.baseState,firstBaseUpdate:S,lastBaseUpdate:E,shared:v.shared,effects:v.effects},a.updateQueue=p;return}a=p.lastBaseUpdate,a===null?p.firstBaseUpdate=c:a.next=c,p.lastBaseUpdate=c}function lf(a,c,p,v){var S=a.updateQueue;ea=!1;var E=S.firstBaseUpdate,T=S.lastBaseUpdate,I=S.shared.pending;if(I!==null){S.shared.pending=null;var $=I,ae=$.next;$.next=null,T===null?E=ae:T.next=ae,T=$;var xe=a.alternate;xe!==null&&(xe=xe.updateQueue,I=xe.lastBaseUpdate,I!==T&&(I===null?xe.firstBaseUpdate=ae:I.next=ae,xe.lastBaseUpdate=$))}if(E!==null){var we=S.baseState;T=0,xe=ae=$=null,I=E;do{var be=I.lane,De=I.eventTime;if((v&be)===be){xe!==null&&(xe=xe.next={eventTime:De,lane:0,tag:I.tag,payload:I.payload,callback:I.callback,next:null});e:{var He=a,Ke=I;switch(be=c,De=p,Ke.tag){case 1:if(He=Ke.payload,typeof He=="function"){we=He.call(De,we,be);break e}we=He;break e;case 3:He.flags=He.flags&-65537|128;case 0:if(He=Ke.payload,be=typeof He=="function"?He.call(De,we,be):He,be==null)break e;we=he({},we,be);break e;case 2:ea=!0}}I.callback!==null&&I.lane!==0&&(a.flags|=64,be=S.effects,be===null?S.effects=[I]:be.push(I))}else De={eventTime:De,lane:be,tag:I.tag,payload:I.payload,callback:I.callback,next:null},xe===null?(ae=xe=De,$=we):xe=xe.next=De,T|=be;if(I=I.next,I===null){if(I=S.shared.pending,I===null)break;be=I,I=be.next,be.next=null,S.lastBaseUpdate=be,S.shared.pending=null}}while(!0);if(xe===null&&($=we),S.baseState=$,S.firstBaseUpdate=ae,S.lastBaseUpdate=xe,c=S.shared.interleaved,c!==null){S=c;do T|=S.lane,S=S.next;while(S!==c)}else E===null&&(S.shared.lanes=0);Ya|=T,a.lanes=T,a.memoizedState=we}}function yS(a,c,p){if(a=c.effects,c.effects=null,a!==null)for(c=0;cp?p:4,a(!0);var v=xm.transition;xm.transition={};try{a(!1),c()}finally{Kt=p,xm.transition=v}}function FS(){return Xr().memoizedState}function QA(a,c,p){var v=oa(a);if(p={lane:v,action:p,hasEagerState:!1,eagerState:null,next:null},LS(a))$S(c,p);else if(p=gS(a,c,p,v),p!==null){var S=ir();ys(p,a,v,S),BS(p,c,v)}}function ZA(a,c,p){var v=oa(a),S={lane:v,action:p,hasEagerState:!1,eagerState:null,next:null};if(LS(a))$S(c,S);else{var E=a.alternate;if(a.lanes===0&&(E===null||E.lanes===0)&&(E=c.lastRenderedReducer,E!==null))try{var T=c.lastRenderedState,I=E(T,p);if(S.hasEagerState=!0,S.eagerState=I,ps(I,T)){var $=c.interleaved;$===null?(S.next=S,hm(c)):(S.next=$.next,$.next=S),c.interleaved=S;return}}catch{}finally{}p=gS(a,c,S,v),p!==null&&(S=ir(),ys(p,a,v,S),BS(p,c,v))}}function LS(a){var c=a.alternate;return a===hn||c!==null&&c===hn}function $S(a,c){Vc=df=!0;var p=a.pending;p===null?c.next=c:(c.next=p.next,p.next=c),a.pending=c}function BS(a,c,p){if((p&4194240)!==0){var v=c.lanes;v&=a.pendingLanes,p|=v,c.lanes=p,Mg(a,p)}}var hf={readContext:Yr,useCallback:Yn,useContext:Yn,useEffect:Yn,useImperativeHandle:Yn,useInsertionEffect:Yn,useLayoutEffect:Yn,useMemo:Yn,useReducer:Yn,useRef:Yn,useState:Yn,useDebugValue:Yn,useDeferredValue:Yn,useTransition:Yn,useMutableSource:Yn,useSyncExternalStore:Yn,useId:Yn,unstable_isNewReconciler:!1},YA={readContext:Yr,useCallback:function(a,c){return Fs().memoizedState=[a,c===void 0?null:c],a},useContext:Yr,useEffect:MS,useImperativeHandle:function(a,c,p){return p=p!=null?p.concat([a]):null,ff(4194308,4,PS.bind(null,c,a),p)},useLayoutEffect:function(a,c){return ff(4194308,4,a,c)},useInsertionEffect:function(a,c){return ff(4,2,a,c)},useMemo:function(a,c){var p=Fs();return c=c===void 0?null:c,a=a(),p.memoizedState=[a,c],a},useReducer:function(a,c,p){var v=Fs();return c=p!==void 0?p(c):c,v.memoizedState=v.baseState=c,a={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:a,lastRenderedState:c},v.queue=a,a=a.dispatch=QA.bind(null,hn,a),[v.memoizedState,a]},useRef:function(a){var c=Fs();return a={current:a},c.memoizedState=a},useState:TS,useDebugValue:Tm,useDeferredValue:function(a){return Fs().memoizedState=a},useTransition:function(){var a=TS(!1),c=a[0];return a=JA.bind(null,a[1]),Fs().memoizedState=a,[c,a]},useMutableSource:function(){},useSyncExternalStore:function(a,c,p){var v=hn,S=Fs();if(cn){if(p===void 0)throw Error(n(407));p=p()}else{if(p=c(),Un===null)throw Error(n(349));(Za&30)!==0||SS(v,c,p)}S.memoizedState=p;var E={value:p,getSnapshot:c};return S.queue=E,MS(ES.bind(null,v,E,a),[a]),v.flags|=2048,Kc(9,CS.bind(null,v,E,p,c),void 0,null),p},useId:function(){var a=Fs(),c=Un.identifierPrefix;if(cn){var p=lo,v=io;p=(v&~(1<<32-Tt(v)-1)).toString(32)+p,c=":"+c+"R"+p,p=Hc++,0<\/script>",a=a.removeChild(a.firstChild)):typeof v.is=="string"?a=T.createElement(p,{is:v.is}):(a=T.createElement(p),p==="select"&&(T=a,v.multiple?T.multiple=!0:v.size&&(T.size=v.size))):a=T.createElementNS(a,p),a[As]=c,a[Fc]=v,a0(a,c,!1,!1),c.stateNode=a;e:{switch(T=Tn(p,v),p){case"dialog":Xt("cancel",a),Xt("close",a),S=v;break;case"iframe":case"object":case"embed":Xt("load",a),S=v;break;case"video":case"audio":for(S=0;Sul&&(c.flags|=128,v=!0,Wc(E,!1),c.lanes=4194304)}else{if(!v)if(a=cf(T),a!==null){if(c.flags|=128,v=!0,p=a.updateQueue,p!==null&&(c.updateQueue=p,c.flags|=4),Wc(E,!0),E.tail===null&&E.tailMode==="hidden"&&!T.alternate&&!cn)return Xn(c),null}else 2*Gt()-E.renderingStartTime>ul&&p!==1073741824&&(c.flags|=128,v=!0,Wc(E,!1),c.lanes=4194304);E.isBackwards?(T.sibling=c.child,c.child=T):(p=E.last,p!==null?p.sibling=T:c.child=T,E.last=T)}return E.tail!==null?(c=E.tail,E.rendering=c,E.tail=c.sibling,E.renderingStartTime=Gt(),c.sibling=null,p=pn.current,Qt(pn,v?p&1|2:p&1),c):(Xn(c),null);case 22:case 23:return Zm(),v=c.memoizedState!==null,a!==null&&a.memoizedState!==null!==v&&(c.flags|=8192),v&&(c.mode&1)!==0?(Dr&1073741824)!==0&&(Xn(c),c.subtreeFlags&6&&(c.flags|=8192)):Xn(c),null;case 24:return null;case 25:return null}throw Error(n(156,c.tag))}function aD(a,c){switch(am(c),c.tag){case 1:return br(c.type)&&Zd(),a=c.flags,a&65536?(c.flags=a&-65537|128,c):null;case 3:return al(),en(yr),en(Zn),bm(),a=c.flags,(a&65536)!==0&&(a&128)===0?(c.flags=a&-65537|128,c):null;case 5:return vm(c),null;case 13:if(en(pn),a=c.memoizedState,a!==null&&a.dehydrated!==null){if(c.alternate===null)throw Error(n(340));nl()}return a=c.flags,a&65536?(c.flags=a&-65537|128,c):null;case 19:return en(pn),null;case 4:return al(),null;case 10:return fm(c.type._context),null;case 22:case 23:return Zm(),null;case 24:return null;default:return null}}var yf=!1,er=!1,iD=typeof WeakSet=="function"?WeakSet:Set,ze=null;function ll(a,c){var p=a.ref;if(p!==null)if(typeof p=="function")try{p(null)}catch(v){xn(a,c,v)}else p.current=null}function $m(a,c,p){try{p()}catch(v){xn(a,c,v)}}var c0=!1;function lD(a,c){if(Zg=Fd,a=zw(),Vg(a)){if("selectionStart"in a)var p={start:a.selectionStart,end:a.selectionEnd};else e:{p=(p=a.ownerDocument)&&p.defaultView||window;var v=p.getSelection&&p.getSelection();if(v&&v.rangeCount!==0){p=v.anchorNode;var S=v.anchorOffset,E=v.focusNode;v=v.focusOffset;try{p.nodeType,E.nodeType}catch{p=null;break e}var T=0,I=-1,$=-1,ae=0,xe=0,we=a,be=null;t:for(;;){for(var De;we!==p||S!==0&&we.nodeType!==3||(I=T+S),we!==E||v!==0&&we.nodeType!==3||($=T+v),we.nodeType===3&&(T+=we.nodeValue.length),(De=we.firstChild)!==null;)be=we,we=De;for(;;){if(we===a)break t;if(be===p&&++ae===S&&(I=T),be===E&&++xe===v&&($=T),(De=we.nextSibling)!==null)break;we=be,be=we.parentNode}we=De}p=I===-1||$===-1?null:{start:I,end:$}}else p=null}p=p||{start:0,end:0}}else p=null;for(Yg={focusedElem:a,selectionRange:p},Fd=!1,ze=c;ze!==null;)if(c=ze,a=c.child,(c.subtreeFlags&1028)!==0&&a!==null)a.return=c,ze=a;else for(;ze!==null;){c=ze;try{var He=c.alternate;if((c.flags&1024)!==0)switch(c.tag){case 0:case 11:case 15:break;case 1:if(He!==null){var Ke=He.memoizedProps,kn=He.memoizedState,J=c.stateNode,U=J.getSnapshotBeforeUpdate(c.elementType===c.type?Ke:gs(c.type,Ke),kn);J.__reactInternalSnapshotBeforeUpdate=U}break;case 3:var ee=c.stateNode.containerInfo;ee.nodeType===1?ee.textContent="":ee.nodeType===9&&ee.documentElement&&ee.removeChild(ee.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(n(163))}}catch(ke){xn(c,c.return,ke)}if(a=c.sibling,a!==null){a.return=c.return,ze=a;break}ze=c.return}return He=c0,c0=!1,He}function Gc(a,c,p){var v=c.updateQueue;if(v=v!==null?v.lastEffect:null,v!==null){var S=v=v.next;do{if((S.tag&a)===a){var E=S.destroy;S.destroy=void 0,E!==void 0&&$m(c,p,E)}S=S.next}while(S!==v)}}function bf(a,c){if(c=c.updateQueue,c=c!==null?c.lastEffect:null,c!==null){var p=c=c.next;do{if((p.tag&a)===a){var v=p.create;p.destroy=v()}p=p.next}while(p!==c)}}function Bm(a){var c=a.ref;if(c!==null){var p=a.stateNode;switch(a.tag){case 5:a=p;break;default:a=p}typeof c=="function"?c(a):c.current=a}}function u0(a){var c=a.alternate;c!==null&&(a.alternate=null,u0(c)),a.child=null,a.deletions=null,a.sibling=null,a.tag===5&&(c=a.stateNode,c!==null&&(delete c[As],delete c[Fc],delete c[nm],delete c[HA],delete c[qA])),a.stateNode=null,a.return=null,a.dependencies=null,a.memoizedProps=null,a.memoizedState=null,a.pendingProps=null,a.stateNode=null,a.updateQueue=null}function d0(a){return a.tag===5||a.tag===3||a.tag===4}function f0(a){e:for(;;){for(;a.sibling===null;){if(a.return===null||d0(a.return))return null;a=a.return}for(a.sibling.return=a.return,a=a.sibling;a.tag!==5&&a.tag!==6&&a.tag!==18;){if(a.flags&2||a.child===null||a.tag===4)continue e;a.child.return=a,a=a.child}if(!(a.flags&2))return a.stateNode}}function zm(a,c,p){var v=a.tag;if(v===5||v===6)a=a.stateNode,c?p.nodeType===8?p.parentNode.insertBefore(a,c):p.insertBefore(a,c):(p.nodeType===8?(c=p.parentNode,c.insertBefore(a,p)):(c=p,c.appendChild(a)),p=p._reactRootContainer,p!=null||c.onclick!==null||(c.onclick=Jd));else if(v!==4&&(a=a.child,a!==null))for(zm(a,c,p),a=a.sibling;a!==null;)zm(a,c,p),a=a.sibling}function Um(a,c,p){var v=a.tag;if(v===5||v===6)a=a.stateNode,c?p.insertBefore(a,c):p.appendChild(a);else if(v!==4&&(a=a.child,a!==null))for(Um(a,c,p),a=a.sibling;a!==null;)Um(a,c,p),a=a.sibling}var qn=null,ms=!1;function na(a,c,p){for(p=p.child;p!==null;)p0(a,c,p),p=p.sibling}function p0(a,c,p){if(Dt&&typeof Dt.onCommitFiberUnmount=="function")try{Dt.onCommitFiberUnmount(pt,p)}catch{}switch(p.tag){case 5:er||ll(p,c);case 6:var v=qn,S=ms;qn=null,na(a,c,p),qn=v,ms=S,qn!==null&&(ms?(a=qn,p=p.stateNode,a.nodeType===8?a.parentNode.removeChild(p):a.removeChild(p)):qn.removeChild(p.stateNode));break;case 18:qn!==null&&(ms?(a=qn,p=p.stateNode,a.nodeType===8?tm(a.parentNode,p):a.nodeType===1&&tm(a,p),jc(a)):tm(qn,p.stateNode));break;case 4:v=qn,S=ms,qn=p.stateNode.containerInfo,ms=!0,na(a,c,p),qn=v,ms=S;break;case 0:case 11:case 14:case 15:if(!er&&(v=p.updateQueue,v!==null&&(v=v.lastEffect,v!==null))){S=v=v.next;do{var E=S,T=E.destroy;E=E.tag,T!==void 0&&((E&2)!==0||(E&4)!==0)&&$m(p,c,T),S=S.next}while(S!==v)}na(a,c,p);break;case 1:if(!er&&(ll(p,c),v=p.stateNode,typeof v.componentWillUnmount=="function"))try{v.props=p.memoizedProps,v.state=p.memoizedState,v.componentWillUnmount()}catch(I){xn(p,c,I)}na(a,c,p);break;case 21:na(a,c,p);break;case 22:p.mode&1?(er=(v=er)||p.memoizedState!==null,na(a,c,p),er=v):na(a,c,p);break;default:na(a,c,p)}}function h0(a){var c=a.updateQueue;if(c!==null){a.updateQueue=null;var p=a.stateNode;p===null&&(p=a.stateNode=new iD),c.forEach(function(v){var S=vD.bind(null,a,v);p.has(v)||(p.add(v),v.then(S,S))})}}function vs(a,c){var p=c.deletions;if(p!==null)for(var v=0;vS&&(S=T),v&=~E}if(v=S,v=Gt()-v,v=(120>v?120:480>v?480:1080>v?1080:1920>v?1920:3e3>v?3e3:4320>v?4320:1960*uD(v/1960))-v,10a?16:a,sa===null)var v=!1;else{if(a=sa,sa=null,Ef=0,(Ft&6)!==0)throw Error(n(331));var S=Ft;for(Ft|=4,ze=a.current;ze!==null;){var E=ze,T=E.child;if((ze.flags&16)!==0){var I=E.deletions;if(I!==null){for(var $=0;$Gt()-qm?ei(a,0):Hm|=p),Sr(a,c)}function T0(a,c){c===0&&((a.mode&1)===0?c=1:(c=Od,Od<<=1,(Od&130023424)===0&&(Od=4194304)));var p=ir();a=co(a,c),a!==null&&(wc(a,c,p),Sr(a,p))}function mD(a){var c=a.memoizedState,p=0;c!==null&&(p=c.retryLane),T0(a,p)}function vD(a,c){var p=0;switch(a.tag){case 13:var v=a.stateNode,S=a.memoizedState;S!==null&&(p=S.retryLane);break;case 19:v=a.stateNode;break;default:throw Error(n(314))}v!==null&&v.delete(c),T0(a,p)}var N0;N0=function(a,c,p){if(a!==null)if(a.memoizedProps!==c.pendingProps||yr.current)xr=!0;else{if((a.lanes&p)===0&&(c.flags&128)===0)return xr=!1,sD(a,c,p);xr=(a.flags&131072)!==0}else xr=!1,cn&&(c.flags&1048576)!==0&&iS(c,tf,c.index);switch(c.lanes=0,c.tag){case 2:var v=c.type;vf(a,c),a=c.pendingProps;var S=Xi(c,Zn.current);ol(c,p),S=Sm(null,c,v,a,S,p);var E=Cm();return c.flags|=1,typeof S=="object"&&S!==null&&typeof S.render=="function"&&S.$$typeof===void 0?(c.tag=1,c.memoizedState=null,c.updateQueue=null,br(v)?(E=!0,Yd(c)):E=!1,c.memoizedState=S.state!==null&&S.state!==void 0?S.state:null,gm(c),S.updater=gf,c.stateNode=S,S._reactInternals=c,Mm(c,v,a,p),c=Om(null,c,v,!0,E,p)):(c.tag=0,cn&&E&&om(c),ar(null,c,S,p),c=c.child),c;case 16:v=c.elementType;e:{switch(vf(a,c),a=c.pendingProps,S=v._init,v=S(v._payload),c.type=v,S=c.tag=bD(v),a=gs(v,a),S){case 0:c=Pm(null,c,v,a,p);break e;case 1:c=e0(null,c,v,a,p);break e;case 11:c=JS(null,c,v,a,p);break e;case 14:c=QS(null,c,v,gs(v.type,a),p);break e}throw Error(n(306,v,""))}return c;case 0:return v=c.type,S=c.pendingProps,S=c.elementType===v?S:gs(v,S),Pm(a,c,v,S,p);case 1:return v=c.type,S=c.pendingProps,S=c.elementType===v?S:gs(v,S),e0(a,c,v,S,p);case 3:e:{if(t0(c),a===null)throw Error(n(387));v=c.pendingProps,E=c.memoizedState,S=E.element,mS(a,c),lf(c,v,null,p);var T=c.memoizedState;if(v=T.element,E.isDehydrated)if(E={element:v,isDehydrated:!1,cache:T.cache,pendingSuspenseBoundaries:T.pendingSuspenseBoundaries,transitions:T.transitions},c.updateQueue.baseState=E,c.memoizedState=E,c.flags&256){S=il(Error(n(423)),c),c=n0(a,c,v,p,S);break e}else if(v!==S){S=il(Error(n(424)),c),c=n0(a,c,v,p,S);break e}else for(Ar=Qo(c.stateNode.containerInfo.firstChild),Ir=c,cn=!0,hs=null,p=hS(c,null,v,p),c.child=p;p;)p.flags=p.flags&-3|4096,p=p.sibling;else{if(nl(),v===S){c=fo(a,c,p);break e}ar(a,c,v,p)}c=c.child}return c;case 5:return bS(c),a===null&&lm(c),v=c.type,S=c.pendingProps,E=a!==null?a.memoizedProps:null,T=S.children,Xg(v,S)?T=null:E!==null&&Xg(v,E)&&(c.flags|=32),XS(a,c),ar(a,c,T,p),c.child;case 6:return a===null&&lm(c),null;case 13:return r0(a,c,p);case 4:return mm(c,c.stateNode.containerInfo),v=c.pendingProps,a===null?c.child=rl(c,null,v,p):ar(a,c,v,p),c.child;case 11:return v=c.type,S=c.pendingProps,S=c.elementType===v?S:gs(v,S),JS(a,c,v,S,p);case 7:return ar(a,c,c.pendingProps,p),c.child;case 8:return ar(a,c,c.pendingProps.children,p),c.child;case 12:return ar(a,c,c.pendingProps.children,p),c.child;case 10:e:{if(v=c.type._context,S=c.pendingProps,E=c.memoizedProps,T=S.value,Qt(sf,v._currentValue),v._currentValue=T,E!==null)if(ps(E.value,T)){if(E.children===S.children&&!yr.current){c=fo(a,c,p);break e}}else for(E=c.child,E!==null&&(E.return=c);E!==null;){var I=E.dependencies;if(I!==null){T=E.child;for(var $=I.firstContext;$!==null;){if($.context===v){if(E.tag===1){$=uo(-1,p&-p),$.tag=2;var ae=E.updateQueue;if(ae!==null){ae=ae.shared;var xe=ae.pending;xe===null?$.next=$:($.next=xe.next,xe.next=$),ae.pending=$}}E.lanes|=p,$=E.alternate,$!==null&&($.lanes|=p),pm(E.return,p,c),I.lanes|=p;break}$=$.next}}else if(E.tag===10)T=E.type===c.type?null:E.child;else if(E.tag===18){if(T=E.return,T===null)throw Error(n(341));T.lanes|=p,I=T.alternate,I!==null&&(I.lanes|=p),pm(T,p,c),T=E.sibling}else T=E.child;if(T!==null)T.return=E;else for(T=E;T!==null;){if(T===c){T=null;break}if(E=T.sibling,E!==null){E.return=T.return,T=E;break}T=T.return}E=T}ar(a,c,S.children,p),c=c.child}return c;case 9:return S=c.type,v=c.pendingProps.children,ol(c,p),S=Yr(S),v=v(S),c.flags|=1,ar(a,c,v,p),c.child;case 14:return v=c.type,S=gs(v,c.pendingProps),S=gs(v.type,S),QS(a,c,v,S,p);case 15:return ZS(a,c,c.type,c.pendingProps,p);case 17:return v=c.type,S=c.pendingProps,S=c.elementType===v?S:gs(v,S),vf(a,c),c.tag=1,br(v)?(a=!0,Yd(c)):a=!1,ol(c,p),US(c,v,S),Mm(c,v,S,p),Om(null,c,v,!0,a,p);case 19:return o0(a,c,p);case 22:return YS(a,c,p)}throw Error(n(156,c.tag))};function M0(a,c){return Nn(a,c)}function yD(a,c,p,v){this.tag=a,this.key=p,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=c,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=v,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function ts(a,c,p,v){return new yD(a,c,p,v)}function Xm(a){return a=a.prototype,!(!a||!a.isReactComponent)}function bD(a){if(typeof a=="function")return Xm(a)?1:0;if(a!=null){if(a=a.$$typeof,a===V)return 11;if(a===ie)return 14}return 2}function ia(a,c){var p=a.alternate;return p===null?(p=ts(a.tag,c,a.key,a.mode),p.elementType=a.elementType,p.type=a.type,p.stateNode=a.stateNode,p.alternate=a,a.alternate=p):(p.pendingProps=c,p.type=a.type,p.flags=0,p.subtreeFlags=0,p.deletions=null),p.flags=a.flags&14680064,p.childLanes=a.childLanes,p.lanes=a.lanes,p.child=a.child,p.memoizedProps=a.memoizedProps,p.memoizedState=a.memoizedState,p.updateQueue=a.updateQueue,c=a.dependencies,p.dependencies=c===null?null:{lanes:c.lanes,firstContext:c.firstContext},p.sibling=a.sibling,p.index=a.index,p.ref=a.ref,p}function Nf(a,c,p,v,S,E){var T=2;if(v=a,typeof a=="function")Xm(a)&&(T=1);else if(typeof a=="string")T=5;else e:switch(a){case O:return ni(p.children,S,E,c);case D:T=8,S|=8;break;case z:return a=ts(12,p,c,S|2),a.elementType=z,a.lanes=E,a;case G:return a=ts(13,p,c,S),a.elementType=G,a.lanes=E,a;case W:return a=ts(19,p,c,S),a.elementType=W,a.lanes=E,a;case Y:return Mf(p,S,E,c);default:if(typeof a=="object"&&a!==null)switch(a.$$typeof){case Q:T=10;break e;case pe:T=9;break e;case V:T=11;break e;case ie:T=14;break e;case re:T=16,v=null;break e}throw Error(n(130,a==null?a:typeof a,""))}return c=ts(T,p,c,S),c.elementType=a,c.type=v,c.lanes=E,c}function ni(a,c,p,v){return a=ts(7,a,v,c),a.lanes=p,a}function Mf(a,c,p,v){return a=ts(22,a,v,c),a.elementType=Y,a.lanes=p,a.stateNode={isHidden:!1},a}function ev(a,c,p){return a=ts(6,a,null,c),a.lanes=p,a}function tv(a,c,p){return c=ts(4,a.children!==null?a.children:[],a.key,c),c.lanes=p,c.stateNode={containerInfo:a.containerInfo,pendingChildren:null,implementation:a.implementation},c}function xD(a,c,p,v,S){this.tag=c,this.containerInfo=a,this.finishedWork=this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.pendingContext=this.context=null,this.callbackPriority=0,this.eventTimes=Ng(0),this.expirationTimes=Ng(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Ng(0),this.identifierPrefix=v,this.onRecoverableError=S,this.mutableSourceEagerHydrationData=null}function nv(a,c,p,v,S,E,T,I,$){return a=new xD(a,c,p,I,$),c===1?(c=1,E===!0&&(c|=8)):c=0,E=ts(3,null,null,c),a.current=E,E.stateNode=a,E.memoizedState={element:v,isDehydrated:p,cache:null,transitions:null,pendingSuspenseBoundaries:null},gm(E),a}function wD(a,c,p){var v=3"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(e)}catch(t){console.error(t)}}return e(),cv.exports=fF(),cv.exports}var Q0;function pF(){if(Q0)return Ff;Q0=1;var e=tj();return Ff.createRoot=e.createRoot,Ff.hydrateRoot=e.hydrateRoot,Ff}var hF=pF();const gF=fd(hF),mF=(...e)=>{console?.warn&&(fi(e[0])&&(e[0]=`react-i18next:: ${e[0]}`),console.warn(...e))},Z0={},jy=(...e)=>{fi(e[0])&&Z0[e[0]]||(fi(e[0])&&(Z0[e[0]]=new Date),mF(...e))},nj=(e,t)=>()=>{if(e.isInitialized)t();else{const n=()=>{setTimeout(()=>{e.off("initialized",n)},0),t()};e.on("initialized",n)}},Y0=(e,t,n)=>{e.loadNamespaces(t,nj(e,n))},X0=(e,t,n,r)=>{fi(n)&&(n=[n]),n.forEach(s=>{e.options.ns.indexOf(s)<0&&e.options.ns.push(s)}),e.loadLanguages(t,nj(e,r))},vF=(e,t,n={})=>!t.languages||!t.languages.length?(jy("i18n.languages were undefined or empty",t.languages),!0):t.hasLoadedNamespace(e,{lng:n.lng,precheck:(r,s)=>{if(n.bindI18n?.indexOf("languageChanging")>-1&&r.services.backendConnector.backend&&r.isLanguageChangingTo&&!s(r.isLanguageChangingTo,e))return!1}}),fi=e=>typeof e=="string",yF=e=>typeof e=="object"&&e!==null,bF=/&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g,xF={"&":"&","&":"&","<":"<","<":"<",">":">",">":">","'":"'","'":"'",""":'"',""":'"'," ":" "," ":" ","©":"©","©":"©","®":"®","®":"®","…":"…","…":"…","/":"/","/":"/"},wF=e=>xF[e],SF=e=>e.replace(bF,wF);let Ty={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transWrapTextNodes:"",transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0,unescape:SF};const CF=(e={})=>{Ty={...Ty,...e}},EF=()=>Ty;let rj;const kF=e=>{rj=e},jF=()=>rj,TF={type:"3rdParty",init(e){CF(e.options.react),kF(e)}},sj=y.createContext();class NF{constructor(){this.usedNamespaces={}}addUsedNamespaces(t){t.forEach(n=>{this.usedNamespaces[n]??=!0})}getUsedNamespaces(){return Object.keys(this.usedNamespaces)}}const MF=(e,t)=>{const n=y.useRef();return y.useEffect(()=>{n.current=e},[e,t]),n.current},oj=(e,t,n,r)=>e.getFixedT(t,n,r),_F=(e,t,n,r)=>y.useCallback(oj(e,t,n,r),[e,t,n,r]),Ve=(e,t={})=>{const{i18n:n}=t,{i18n:r,defaultNS:s}=y.useContext(sj)||{},o=n||r||jF();if(o&&!o.reportNamespaces&&(o.reportNamespaces=new NF),!o){jy("You will need to pass in an i18next instance by using initReactI18next");const _=(N,O)=>fi(O)?O:yF(O)&&fi(O.defaultValue)?O.defaultValue:Array.isArray(N)?N[N.length-1]:N,R=[_,{},!1];return R.t=_,R.i18n={},R.ready=!1,R}o.options.react?.wait&&jy("It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");const l={...EF(),...o.options.react,...t},{useSuspense:u,keyPrefix:d}=l;let f=s||o.options?.defaultNS;f=fi(f)?[f]:f||["translation"],o.reportNamespaces.addUsedNamespaces?.(f);const h=(o.isInitialized||o.initializedStoreOnce)&&f.every(_=>vF(_,o,l)),m=_F(o,t.lng||null,l.nsMode==="fallback"?f:f[0],d),g=()=>m,x=()=>oj(o,t.lng||null,l.nsMode==="fallback"?f:f[0],d),[b,w]=y.useState(g);let C=f.join();t.lng&&(C=`${t.lng}${C}`);const k=MF(C),j=y.useRef(!0);y.useEffect(()=>{const{bindI18n:_,bindI18nStore:R}=l;j.current=!0,!h&&!u&&(t.lng?X0(o,t.lng,f,()=>{j.current&&w(x)}):Y0(o,f,()=>{j.current&&w(x)})),h&&k&&k!==C&&j.current&&w(x);const N=()=>{j.current&&w(x)};return _&&o?.on(_,N),R&&o?.store.on(R,N),()=>{j.current=!1,o&&_?.split(" ").forEach(O=>o.off(O,N)),R&&o&&R.split(" ").forEach(O=>o.store.off(O,N))}},[o,C]),y.useEffect(()=>{j.current&&h&&w(g)},[o,d,h]);const M=[b,o,h];if(M.t=b,M.i18n=o,M.ready=h,h||!h&&!u)return M;throw new Promise(_=>{t.lng?X0(o,t.lng,f,()=>_()):Y0(o,f,()=>_())})};function RF({i18n:e,defaultNS:t,children:n}){const r=y.useMemo(()=>({i18n:e,defaultNS:t}),[e,t]);return y.createElement(sj.Provider,{value:r},n)}var Ma=tj();const Ib=fd(Ma),PF=Bk({__proto__:null,default:Ib},[Ma]);/** * @remix-run/router v1.18.0 * * Copyright (c) Remix Software Inc. * * This source code is licensed under the MIT license found in the * LICENSE.md file in the root directory of this source tree. * * @license MIT */function mn(){return mn=Object.assign?Object.assign.bind():function(e){for(var t=1;t"u")throw new Error(t)}function Ll(e,t){if(!e){typeof console<"u"&&console.warn(t);try{throw new Error(t)}catch{}}}function IF(){return Math.random().toString(36).substr(2,8)}function tC(e,t){return{usr:e.state,key:e.key,idx:t}}function Iu(e,t,n,r){return n===void 0&&(n=null),mn({pathname:typeof e=="string"?e:e.pathname,search:"",hash:""},typeof t=="string"?_a(t):t,{state:n,key:t&&t.key||r||IF()})}function wi(e){let{pathname:t="/",search:n="",hash:r=""}=e;return n&&n!=="?"&&(t+=n.charAt(0)==="?"?n:"?"+n),r&&r!=="#"&&(t+=r.charAt(0)==="#"?r:"#"+r),t}function _a(e){let t={};if(e){let n=e.indexOf("#");n>=0&&(t.hash=e.substr(n),e=e.substr(0,n));let r=e.indexOf("?");r>=0&&(t.search=e.substr(r),e=e.substr(0,r)),e&&(t.pathname=e)}return t}function AF(e,t,n,r){r===void 0&&(r={});let{window:s=document.defaultView,v5Compat:o=!1}=r,l=s.history,u=_n.Pop,d=null,f=h();f==null&&(f=0,l.replaceState(mn({},l.state,{idx:f}),""));function h(){return(l.state||{idx:null}).idx}function m(){u=_n.Pop;let C=h(),k=C==null?null:C-f;f=C,d&&d({action:u,location:w.location,delta:k})}function g(C,k){u=_n.Push;let j=Iu(w.location,C,k);f=h()+1;let M=tC(j,f),_=w.createHref(j);try{l.pushState(M,"",_)}catch(R){if(R instanceof DOMException&&R.name==="DataCloneError")throw R;s.location.assign(_)}o&&d&&d({action:u,location:w.location,delta:1})}function x(C,k){u=_n.Replace;let j=Iu(w.location,C,k);f=h();let M=tC(j,f),_=w.createHref(j);l.replaceState(M,"",_),o&&d&&d({action:u,location:w.location,delta:0})}function b(C){let k=s.location.origin!=="null"?s.location.origin:s.location.href,j=typeof C=="string"?C:wi(C);return j=j.replace(/ $/,"%20"),Ct(k,"No window.location.(origin|href) available to create URL for href: "+j),new URL(j,k)}let w={get action(){return u},get location(){return e(s,l)},listen(C){if(d)throw new Error("A history only accepts one active listener");return s.addEventListener(eC,m),d=C,()=>{s.removeEventListener(eC,m),d=null}},createHref(C){return t(s,C)},createURL:b,encodeLocation(C){let k=b(C);return{pathname:k.pathname,search:k.search,hash:k.hash}},push:g,replace:x,go(C){return l.go(C)}};return w}var Zt;(function(e){e.data="data",e.deferred="deferred",e.redirect="redirect",e.error="error"})(Zt||(Zt={}));const DF=new Set(["lazy","caseSensitive","path","id","index","children"]);function FF(e){return e.index===!0}function Au(e,t,n,r){return n===void 0&&(n=[]),r===void 0&&(r={}),e.map((s,o)=>{let l=[...n,String(o)],u=typeof s.id=="string"?s.id:l.join("-");if(Ct(s.index!==!0||!s.children,"Cannot specify children on an index route"),Ct(!r[u],'Found a route id collision on id "'+u+`". Route id's must be globally unique within Data Router usages`),FF(s)){let d=mn({},s,t(s),{id:u});return r[u]=d,d}else{let d=mn({},s,t(s),{id:u,children:void 0});return r[u]=d,s.children&&(d.children=Au(s.children,t,l,r)),d}})}function oi(e,t,n){return n===void 0&&(n="/"),cp(e,t,n,!1)}function cp(e,t,n,r){let s=typeof t=="string"?_a(t):t,o=Xl(s.pathname||"/",n);if(o==null)return null;let l=aj(e);$F(l);let u=null;for(let d=0;u==null&&d{let d={relativePath:u===void 0?o.path||"":u,caseSensitive:o.caseSensitive===!0,childrenIndex:l,route:o};d.relativePath.startsWith("/")&&(Ct(d.relativePath.startsWith(r),'Absolute route path "'+d.relativePath+'" nested under path '+('"'+r+'" is not valid. An absolute child route path ')+"must start with the combined path of all its parent routes."),d.relativePath=d.relativePath.slice(r.length));let f=To([r,d.relativePath]),h=n.concat(d);o.children&&o.children.length>0&&(Ct(o.index!==!0,"Index routes must not have child routes. Please remove "+('all child routes from route path "'+f+'".')),aj(o.children,t,h,f)),!(o.path==null&&!o.index)&&t.push({path:f,score:KF(f,o.index),routesMeta:h})};return e.forEach((o,l)=>{var u;if(o.path===""||!((u=o.path)!=null&&u.includes("?")))s(o,l);else for(let d of ij(o.path))s(o,l,d)}),t}function ij(e){let t=e.split("/");if(t.length===0)return[];let[n,...r]=t,s=n.endsWith("?"),o=n.replace(/\?$/,"");if(r.length===0)return s?[o,""]:[o];let l=ij(r.join("/")),u=[];return u.push(...l.map(d=>d===""?o:[o,d].join("/"))),s&&u.push(...l),u.map(d=>e.startsWith("/")&&d===""?"/":d)}function $F(e){e.sort((t,n)=>t.score!==n.score?n.score-t.score:WF(t.routesMeta.map(r=>r.childrenIndex),n.routesMeta.map(r=>r.childrenIndex)))}const BF=/^:[\w-]+$/,zF=3,UF=2,VF=1,HF=10,qF=-2,nC=e=>e==="*";function KF(e,t){let n=e.split("/"),r=n.length;return n.some(nC)&&(r+=qF),t&&(r+=UF),n.filter(s=>!nC(s)).reduce((s,o)=>s+(BF.test(o)?zF:o===""?VF:HF),r)}function WF(e,t){return e.length===t.length&&e.slice(0,-1).every((r,s)=>r===t[s])?e[e.length-1]-t[t.length-1]:0}function GF(e,t,n){n===void 0&&(n=!1);let{routesMeta:r}=e,s={},o="/",l=[];for(let u=0;u{let{paramName:g,isOptional:x}=h;if(g==="*"){let w=u[m]||"";l=o.slice(0,o.length-w.length).replace(/(.)\/+$/,"$1")}const b=u[m];return x&&!b?f[g]=void 0:f[g]=(b||"").replace(/%2F/g,"/"),f},{}),pathname:o,pathnameBase:l,pattern:e}}function JF(e,t,n){t===void 0&&(t=!1),n===void 0&&(n=!0),Ll(e==="*"||!e.endsWith("*")||e.endsWith("/*"),'Route path "'+e+'" will be treated as if it were '+('"'+e.replace(/\*$/,"/*")+'" because the `*` character must ')+"always follow a `/` in the pattern. To get rid of this warning, "+('please change the route path to "'+e.replace(/\*$/,"/*")+'".'));let r=[],s="^"+e.replace(/\/*\*?$/,"").replace(/^\/*/,"/").replace(/[\\.*+^${}|()[\]]/g,"\\$&").replace(/\/:([\w-]+)(\?)?/g,(l,u,d)=>(r.push({paramName:u,isOptional:d!=null}),d?"/?([^\\/]+)?":"/([^\\/]+)"));return e.endsWith("*")?(r.push({paramName:"*"}),s+=e==="*"||e==="/*"?"(.*)$":"(?:\\/(.+)|\\/*)$"):n?s+="\\/*$":e!==""&&e!=="/"&&(s+="(?:(?=\\/|$))"),[new RegExp(s,t?void 0:"i"),r]}function QF(e){try{return e.split("/").map(t=>decodeURIComponent(t).replace(/\//g,"%2F")).join("/")}catch(t){return Ll(!1,'The URL path "'+e+'" could not be decoded because it is is a malformed URL segment. This is probably due to a bad percent '+("encoding ("+t+").")),e}}function Xl(e,t){if(t==="/")return e;if(!e.toLowerCase().startsWith(t.toLowerCase()))return null;let n=t.endsWith("/")?t.length-1:t.length,r=e.charAt(n);return r&&r!=="/"?null:e.slice(n)||"/"}function ZF(e,t){t===void 0&&(t="/");let{pathname:n,search:r="",hash:s=""}=typeof e=="string"?_a(e):e;return{pathname:n?n.startsWith("/")?n:YF(n,t):t,search:e2(r),hash:t2(s)}}function YF(e,t){let n=t.replace(/\/+$/,"").split("/");return e.split("/").forEach(s=>{s===".."?n.length>1&&n.pop():s!=="."&&n.push(s)}),n.length>1?n.join("/"):"/"}function fv(e,t,n,r){return"Cannot include a '"+e+"' character in a manually specified "+("`to."+t+"` field ["+JSON.stringify(r)+"]. Please separate it out to the ")+("`to."+n+"` field. Alternatively you may provide the full path as ")+'a string in and the router will parse it for you.'}function lj(e){return e.filter((t,n)=>n===0||t.route.path&&t.route.path.length>0)}function hh(e,t){let n=lj(e);return t?n.map((r,s)=>s===n.length-1?r.pathname:r.pathnameBase):n.map(r=>r.pathnameBase)}function gh(e,t,n,r){r===void 0&&(r=!1);let s;typeof e=="string"?s=_a(e):(s=mn({},e),Ct(!s.pathname||!s.pathname.includes("?"),fv("?","pathname","search",s)),Ct(!s.pathname||!s.pathname.includes("#"),fv("#","pathname","hash",s)),Ct(!s.search||!s.search.includes("#"),fv("#","search","hash",s)));let o=e===""||s.pathname==="",l=o?"/":s.pathname,u;if(l==null)u=n;else{let m=t.length-1;if(!r&&l.startsWith("..")){let g=l.split("/");for(;g[0]==="..";)g.shift(),m-=1;s.pathname=g.join("/")}u=m>=0?t[m]:"/"}let d=ZF(s,u),f=l&&l!=="/"&&l.endsWith("/"),h=(o||l===".")&&n.endsWith("/");return!d.pathname.endsWith("/")&&(f||h)&&(d.pathname+="/"),d}const To=e=>e.join("/").replace(/\/\/+/g,"/"),XF=e=>e.replace(/\/+$/,"").replace(/^\/*/,"/"),e2=e=>!e||e==="?"?"":e.startsWith("?")?e:"?"+e,t2=e=>!e||e==="#"?"":e.startsWith("#")?e:"#"+e;class Ab{constructor(t,n,r,s){s===void 0&&(s=!1),this.status=t,this.statusText=n||"",this.internal=s,r instanceof Error?(this.data=r.toString(),this.error=r):this.data=r}}function mh(e){return e!=null&&typeof e.status=="number"&&typeof e.statusText=="string"&&typeof e.internal=="boolean"&&"data"in e}const cj=["post","put","patch","delete"],n2=new Set(cj),r2=["get",...cj],s2=new Set(r2),o2=new Set([301,302,303,307,308]),a2=new Set([307,308]),pv={state:"idle",location:void 0,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0,json:void 0,text:void 0},i2={state:"idle",data:void 0,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0,json:void 0,text:void 0},eu={state:"unblocked",proceed:void 0,reset:void 0,location:void 0},Db=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,l2=e=>({hasErrorBoundary:!!e.hasErrorBoundary}),uj="remix-router-transitions";function c2(e){const t=e.window?e.window:typeof window<"u"?window:void 0,n=typeof t<"u"&&typeof t.document<"u"&&typeof t.document.createElement<"u",r=!n;Ct(e.routes.length>0,"You must provide a non-empty routes array to createRouter");let s;if(e.mapRouteProperties)s=e.mapRouteProperties;else if(e.detectErrorBoundary){let B=e.detectErrorBoundary;s=K=>({hasErrorBoundary:B(K)})}else s=l2;let o={},l=Au(e.routes,s,void 0,o),u,d=e.basename||"/",f=e.unstable_dataStrategy||h2,h=e.unstable_patchRoutesOnMiss,m=mn({v7_fetcherPersist:!1,v7_normalizeFormMethod:!1,v7_partialHydration:!1,v7_prependBasename:!1,v7_relativeSplatPath:!1,v7_skipActionErrorRevalidation:!1},e.future),g=null,x=new Set,b=null,w=null,C=null,k=e.hydrationData!=null,j=oi(l,e.history.location,d),M=null;if(j==null&&!h){let B=lr(404,{pathname:e.history.location.pathname}),{matches:K,route:oe}=pC(l);j=K,M={[oe.id]:B}}j&&h&&!e.hydrationData&&Ba(j,l,e.history.location.pathname).active&&(j=null);let _;if(!j)_=!1,j=[];else if(j.some(B=>B.route.lazy))_=!1;else if(!j.some(B=>B.route.loader))_=!0;else if(m.v7_partialHydration){let B=e.hydrationData?e.hydrationData.loaderData:null,K=e.hydrationData?e.hydrationData.errors:null,oe=ve=>ve.route.loader?typeof ve.route.loader=="function"&&ve.route.loader.hydrate===!0?!1:B&&B[ve.route.id]!==void 0||K&&K[ve.route.id]!==void 0:!0;if(K){let ve=j.findIndex(Oe=>K[Oe.route.id]!==void 0);_=j.slice(0,ve+1).every(oe)}else _=j.every(oe)}else _=e.hydrationData!=null;let R,N={historyAction:e.history.action,location:e.history.location,matches:j,initialized:_,navigation:pv,restoreScrollPosition:e.hydrationData!=null?!1:null,preventScrollReset:!1,revalidation:"idle",loaderData:e.hydrationData&&e.hydrationData.loaderData||{},actionData:e.hydrationData&&e.hydrationData.actionData||null,errors:e.hydrationData&&e.hydrationData.errors||M,fetchers:new Map,blockers:new Map},O=_n.Pop,D=!1,z,Q=!1,pe=new Map,V=null,G=!1,W=!1,ie=[],re=[],Y=new Map,H=0,q=-1,he=new Map,A=new Set,F=new Map,fe=new Map,te=new Set,de=new Map,ge=new Map,Z=new Map,ye=!1;function Re(){if(g=e.history.listen(B=>{let{action:K,location:oe,delta:ve}=B;if(ye){ye=!1;return}Ll(ge.size===0||ve!=null,"You are trying to use a blocker on a POP navigation to a location that was not created by @remix-run/router. This will fail silently in production. This can happen if you are navigating outside the router via `window.history.pushState`/`window.location.hash` instead of using router navigation APIs. This can also happen if you are using createHashRouter and the user manually changes the URL.");let Oe=Gr({currentLocation:N.location,nextLocation:oe,historyAction:K});if(Oe&&ve!=null){ye=!0,e.history.go(ve*-1),vr(Oe,{state:"blocked",location:oe,proceed(){vr(Oe,{state:"proceeding",proceed:void 0,reset:void 0,location:oe}),e.history.go(ve)},reset(){let We=new Map(N.blockers);We.set(Oe,eu),Fe({blockers:We})}});return}return vn(K,oe)}),n){T2(t,pe);let B=()=>N2(t,pe);t.addEventListener("pagehide",B),V=()=>t.removeEventListener("pagehide",B)}return N.initialized||vn(_n.Pop,N.location,{initialHydration:!0}),R}function $e(){g&&g(),V&&V(),x.clear(),z&&z.abort(),N.fetchers.forEach((B,K)=>Qn(K)),N.blockers.forEach((B,K)=>mr(K))}function Ye(B){return x.add(B),()=>x.delete(B)}function Fe(B,K){K===void 0&&(K={}),N=mn({},N,B);let oe=[],ve=[];m.v7_fetcherPersist&&N.fetchers.forEach((Oe,We)=>{Oe.state==="idle"&&(te.has(We)?ve.push(We):oe.push(We))}),[...x].forEach(Oe=>Oe(N,{deletedFetchers:ve,unstable_viewTransitionOpts:K.viewTransitionOpts,unstable_flushSync:K.flushSync===!0})),m.v7_fetcherPersist&&(oe.forEach(Oe=>N.fetchers.delete(Oe)),ve.forEach(Oe=>Qn(Oe)))}function ft(B,K,oe){var ve,Oe;let{flushSync:We}=oe===void 0?{}:oe,st=N.actionData!=null&&N.navigation.formMethod!=null&&bs(N.navigation.formMethod)&&N.navigation.state==="loading"&&((ve=B.state)==null?void 0:ve._isRedirect)!==!0,Me;K.actionData?Object.keys(K.actionData).length>0?Me=K.actionData:Me=null:st?Me=N.actionData:Me=null;let ht=K.loaderData?dC(N.loaderData,K.loaderData,K.matches||[],K.errors):N.loaderData,Ge=N.blockers;Ge.size>0&&(Ge=new Map(Ge),Ge.forEach((Vt,Ht)=>Ge.set(Ht,eu)));let Xe=D===!0||N.navigation.formMethod!=null&&bs(N.navigation.formMethod)&&((Oe=B.state)==null?void 0:Oe._isRedirect)!==!0;u&&(l=u,u=void 0),G||O===_n.Pop||(O===_n.Push?e.history.push(B,B.state):O===_n.Replace&&e.history.replace(B,B.state));let Ut;if(O===_n.Pop){let Vt=pe.get(N.location.pathname);Vt&&Vt.has(B.pathname)?Ut={currentLocation:N.location,nextLocation:B}:pe.has(B.pathname)&&(Ut={currentLocation:B,nextLocation:N.location})}else if(Q){let Vt=pe.get(N.location.pathname);Vt?Vt.add(B.pathname):(Vt=new Set([B.pathname]),pe.set(N.location.pathname,Vt)),Ut={currentLocation:N.location,nextLocation:B}}Fe(mn({},K,{actionData:Me,loaderData:ht,historyAction:O,location:B,initialized:!0,navigation:pv,revalidation:"idle",restoreScrollPosition:yc(B,K.matches||N.matches),preventScrollReset:Xe,blockers:Ge}),{viewTransitionOpts:Ut,flushSync:We===!0}),O=_n.Pop,D=!1,Q=!1,G=!1,W=!1,ie=[],re=[]}async function ln(B,K){if(typeof B=="number"){e.history.go(B);return}let oe=Ny(N.location,N.matches,d,m.v7_prependBasename,B,m.v7_relativeSplatPath,K?.fromRouteId,K?.relative),{path:ve,submission:Oe,error:We}=sC(m.v7_normalizeFormMethod,!1,oe,K),st=N.location,Me=Iu(N.location,ve,K&&K.state);Me=mn({},Me,e.history.encodeLocation(Me));let ht=K&&K.replace!=null?K.replace:void 0,Ge=_n.Push;ht===!0?Ge=_n.Replace:ht===!1||Oe!=null&&bs(Oe.formMethod)&&Oe.formAction===N.location.pathname+N.location.search&&(Ge=_n.Replace);let Xe=K&&"preventScrollReset"in K?K.preventScrollReset===!0:void 0,Ut=(K&&K.unstable_flushSync)===!0,Vt=Gr({currentLocation:st,nextLocation:Me,historyAction:Ge});if(Vt){vr(Vt,{state:"blocked",location:Me,proceed(){vr(Vt,{state:"proceeding",proceed:void 0,reset:void 0,location:Me}),ln(B,K)},reset(){let Ht=new Map(N.blockers);Ht.set(Vt,eu),Fe({blockers:Ht})}});return}return await vn(Ge,Me,{submission:Oe,pendingError:We,preventScrollReset:Xe,replace:K&&K.replace,enableViewTransition:K&&K.unstable_viewTransition,flushSync:Ut})}function Sn(){if(yn(),Fe({revalidation:"loading"}),N.navigation.state!=="submitting"){if(N.navigation.state==="idle"){vn(N.historyAction,N.location,{startUninterruptedRevalidation:!0});return}vn(O||N.historyAction,N.navigation.location,{overrideNavigation:N.navigation})}}async function vn(B,K,oe){z&&z.abort(),z=null,O=B,G=(oe&&oe.startUninterruptedRevalidation)===!0,_d(N.location,N.matches),D=(oe&&oe.preventScrollReset)===!0,Q=(oe&&oe.enableViewTransition)===!0;let ve=u||l,Oe=oe&&oe.overrideNavigation,We=oi(ve,K,d),st=(oe&&oe.flushSync)===!0,Me=Ba(We,ve,K.pathname);if(Me.active&&Me.matches&&(We=Me.matches),!We){let{error:At,notFoundMatches:Nn,route:fn}=Jr(K.pathname);ft(K,{matches:Nn,loaderData:{},errors:{[fn.id]:At}},{flushSync:st});return}if(N.initialized&&!W&&x2(N.location,K)&&!(oe&&oe.submission&&bs(oe.submission.formMethod))){ft(K,{matches:We},{flushSync:st});return}z=new AbortController;let ht=fl(e.history,K,z.signal,oe&&oe.submission),Ge;if(oe&&oe.pendingError)Ge=[jl(We).route.id,{type:Zt.error,error:oe.pendingError}];else if(oe&&oe.submission&&bs(oe.submission.formMethod)){let At=await Cn(ht,K,oe.submission,We,Me.active,{replace:oe.replace,flushSync:st});if(At.shortCircuited)return;if(At.pendingActionResult){let[Nn,fn]=At.pendingActionResult;if(Br(fn)&&mh(fn.error)&&fn.error.status===404){z=null,ft(K,{matches:At.matches,loaderData:{},errors:{[Nn]:fn.error}});return}}We=At.matches||We,Ge=At.pendingActionResult,Oe=hv(K,oe.submission),st=!1,Me.active=!1,ht=fl(e.history,ht.url,ht.signal)}let{shortCircuited:Xe,matches:Ut,loaderData:Vt,errors:Ht}=await L(ht,K,We,Me.active,Oe,oe&&oe.submission,oe&&oe.fetcherSubmission,oe&&oe.replace,oe&&oe.initialHydration===!0,st,Ge);Xe||(z=null,ft(K,mn({matches:Ut||We},fC(Ge),{loaderData:Vt,errors:Ht})))}async function Cn(B,K,oe,ve,Oe,We){We===void 0&&(We={}),yn();let st=k2(K,oe);if(Fe({navigation:st},{flushSync:We.flushSync===!0}),Oe){let Ge=await za(ve,K.pathname,B.signal);if(Ge.type==="aborted")return{shortCircuited:!0};if(Ge.type==="error"){let{boundaryId:Xe,error:Ut}=_r(K.pathname,Ge);return{matches:Ge.partialMatches,pendingActionResult:[Xe,{type:Zt.error,error:Ut}]}}else if(Ge.matches)ve=Ge.matches;else{let{notFoundMatches:Xe,error:Ut,route:Vt}=Jr(K.pathname);return{matches:Xe,pendingActionResult:[Vt.id,{type:Zt.error,error:Ut}]}}}let Me,ht=gu(ve,K);if(!ht.route.action&&!ht.route.lazy)Me={type:Zt.error,error:lr(405,{method:B.method,pathname:K.pathname,routeId:ht.route.id})};else if(Me=(await bt("action",B,[ht],ve))[0],B.signal.aborted)return{shortCircuited:!0};if(ii(Me)){let Ge;return We&&We.replace!=null?Ge=We.replace:Ge=lC(Me.response.headers.get("Location"),new URL(B.url),d)===N.location.pathname+N.location.search,await Be(B,Me,{submission:oe,replace:Ge}),{shortCircuited:!0}}if(ai(Me))throw lr(400,{type:"defer-action"});if(Br(Me)){let Ge=jl(ve,ht.route.id);return(We&&We.replace)!==!0&&(O=_n.Push),{matches:ve,pendingActionResult:[Ge.route.id,Me]}}return{matches:ve,pendingActionResult:[ht.route.id,Me]}}async function L(B,K,oe,ve,Oe,We,st,Me,ht,Ge,Xe){let Ut=Oe||hv(K,We),Vt=We||st||mC(Ut),Ht=!G&&(!m.v7_partialHydration||!ht);if(ve){if(Ht){let Dt=X(Xe);Fe(mn({navigation:Ut},Dt!==void 0?{actionData:Dt}:{}),{flushSync:Ge})}let pt=await za(oe,K.pathname,B.signal);if(pt.type==="aborted")return{shortCircuited:!0};if(pt.type==="error"){let{boundaryId:Dt,error:or}=_r(K.pathname,pt);return{matches:pt.partialMatches,loaderData:{},errors:{[Dt]:or}}}else if(pt.matches)oe=pt.matches;else{let{error:Dt,notFoundMatches:or,route:Tt}=Jr(K.pathname);return{matches:or,loaderData:{},errors:{[Tt.id]:Dt}}}}let At=u||l,[Nn,fn]=oC(e.history,N,oe,Vt,K,m.v7_partialHydration&&ht===!0,m.v7_skipActionErrorRevalidation,W,ie,re,te,F,A,At,d,Xe);if(Rr(pt=>!(oe&&oe.some(Dt=>Dt.route.id===pt))||Nn&&Nn.some(Dt=>Dt.route.id===pt)),q=++H,Nn.length===0&&fn.length===0){let pt=ut();return ft(K,mn({matches:oe,loaderData:{},errors:Xe&&Br(Xe[1])?{[Xe[0]]:Xe[1].error}:null},fC(Xe),pt?{fetchers:new Map(N.fetchers)}:{}),{flushSync:Ge}),{shortCircuited:!0}}if(Ht){let pt={};if(!ve){pt.navigation=Ut;let Dt=X(Xe);Dt!==void 0&&(pt.actionData=Dt)}fn.length>0&&(pt.fetchers=ue(fn)),Fe(pt,{flushSync:Ge})}fn.forEach(pt=>{Y.has(pt.key)&&Bn(pt.key),pt.controller&&Y.set(pt.key,pt.controller)});let Va=()=>fn.forEach(pt=>Bn(pt.key));z&&z.signal.addEventListener("abort",Va);let{loaderResults:Os,fetcherResults:Gt}=await Wt(N.matches,oe,Nn,fn,B);if(B.signal.aborted)return{shortCircuited:!0};z&&z.signal.removeEventListener("abort",Va),fn.forEach(pt=>Y.delete(pt.key));let Vo=hC([...Os,...Gt]);if(Vo){if(Vo.idx>=Nn.length){let pt=fn[Vo.idx-Nn.length].key;A.add(pt)}return await Be(B,Vo.result,{replace:Me}),{shortCircuited:!0}}let{loaderData:Is,errors:Pr}=uC(N,oe,Nn,Os,Xe,fn,Gt,de);de.forEach((pt,Dt)=>{pt.subscribe(or=>{(or||pt.done)&&de.delete(Dt)})}),m.v7_partialHydration&&ht&&N.errors&&Object.entries(N.errors).filter(pt=>{let[Dt]=pt;return!Nn.some(or=>or.route.id===Dt)}).forEach(pt=>{let[Dt,or]=pt;Pr=Object.assign(Pr||{},{[Dt]:or})});let so=ut(),Vi=It(q),Ha=so||Vi||fn.length>0;return mn({matches:oe,loaderData:Is,errors:Pr},Ha?{fetchers:new Map(N.fetchers)}:{})}function X(B){if(B&&!Br(B[1]))return{[B[0]]:B[1].data};if(N.actionData)return Object.keys(N.actionData).length===0?null:N.actionData}function ue(B){return B.forEach(K=>{let oe=N.fetchers.get(K.key),ve=tu(void 0,oe?oe.data:void 0);N.fetchers.set(K.key,ve)}),new Map(N.fetchers)}function Ne(B,K,oe,ve){if(r)throw new Error("router.fetch() was called during the server render, but it shouldn't be. You are likely calling a useFetcher() method in the body of your component. Try moving it to a useEffect or a callback.");Y.has(B)&&Bn(B);let Oe=(ve&&ve.unstable_flushSync)===!0,We=u||l,st=Ny(N.location,N.matches,d,m.v7_prependBasename,oe,m.v7_relativeSplatPath,K,ve?.relative),Me=oi(We,st,d),ht=Ba(Me,We,st);if(ht.active&&ht.matches&&(Me=ht.matches),!Me){En(B,K,lr(404,{pathname:st}),{flushSync:Oe});return}let{path:Ge,submission:Xe,error:Ut}=sC(m.v7_normalizeFormMethod,!0,st,ve);if(Ut){En(B,K,Ut,{flushSync:Oe});return}let Vt=gu(Me,Ge);if(D=(ve&&ve.preventScrollReset)===!0,Xe&&bs(Xe.formMethod)){je(B,K,Ge,Vt,Me,ht.active,Oe,Xe);return}F.set(B,{routeId:K,path:Ge}),Se(B,K,Ge,Vt,Me,ht.active,Oe,Xe)}async function je(B,K,oe,ve,Oe,We,st,Me){yn(),F.delete(B);function ht(Tt){if(!Tt.route.action&&!Tt.route.lazy){let fs=lr(405,{method:Me.formMethod,pathname:oe,routeId:K});return En(B,K,fs,{flushSync:st}),!0}return!1}if(!We&&ht(ve))return;let Ge=N.fetchers.get(B);bn(B,j2(Me,Ge),{flushSync:st});let Xe=new AbortController,Ut=fl(e.history,oe,Xe.signal,Me);if(We){let Tt=await za(Oe,oe,Ut.signal);if(Tt.type==="aborted")return;if(Tt.type==="error"){let{error:fs}=_r(oe,Tt);En(B,K,fs,{flushSync:st});return}else if(Tt.matches){if(Oe=Tt.matches,ve=gu(Oe,oe),ht(ve))return}else{En(B,K,lr(404,{pathname:oe}),{flushSync:st});return}}Y.set(B,Xe);let Vt=H,At=(await bt("action",Ut,[ve],Oe))[0];if(Ut.signal.aborted){Y.get(B)===Xe&&Y.delete(B);return}if(m.v7_fetcherPersist&&te.has(B)){if(ii(At)||Br(At)){bn(B,da(void 0));return}}else{if(ii(At))if(Y.delete(B),q>Vt){bn(B,da(void 0));return}else return A.add(B),bn(B,tu(Me)),Be(Ut,At,{fetcherSubmission:Me});if(Br(At)){En(B,K,At.error);return}}if(ai(At))throw lr(400,{type:"defer-action"});let Nn=N.navigation.location||N.location,fn=fl(e.history,Nn,Xe.signal),Va=u||l,Os=N.navigation.state!=="idle"?oi(Va,N.navigation.location,d):N.matches;Ct(Os,"Didn't find any matches after fetcher action");let Gt=++H;he.set(B,Gt);let Vo=tu(Me,At.data);N.fetchers.set(B,Vo);let[Is,Pr]=oC(e.history,N,Os,Me,Nn,!1,m.v7_skipActionErrorRevalidation,W,ie,re,te,F,A,Va,d,[ve.route.id,At]);Pr.filter(Tt=>Tt.key!==B).forEach(Tt=>{let fs=Tt.key,Rd=N.fetchers.get(fs),jg=tu(void 0,Rd?Rd.data:void 0);N.fetchers.set(fs,jg),Y.has(fs)&&Bn(fs),Tt.controller&&Y.set(fs,Tt.controller)}),Fe({fetchers:new Map(N.fetchers)});let so=()=>Pr.forEach(Tt=>Bn(Tt.key));Xe.signal.addEventListener("abort",so);let{loaderResults:Vi,fetcherResults:Ha}=await Wt(N.matches,Os,Is,Pr,fn);if(Xe.signal.aborted)return;Xe.signal.removeEventListener("abort",so),he.delete(B),Y.delete(B),Pr.forEach(Tt=>Y.delete(Tt.key));let pt=hC([...Vi,...Ha]);if(pt){if(pt.idx>=Is.length){let Tt=Pr[pt.idx-Is.length].key;A.add(Tt)}return Be(fn,pt.result)}let{loaderData:Dt,errors:or}=uC(N,N.matches,Is,Vi,void 0,Pr,Ha,de);if(N.fetchers.has(B)){let Tt=da(At.data);N.fetchers.set(B,Tt)}It(Gt),N.navigation.state==="loading"&&Gt>q?(Ct(O,"Expected pending action"),z&&z.abort(),ft(N.navigation.location,{matches:Os,loaderData:Dt,errors:or,fetchers:new Map(N.fetchers)})):(Fe({errors:or,loaderData:dC(N.loaderData,Dt,Os,or),fetchers:new Map(N.fetchers)}),W=!1)}async function Se(B,K,oe,ve,Oe,We,st,Me){let ht=N.fetchers.get(B);bn(B,tu(Me,ht?ht.data:void 0),{flushSync:st});let Ge=new AbortController,Xe=fl(e.history,oe,Ge.signal);if(We){let At=await za(Oe,oe,Xe.signal);if(At.type==="aborted")return;if(At.type==="error"){let{error:Nn}=_r(oe,At);En(B,K,Nn,{flushSync:st});return}else if(At.matches)Oe=At.matches,ve=gu(Oe,oe);else{En(B,K,lr(404,{pathname:oe}),{flushSync:st});return}}Y.set(B,Ge);let Ut=H,Ht=(await bt("loader",Xe,[ve],Oe))[0];if(ai(Ht)&&(Ht=await gj(Ht,Xe.signal,!0)||Ht),Y.get(B)===Ge&&Y.delete(B),!Xe.signal.aborted){if(te.has(B)){bn(B,da(void 0));return}if(ii(Ht))if(q>Ut){bn(B,da(void 0));return}else{A.add(B),await Be(Xe,Ht);return}if(Br(Ht)){En(B,K,Ht.error);return}Ct(!ai(Ht),"Unhandled fetcher deferred data"),bn(B,da(Ht.data))}}async function Be(B,K,oe){let{submission:ve,fetcherSubmission:Oe,replace:We}=oe===void 0?{}:oe;K.response.headers.has("X-Remix-Revalidate")&&(W=!0);let st=K.response.headers.get("Location");Ct(st,"Expected a Location header on the redirect Response"),st=lC(st,new URL(B.url),d);let Me=Iu(N.location,st,{_isRedirect:!0});if(n){let Ht=!1;if(K.response.headers.has("X-Remix-Reload-Document"))Ht=!0;else if(Db.test(st)){const At=e.history.createURL(st);Ht=At.origin!==t.location.origin||Xl(At.pathname,d)==null}if(Ht){We?t.location.replace(st):t.location.assign(st);return}}z=null;let ht=We===!0?_n.Replace:_n.Push,{formMethod:Ge,formAction:Xe,formEncType:Ut}=N.navigation;!ve&&!Oe&&Ge&&Xe&&Ut&&(ve=mC(N.navigation));let Vt=ve||Oe;if(a2.has(K.response.status)&&Vt&&bs(Vt.formMethod))await vn(ht,Me,{submission:mn({},Vt,{formAction:st}),preventScrollReset:D});else{let Ht=hv(Me,ve);await vn(ht,Me,{overrideNavigation:Ht,fetcherSubmission:Oe,preventScrollReset:D})}}async function bt(B,K,oe,ve){try{let Oe=await g2(f,B,K,oe,ve,o,s);return await Promise.all(Oe.map((We,st)=>{if(S2(We)){let Me=We.result;return{type:Zt.redirect,response:y2(Me,K,oe[st].route.id,ve,d,m.v7_relativeSplatPath)}}return v2(We)}))}catch(Oe){return oe.map(()=>({type:Zt.error,error:Oe}))}}async function Wt(B,K,oe,ve,Oe){let[We,...st]=await Promise.all([oe.length?bt("loader",Oe,oe,K):[],...ve.map(Me=>{if(Me.matches&&Me.match&&Me.controller){let ht=fl(e.history,Me.path,Me.controller.signal);return bt("loader",ht,[Me.match],Me.matches).then(Ge=>Ge[0])}else return Promise.resolve({type:Zt.error,error:lr(404,{pathname:Me.path})})})]);return await Promise.all([gC(B,oe,We,We.map(()=>Oe.signal),!1,N.loaderData),gC(B,ve.map(Me=>Me.match),st,ve.map(Me=>Me.controller?Me.controller.signal:null),!0)]),{loaderResults:We,fetcherResults:st}}function yn(){W=!0,ie.push(...Rr()),F.forEach((B,K)=>{Y.has(K)&&(re.push(K),Bn(K))})}function bn(B,K,oe){oe===void 0&&(oe={}),N.fetchers.set(B,K),Fe({fetchers:new Map(N.fetchers)},{flushSync:(oe&&oe.flushSync)===!0})}function En(B,K,oe,ve){ve===void 0&&(ve={});let Oe=jl(N.matches,K);Qn(B),Fe({errors:{[Oe.route.id]:oe},fetchers:new Map(N.fetchers)},{flushSync:(ve&&ve.flushSync)===!0})}function gr(B){return m.v7_fetcherPersist&&(fe.set(B,(fe.get(B)||0)+1),te.has(B)&&te.delete(B)),N.fetchers.get(B)||i2}function Qn(B){let K=N.fetchers.get(B);Y.has(B)&&!(K&&K.state==="loading"&&he.has(B))&&Bn(B),F.delete(B),he.delete(B),A.delete(B),te.delete(B),N.fetchers.delete(B)}function ro(B){if(m.v7_fetcherPersist){let K=(fe.get(B)||0)-1;K<=0?(fe.delete(B),te.add(B)):fe.set(B,K)}else Qn(B);Fe({fetchers:new Map(N.fetchers)})}function Bn(B){let K=Y.get(B);Ct(K,"Expected fetch controller: "+B),K.abort(),Y.delete(B)}function Te(B){for(let K of B){let oe=gr(K),ve=da(oe.data);N.fetchers.set(K,ve)}}function ut(){let B=[],K=!1;for(let oe of A){let ve=N.fetchers.get(oe);Ct(ve,"Expected fetcher: "+oe),ve.state==="loading"&&(A.delete(oe),B.push(oe),K=!0)}return Te(B),K}function It(B){let K=[];for(let[oe,ve]of he)if(ve0}function Tn(B,K){let oe=N.blockers.get(B)||eu;return ge.get(B)!==K&&ge.set(B,K),oe}function mr(B){N.blockers.delete(B),ge.delete(B)}function vr(B,K){let oe=N.blockers.get(B)||eu;Ct(oe.state==="unblocked"&&K.state==="blocked"||oe.state==="blocked"&&K.state==="blocked"||oe.state==="blocked"&&K.state==="proceeding"||oe.state==="blocked"&&K.state==="unblocked"||oe.state==="proceeding"&&K.state==="unblocked","Invalid blocker state transition: "+oe.state+" -> "+K.state);let ve=new Map(N.blockers);ve.set(B,K),Fe({blockers:ve})}function Gr(B){let{currentLocation:K,nextLocation:oe,historyAction:ve}=B;if(ge.size===0)return;ge.size>1&&Ll(!1,"A router only supports one blocker at a time");let Oe=Array.from(ge.entries()),[We,st]=Oe[Oe.length-1],Me=N.blockers.get(We);if(!(Me&&Me.state==="proceeding")&&st({currentLocation:K,nextLocation:oe,historyAction:ve}))return We}function Jr(B){let K=lr(404,{pathname:B}),oe=u||l,{matches:ve,route:Oe}=pC(oe);return Rr(),{notFoundMatches:ve,route:Oe,error:K}}function _r(B,K){return{boundaryId:jl(K.partialMatches).route.id,error:lr(400,{type:"route-discovery",pathname:B,message:K.error!=null&&"message"in K.error?K.error:String(K.error)})}}function Rr(B){let K=[];return de.forEach((oe,ve)=>{(!B||B(ve))&&(oe.cancel(),K.push(ve),de.delete(ve))}),K}function Uo(B,K,oe){if(b=B,C=K,w=oe||null,!k&&N.navigation===pv){k=!0;let ve=yc(N.location,N.matches);ve!=null&&Fe({restoreScrollPosition:ve})}return()=>{b=null,C=null,w=null}}function vc(B,K){return w&&w(B,K.map(ve=>LF(ve,N.loaderData)))||B.key}function _d(B,K){if(b&&C){let oe=vc(B,K);b[oe]=C()}}function yc(B,K){if(b){let oe=vc(B,K),ve=b[oe];if(typeof ve=="number")return ve}return null}function Ba(B,K,oe){if(h)if(B){let ve=B[B.length-1].route;if(ve.path&&(ve.path==="*"||ve.path.endsWith("/*")))return{active:!0,matches:cp(K,oe,d,!0)}}else return{active:!0,matches:cp(K,oe,d,!0)||[]};return{active:!1,matches:null}}async function za(B,K,oe){let ve=B,Oe=ve.length>0?ve[ve.length-1].route:null;for(;;){let We=u==null,st=u||l;try{await p2(h,K,ve,st,o,s,Z,oe)}catch(Xe){return{type:"error",error:Xe,partialMatches:ve}}finally{We&&(l=[...l])}if(oe.aborted)return{type:"aborted"};let Me=oi(st,K,d),ht=!1;if(Me){let Xe=Me[Me.length-1].route;if(Xe.index)return{type:"success",matches:Me};if(Xe.path&&Xe.path.length>0)if(Xe.path==="*")ht=!0;else return{type:"success",matches:Me}}let Ge=cp(st,K,d,!0);if(!Ge||ve.map(Xe=>Xe.route.id).join("-")===Ge.map(Xe=>Xe.route.id).join("-"))return{type:"success",matches:ht?Me:null};if(ve=Ge,Oe=ve[ve.length-1].route,Oe.path==="*")return{type:"success",matches:ve}}}function Ua(B){o={},u=Au(B,s,void 0,o)}function bc(B,K){let oe=u==null;fj(B,K,u||l,o,s),oe&&(l=[...l],Fe({}))}return R={get basename(){return d},get future(){return m},get state(){return N},get routes(){return l},get window(){return t},initialize:Re,subscribe:Ye,enableScrollRestoration:Uo,navigate:ln,fetch:Ne,revalidate:Sn,createHref:B=>e.history.createHref(B),encodeLocation:B=>e.history.encodeLocation(B),getFetcher:gr,deleteFetcher:ro,dispose:$e,getBlocker:Tn,deleteBlocker:mr,patchRoutes:bc,_internalFetchControllers:Y,_internalActiveDeferreds:de,_internalSetRoutes:Ua},R}function u2(e){return e!=null&&("formData"in e&&e.formData!=null||"body"in e&&e.body!==void 0)}function Ny(e,t,n,r,s,o,l,u){let d,f;if(l){d=[];for(let m of t)if(d.push(m),m.route.id===l){f=m;break}}else d=t,f=t[t.length-1];let h=gh(s||".",hh(d,o),Xl(e.pathname,n)||e.pathname,u==="path");return s==null&&(h.search=e.search,h.hash=e.hash),(s==null||s===""||s===".")&&f&&f.route.index&&!Fb(h.search)&&(h.search=h.search?h.search.replace(/^\?/,"?index&"):"?index"),r&&n!=="/"&&(h.pathname=h.pathname==="/"?n:To([n,h.pathname])),wi(h)}function sC(e,t,n,r){if(!r||!u2(r))return{path:n};if(r.formMethod&&!E2(r.formMethod))return{path:n,error:lr(405,{method:r.formMethod})};let s=()=>({path:n,error:lr(400,{type:"invalid-body"})}),o=r.formMethod||"get",l=e?o.toUpperCase():o.toLowerCase(),u=pj(n);if(r.body!==void 0){if(r.formEncType==="text/plain"){if(!bs(l))return s();let g=typeof r.body=="string"?r.body:r.body instanceof FormData||r.body instanceof URLSearchParams?Array.from(r.body.entries()).reduce((x,b)=>{let[w,C]=b;return""+x+w+"="+C+` `},""):String(r.body);return{path:n,submission:{formMethod:l,formAction:u,formEncType:r.formEncType,formData:void 0,json:void 0,text:g}}}else if(r.formEncType==="application/json"){if(!bs(l))return s();try{let g=typeof r.body=="string"?JSON.parse(r.body):r.body;return{path:n,submission:{formMethod:l,formAction:u,formEncType:r.formEncType,formData:void 0,json:g,text:void 0}}}catch{return s()}}}Ct(typeof FormData=="function","FormData is not available in this environment");let d,f;if(r.formData)d=My(r.formData),f=r.formData;else if(r.body instanceof FormData)d=My(r.body),f=r.body;else if(r.body instanceof URLSearchParams)d=r.body,f=cC(d);else if(r.body==null)d=new URLSearchParams,f=new FormData;else try{d=new URLSearchParams(r.body),f=cC(d)}catch{return s()}let h={formMethod:l,formAction:u,formEncType:r&&r.formEncType||"application/x-www-form-urlencoded",formData:f,json:void 0,text:void 0};if(bs(h.formMethod))return{path:n,submission:h};let m=_a(n);return t&&m.search&&Fb(m.search)&&d.append("index",""),m.search="?"+d,{path:wi(m),submission:h}}function d2(e,t){let n=e;if(t){let r=e.findIndex(s=>s.route.id===t);r>=0&&(n=e.slice(0,r))}return n}function oC(e,t,n,r,s,o,l,u,d,f,h,m,g,x,b,w){let C=w?Br(w[1])?w[1].error:w[1].data:void 0,k=e.createURL(t.location),j=e.createURL(s),M=w&&Br(w[1])?w[0]:void 0,_=M?d2(n,M):n,R=w?w[1].statusCode:void 0,N=l&&R&&R>=400,O=_.filter((z,Q)=>{let{route:pe}=z;if(pe.lazy)return!0;if(pe.loader==null)return!1;if(o)return typeof pe.loader!="function"||pe.loader.hydrate?!0:t.loaderData[pe.id]===void 0&&(!t.errors||t.errors[pe.id]===void 0);if(f2(t.loaderData,t.matches[Q],z)||d.some(W=>W===z.route.id))return!0;let V=t.matches[Q],G=z;return aC(z,mn({currentUrl:k,currentParams:V.params,nextUrl:j,nextParams:G.params},r,{actionResult:C,actionStatus:R,defaultShouldRevalidate:N?!1:u||k.pathname+k.search===j.pathname+j.search||k.search!==j.search||dj(V,G)}))}),D=[];return m.forEach((z,Q)=>{if(o||!n.some(ie=>ie.route.id===z.routeId)||h.has(Q))return;let pe=oi(x,z.path,b);if(!pe){D.push({key:Q,routeId:z.routeId,path:z.path,matches:null,match:null,controller:null});return}let V=t.fetchers.get(Q),G=gu(pe,z.path),W=!1;g.has(Q)?W=!1:f.includes(Q)?W=!0:V&&V.state!=="idle"&&V.data===void 0?W=u:W=aC(G,mn({currentUrl:k,currentParams:t.matches[t.matches.length-1].params,nextUrl:j,nextParams:n[n.length-1].params},r,{actionResult:C,actionStatus:R,defaultShouldRevalidate:N?!1:u})),W&&D.push({key:Q,routeId:z.routeId,path:z.path,matches:pe,match:G,controller:new AbortController})}),[O,D]}function f2(e,t,n){let r=!t||n.route.id!==t.route.id,s=e[n.route.id]===void 0;return r||s}function dj(e,t){let n=e.route.path;return e.pathname!==t.pathname||n!=null&&n.endsWith("*")&&e.params["*"]!==t.params["*"]}function aC(e,t){if(e.route.shouldRevalidate){let n=e.route.shouldRevalidate(t);if(typeof n=="boolean")return n}return t.defaultShouldRevalidate}async function p2(e,t,n,r,s,o,l,u){let d=[t,...n.map(f=>f.route.id)].join("-");try{let f=l.get(d);f||(f=e({path:t,matches:n,patch:(h,m)=>{u.aborted||fj(h,m,r,s,o)}}),l.set(d,f)),f&&w2(f)&&await f}finally{l.delete(d)}}function fj(e,t,n,r,s){if(e){var o;let l=r[e];Ct(l,"No route found to patch children into: routeId = "+e);let u=Au(t,s,[e,"patch",String(((o=l.children)==null?void 0:o.length)||"0")],r);l.children?l.children.push(...u):l.children=u}else{let l=Au(t,s,["patch",String(n.length||"0")],r);n.push(...l)}}async function iC(e,t,n){if(!e.lazy)return;let r=await e.lazy();if(!e.lazy)return;let s=n[e.id];Ct(s,"No route found in manifest");let o={};for(let l in r){let d=s[l]!==void 0&&l!=="hasErrorBoundary";Ll(!d,'Route "'+s.id+'" has a static property "'+l+'" defined but its lazy function is also returning a value for this property. '+('The lazy route property "'+l+'" will be ignored.')),!d&&!DF.has(l)&&(o[l]=r[l])}Object.assign(s,o),Object.assign(s,mn({},t(s),{lazy:void 0}))}function h2(e){return Promise.all(e.matches.map(t=>t.resolve()))}async function g2(e,t,n,r,s,o,l,u){let d=r.reduce((m,g)=>m.add(g.route.id),new Set),f=new Set,h=await e({matches:s.map(m=>{let g=d.has(m.route.id);return mn({},m,{shouldLoad:g,resolve:b=>(f.add(m.route.id),g?m2(t,n,m,o,l,b,u):Promise.resolve({type:Zt.data,result:void 0}))})}),request:n,params:s[0].params,context:u});return s.forEach(m=>Ct(f.has(m.route.id),'`match.resolve()` was not called for route id "'+m.route.id+'". You must call `match.resolve()` on every match passed to `dataStrategy` to ensure all routes are properly loaded.')),h.filter((m,g)=>d.has(s[g].route.id))}async function m2(e,t,n,r,s,o,l){let u,d,f=h=>{let m,g=new Promise((w,C)=>m=C);d=()=>m(),t.signal.addEventListener("abort",d);let x=w=>typeof h!="function"?Promise.reject(new Error("You cannot call the handler for a route which defines a boolean "+('"'+e+'" [routeId: '+n.route.id+"]"))):h({request:t,params:n.params,context:l},...w!==void 0?[w]:[]),b;return o?b=o(w=>x(w)):b=(async()=>{try{return{type:"data",result:await x()}}catch(w){return{type:"error",result:w}}})(),Promise.race([b,g])};try{let h=n.route[e];if(n.route.lazy)if(h){let m,[g]=await Promise.all([f(h).catch(x=>{m=x}),iC(n.route,s,r)]);if(m!==void 0)throw m;u=g}else if(await iC(n.route,s,r),h=n.route[e],h)u=await f(h);else if(e==="action"){let m=new URL(t.url),g=m.pathname+m.search;throw lr(405,{method:t.method,pathname:g,routeId:n.route.id})}else return{type:Zt.data,result:void 0};else if(h)u=await f(h);else{let m=new URL(t.url),g=m.pathname+m.search;throw lr(404,{pathname:g})}Ct(u.result!==void 0,"You defined "+(e==="action"?"an action":"a loader")+" for route "+('"'+n.route.id+"\" but didn't return anything from your `"+e+"` ")+"function. Please return a value or `null`.")}catch(h){return{type:Zt.error,result:h}}finally{d&&t.signal.removeEventListener("abort",d)}return u}async function v2(e){let{result:t,type:n,status:r}=e;if(hj(t)){let l;try{let u=t.headers.get("Content-Type");u&&/\bapplication\/json\b/.test(u)?t.body==null?l=null:l=await t.json():l=await t.text()}catch(u){return{type:Zt.error,error:u}}return n===Zt.error?{type:Zt.error,error:new Ab(t.status,t.statusText,l),statusCode:t.status,headers:t.headers}:{type:Zt.data,data:l,statusCode:t.status,headers:t.headers}}if(n===Zt.error)return{type:Zt.error,error:t,statusCode:mh(t)?t.status:r};if(C2(t)){var s,o;return{type:Zt.deferred,deferredData:t,statusCode:(s=t.init)==null?void 0:s.status,headers:((o=t.init)==null?void 0:o.headers)&&new Headers(t.init.headers)}}return{type:Zt.data,data:t,statusCode:r}}function y2(e,t,n,r,s,o){let l=e.headers.get("Location");if(Ct(l,"Redirects returned/thrown from loaders/actions must have a Location header"),!Db.test(l)){let u=r.slice(0,r.findIndex(d=>d.route.id===n)+1);l=Ny(new URL(t.url),u,s,!0,l,o),e.headers.set("Location",l)}return e}function lC(e,t,n){if(Db.test(e)){let r=e,s=r.startsWith("//")?new URL(t.protocol+r):new URL(r),o=Xl(s.pathname,n)!=null;if(s.origin===t.origin&&o)return s.pathname+s.search+s.hash}return e}function fl(e,t,n,r){let s=e.createURL(pj(t)).toString(),o={signal:n};if(r&&bs(r.formMethod)){let{formMethod:l,formEncType:u}=r;o.method=l.toUpperCase(),u==="application/json"?(o.headers=new Headers({"Content-Type":u}),o.body=JSON.stringify(r.json)):u==="text/plain"?o.body=r.text:u==="application/x-www-form-urlencoded"&&r.formData?o.body=My(r.formData):o.body=r.formData}return new Request(s,o)}function My(e){let t=new URLSearchParams;for(let[n,r]of e.entries())t.append(n,typeof r=="string"?r:r.name);return t}function cC(e){let t=new FormData;for(let[n,r]of e.entries())t.append(n,r);return t}function b2(e,t,n,r,s,o){let l={},u=null,d,f=!1,h={},m=r&&Br(r[1])?r[1].error:void 0;return n.forEach((g,x)=>{let b=t[x].route.id;if(Ct(!ii(g),"Cannot handle redirect results in processLoaderData"),Br(g)){let w=g.error;m!==void 0&&(w=m,m=void 0),u=u||{};{let C=jl(e,b);u[C.route.id]==null&&(u[C.route.id]=w)}l[b]=void 0,f||(f=!0,d=mh(g.error)?g.error.status:500),g.headers&&(h[b]=g.headers)}else ai(g)?(s.set(b,g.deferredData),l[b]=g.deferredData.data,g.statusCode!=null&&g.statusCode!==200&&!f&&(d=g.statusCode),g.headers&&(h[b]=g.headers)):(l[b]=g.data,g.statusCode&&g.statusCode!==200&&!f&&(d=g.statusCode),g.headers&&(h[b]=g.headers))}),m!==void 0&&r&&(u={[r[0]]:m},l[r[0]]=void 0),{loaderData:l,errors:u,statusCode:d||200,loaderHeaders:h}}function uC(e,t,n,r,s,o,l,u){let{loaderData:d,errors:f}=b2(t,n,r,s,u);for(let h=0;hr.route.id===t)+1):[...e]).reverse().find(r=>r.route.hasErrorBoundary===!0)||e[0]}function pC(e){let t=e.length===1?e[0]:e.find(n=>n.index||!n.path||n.path==="/")||{id:"__shim-error-route__"};return{matches:[{params:{},pathname:"",pathnameBase:"",route:t}],route:t}}function lr(e,t){let{pathname:n,routeId:r,method:s,type:o,message:l}=t===void 0?{}:t,u="Unknown Server Error",d="Unknown @remix-run/router error";return e===400?(u="Bad Request",o==="route-discovery"?d='Unable to match URL "'+n+'" - the `unstable_patchRoutesOnMiss()` '+(`function threw the following error: `+l):s&&n&&r?d="You made a "+s+' request to "'+n+'" but '+('did not provide a `loader` for route "'+r+'", ')+"so there is no way to handle the request.":o==="defer-action"?d="defer() is not supported in actions":o==="invalid-body"&&(d="Unable to encode submission body")):e===403?(u="Forbidden",d='Route "'+r+'" does not match URL "'+n+'"'):e===404?(u="Not Found",d='No route matches URL "'+n+'"'):e===405&&(u="Method Not Allowed",s&&n&&r?d="You made a "+s.toUpperCase()+' request to "'+n+'" but '+('did not provide an `action` for route "'+r+'", ')+"so there is no way to handle the request.":s&&(d='Invalid request method "'+s.toUpperCase()+'"')),new Ab(e||500,u,new Error(d),!0)}function hC(e){for(let t=e.length-1;t>=0;t--){let n=e[t];if(ii(n))return{result:n,idx:t}}}function pj(e){let t=typeof e=="string"?_a(e):e;return wi(mn({},t,{hash:""}))}function x2(e,t){return e.pathname!==t.pathname||e.search!==t.search?!1:e.hash===""?t.hash!=="":e.hash===t.hash?!0:t.hash!==""}function w2(e){return typeof e=="object"&&e!=null&&"then"in e}function S2(e){return hj(e.result)&&o2.has(e.result.status)}function ai(e){return e.type===Zt.deferred}function Br(e){return e.type===Zt.error}function ii(e){return(e&&e.type)===Zt.redirect}function C2(e){let t=e;return t&&typeof t=="object"&&typeof t.data=="object"&&typeof t.subscribe=="function"&&typeof t.cancel=="function"&&typeof t.resolveData=="function"}function hj(e){return e!=null&&typeof e.status=="number"&&typeof e.statusText=="string"&&typeof e.headers=="object"&&typeof e.body<"u"}function E2(e){return s2.has(e.toLowerCase())}function bs(e){return n2.has(e.toLowerCase())}async function gC(e,t,n,r,s,o){for(let l=0;lm.route.id===d.route.id),h=f!=null&&!dj(f,d)&&(o&&o[d.route.id])!==void 0;if(ai(u)&&(s||h)){let m=r[l];Ct(m,"Expected an AbortSignal for revalidating fetcher deferred result"),await gj(u,m,s).then(g=>{g&&(n[l]=g||n[l])})}}}async function gj(e,t,n){if(n===void 0&&(n=!1),!await e.deferredData.resolveData(t)){if(n)try{return{type:Zt.data,data:e.deferredData.unwrappedData}}catch(s){return{type:Zt.error,error:s}}return{type:Zt.data,data:e.deferredData.data}}}function Fb(e){return new URLSearchParams(e).getAll("index").some(t=>t==="")}function gu(e,t){let n=typeof t=="string"?_a(t).search:t.search;if(e[e.length-1].route.index&&Fb(n||""))return e[e.length-1];let r=lj(e);return r[r.length-1]}function mC(e){let{formMethod:t,formAction:n,formEncType:r,text:s,formData:o,json:l}=e;if(!(!t||!n||!r)){if(s!=null)return{formMethod:t,formAction:n,formEncType:r,formData:void 0,json:void 0,text:s};if(o!=null)return{formMethod:t,formAction:n,formEncType:r,formData:o,json:void 0,text:void 0};if(l!==void 0)return{formMethod:t,formAction:n,formEncType:r,formData:void 0,json:l,text:void 0}}}function hv(e,t){return t?{state:"loading",location:e,formMethod:t.formMethod,formAction:t.formAction,formEncType:t.formEncType,formData:t.formData,json:t.json,text:t.text}:{state:"loading",location:e,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0,json:void 0,text:void 0}}function k2(e,t){return{state:"submitting",location:e,formMethod:t.formMethod,formAction:t.formAction,formEncType:t.formEncType,formData:t.formData,json:t.json,text:t.text}}function tu(e,t){return e?{state:"loading",formMethod:e.formMethod,formAction:e.formAction,formEncType:e.formEncType,formData:e.formData,json:e.json,text:e.text,data:t}:{state:"loading",formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0,json:void 0,text:void 0,data:t}}function j2(e,t){return{state:"submitting",formMethod:e.formMethod,formAction:e.formAction,formEncType:e.formEncType,formData:e.formData,json:e.json,text:e.text,data:t?t.data:void 0}}function da(e){return{state:"idle",formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0,json:void 0,text:void 0,data:e}}function T2(e,t){try{let n=e.sessionStorage.getItem(uj);if(n){let r=JSON.parse(n);for(let[s,o]of Object.entries(r||{}))o&&Array.isArray(o)&&t.set(s,new Set(o||[]))}}catch{}}function N2(e,t){if(t.size>0){let n={};for(let[r,s]of t)n[r]=[...s];try{e.sessionStorage.setItem(uj,JSON.stringify(n))}catch(r){Ll(!1,"Failed to save applied view transitions in sessionStorage ("+r+").")}}}/** * React Router v6.25.1 * * Copyright (c) Remix Software Inc. * * This source code is licensed under the MIT license found in the * LICENSE.md file in the root directory of this source tree. * * @license MIT */function Rp(){return Rp=Object.assign?Object.assign.bind():function(e){for(var t=1;t{u.current=!0}),y.useCallback(function(f,h){if(h===void 0&&(h={}),!u.current)return;if(typeof f=="number"){r.go(f);return}let m=gh(f,JSON.parse(l),o,h.relative==="path");e==null&&t!=="/"&&(m.pathname=m.pathname==="/"?t:To([t,m.pathname])),(h.replace?r.replace:r.push)(m,h.state,h)},[t,r,l,o,e])}function ls(){let{matches:e}=y.useContext(Po),t=e[e.length-1];return t?t.params:{}}function bj(e,t){let{relative:n}=t===void 0?{}:t,{future:r}=y.useContext(Ra),{matches:s}=y.useContext(Po),{pathname:o}=Pi(),l=JSON.stringify(hh(s,r.v7_relativeSplatPath));return y.useMemo(()=>gh(e,JSON.parse(l),o,n==="path"),[e,l,o,n])}function R2(e,t,n,r){ec()||Ct(!1);let{navigator:s}=y.useContext(Ra),{matches:o}=y.useContext(Po),l=o[o.length-1],u=l?l.params:{};l&&l.pathname;let d=l?l.pathnameBase:"/";l&&l.route;let f=Pi(),h;h=f;let m=h.pathname||"/",g=m;if(d!=="/"){let w=d.replace(/^\//,"").split("/");g="/"+m.replace(/^\//,"").split("/").slice(w.length).join("/")}let x=oi(e,{pathname:g});return D2(x&&x.map(w=>Object.assign({},w,{params:Object.assign({},u,w.params),pathname:To([d,s.encodeLocation?s.encodeLocation(w.pathname).pathname:w.pathname]),pathnameBase:w.pathnameBase==="/"?d:To([d,s.encodeLocation?s.encodeLocation(w.pathnameBase).pathname:w.pathnameBase])})),o,n,r)}function P2(){let e=B2(),t=mh(e)?e.status+" "+e.statusText:e instanceof Error?e.message:JSON.stringify(e),n=e instanceof Error?e.stack:null,s={padding:"0.5rem",backgroundColor:"rgba(200,200,200, 0.5)"};return y.createElement(y.Fragment,null,y.createElement("h2",null,"Unexpected Application Error!"),y.createElement("h3",{style:{fontStyle:"italic"}},t),n?y.createElement("pre",{style:s},n):null,null)}const O2=y.createElement(P2,null);class I2 extends y.Component{constructor(t){super(t),this.state={location:t.location,revalidation:t.revalidation,error:t.error}}static getDerivedStateFromError(t){return{error:t}}static getDerivedStateFromProps(t,n){return n.location!==t.location||n.revalidation!=="idle"&&t.revalidation==="idle"?{error:t.error,location:t.location,revalidation:t.revalidation}:{error:t.error!==void 0?t.error:n.error,location:n.location,revalidation:t.revalidation||n.revalidation}}componentDidCatch(t,n){console.error("React Router caught the following error during render",t,n)}render(){return this.state.error!==void 0?y.createElement(Po.Provider,{value:this.props.routeContext},y.createElement(vj.Provider,{value:this.state.error,children:this.props.component})):this.props.children}}function A2(e){let{routeContext:t,match:n,children:r}=e,s=y.useContext(vh);return s&&s.static&&s.staticContext&&(n.route.errorElement||n.route.ErrorBoundary)&&(s.staticContext._deepestRenderedBoundaryId=n.route.id),y.createElement(Po.Provider,{value:t},r)}function D2(e,t,n,r){var s;if(t===void 0&&(t=[]),n===void 0&&(n=null),r===void 0&&(r=null),e==null){var o;if((o=n)!=null&&o.errors)e=n.matches;else return null}let l=e,u=(s=n)==null?void 0:s.errors;if(u!=null){let h=l.findIndex(m=>m.route.id&&u?.[m.route.id]!==void 0);h>=0||Ct(!1),l=l.slice(0,Math.min(l.length,h+1))}let d=!1,f=-1;if(n&&r&&r.v7_partialHydration)for(let h=0;h=0?l=l.slice(0,f+1):l=[l[0]];break}}}return l.reduceRight((h,m,g)=>{let x,b=!1,w=null,C=null;n&&(x=u&&m.route.id?u[m.route.id]:void 0,w=m.route.errorElement||O2,d&&(f<0&&g===0?(U2("route-fallback"),b=!0,C=null):f===g&&(b=!0,C=m.route.hydrateFallbackElement||null)));let k=t.concat(l.slice(0,g+1)),j=()=>{let M;return x?M=w:b?M=C:m.route.Component?M=y.createElement(m.route.Component,null):m.route.element?M=m.route.element:M=h,y.createElement(A2,{match:m,routeContext:{outlet:h,matches:k,isDataRoute:n!=null},children:M})};return n&&(m.route.ErrorBoundary||m.route.errorElement||g===0)?y.createElement(I2,{location:n.location,revalidation:n.revalidation,component:w,error:x,children:j(),routeContext:{outlet:null,matches:k,isDataRoute:!0}}):j()},null)}var xj=(function(e){return e.UseBlocker="useBlocker",e.UseRevalidator="useRevalidator",e.UseNavigateStable="useNavigate",e})(xj||{}),wj=(function(e){return e.UseBlocker="useBlocker",e.UseLoaderData="useLoaderData",e.UseActionData="useActionData",e.UseRouteError="useRouteError",e.UseNavigation="useNavigation",e.UseRouteLoaderData="useRouteLoaderData",e.UseMatches="useMatches",e.UseRevalidator="useRevalidator",e.UseNavigateStable="useNavigate",e.UseRouteId="useRouteId",e})(wj||{});function F2(e){let t=y.useContext(vh);return t||Ct(!1),t}function L2(e){let t=y.useContext(mj);return t||Ct(!1),t}function $2(e){let t=y.useContext(Po);return t||Ct(!1),t}function Sj(e){let t=$2(),n=t.matches[t.matches.length-1];return n.route.id||Ct(!1),n.route.id}function B2(){var e;let t=y.useContext(vj),n=L2(wj.UseRouteError),r=Sj();return t!==void 0?t:(e=n.errors)==null?void 0:e[r]}function z2(){let{router:e}=F2(xj.UseNavigateStable),t=Sj(),n=y.useRef(!1);return yj(()=>{n.current=!0}),y.useCallback(function(s,o){o===void 0&&(o={}),n.current&&(typeof s=="number"?e.navigate(s):e.navigate(s,Rp({fromRouteId:t},o)))},[e,t])}const vC={};function U2(e,t,n){vC[e]||(vC[e]=!0)}function Cj(e){let{to:t,replace:n,state:r,relative:s}=e;ec()||Ct(!1);let{future:o,static:l}=y.useContext(Ra),{matches:u}=y.useContext(Po),{pathname:d}=Pi(),f=dn(),h=gh(t,hh(u,o.v7_relativeSplatPath),d,s==="path"),m=JSON.stringify(h);return y.useEffect(()=>f(JSON.parse(m),{replace:n,state:r,relative:s}),[f,m,s,n,r]),null}function V2(e){let{basename:t="/",children:n=null,location:r,navigationType:s=_n.Pop,navigator:o,static:l=!1,future:u}=e;ec()&&Ct(!1);let d=t.replace(/^\/*/,"/"),f=y.useMemo(()=>({basename:d,navigator:o,static:l,future:Rp({v7_relativeSplatPath:!1},u)}),[d,u,o,l]);typeof r=="string"&&(r=_a(r));let{pathname:h="/",search:m="",hash:g="",state:x=null,key:b="default"}=r,w=y.useMemo(()=>{let C=Xl(h,d);return C==null?null:{location:{pathname:C,search:m,hash:g,state:x,key:b},navigationType:s}},[d,h,m,g,x,b,s]);return w==null?null:y.createElement(Ra.Provider,{value:f},y.createElement(Lb.Provider,{children:n,value:w}))}new Promise(()=>{});function H2(e){let t={hasErrorBoundary:e.ErrorBoundary!=null||e.errorElement!=null};return e.Component&&Object.assign(t,{element:y.createElement(e.Component),Component:void 0}),e.HydrateFallback&&Object.assign(t,{hydrateFallbackElement:y.createElement(e.HydrateFallback),HydrateFallback:void 0}),e.ErrorBoundary&&Object.assign(t,{errorElement:y.createElement(e.ErrorBoundary),ErrorBoundary:void 0}),t}/** * React Router DOM v6.25.1 * * Copyright (c) Remix Software Inc. * * This source code is licensed under the MIT license found in the * LICENSE.md file in the root directory of this source tree. * * @license MIT */function Du(){return Du=Object.assign?Object.assign.bind():function(e){for(var t=1;t=0)&&(n[s]=e[s]);return n}function K2(e){return!!(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)}function W2(e,t){return e.button===0&&(!t||t==="_self")&&!K2(e)}function _y(e){return e===void 0&&(e=""),new URLSearchParams(typeof e=="string"||Array.isArray(e)||e instanceof URLSearchParams?e:Object.keys(e).reduce((t,n)=>{let r=e[n];return t.concat(Array.isArray(r)?r.map(s=>[n,s]):[[n,r]])},[]))}function G2(e,t){let n=_y(e);return t&&t.forEach((r,s)=>{n.has(s)||t.getAll(s).forEach(o=>{n.append(s,o)})}),n}const J2=["onClick","relative","reloadDocument","replace","state","target","to","preventScrollReset","unstable_viewTransition"],Q2="6";try{window.__reactRouterVersion=Q2}catch{}function Z2(e,t){return c2({basename:void 0,future:Du({},void 0,{v7_prependBasename:!0}),history:OF({window:void 0}),hydrationData:Y2(),routes:e,mapRouteProperties:H2,unstable_dataStrategy:void 0,unstable_patchRoutesOnMiss:void 0,window:void 0}).initialize()}function Y2(){var e;let t=(e=window)==null?void 0:e.__staticRouterHydrationData;return t&&t.errors&&(t=Du({},t,{errors:X2(t.errors)})),t}function X2(e){if(!e)return null;let t=Object.entries(e),n={};for(let[r,s]of t)if(s&&s.__type==="RouteErrorResponse")n[r]=new Ab(s.status,s.statusText,s.data,s.internal===!0);else if(s&&s.__type==="Error"){if(s.__subType){let o=window[s.__subType];if(typeof o=="function")try{let l=new o(s.message);l.stack="",n[r]=l}catch{}}if(n[r]==null){let o=new Error(s.message);o.stack="",n[r]=o}}else n[r]=s;return n}const eL=y.createContext({isTransitioning:!1}),tL=y.createContext(new Map),nL="startTransition",yC=Yl[nL],rL="flushSync",bC=PF[rL];function sL(e){yC?yC(e):e()}function nu(e){bC?bC(e):e()}class oL{constructor(){this.status="pending",this.promise=new Promise((t,n)=>{this.resolve=r=>{this.status==="pending"&&(this.status="resolved",t(r))},this.reject=r=>{this.status==="pending"&&(this.status="rejected",n(r))}})}}function aL(e){let{fallbackElement:t,router:n,future:r}=e,[s,o]=y.useState(n.state),[l,u]=y.useState(),[d,f]=y.useState({isTransitioning:!1}),[h,m]=y.useState(),[g,x]=y.useState(),[b,w]=y.useState(),C=y.useRef(new Map),{v7_startTransition:k}=r||{},j=y.useCallback(D=>{k?sL(D):D()},[k]),M=y.useCallback((D,z)=>{let{deletedFetchers:Q,unstable_flushSync:pe,unstable_viewTransitionOpts:V}=z;Q.forEach(W=>C.current.delete(W)),D.fetchers.forEach((W,ie)=>{W.data!==void 0&&C.current.set(ie,W.data)});let G=n.window==null||n.window.document==null||typeof n.window.document.startViewTransition!="function";if(!V||G){pe?nu(()=>o(D)):j(()=>o(D));return}if(pe){nu(()=>{g&&(h&&h.resolve(),g.skipTransition()),f({isTransitioning:!0,flushSync:!0,currentLocation:V.currentLocation,nextLocation:V.nextLocation})});let W=n.window.document.startViewTransition(()=>{nu(()=>o(D))});W.finished.finally(()=>{nu(()=>{m(void 0),x(void 0),u(void 0),f({isTransitioning:!1})})}),nu(()=>x(W));return}g?(h&&h.resolve(),g.skipTransition(),w({state:D,currentLocation:V.currentLocation,nextLocation:V.nextLocation})):(u(D),f({isTransitioning:!0,flushSync:!1,currentLocation:V.currentLocation,nextLocation:V.nextLocation}))},[n.window,g,h,C,j]);y.useLayoutEffect(()=>n.subscribe(M),[n,M]),y.useEffect(()=>{d.isTransitioning&&!d.flushSync&&m(new oL)},[d]),y.useEffect(()=>{if(h&&l&&n.window){let D=l,z=h.promise,Q=n.window.document.startViewTransition(async()=>{j(()=>o(D)),await z});Q.finished.finally(()=>{m(void 0),x(void 0),u(void 0),f({isTransitioning:!1})}),x(Q)}},[j,l,h,n.window]),y.useEffect(()=>{h&&l&&s.location.key===l.location.key&&h.resolve()},[h,g,s.location,l]),y.useEffect(()=>{!d.isTransitioning&&b&&(u(b.state),f({isTransitioning:!0,flushSync:!1,currentLocation:b.currentLocation,nextLocation:b.nextLocation}),w(void 0))},[d.isTransitioning,b]),y.useEffect(()=>{},[]);let _=y.useMemo(()=>({createHref:n.createHref,encodeLocation:n.encodeLocation,go:D=>n.navigate(D),push:(D,z,Q)=>n.navigate(D,{state:z,preventScrollReset:Q?.preventScrollReset}),replace:(D,z,Q)=>n.navigate(D,{replace:!0,state:z,preventScrollReset:Q?.preventScrollReset})}),[n]),R=n.basename||"/",N=y.useMemo(()=>({router:n,navigator:_,static:!1,basename:R}),[n,_,R]),O=y.useMemo(()=>({v7_relativeSplatPath:n.future.v7_relativeSplatPath}),[n.future.v7_relativeSplatPath]);return y.createElement(y.Fragment,null,y.createElement(vh.Provider,{value:N},y.createElement(mj.Provider,{value:s},y.createElement(tL.Provider,{value:C.current},y.createElement(eL.Provider,{value:d},y.createElement(V2,{basename:R,location:s.location,navigationType:s.historyAction,navigator:_,future:O},s.initialized||n.future.v7_partialHydration?y.createElement(iL,{routes:n.routes,future:n.future,state:s}):t))))),null)}const iL=y.memo(lL);function lL(e){let{routes:t,future:n,state:r}=e;return R2(t,void 0,r,n)}const cL=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",uL=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,Fu=y.forwardRef(function(t,n){let{onClick:r,relative:s,reloadDocument:o,replace:l,state:u,target:d,to:f,preventScrollReset:h,unstable_viewTransition:m}=t,g=q2(t,J2),{basename:x}=y.useContext(Ra),b,w=!1;if(typeof f=="string"&&uL.test(f)&&(b=f,cL))try{let M=new URL(window.location.href),_=f.startsWith("//")?new URL(M.protocol+f):new URL(f),R=Xl(_.pathname,x);_.origin===M.origin&&R!=null?f=R+_.search+_.hash:w=!0}catch{}let C=M2(f,{relative:s}),k=dL(f,{replace:l,state:u,target:d,preventScrollReset:h,relative:s,unstable_viewTransition:m});function j(M){r&&r(M),M.defaultPrevented||k(M)}return y.createElement("a",Du({},g,{href:b||C,onClick:w||o?r:j,ref:n,target:d}))});var xC;(function(e){e.UseScrollRestoration="useScrollRestoration",e.UseSubmit="useSubmit",e.UseSubmitFetcher="useSubmitFetcher",e.UseFetcher="useFetcher",e.useViewTransitionState="useViewTransitionState"})(xC||(xC={}));var wC;(function(e){e.UseFetcher="useFetcher",e.UseFetchers="useFetchers",e.UseScrollRestoration="useScrollRestoration"})(wC||(wC={}));function dL(e,t){let{target:n,replace:r,state:s,preventScrollReset:o,relative:l,unstable_viewTransition:u}=t===void 0?{}:t,d=dn(),f=Pi(),h=bj(e,{relative:l});return y.useCallback(m=>{if(W2(m,n)){m.preventDefault();let g=r!==void 0?r:wi(f)===wi(h);d(e,{replace:g,state:s,preventScrollReset:o,relative:l,unstable_viewTransition:u})}},[f,d,h,r,s,n,e,o,l,u])}function hd(e){let t=y.useRef(_y(e)),n=y.useRef(!1),r=Pi(),s=y.useMemo(()=>G2(r.search,n.current?null:t.current),[r.search]),o=dn(),l=y.useCallback((u,d)=>{const f=_y(typeof u=="function"?u(s):u);n.current=!0,o("?"+f,d)},[o,s]);return[s,l]}function Ej(e){var t,n,r="";if(typeof e=="string"||typeof e=="number")r+=e;else if(typeof e=="object")if(Array.isArray(e)){var s=e.length;for(t=0;ttypeof e=="number"&&!isNaN(e),pi=e=>typeof e=="string",Ur=e=>typeof e=="function",up=e=>pi(e)||Ur(e)?e:null,Ry=e=>y.isValidElement(e)||pi(e)||Ur(e)||Lu(e);function fL(e,t,n){n===void 0&&(n=300);const{scrollHeight:r,style:s}=e;requestAnimationFrame(()=>{s.minHeight="initial",s.height=r+"px",s.transition=`all ${n}ms`,requestAnimationFrame(()=>{s.height="0",s.padding="0",s.margin="0",setTimeout(t,n)})})}function yh(e){let{enter:t,exit:n,appendPosition:r=!1,collapse:s=!0,collapseDuration:o=300}=e;return function(l){let{children:u,position:d,preventExitTransition:f,done:h,nodeRef:m,isIn:g,playToast:x}=l;const b=r?`${t}--${d}`:t,w=r?`${n}--${d}`:n,C=y.useRef(0);return y.useLayoutEffect(()=>{const k=m.current,j=b.split(" "),M=_=>{_.target===m.current&&(x(),k.removeEventListener("animationend",M),k.removeEventListener("animationcancel",M),C.current===0&&_.type!=="animationcancel"&&k.classList.remove(...j))};k.classList.add(...j),k.addEventListener("animationend",M),k.addEventListener("animationcancel",M)},[]),y.useEffect(()=>{const k=m.current,j=()=>{k.removeEventListener("animationend",j),s?fL(k,h,o):h()};g||(f?j():(C.current=1,k.className+=` ${w}`,k.addEventListener("animationend",j)))},[g]),qe.createElement(qe.Fragment,null,u)}}function SC(e,t){return e!=null?{content:e.content,containerId:e.props.containerId,id:e.props.toastId,theme:e.props.theme,type:e.props.type,data:e.props.data||{},isLoading:e.props.isLoading,icon:e.props.icon,status:t}:{}}const ur=new Map;let $u=[];const Py=new Set,pL=e=>Py.forEach(t=>t(e)),kj=()=>ur.size>0;function jj(e,t){var n;if(t)return!((n=ur.get(t))==null||!n.isToastActive(e));let r=!1;return ur.forEach(s=>{s.isToastActive(e)&&(r=!0)}),r}function Tj(e,t){Ry(e)&&(kj()||$u.push({content:e,options:t}),ur.forEach(n=>{n.buildToast(e,t)}))}function CC(e,t){ur.forEach(n=>{t!=null&&t!=null&&t.containerId?t?.containerId===n.id&&n.toggle(e,t?.id):n.toggle(e,t?.id)})}function hL(e){const{subscribe:t,getSnapshot:n,setProps:r}=y.useRef((function(o){const l=o.containerId||1;return{subscribe(u){const d=(function(h,m,g){let x=1,b=0,w=[],C=[],k=[],j=m;const M=new Map,_=new Set,R=()=>{k=Array.from(M.values()),_.forEach(D=>D())},N=D=>{C=D==null?[]:C.filter(z=>z!==D),R()},O=D=>{const{toastId:z,onOpen:Q,updateId:pe,children:V}=D.props,G=pe==null;D.staleId&&M.delete(D.staleId),M.set(z,D),C=[...C,D.props.toastId].filter(W=>W!==D.staleId),R(),g(SC(D,G?"added":"updated")),G&&Ur(Q)&&Q(y.isValidElement(V)&&V.props)};return{id:h,props:j,observe:D=>(_.add(D),()=>_.delete(D)),toggle:(D,z)=>{M.forEach(Q=>{z!=null&&z!==Q.props.toastId||Ur(Q.toggle)&&Q.toggle(D)})},removeToast:N,toasts:M,clearQueue:()=>{b-=w.length,w=[]},buildToast:(D,z)=>{if((F=>{let{containerId:fe,toastId:te,updateId:de}=F;const ge=fe?fe!==h:h!==1,Z=M.has(te)&&de==null;return ge||Z})(z))return;const{toastId:Q,updateId:pe,data:V,staleId:G,delay:W}=z,ie=()=>{N(Q)},re=pe==null;re&&b++;const Y={...j,style:j.toastStyle,key:x++,...Object.fromEntries(Object.entries(z).filter(F=>{let[fe,te]=F;return te!=null})),toastId:Q,updateId:pe,data:V,closeToast:ie,isIn:!1,className:up(z.className||j.toastClassName),bodyClassName:up(z.bodyClassName||j.bodyClassName),progressClassName:up(z.progressClassName||j.progressClassName),autoClose:!z.isLoading&&(H=z.autoClose,q=j.autoClose,H===!1||Lu(H)&&H>0?H:q),deleteToast(){const F=M.get(Q),{onClose:fe,children:te}=F.props;Ur(fe)&&fe(y.isValidElement(te)&&te.props),g(SC(F,"removed")),M.delete(Q),b--,b<0&&(b=0),w.length>0?O(w.shift()):R()}};var H,q;Y.closeButton=j.closeButton,z.closeButton===!1||Ry(z.closeButton)?Y.closeButton=z.closeButton:z.closeButton===!0&&(Y.closeButton=!Ry(j.closeButton)||j.closeButton);let he=D;y.isValidElement(D)&&!pi(D.type)?he=y.cloneElement(D,{closeToast:ie,toastProps:Y,data:V}):Ur(D)&&(he=D({closeToast:ie,toastProps:Y,data:V}));const A={content:he,props:Y,staleId:G};j.limit&&j.limit>0&&b>j.limit&&re?w.push(A):Lu(W)?setTimeout(()=>{O(A)},W):O(A)},setProps(D){j=D},setToggle:(D,z)=>{M.get(D).toggle=z},isToastActive:D=>C.some(z=>z===D),getSnapshot:()=>j.newestOnTop?k.reverse():k}})(l,o,pL);ur.set(l,d);const f=d.observe(u);return $u.forEach(h=>Tj(h.content,h.options)),$u=[],()=>{f(),ur.delete(l)}},setProps(u){var d;(d=ur.get(l))==null||d.setProps(u)},getSnapshot(){var u;return(u=ur.get(l))==null?void 0:u.getSnapshot()}}})(e)).current;r(e);const s=y.useSyncExternalStore(t,n,n);return{getToastToRender:function(o){if(!s)return[];const l=new Map;return s.forEach(u=>{const{position:d}=u.props;l.has(d)||l.set(d,[]),l.get(d).push(u)}),Array.from(l,u=>o(u[0],u[1]))},isToastActive:jj,count:s?.length}}function gL(e){const[t,n]=y.useState(!1),[r,s]=y.useState(!1),o=y.useRef(null),l=y.useRef({start:0,delta:0,removalDistance:0,canCloseOnClick:!0,canDrag:!1,didMove:!1}).current,{autoClose:u,pauseOnHover:d,closeToast:f,onClick:h,closeOnClick:m}=e;var g,x;function b(){n(!0)}function w(){n(!1)}function C(M){const _=o.current;l.canDrag&&_&&(l.didMove=!0,t&&w(),l.delta=e.draggableDirection==="x"?M.clientX-l.start:M.clientY-l.start,l.start!==M.clientX&&(l.canCloseOnClick=!1),_.style.transform=`translate3d(${e.draggableDirection==="x"?`${l.delta}px, var(--y)`:`0, calc(${l.delta}px + var(--y))`},0)`,_.style.opacity=""+(1-Math.abs(l.delta/l.removalDistance)))}function k(){document.removeEventListener("pointermove",C),document.removeEventListener("pointerup",k);const M=o.current;if(l.canDrag&&l.didMove&&M){if(l.canDrag=!1,Math.abs(l.delta)>l.removalDistance)return s(!0),e.closeToast(),void e.collapseAll();M.style.transition="transform 0.2s, opacity 0.2s",M.style.removeProperty("transform"),M.style.removeProperty("opacity")}}(x=ur.get((g={id:e.toastId,containerId:e.containerId,fn:n}).containerId||1))==null||x.setToggle(g.id,g.fn),y.useEffect(()=>{if(e.pauseOnFocusLoss)return document.hasFocus()||w(),window.addEventListener("focus",b),window.addEventListener("blur",w),()=>{window.removeEventListener("focus",b),window.removeEventListener("blur",w)}},[e.pauseOnFocusLoss]);const j={onPointerDown:function(M){if(e.draggable===!0||e.draggable===M.pointerType){l.didMove=!1,document.addEventListener("pointermove",C),document.addEventListener("pointerup",k);const _=o.current;l.canCloseOnClick=!0,l.canDrag=!0,_.style.transition="none",e.draggableDirection==="x"?(l.start=M.clientX,l.removalDistance=_.offsetWidth*(e.draggablePercent/100)):(l.start=M.clientY,l.removalDistance=_.offsetHeight*(e.draggablePercent===80?1.5*e.draggablePercent:e.draggablePercent)/100)}},onPointerUp:function(M){const{top:_,bottom:R,left:N,right:O}=o.current.getBoundingClientRect();M.nativeEvent.type!=="touchend"&&e.pauseOnHover&&M.clientX>=N&&M.clientX<=O&&M.clientY>=_&&M.clientY<=R?w():b()}};return u&&d&&(j.onMouseEnter=w,e.stacked||(j.onMouseLeave=b)),m&&(j.onClick=M=>{h&&h(M),l.canCloseOnClick&&f()}),{playToast:b,pauseToast:w,isRunning:t,preventExitTransition:r,toastRef:o,eventHandlers:j}}function mL(e){let{delay:t,isRunning:n,closeToast:r,type:s="default",hide:o,className:l,style:u,controlledProgress:d,progress:f,rtl:h,isIn:m,theme:g}=e;const x=o||d&&f===0,b={...u,animationDuration:`${t}ms`,animationPlayState:n?"running":"paused"};d&&(b.transform=`scaleX(${f})`);const w=wo("Toastify__progress-bar",d?"Toastify__progress-bar--controlled":"Toastify__progress-bar--animated",`Toastify__progress-bar-theme--${g}`,`Toastify__progress-bar--${s}`,{"Toastify__progress-bar--rtl":h}),C=Ur(l)?l({rtl:h,type:s,defaultClassName:w}):wo(w,l),k={[d&&f>=1?"onTransitionEnd":"onAnimationEnd"]:d&&f<1?null:()=>{m&&r()}};return qe.createElement("div",{className:"Toastify__progress-bar--wrp","data-hidden":x},qe.createElement("div",{className:`Toastify__progress-bar--bg Toastify__progress-bar-theme--${g} Toastify__progress-bar--${s}`}),qe.createElement("div",{role:"progressbar","aria-hidden":x?"true":"false","aria-label":"notification timer",className:C,style:b,...k}))}let vL=1;const Nj=()=>""+vL++;function yL(e){return e&&(pi(e.toastId)||Lu(e.toastId))?e.toastId:Nj()}function ku(e,t){return Tj(e,t),t.toastId}function Pp(e,t){return{...t,type:t&&t.type||e,toastId:yL(t)}}function Lf(e){return(t,n)=>ku(t,Pp(e,n))}function me(e,t){return ku(e,Pp("default",t))}me.loading=(e,t)=>ku(e,Pp("default",{isLoading:!0,autoClose:!1,closeOnClick:!1,closeButton:!1,draggable:!1,...t})),me.promise=function(e,t,n){let r,{pending:s,error:o,success:l}=t;s&&(r=pi(s)?me.loading(s,n):me.loading(s.render,{...n,...s}));const u={isLoading:null,autoClose:null,closeOnClick:null,closeButton:null,draggable:null},d=(h,m,g)=>{if(m==null)return void me.dismiss(r);const x={type:h,...u,...n,data:g},b=pi(m)?{render:m}:m;return r?me.update(r,{...x,...b}):me(b.render,{...x,...b}),g},f=Ur(e)?e():e;return f.then(h=>d("success",l,h)).catch(h=>d("error",o,h)),f},me.success=Lf("success"),me.info=Lf("info"),me.error=Lf("error"),me.warning=Lf("warning"),me.warn=me.warning,me.dark=(e,t)=>ku(e,Pp("default",{theme:"dark",...t})),me.dismiss=function(e){(function(t){var n;if(kj()){if(t==null||pi(n=t)||Lu(n))ur.forEach(r=>{r.removeToast(t)});else if(t&&("containerId"in t||"id"in t)){const r=ur.get(t.containerId);r?r.removeToast(t.id):ur.forEach(s=>{s.removeToast(t.id)})}}else $u=$u.filter(r=>t!=null&&r.options.toastId!==t)})(e)},me.clearWaitingQueue=function(e){e===void 0&&(e={}),ur.forEach(t=>{!t.props.limit||e.containerId&&t.id!==e.containerId||t.clearQueue()})},me.isActive=jj,me.update=function(e,t){t===void 0&&(t={});const n=((r,s)=>{var o;let{containerId:l}=s;return(o=ur.get(l||1))==null?void 0:o.toasts.get(r)})(e,t);if(n){const{props:r,content:s}=n,o={delay:100,...r,...t,toastId:t.toastId||e,updateId:Nj()};o.toastId!==e&&(o.staleId=e);const l=o.render||s;delete o.render,ku(l,o)}},me.done=e=>{me.update(e,{progress:1})},me.onChange=function(e){return Py.add(e),()=>{Py.delete(e)}},me.play=e=>CC(!0,e),me.pause=e=>CC(!1,e);const bL=typeof window<"u"?y.useLayoutEffect:y.useEffect,$f=e=>{let{theme:t,type:n,isLoading:r,...s}=e;return qe.createElement("svg",{viewBox:"0 0 24 24",width:"100%",height:"100%",fill:t==="colored"?"currentColor":`var(--toastify-icon-color-${n})`,...s})},gv={info:function(e){return qe.createElement($f,{...e},qe.createElement("path",{d:"M12 0a12 12 0 1012 12A12.013 12.013 0 0012 0zm.25 5a1.5 1.5 0 11-1.5 1.5 1.5 1.5 0 011.5-1.5zm2.25 13.5h-4a1 1 0 010-2h.75a.25.25 0 00.25-.25v-4.5a.25.25 0 00-.25-.25h-.75a1 1 0 010-2h1a2 2 0 012 2v4.75a.25.25 0 00.25.25h.75a1 1 0 110 2z"}))},warning:function(e){return qe.createElement($f,{...e},qe.createElement("path",{d:"M23.32 17.191L15.438 2.184C14.728.833 13.416 0 11.996 0c-1.42 0-2.733.833-3.443 2.184L.533 17.448a4.744 4.744 0 000 4.368C1.243 23.167 2.555 24 3.975 24h16.05C22.22 24 24 22.044 24 19.632c0-.904-.251-1.746-.68-2.44zm-9.622 1.46c0 1.033-.724 1.823-1.698 1.823s-1.698-.79-1.698-1.822v-.043c0-1.028.724-1.822 1.698-1.822s1.698.79 1.698 1.822v.043zm.039-12.285l-.84 8.06c-.057.581-.408.943-.897.943-.49 0-.84-.367-.896-.942l-.84-8.065c-.057-.624.25-1.095.779-1.095h1.91c.528.005.84.476.784 1.1z"}))},success:function(e){return qe.createElement($f,{...e},qe.createElement("path",{d:"M12 0a12 12 0 1012 12A12.014 12.014 0 0012 0zm6.927 8.2l-6.845 9.289a1.011 1.011 0 01-1.43.188l-4.888-3.908a1 1 0 111.25-1.562l4.076 3.261 6.227-8.451a1 1 0 111.61 1.183z"}))},error:function(e){return qe.createElement($f,{...e},qe.createElement("path",{d:"M11.983 0a12.206 12.206 0 00-8.51 3.653A11.8 11.8 0 000 12.207 11.779 11.779 0 0011.8 24h.214A12.111 12.111 0 0024 11.791 11.766 11.766 0 0011.983 0zM10.5 16.542a1.476 1.476 0 011.449-1.53h.027a1.527 1.527 0 011.523 1.47 1.475 1.475 0 01-1.449 1.53h-.027a1.529 1.529 0 01-1.523-1.47zM11 12.5v-6a1 1 0 012 0v6a1 1 0 11-2 0z"}))},spinner:function(){return qe.createElement("div",{className:"Toastify__spinner"})}},xL=e=>{const{isRunning:t,preventExitTransition:n,toastRef:r,eventHandlers:s,playToast:o}=gL(e),{closeButton:l,children:u,autoClose:d,onClick:f,type:h,hideProgressBar:m,closeToast:g,transition:x,position:b,className:w,style:C,bodyClassName:k,bodyStyle:j,progressClassName:M,progressStyle:_,updateId:R,role:N,progress:O,rtl:D,toastId:z,deleteToast:Q,isIn:pe,isLoading:V,closeOnClick:G,theme:W}=e,ie=wo("Toastify__toast",`Toastify__toast-theme--${W}`,`Toastify__toast--${h}`,{"Toastify__toast--rtl":D},{"Toastify__toast--close-on-click":G}),re=Ur(w)?w({rtl:D,position:b,type:h,defaultClassName:ie}):wo(ie,w),Y=(function(A){let{theme:F,type:fe,isLoading:te,icon:de}=A,ge=null;const Z={theme:F,type:fe};return de===!1||(Ur(de)?ge=de({...Z,isLoading:te}):y.isValidElement(de)?ge=y.cloneElement(de,Z):te?ge=gv.spinner():(ye=>ye in gv)(fe)&&(ge=gv[fe](Z))),ge})(e),H=!!O||!d,q={closeToast:g,type:h,theme:W};let he=null;return l===!1||(he=Ur(l)?l(q):y.isValidElement(l)?y.cloneElement(l,q):(function(A){let{closeToast:F,theme:fe,ariaLabel:te="close"}=A;return qe.createElement("button",{className:`Toastify__close-button Toastify__close-button--${fe}`,type:"button",onClick:de=>{de.stopPropagation(),F(de)},"aria-label":te},qe.createElement("svg",{"aria-hidden":"true",viewBox:"0 0 14 16"},qe.createElement("path",{fillRule:"evenodd",d:"M7.71 8.23l3.75 3.75-1.48 1.48-3.75-3.75-3.75 3.75L1 11.98l3.75-3.75L1 4.48 2.48 3l3.75 3.75L9.98 3l1.48 1.48-3.75 3.75z"})))})(q)),qe.createElement(x,{isIn:pe,done:Q,position:b,preventExitTransition:n,nodeRef:r,playToast:o},qe.createElement("div",{id:z,onClick:f,"data-in":pe,className:re,...s,style:C,ref:r},qe.createElement("div",{...pe&&{role:N},className:Ur(k)?k({type:h}):wo("Toastify__toast-body",k),style:j},Y!=null&&qe.createElement("div",{className:wo("Toastify__toast-icon",{"Toastify--animate-icon Toastify__zoom-enter":!V})},Y),qe.createElement("div",null,u)),he,qe.createElement(mL,{...R&&!H?{key:`pb-${R}`}:{},rtl:D,theme:W,delay:d,isRunning:t,isIn:pe,closeToast:g,hide:m,type:h,style:_,className:M,controlledProgress:H,progress:O||0})))},bh=function(e,t){return t===void 0&&(t=!1),{enter:`Toastify--animate Toastify__${e}-enter`,exit:`Toastify--animate Toastify__${e}-exit`,appendPosition:t}},wL=yh(bh("bounce",!0));yh(bh("slide",!0));yh(bh("zoom"));yh(bh("flip"));const SL={position:"top-right",transition:wL,autoClose:5e3,closeButton:!0,pauseOnHover:!0,pauseOnFocusLoss:!0,draggable:"touch",draggablePercent:80,draggableDirection:"x",role:"alert",theme:"light"};function CL(e){let t={...SL,...e};const n=e.stacked,[r,s]=y.useState(!0),o=y.useRef(null),{getToastToRender:l,isToastActive:u,count:d}=hL(t),{className:f,style:h,rtl:m,containerId:g}=t;function x(w){const C=wo("Toastify__toast-container",`Toastify__toast-container--${w}`,{"Toastify__toast-container--rtl":m});return Ur(f)?f({position:w,rtl:m,defaultClassName:C}):wo(C,up(f))}function b(){n&&(s(!0),me.play())}return bL(()=>{if(n){var w;const C=o.current.querySelectorAll('[data-in="true"]'),k=12,j=(w=t.position)==null?void 0:w.includes("top");let M=0,_=0;Array.from(C).reverse().forEach((R,N)=>{const O=R;O.classList.add("Toastify__toast--stacked"),N>0&&(O.dataset.collapsed=`${r}`),O.dataset.pos||(O.dataset.pos=j?"top":"bot");const D=M*(r?.2:1)+(r?0:k*N);O.style.setProperty("--y",`${j?D:-1*D}px`),O.style.setProperty("--g",`${k}`),O.style.setProperty("--s",""+(1-(r?_:0))),M+=O.offsetHeight,_+=.025})}},[r,d,n]),qe.createElement("div",{ref:o,className:"Toastify",id:g,onMouseEnter:()=>{n&&(s(!1),me.pause())},onMouseLeave:b},l((w,C)=>{const k=C.length?{...h}:{...h,pointerEvents:"none"};return qe.createElement("div",{className:x(w),style:k,key:`container-${w}`},C.map(j=>{let{content:M,props:_}=j;return qe.createElement(xL,{..._,stacked:n,collapseAll:b,isIn:u(_.toastId,_.containerId),style:_.style,key:`toast-${_.key}`},M)}))}))}const EL={theme:"system",setTheme:()=>null},Mj=y.createContext(EL);function kL({children:e,defaultTheme:t="system",storageKey:n="vite-ui-theme",...r}){const[s,o]=y.useState(()=>localStorage.getItem(n)||t);y.useEffect(()=>{const u=window.document.documentElement;if(u.classList.remove("light","dark"),s==="system"){const d=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light";u.classList.add(d);return}u.classList.add(s)},[s]);const l={theme:s,setTheme:u=>{localStorage.setItem(n,u),o(u)}};return i.jsx(Mj.Provider,{...r,value:l,children:e})}const tc=()=>{const e=y.useContext(Mj);if(e===void 0)throw new Error("useTheme must be used within a ThemeProvider");return e};let mv=!1;const _j=new KD({defaultOptions:{queries:{staleTime:1e3*60*5,retry(e){return e>=3?(mv===!1&&(mv=!0,me.error("The application is taking longer than expected to load, please try again in a few minutes.",{onClose:()=>{mv=!1}})),!1):!0}}}});var jn=(e=>(e.API_URL="apiUrl",e.TOKEN="token",e.INSTANCE_ID="instanceId",e.INSTANCE_NAME="instanceName",e.INSTANCE_TOKEN="instanceToken",e.VERSION="version",e.FACEBOOK_APP_ID="facebookAppId",e.FACEBOOK_CONFIG_ID="facebookConfigId",e.FACEBOOK_USER_TOKEN="facebookUserToken",e.CLIENT_NAME="clientName",e))(jn||{});const Rj=async e=>{if(e.url){const t=e.url.endsWith("/")?e.url.slice(0,-1):e.url;localStorage.setItem("apiUrl",t)}e.token&&localStorage.setItem("token",e.token),e.version&&localStorage.setItem("version",e.version),e.facebookAppId&&localStorage.setItem("facebookAppId",e.facebookAppId),e.facebookConfigId&&localStorage.setItem("facebookConfigId",e.facebookConfigId),e.facebookUserToken&&localStorage.setItem("facebookUserToken",e.facebookUserToken),e.clientName&&localStorage.setItem("clientName",e.clientName)},Pj=()=>{localStorage.removeItem("apiUrl"),localStorage.removeItem("token"),localStorage.removeItem("version"),localStorage.removeItem("facebookAppId"),localStorage.removeItem("facebookConfigId"),localStorage.removeItem("facebookUserToken"),localStorage.removeItem("clientName")},dr=e=>localStorage.getItem(e),tn=({children:e})=>{const t=dr(jn.API_URL),n=dr(jn.TOKEN),r=dr(jn.VERSION);return!t||!n||!r?i.jsx(Cj,{to:"/manager/login"}):e},jL=({children:e})=>{const t=dr(jn.API_URL),n=dr(jn.TOKEN),r=dr(jn.VERSION);return t&&n&&r?i.jsx(Cj,{to:"/"}):e};function Oj(e,t){return function(){return e.apply(t,arguments)}}const{toString:TL}=Object.prototype,{getPrototypeOf:$b}=Object,{iterator:xh,toStringTag:Ij}=Symbol,wh=(e=>t=>{const n=TL.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),Rs=e=>(e=e.toLowerCase(),t=>wh(t)===e),Sh=e=>t=>typeof t===e,{isArray:nc}=Array,$l=Sh("undefined");function gd(e){return e!==null&&!$l(e)&&e.constructor!==null&&!$l(e.constructor)&&jr(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const Aj=Rs("ArrayBuffer");function NL(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&Aj(e.buffer),t}const ML=Sh("string"),jr=Sh("function"),Dj=Sh("number"),md=e=>e!==null&&typeof e=="object",_L=e=>e===!0||e===!1,dp=e=>{if(wh(e)!=="object")return!1;const t=$b(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Ij in e)&&!(xh in e)},RL=e=>{if(!md(e)||gd(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},PL=Rs("Date"),OL=Rs("File"),IL=Rs("Blob"),AL=Rs("FileList"),DL=e=>md(e)&&jr(e.pipe),FL=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||jr(e.append)&&((t=wh(e))==="formdata"||t==="object"&&jr(e.toString)&&e.toString()==="[object FormData]"))},LL=Rs("URLSearchParams"),[$L,BL,zL,UL]=["ReadableStream","Request","Response","Headers"].map(Rs),VL=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function vd(e,t,{allOwnKeys:n=!1}={}){if(e===null||typeof e>"u")return;let r,s;if(typeof e!="object"&&(e=[e]),nc(e))for(r=0,s=e.length;r0;)if(s=n[r],t===s.toLowerCase())return s;return null}const li=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,Lj=e=>!$l(e)&&e!==li;function Oy(){const{caseless:e,skipUndefined:t}=Lj(this)&&this||{},n={},r=(s,o)=>{const l=e&&Fj(n,o)||o;dp(n[l])&&dp(s)?n[l]=Oy(n[l],s):dp(s)?n[l]=Oy({},s):nc(s)?n[l]=s.slice():(!t||!$l(s))&&(n[l]=s)};for(let s=0,o=arguments.length;s(vd(t,(s,o)=>{n&&jr(s)?e[o]=Oj(s,n):e[o]=s},{allOwnKeys:r}),e),qL=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),KL=(e,t,n,r)=>{e.prototype=Object.create(t.prototype,r),e.prototype.constructor=e,Object.defineProperty(e,"super",{value:t.prototype}),n&&Object.assign(e.prototype,n)},WL=(e,t,n,r)=>{let s,o,l;const u={};if(t=t||{},e==null)return t;do{for(s=Object.getOwnPropertyNames(e),o=s.length;o-- >0;)l=s[o],(!r||r(l,e,t))&&!u[l]&&(t[l]=e[l],u[l]=!0);e=n!==!1&&$b(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},GL=(e,t,n)=>{e=String(e),(n===void 0||n>e.length)&&(n=e.length),n-=t.length;const r=e.indexOf(t,n);return r!==-1&&r===n},JL=e=>{if(!e)return null;if(nc(e))return e;let t=e.length;if(!Dj(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},QL=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&$b(Uint8Array)),ZL=(e,t)=>{const r=(e&&e[xh]).call(e);let s;for(;(s=r.next())&&!s.done;){const o=s.value;t.call(e,o[0],o[1])}},YL=(e,t)=>{let n;const r=[];for(;(n=e.exec(t))!==null;)r.push(n);return r},XL=Rs("HTMLFormElement"),e4=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,r,s){return r.toUpperCase()+s}),EC=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),t4=Rs("RegExp"),$j=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};vd(n,(s,o)=>{let l;(l=t(s,o,e))!==!1&&(r[o]=l||s)}),Object.defineProperties(e,r)},n4=e=>{$j(e,(t,n)=>{if(jr(e)&&["arguments","caller","callee"].indexOf(n)!==-1)return!1;const r=e[n];if(jr(r)){if(t.enumerable=!1,"writable"in t){t.writable=!1;return}t.set||(t.set=()=>{throw Error("Can not rewrite read-only method '"+n+"'")})}})},r4=(e,t)=>{const n={},r=s=>{s.forEach(o=>{n[o]=!0})};return nc(e)?r(e):r(String(e).split(t)),n},s4=()=>{},o4=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function a4(e){return!!(e&&jr(e.append)&&e[Ij]==="FormData"&&e[xh])}const i4=e=>{const t=new Array(10),n=(r,s)=>{if(md(r)){if(t.indexOf(r)>=0)return;if(gd(r))return r;if(!("toJSON"in r)){t[s]=r;const o=nc(r)?[]:{};return vd(r,(l,u)=>{const d=n(l,s+1);!$l(d)&&(o[u]=d)}),t[s]=void 0,o}}return r};return n(e,0)},l4=Rs("AsyncFunction"),c4=e=>e&&(md(e)||jr(e))&&jr(e.then)&&jr(e.catch),Bj=((e,t)=>e?setImmediate:t?((n,r)=>(li.addEventListener("message",({source:s,data:o})=>{s===li&&o===n&&r.length&&r.shift()()},!1),s=>{r.push(s),li.postMessage(n,"*")}))(`axios@${Math.random()}`,[]):n=>setTimeout(n))(typeof setImmediate=="function",jr(li.postMessage)),u4=typeof queueMicrotask<"u"?queueMicrotask.bind(li):typeof process<"u"&&process.nextTick||Bj,d4=e=>e!=null&&jr(e[xh]),ce={isArray:nc,isArrayBuffer:Aj,isBuffer:gd,isFormData:FL,isArrayBufferView:NL,isString:ML,isNumber:Dj,isBoolean:_L,isObject:md,isPlainObject:dp,isEmptyObject:RL,isReadableStream:$L,isRequest:BL,isResponse:zL,isHeaders:UL,isUndefined:$l,isDate:PL,isFile:OL,isBlob:IL,isRegExp:t4,isFunction:jr,isStream:DL,isURLSearchParams:LL,isTypedArray:QL,isFileList:AL,forEach:vd,merge:Oy,extend:HL,trim:VL,stripBOM:qL,inherits:KL,toFlatObject:WL,kindOf:wh,kindOfTest:Rs,endsWith:GL,toArray:JL,forEachEntry:ZL,matchAll:YL,isHTMLForm:XL,hasOwnProperty:EC,hasOwnProp:EC,reduceDescriptors:$j,freezeMethods:n4,toObjectSet:r4,toCamelCase:e4,noop:s4,toFiniteNumber:o4,findKey:Fj,global:li,isContextDefined:Lj,isSpecCompliantForm:a4,toJSONObject:i4,isAsyncFn:l4,isThenable:c4,setImmediate:Bj,asap:u4,isIterable:d4};function vt(e,t,n,r,s){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=new Error().stack,this.message=e,this.name="AxiosError",t&&(this.code=t),n&&(this.config=n),r&&(this.request=r),s&&(this.response=s,this.status=s.status?s.status:null)}ce.inherits(vt,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:ce.toJSONObject(this.config),code:this.code,status:this.status}}});const zj=vt.prototype,Uj={};["ERR_BAD_OPTION_VALUE","ERR_BAD_OPTION","ECONNABORTED","ETIMEDOUT","ERR_NETWORK","ERR_FR_TOO_MANY_REDIRECTS","ERR_DEPRECATED","ERR_BAD_RESPONSE","ERR_BAD_REQUEST","ERR_CANCELED","ERR_NOT_SUPPORT","ERR_INVALID_URL"].forEach(e=>{Uj[e]={value:e}});Object.defineProperties(vt,Uj);Object.defineProperty(zj,"isAxiosError",{value:!0});vt.from=(e,t,n,r,s,o)=>{const l=Object.create(zj);ce.toFlatObject(e,l,function(h){return h!==Error.prototype},f=>f!=="isAxiosError");const u=e&&e.message?e.message:"Error",d=t==null&&e?e.code:t;return vt.call(l,u,d,n,r,s),e&&l.cause==null&&Object.defineProperty(l,"cause",{value:e,configurable:!0}),l.name=e&&e.name||"Error",o&&Object.assign(l,o),l};const f4=null;function Iy(e){return ce.isPlainObject(e)||ce.isArray(e)}function Vj(e){return ce.endsWith(e,"[]")?e.slice(0,-2):e}function kC(e,t,n){return e?e.concat(t).map(function(s,o){return s=Vj(s),!n&&o?"["+s+"]":s}).join(n?".":""):t}function p4(e){return ce.isArray(e)&&!e.some(Iy)}const h4=ce.toFlatObject(ce,{},null,function(t){return/^is[A-Z]/.test(t)});function Ch(e,t,n){if(!ce.isObject(e))throw new TypeError("target must be an object");t=t||new FormData,n=ce.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(w,C){return!ce.isUndefined(C[w])});const r=n.metaTokens,s=n.visitor||h,o=n.dots,l=n.indexes,d=(n.Blob||typeof Blob<"u"&&Blob)&&ce.isSpecCompliantForm(t);if(!ce.isFunction(s))throw new TypeError("visitor must be a function");function f(b){if(b===null)return"";if(ce.isDate(b))return b.toISOString();if(ce.isBoolean(b))return b.toString();if(!d&&ce.isBlob(b))throw new vt("Blob is not supported. Use a Buffer instead.");return ce.isArrayBuffer(b)||ce.isTypedArray(b)?d&&typeof Blob=="function"?new Blob([b]):Buffer.from(b):b}function h(b,w,C){let k=b;if(b&&!C&&typeof b=="object"){if(ce.endsWith(w,"{}"))w=r?w:w.slice(0,-2),b=JSON.stringify(b);else if(ce.isArray(b)&&p4(b)||(ce.isFileList(b)||ce.endsWith(w,"[]"))&&(k=ce.toArray(b)))return w=Vj(w),k.forEach(function(M,_){!(ce.isUndefined(M)||M===null)&&t.append(l===!0?kC([w],_,o):l===null?w:w+"[]",f(M))}),!1}return Iy(b)?!0:(t.append(kC(C,w,o),f(b)),!1)}const m=[],g=Object.assign(h4,{defaultVisitor:h,convertValue:f,isVisitable:Iy});function x(b,w){if(!ce.isUndefined(b)){if(m.indexOf(b)!==-1)throw Error("Circular reference detected in "+w.join("."));m.push(b),ce.forEach(b,function(k,j){(!(ce.isUndefined(k)||k===null)&&s.call(t,k,ce.isString(j)?j.trim():j,w,g))===!0&&x(k,w?w.concat(j):[j])}),m.pop()}}if(!ce.isObject(e))throw new TypeError("data must be an object");return x(e),t}function jC(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(r){return t[r]})}function Bb(e,t){this._pairs=[],e&&Ch(e,this,t)}const Hj=Bb.prototype;Hj.append=function(t,n){this._pairs.push([t,n])};Hj.toString=function(t){const n=t?function(r){return t.call(this,r,jC)}:jC;return this._pairs.map(function(s){return n(s[0])+"="+n(s[1])},"").join("&")};function g4(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function qj(e,t,n){if(!t)return e;const r=n&&n.encode||g4;ce.isFunction(n)&&(n={serialize:n});const s=n&&n.serialize;let o;if(s?o=s(t,n):o=ce.isURLSearchParams(t)?t.toString():new Bb(t,n).toString(r),o){const l=e.indexOf("#");l!==-1&&(e=e.slice(0,l)),e+=(e.indexOf("?")===-1?"?":"&")+o}return e}class TC{constructor(){this.handlers=[]}use(t,n,r){return this.handlers.push({fulfilled:t,rejected:n,synchronous:r?r.synchronous:!1,runWhen:r?r.runWhen:null}),this.handlers.length-1}eject(t){this.handlers[t]&&(this.handlers[t]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(t){ce.forEach(this.handlers,function(r){r!==null&&t(r)})}}const Kj={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},m4=typeof URLSearchParams<"u"?URLSearchParams:Bb,v4=typeof FormData<"u"?FormData:null,y4=typeof Blob<"u"?Blob:null,b4={isBrowser:!0,classes:{URLSearchParams:m4,FormData:v4,Blob:y4},protocols:["http","https","file","blob","url","data"]},zb=typeof window<"u"&&typeof document<"u",Ay=typeof navigator=="object"&&navigator||void 0,x4=zb&&(!Ay||["ReactNative","NativeScript","NS"].indexOf(Ay.product)<0),w4=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",S4=zb&&window.location.href||"http://localhost",C4=Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:zb,hasStandardBrowserEnv:x4,hasStandardBrowserWebWorkerEnv:w4,navigator:Ay,origin:S4},Symbol.toStringTag,{value:"Module"})),rr={...C4,...b4};function E4(e,t){return Ch(e,new rr.classes.URLSearchParams,{visitor:function(n,r,s,o){return rr.isNode&&ce.isBuffer(n)?(this.append(r,n.toString("base64")),!1):o.defaultVisitor.apply(this,arguments)},...t})}function k4(e){return ce.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function j4(e){const t={},n=Object.keys(e);let r;const s=n.length;let o;for(r=0;r=n.length;return l=!l&&ce.isArray(s)?s.length:l,d?(ce.hasOwnProp(s,l)?s[l]=[s[l],r]:s[l]=r,!u):((!s[l]||!ce.isObject(s[l]))&&(s[l]=[]),t(n,r,s[l],o)&&ce.isArray(s[l])&&(s[l]=j4(s[l])),!u)}if(ce.isFormData(e)&&ce.isFunction(e.entries)){const n={};return ce.forEachEntry(e,(r,s)=>{t(k4(r),s,n,0)}),n}return null}function T4(e,t,n){if(ce.isString(e))try{return(t||JSON.parse)(e),ce.trim(e)}catch(r){if(r.name!=="SyntaxError")throw r}return(n||JSON.stringify)(e)}const yd={transitional:Kj,adapter:["xhr","http","fetch"],transformRequest:[function(t,n){const r=n.getContentType()||"",s=r.indexOf("application/json")>-1,o=ce.isObject(t);if(o&&ce.isHTMLForm(t)&&(t=new FormData(t)),ce.isFormData(t))return s?JSON.stringify(Wj(t)):t;if(ce.isArrayBuffer(t)||ce.isBuffer(t)||ce.isStream(t)||ce.isFile(t)||ce.isBlob(t)||ce.isReadableStream(t))return t;if(ce.isArrayBufferView(t))return t.buffer;if(ce.isURLSearchParams(t))return n.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),t.toString();let u;if(o){if(r.indexOf("application/x-www-form-urlencoded")>-1)return E4(t,this.formSerializer).toString();if((u=ce.isFileList(t))||r.indexOf("multipart/form-data")>-1){const d=this.env&&this.env.FormData;return Ch(u?{"files[]":t}:t,d&&new d,this.formSerializer)}}return o||s?(n.setContentType("application/json",!1),T4(t)):t}],transformResponse:[function(t){const n=this.transitional||yd.transitional,r=n&&n.forcedJSONParsing,s=this.responseType==="json";if(ce.isResponse(t)||ce.isReadableStream(t))return t;if(t&&ce.isString(t)&&(r&&!this.responseType||s)){const l=!(n&&n.silentJSONParsing)&&s;try{return JSON.parse(t,this.parseReviver)}catch(u){if(l)throw u.name==="SyntaxError"?vt.from(u,vt.ERR_BAD_RESPONSE,this,null,this.response):u}}return t}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:rr.classes.FormData,Blob:rr.classes.Blob},validateStatus:function(t){return t>=200&&t<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};ce.forEach(["delete","get","head","post","put","patch"],e=>{yd.headers[e]={}});const N4=ce.toObjectSet(["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"]),M4=e=>{const t={};let n,r,s;return e&&e.split(` `).forEach(function(l){s=l.indexOf(":"),n=l.substring(0,s).trim().toLowerCase(),r=l.substring(s+1).trim(),!(!n||t[n]&&N4[n])&&(n==="set-cookie"?t[n]?t[n].push(r):t[n]=[r]:t[n]=t[n]?t[n]+", "+r:r)}),t},NC=Symbol("internals");function ru(e){return e&&String(e).trim().toLowerCase()}function fp(e){return e===!1||e==null?e:ce.isArray(e)?e.map(fp):String(e)}function _4(e){const t=Object.create(null),n=/([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;let r;for(;r=n.exec(e);)t[r[1]]=r[2];return t}const R4=e=>/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(e.trim());function vv(e,t,n,r,s){if(ce.isFunction(r))return r.call(this,t,n);if(s&&(t=n),!!ce.isString(t)){if(ce.isString(r))return t.indexOf(r)!==-1;if(ce.isRegExp(r))return r.test(t)}}function P4(e){return e.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(t,n,r)=>n.toUpperCase()+r)}function O4(e,t){const n=ce.toCamelCase(" "+t);["get","set","has"].forEach(r=>{Object.defineProperty(e,r+n,{value:function(s,o,l){return this[r].call(this,t,s,o,l)},configurable:!0})})}let Tr=class{constructor(t){t&&this.set(t)}set(t,n,r){const s=this;function o(u,d,f){const h=ru(d);if(!h)throw new Error("header name must be a non-empty string");const m=ce.findKey(s,h);(!m||s[m]===void 0||f===!0||f===void 0&&s[m]!==!1)&&(s[m||d]=fp(u))}const l=(u,d)=>ce.forEach(u,(f,h)=>o(f,h,d));if(ce.isPlainObject(t)||t instanceof this.constructor)l(t,n);else if(ce.isString(t)&&(t=t.trim())&&!R4(t))l(M4(t),n);else if(ce.isObject(t)&&ce.isIterable(t)){let u={},d,f;for(const h of t){if(!ce.isArray(h))throw TypeError("Object iterator must return a key-value pair");u[f=h[0]]=(d=u[f])?ce.isArray(d)?[...d,h[1]]:[d,h[1]]:h[1]}l(u,n)}else t!=null&&o(n,t,r);return this}get(t,n){if(t=ru(t),t){const r=ce.findKey(this,t);if(r){const s=this[r];if(!n)return s;if(n===!0)return _4(s);if(ce.isFunction(n))return n.call(this,s,r);if(ce.isRegExp(n))return n.exec(s);throw new TypeError("parser must be boolean|regexp|function")}}}has(t,n){if(t=ru(t),t){const r=ce.findKey(this,t);return!!(r&&this[r]!==void 0&&(!n||vv(this,this[r],r,n)))}return!1}delete(t,n){const r=this;let s=!1;function o(l){if(l=ru(l),l){const u=ce.findKey(r,l);u&&(!n||vv(r,r[u],u,n))&&(delete r[u],s=!0)}}return ce.isArray(t)?t.forEach(o):o(t),s}clear(t){const n=Object.keys(this);let r=n.length,s=!1;for(;r--;){const o=n[r];(!t||vv(this,this[o],o,t,!0))&&(delete this[o],s=!0)}return s}normalize(t){const n=this,r={};return ce.forEach(this,(s,o)=>{const l=ce.findKey(r,o);if(l){n[l]=fp(s),delete n[o];return}const u=t?P4(o):String(o).trim();u!==o&&delete n[o],n[u]=fp(s),r[u]=!0}),this}concat(...t){return this.constructor.concat(this,...t)}toJSON(t){const n=Object.create(null);return ce.forEach(this,(r,s)=>{r!=null&&r!==!1&&(n[s]=t&&ce.isArray(r)?r.join(", "):r)}),n}[Symbol.iterator](){return Object.entries(this.toJSON())[Symbol.iterator]()}toString(){return Object.entries(this.toJSON()).map(([t,n])=>t+": "+n).join(` `)}getSetCookie(){return this.get("set-cookie")||[]}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(t){return t instanceof this?t:new this(t)}static concat(t,...n){const r=new this(t);return n.forEach(s=>r.set(s)),r}static accessor(t){const r=(this[NC]=this[NC]={accessors:{}}).accessors,s=this.prototype;function o(l){const u=ru(l);r[u]||(O4(s,l),r[u]=!0)}return ce.isArray(t)?t.forEach(o):o(t),this}};Tr.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]);ce.reduceDescriptors(Tr.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}});ce.freezeMethods(Tr);function yv(e,t){const n=this||yd,r=t||n,s=Tr.from(r.headers);let o=r.data;return ce.forEach(e,function(u){o=u.call(n,o,s.normalize(),t?t.status:void 0)}),s.normalize(),o}function Gj(e){return!!(e&&e.__CANCEL__)}function rc(e,t,n){vt.call(this,e??"canceled",vt.ERR_CANCELED,t,n),this.name="CanceledError"}ce.inherits(rc,vt,{__CANCEL__:!0});function Jj(e,t,n){const r=n.config.validateStatus;!n.status||!r||r(n.status)?e(n):t(new vt("Request failed with status code "+n.status,[vt.ERR_BAD_REQUEST,vt.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}function I4(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function A4(e,t){e=e||10;const n=new Array(e),r=new Array(e);let s=0,o=0,l;return t=t!==void 0?t:1e3,function(d){const f=Date.now(),h=r[o];l||(l=f),n[s]=d,r[s]=f;let m=o,g=0;for(;m!==s;)g+=n[m++],m=m%e;if(s=(s+1)%e,s===o&&(o=(o+1)%e),f-l{n=h,s=null,o&&(clearTimeout(o),o=null),e(...f)};return[(...f)=>{const h=Date.now(),m=h-n;m>=r?l(f,h):(s=f,o||(o=setTimeout(()=>{o=null,l(s)},r-m)))},()=>s&&l(s)]}const Op=(e,t,n=3)=>{let r=0;const s=A4(50,250);return D4(o=>{const l=o.loaded,u=o.lengthComputable?o.total:void 0,d=l-r,f=s(d),h=l<=u;r=l;const m={loaded:l,total:u,progress:u?l/u:void 0,bytes:d,rate:f||void 0,estimated:f&&u&&h?(u-l)/f:void 0,event:o,lengthComputable:u!=null,[t?"download":"upload"]:!0};e(m)},n)},MC=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},_C=e=>(...t)=>ce.asap(()=>e(...t)),F4=rr.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,rr.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(rr.origin),rr.navigator&&/(msie|trident)/i.test(rr.navigator.userAgent)):()=>!0,L4=rr.hasStandardBrowserEnv?{write(e,t,n,r,s,o){const l=[e+"="+encodeURIComponent(t)];ce.isNumber(n)&&l.push("expires="+new Date(n).toGMTString()),ce.isString(r)&&l.push("path="+r),ce.isString(s)&&l.push("domain="+s),o===!0&&l.push("secure"),document.cookie=l.join("; ")},read(e){const t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove(e){this.write(e,"",Date.now()-864e5)}}:{write(){},read(){return null},remove(){}};function $4(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function B4(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function Qj(e,t,n){let r=!$4(t);return e&&(r||n==!1)?B4(e,t):t}const RC=e=>e instanceof Tr?{...e}:e;function Si(e,t){t=t||{};const n={};function r(f,h,m,g){return ce.isPlainObject(f)&&ce.isPlainObject(h)?ce.merge.call({caseless:g},f,h):ce.isPlainObject(h)?ce.merge({},h):ce.isArray(h)?h.slice():h}function s(f,h,m,g){if(ce.isUndefined(h)){if(!ce.isUndefined(f))return r(void 0,f,m,g)}else return r(f,h,m,g)}function o(f,h){if(!ce.isUndefined(h))return r(void 0,h)}function l(f,h){if(ce.isUndefined(h)){if(!ce.isUndefined(f))return r(void 0,f)}else return r(void 0,h)}function u(f,h,m){if(m in t)return r(f,h);if(m in e)return r(void 0,f)}const d={url:o,method:o,data:o,baseURL:l,transformRequest:l,transformResponse:l,paramsSerializer:l,timeout:l,timeoutMessage:l,withCredentials:l,withXSRFToken:l,adapter:l,responseType:l,xsrfCookieName:l,xsrfHeaderName:l,onUploadProgress:l,onDownloadProgress:l,decompress:l,maxContentLength:l,maxBodyLength:l,beforeRedirect:l,transport:l,httpAgent:l,httpsAgent:l,cancelToken:l,socketPath:l,responseEncoding:l,validateStatus:u,headers:(f,h,m)=>s(RC(f),RC(h),m,!0)};return ce.forEach(Object.keys({...e,...t}),function(h){const m=d[h]||s,g=m(e[h],t[h],h);ce.isUndefined(g)&&m!==u||(n[h]=g)}),n}const Zj=e=>{const t=Si({},e);let{data:n,withXSRFToken:r,xsrfHeaderName:s,xsrfCookieName:o,headers:l,auth:u}=t;if(t.headers=l=Tr.from(l),t.url=qj(Qj(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),u&&l.set("Authorization","Basic "+btoa((u.username||"")+":"+(u.password?unescape(encodeURIComponent(u.password)):""))),ce.isFormData(n)){if(rr.hasStandardBrowserEnv||rr.hasStandardBrowserWebWorkerEnv)l.setContentType(void 0);else if(ce.isFunction(n.getHeaders)){const d=n.getHeaders(),f=["content-type","content-length"];Object.entries(d).forEach(([h,m])=>{f.includes(h.toLowerCase())&&l.set(h,m)})}}if(rr.hasStandardBrowserEnv&&(r&&ce.isFunction(r)&&(r=r(t)),r||r!==!1&&F4(t.url))){const d=s&&o&&L4.read(o);d&&l.set(s,d)}return t},z4=typeof XMLHttpRequest<"u",U4=z4&&function(e){return new Promise(function(n,r){const s=Zj(e);let o=s.data;const l=Tr.from(s.headers).normalize();let{responseType:u,onUploadProgress:d,onDownloadProgress:f}=s,h,m,g,x,b;function w(){x&&x(),b&&b(),s.cancelToken&&s.cancelToken.unsubscribe(h),s.signal&&s.signal.removeEventListener("abort",h)}let C=new XMLHttpRequest;C.open(s.method.toUpperCase(),s.url,!0),C.timeout=s.timeout;function k(){if(!C)return;const M=Tr.from("getAllResponseHeaders"in C&&C.getAllResponseHeaders()),R={data:!u||u==="text"||u==="json"?C.responseText:C.response,status:C.status,statusText:C.statusText,headers:M,config:e,request:C};Jj(function(O){n(O),w()},function(O){r(O),w()},R),C=null}"onloadend"in C?C.onloadend=k:C.onreadystatechange=function(){!C||C.readyState!==4||C.status===0&&!(C.responseURL&&C.responseURL.indexOf("file:")===0)||setTimeout(k)},C.onabort=function(){C&&(r(new vt("Request aborted",vt.ECONNABORTED,e,C)),C=null)},C.onerror=function(_){const R=_&&_.message?_.message:"Network Error",N=new vt(R,vt.ERR_NETWORK,e,C);N.event=_||null,r(N),C=null},C.ontimeout=function(){let _=s.timeout?"timeout of "+s.timeout+"ms exceeded":"timeout exceeded";const R=s.transitional||Kj;s.timeoutErrorMessage&&(_=s.timeoutErrorMessage),r(new vt(_,R.clarifyTimeoutError?vt.ETIMEDOUT:vt.ECONNABORTED,e,C)),C=null},o===void 0&&l.setContentType(null),"setRequestHeader"in C&&ce.forEach(l.toJSON(),function(_,R){C.setRequestHeader(R,_)}),ce.isUndefined(s.withCredentials)||(C.withCredentials=!!s.withCredentials),u&&u!=="json"&&(C.responseType=s.responseType),f&&([g,b]=Op(f,!0),C.addEventListener("progress",g)),d&&C.upload&&([m,x]=Op(d),C.upload.addEventListener("progress",m),C.upload.addEventListener("loadend",x)),(s.cancelToken||s.signal)&&(h=M=>{C&&(r(!M||M.type?new rc(null,e,C):M),C.abort(),C=null)},s.cancelToken&&s.cancelToken.subscribe(h),s.signal&&(s.signal.aborted?h():s.signal.addEventListener("abort",h)));const j=I4(s.url);if(j&&rr.protocols.indexOf(j)===-1){r(new vt("Unsupported protocol "+j+":",vt.ERR_BAD_REQUEST,e));return}C.send(o||null)})},V4=(e,t)=>{const{length:n}=e=e?e.filter(Boolean):[];if(t||n){let r=new AbortController,s;const o=function(f){if(!s){s=!0,u();const h=f instanceof Error?f:this.reason;r.abort(h instanceof vt?h:new rc(h instanceof Error?h.message:h))}};let l=t&&setTimeout(()=>{l=null,o(new vt(`timeout ${t} of ms exceeded`,vt.ETIMEDOUT))},t);const u=()=>{e&&(l&&clearTimeout(l),l=null,e.forEach(f=>{f.unsubscribe?f.unsubscribe(o):f.removeEventListener("abort",o)}),e=null)};e.forEach(f=>f.addEventListener("abort",o));const{signal:d}=r;return d.unsubscribe=()=>ce.asap(u),d}},H4=function*(e,t){let n=e.byteLength;if(n{const s=q4(e,t);let o=0,l,u=d=>{l||(l=!0,r&&r(d))};return new ReadableStream({async pull(d){try{const{done:f,value:h}=await s.next();if(f){u(),d.close();return}let m=h.byteLength;if(n){let g=o+=m;n(g)}d.enqueue(new Uint8Array(h))}catch(f){throw u(f),f}},cancel(d){return u(d),s.return()}},{highWaterMark:2})},OC=64*1024,{isFunction:Bf}=ce,W4=(({Request:e,Response:t})=>({Request:e,Response:t}))(ce.global),{ReadableStream:IC,TextEncoder:AC}=ce.global,DC=(e,...t)=>{try{return!!e(...t)}catch{return!1}},G4=e=>{e=ce.merge.call({skipUndefined:!0},W4,e);const{fetch:t,Request:n,Response:r}=e,s=t?Bf(t):typeof fetch=="function",o=Bf(n),l=Bf(r);if(!s)return!1;const u=s&&Bf(IC),d=s&&(typeof AC=="function"?(b=>w=>b.encode(w))(new AC):async b=>new Uint8Array(await new n(b).arrayBuffer())),f=o&&u&&DC(()=>{let b=!1;const w=new n(rr.origin,{body:new IC,method:"POST",get duplex(){return b=!0,"half"}}).headers.has("Content-Type");return b&&!w}),h=l&&u&&DC(()=>ce.isReadableStream(new r("").body)),m={stream:h&&(b=>b.body)};s&&["text","arrayBuffer","blob","formData","stream"].forEach(b=>{!m[b]&&(m[b]=(w,C)=>{let k=w&&w[b];if(k)return k.call(w);throw new vt(`Response type '${b}' is not supported`,vt.ERR_NOT_SUPPORT,C)})});const g=async b=>{if(b==null)return 0;if(ce.isBlob(b))return b.size;if(ce.isSpecCompliantForm(b))return(await new n(rr.origin,{method:"POST",body:b}).arrayBuffer()).byteLength;if(ce.isArrayBufferView(b)||ce.isArrayBuffer(b))return b.byteLength;if(ce.isURLSearchParams(b)&&(b=b+""),ce.isString(b))return(await d(b)).byteLength},x=async(b,w)=>{const C=ce.toFiniteNumber(b.getContentLength());return C??g(w)};return async b=>{let{url:w,method:C,data:k,signal:j,cancelToken:M,timeout:_,onDownloadProgress:R,onUploadProgress:N,responseType:O,headers:D,withCredentials:z="same-origin",fetchOptions:Q}=Zj(b),pe=t||fetch;O=O?(O+"").toLowerCase():"text";let V=V4([j,M&&M.toAbortSignal()],_),G=null;const W=V&&V.unsubscribe&&(()=>{V.unsubscribe()});let ie;try{if(N&&f&&C!=="get"&&C!=="head"&&(ie=await x(D,k))!==0){let A=new n(w,{method:"POST",body:k,duplex:"half"}),F;if(ce.isFormData(k)&&(F=A.headers.get("content-type"))&&D.setContentType(F),A.body){const[fe,te]=MC(ie,Op(_C(N)));k=PC(A.body,OC,fe,te)}}ce.isString(z)||(z=z?"include":"omit");const re=o&&"credentials"in n.prototype,Y={...Q,signal:V,method:C.toUpperCase(),headers:D.normalize().toJSON(),body:k,duplex:"half",credentials:re?z:void 0};G=o&&new n(w,Y);let H=await(o?pe(G,Q):pe(w,Y));const q=h&&(O==="stream"||O==="response");if(h&&(R||q&&W)){const A={};["status","statusText","headers"].forEach(de=>{A[de]=H[de]});const F=ce.toFiniteNumber(H.headers.get("content-length")),[fe,te]=R&&MC(F,Op(_C(R),!0))||[];H=new r(PC(H.body,OC,fe,()=>{te&&te(),W&&W()}),A)}O=O||"text";let he=await m[ce.findKey(m,O)||"text"](H,b);return!q&&W&&W(),await new Promise((A,F)=>{Jj(A,F,{data:he,headers:Tr.from(H.headers),status:H.status,statusText:H.statusText,config:b,request:G})})}catch(re){throw W&&W(),re&&re.name==="TypeError"&&/Load failed|fetch/i.test(re.message)?Object.assign(new vt("Network Error",vt.ERR_NETWORK,b,G),{cause:re.cause||re}):vt.from(re,re&&re.code,b,G)}}},J4=new Map,Yj=e=>{let t=e?e.env:{};const{fetch:n,Request:r,Response:s}=t,o=[r,s,n];let l=o.length,u=l,d,f,h=J4;for(;u--;)d=o[u],f=h.get(d),f===void 0&&h.set(d,f=u?new Map:G4(t)),h=f;return f};Yj();const Dy={http:f4,xhr:U4,fetch:{get:Yj}};ce.forEach(Dy,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const FC=e=>`- ${e}`,Q4=e=>ce.isFunction(e)||e===null||e===!1,Xj={getAdapter:(e,t)=>{e=ce.isArray(e)?e:[e];const{length:n}=e;let r,s;const o={};for(let l=0;l`adapter ${d} `+(f===!1?"is not supported by the environment":"is not available in the build"));let u=n?l.length>1?`since : `+l.map(FC).join(` `):" "+FC(l[0]):"as no adapter specified";throw new vt("There is no suitable adapter to dispatch the request "+u,"ERR_NOT_SUPPORT")}return s},adapters:Dy};function bv(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new rc(null,e)}function LC(e){return bv(e),e.headers=Tr.from(e.headers),e.data=yv.call(e,e.transformRequest),["post","put","patch"].indexOf(e.method)!==-1&&e.headers.setContentType("application/x-www-form-urlencoded",!1),Xj.getAdapter(e.adapter||yd.adapter,e)(e).then(function(r){return bv(e),r.data=yv.call(e,e.transformResponse,r),r.headers=Tr.from(r.headers),r},function(r){return Gj(r)||(bv(e),r&&r.response&&(r.response.data=yv.call(e,e.transformResponse,r.response),r.response.headers=Tr.from(r.response.headers))),Promise.reject(r)})}const eT="1.12.2",Eh={};["object","boolean","number","function","string","symbol"].forEach((e,t)=>{Eh[e]=function(r){return typeof r===e||"a"+(t<1?"n ":" ")+e}});const $C={};Eh.transitional=function(t,n,r){function s(o,l){return"[Axios v"+eT+"] Transitional option '"+o+"'"+l+(r?". "+r:"")}return(o,l,u)=>{if(t===!1)throw new vt(s(l," has been removed"+(n?" in "+n:"")),vt.ERR_DEPRECATED);return n&&!$C[l]&&($C[l]=!0,console.warn(s(l," has been deprecated since v"+n+" and will be removed in the near future"))),t?t(o,l,u):!0}};Eh.spelling=function(t){return(n,r)=>(console.warn(`${r} is likely a misspelling of ${t}`),!0)};function Z4(e,t,n){if(typeof e!="object")throw new vt("options must be an object",vt.ERR_BAD_OPTION_VALUE);const r=Object.keys(e);let s=r.length;for(;s-- >0;){const o=r[s],l=t[o];if(l){const u=e[o],d=u===void 0||l(u,o,e);if(d!==!0)throw new vt("option "+o+" must be "+d,vt.ERR_BAD_OPTION_VALUE);continue}if(n!==!0)throw new vt("Unknown option "+o,vt.ERR_BAD_OPTION)}}const pp={assertOptions:Z4,validators:Eh},$s=pp.validators;let hi=class{constructor(t){this.defaults=t||{},this.interceptors={request:new TC,response:new TC}}async request(t,n){try{return await this._request(t,n)}catch(r){if(r instanceof Error){let s={};Error.captureStackTrace?Error.captureStackTrace(s):s=new Error;const o=s.stack?s.stack.replace(/^.+\n/,""):"";try{r.stack?o&&!String(r.stack).endsWith(o.replace(/^.+\n.+\n/,""))&&(r.stack+=` `+o):r.stack=o}catch{}}throw r}}_request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=Si(this.defaults,n);const{transitional:r,paramsSerializer:s,headers:o}=n;r!==void 0&&pp.assertOptions(r,{silentJSONParsing:$s.transitional($s.boolean),forcedJSONParsing:$s.transitional($s.boolean),clarifyTimeoutError:$s.transitional($s.boolean)},!1),s!=null&&(ce.isFunction(s)?n.paramsSerializer={serialize:s}:pp.assertOptions(s,{encode:$s.function,serialize:$s.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),pp.assertOptions(n,{baseUrl:$s.spelling("baseURL"),withXsrfToken:$s.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let l=o&&ce.merge(o.common,o[n.method]);o&&ce.forEach(["delete","get","head","post","put","patch","common"],b=>{delete o[b]}),n.headers=Tr.concat(l,o);const u=[];let d=!0;this.interceptors.request.forEach(function(w){typeof w.runWhen=="function"&&w.runWhen(n)===!1||(d=d&&w.synchronous,u.unshift(w.fulfilled,w.rejected))});const f=[];this.interceptors.response.forEach(function(w){f.push(w.fulfilled,w.rejected)});let h,m=0,g;if(!d){const b=[LC.bind(this),void 0];for(b.unshift(...u),b.push(...f),g=b.length,h=Promise.resolve(n);m{if(!r._listeners)return;let o=r._listeners.length;for(;o-- >0;)r._listeners[o](s);r._listeners=null}),this.promise.then=s=>{let o;const l=new Promise(u=>{r.subscribe(u),o=u}).then(s);return l.cancel=function(){r.unsubscribe(o)},l},t(function(o,l,u){r.reason||(r.reason=new rc(o,l,u),n(r.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(t){if(this.reason){t(this.reason);return}this._listeners?this._listeners.push(t):this._listeners=[t]}unsubscribe(t){if(!this._listeners)return;const n=this._listeners.indexOf(t);n!==-1&&this._listeners.splice(n,1)}toAbortSignal(){const t=new AbortController,n=r=>{t.abort(r)};return this.subscribe(n),t.signal.unsubscribe=()=>this.unsubscribe(n),t.signal}static source(){let t;return{token:new tT(function(s){t=s}),cancel:t}}};function X4(e){return function(n){return e.apply(null,n)}}function e$(e){return ce.isObject(e)&&e.isAxiosError===!0}const Fy={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511};Object.entries(Fy).forEach(([e,t])=>{Fy[t]=e});function nT(e){const t=new hi(e),n=Oj(hi.prototype.request,t);return ce.extend(n,hi.prototype,t,{allOwnKeys:!0}),ce.extend(n,t,null,{allOwnKeys:!0}),n.create=function(s){return nT(Si(e,s))},n}const sn=nT(yd);sn.Axios=hi;sn.CanceledError=rc;sn.CancelToken=Y4;sn.isCancel=Gj;sn.VERSION=eT;sn.toFormData=Ch;sn.AxiosError=vt;sn.Cancel=sn.CanceledError;sn.all=function(t){return Promise.all(t)};sn.spread=X4;sn.isAxiosError=e$;sn.mergeConfig=Si;sn.AxiosHeaders=Tr;sn.formToJSON=e=>Wj(ce.isHTMLForm(e)?new FormData(e):e);sn.getAdapter=Xj.getAdapter;sn.HttpStatusCode=Fy;sn.default=sn;const{Axios:aie,AxiosError:iie,CanceledError:lie,isCancel:cie,CancelToken:uie,VERSION:die,all:fie,Cancel:pie,isAxiosError:rT,spread:hie,toFormData:gie,AxiosHeaders:mie,HttpStatusCode:vie,formToJSON:yie,getAdapter:bie,mergeConfig:xie}=sn,t$=e=>["auth","verifyServer",JSON.stringify(e)],sT=async({url:e})=>(await sn.get(`${e}/`)).data,n$=e=>{const{url:t,...n}=e;return mt({...n,queryKey:t$({url:t}),queryFn:()=>sT({url:t}),enabled:!!t})};function r$(e,t){typeof e=="function"?e(t):e!=null&&(e.current=t)}function kh(...e){return t=>e.forEach(n=>r$(n,t))}function Rt(...e){return y.useCallback(kh(...e),e)}var No=y.forwardRef((e,t)=>{const{children:n,...r}=e,s=y.Children.toArray(n),o=s.find(o$);if(o){const l=o.props.children,u=s.map(d=>d===o?y.Children.count(l)>1?y.Children.only(null):y.isValidElement(l)?l.props.children:null:d);return i.jsx(Ly,{...r,ref:t,children:y.isValidElement(l)?y.cloneElement(l,void 0,u):null})}return i.jsx(Ly,{...r,ref:t,children:n})});No.displayName="Slot";var Ly=y.forwardRef((e,t)=>{const{children:n,...r}=e;if(y.isValidElement(n)){const s=i$(n);return y.cloneElement(n,{...a$(r,n.props),ref:t?kh(t,s):s})}return y.Children.count(n)>1?y.Children.only(null):null});Ly.displayName="SlotClone";var s$=({children:e})=>i.jsx(i.Fragment,{children:e});function o$(e){return y.isValidElement(e)&&e.type===s$}function a$(e,t){const n={...t};for(const r in t){const s=e[r],o=t[r];/^on[A-Z]/.test(r)?s&&o?n[r]=(...u)=>{o(...u),s(...u)}:s&&(n[r]=s):r==="style"?n[r]={...s,...o}:r==="className"&&(n[r]=[s,o].filter(Boolean).join(" "))}return{...e,...n}}function i$(e){let t=Object.getOwnPropertyDescriptor(e.props,"ref")?.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=Object.getOwnPropertyDescriptor(e,"ref")?.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}function oT(e){var t,n,r="";if(typeof e=="string"||typeof e=="number")r+=e;else if(typeof e=="object")if(Array.isArray(e))for(t=0;ttypeof e=="boolean"?"".concat(e):e===0?"0":e,zC=l$,jh=(e,t)=>n=>{var r;if(t?.variants==null)return zC(e,n?.class,n?.className);const{variants:s,defaultVariants:o}=t,l=Object.keys(s).map(f=>{const h=n?.[f],m=o?.[f];if(h===null)return null;const g=BC(h)||BC(m);return s[f][g]}),u=n&&Object.entries(n).reduce((f,h)=>{let[m,g]=h;return g===void 0||(f[m]=g),f},{}),d=t==null||(r=t.compoundVariants)===null||r===void 0?void 0:r.reduce((f,h)=>{let{class:m,className:g,...x}=h;return Object.entries(x).every(b=>{let[w,C]=b;return Array.isArray(C)?C.includes({...o,...u}[w]):{...o,...u}[w]===C})?[...f,m,g]:f},[]);return zC(e,l,d,n?.class,n?.className)},Ub="-";function c$(e){const t=d$(e),{conflictingClassGroups:n,conflictingClassGroupModifiers:r}=e;function s(l){const u=l.split(Ub);return u[0]===""&&u.length!==1&&u.shift(),aT(u,t)||u$(l)}function o(l,u){const d=n[l]||[];return u&&r[l]?[...d,...r[l]]:d}return{getClassGroupId:s,getConflictingClassGroupIds:o}}function aT(e,t){if(e.length===0)return t.classGroupId;const n=e[0],r=t.nextPart.get(n),s=r?aT(e.slice(1),r):void 0;if(s)return s;if(t.validators.length===0)return;const o=e.join(Ub);return t.validators.find(({validator:l})=>l(o))?.classGroupId}const UC=/^\[(.+)\]$/;function u$(e){if(UC.test(e)){const t=UC.exec(e)[1],n=t?.substring(0,t.indexOf(":"));if(n)return"arbitrary.."+n}}function d$(e){const{theme:t,prefix:n}=e,r={nextPart:new Map,validators:[]};return p$(Object.entries(e.classGroups),n).forEach(([o,l])=>{$y(l,r,o,t)}),r}function $y(e,t,n,r){e.forEach(s=>{if(typeof s=="string"){const o=s===""?t:VC(t,s);o.classGroupId=n;return}if(typeof s=="function"){if(f$(s)){$y(s(r),t,n,r);return}t.validators.push({validator:s,classGroupId:n});return}Object.entries(s).forEach(([o,l])=>{$y(l,VC(t,o),n,r)})})}function VC(e,t){let n=e;return t.split(Ub).forEach(r=>{n.nextPart.has(r)||n.nextPart.set(r,{nextPart:new Map,validators:[]}),n=n.nextPart.get(r)}),n}function f$(e){return e.isThemeGetter}function p$(e,t){return t?e.map(([n,r])=>{const s=r.map(o=>typeof o=="string"?t+o:typeof o=="object"?Object.fromEntries(Object.entries(o).map(([l,u])=>[t+l,u])):o);return[n,s]}):e}function h$(e){if(e<1)return{get:()=>{},set:()=>{}};let t=0,n=new Map,r=new Map;function s(o,l){n.set(o,l),t++,t>e&&(t=0,r=n,n=new Map)}return{get(o){let l=n.get(o);if(l!==void 0)return l;if((l=r.get(o))!==void 0)return s(o,l),l},set(o,l){n.has(o)?n.set(o,l):s(o,l)}}}const iT="!";function g$(e){const{separator:t,experimentalParseClassName:n}=e,r=t.length===1,s=t[0],o=t.length;function l(u){const d=[];let f=0,h=0,m;for(let C=0;Ch?m-h:void 0;return{modifiers:d,hasImportantModifier:x,baseClassName:b,maybePostfixModifierPosition:w}}return n?function(d){return n({className:d,parseClassName:l})}:l}function m$(e){if(e.length<=1)return e;const t=[];let n=[];return e.forEach(r=>{r[0]==="["?(t.push(...n.sort(),r),n=[]):n.push(r)}),t.push(...n.sort()),t}function v$(e){return{cache:h$(e.cacheSize),parseClassName:g$(e),...c$(e)}}const y$=/\s+/;function b$(e,t){const{parseClassName:n,getClassGroupId:r,getConflictingClassGroupIds:s}=t,o=new Set;return e.trim().split(y$).map(l=>{const{modifiers:u,hasImportantModifier:d,baseClassName:f,maybePostfixModifierPosition:h}=n(l);let m=!!h,g=r(m?f.substring(0,h):f);if(!g){if(!m)return{isTailwindClass:!1,originalClassName:l};if(g=r(f),!g)return{isTailwindClass:!1,originalClassName:l};m=!1}const x=m$(u).join(":");return{isTailwindClass:!0,modifierId:d?x+iT:x,classGroupId:g,originalClassName:l,hasPostfixModifier:m}}).reverse().filter(l=>{if(!l.isTailwindClass)return!0;const{modifierId:u,classGroupId:d,hasPostfixModifier:f}=l,h=u+d;return o.has(h)?!1:(o.add(h),s(d,f).forEach(m=>o.add(u+m)),!0)}).reverse().map(l=>l.originalClassName).join(" ")}function x$(){let e=0,t,n,r="";for(;em(h),e());return n=v$(f),r=n.cache.get,s=n.cache.set,o=u,u(d)}function u(d){const f=r(d);if(f)return f;const h=b$(d,n);return s(d,h),h}return function(){return o(x$.apply(null,arguments))}}function nn(e){const t=n=>n[e]||[];return t.isThemeGetter=!0,t}const cT=/^\[(?:([a-z-]+):)?(.+)\]$/i,S$=/^\d+\/\d+$/,C$=new Set(["px","full","screen"]),E$=/^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/,k$=/\d+(%|px|r?em|[sdl]?v([hwib]|min|max)|pt|pc|in|cm|mm|cap|ch|ex|r?lh|cq(w|h|i|b|min|max))|\b(calc|min|max|clamp)\(.+\)|^0$/,j$=/^(rgba?|hsla?|hwb|(ok)?(lab|lch))\(.+\)$/,T$=/^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/,N$=/^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/;function ho(e){return ci(e)||C$.has(e)||S$.test(e)}function ca(e){return sc(e,"length",D$)}function ci(e){return!!e&&!Number.isNaN(Number(e))}function zf(e){return sc(e,"number",ci)}function su(e){return!!e&&Number.isInteger(Number(e))}function M$(e){return e.endsWith("%")&&ci(e.slice(0,-1))}function xt(e){return cT.test(e)}function ua(e){return E$.test(e)}const _$=new Set(["length","size","percentage"]);function R$(e){return sc(e,_$,uT)}function P$(e){return sc(e,"position",uT)}const O$=new Set(["image","url"]);function I$(e){return sc(e,O$,L$)}function A$(e){return sc(e,"",F$)}function ou(){return!0}function sc(e,t,n){const r=cT.exec(e);return r?r[1]?typeof t=="string"?r[1]===t:t.has(r[1]):n(r[2]):!1}function D$(e){return k$.test(e)&&!j$.test(e)}function uT(){return!1}function F$(e){return T$.test(e)}function L$(e){return N$.test(e)}function $$(){const e=nn("colors"),t=nn("spacing"),n=nn("blur"),r=nn("brightness"),s=nn("borderColor"),o=nn("borderRadius"),l=nn("borderSpacing"),u=nn("borderWidth"),d=nn("contrast"),f=nn("grayscale"),h=nn("hueRotate"),m=nn("invert"),g=nn("gap"),x=nn("gradientColorStops"),b=nn("gradientColorStopPositions"),w=nn("inset"),C=nn("margin"),k=nn("opacity"),j=nn("padding"),M=nn("saturate"),_=nn("scale"),R=nn("sepia"),N=nn("skew"),O=nn("space"),D=nn("translate"),z=()=>["auto","contain","none"],Q=()=>["auto","hidden","clip","visible","scroll"],pe=()=>["auto",xt,t],V=()=>[xt,t],G=()=>["",ho,ca],W=()=>["auto",ci,xt],ie=()=>["bottom","center","left","left-bottom","left-top","right","right-bottom","right-top","top"],re=()=>["solid","dashed","dotted","double","none"],Y=()=>["normal","multiply","screen","overlay","darken","lighten","color-dodge","color-burn","hard-light","soft-light","difference","exclusion","hue","saturation","color","luminosity"],H=()=>["start","end","center","between","around","evenly","stretch"],q=()=>["","0",xt],he=()=>["auto","avoid","all","avoid-page","page","left","right","column"],A=()=>[ci,zf],F=()=>[ci,xt];return{cacheSize:500,separator:":",theme:{colors:[ou],spacing:[ho,ca],blur:["none","",ua,xt],brightness:A(),borderColor:[e],borderRadius:["none","","full",ua,xt],borderSpacing:V(),borderWidth:G(),contrast:A(),grayscale:q(),hueRotate:F(),invert:q(),gap:V(),gradientColorStops:[e],gradientColorStopPositions:[M$,ca],inset:pe(),margin:pe(),opacity:A(),padding:V(),saturate:A(),scale:A(),sepia:q(),skew:F(),space:V(),translate:V()},classGroups:{aspect:[{aspect:["auto","square","video",xt]}],container:["container"],columns:[{columns:[ua]}],"break-after":[{"break-after":he()}],"break-before":[{"break-before":he()}],"break-inside":[{"break-inside":["auto","avoid","avoid-page","avoid-column"]}],"box-decoration":[{"box-decoration":["slice","clone"]}],box:[{box:["border","content"]}],display:["block","inline-block","inline","flex","inline-flex","table","inline-table","table-caption","table-cell","table-column","table-column-group","table-footer-group","table-header-group","table-row-group","table-row","flow-root","grid","inline-grid","contents","list-item","hidden"],float:[{float:["right","left","none","start","end"]}],clear:[{clear:["left","right","both","none","start","end"]}],isolation:["isolate","isolation-auto"],"object-fit":[{object:["contain","cover","fill","none","scale-down"]}],"object-position":[{object:[...ie(),xt]}],overflow:[{overflow:Q()}],"overflow-x":[{"overflow-x":Q()}],"overflow-y":[{"overflow-y":Q()}],overscroll:[{overscroll:z()}],"overscroll-x":[{"overscroll-x":z()}],"overscroll-y":[{"overscroll-y":z()}],position:["static","fixed","absolute","relative","sticky"],inset:[{inset:[w]}],"inset-x":[{"inset-x":[w]}],"inset-y":[{"inset-y":[w]}],start:[{start:[w]}],end:[{end:[w]}],top:[{top:[w]}],right:[{right:[w]}],bottom:[{bottom:[w]}],left:[{left:[w]}],visibility:["visible","invisible","collapse"],z:[{z:["auto",su,xt]}],basis:[{basis:pe()}],"flex-direction":[{flex:["row","row-reverse","col","col-reverse"]}],"flex-wrap":[{flex:["wrap","wrap-reverse","nowrap"]}],flex:[{flex:["1","auto","initial","none",xt]}],grow:[{grow:q()}],shrink:[{shrink:q()}],order:[{order:["first","last","none",su,xt]}],"grid-cols":[{"grid-cols":[ou]}],"col-start-end":[{col:["auto",{span:["full",su,xt]},xt]}],"col-start":[{"col-start":W()}],"col-end":[{"col-end":W()}],"grid-rows":[{"grid-rows":[ou]}],"row-start-end":[{row:["auto",{span:[su,xt]},xt]}],"row-start":[{"row-start":W()}],"row-end":[{"row-end":W()}],"grid-flow":[{"grid-flow":["row","col","dense","row-dense","col-dense"]}],"auto-cols":[{"auto-cols":["auto","min","max","fr",xt]}],"auto-rows":[{"auto-rows":["auto","min","max","fr",xt]}],gap:[{gap:[g]}],"gap-x":[{"gap-x":[g]}],"gap-y":[{"gap-y":[g]}],"justify-content":[{justify:["normal",...H()]}],"justify-items":[{"justify-items":["start","end","center","stretch"]}],"justify-self":[{"justify-self":["auto","start","end","center","stretch"]}],"align-content":[{content:["normal",...H(),"baseline"]}],"align-items":[{items:["start","end","center","baseline","stretch"]}],"align-self":[{self:["auto","start","end","center","stretch","baseline"]}],"place-content":[{"place-content":[...H(),"baseline"]}],"place-items":[{"place-items":["start","end","center","baseline","stretch"]}],"place-self":[{"place-self":["auto","start","end","center","stretch"]}],p:[{p:[j]}],px:[{px:[j]}],py:[{py:[j]}],ps:[{ps:[j]}],pe:[{pe:[j]}],pt:[{pt:[j]}],pr:[{pr:[j]}],pb:[{pb:[j]}],pl:[{pl:[j]}],m:[{m:[C]}],mx:[{mx:[C]}],my:[{my:[C]}],ms:[{ms:[C]}],me:[{me:[C]}],mt:[{mt:[C]}],mr:[{mr:[C]}],mb:[{mb:[C]}],ml:[{ml:[C]}],"space-x":[{"space-x":[O]}],"space-x-reverse":["space-x-reverse"],"space-y":[{"space-y":[O]}],"space-y-reverse":["space-y-reverse"],w:[{w:["auto","min","max","fit","svw","lvw","dvw",xt,t]}],"min-w":[{"min-w":[xt,t,"min","max","fit"]}],"max-w":[{"max-w":[xt,t,"none","full","min","max","fit","prose",{screen:[ua]},ua]}],h:[{h:[xt,t,"auto","min","max","fit","svh","lvh","dvh"]}],"min-h":[{"min-h":[xt,t,"min","max","fit","svh","lvh","dvh"]}],"max-h":[{"max-h":[xt,t,"min","max","fit","svh","lvh","dvh"]}],size:[{size:[xt,t,"auto","min","max","fit"]}],"font-size":[{text:["base",ua,ca]}],"font-smoothing":["antialiased","subpixel-antialiased"],"font-style":["italic","not-italic"],"font-weight":[{font:["thin","extralight","light","normal","medium","semibold","bold","extrabold","black",zf]}],"font-family":[{font:[ou]}],"fvn-normal":["normal-nums"],"fvn-ordinal":["ordinal"],"fvn-slashed-zero":["slashed-zero"],"fvn-figure":["lining-nums","oldstyle-nums"],"fvn-spacing":["proportional-nums","tabular-nums"],"fvn-fraction":["diagonal-fractions","stacked-fractons"],tracking:[{tracking:["tighter","tight","normal","wide","wider","widest",xt]}],"line-clamp":[{"line-clamp":["none",ci,zf]}],leading:[{leading:["none","tight","snug","normal","relaxed","loose",ho,xt]}],"list-image":[{"list-image":["none",xt]}],"list-style-type":[{list:["none","disc","decimal",xt]}],"list-style-position":[{list:["inside","outside"]}],"placeholder-color":[{placeholder:[e]}],"placeholder-opacity":[{"placeholder-opacity":[k]}],"text-alignment":[{text:["left","center","right","justify","start","end"]}],"text-color":[{text:[e]}],"text-opacity":[{"text-opacity":[k]}],"text-decoration":["underline","overline","line-through","no-underline"],"text-decoration-style":[{decoration:[...re(),"wavy"]}],"text-decoration-thickness":[{decoration:["auto","from-font",ho,ca]}],"underline-offset":[{"underline-offset":["auto",ho,xt]}],"text-decoration-color":[{decoration:[e]}],"text-transform":["uppercase","lowercase","capitalize","normal-case"],"text-overflow":["truncate","text-ellipsis","text-clip"],"text-wrap":[{text:["wrap","nowrap","balance","pretty"]}],indent:[{indent:V()}],"vertical-align":[{align:["baseline","top","middle","bottom","text-top","text-bottom","sub","super",xt]}],whitespace:[{whitespace:["normal","nowrap","pre","pre-line","pre-wrap","break-spaces"]}],break:[{break:["normal","words","all","keep"]}],hyphens:[{hyphens:["none","manual","auto"]}],content:[{content:["none",xt]}],"bg-attachment":[{bg:["fixed","local","scroll"]}],"bg-clip":[{"bg-clip":["border","padding","content","text"]}],"bg-opacity":[{"bg-opacity":[k]}],"bg-origin":[{"bg-origin":["border","padding","content"]}],"bg-position":[{bg:[...ie(),P$]}],"bg-repeat":[{bg:["no-repeat",{repeat:["","x","y","round","space"]}]}],"bg-size":[{bg:["auto","cover","contain",R$]}],"bg-image":[{bg:["none",{"gradient-to":["t","tr","r","br","b","bl","l","tl"]},I$]}],"bg-color":[{bg:[e]}],"gradient-from-pos":[{from:[b]}],"gradient-via-pos":[{via:[b]}],"gradient-to-pos":[{to:[b]}],"gradient-from":[{from:[x]}],"gradient-via":[{via:[x]}],"gradient-to":[{to:[x]}],rounded:[{rounded:[o]}],"rounded-s":[{"rounded-s":[o]}],"rounded-e":[{"rounded-e":[o]}],"rounded-t":[{"rounded-t":[o]}],"rounded-r":[{"rounded-r":[o]}],"rounded-b":[{"rounded-b":[o]}],"rounded-l":[{"rounded-l":[o]}],"rounded-ss":[{"rounded-ss":[o]}],"rounded-se":[{"rounded-se":[o]}],"rounded-ee":[{"rounded-ee":[o]}],"rounded-es":[{"rounded-es":[o]}],"rounded-tl":[{"rounded-tl":[o]}],"rounded-tr":[{"rounded-tr":[o]}],"rounded-br":[{"rounded-br":[o]}],"rounded-bl":[{"rounded-bl":[o]}],"border-w":[{border:[u]}],"border-w-x":[{"border-x":[u]}],"border-w-y":[{"border-y":[u]}],"border-w-s":[{"border-s":[u]}],"border-w-e":[{"border-e":[u]}],"border-w-t":[{"border-t":[u]}],"border-w-r":[{"border-r":[u]}],"border-w-b":[{"border-b":[u]}],"border-w-l":[{"border-l":[u]}],"border-opacity":[{"border-opacity":[k]}],"border-style":[{border:[...re(),"hidden"]}],"divide-x":[{"divide-x":[u]}],"divide-x-reverse":["divide-x-reverse"],"divide-y":[{"divide-y":[u]}],"divide-y-reverse":["divide-y-reverse"],"divide-opacity":[{"divide-opacity":[k]}],"divide-style":[{divide:re()}],"border-color":[{border:[s]}],"border-color-x":[{"border-x":[s]}],"border-color-y":[{"border-y":[s]}],"border-color-t":[{"border-t":[s]}],"border-color-r":[{"border-r":[s]}],"border-color-b":[{"border-b":[s]}],"border-color-l":[{"border-l":[s]}],"divide-color":[{divide:[s]}],"outline-style":[{outline:["",...re()]}],"outline-offset":[{"outline-offset":[ho,xt]}],"outline-w":[{outline:[ho,ca]}],"outline-color":[{outline:[e]}],"ring-w":[{ring:G()}],"ring-w-inset":["ring-inset"],"ring-color":[{ring:[e]}],"ring-opacity":[{"ring-opacity":[k]}],"ring-offset-w":[{"ring-offset":[ho,ca]}],"ring-offset-color":[{"ring-offset":[e]}],shadow:[{shadow:["","inner","none",ua,A$]}],"shadow-color":[{shadow:[ou]}],opacity:[{opacity:[k]}],"mix-blend":[{"mix-blend":[...Y(),"plus-lighter","plus-darker"]}],"bg-blend":[{"bg-blend":Y()}],filter:[{filter:["","none"]}],blur:[{blur:[n]}],brightness:[{brightness:[r]}],contrast:[{contrast:[d]}],"drop-shadow":[{"drop-shadow":["","none",ua,xt]}],grayscale:[{grayscale:[f]}],"hue-rotate":[{"hue-rotate":[h]}],invert:[{invert:[m]}],saturate:[{saturate:[M]}],sepia:[{sepia:[R]}],"backdrop-filter":[{"backdrop-filter":["","none"]}],"backdrop-blur":[{"backdrop-blur":[n]}],"backdrop-brightness":[{"backdrop-brightness":[r]}],"backdrop-contrast":[{"backdrop-contrast":[d]}],"backdrop-grayscale":[{"backdrop-grayscale":[f]}],"backdrop-hue-rotate":[{"backdrop-hue-rotate":[h]}],"backdrop-invert":[{"backdrop-invert":[m]}],"backdrop-opacity":[{"backdrop-opacity":[k]}],"backdrop-saturate":[{"backdrop-saturate":[M]}],"backdrop-sepia":[{"backdrop-sepia":[R]}],"border-collapse":[{border:["collapse","separate"]}],"border-spacing":[{"border-spacing":[l]}],"border-spacing-x":[{"border-spacing-x":[l]}],"border-spacing-y":[{"border-spacing-y":[l]}],"table-layout":[{table:["auto","fixed"]}],caption:[{caption:["top","bottom"]}],transition:[{transition:["none","all","","colors","opacity","shadow","transform",xt]}],duration:[{duration:F()}],ease:[{ease:["linear","in","out","in-out",xt]}],delay:[{delay:F()}],animate:[{animate:["none","spin","ping","pulse","bounce",xt]}],transform:[{transform:["","gpu","none"]}],scale:[{scale:[_]}],"scale-x":[{"scale-x":[_]}],"scale-y":[{"scale-y":[_]}],rotate:[{rotate:[su,xt]}],"translate-x":[{"translate-x":[D]}],"translate-y":[{"translate-y":[D]}],"skew-x":[{"skew-x":[N]}],"skew-y":[{"skew-y":[N]}],"transform-origin":[{origin:["center","top","top-right","right","bottom-right","bottom","bottom-left","left","top-left",xt]}],accent:[{accent:["auto",e]}],appearance:[{appearance:["none","auto"]}],cursor:[{cursor:["auto","default","pointer","wait","text","move","help","not-allowed","none","context-menu","progress","cell","crosshair","vertical-text","alias","copy","no-drop","grab","grabbing","all-scroll","col-resize","row-resize","n-resize","e-resize","s-resize","w-resize","ne-resize","nw-resize","se-resize","sw-resize","ew-resize","ns-resize","nesw-resize","nwse-resize","zoom-in","zoom-out",xt]}],"caret-color":[{caret:[e]}],"pointer-events":[{"pointer-events":["none","auto"]}],resize:[{resize:["none","y","x",""]}],"scroll-behavior":[{scroll:["auto","smooth"]}],"scroll-m":[{"scroll-m":V()}],"scroll-mx":[{"scroll-mx":V()}],"scroll-my":[{"scroll-my":V()}],"scroll-ms":[{"scroll-ms":V()}],"scroll-me":[{"scroll-me":V()}],"scroll-mt":[{"scroll-mt":V()}],"scroll-mr":[{"scroll-mr":V()}],"scroll-mb":[{"scroll-mb":V()}],"scroll-ml":[{"scroll-ml":V()}],"scroll-p":[{"scroll-p":V()}],"scroll-px":[{"scroll-px":V()}],"scroll-py":[{"scroll-py":V()}],"scroll-ps":[{"scroll-ps":V()}],"scroll-pe":[{"scroll-pe":V()}],"scroll-pt":[{"scroll-pt":V()}],"scroll-pr":[{"scroll-pr":V()}],"scroll-pb":[{"scroll-pb":V()}],"scroll-pl":[{"scroll-pl":V()}],"snap-align":[{snap:["start","end","center","align-none"]}],"snap-stop":[{snap:["normal","always"]}],"snap-type":[{snap:["none","x","y","both"]}],"snap-strictness":[{snap:["mandatory","proximity"]}],touch:[{touch:["auto","none","manipulation"]}],"touch-x":[{"touch-pan":["x","left","right"]}],"touch-y":[{"touch-pan":["y","up","down"]}],"touch-pz":["touch-pinch-zoom"],select:[{select:["none","text","all","auto"]}],"will-change":[{"will-change":["auto","scroll","contents","transform",xt]}],fill:[{fill:[e,"none"]}],"stroke-w":[{stroke:[ho,ca,zf]}],stroke:[{stroke:[e,"none"]}],sr:["sr-only","not-sr-only"],"forced-color-adjust":[{"forced-color-adjust":["auto","none"]}]},conflictingClassGroups:{overflow:["overflow-x","overflow-y"],overscroll:["overscroll-x","overscroll-y"],inset:["inset-x","inset-y","start","end","top","right","bottom","left"],"inset-x":["right","left"],"inset-y":["top","bottom"],flex:["basis","grow","shrink"],gap:["gap-x","gap-y"],p:["px","py","ps","pe","pt","pr","pb","pl"],px:["pr","pl"],py:["pt","pb"],m:["mx","my","ms","me","mt","mr","mb","ml"],mx:["mr","ml"],my:["mt","mb"],size:["w","h"],"font-size":["leading"],"fvn-normal":["fvn-ordinal","fvn-slashed-zero","fvn-figure","fvn-spacing","fvn-fraction"],"fvn-ordinal":["fvn-normal"],"fvn-slashed-zero":["fvn-normal"],"fvn-figure":["fvn-normal"],"fvn-spacing":["fvn-normal"],"fvn-fraction":["fvn-normal"],"line-clamp":["display","overflow"],rounded:["rounded-s","rounded-e","rounded-t","rounded-r","rounded-b","rounded-l","rounded-ss","rounded-se","rounded-ee","rounded-es","rounded-tl","rounded-tr","rounded-br","rounded-bl"],"rounded-s":["rounded-ss","rounded-es"],"rounded-e":["rounded-se","rounded-ee"],"rounded-t":["rounded-tl","rounded-tr"],"rounded-r":["rounded-tr","rounded-br"],"rounded-b":["rounded-br","rounded-bl"],"rounded-l":["rounded-tl","rounded-bl"],"border-spacing":["border-spacing-x","border-spacing-y"],"border-w":["border-w-s","border-w-e","border-w-t","border-w-r","border-w-b","border-w-l"],"border-w-x":["border-w-r","border-w-l"],"border-w-y":["border-w-t","border-w-b"],"border-color":["border-color-t","border-color-r","border-color-b","border-color-l"],"border-color-x":["border-color-r","border-color-l"],"border-color-y":["border-color-t","border-color-b"],"scroll-m":["scroll-mx","scroll-my","scroll-ms","scroll-me","scroll-mt","scroll-mr","scroll-mb","scroll-ml"],"scroll-mx":["scroll-mr","scroll-ml"],"scroll-my":["scroll-mt","scroll-mb"],"scroll-p":["scroll-px","scroll-py","scroll-ps","scroll-pe","scroll-pt","scroll-pr","scroll-pb","scroll-pl"],"scroll-px":["scroll-pr","scroll-pl"],"scroll-py":["scroll-pt","scroll-pb"],touch:["touch-x","touch-y","touch-pz"],"touch-x":["touch"],"touch-y":["touch"],"touch-pz":["touch"]},conflictingClassGroupModifiers:{"font-size":["leading"]}}}const B$=w$($$);function Ie(...e){return B$(wo(e))}const z$=jh("inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",warning:"bg-amber-600 shadow-sm hover:bg-amber-600/90 data-active:bg-amber-600/90 text-foreground",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),se=y.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...s},o)=>{const l=r?No:"button";return i.jsx(l,{className:Ie(z$({variant:t,size:n,className:e})),ref:o,...s})});se.displayName="Button";function Vb(){const{t:e}=Ve(),t=dr(jn.API_URL),{data:n}=n$({url:t}),r=y.useMemo(()=>n?.clientName,[n]),s=y.useMemo(()=>n?.version,[n]),o=[{name:"Discord",url:"https://evolution-api.com/discord"},{name:"Postman",url:"https://evolution-api.com/postman"},{name:"GitHub",url:"https://github.com/EvolutionAPI/evolution-api"},{name:"Docs",url:"https://doc.evolution-api.com"}];return i.jsxs("footer",{className:"flex w-full flex-col items-center justify-between p-6 text-xs text-secondary-foreground sm:flex-row",children:[i.jsxs("div",{className:"flex items-center space-x-3 divide-x",children:[r&&r!==""&&i.jsxs("span",{children:[e("footer.clientName"),": ",i.jsx("strong",{children:r})]}),s&&s!==""&&i.jsxs("span",{className:"pl-3",children:[e("footer.version"),": ",i.jsx("strong",{children:s})]})]}),i.jsx("div",{className:"flex gap-2",children:o.map(l=>i.jsx(se,{variant:"link",asChild:!0,size:"sm",className:"text-xs",children:i.jsx("a",{href:l.url,target:"_blank",rel:"noopener noreferrer",children:l.name})},l.url))})]})}/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const U$=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),dT=(...e)=>e.filter((t,n,r)=>!!t&&r.indexOf(t)===n).join(" ");/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */var V$={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const H$=y.forwardRef(({color:e="currentColor",size:t=24,strokeWidth:n=2,absoluteStrokeWidth:r,className:s="",children:o,iconNode:l,...u},d)=>y.createElement("svg",{ref:d,...V$,width:t,height:t,stroke:e,strokeWidth:r?Number(n)*24/Number(t):n,className:dT("lucide",s),...u},[...l.map(([f,h])=>y.createElement(f,h)),...Array.isArray(o)?o:[o]]));/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Qe=(e,t)=>{const n=y.forwardRef(({className:r,...s},o)=>y.createElement(H$,{ref:o,iconNode:t,className:dT(`lucide-${U$(e)}`,r),...s}));return n.displayName=`${e}`,n};/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const HC=Qe("Apple",[["path",{d:"M12 20.94c1.5 0 2.75 1.06 4 1.06 3 0 6-8 6-12.22A4.91 4.91 0 0 0 17 5c-2.22 0-4 1.44-5 2-1-.56-2.78-2-5-2a4.9 4.9 0 0 0-5 4.78C2 14 5 22 8 22c1.25 0 2.5-1.06 4-1.06Z",key:"3s7exb"}],["path",{d:"M10 2c1 .5 2 2 2 5",key:"fcco2y"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Th=Qe("ArrowRight",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const q$=Qe("ArrowUpDown",[["path",{d:"m21 16-4 4-4-4",key:"f6ql7i"}],["path",{d:"M17 20V4",key:"1ejh1v"}],["path",{d:"m3 8 4-4 4 4",key:"11wl7u"}],["path",{d:"M7 4v16",key:"1glfcx"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const K$=Qe("Car",[["path",{d:"M19 17h2c.6 0 1-.4 1-1v-3c0-.9-.7-1.7-1.5-1.9C18.7 10.6 16 10 16 10s-1.3-1.4-2.2-2.3c-.5-.4-1.1-.7-1.8-.7H5c-.6 0-1.1.4-1.4.9l-1.4 2.9A3.7 3.7 0 0 0 2 12v4c0 .6.4 1 1 1h2",key:"5owen"}],["circle",{cx:"7",cy:"17",r:"2",key:"u2ysq9"}],["path",{d:"M9 17h6",key:"r8uit2"}],["circle",{cx:"17",cy:"17",r:"2",key:"axvx0g"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const fT=Qe("Check",[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Nh=Qe("ChevronDown",[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const W$=Qe("ChevronRight",[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const G$=Qe("ChevronUp",[["path",{d:"m18 15-6-6-6 6",key:"153udz"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const J$=Qe("ChevronsUpDown",[["path",{d:"m7 15 5 5 5-5",key:"1hf1tw"}],["path",{d:"m7 9 5-5 5 5",key:"sgt6xg"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Q$=Qe("CircleHelp",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3",key:"1u773s"}],["path",{d:"M12 17h.01",key:"p32p05"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Oi=Qe("CircleStop",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["rect",{width:"6",height:"6",x:"9",y:"9",key:"1wrtvo"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const pT=Qe("CircleUser",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["circle",{cx:"12",cy:"10",r:"3",key:"ilqhr7"}],["path",{d:"M7 20.662V19a2 2 0 0 1 2-2h6a2 2 0 0 1 2 2v1.662",key:"154egf"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Z$=Qe("Circle",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Y$=Qe("Club",[["path",{d:"M17.28 9.05a5.5 5.5 0 1 0-10.56 0A5.5 5.5 0 1 0 12 17.66a5.5 5.5 0 1 0 5.28-8.6Z",key:"27yuqz"}],["path",{d:"M12 17.66L12 22",key:"ogfahf"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Oo=Qe("Cog",[["path",{d:"M12 20a8 8 0 1 0 0-16 8 8 0 0 0 0 16Z",key:"sobvz5"}],["path",{d:"M12 14a2 2 0 1 0 0-4 2 2 0 0 0 0 4Z",key:"11i496"}],["path",{d:"M12 2v2",key:"tus03m"}],["path",{d:"M12 22v-2",key:"1osdcq"}],["path",{d:"m17 20.66-1-1.73",key:"eq3orb"}],["path",{d:"M11 10.27 7 3.34",key:"16pf9h"}],["path",{d:"m20.66 17-1.73-1",key:"sg0v6f"}],["path",{d:"m3.34 7 1.73 1",key:"1ulond"}],["path",{d:"M14 12h8",key:"4f43i9"}],["path",{d:"M2 12h2",key:"1t8f8n"}],["path",{d:"m20.66 7-1.73 1",key:"1ow05n"}],["path",{d:"m3.34 17 1.73-1",key:"nuk764"}],["path",{d:"m17 3.34-1 1.73",key:"2wel8s"}],["path",{d:"m11 13.73-4 6.93",key:"794ttg"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const X$=Qe("Copy",[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Ii=Qe("Delete",[["path",{d:"M10 5a2 2 0 0 0-1.344.519l-6.328 5.74a1 1 0 0 0 0 1.481l6.328 5.741A2 2 0 0 0 10 19h10a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2z",key:"1yo7s0"}],["path",{d:"m12 9 6 6",key:"anjzzh"}],["path",{d:"m18 9-6 6",key:"1fp51s"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const eB=Qe("DoorOpen",[["path",{d:"M13 4h3a2 2 0 0 1 2 2v14",key:"hrm0s9"}],["path",{d:"M2 20h3",key:"1gaodv"}],["path",{d:"M13 20h9",key:"s90cdi"}],["path",{d:"M10 12v.01",key:"vx6srw"}],["path",{d:"M13 4.562v16.157a1 1 0 0 1-1.242.97L5 20V5.562a2 2 0 0 1 1.515-1.94l4-1A2 2 0 0 1 13 4.561Z",key:"199qr4"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Pa=Qe("Ellipsis",[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"19",cy:"12",r:"1",key:"1wjl8i"}],["circle",{cx:"5",cy:"12",r:"1",key:"1pcz8c"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const tB=Qe("EyeOff",[["path",{d:"M9.88 9.88a3 3 0 1 0 4.24 4.24",key:"1jxqfv"}],["path",{d:"M10.73 5.08A10.43 10.43 0 0 1 12 5c7 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68",key:"9wicm4"}],["path",{d:"M6.61 6.61A13.526 13.526 0 0 0 2 12s3 7 10 7a9.74 9.74 0 0 0 5.39-1.61",key:"1jreej"}],["line",{x1:"2",x2:"22",y1:"2",y2:"22",key:"a6p6uj"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const nB=Qe("Eye",[["path",{d:"M2 12s3-7 10-7 10 7 10 7-3 7-10 7-10-7-10-7Z",key:"rwhkz3"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const rB=Qe("FilePlus",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M9 15h6",key:"cctwl0"}],["path",{d:"M12 18v-6",key:"17g6i2"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const sB=Qe("FileQuestion",[["path",{d:"M12 17h.01",key:"p32p05"}],["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7z",key:"1mlx9k"}],["path",{d:"M9.1 9a3 3 0 0 1 5.82 1c0 2-3 3-3 3",key:"mhlwft"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Hb=Qe("File",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const oB=Qe("Flag",[["path",{d:"M4 15s1-1 4-1 5 2 8 2 4-1 4-1V3s-1 1-4 1-5-2-8-2-4 1-4 1z",key:"i9b6wo"}],["line",{x1:"4",x2:"4",y1:"22",y2:"15",key:"1cm3nv"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const aB=Qe("Github",[["path",{d:"M15 22v-4a4.8 4.8 0 0 0-1-3.5c3 0 6-2 6-5.5.08-1.25-.27-2.48-1-3.5.28-1.15.28-2.35 0-3.5 0 0-1 0-3 1.5-2.64-.5-5.36-.5-8 0C6 2 5 2 5 2c-.3 1.15-.3 2.35 0 3.5A5.403 5.403 0 0 0 4 9c0 3.5 3 5.5 6 5.5-.39.49-.68 1.05-.85 1.65-.17.6-.22 1.23-.15 1.85v4",key:"tonef"}],["path",{d:"M9 18c-4.51 2-5-2-7-2",key:"9comsn"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const iB=Qe("Globe",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20",key:"13o1zl"}],["path",{d:"M2 12h20",key:"9i4pu4"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const lB=Qe("GripVertical",[["circle",{cx:"9",cy:"12",r:"1",key:"1vctgf"}],["circle",{cx:"9",cy:"5",r:"1",key:"hp0tcf"}],["circle",{cx:"9",cy:"19",r:"1",key:"fkjjf6"}],["circle",{cx:"15",cy:"12",r:"1",key:"1tmaij"}],["circle",{cx:"15",cy:"5",r:"1",key:"19l28e"}],["circle",{cx:"15",cy:"19",r:"1",key:"f4zoj3"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const cB=Qe("Image",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}],["circle",{cx:"9",cy:"9",r:"2",key:"af1f0g"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21",key:"1xmnt7"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const uB=Qe("Images",[["path",{d:"M18 22H4a2 2 0 0 1-2-2V6",key:"pblm9e"}],["path",{d:"m22 13-1.296-1.296a2.41 2.41 0 0 0-3.408 0L11 18",key:"nf6bnh"}],["circle",{cx:"12",cy:"8",r:"2",key:"1822b1"}],["rect",{width:"16",height:"16",x:"6",y:"2",rx:"2",key:"12espp"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const dB=Qe("IterationCcw",[["path",{d:"M20 10c0-4.4-3.6-8-8-8s-8 3.6-8 8 3.6 8 8 8h8",key:"4znkd0"}],["polyline",{points:"16 14 20 18 16 22",key:"11njsm"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const fB=Qe("Languages",[["path",{d:"m5 8 6 6",key:"1wu5hv"}],["path",{d:"m4 14 6-6 2-3",key:"1k1g8d"}],["path",{d:"M2 5h12",key:"or177f"}],["path",{d:"M7 2h1",key:"1t2jsx"}],["path",{d:"m22 22-5-10-5 10",key:"don7ne"}],["path",{d:"M14 18h6",key:"1m8k6r"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const pB=Qe("LayoutDashboard",[["rect",{width:"7",height:"9",x:"3",y:"3",rx:"1",key:"10lvy0"}],["rect",{width:"7",height:"5",x:"14",y:"3",rx:"1",key:"16une8"}],["rect",{width:"7",height:"9",x:"14",y:"12",rx:"1",key:"1hutg5"}],["rect",{width:"7",height:"5",x:"3",y:"16",rx:"1",key:"ldoo1y"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const hB=Qe("LifeBuoy",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m4.93 4.93 4.24 4.24",key:"1ymg45"}],["path",{d:"m14.83 9.17 4.24-4.24",key:"1cb5xl"}],["path",{d:"m14.83 14.83 4.24 4.24",key:"q42g0n"}],["path",{d:"m9.17 14.83-4.24 4.24",key:"bqpfvv"}],["circle",{cx:"12",cy:"12",r:"4",key:"4exip2"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const gB=Qe("Lightbulb",[["path",{d:"M15 14c.2-1 .7-1.7 1.5-2.5 1-.9 1.5-2.2 1.5-3.5A6 6 0 0 0 6 8c0 1 .2 2.2 1.5 3.5.7.7 1.3 1.5 1.5 2.5",key:"1gvzjb"}],["path",{d:"M9 18h6",key:"x1upvd"}],["path",{d:"M10 22h4",key:"ceow96"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Ai=Qe("ListCollapse",[["path",{d:"m3 10 2.5-2.5L3 5",key:"i6eama"}],["path",{d:"m3 19 2.5-2.5L3 14",key:"w2gmor"}],["path",{d:"M10 6h11",key:"c7qv1k"}],["path",{d:"M10 12h11",key:"6m4ad9"}],["path",{d:"M10 18h11",key:"11hvi2"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const mB=Qe("Lock",[["rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2",key:"1w4ew1"}],["path",{d:"M7 11V7a5 5 0 0 1 10 0v4",key:"fwvmzm"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const vB=Qe("Mail",[["rect",{width:"20",height:"16",x:"2",y:"4",rx:"2",key:"18n3k1"}],["path",{d:"m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7",key:"1ocrg3"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const yB=Qe("MapPin",[["path",{d:"M20 10c0 6-8 12-8 12s-8-6-8-12a8 8 0 0 1 16 0Z",key:"2oe9fu"}],["circle",{cx:"12",cy:"10",r:"3",key:"ilqhr7"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Bl=Qe("MessageCircle",[["path",{d:"M7.9 20A9 9 0 1 0 4 16.1L2 22Z",key:"vv11sd"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const hT=Qe("Mic",[["path",{d:"M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3Z",key:"131961"}],["path",{d:"M19 10v2a7 7 0 0 1-14 0v-2",key:"1vc78b"}],["line",{x1:"12",x2:"12",y1:"19",y2:"22",key:"x3vr5v"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const bB=Qe("Moon",[["path",{d:"M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z",key:"a7tn18"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Di=Qe("Pause",[["rect",{x:"14",y:"4",width:"4",height:"16",rx:"1",key:"zuxfzm"}],["rect",{x:"6",y:"4",width:"4",height:"16",rx:"1",key:"1okwgv"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Fi=Qe("Play",[["polygon",{points:"6 3 20 12 6 21 6 3",key:"1oa8hb"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const cs=Qe("Plus",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Ip=Qe("RefreshCw",[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Li=Qe("RotateCcw",[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const xB=Qe("Shield",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const gT=Qe("Smile",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M8 14s1.5 2 4 2 4-2 4-2",key:"1y1vjs"}],["line",{x1:"9",x2:"9.01",y1:"9",y2:"9",key:"yxxnd0"}],["line",{x1:"15",x2:"15.01",y1:"9",y2:"9",key:"1p4y9e"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const wB=Qe("Sparkle",[["path",{d:"M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z",key:"4pj2yx"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const SB=Qe("Square",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const CB=Qe("Sticker",[["path",{d:"M15.5 3H5a2 2 0 0 0-2 2v14c0 1.1.9 2 2 2h14a2 2 0 0 0 2-2V8.5L15.5 3Z",key:"1wis1t"}],["path",{d:"M14 3v4a2 2 0 0 0 2 2h4",key:"36rjfy"}],["path",{d:"M8 13h.01",key:"1sbv64"}],["path",{d:"M16 13h.01",key:"wip0gl"}],["path",{d:"M10 16s.8 1 2 1c1.3 0 2-1 2-1",key:"1vvgv3"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const EB=Qe("Sun",[["circle",{cx:"12",cy:"12",r:"4",key:"4exip2"}],["path",{d:"M12 2v2",key:"tus03m"}],["path",{d:"M12 20v2",key:"1lh1kg"}],["path",{d:"m4.93 4.93 1.41 1.41",key:"149t6j"}],["path",{d:"m17.66 17.66 1.41 1.41",key:"ptbguv"}],["path",{d:"M2 12h2",key:"1t8f8n"}],["path",{d:"M20 12h2",key:"1q8mjw"}],["path",{d:"m6.34 17.66-1.41 1.41",key:"1m8zz5"}],["path",{d:"m19.07 4.93-1.41 1.41",key:"1shlcs"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const kB=Qe("Trash",[["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6",key:"4alrt4"}],["path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2",key:"v07s0e"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Ap=Qe("User",[["path",{d:"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2",key:"975kel"}],["circle",{cx:"12",cy:"7",r:"4",key:"17ys0d"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const jB=Qe("UsersRound",[["path",{d:"M18 21a8 8 0 0 0-16 0",key:"3ypg7q"}],["circle",{cx:"10",cy:"8",r:"5",key:"o932ke"}],["path",{d:"M22 20c0-3.37-2-6.5-4-8a5 5 0 0 0-.45-8.3",key:"10s06x"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const TB=Qe("Video",[["path",{d:"m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.752-.432L16 10.5",key:"ftymec"}],["rect",{x:"2",y:"6",width:"14",height:"12",rx:"2",key:"158x01"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const qb=Qe("X",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]);/** * @license lucide-react v0.408.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const mT=Qe("Zap",[["path",{d:"M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z",key:"1xq2db"}]]),Ee=sn.create({timeout:3e4});Ee.interceptors.request.use(async e=>{const t=dr(jn.API_URL);if(t&&(e.baseURL=t.toString()),!e.headers.apiKey||e.headers.apiKey===""){const n=dr(jn.INSTANCE_TOKEN);n&&(e.headers.apikey=`${n}`)}return e},e=>Promise.reject(e));const bd=sn.create({timeout:3e4});bd.interceptors.request.use(async e=>{const t=dr(jn.API_URL);if(t&&(e.baseURL=t.toString()),!e.headers.apiKey||e.headers.apiKey===""){const n=dr(jn.TOKEN);n&&(e.headers.apikey=`${n}`)}return e},e=>Promise.reject(e));const NB=e=>["instance","fetchInstance",JSON.stringify(e)],MB=async({instanceId:e})=>{const t=await bd.get("/instance/fetchInstances",{params:{instanceId:e}});return Array.isArray(t.data)?t.data[0]:t.data},vT=e=>{const{instanceId:t,...n}=e;return mt({...n,queryKey:NB({instanceId:t}),queryFn:()=>MB({instanceId:t}),enabled:!!t})};function Ue(e,t,{checkForDefaultPrevented:n=!0}={}){return function(s){if(e?.(s),n===!1||!s.defaultPrevented)return t?.(s)}}function _B(e,t){const n=y.createContext(t);function r(o){const{children:l,...u}=o,d=y.useMemo(()=>u,Object.values(u));return i.jsx(n.Provider,{value:d,children:l})}function s(o){const l=y.useContext(n);if(l)return l;if(t!==void 0)return t;throw new Error(`\`${o}\` must be used within \`${e}\``)}return r.displayName=e+"Provider",[r,s]}function us(e,t=[]){let n=[];function r(o,l){const u=y.createContext(l),d=n.length;n=[...n,l];function f(m){const{scope:g,children:x,...b}=m,w=g?.[e][d]||u,C=y.useMemo(()=>b,Object.values(b));return i.jsx(w.Provider,{value:C,children:x})}function h(m,g){const x=g?.[e][d]||u,b=y.useContext(x);if(b)return b;if(l!==void 0)return l;throw new Error(`\`${m}\` must be used within \`${o}\``)}return f.displayName=o+"Provider",[f,h]}const s=()=>{const o=n.map(l=>y.createContext(l));return function(u){const d=u?.[e]||o;return y.useMemo(()=>({[`__scope${e}`]:{...u,[e]:d}}),[u,d])}};return s.scopeName=e,[r,RB(s,...t)]}function RB(...e){const t=e[0];if(e.length===1)return t;const n=()=>{const r=e.map(s=>({useScope:s(),scopeName:s.scopeName}));return function(o){const l=r.reduce((u,{useScope:d,scopeName:f})=>{const m=d(o)[`__scope${f}`];return{...u,...m}},{});return y.useMemo(()=>({[`__scope${t.scopeName}`]:l}),[l])}};return n.scopeName=t.scopeName,n}function Rn(e){const t=y.useRef(e);return y.useEffect(()=>{t.current=e}),y.useMemo(()=>(...n)=>t.current?.(...n),[])}function ya({prop:e,defaultProp:t,onChange:n=()=>{}}){const[r,s]=PB({defaultProp:t,onChange:n}),o=e!==void 0,l=o?e:r,u=Rn(n),d=y.useCallback(f=>{if(o){const m=typeof f=="function"?f(e):f;m!==e&&u(m)}else s(f)},[o,e,s,u]);return[l,d]}function PB({defaultProp:e,onChange:t}){const n=y.useState(e),[r]=n,s=y.useRef(r),o=Rn(t);return y.useEffect(()=>{s.current!==r&&(o(r),s.current=r)},[r,s,o]),n}var OB=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","span","svg","ul"],rt=OB.reduce((e,t)=>{const n=y.forwardRef((r,s)=>{const{asChild:o,...l}=r,u=o?No:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),i.jsx(u,{...l,ref:s})});return n.displayName=`Primitive.${t}`,{...e,[t]:n}},{});function yT(e,t){e&&Ma.flushSync(()=>e.dispatchEvent(t))}function Kb(e){const t=e+"CollectionProvider",[n,r]=us(t),[s,o]=n(t,{collectionRef:{current:null},itemMap:new Map}),l=x=>{const{scope:b,children:w}=x,C=qe.useRef(null),k=qe.useRef(new Map).current;return i.jsx(s,{scope:b,itemMap:k,collectionRef:C,children:w})};l.displayName=t;const u=e+"CollectionSlot",d=qe.forwardRef((x,b)=>{const{scope:w,children:C}=x,k=o(u,w),j=Rt(b,k.collectionRef);return i.jsx(No,{ref:j,children:C})});d.displayName=u;const f=e+"CollectionItemSlot",h="data-radix-collection-item",m=qe.forwardRef((x,b)=>{const{scope:w,children:C,...k}=x,j=qe.useRef(null),M=Rt(b,j),_=o(f,w);return qe.useEffect(()=>(_.itemMap.set(j,{ref:j,...k}),()=>void _.itemMap.delete(j))),i.jsx(No,{[h]:"",ref:M,children:C})});m.displayName=f;function g(x){const b=o(e+"CollectionConsumer",x);return qe.useCallback(()=>{const C=b.collectionRef.current;if(!C)return[];const k=Array.from(C.querySelectorAll(`[${h}]`));return Array.from(b.itemMap.values()).sort((_,R)=>k.indexOf(_.ref.current)-k.indexOf(R.ref.current))},[b.collectionRef,b.itemMap])}return[{Provider:l,Slot:d,ItemSlot:m},g,r]}var IB=y.createContext(void 0);function xd(e){const t=y.useContext(IB);return e||t||"ltr"}function AB(e,t=globalThis?.document){const n=Rn(e);y.useEffect(()=>{const r=s=>{s.key==="Escape"&&n(s)};return t.addEventListener("keydown",r,{capture:!0}),()=>t.removeEventListener("keydown",r,{capture:!0})},[n,t])}var DB="DismissableLayer",By="dismissableLayer.update",FB="dismissableLayer.pointerDownOutside",LB="dismissableLayer.focusOutside",qC,bT=y.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),Mh=y.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:s,onFocusOutside:o,onInteractOutside:l,onDismiss:u,...d}=e,f=y.useContext(bT),[h,m]=y.useState(null),g=h?.ownerDocument??globalThis?.document,[,x]=y.useState({}),b=Rt(t,O=>m(O)),w=Array.from(f.layers),[C]=[...f.layersWithOutsidePointerEventsDisabled].slice(-1),k=w.indexOf(C),j=h?w.indexOf(h):-1,M=f.layersWithOutsidePointerEventsDisabled.size>0,_=j>=k,R=zB(O=>{const D=O.target,z=[...f.branches].some(Q=>Q.contains(D));!_||z||(s?.(O),l?.(O),O.defaultPrevented||u?.())},g),N=UB(O=>{const D=O.target;[...f.branches].some(Q=>Q.contains(D))||(o?.(O),l?.(O),O.defaultPrevented||u?.())},g);return AB(O=>{j===f.layers.size-1&&(r?.(O),!O.defaultPrevented&&u&&(O.preventDefault(),u()))},g),y.useEffect(()=>{if(h)return n&&(f.layersWithOutsidePointerEventsDisabled.size===0&&(qC=g.body.style.pointerEvents,g.body.style.pointerEvents="none"),f.layersWithOutsidePointerEventsDisabled.add(h)),f.layers.add(h),KC(),()=>{n&&f.layersWithOutsidePointerEventsDisabled.size===1&&(g.body.style.pointerEvents=qC)}},[h,g,n,f]),y.useEffect(()=>()=>{h&&(f.layers.delete(h),f.layersWithOutsidePointerEventsDisabled.delete(h),KC())},[h,f]),y.useEffect(()=>{const O=()=>x({});return document.addEventListener(By,O),()=>document.removeEventListener(By,O)},[]),i.jsx(rt.div,{...d,ref:b,style:{pointerEvents:M?_?"auto":"none":void 0,...e.style},onFocusCapture:Ue(e.onFocusCapture,N.onFocusCapture),onBlurCapture:Ue(e.onBlurCapture,N.onBlurCapture),onPointerDownCapture:Ue(e.onPointerDownCapture,R.onPointerDownCapture)})});Mh.displayName=DB;var $B="DismissableLayerBranch",BB=y.forwardRef((e,t)=>{const n=y.useContext(bT),r=y.useRef(null),s=Rt(t,r);return y.useEffect(()=>{const o=r.current;if(o)return n.branches.add(o),()=>{n.branches.delete(o)}},[n.branches]),i.jsx(rt.div,{...e,ref:s})});BB.displayName=$B;function zB(e,t=globalThis?.document){const n=Rn(e),r=y.useRef(!1),s=y.useRef(()=>{});return y.useEffect(()=>{const o=u=>{if(u.target&&!r.current){let d=function(){xT(FB,n,f,{discrete:!0})};const f={originalEvent:u};u.pointerType==="touch"?(t.removeEventListener("click",s.current),s.current=d,t.addEventListener("click",s.current,{once:!0})):d()}else t.removeEventListener("click",s.current);r.current=!1},l=window.setTimeout(()=>{t.addEventListener("pointerdown",o)},0);return()=>{window.clearTimeout(l),t.removeEventListener("pointerdown",o),t.removeEventListener("click",s.current)}},[t,n]),{onPointerDownCapture:()=>r.current=!0}}function UB(e,t=globalThis?.document){const n=Rn(e),r=y.useRef(!1);return y.useEffect(()=>{const s=o=>{o.target&&!r.current&&xT(LB,n,{originalEvent:o},{discrete:!1})};return t.addEventListener("focusin",s),()=>t.removeEventListener("focusin",s)},[t,n]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function KC(){const e=new CustomEvent(By);document.dispatchEvent(e)}function xT(e,t,n,{discrete:r}){const s=n.originalEvent.target,o=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:n});t&&s.addEventListener(e,t,{once:!0}),r?yT(s,o):s.dispatchEvent(o)}var xv=0;function Wb(){y.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??WC()),document.body.insertAdjacentElement("beforeend",e[1]??WC()),xv++,()=>{xv===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),xv--}},[])}function WC(){const e=document.createElement("span");return e.setAttribute("data-radix-focus-guard",""),e.tabIndex=0,e.style.cssText="outline: none; opacity: 0; position: fixed; pointer-events: none",e}var wv="focusScope.autoFocusOnMount",Sv="focusScope.autoFocusOnUnmount",GC={bubbles:!1,cancelable:!0},VB="FocusScope",_h=y.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:s,onUnmountAutoFocus:o,...l}=e,[u,d]=y.useState(null),f=Rn(s),h=Rn(o),m=y.useRef(null),g=Rt(t,w=>d(w)),x=y.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;y.useEffect(()=>{if(r){let w=function(M){if(x.paused||!u)return;const _=M.target;u.contains(_)?m.current=_:fa(m.current,{select:!0})},C=function(M){if(x.paused||!u)return;const _=M.relatedTarget;_!==null&&(u.contains(_)||fa(m.current,{select:!0}))},k=function(M){if(document.activeElement===document.body)for(const R of M)R.removedNodes.length>0&&fa(u)};document.addEventListener("focusin",w),document.addEventListener("focusout",C);const j=new MutationObserver(k);return u&&j.observe(u,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",w),document.removeEventListener("focusout",C),j.disconnect()}}},[r,u,x.paused]),y.useEffect(()=>{if(u){QC.add(x);const w=document.activeElement;if(!u.contains(w)){const k=new CustomEvent(wv,GC);u.addEventListener(wv,f),u.dispatchEvent(k),k.defaultPrevented||(HB(JB(wT(u)),{select:!0}),document.activeElement===w&&fa(u))}return()=>{u.removeEventListener(wv,f),setTimeout(()=>{const k=new CustomEvent(Sv,GC);u.addEventListener(Sv,h),u.dispatchEvent(k),k.defaultPrevented||fa(w??document.body,{select:!0}),u.removeEventListener(Sv,h),QC.remove(x)},0)}}},[u,f,h,x]);const b=y.useCallback(w=>{if(!n&&!r||x.paused)return;const C=w.key==="Tab"&&!w.altKey&&!w.ctrlKey&&!w.metaKey,k=document.activeElement;if(C&&k){const j=w.currentTarget,[M,_]=qB(j);M&&_?!w.shiftKey&&k===_?(w.preventDefault(),n&&fa(M,{select:!0})):w.shiftKey&&k===M&&(w.preventDefault(),n&&fa(_,{select:!0})):k===j&&w.preventDefault()}},[n,r,x.paused]);return i.jsx(rt.div,{tabIndex:-1,...l,ref:g,onKeyDown:b})});_h.displayName=VB;function HB(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(fa(r,{select:t}),document.activeElement!==n)return}function qB(e){const t=wT(e),n=JC(t,e),r=JC(t.reverse(),e);return[n,r]}function wT(e){const t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const s=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||s?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)t.push(n.currentNode);return t}function JC(e,t){for(const n of e)if(!KB(n,{upTo:t}))return n}function KB(e,{upTo:t}){if(getComputedStyle(e).visibility==="hidden")return!0;for(;e;){if(t!==void 0&&e===t)return!1;if(getComputedStyle(e).display==="none")return!0;e=e.parentElement}return!1}function WB(e){return e instanceof HTMLInputElement&&"select"in e}function fa(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&WB(e)&&t&&e.select()}}var QC=GB();function GB(){let e=[];return{add(t){const n=e[0];t!==n&&n?.pause(),e=ZC(e,t),e.unshift(t)},remove(t){e=ZC(e,t),e[0]?.resume()}}}function ZC(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function JB(e){return e.filter(t=>t.tagName!=="A")}var Ln=globalThis?.document?y.useLayoutEffect:()=>{},QB=Yl.useId||(()=>{}),ZB=0;function Es(e){const[t,n]=y.useState(QB());return Ln(()=>{n(r=>r??String(ZB++))},[e]),t?`radix-${t}`:""}const YB=["top","right","bottom","left"],Hs=Math.min,zr=Math.max,Dp=Math.round,Uf=Math.floor,ba=e=>({x:e,y:e}),XB={left:"right",right:"left",bottom:"top",top:"bottom"},e3={start:"end",end:"start"};function zy(e,t,n){return zr(e,Hs(t,n))}function Mo(e,t){return typeof e=="function"?e(t):e}function _o(e){return e.split("-")[0]}function oc(e){return e.split("-")[1]}function Gb(e){return e==="x"?"y":"x"}function Jb(e){return e==="y"?"height":"width"}function xa(e){return["top","bottom"].includes(_o(e))?"y":"x"}function Qb(e){return Gb(xa(e))}function t3(e,t,n){n===void 0&&(n=!1);const r=oc(e),s=Qb(e),o=Jb(s);let l=s==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[o]>t.floating[o]&&(l=Fp(l)),[l,Fp(l)]}function n3(e){const t=Fp(e);return[Uy(e),t,Uy(t)]}function Uy(e){return e.replace(/start|end/g,t=>e3[t])}function r3(e,t,n){const r=["left","right"],s=["right","left"],o=["top","bottom"],l=["bottom","top"];switch(e){case"top":case"bottom":return n?t?s:r:t?r:s;case"left":case"right":return t?o:l;default:return[]}}function s3(e,t,n,r){const s=oc(e);let o=r3(_o(e),n==="start",r);return s&&(o=o.map(l=>l+"-"+s),t&&(o=o.concat(o.map(Uy)))),o}function Fp(e){return e.replace(/left|right|bottom|top/g,t=>XB[t])}function o3(e){return{top:0,right:0,bottom:0,left:0,...e}}function ST(e){return typeof e!="number"?o3(e):{top:e,right:e,bottom:e,left:e}}function Lp(e){const{x:t,y:n,width:r,height:s}=e;return{width:r,height:s,top:n,left:t,right:t+r,bottom:n+s,x:t,y:n}}function YC(e,t,n){let{reference:r,floating:s}=e;const o=xa(t),l=Qb(t),u=Jb(l),d=_o(t),f=o==="y",h=r.x+r.width/2-s.width/2,m=r.y+r.height/2-s.height/2,g=r[u]/2-s[u]/2;let x;switch(d){case"top":x={x:h,y:r.y-s.height};break;case"bottom":x={x:h,y:r.y+r.height};break;case"right":x={x:r.x+r.width,y:m};break;case"left":x={x:r.x-s.width,y:m};break;default:x={x:r.x,y:r.y}}switch(oc(t)){case"start":x[l]-=g*(n&&f?-1:1);break;case"end":x[l]+=g*(n&&f?-1:1);break}return x}const a3=async(e,t,n)=>{const{placement:r="bottom",strategy:s="absolute",middleware:o=[],platform:l}=n,u=o.filter(Boolean),d=await(l.isRTL==null?void 0:l.isRTL(t));let f=await l.getElementRects({reference:e,floating:t,strategy:s}),{x:h,y:m}=YC(f,r,d),g=r,x={},b=0;for(let w=0;w({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:s,rects:o,platform:l,elements:u,middlewareData:d}=t,{element:f,padding:h=0}=Mo(e,t)||{};if(f==null)return{};const m=ST(h),g={x:n,y:r},x=Qb(s),b=Jb(x),w=await l.getDimensions(f),C=x==="y",k=C?"top":"left",j=C?"bottom":"right",M=C?"clientHeight":"clientWidth",_=o.reference[b]+o.reference[x]-g[x]-o.floating[b],R=g[x]-o.reference[x],N=await(l.getOffsetParent==null?void 0:l.getOffsetParent(f));let O=N?N[M]:0;(!O||!await(l.isElement==null?void 0:l.isElement(N)))&&(O=u.floating[M]||o.floating[b]);const D=_/2-R/2,z=O/2-w[b]/2-1,Q=Hs(m[k],z),pe=Hs(m[j],z),V=Q,G=O-w[b]-pe,W=O/2-w[b]/2+D,ie=zy(V,W,G),re=!d.arrow&&oc(s)!=null&&W!==ie&&o.reference[b]/2-(WW<=0)){var pe,V;const W=(((pe=o.flip)==null?void 0:pe.index)||0)+1,ie=O[W];if(ie)return{data:{index:W,overflows:Q},reset:{placement:ie}};let re=(V=Q.filter(Y=>Y.overflows[0]<=0).sort((Y,H)=>Y.overflows[1]-H.overflows[1])[0])==null?void 0:V.placement;if(!re)switch(x){case"bestFit":{var G;const Y=(G=Q.filter(H=>{if(N){const q=xa(H.placement);return q===j||q==="y"}return!0}).map(H=>[H.placement,H.overflows.filter(q=>q>0).reduce((q,he)=>q+he,0)]).sort((H,q)=>H[1]-q[1])[0])==null?void 0:G[0];Y&&(re=Y);break}case"initialPlacement":re=u;break}if(s!==re)return{reset:{placement:re}}}return{}}}};function XC(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function e1(e){return YB.some(t=>e[t]>=0)}const c3=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n}=t,{strategy:r="referenceHidden",...s}=Mo(e,t);switch(r){case"referenceHidden":{const o=await Bu(t,{...s,elementContext:"reference"}),l=XC(o,n.reference);return{data:{referenceHiddenOffsets:l,referenceHidden:e1(l)}}}case"escaped":{const o=await Bu(t,{...s,altBoundary:!0}),l=XC(o,n.floating);return{data:{escapedOffsets:l,escaped:e1(l)}}}default:return{}}}}};async function u3(e,t){const{placement:n,platform:r,elements:s}=e,o=await(r.isRTL==null?void 0:r.isRTL(s.floating)),l=_o(n),u=oc(n),d=xa(n)==="y",f=["left","top"].includes(l)?-1:1,h=o&&d?-1:1,m=Mo(t,e);let{mainAxis:g,crossAxis:x,alignmentAxis:b}=typeof m=="number"?{mainAxis:m,crossAxis:0,alignmentAxis:null}:{mainAxis:0,crossAxis:0,alignmentAxis:null,...m};return u&&typeof b=="number"&&(x=u==="end"?b*-1:b),d?{x:x*h,y:g*f}:{x:g*f,y:x*h}}const d3=function(e){return e===void 0&&(e=0),{name:"offset",options:e,async fn(t){var n,r;const{x:s,y:o,placement:l,middlewareData:u}=t,d=await u3(t,e);return l===((n=u.offset)==null?void 0:n.placement)&&(r=u.arrow)!=null&&r.alignmentOffset?{}:{x:s+d.x,y:o+d.y,data:{...d,placement:l}}}}},f3=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:n,y:r,placement:s}=t,{mainAxis:o=!0,crossAxis:l=!1,limiter:u={fn:C=>{let{x:k,y:j}=C;return{x:k,y:j}}},...d}=Mo(e,t),f={x:n,y:r},h=await Bu(t,d),m=xa(_o(s)),g=Gb(m);let x=f[g],b=f[m];if(o){const C=g==="y"?"top":"left",k=g==="y"?"bottom":"right",j=x+h[C],M=x-h[k];x=zy(j,x,M)}if(l){const C=m==="y"?"top":"left",k=m==="y"?"bottom":"right",j=b+h[C],M=b-h[k];b=zy(j,b,M)}const w=u.fn({...t,[g]:x,[m]:b});return{...w,data:{x:w.x-n,y:w.y-r}}}}},p3=function(e){return e===void 0&&(e={}),{options:e,fn(t){const{x:n,y:r,placement:s,rects:o,middlewareData:l}=t,{offset:u=0,mainAxis:d=!0,crossAxis:f=!0}=Mo(e,t),h={x:n,y:r},m=xa(s),g=Gb(m);let x=h[g],b=h[m];const w=Mo(u,t),C=typeof w=="number"?{mainAxis:w,crossAxis:0}:{mainAxis:0,crossAxis:0,...w};if(d){const M=g==="y"?"height":"width",_=o.reference[g]-o.floating[M]+C.mainAxis,R=o.reference[g]+o.reference[M]-C.mainAxis;x<_?x=_:x>R&&(x=R)}if(f){var k,j;const M=g==="y"?"width":"height",_=["top","left"].includes(_o(s)),R=o.reference[m]-o.floating[M]+(_&&((k=l.offset)==null?void 0:k[m])||0)+(_?0:C.crossAxis),N=o.reference[m]+o.reference[M]+(_?0:((j=l.offset)==null?void 0:j[m])||0)-(_?C.crossAxis:0);bN&&(b=N)}return{[g]:x,[m]:b}}}},h3=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(t){const{placement:n,rects:r,platform:s,elements:o}=t,{apply:l=()=>{},...u}=Mo(e,t),d=await Bu(t,u),f=_o(n),h=oc(n),m=xa(n)==="y",{width:g,height:x}=r.floating;let b,w;f==="top"||f==="bottom"?(b=f,w=h===(await(s.isRTL==null?void 0:s.isRTL(o.floating))?"start":"end")?"left":"right"):(w=f,b=h==="end"?"top":"bottom");const C=x-d.top-d.bottom,k=g-d.left-d.right,j=Hs(x-d[b],C),M=Hs(g-d[w],k),_=!t.middlewareData.shift;let R=j,N=M;if(m?N=h||_?Hs(M,k):k:R=h||_?Hs(j,C):C,_&&!h){const D=zr(d.left,0),z=zr(d.right,0),Q=zr(d.top,0),pe=zr(d.bottom,0);m?N=g-2*(D!==0||z!==0?D+z:zr(d.left,d.right)):R=x-2*(Q!==0||pe!==0?Q+pe:zr(d.top,d.bottom))}await l({...t,availableWidth:N,availableHeight:R});const O=await s.getDimensions(o.floating);return g!==O.width||x!==O.height?{reset:{rects:!0}}:{}}}};function ac(e){return CT(e)?(e.nodeName||"").toLowerCase():"#document"}function Vr(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function Io(e){var t;return(t=(CT(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function CT(e){return e instanceof Node||e instanceof Vr(e).Node}function Gs(e){return e instanceof Element||e instanceof Vr(e).Element}function Js(e){return e instanceof HTMLElement||e instanceof Vr(e).HTMLElement}function t1(e){return typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Vr(e).ShadowRoot}function wd(e){const{overflow:t,overflowX:n,overflowY:r,display:s}=Ns(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!["inline","contents"].includes(s)}function g3(e){return["table","td","th"].includes(ac(e))}function Rh(e){return[":popover-open",":modal"].some(t=>{try{return e.matches(t)}catch{return!1}})}function Zb(e){const t=Yb(),n=Ns(e);return n.transform!=="none"||n.perspective!=="none"||(n.containerType?n.containerType!=="normal":!1)||!t&&(n.backdropFilter?n.backdropFilter!=="none":!1)||!t&&(n.filter?n.filter!=="none":!1)||["transform","perspective","filter"].some(r=>(n.willChange||"").includes(r))||["paint","layout","strict","content"].some(r=>(n.contain||"").includes(r))}function m3(e){let t=wa(e);for(;Js(t)&&!zl(t);){if(Rh(t))return null;if(Zb(t))return t;t=wa(t)}return null}function Yb(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}function zl(e){return["html","body","#document"].includes(ac(e))}function Ns(e){return Vr(e).getComputedStyle(e)}function Ph(e){return Gs(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function wa(e){if(ac(e)==="html")return e;const t=e.assignedSlot||e.parentNode||t1(e)&&e.host||Io(e);return t1(t)?t.host:t}function ET(e){const t=wa(e);return zl(t)?e.ownerDocument?e.ownerDocument.body:e.body:Js(t)&&wd(t)?t:ET(t)}function zu(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const s=ET(e),o=s===((r=e.ownerDocument)==null?void 0:r.body),l=Vr(s);return o?t.concat(l,l.visualViewport||[],wd(s)?s:[],l.frameElement&&n?zu(l.frameElement):[]):t.concat(s,zu(s,[],n))}function kT(e){const t=Ns(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const s=Js(e),o=s?e.offsetWidth:n,l=s?e.offsetHeight:r,u=Dp(n)!==o||Dp(r)!==l;return u&&(n=o,r=l),{width:n,height:r,$:u}}function Xb(e){return Gs(e)?e:e.contextElement}function Rl(e){const t=Xb(e);if(!Js(t))return ba(1);const n=t.getBoundingClientRect(),{width:r,height:s,$:o}=kT(t);let l=(o?Dp(n.width):n.width)/r,u=(o?Dp(n.height):n.height)/s;return(!l||!Number.isFinite(l))&&(l=1),(!u||!Number.isFinite(u))&&(u=1),{x:l,y:u}}const v3=ba(0);function jT(e){const t=Vr(e);return!Yb()||!t.visualViewport?v3:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function y3(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Vr(e)?!1:t}function Ci(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const s=e.getBoundingClientRect(),o=Xb(e);let l=ba(1);t&&(r?Gs(r)&&(l=Rl(r)):l=Rl(e));const u=y3(o,n,r)?jT(o):ba(0);let d=(s.left+u.x)/l.x,f=(s.top+u.y)/l.y,h=s.width/l.x,m=s.height/l.y;if(o){const g=Vr(o),x=r&&Gs(r)?Vr(r):r;let b=g,w=b.frameElement;for(;w&&r&&x!==b;){const C=Rl(w),k=w.getBoundingClientRect(),j=Ns(w),M=k.left+(w.clientLeft+parseFloat(j.paddingLeft))*C.x,_=k.top+(w.clientTop+parseFloat(j.paddingTop))*C.y;d*=C.x,f*=C.y,h*=C.x,m*=C.y,d+=M,f+=_,b=Vr(w),w=b.frameElement}}return Lp({width:h,height:m,x:d,y:f})}function b3(e){let{elements:t,rect:n,offsetParent:r,strategy:s}=e;const o=s==="fixed",l=Io(r),u=t?Rh(t.floating):!1;if(r===l||u&&o)return n;let d={scrollLeft:0,scrollTop:0},f=ba(1);const h=ba(0),m=Js(r);if((m||!m&&!o)&&((ac(r)!=="body"||wd(l))&&(d=Ph(r)),Js(r))){const g=Ci(r);f=Rl(r),h.x=g.x+r.clientLeft,h.y=g.y+r.clientTop}return{width:n.width*f.x,height:n.height*f.y,x:n.x*f.x-d.scrollLeft*f.x+h.x,y:n.y*f.y-d.scrollTop*f.y+h.y}}function x3(e){return Array.from(e.getClientRects())}function TT(e){return Ci(Io(e)).left+Ph(e).scrollLeft}function w3(e){const t=Io(e),n=Ph(e),r=e.ownerDocument.body,s=zr(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),o=zr(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let l=-n.scrollLeft+TT(e);const u=-n.scrollTop;return Ns(r).direction==="rtl"&&(l+=zr(t.clientWidth,r.clientWidth)-s),{width:s,height:o,x:l,y:u}}function S3(e,t){const n=Vr(e),r=Io(e),s=n.visualViewport;let o=r.clientWidth,l=r.clientHeight,u=0,d=0;if(s){o=s.width,l=s.height;const f=Yb();(!f||f&&t==="fixed")&&(u=s.offsetLeft,d=s.offsetTop)}return{width:o,height:l,x:u,y:d}}function C3(e,t){const n=Ci(e,!0,t==="fixed"),r=n.top+e.clientTop,s=n.left+e.clientLeft,o=Js(e)?Rl(e):ba(1),l=e.clientWidth*o.x,u=e.clientHeight*o.y,d=s*o.x,f=r*o.y;return{width:l,height:u,x:d,y:f}}function n1(e,t,n){let r;if(t==="viewport")r=S3(e,n);else if(t==="document")r=w3(Io(e));else if(Gs(t))r=C3(t,n);else{const s=jT(e);r={...t,x:t.x-s.x,y:t.y-s.y}}return Lp(r)}function NT(e,t){const n=wa(e);return n===t||!Gs(n)||zl(n)?!1:Ns(n).position==="fixed"||NT(n,t)}function E3(e,t){const n=t.get(e);if(n)return n;let r=zu(e,[],!1).filter(u=>Gs(u)&&ac(u)!=="body"),s=null;const o=Ns(e).position==="fixed";let l=o?wa(e):e;for(;Gs(l)&&!zl(l);){const u=Ns(l),d=Zb(l);!d&&u.position==="fixed"&&(s=null),(o?!d&&!s:!d&&u.position==="static"&&!!s&&["absolute","fixed"].includes(s.position)||wd(l)&&!d&&NT(e,l))?r=r.filter(h=>h!==l):s=u,l=wa(l)}return t.set(e,r),r}function k3(e){let{element:t,boundary:n,rootBoundary:r,strategy:s}=e;const l=[...n==="clippingAncestors"?Rh(t)?[]:E3(t,this._c):[].concat(n),r],u=l[0],d=l.reduce((f,h)=>{const m=n1(t,h,s);return f.top=zr(m.top,f.top),f.right=Hs(m.right,f.right),f.bottom=Hs(m.bottom,f.bottom),f.left=zr(m.left,f.left),f},n1(t,u,s));return{width:d.right-d.left,height:d.bottom-d.top,x:d.left,y:d.top}}function j3(e){const{width:t,height:n}=kT(e);return{width:t,height:n}}function T3(e,t,n){const r=Js(t),s=Io(t),o=n==="fixed",l=Ci(e,!0,o,t);let u={scrollLeft:0,scrollTop:0};const d=ba(0);if(r||!r&&!o)if((ac(t)!=="body"||wd(s))&&(u=Ph(t)),r){const m=Ci(t,!0,o,t);d.x=m.x+t.clientLeft,d.y=m.y+t.clientTop}else s&&(d.x=TT(s));const f=l.left+u.scrollLeft-d.x,h=l.top+u.scrollTop-d.y;return{x:f,y:h,width:l.width,height:l.height}}function Cv(e){return Ns(e).position==="static"}function r1(e,t){return!Js(e)||Ns(e).position==="fixed"?null:t?t(e):e.offsetParent}function MT(e,t){const n=Vr(e);if(Rh(e))return n;if(!Js(e)){let s=wa(e);for(;s&&!zl(s);){if(Gs(s)&&!Cv(s))return s;s=wa(s)}return n}let r=r1(e,t);for(;r&&g3(r)&&Cv(r);)r=r1(r,t);return r&&zl(r)&&Cv(r)&&!Zb(r)?n:r||m3(e)||n}const N3=async function(e){const t=this.getOffsetParent||MT,n=this.getDimensions,r=await n(e.floating);return{reference:T3(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function M3(e){return Ns(e).direction==="rtl"}const _3={convertOffsetParentRelativeRectToViewportRelativeRect:b3,getDocumentElement:Io,getClippingRect:k3,getOffsetParent:MT,getElementRects:N3,getClientRects:x3,getDimensions:j3,getScale:Rl,isElement:Gs,isRTL:M3};function R3(e,t){let n=null,r;const s=Io(e);function o(){var u;clearTimeout(r),(u=n)==null||u.disconnect(),n=null}function l(u,d){u===void 0&&(u=!1),d===void 0&&(d=1),o();const{left:f,top:h,width:m,height:g}=e.getBoundingClientRect();if(u||t(),!m||!g)return;const x=Uf(h),b=Uf(s.clientWidth-(f+m)),w=Uf(s.clientHeight-(h+g)),C=Uf(f),j={rootMargin:-x+"px "+-b+"px "+-w+"px "+-C+"px",threshold:zr(0,Hs(1,d))||1};let M=!0;function _(R){const N=R[0].intersectionRatio;if(N!==d){if(!M)return l();N?l(!1,N):r=setTimeout(()=>{l(!1,1e-7)},1e3)}M=!1}try{n=new IntersectionObserver(_,{...j,root:s.ownerDocument})}catch{n=new IntersectionObserver(_,j)}n.observe(e)}return l(!0),o}function _T(e,t,n,r){r===void 0&&(r={});const{ancestorScroll:s=!0,ancestorResize:o=!0,elementResize:l=typeof ResizeObserver=="function",layoutShift:u=typeof IntersectionObserver=="function",animationFrame:d=!1}=r,f=Xb(e),h=s||o?[...f?zu(f):[],...zu(t)]:[];h.forEach(k=>{s&&k.addEventListener("scroll",n,{passive:!0}),o&&k.addEventListener("resize",n)});const m=f&&u?R3(f,n):null;let g=-1,x=null;l&&(x=new ResizeObserver(k=>{let[j]=k;j&&j.target===f&&x&&(x.unobserve(t),cancelAnimationFrame(g),g=requestAnimationFrame(()=>{var M;(M=x)==null||M.observe(t)})),n()}),f&&!d&&x.observe(f),x.observe(t));let b,w=d?Ci(e):null;d&&C();function C(){const k=Ci(e);w&&(k.x!==w.x||k.y!==w.y||k.width!==w.width||k.height!==w.height)&&n(),w=k,b=requestAnimationFrame(C)}return n(),()=>{var k;h.forEach(j=>{s&&j.removeEventListener("scroll",n),o&&j.removeEventListener("resize",n)}),m?.(),(k=x)==null||k.disconnect(),x=null,d&&cancelAnimationFrame(b)}}const P3=d3,O3=f3,I3=l3,A3=h3,D3=c3,s1=i3,F3=p3,L3=(e,t,n)=>{const r=new Map,s={platform:_3,...n},o={...s.platform,_c:r};return a3(e,t,{...s,platform:o})};var hp=typeof document<"u"?y.useLayoutEffect:y.useEffect;function $p(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e=="function"&&e.toString()===t.toString())return!0;let n,r,s;if(e&&t&&typeof e=="object"){if(Array.isArray(e)){if(n=e.length,n!==t.length)return!1;for(r=n;r--!==0;)if(!$p(e[r],t[r]))return!1;return!0}if(s=Object.keys(e),n=s.length,n!==Object.keys(t).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(t,s[r]))return!1;for(r=n;r--!==0;){const o=s[r];if(!(o==="_owner"&&e.$$typeof)&&!$p(e[o],t[o]))return!1}return!0}return e!==e&&t!==t}function RT(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function o1(e,t){const n=RT(e);return Math.round(t*n)/n}function a1(e){const t=y.useRef(e);return hp(()=>{t.current=e}),t}function PT(e){e===void 0&&(e={});const{placement:t="bottom",strategy:n="absolute",middleware:r=[],platform:s,elements:{reference:o,floating:l}={},transform:u=!0,whileElementsMounted:d,open:f}=e,[h,m]=y.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[g,x]=y.useState(r);$p(g,r)||x(r);const[b,w]=y.useState(null),[C,k]=y.useState(null),j=y.useCallback(Y=>{Y!==N.current&&(N.current=Y,w(Y))},[]),M=y.useCallback(Y=>{Y!==O.current&&(O.current=Y,k(Y))},[]),_=o||b,R=l||C,N=y.useRef(null),O=y.useRef(null),D=y.useRef(h),z=d!=null,Q=a1(d),pe=a1(s),V=y.useCallback(()=>{if(!N.current||!O.current)return;const Y={placement:t,strategy:n,middleware:g};pe.current&&(Y.platform=pe.current),L3(N.current,O.current,Y).then(H=>{const q={...H,isPositioned:!0};G.current&&!$p(D.current,q)&&(D.current=q,Ma.flushSync(()=>{m(q)}))})},[g,t,n,pe]);hp(()=>{f===!1&&D.current.isPositioned&&(D.current.isPositioned=!1,m(Y=>({...Y,isPositioned:!1})))},[f]);const G=y.useRef(!1);hp(()=>(G.current=!0,()=>{G.current=!1}),[]),hp(()=>{if(_&&(N.current=_),R&&(O.current=R),_&&R){if(Q.current)return Q.current(_,R,V);V()}},[_,R,V,Q,z]);const W=y.useMemo(()=>({reference:N,floating:O,setReference:j,setFloating:M}),[j,M]),ie=y.useMemo(()=>({reference:_,floating:R}),[_,R]),re=y.useMemo(()=>{const Y={position:n,left:0,top:0};if(!ie.floating)return Y;const H=o1(ie.floating,h.x),q=o1(ie.floating,h.y);return u?{...Y,transform:"translate("+H+"px, "+q+"px)",...RT(ie.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:H,top:q}},[n,u,ie.floating,h.x,h.y]);return y.useMemo(()=>({...h,update:V,refs:W,elements:ie,floatingStyles:re}),[h,V,W,ie,re])}const $3=e=>{function t(n){return{}.hasOwnProperty.call(n,"current")}return{name:"arrow",options:e,fn(n){const{element:r,padding:s}=typeof e=="function"?e(n):e;return r&&t(r)?r.current!=null?s1({element:r.current,padding:s}).fn(n):{}:r?s1({element:r,padding:s}).fn(n):{}}}},OT=(e,t)=>({...P3(e),options:[e,t]}),IT=(e,t)=>({...O3(e),options:[e,t]}),AT=(e,t)=>({...F3(e),options:[e,t]}),DT=(e,t)=>({...I3(e),options:[e,t]}),FT=(e,t)=>({...A3(e),options:[e,t]}),LT=(e,t)=>({...D3(e),options:[e,t]}),$T=(e,t)=>({...$3(e),options:[e,t]});var B3="Arrow",BT=y.forwardRef((e,t)=>{const{children:n,width:r=10,height:s=5,...o}=e;return i.jsx(rt.svg,{...o,ref:t,width:r,height:s,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:i.jsx("polygon",{points:"0,0 30,0 15,10"})})});BT.displayName=B3;var z3=BT;function zT(e){const[t,n]=y.useState(void 0);return Ln(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(s=>{if(!Array.isArray(s)||!s.length)return;const o=s[0];let l,u;if("borderBoxSize"in o){const d=o.borderBoxSize,f=Array.isArray(d)?d[0]:d;l=f.inlineSize,u=f.blockSize}else l=e.offsetWidth,u=e.offsetHeight;n({width:l,height:u})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else n(void 0)},[e]),t}var ex="Popper",[UT,Oh]=us(ex),[U3,VT]=UT(ex),HT=e=>{const{__scopePopper:t,children:n}=e,[r,s]=y.useState(null);return i.jsx(U3,{scope:t,anchor:r,onAnchorChange:s,children:n})};HT.displayName=ex;var qT="PopperAnchor",KT=y.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...s}=e,o=VT(qT,n),l=y.useRef(null),u=Rt(t,l);return y.useEffect(()=>{o.onAnchorChange(r?.current||l.current)}),r?null:i.jsx(rt.div,{...s,ref:u})});KT.displayName=qT;var tx="PopperContent",[V3,H3]=UT(tx),WT=y.forwardRef((e,t)=>{const{__scopePopper:n,side:r="bottom",sideOffset:s=0,align:o="center",alignOffset:l=0,arrowPadding:u=0,avoidCollisions:d=!0,collisionBoundary:f=[],collisionPadding:h=0,sticky:m="partial",hideWhenDetached:g=!1,updatePositionStrategy:x="optimized",onPlaced:b,...w}=e,C=VT(tx,n),[k,j]=y.useState(null),M=Rt(t,Z=>j(Z)),[_,R]=y.useState(null),N=zT(_),O=N?.width??0,D=N?.height??0,z=r+(o!=="center"?"-"+o:""),Q=typeof h=="number"?h:{top:0,right:0,bottom:0,left:0,...h},pe=Array.isArray(f)?f:[f],V=pe.length>0,G={padding:Q,boundary:pe.filter(K3),altBoundary:V},{refs:W,floatingStyles:ie,placement:re,isPositioned:Y,middlewareData:H}=PT({strategy:"fixed",placement:z,whileElementsMounted:(...Z)=>_T(...Z,{animationFrame:x==="always"}),elements:{reference:C.anchor},middleware:[OT({mainAxis:s+D,alignmentAxis:l}),d&&IT({mainAxis:!0,crossAxis:!1,limiter:m==="partial"?AT():void 0,...G}),d&&DT({...G}),FT({...G,apply:({elements:Z,rects:ye,availableWidth:Re,availableHeight:$e})=>{const{width:Ye,height:Fe}=ye.reference,ft=Z.floating.style;ft.setProperty("--radix-popper-available-width",`${Re}px`),ft.setProperty("--radix-popper-available-height",`${$e}px`),ft.setProperty("--radix-popper-anchor-width",`${Ye}px`),ft.setProperty("--radix-popper-anchor-height",`${Fe}px`)}}),_&&$T({element:_,padding:u}),W3({arrowWidth:O,arrowHeight:D}),g&<({strategy:"referenceHidden",...G})]}),[q,he]=QT(re),A=Rn(b);Ln(()=>{Y&&A?.()},[Y,A]);const F=H.arrow?.x,fe=H.arrow?.y,te=H.arrow?.centerOffset!==0,[de,ge]=y.useState();return Ln(()=>{k&&ge(window.getComputedStyle(k).zIndex)},[k]),i.jsx("div",{ref:W.setFloating,"data-radix-popper-content-wrapper":"",style:{...ie,transform:Y?ie.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:de,"--radix-popper-transform-origin":[H.transformOrigin?.x,H.transformOrigin?.y].join(" "),...H.hide?.referenceHidden&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:i.jsx(V3,{scope:n,placedSide:q,onArrowChange:R,arrowX:F,arrowY:fe,shouldHideArrow:te,children:i.jsx(rt.div,{"data-side":q,"data-align":he,...w,ref:M,style:{...w.style,animation:Y?void 0:"none"}})})})});WT.displayName=tx;var GT="PopperArrow",q3={top:"bottom",right:"left",bottom:"top",left:"right"},JT=y.forwardRef(function(t,n){const{__scopePopper:r,...s}=t,o=H3(GT,r),l=q3[o.placedSide];return i.jsx("span",{ref:o.onArrowChange,style:{position:"absolute",left:o.arrowX,top:o.arrowY,[l]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[o.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[o.placedSide],visibility:o.shouldHideArrow?"hidden":void 0},children:i.jsx(z3,{...s,ref:n,style:{...s.style,display:"block"}})})});JT.displayName=GT;function K3(e){return e!==null}var W3=e=>({name:"transformOrigin",options:e,fn(t){const{placement:n,rects:r,middlewareData:s}=t,l=s.arrow?.centerOffset!==0,u=l?0:e.arrowWidth,d=l?0:e.arrowHeight,[f,h]=QT(n),m={start:"0%",center:"50%",end:"100%"}[h],g=(s.arrow?.x??0)+u/2,x=(s.arrow?.y??0)+d/2;let b="",w="";return f==="bottom"?(b=l?m:`${g}px`,w=`${-d}px`):f==="top"?(b=l?m:`${g}px`,w=`${r.floating.height+d}px`):f==="right"?(b=`${-d}px`,w=l?m:`${x}px`):f==="left"&&(b=`${r.floating.width+d}px`,w=l?m:`${x}px`),{data:{x:b,y:w}}}});function QT(e){const[t,n="center"]=e.split("-");return[t,n]}var ZT=HT,YT=KT,XT=WT,eN=JT,G3="Portal",Ih=y.forwardRef((e,t)=>{const{container:n,...r}=e,[s,o]=y.useState(!1);Ln(()=>o(!0),[]);const l=n||s&&globalThis?.document?.body;return l?Ib.createPortal(i.jsx(rt.div,{...r,ref:t}),l):null});Ih.displayName=G3;function J3(e,t){return y.useReducer((n,r)=>t[n][r]??n,e)}var Mr=e=>{const{present:t,children:n}=e,r=Q3(t),s=typeof n=="function"?n({present:r.isPresent}):y.Children.only(n),o=Rt(r.ref,Z3(s));return typeof n=="function"||r.isPresent?y.cloneElement(s,{ref:o}):null};Mr.displayName="Presence";function Q3(e){const[t,n]=y.useState(),r=y.useRef({}),s=y.useRef(e),o=y.useRef("none"),l=e?"mounted":"unmounted",[u,d]=J3(l,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return y.useEffect(()=>{const f=Vf(r.current);o.current=u==="mounted"?f:"none"},[u]),Ln(()=>{const f=r.current,h=s.current;if(h!==e){const g=o.current,x=Vf(f);e?d("MOUNT"):x==="none"||f?.display==="none"?d("UNMOUNT"):d(h&&g!==x?"ANIMATION_OUT":"UNMOUNT"),s.current=e}},[e,d]),Ln(()=>{if(t){const f=m=>{const x=Vf(r.current).includes(m.animationName);m.target===t&&x&&Ma.flushSync(()=>d("ANIMATION_END"))},h=m=>{m.target===t&&(o.current=Vf(r.current))};return t.addEventListener("animationstart",h),t.addEventListener("animationcancel",f),t.addEventListener("animationend",f),()=>{t.removeEventListener("animationstart",h),t.removeEventListener("animationcancel",f),t.removeEventListener("animationend",f)}}else d("ANIMATION_END")},[t,d]),{isPresent:["mounted","unmountSuspended"].includes(u),ref:y.useCallback(f=>{f&&(r.current=getComputedStyle(f)),n(f)},[])}}function Vf(e){return e?.animationName||"none"}function Z3(e){let t=Object.getOwnPropertyDescriptor(e.props,"ref")?.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=Object.getOwnPropertyDescriptor(e,"ref")?.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}var Ev="rovingFocusGroup.onEntryFocus",Y3={bubbles:!1,cancelable:!0},Ah="RovingFocusGroup",[Vy,tN,X3]=Kb(Ah),[ez,Dh]=us(Ah,[X3]),[tz,nz]=ez(Ah),nN=y.forwardRef((e,t)=>i.jsx(Vy.Provider,{scope:e.__scopeRovingFocusGroup,children:i.jsx(Vy.Slot,{scope:e.__scopeRovingFocusGroup,children:i.jsx(rz,{...e,ref:t})})}));nN.displayName=Ah;var rz=y.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:s=!1,dir:o,currentTabStopId:l,defaultCurrentTabStopId:u,onCurrentTabStopIdChange:d,onEntryFocus:f,preventScrollOnEntryFocus:h=!1,...m}=e,g=y.useRef(null),x=Rt(t,g),b=xd(o),[w=null,C]=ya({prop:l,defaultProp:u,onChange:d}),[k,j]=y.useState(!1),M=Rn(f),_=tN(n),R=y.useRef(!1),[N,O]=y.useState(0);return y.useEffect(()=>{const D=g.current;if(D)return D.addEventListener(Ev,M),()=>D.removeEventListener(Ev,M)},[M]),i.jsx(tz,{scope:n,orientation:r,dir:b,loop:s,currentTabStopId:w,onItemFocus:y.useCallback(D=>C(D),[C]),onItemShiftTab:y.useCallback(()=>j(!0),[]),onFocusableItemAdd:y.useCallback(()=>O(D=>D+1),[]),onFocusableItemRemove:y.useCallback(()=>O(D=>D-1),[]),children:i.jsx(rt.div,{tabIndex:k||N===0?-1:0,"data-orientation":r,...m,ref:x,style:{outline:"none",...e.style},onMouseDown:Ue(e.onMouseDown,()=>{R.current=!0}),onFocus:Ue(e.onFocus,D=>{const z=!R.current;if(D.target===D.currentTarget&&z&&!k){const Q=new CustomEvent(Ev,Y3);if(D.currentTarget.dispatchEvent(Q),!Q.defaultPrevented){const pe=_().filter(re=>re.focusable),V=pe.find(re=>re.active),G=pe.find(re=>re.id===w),ie=[V,G,...pe].filter(Boolean).map(re=>re.ref.current);oN(ie,h)}}R.current=!1}),onBlur:Ue(e.onBlur,()=>j(!1))})})}),rN="RovingFocusGroupItem",sN=y.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:s=!1,tabStopId:o,...l}=e,u=Es(),d=o||u,f=nz(rN,n),h=f.currentTabStopId===d,m=tN(n),{onFocusableItemAdd:g,onFocusableItemRemove:x}=f;return y.useEffect(()=>{if(r)return g(),()=>x()},[r,g,x]),i.jsx(Vy.ItemSlot,{scope:n,id:d,focusable:r,active:s,children:i.jsx(rt.span,{tabIndex:h?0:-1,"data-orientation":f.orientation,...l,ref:t,onMouseDown:Ue(e.onMouseDown,b=>{r?f.onItemFocus(d):b.preventDefault()}),onFocus:Ue(e.onFocus,()=>f.onItemFocus(d)),onKeyDown:Ue(e.onKeyDown,b=>{if(b.key==="Tab"&&b.shiftKey){f.onItemShiftTab();return}if(b.target!==b.currentTarget)return;const w=az(b,f.orientation,f.dir);if(w!==void 0){if(b.metaKey||b.ctrlKey||b.altKey||b.shiftKey)return;b.preventDefault();let k=m().filter(j=>j.focusable).map(j=>j.ref.current);if(w==="last")k.reverse();else if(w==="prev"||w==="next"){w==="prev"&&k.reverse();const j=k.indexOf(b.currentTarget);k=f.loop?iz(k,j+1):k.slice(j+1)}setTimeout(()=>oN(k))}})})})});sN.displayName=rN;var sz={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function oz(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function az(e,t,n){const r=oz(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return sz[r]}function oN(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function iz(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var aN=nN,iN=sN,lz=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},pl=new WeakMap,Hf=new WeakMap,qf={},kv=0,lN=function(e){return e&&(e.host||lN(e.parentNode))},cz=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=lN(n);return r&&e.contains(r)?r:(console.error("aria-hidden",n,"in not contained inside",e,". Doing nothing"),null)}).filter(function(n){return!!n})},uz=function(e,t,n,r){var s=cz(t,Array.isArray(e)?e:[e]);qf[n]||(qf[n]=new WeakMap);var o=qf[n],l=[],u=new Set,d=new Set(s),f=function(m){!m||u.has(m)||(u.add(m),f(m.parentNode))};s.forEach(f);var h=function(m){!m||d.has(m)||Array.prototype.forEach.call(m.children,function(g){if(u.has(g))h(g);else try{var x=g.getAttribute(r),b=x!==null&&x!=="false",w=(pl.get(g)||0)+1,C=(o.get(g)||0)+1;pl.set(g,w),o.set(g,C),l.push(g),w===1&&b&&Hf.set(g,!0),C===1&&g.setAttribute(n,"true"),b||g.setAttribute(r,"true")}catch(k){console.error("aria-hidden: cannot operate on ",g,k)}})};return h(t),u.clear(),kv++,function(){l.forEach(function(m){var g=pl.get(m)-1,x=o.get(m)-1;pl.set(m,g),o.set(m,x),g||(Hf.has(m)||m.removeAttribute(r),Hf.delete(m)),x||m.removeAttribute(n)}),kv--,kv||(pl=new WeakMap,pl=new WeakMap,Hf=new WeakMap,qf={})}},nx=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),s=lz(e);return s?(r.push.apply(r,Array.from(s.querySelectorAll("[aria-live]"))),uz(r,s,n,"aria-hidden")):function(){return null}},zs=function(){return zs=Object.assign||function(t){for(var n,r=1,s=arguments.length;r"u")return Tz;var t=Nz(e),n=document.documentElement.clientWidth,r=window.innerWidth;return{left:t[0],top:t[1],right:t[2],gap:Math.max(0,r-n+t[2]-t[0])}},_z=fN(),Pl="data-scroll-locked",Rz=function(e,t,n,r){var s=e.left,o=e.top,l=e.right,u=e.gap;return n===void 0&&(n="margin"),` .`.concat(fz,` { overflow: hidden `).concat(r,`; padding-right: `).concat(u,"px ").concat(r,`; } body[`).concat(Pl,`] { overflow: hidden `).concat(r,`; overscroll-behavior: contain; `).concat([t&&"position: relative ".concat(r,";"),n==="margin"&&` padding-left: `.concat(s,`px; padding-top: `).concat(o,`px; padding-right: `).concat(l,`px; margin-left:0; margin-top:0; margin-right: `).concat(u,"px ").concat(r,`; `),n==="padding"&&"padding-right: ".concat(u,"px ").concat(r,";")].filter(Boolean).join(""),` } .`).concat(gp,` { right: `).concat(u,"px ").concat(r,`; } .`).concat(mp,` { margin-right: `).concat(u,"px ").concat(r,`; } .`).concat(gp," .").concat(gp,` { right: 0 `).concat(r,`; } .`).concat(mp," .").concat(mp,` { margin-right: 0 `).concat(r,`; } body[`).concat(Pl,`] { `).concat(pz,": ").concat(u,`px; } `)},l1=function(){var e=parseInt(document.body.getAttribute(Pl)||"0",10);return isFinite(e)?e:0},Pz=function(){y.useEffect(function(){return document.body.setAttribute(Pl,(l1()+1).toString()),function(){var e=l1()-1;e<=0?document.body.removeAttribute(Pl):document.body.setAttribute(Pl,e.toString())}},[])},Oz=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,s=r===void 0?"margin":r;Pz();var o=y.useMemo(function(){return Mz(s)},[s]);return y.createElement(_z,{styles:Rz(o,!t,s,n?"":"!important")})},Hy=!1;if(typeof window<"u")try{var Kf=Object.defineProperty({},"passive",{get:function(){return Hy=!0,!0}});window.addEventListener("test",Kf,Kf),window.removeEventListener("test",Kf,Kf)}catch{Hy=!1}var hl=Hy?{passive:!1}:!1,Iz=function(e){return e.tagName==="TEXTAREA"},pN=function(e,t){var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!Iz(e)&&n[t]==="visible")},Az=function(e){return pN(e,"overflowY")},Dz=function(e){return pN(e,"overflowX")},c1=function(e,t){var n=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var s=hN(e,r);if(s){var o=gN(e,r),l=o[1],u=o[2];if(l>u)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},Fz=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},Lz=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},hN=function(e,t){return e==="v"?Az(t):Dz(t)},gN=function(e,t){return e==="v"?Fz(t):Lz(t)},$z=function(e,t){return e==="h"&&t==="rtl"?-1:1},Bz=function(e,t,n,r,s){var o=$z(e,window.getComputedStyle(t).direction),l=o*r,u=n.target,d=t.contains(u),f=!1,h=l>0,m=0,g=0;do{var x=gN(e,u),b=x[0],w=x[1],C=x[2],k=w-C-o*b;(b||k)&&hN(e,u)&&(m+=k,g+=b),u instanceof ShadowRoot?u=u.host:u=u.parentNode}while(!d&&u!==document.body||d&&(t.contains(u)||t===u));return(h&&Math.abs(m)<1||!h&&Math.abs(g)<1)&&(f=!0),f},Wf=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},u1=function(e){return[e.deltaX,e.deltaY]},d1=function(e){return e&&"current"in e?e.current:e},zz=function(e,t){return e[0]===t[0]&&e[1]===t[1]},Uz=function(e){return` .block-interactivity-`.concat(e,` {pointer-events: none;} .allow-interactivity-`).concat(e,` {pointer-events: all;} `)},Vz=0,gl=[];function Hz(e){var t=y.useRef([]),n=y.useRef([0,0]),r=y.useRef(),s=y.useState(Vz++)[0],o=y.useState(fN)[0],l=y.useRef(e);y.useEffect(function(){l.current=e},[e]),y.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(s));var w=dz([e.lockRef.current],(e.shards||[]).map(d1),!0).filter(Boolean);return w.forEach(function(C){return C.classList.add("allow-interactivity-".concat(s))}),function(){document.body.classList.remove("block-interactivity-".concat(s)),w.forEach(function(C){return C.classList.remove("allow-interactivity-".concat(s))})}}},[e.inert,e.lockRef.current,e.shards]);var u=y.useCallback(function(w,C){if("touches"in w&&w.touches.length===2)return!l.current.allowPinchZoom;var k=Wf(w),j=n.current,M="deltaX"in w?w.deltaX:j[0]-k[0],_="deltaY"in w?w.deltaY:j[1]-k[1],R,N=w.target,O=Math.abs(M)>Math.abs(_)?"h":"v";if("touches"in w&&O==="h"&&N.type==="range")return!1;var D=c1(O,N);if(!D)return!0;if(D?R=O:(R=O==="v"?"h":"v",D=c1(O,N)),!D)return!1;if(!r.current&&"changedTouches"in w&&(M||_)&&(r.current=R),!R)return!0;var z=r.current||R;return Bz(z,C,w,z==="h"?M:_)},[]),d=y.useCallback(function(w){var C=w;if(!(!gl.length||gl[gl.length-1]!==o)){var k="deltaY"in C?u1(C):Wf(C),j=t.current.filter(function(R){return R.name===C.type&&(R.target===C.target||C.target===R.shadowParent)&&zz(R.delta,k)})[0];if(j&&j.should){C.cancelable&&C.preventDefault();return}if(!j){var M=(l.current.shards||[]).map(d1).filter(Boolean).filter(function(R){return R.contains(C.target)}),_=M.length>0?u(C,M[0]):!l.current.noIsolation;_&&C.cancelable&&C.preventDefault()}}},[]),f=y.useCallback(function(w,C,k,j){var M={name:w,delta:C,target:k,should:j,shadowParent:qz(k)};t.current.push(M),setTimeout(function(){t.current=t.current.filter(function(_){return _!==M})},1)},[]),h=y.useCallback(function(w){n.current=Wf(w),r.current=void 0},[]),m=y.useCallback(function(w){f(w.type,u1(w),w.target,u(w,e.lockRef.current))},[]),g=y.useCallback(function(w){f(w.type,Wf(w),w.target,u(w,e.lockRef.current))},[]);y.useEffect(function(){return gl.push(o),e.setCallbacks({onScrollCapture:m,onWheelCapture:m,onTouchMoveCapture:g}),document.addEventListener("wheel",d,hl),document.addEventListener("touchmove",d,hl),document.addEventListener("touchstart",h,hl),function(){gl=gl.filter(function(w){return w!==o}),document.removeEventListener("wheel",d,hl),document.removeEventListener("touchmove",d,hl),document.removeEventListener("touchstart",h,hl)}},[]);var x=e.removeScrollBar,b=e.inert;return y.createElement(y.Fragment,null,b?y.createElement(o,{styles:Uz(s)}):null,x?y.createElement(Oz,{gapMode:e.gapMode}):null)}function qz(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const Kz=xz(dN,Hz);var Lh=y.forwardRef(function(e,t){return y.createElement(Fh,zs({},e,{ref:t,sideCar:Kz}))});Lh.classNames=Fh.classNames;var qy=["Enter"," "],Wz=["ArrowDown","PageUp","Home"],mN=["ArrowUp","PageDown","End"],Gz=[...Wz,...mN],Jz={ltr:[...qy,"ArrowRight"],rtl:[...qy,"ArrowLeft"]},Qz={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Sd="Menu",[Uu,Zz,Yz]=Kb(Sd),[$i,vN]=us(Sd,[Yz,Oh,Dh]),$h=Oh(),yN=Dh(),[Xz,Bi]=$i(Sd),[eU,Cd]=$i(Sd),bN=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:s,onOpenChange:o,modal:l=!0}=e,u=$h(t),[d,f]=y.useState(null),h=y.useRef(!1),m=Rn(o),g=xd(s);return y.useEffect(()=>{const x=()=>{h.current=!0,document.addEventListener("pointerdown",b,{capture:!0,once:!0}),document.addEventListener("pointermove",b,{capture:!0,once:!0})},b=()=>h.current=!1;return document.addEventListener("keydown",x,{capture:!0}),()=>{document.removeEventListener("keydown",x,{capture:!0}),document.removeEventListener("pointerdown",b,{capture:!0}),document.removeEventListener("pointermove",b,{capture:!0})}},[]),i.jsx(ZT,{...u,children:i.jsx(Xz,{scope:t,open:n,onOpenChange:m,content:d,onContentChange:f,children:i.jsx(eU,{scope:t,onClose:y.useCallback(()=>m(!1),[m]),isUsingKeyboardRef:h,dir:g,modal:l,children:r})})})};bN.displayName=Sd;var tU="MenuAnchor",rx=y.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,s=$h(n);return i.jsx(YT,{...s,...r,ref:t})});rx.displayName=tU;var sx="MenuPortal",[nU,xN]=$i(sx,{forceMount:void 0}),wN=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:s}=e,o=Bi(sx,t);return i.jsx(nU,{scope:t,forceMount:n,children:i.jsx(Mr,{present:n||o.open,children:i.jsx(Ih,{asChild:!0,container:s,children:r})})})};wN.displayName=sx;var is="MenuContent",[rU,ox]=$i(is),SN=y.forwardRef((e,t)=>{const n=xN(is,e.__scopeMenu),{forceMount:r=n.forceMount,...s}=e,o=Bi(is,e.__scopeMenu),l=Cd(is,e.__scopeMenu);return i.jsx(Uu.Provider,{scope:e.__scopeMenu,children:i.jsx(Mr,{present:r||o.open,children:i.jsx(Uu.Slot,{scope:e.__scopeMenu,children:l.modal?i.jsx(sU,{...s,ref:t}):i.jsx(oU,{...s,ref:t})})})})}),sU=y.forwardRef((e,t)=>{const n=Bi(is,e.__scopeMenu),r=y.useRef(null),s=Rt(t,r);return y.useEffect(()=>{const o=r.current;if(o)return nx(o)},[]),i.jsx(ax,{...e,ref:s,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:Ue(e.onFocusOutside,o=>o.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),oU=y.forwardRef((e,t)=>{const n=Bi(is,e.__scopeMenu);return i.jsx(ax,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),ax=y.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:s,onOpenAutoFocus:o,onCloseAutoFocus:l,disableOutsidePointerEvents:u,onEntryFocus:d,onEscapeKeyDown:f,onPointerDownOutside:h,onFocusOutside:m,onInteractOutside:g,onDismiss:x,disableOutsideScroll:b,...w}=e,C=Bi(is,n),k=Cd(is,n),j=$h(n),M=yN(n),_=Zz(n),[R,N]=y.useState(null),O=y.useRef(null),D=Rt(t,O,C.onContentChange),z=y.useRef(0),Q=y.useRef(""),pe=y.useRef(0),V=y.useRef(null),G=y.useRef("right"),W=y.useRef(0),ie=b?Lh:y.Fragment,re=b?{as:No,allowPinchZoom:!0}:void 0,Y=q=>{const he=Q.current+q,A=_().filter(Z=>!Z.disabled),F=document.activeElement,fe=A.find(Z=>Z.ref.current===F)?.textValue,te=A.map(Z=>Z.textValue),de=vU(te,he,fe),ge=A.find(Z=>Z.textValue===de)?.ref.current;(function Z(ye){Q.current=ye,window.clearTimeout(z.current),ye!==""&&(z.current=window.setTimeout(()=>Z(""),1e3))})(he),ge&&setTimeout(()=>ge.focus())};y.useEffect(()=>()=>window.clearTimeout(z.current),[]),Wb();const H=y.useCallback(q=>G.current===V.current?.side&&bU(q,V.current?.area),[]);return i.jsx(rU,{scope:n,searchRef:Q,onItemEnter:y.useCallback(q=>{H(q)&&q.preventDefault()},[H]),onItemLeave:y.useCallback(q=>{H(q)||(O.current?.focus(),N(null))},[H]),onTriggerLeave:y.useCallback(q=>{H(q)&&q.preventDefault()},[H]),pointerGraceTimerRef:pe,onPointerGraceIntentChange:y.useCallback(q=>{V.current=q},[]),children:i.jsx(ie,{...re,children:i.jsx(_h,{asChild:!0,trapped:s,onMountAutoFocus:Ue(o,q=>{q.preventDefault(),O.current?.focus({preventScroll:!0})}),onUnmountAutoFocus:l,children:i.jsx(Mh,{asChild:!0,disableOutsidePointerEvents:u,onEscapeKeyDown:f,onPointerDownOutside:h,onFocusOutside:m,onInteractOutside:g,onDismiss:x,children:i.jsx(aN,{asChild:!0,...M,dir:k.dir,orientation:"vertical",loop:r,currentTabStopId:R,onCurrentTabStopIdChange:N,onEntryFocus:Ue(d,q=>{k.isUsingKeyboardRef.current||q.preventDefault()}),preventScrollOnEntryFocus:!0,children:i.jsx(XT,{role:"menu","aria-orientation":"vertical","data-state":LN(C.open),"data-radix-menu-content":"",dir:k.dir,...j,...w,ref:D,style:{outline:"none",...w.style},onKeyDown:Ue(w.onKeyDown,q=>{const A=q.target.closest("[data-radix-menu-content]")===q.currentTarget,F=q.ctrlKey||q.altKey||q.metaKey,fe=q.key.length===1;A&&(q.key==="Tab"&&q.preventDefault(),!F&&fe&&Y(q.key));const te=O.current;if(q.target!==te||!Gz.includes(q.key))return;q.preventDefault();const ge=_().filter(Z=>!Z.disabled).map(Z=>Z.ref.current);mN.includes(q.key)&&ge.reverse(),gU(ge)}),onBlur:Ue(e.onBlur,q=>{q.currentTarget.contains(q.target)||(window.clearTimeout(z.current),Q.current="")}),onPointerMove:Ue(e.onPointerMove,Vu(q=>{const he=q.target,A=W.current!==q.clientX;if(q.currentTarget.contains(he)&&A){const F=q.clientX>W.current?"right":"left";G.current=F,W.current=q.clientX}}))})})})})})})});SN.displayName=is;var aU="MenuGroup",ix=y.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return i.jsx(rt.div,{role:"group",...r,ref:t})});ix.displayName=aU;var iU="MenuLabel",CN=y.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return i.jsx(rt.div,{...r,ref:t})});CN.displayName=iU;var Bp="MenuItem",f1="menu.itemSelect",Bh=y.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...s}=e,o=y.useRef(null),l=Cd(Bp,e.__scopeMenu),u=ox(Bp,e.__scopeMenu),d=Rt(t,o),f=y.useRef(!1),h=()=>{const m=o.current;if(!n&&m){const g=new CustomEvent(f1,{bubbles:!0,cancelable:!0});m.addEventListener(f1,x=>r?.(x),{once:!0}),yT(m,g),g.defaultPrevented?f.current=!1:l.onClose()}};return i.jsx(EN,{...s,ref:d,disabled:n,onClick:Ue(e.onClick,h),onPointerDown:m=>{e.onPointerDown?.(m),f.current=!0},onPointerUp:Ue(e.onPointerUp,m=>{f.current||m.currentTarget?.click()}),onKeyDown:Ue(e.onKeyDown,m=>{const g=u.searchRef.current!=="";n||g&&m.key===" "||qy.includes(m.key)&&(m.currentTarget.click(),m.preventDefault())})})});Bh.displayName=Bp;var EN=y.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:s,...o}=e,l=ox(Bp,n),u=yN(n),d=y.useRef(null),f=Rt(t,d),[h,m]=y.useState(!1),[g,x]=y.useState("");return y.useEffect(()=>{const b=d.current;b&&x((b.textContent??"").trim())},[o.children]),i.jsx(Uu.ItemSlot,{scope:n,disabled:r,textValue:s??g,children:i.jsx(iN,{asChild:!0,...u,focusable:!r,children:i.jsx(rt.div,{role:"menuitem","data-highlighted":h?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...o,ref:f,onPointerMove:Ue(e.onPointerMove,Vu(b=>{r?l.onItemLeave(b):(l.onItemEnter(b),b.defaultPrevented||b.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:Ue(e.onPointerLeave,Vu(b=>l.onItemLeave(b))),onFocus:Ue(e.onFocus,()=>m(!0)),onBlur:Ue(e.onBlur,()=>m(!1))})})})}),lU="MenuCheckboxItem",kN=y.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...s}=e;return i.jsx(_N,{scope:e.__scopeMenu,checked:n,children:i.jsx(Bh,{role:"menuitemcheckbox","aria-checked":zp(n)?"mixed":n,...s,ref:t,"data-state":cx(n),onSelect:Ue(s.onSelect,()=>r?.(zp(n)?!0:!n),{checkForDefaultPrevented:!1})})})});kN.displayName=lU;var jN="MenuRadioGroup",[cU,uU]=$i(jN,{value:void 0,onValueChange:()=>{}}),TN=y.forwardRef((e,t)=>{const{value:n,onValueChange:r,...s}=e,o=Rn(r);return i.jsx(cU,{scope:e.__scopeMenu,value:n,onValueChange:o,children:i.jsx(ix,{...s,ref:t})})});TN.displayName=jN;var NN="MenuRadioItem",MN=y.forwardRef((e,t)=>{const{value:n,...r}=e,s=uU(NN,e.__scopeMenu),o=n===s.value;return i.jsx(_N,{scope:e.__scopeMenu,checked:o,children:i.jsx(Bh,{role:"menuitemradio","aria-checked":o,...r,ref:t,"data-state":cx(o),onSelect:Ue(r.onSelect,()=>s.onValueChange?.(n),{checkForDefaultPrevented:!1})})})});MN.displayName=NN;var lx="MenuItemIndicator",[_N,dU]=$i(lx,{checked:!1}),RN=y.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...s}=e,o=dU(lx,n);return i.jsx(Mr,{present:r||zp(o.checked)||o.checked===!0,children:i.jsx(rt.span,{...s,ref:t,"data-state":cx(o.checked)})})});RN.displayName=lx;var fU="MenuSeparator",PN=y.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return i.jsx(rt.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});PN.displayName=fU;var pU="MenuArrow",ON=y.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,s=$h(n);return i.jsx(eN,{...s,...r,ref:t})});ON.displayName=pU;var hU="MenuSub",[wie,IN]=$i(hU),mu="MenuSubTrigger",AN=y.forwardRef((e,t)=>{const n=Bi(mu,e.__scopeMenu),r=Cd(mu,e.__scopeMenu),s=IN(mu,e.__scopeMenu),o=ox(mu,e.__scopeMenu),l=y.useRef(null),{pointerGraceTimerRef:u,onPointerGraceIntentChange:d}=o,f={__scopeMenu:e.__scopeMenu},h=y.useCallback(()=>{l.current&&window.clearTimeout(l.current),l.current=null},[]);return y.useEffect(()=>h,[h]),y.useEffect(()=>{const m=u.current;return()=>{window.clearTimeout(m),d(null)}},[u,d]),i.jsx(rx,{asChild:!0,...f,children:i.jsx(EN,{id:s.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":s.contentId,"data-state":LN(n.open),...e,ref:kh(t,s.onTriggerChange),onClick:m=>{e.onClick?.(m),!(e.disabled||m.defaultPrevented)&&(m.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:Ue(e.onPointerMove,Vu(m=>{o.onItemEnter(m),!m.defaultPrevented&&!e.disabled&&!n.open&&!l.current&&(o.onPointerGraceIntentChange(null),l.current=window.setTimeout(()=>{n.onOpenChange(!0),h()},100))})),onPointerLeave:Ue(e.onPointerLeave,Vu(m=>{h();const g=n.content?.getBoundingClientRect();if(g){const x=n.content?.dataset.side,b=x==="right",w=b?-5:5,C=g[b?"left":"right"],k=g[b?"right":"left"];o.onPointerGraceIntentChange({area:[{x:m.clientX+w,y:m.clientY},{x:C,y:g.top},{x:k,y:g.top},{x:k,y:g.bottom},{x:C,y:g.bottom}],side:x}),window.clearTimeout(u.current),u.current=window.setTimeout(()=>o.onPointerGraceIntentChange(null),300)}else{if(o.onTriggerLeave(m),m.defaultPrevented)return;o.onPointerGraceIntentChange(null)}})),onKeyDown:Ue(e.onKeyDown,m=>{const g=o.searchRef.current!=="";e.disabled||g&&m.key===" "||Jz[r.dir].includes(m.key)&&(n.onOpenChange(!0),n.content?.focus(),m.preventDefault())})})})});AN.displayName=mu;var DN="MenuSubContent",FN=y.forwardRef((e,t)=>{const n=xN(is,e.__scopeMenu),{forceMount:r=n.forceMount,...s}=e,o=Bi(is,e.__scopeMenu),l=Cd(is,e.__scopeMenu),u=IN(DN,e.__scopeMenu),d=y.useRef(null),f=Rt(t,d);return i.jsx(Uu.Provider,{scope:e.__scopeMenu,children:i.jsx(Mr,{present:r||o.open,children:i.jsx(Uu.Slot,{scope:e.__scopeMenu,children:i.jsx(ax,{id:u.contentId,"aria-labelledby":u.triggerId,...s,ref:f,align:"start",side:l.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:h=>{l.isUsingKeyboardRef.current&&d.current?.focus(),h.preventDefault()},onCloseAutoFocus:h=>h.preventDefault(),onFocusOutside:Ue(e.onFocusOutside,h=>{h.target!==u.trigger&&o.onOpenChange(!1)}),onEscapeKeyDown:Ue(e.onEscapeKeyDown,h=>{l.onClose(),h.preventDefault()}),onKeyDown:Ue(e.onKeyDown,h=>{const m=h.currentTarget.contains(h.target),g=Qz[l.dir].includes(h.key);m&&g&&(o.onOpenChange(!1),u.trigger?.focus(),h.preventDefault())})})})})})});FN.displayName=DN;function LN(e){return e?"open":"closed"}function zp(e){return e==="indeterminate"}function cx(e){return zp(e)?"indeterminate":e?"checked":"unchecked"}function gU(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function mU(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function vU(e,t,n){const s=t.length>1&&Array.from(t).every(f=>f===t[0])?t[0]:t,o=n?e.indexOf(n):-1;let l=mU(e,Math.max(o,0));s.length===1&&(l=l.filter(f=>f!==n));const d=l.find(f=>f.toLowerCase().startsWith(s.toLowerCase()));return d!==n?d:void 0}function yU(e,t){const{x:n,y:r}=e;let s=!1;for(let o=0,l=t.length-1;or!=h>r&&n<(f-u)*(r-d)/(h-d)+u&&(s=!s)}return s}function bU(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return yU(n,t)}function Vu(e){return t=>t.pointerType==="mouse"?e(t):void 0}var xU=bN,wU=rx,SU=wN,CU=SN,EU=ix,kU=CN,jU=Bh,TU=kN,NU=TN,MU=MN,_U=RN,RU=PN,PU=ON,OU=AN,IU=FN,ux="DropdownMenu",[AU]=us(ux,[vN]),pr=vN(),[DU,$N]=AU(ux),dx=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:s,defaultOpen:o,onOpenChange:l,modal:u=!0}=e,d=pr(t),f=y.useRef(null),[h=!1,m]=ya({prop:s,defaultProp:o,onChange:l});return i.jsx(DU,{scope:t,triggerId:Es(),triggerRef:f,contentId:Es(),open:h,onOpenChange:m,onOpenToggle:y.useCallback(()=>m(g=>!g),[m]),modal:u,children:i.jsx(xU,{...d,open:h,onOpenChange:m,dir:r,modal:u,children:n})})};dx.displayName=ux;var BN="DropdownMenuTrigger",fx=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...s}=e,o=$N(BN,n),l=pr(n);return i.jsx(wU,{asChild:!0,...l,children:i.jsx(rt.button,{type:"button",id:o.triggerId,"aria-haspopup":"menu","aria-expanded":o.open,"aria-controls":o.open?o.contentId:void 0,"data-state":o.open?"open":"closed","data-disabled":r?"":void 0,disabled:r,...s,ref:kh(t,o.triggerRef),onPointerDown:Ue(e.onPointerDown,u=>{!r&&u.button===0&&u.ctrlKey===!1&&(o.onOpenToggle(),o.open||u.preventDefault())}),onKeyDown:Ue(e.onKeyDown,u=>{r||(["Enter"," "].includes(u.key)&&o.onOpenToggle(),u.key==="ArrowDown"&&o.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(u.key)&&u.preventDefault())})})})});fx.displayName=BN;var FU="DropdownMenuPortal",zN=e=>{const{__scopeDropdownMenu:t,...n}=e,r=pr(t);return i.jsx(SU,{...r,...n})};zN.displayName=FU;var UN="DropdownMenuContent",VN=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,s=$N(UN,n),o=pr(n),l=y.useRef(!1);return i.jsx(CU,{id:s.contentId,"aria-labelledby":s.triggerId,...o,...r,ref:t,onCloseAutoFocus:Ue(e.onCloseAutoFocus,u=>{l.current||s.triggerRef.current?.focus(),l.current=!1,u.preventDefault()}),onInteractOutside:Ue(e.onInteractOutside,u=>{const d=u.detail.originalEvent,f=d.button===0&&d.ctrlKey===!0,h=d.button===2||f;(!s.modal||h)&&(l.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});VN.displayName=UN;var LU="DropdownMenuGroup",$U=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,s=pr(n);return i.jsx(EU,{...s,...r,ref:t})});$U.displayName=LU;var BU="DropdownMenuLabel",HN=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,s=pr(n);return i.jsx(kU,{...s,...r,ref:t})});HN.displayName=BU;var zU="DropdownMenuItem",qN=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,s=pr(n);return i.jsx(jU,{...s,...r,ref:t})});qN.displayName=zU;var UU="DropdownMenuCheckboxItem",KN=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,s=pr(n);return i.jsx(TU,{...s,...r,ref:t})});KN.displayName=UU;var VU="DropdownMenuRadioGroup",HU=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,s=pr(n);return i.jsx(NU,{...s,...r,ref:t})});HU.displayName=VU;var qU="DropdownMenuRadioItem",WN=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,s=pr(n);return i.jsx(MU,{...s,...r,ref:t})});WN.displayName=qU;var KU="DropdownMenuItemIndicator",GN=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,s=pr(n);return i.jsx(_U,{...s,...r,ref:t})});GN.displayName=KU;var WU="DropdownMenuSeparator",JN=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,s=pr(n);return i.jsx(RU,{...s,...r,ref:t})});JN.displayName=WU;var GU="DropdownMenuArrow",JU=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,s=pr(n);return i.jsx(PU,{...s,...r,ref:t})});JU.displayName=GU;var QU="DropdownMenuSubTrigger",QN=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,s=pr(n);return i.jsx(OU,{...s,...r,ref:t})});QN.displayName=QU;var ZU="DropdownMenuSubContent",ZN=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,s=pr(n);return i.jsx(IU,{...s,...r,ref:t,style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});ZN.displayName=ZU;var YU=dx,XU=fx,e5=zN,YN=VN,XN=HN,eM=qN,tM=KN,nM=WN,rM=GN,Oa=JN,sM=QN,oM=ZN;const Kr=YU,Wr=XU,t5=y.forwardRef(({className:e,inset:t,children:n,...r},s)=>i.jsxs(sM,{ref:s,className:Ie("flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent",t&&"pl-8",e),...r,children:[n,i.jsx(W$,{className:"ml-auto h-4 w-4"})]}));t5.displayName=sM.displayName;const n5=y.forwardRef(({className:e,...t},n)=>i.jsx(oM,{ref:n,className:Ie("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...t}));n5.displayName=oM.displayName;const hr=y.forwardRef(({className:e,sideOffset:t=4,...n},r)=>i.jsx(e5,{children:i.jsx(YN,{ref:r,sideOffset:t,className:Ie("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...n})}));hr.displayName=YN.displayName;const wt=y.forwardRef(({className:e,inset:t,...n},r)=>i.jsx(eM,{ref:r,className:Ie("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t&&"pl-8",e),...n}));wt.displayName=eM.displayName;const aM=y.forwardRef(({className:e,children:t,checked:n,...r},s)=>i.jsxs(tM,{ref:s,className:Ie("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),checked:n,...r,children:[i.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:i.jsx(rM,{children:i.jsx(fT,{className:"h-4 w-4"})})}),t]}));aM.displayName=tM.displayName;const r5=y.forwardRef(({className:e,children:t,...n},r)=>i.jsxs(nM,{ref:r,className:Ie("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[i.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:i.jsx(rM,{children:i.jsx(Z$,{className:"h-2 w-2 fill-current"})})}),t]}));r5.displayName=nM.displayName;const Ao=y.forwardRef(({className:e,inset:t,...n},r)=>i.jsx(XN,{ref:r,className:Ie("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));Ao.displayName=XN.displayName;const Xs=y.forwardRef(({className:e,...t},n)=>i.jsx(Oa,{ref:n,className:Ie("-mx-1 my-1 h-px bg-muted",e),...t}));Xs.displayName=Oa.displayName;function iM(){const{t:e,i18n:t}=Ve(),n=r=>{t.changeLanguage(r),localStorage.setItem("i18nextLng",r),window.location.reload()};return i.jsxs(Kr,{children:[i.jsx(Wr,{asChild:!0,children:i.jsxs(se,{variant:"outline",size:"icon",children:[i.jsx(fB,{className:"h-[1.2rem] w-[1.2rem] rotate-0 scale-100 transition-all"}),i.jsx("span",{className:"sr-only",children:e("header.theme.label")})]})}),i.jsxs(hr,{align:"end",children:[i.jsx(wt,{className:t.language==="pt-BR"?"font-bold":"",onClick:()=>n("pt-BR"),children:e("header.language.portuguese")}),i.jsx(wt,{className:t.language==="en-US"?"font-bold":"",onClick:()=>n("en-US"),children:e("header.language.english")}),i.jsx(wt,{className:t.language==="es-ES"?"font-bold":"",onClick:()=>n("es-ES"),children:e("header.language.spanish")}),i.jsx(wt,{className:t.language==="fr-FR"?"font-bold":"",onClick:()=>n("fr-FR"),children:e("header.language.french")})]})]})}function lM(){const{t:e}=Ve(),{setTheme:t}=tc();return i.jsxs(Kr,{children:[i.jsx(Wr,{asChild:!0,children:i.jsxs(se,{variant:"outline",size:"icon",children:[i.jsx(EB,{className:"h-[1.2rem] w-[1.2rem] rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0"}),i.jsx(bB,{className:"absolute h-[1.2rem] w-[1.2rem] rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100"}),i.jsx("span",{className:"sr-only",children:e("header.theme.label")})]})}),i.jsxs(hr,{align:"end",children:[i.jsx(wt,{onClick:()=>t("light"),children:e("header.theme.light")}),i.jsx(wt,{onClick:()=>t("dark"),children:e("header.theme.dark")}),i.jsx(wt,{onClick:()=>t("system"),children:e("header.theme.system")})]})]})}var px="Avatar",[s5]=us(px),[o5,cM]=s5(px),uM=y.forwardRef((e,t)=>{const{__scopeAvatar:n,...r}=e,[s,o]=y.useState("idle");return i.jsx(o5,{scope:n,imageLoadingStatus:s,onImageLoadingStatusChange:o,children:i.jsx(rt.span,{...r,ref:t})})});uM.displayName=px;var dM="AvatarImage",fM=y.forwardRef((e,t)=>{const{__scopeAvatar:n,src:r,onLoadingStatusChange:s=()=>{},...o}=e,l=cM(dM,n),u=a5(r),d=Rn(f=>{s(f),l.onImageLoadingStatusChange(f)});return Ln(()=>{u!=="idle"&&d(u)},[u,d]),u==="loaded"?i.jsx(rt.img,{...o,ref:t,src:r}):null});fM.displayName=dM;var pM="AvatarFallback",hM=y.forwardRef((e,t)=>{const{__scopeAvatar:n,delayMs:r,...s}=e,o=cM(pM,n),[l,u]=y.useState(r===void 0);return y.useEffect(()=>{if(r!==void 0){const d=window.setTimeout(()=>u(!0),r);return()=>window.clearTimeout(d)}},[r]),l&&o.imageLoadingStatus!=="loaded"?i.jsx(rt.span,{...s,ref:t}):null});hM.displayName=pM;function a5(e){const[t,n]=y.useState("idle");return Ln(()=>{if(!e){n("error");return}let r=!0;const s=new window.Image,o=l=>()=>{r&&n(l)};return n("loading"),s.onload=o("loaded"),s.onerror=o("error"),s.src=e,()=>{r=!1}},[e]),t}var gM=uM,mM=fM,vM=hM;const Ei=y.forwardRef(({className:e,...t},n)=>i.jsx(gM,{ref:n,className:Ie("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",e),...t}));Ei.displayName=gM.displayName;const ki=y.forwardRef(({className:e,...t},n)=>i.jsx(mM,{ref:n,className:Ie("aspect-square h-full w-full",e),...t}));ki.displayName=mM.displayName;const Up=y.forwardRef(({className:e,...t},n)=>i.jsx(vM,{ref:n,className:Ie("flex h-full w-full items-center justify-center rounded-full bg-muted",e),...t}));Up.displayName=vM.displayName;var hx="Dialog",[yM]=us(hx),[i5,Ps]=yM(hx),bM=e=>{const{__scopeDialog:t,children:n,open:r,defaultOpen:s,onOpenChange:o,modal:l=!0}=e,u=y.useRef(null),d=y.useRef(null),[f=!1,h]=ya({prop:r,defaultProp:s,onChange:o});return i.jsx(i5,{scope:t,triggerRef:u,contentRef:d,contentId:Es(),titleId:Es(),descriptionId:Es(),open:f,onOpenChange:h,onOpenToggle:y.useCallback(()=>h(m=>!m),[h]),modal:l,children:n})};bM.displayName=hx;var xM="DialogTrigger",wM=y.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,s=Ps(xM,n),o=Rt(t,s.triggerRef);return i.jsx(rt.button,{type:"button","aria-haspopup":"dialog","aria-expanded":s.open,"aria-controls":s.contentId,"data-state":vx(s.open),...r,ref:o,onClick:Ue(e.onClick,s.onOpenToggle)})});wM.displayName=xM;var gx="DialogPortal",[l5,SM]=yM(gx,{forceMount:void 0}),CM=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:s}=e,o=Ps(gx,t);return i.jsx(l5,{scope:t,forceMount:n,children:y.Children.map(r,l=>i.jsx(Mr,{present:n||o.open,children:i.jsx(Ih,{asChild:!0,container:s,children:l})}))})};CM.displayName=gx;var Vp="DialogOverlay",EM=y.forwardRef((e,t)=>{const n=SM(Vp,e.__scopeDialog),{forceMount:r=n.forceMount,...s}=e,o=Ps(Vp,e.__scopeDialog);return o.modal?i.jsx(Mr,{present:r||o.open,children:i.jsx(c5,{...s,ref:t})}):null});EM.displayName=Vp;var c5=y.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,s=Ps(Vp,n);return i.jsx(Lh,{as:No,allowPinchZoom:!0,shards:[s.contentRef],children:i.jsx(rt.div,{"data-state":vx(s.open),...r,ref:t,style:{pointerEvents:"auto",...r.style}})})}),ji="DialogContent",kM=y.forwardRef((e,t)=>{const n=SM(ji,e.__scopeDialog),{forceMount:r=n.forceMount,...s}=e,o=Ps(ji,e.__scopeDialog);return i.jsx(Mr,{present:r||o.open,children:o.modal?i.jsx(u5,{...s,ref:t}):i.jsx(d5,{...s,ref:t})})});kM.displayName=ji;var u5=y.forwardRef((e,t)=>{const n=Ps(ji,e.__scopeDialog),r=y.useRef(null),s=Rt(t,n.contentRef,r);return y.useEffect(()=>{const o=r.current;if(o)return nx(o)},[]),i.jsx(jM,{...e,ref:s,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Ue(e.onCloseAutoFocus,o=>{o.preventDefault(),n.triggerRef.current?.focus()}),onPointerDownOutside:Ue(e.onPointerDownOutside,o=>{const l=o.detail.originalEvent,u=l.button===0&&l.ctrlKey===!0;(l.button===2||u)&&o.preventDefault()}),onFocusOutside:Ue(e.onFocusOutside,o=>o.preventDefault())})}),d5=y.forwardRef((e,t)=>{const n=Ps(ji,e.__scopeDialog),r=y.useRef(!1),s=y.useRef(!1);return i.jsx(jM,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:o=>{e.onCloseAutoFocus?.(o),o.defaultPrevented||(r.current||n.triggerRef.current?.focus(),o.preventDefault()),r.current=!1,s.current=!1},onInteractOutside:o=>{e.onInteractOutside?.(o),o.defaultPrevented||(r.current=!0,o.detail.originalEvent.type==="pointerdown"&&(s.current=!0));const l=o.target;n.triggerRef.current?.contains(l)&&o.preventDefault(),o.detail.originalEvent.type==="focusin"&&s.current&&o.preventDefault()}})}),jM=y.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:s,onCloseAutoFocus:o,...l}=e,u=Ps(ji,n),d=y.useRef(null),f=Rt(t,d);return Wb(),i.jsxs(i.Fragment,{children:[i.jsx(_h,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:s,onUnmountAutoFocus:o,children:i.jsx(Mh,{role:"dialog",id:u.contentId,"aria-describedby":u.descriptionId,"aria-labelledby":u.titleId,"data-state":vx(u.open),...l,ref:f,onDismiss:()=>u.onOpenChange(!1)})}),i.jsxs(i.Fragment,{children:[i.jsx(f5,{titleId:u.titleId}),i.jsx(h5,{contentRef:d,descriptionId:u.descriptionId})]})]})}),mx="DialogTitle",TM=y.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,s=Ps(mx,n);return i.jsx(rt.h2,{id:s.titleId,...r,ref:t})});TM.displayName=mx;var NM="DialogDescription",MM=y.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,s=Ps(NM,n);return i.jsx(rt.p,{id:s.descriptionId,...r,ref:t})});MM.displayName=NM;var _M="DialogClose",RM=y.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,s=Ps(_M,n);return i.jsx(rt.button,{type:"button",...r,ref:t,onClick:Ue(e.onClick,()=>s.onOpenChange(!1))})});RM.displayName=_M;function vx(e){return e?"open":"closed"}var PM="DialogTitleWarning",[Sie,OM]=_B(PM,{contentName:ji,titleName:mx,docsSlug:"dialog"}),f5=({titleId:e})=>{const t=OM(PM),n=`\`${t.contentName}\` requires a \`${t.titleName}\` for the component to be accessible for screen reader users. If you want to hide the \`${t.titleName}\`, you can wrap it with our VisuallyHidden component. For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return y.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},p5="DialogDescriptionWarning",h5=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${OM(p5).contentName}}.`;return y.useEffect(()=>{const s=e.current?.getAttribute("aria-describedby");t&&s&&(document.getElementById(t)||console.warn(r))},[r,e,t]),null},g5=bM,m5=wM,v5=CM,IM=EM,AM=kM,DM=TM,FM=MM,LM=RM;const Pt=g5,Bt=m5,y5=v5,$M=LM,BM=y.forwardRef(({className:e,...t},n)=>i.jsx(IM,{ref:n,className:Ie("fixed inset-0 z-50 bg-background/80 backdrop-blur-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",e),...t}));BM.displayName=IM.displayName;const Nt=y.forwardRef(({className:e,children:t,closeBtn:n=!0,...r},s)=>i.jsx(y5,{children:i.jsx(BM,{className:"fixed inset-0 grid place-items-center overflow-y-auto",children:i.jsxs(AM,{ref:s,className:Ie("relative z-50 grid w-full max-w-lg gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:m-4 sm:rounded-lg md:w-full",e),...r,children:[t,n&&i.jsxs(LM,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[i.jsx(qb,{className:"h-4 w-4"}),i.jsx("span",{className:"sr-only",children:"Close"})]})]})})}));Nt.displayName=AM.displayName;const Mt=({className:e,...t})=>i.jsx("div",{className:Ie("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});Mt.displayName="DialogHeader";const Yt=({className:e,...t})=>i.jsx("div",{className:Ie("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",e),...t});Yt.displayName="DialogFooter";const zt=y.forwardRef(({className:e,...t},n)=>i.jsx(DM,{ref:n,className:Ie("text-lg font-semibold leading-none tracking-tight",e),...t}));zt.displayName=DM.displayName;const eo=y.forwardRef(({className:e,...t},n)=>i.jsx(FM,{ref:n,className:Ie("text-sm text-muted-foreground",e),...t}));eo.displayName=FM.displayName;function zM({instanceId:e}){const[t,n]=y.useState(!1),r=dn(),{theme:s}=tc(),o=()=>{Pj(),r("/manager/login")},l=()=>{r("/manager/")},{data:u}=vT({instanceId:e});return i.jsxs("header",{className:"flex items-center justify-between px-4 py-2",children:[i.jsx(Fu,{to:"/manager",onClick:l,className:"flex h-8 items-center gap-4",children:i.jsx("img",{src:s==="dark"?"https://evolution-api.com/files/evo/evolution-logo-white.svg":"https://evolution-api.com/files/evo/evolution-logo.svg",alt:"Logo",className:"h-full"})}),i.jsxs("div",{className:"flex items-center gap-4",children:[e&&i.jsx(Ei,{className:"h-8 w-8",children:i.jsx(ki,{src:u?.profilePicUrl||"/assets/images/evolution-logo.png",alt:u?.name})}),i.jsx(iM,{}),i.jsx(lM,{}),i.jsx(se,{onClick:()=>n(!0),variant:"destructive",size:"icon",children:i.jsx(eB,{size:"18"})})]}),t&&i.jsx(Pt,{onOpenChange:n,open:t,children:i.jsxs(Nt,{children:[i.jsx($M,{}),i.jsx(Mt,{children:"Deseja realmente sair?"}),i.jsx(Yt,{children:i.jsxs("div",{className:"flex items-center gap-4",children:[i.jsx(se,{onClick:()=>n(!1),size:"sm",variant:"outline",children:"Cancelar"}),i.jsx(se,{onClick:o,variant:"destructive",children:"Sair"})]})})]})})]})}const UM=y.createContext(null),ct=()=>{const e=y.useContext(UM);if(!e)throw new Error("useInstance must be used within an InstanceProvider");return e},VM=({children:e})=>{const t=ls(),[n,r]=y.useState(null),{data:s,refetch:o}=vT({instanceId:n});return y.useEffect(()=>{t.instanceId?r(t.instanceId):r(null)},[t]),i.jsx(UM.Provider,{value:{instance:s??null,reloadInstance:async()=>{await o()}},children:e})};var yx="Collapsible",[b5]=us(yx),[x5,bx]=b5(yx),HM=y.forwardRef((e,t)=>{const{__scopeCollapsible:n,open:r,defaultOpen:s,disabled:o,onOpenChange:l,...u}=e,[d=!1,f]=ya({prop:r,defaultProp:s,onChange:l});return i.jsx(x5,{scope:n,disabled:o,contentId:Es(),open:d,onOpenToggle:y.useCallback(()=>f(h=>!h),[f]),children:i.jsx(rt.div,{"data-state":wx(d),"data-disabled":o?"":void 0,...u,ref:t})})});HM.displayName=yx;var qM="CollapsibleTrigger",KM=y.forwardRef((e,t)=>{const{__scopeCollapsible:n,...r}=e,s=bx(qM,n);return i.jsx(rt.button,{type:"button","aria-controls":s.contentId,"aria-expanded":s.open||!1,"data-state":wx(s.open),"data-disabled":s.disabled?"":void 0,disabled:s.disabled,...r,ref:t,onClick:Ue(e.onClick,s.onOpenToggle)})});KM.displayName=qM;var xx="CollapsibleContent",WM=y.forwardRef((e,t)=>{const{forceMount:n,...r}=e,s=bx(xx,e.__scopeCollapsible);return i.jsx(Mr,{present:n||s.open,children:({present:o})=>i.jsx(w5,{...r,ref:t,present:o})})});WM.displayName=xx;var w5=y.forwardRef((e,t)=>{const{__scopeCollapsible:n,present:r,children:s,...o}=e,l=bx(xx,n),[u,d]=y.useState(r),f=y.useRef(null),h=Rt(t,f),m=y.useRef(0),g=m.current,x=y.useRef(0),b=x.current,w=l.open||u,C=y.useRef(w),k=y.useRef();return y.useEffect(()=>{const j=requestAnimationFrame(()=>C.current=!1);return()=>cancelAnimationFrame(j)},[]),Ln(()=>{const j=f.current;if(j){k.current=k.current||{transitionDuration:j.style.transitionDuration,animationName:j.style.animationName},j.style.transitionDuration="0s",j.style.animationName="none";const M=j.getBoundingClientRect();m.current=M.height,x.current=M.width,C.current||(j.style.transitionDuration=k.current.transitionDuration,j.style.animationName=k.current.animationName),d(r)}},[l.open,r]),i.jsx(rt.div,{"data-state":wx(l.open),"data-disabled":l.disabled?"":void 0,id:l.contentId,hidden:!w,...o,ref:h,style:{"--radix-collapsible-content-height":g?`${g}px`:void 0,"--radix-collapsible-content-width":b?`${b}px`:void 0,...e.style},children:w&&s})});function wx(e){return e?"open":"closed"}var S5=HM;const C5=S5,E5=KM,k5=WM;function j5(){const{t:e}=Ve(),t=y.useMemo(()=>[{id:"dashboard",title:e("sidebar.dashboard"),icon:pB,path:"dashboard"},{id:"chat",title:e("sidebar.chat"),icon:Bl,path:"chat"},{navLabel:!0,title:e("sidebar.configurations"),icon:Oo,children:[{id:"settings",title:e("sidebar.settings"),path:"settings"},{id:"proxy",title:e("sidebar.proxy"),path:"proxy"}]},{title:e("sidebar.events"),icon:dB,children:[{id:"webhook",title:e("sidebar.webhook"),path:"webhook"},{id:"websocket",title:e("sidebar.websocket"),path:"websocket"},{id:"rabbitmq",title:e("sidebar.rabbitmq"),path:"rabbitmq"},{id:"sqs",title:e("sidebar.sqs"),path:"sqs"}]},{title:e("sidebar.integrations"),icon:mT,children:[{id:"evoai",title:e("sidebar.evoai"),path:"evoai"},{id:"n8n",title:e("sidebar.n8n"),path:"n8n"},{id:"evolutionBot",title:e("sidebar.evolutionBot"),path:"evolutionBot"},{id:"chatwoot",title:e("sidebar.chatwoot"),path:"chatwoot"},{id:"typebot",title:e("sidebar.typebot"),path:"typebot"},{id:"openai",title:e("sidebar.openai"),path:"openai"},{id:"dify",title:e("sidebar.dify"),path:"dify"},{id:"flowise",title:e("sidebar.flowise"),path:"flowise"}]},{id:"documentation",title:e("sidebar.documentation"),icon:sB,link:"https://doc.evolution-api.com",divider:!0},{id:"postman",title:e("sidebar.postman"),icon:Q$,link:"https://evolution-api.com/postman"},{id:"discord",title:e("sidebar.discord"),icon:Bl,link:"https://evolution-api.com/discord"},{id:"support-premium",title:e("sidebar.supportPremium"),icon:hB,link:"https://evolution-api.com/suporte-pro"}],[e]),n=dn(),{pathname:r}=Pi(),{instance:s}=ct(),o=u=>{!u||!s||(u.path&&n(`/manager/instance/${s.id}/${u.path}`),u.link&&window.open(u.link,"_blank"))},l=y.useMemo(()=>t.map(u=>({...u,children:"children"in u?u.children?.map(d=>({...d,isActive:"path"in d?r.includes(d.path):!1})):void 0,isActive:"path"in u&&u.path?r.includes(u.path):!1})).map(u=>({...u,isActive:u.isActive||"children"in u&&u.children?.some(d=>d.isActive)})),[t,r]);return i.jsx("ul",{className:"flex h-full w-full flex-col gap-2 border-r border-border px-2",children:l.map(u=>i.jsx("li",{className:"divider"in u?"mt-auto":void 0,children:u.children?i.jsxs(C5,{defaultOpen:u.isActive,children:[i.jsx(E5,{asChild:!0,children:i.jsxs(se,{className:Ie("flex w-full items-center justify-start gap-2"),variant:u.isActive?"secondary":"link",children:[u.icon&&i.jsx(u.icon,{size:"15"}),i.jsx("span",{children:u.title}),i.jsx(Nh,{size:"15",className:"ml-auto"})]})}),i.jsx(k5,{children:i.jsx("ul",{className:"my-4 ml-6 flex flex-col gap-2 text-sm",children:u.children.map(d=>i.jsx("li",{children:i.jsx("button",{onClick:()=>o(d),className:Ie(d.isActive?"text-foreground":"text-muted-foreground"),children:i.jsx("span",{className:"nav-label",children:d.title})})},d.id))})})]}):i.jsxs(se,{className:Ie("relative flex w-full items-center justify-start gap-2",u.isActive&&"pointer-events-none"),variant:u.isActive?"secondary":"link",children:["link"in u&&i.jsx("a",{href:u.link,target:"_blank",rel:"noreferrer",className:"absolute inset-0 h-full w-full"}),"path"in u&&i.jsx(Fu,{to:`/manager/instance/${s?.id}/${u.path}`,className:"absolute inset-0 h-full w-full"}),u.icon&&i.jsx(u.icon,{size:"15"}),i.jsx("span",{children:u.title})]})},u.title))})}function Ky(e,[t,n]){return Math.min(n,Math.max(t,e))}function T5(e,t){return y.useReducer((n,r)=>t[n][r]??n,e)}var Sx="ScrollArea",[GM]=us(Sx),[N5,ds]=GM(Sx),JM=y.forwardRef((e,t)=>{const{__scopeScrollArea:n,type:r="hover",dir:s,scrollHideDelay:o=600,...l}=e,[u,d]=y.useState(null),[f,h]=y.useState(null),[m,g]=y.useState(null),[x,b]=y.useState(null),[w,C]=y.useState(null),[k,j]=y.useState(0),[M,_]=y.useState(0),[R,N]=y.useState(!1),[O,D]=y.useState(!1),z=Rt(t,pe=>d(pe)),Q=xd(s);return i.jsx(N5,{scope:n,type:r,dir:Q,scrollHideDelay:o,scrollArea:u,viewport:f,onViewportChange:h,content:m,onContentChange:g,scrollbarX:x,onScrollbarXChange:b,scrollbarXEnabled:R,onScrollbarXEnabledChange:N,scrollbarY:w,onScrollbarYChange:C,scrollbarYEnabled:O,onScrollbarYEnabledChange:D,onCornerWidthChange:j,onCornerHeightChange:_,children:i.jsx(rt.div,{dir:Q,...l,ref:z,style:{position:"relative","--radix-scroll-area-corner-width":k+"px","--radix-scroll-area-corner-height":M+"px",...e.style}})})});JM.displayName=Sx;var QM="ScrollAreaViewport",ZM=y.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:s,...o}=e,l=ds(QM,n),u=y.useRef(null),d=Rt(t,u,l.onViewportChange);return i.jsxs(i.Fragment,{children:[i.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-scroll-area-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-scroll-area-viewport]::-webkit-scrollbar{display:none}"},nonce:s}),i.jsx(rt.div,{"data-radix-scroll-area-viewport":"",...o,ref:d,style:{overflowX:l.scrollbarXEnabled?"scroll":"hidden",overflowY:l.scrollbarYEnabled?"scroll":"hidden",...e.style},children:i.jsx("div",{ref:l.onContentChange,style:{minWidth:"100%",display:"table"},children:r})})]})});ZM.displayName=QM;var to="ScrollAreaScrollbar",Cx=y.forwardRef((e,t)=>{const{forceMount:n,...r}=e,s=ds(to,e.__scopeScrollArea),{onScrollbarXEnabledChange:o,onScrollbarYEnabledChange:l}=s,u=e.orientation==="horizontal";return y.useEffect(()=>(u?o(!0):l(!0),()=>{u?o(!1):l(!1)}),[u,o,l]),s.type==="hover"?i.jsx(M5,{...r,ref:t,forceMount:n}):s.type==="scroll"?i.jsx(_5,{...r,ref:t,forceMount:n}):s.type==="auto"?i.jsx(YM,{...r,ref:t,forceMount:n}):s.type==="always"?i.jsx(Ex,{...r,ref:t}):null});Cx.displayName=to;var M5=y.forwardRef((e,t)=>{const{forceMount:n,...r}=e,s=ds(to,e.__scopeScrollArea),[o,l]=y.useState(!1);return y.useEffect(()=>{const u=s.scrollArea;let d=0;if(u){const f=()=>{window.clearTimeout(d),l(!0)},h=()=>{d=window.setTimeout(()=>l(!1),s.scrollHideDelay)};return u.addEventListener("pointerenter",f),u.addEventListener("pointerleave",h),()=>{window.clearTimeout(d),u.removeEventListener("pointerenter",f),u.removeEventListener("pointerleave",h)}}},[s.scrollArea,s.scrollHideDelay]),i.jsx(Mr,{present:n||o,children:i.jsx(YM,{"data-state":o?"visible":"hidden",...r,ref:t})})}),_5=y.forwardRef((e,t)=>{const{forceMount:n,...r}=e,s=ds(to,e.__scopeScrollArea),o=e.orientation==="horizontal",l=Uh(()=>d("SCROLL_END"),100),[u,d]=T5("hidden",{hidden:{SCROLL:"scrolling"},scrolling:{SCROLL_END:"idle",POINTER_ENTER:"interacting"},interacting:{SCROLL:"interacting",POINTER_LEAVE:"idle"},idle:{HIDE:"hidden",SCROLL:"scrolling",POINTER_ENTER:"interacting"}});return y.useEffect(()=>{if(u==="idle"){const f=window.setTimeout(()=>d("HIDE"),s.scrollHideDelay);return()=>window.clearTimeout(f)}},[u,s.scrollHideDelay,d]),y.useEffect(()=>{const f=s.viewport,h=o?"scrollLeft":"scrollTop";if(f){let m=f[h];const g=()=>{const x=f[h];m!==x&&(d("SCROLL"),l()),m=x};return f.addEventListener("scroll",g),()=>f.removeEventListener("scroll",g)}},[s.viewport,o,d,l]),i.jsx(Mr,{present:n||u!=="hidden",children:i.jsx(Ex,{"data-state":u==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:Ue(e.onPointerEnter,()=>d("POINTER_ENTER")),onPointerLeave:Ue(e.onPointerLeave,()=>d("POINTER_LEAVE"))})})}),YM=y.forwardRef((e,t)=>{const n=ds(to,e.__scopeScrollArea),{forceMount:r,...s}=e,[o,l]=y.useState(!1),u=e.orientation==="horizontal",d=Uh(()=>{if(n.viewport){const f=n.viewport.offsetWidth{const{orientation:n="vertical",...r}=e,s=ds(to,e.__scopeScrollArea),o=y.useRef(null),l=y.useRef(0),[u,d]=y.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),f=r_(u.viewport,u.content),h={...r,sizes:u,onSizesChange:d,hasThumb:f>0&&f<1,onThumbChange:g=>o.current=g,onThumbPointerUp:()=>l.current=0,onThumbPointerDown:g=>l.current=g};function m(g,x){return D5(g,l.current,u,x)}return n==="horizontal"?i.jsx(R5,{...h,ref:t,onThumbPositionChange:()=>{if(s.viewport&&o.current){const g=s.viewport.scrollLeft,x=p1(g,u,s.dir);o.current.style.transform=`translate3d(${x}px, 0, 0)`}},onWheelScroll:g=>{s.viewport&&(s.viewport.scrollLeft=g)},onDragScroll:g=>{s.viewport&&(s.viewport.scrollLeft=m(g,s.dir))}}):n==="vertical"?i.jsx(P5,{...h,ref:t,onThumbPositionChange:()=>{if(s.viewport&&o.current){const g=s.viewport.scrollTop,x=p1(g,u);o.current.style.transform=`translate3d(0, ${x}px, 0)`}},onWheelScroll:g=>{s.viewport&&(s.viewport.scrollTop=g)},onDragScroll:g=>{s.viewport&&(s.viewport.scrollTop=m(g))}}):null}),R5=y.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...s}=e,o=ds(to,e.__scopeScrollArea),[l,u]=y.useState(),d=y.useRef(null),f=Rt(t,d,o.onScrollbarXChange);return y.useEffect(()=>{d.current&&u(getComputedStyle(d.current))},[d]),i.jsx(e_,{"data-orientation":"horizontal",...s,ref:f,sizes:n,style:{bottom:0,left:o.dir==="rtl"?"var(--radix-scroll-area-corner-width)":0,right:o.dir==="ltr"?"var(--radix-scroll-area-corner-width)":0,"--radix-scroll-area-thumb-width":zh(n)+"px",...e.style},onThumbPointerDown:h=>e.onThumbPointerDown(h.x),onDragScroll:h=>e.onDragScroll(h.x),onWheelScroll:(h,m)=>{if(o.viewport){const g=o.viewport.scrollLeft+h.deltaX;e.onWheelScroll(g),o_(g,m)&&h.preventDefault()}},onResize:()=>{d.current&&o.viewport&&l&&r({content:o.viewport.scrollWidth,viewport:o.viewport.offsetWidth,scrollbar:{size:d.current.clientWidth,paddingStart:qp(l.paddingLeft),paddingEnd:qp(l.paddingRight)}})}})}),P5=y.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...s}=e,o=ds(to,e.__scopeScrollArea),[l,u]=y.useState(),d=y.useRef(null),f=Rt(t,d,o.onScrollbarYChange);return y.useEffect(()=>{d.current&&u(getComputedStyle(d.current))},[d]),i.jsx(e_,{"data-orientation":"vertical",...s,ref:f,sizes:n,style:{top:0,right:o.dir==="ltr"?0:void 0,left:o.dir==="rtl"?0:void 0,bottom:"var(--radix-scroll-area-corner-height)","--radix-scroll-area-thumb-height":zh(n)+"px",...e.style},onThumbPointerDown:h=>e.onThumbPointerDown(h.y),onDragScroll:h=>e.onDragScroll(h.y),onWheelScroll:(h,m)=>{if(o.viewport){const g=o.viewport.scrollTop+h.deltaY;e.onWheelScroll(g),o_(g,m)&&h.preventDefault()}},onResize:()=>{d.current&&o.viewport&&l&&r({content:o.viewport.scrollHeight,viewport:o.viewport.offsetHeight,scrollbar:{size:d.current.clientHeight,paddingStart:qp(l.paddingTop),paddingEnd:qp(l.paddingBottom)}})}})}),[O5,XM]=GM(to),e_=y.forwardRef((e,t)=>{const{__scopeScrollArea:n,sizes:r,hasThumb:s,onThumbChange:o,onThumbPointerUp:l,onThumbPointerDown:u,onThumbPositionChange:d,onDragScroll:f,onWheelScroll:h,onResize:m,...g}=e,x=ds(to,n),[b,w]=y.useState(null),C=Rt(t,z=>w(z)),k=y.useRef(null),j=y.useRef(""),M=x.viewport,_=r.content-r.viewport,R=Rn(h),N=Rn(d),O=Uh(m,10);function D(z){if(k.current){const Q=z.clientX-k.current.left,pe=z.clientY-k.current.top;f({x:Q,y:pe})}}return y.useEffect(()=>{const z=Q=>{const pe=Q.target;b?.contains(pe)&&R(Q,_)};return document.addEventListener("wheel",z,{passive:!1}),()=>document.removeEventListener("wheel",z,{passive:!1})},[M,b,_,R]),y.useEffect(N,[r,N]),Ul(b,O),Ul(x.content,O),i.jsx(O5,{scope:n,scrollbar:b,hasThumb:s,onThumbChange:Rn(o),onThumbPointerUp:Rn(l),onThumbPositionChange:N,onThumbPointerDown:Rn(u),children:i.jsx(rt.div,{...g,ref:C,style:{position:"absolute",...g.style},onPointerDown:Ue(e.onPointerDown,z=>{z.button===0&&(z.target.setPointerCapture(z.pointerId),k.current=b.getBoundingClientRect(),j.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",x.viewport&&(x.viewport.style.scrollBehavior="auto"),D(z))}),onPointerMove:Ue(e.onPointerMove,D),onPointerUp:Ue(e.onPointerUp,z=>{const Q=z.target;Q.hasPointerCapture(z.pointerId)&&Q.releasePointerCapture(z.pointerId),document.body.style.webkitUserSelect=j.current,x.viewport&&(x.viewport.style.scrollBehavior=""),k.current=null})})})}),Hp="ScrollAreaThumb",t_=y.forwardRef((e,t)=>{const{forceMount:n,...r}=e,s=XM(Hp,e.__scopeScrollArea);return i.jsx(Mr,{present:n||s.hasThumb,children:i.jsx(I5,{ref:t,...r})})}),I5=y.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...s}=e,o=ds(Hp,n),l=XM(Hp,n),{onThumbPositionChange:u}=l,d=Rt(t,m=>l.onThumbChange(m)),f=y.useRef(),h=Uh(()=>{f.current&&(f.current(),f.current=void 0)},100);return y.useEffect(()=>{const m=o.viewport;if(m){const g=()=>{if(h(),!f.current){const x=F5(m,u);f.current=x,u()}};return u(),m.addEventListener("scroll",g),()=>m.removeEventListener("scroll",g)}},[o.viewport,h,u]),i.jsx(rt.div,{"data-state":l.hasThumb?"visible":"hidden",...s,ref:d,style:{width:"var(--radix-scroll-area-thumb-width)",height:"var(--radix-scroll-area-thumb-height)",...r},onPointerDownCapture:Ue(e.onPointerDownCapture,m=>{const x=m.target.getBoundingClientRect(),b=m.clientX-x.left,w=m.clientY-x.top;l.onThumbPointerDown({x:b,y:w})}),onPointerUp:Ue(e.onPointerUp,l.onThumbPointerUp)})});t_.displayName=Hp;var kx="ScrollAreaCorner",n_=y.forwardRef((e,t)=>{const n=ds(kx,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?i.jsx(A5,{...e,ref:t}):null});n_.displayName=kx;var A5=y.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,s=ds(kx,n),[o,l]=y.useState(0),[u,d]=y.useState(0),f=!!(o&&u);return Ul(s.scrollbarX,()=>{const h=s.scrollbarX?.offsetHeight||0;s.onCornerHeightChange(h),d(h)}),Ul(s.scrollbarY,()=>{const h=s.scrollbarY?.offsetWidth||0;s.onCornerWidthChange(h),l(h)}),f?i.jsx(rt.div,{...r,ref:t,style:{width:o,height:u,position:"absolute",right:s.dir==="ltr"?0:void 0,left:s.dir==="rtl"?0:void 0,bottom:0,...e.style}}):null});function qp(e){return e?parseInt(e,10):0}function r_(e,t){const n=e/t;return isNaN(n)?0:n}function zh(e){const t=r_(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function D5(e,t,n,r="ltr"){const s=zh(n),o=s/2,l=t||o,u=s-l,d=n.scrollbar.paddingStart+l,f=n.scrollbar.size-n.scrollbar.paddingEnd-u,h=n.content-n.viewport,m=r==="ltr"?[0,h]:[h*-1,0];return s_([d,f],m)(e)}function p1(e,t,n="ltr"){const r=zh(t),s=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,o=t.scrollbar.size-s,l=t.content-t.viewport,u=o-r,d=n==="ltr"?[0,l]:[l*-1,0],f=Ky(e,d);return s_([0,l],[0,u])(f)}function s_(e,t){return n=>{if(e[0]===e[1]||t[0]===t[1])return t[0];const r=(t[1]-t[0])/(e[1]-e[0]);return t[0]+r*(n-e[0])}}function o_(e,t){return e>0&&e{})=>{let n={left:e.scrollLeft,top:e.scrollTop},r=0;return(function s(){const o={left:e.scrollLeft,top:e.scrollTop},l=n.left!==o.left,u=n.top!==o.top;(l||u)&&t(),n=o,r=window.requestAnimationFrame(s)})(),()=>window.cancelAnimationFrame(r)};function Uh(e,t){const n=Rn(e),r=y.useRef(0);return y.useEffect(()=>()=>window.clearTimeout(r.current),[]),y.useCallback(()=>{window.clearTimeout(r.current),r.current=window.setTimeout(n,t)},[n,t])}function Ul(e,t){const n=Rn(t);Ln(()=>{let r=0;if(e){const s=new ResizeObserver(()=>{cancelAnimationFrame(r),r=window.requestAnimationFrame(n)});return s.observe(e),()=>{window.cancelAnimationFrame(r),s.unobserve(e)}}},[e,n])}var a_=JM,L5=ZM,$5=n_;const Wy=y.forwardRef(({className:e,children:t,...n},r)=>i.jsxs(a_,{ref:r,className:Ie("relative overflow-hidden",e),...n,children:[i.jsx(L5,{className:"h-full w-full rounded-[inherit] [&>div[style]]:!block [&>div[style]]:h-full",children:t}),i.jsx(i_,{}),i.jsx($5,{})]}));Wy.displayName=a_.displayName;const i_=y.forwardRef(({className:e,orientation:t="vertical",...n},r)=>i.jsx(Cx,{ref:r,orientation:t,className:Ie("flex touch-none select-none transition-colors",t==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",t==="horizontal"&&"h-2.5 border-t border-t-transparent p-[1px]",e),...n,children:i.jsx(t_,{className:Ie("relative rounded-full bg-border",t==="vertical"&&"flex-1")})}));i_.displayName=Cx.displayName;function un({children:e}){const{instanceId:t}=ls();return i.jsx(VM,{children:i.jsxs("div",{className:"flex h-screen flex-col",children:[i.jsx(zM,{instanceId:t}),i.jsxs("div",{className:"flex min-h-[calc(100vh_-_56px)] flex-1 flex-col md:flex-row",children:[i.jsx(Wy,{className:"mr-2 py-6 md:w-64",children:i.jsx("div",{className:"flex h-full",children:i.jsx(j5,{})})}),i.jsx(Wy,{className:"w-full",children:i.jsxs("div",{className:"flex h-full flex-col",children:[i.jsx("div",{className:"my-2 flex flex-1 flex-col gap-2 pl-2 pr-4",children:e}),i.jsx(Vb,{})]})})]})]})})}function B5({children:e}){return i.jsxs("div",{className:"flex h-full min-h-screen flex-col",children:[i.jsx(zM,{}),i.jsx("main",{className:"flex-1",children:e}),i.jsx(Vb,{})]})}const z5=jh("inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground hover:bg-primary/80",secondary:"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",outline:"text-foreground",warning:"border-transparent bg-amber-600 text-amber-100 hover:bg-amber-600/80"}},defaultVariants:{variant:"default"}});function vu({className:e,variant:t,...n}){return i.jsx("div",{className:Ie(z5({variant:t}),e),...n})}function l_({status:e}){const{t}=Ve();return e?e==="open"?i.jsx(vu,{children:t("status.open")}):e==="connecting"?i.jsx(vu,{variant:"warning",children:t("status.connecting")}):e==="close"||e==="closed"?i.jsx(vu,{variant:"destructive",children:t("status.closed")}):i.jsx(vu,{variant:"secondary",children:e}):null}const U5=e=>{navigator.clipboard.writeText(e),me.success("Copiado para a área de transferência")};function c_({token:e,className:t}){const[n,r]=y.useState(!1);return i.jsxs("div",{className:Ie("flex items-center gap-3 truncate rounded-sm bg-primary/20 px-2 py-1",t),children:[i.jsx("pre",{className:"block truncate text-xs",children:n?e:e?.replace(/\w/g,"*")}),i.jsx(se,{variant:"ghost",size:"icon",onClick:()=>{U5(e)},children:i.jsx(X$,{size:"15"})}),i.jsx(se,{variant:"ghost",size:"icon",onClick:()=>{r(s=>!s)},children:n?i.jsx(tB,{size:"15"}):i.jsx(nB,{size:"15"})})]})}const So=y.forwardRef(({className:e,...t},n)=>i.jsx("div",{ref:n,className:Ie("flex flex-col rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));So.displayName="Card";const Co=y.forwardRef(({className:e,...t},n)=>i.jsx("div",{ref:n,className:Ie("flex flex-col space-y-1.5 p-6",e),...t}));Co.displayName="CardHeader";const gi=y.forwardRef(({className:e,...t},n)=>i.jsx("h3",{ref:n,className:Ie("text-2xl font-semibold leading-none tracking-tight",e),...t}));gi.displayName="CardTitle";const Kp=y.forwardRef(({className:e,...t},n)=>i.jsx("p",{ref:n,className:Ie("text-sm text-muted-foreground",e),...t}));Kp.displayName="CardDescription";const Eo=y.forwardRef(({className:e,...t},n)=>i.jsx("div",{ref:n,className:Ie("p-6 pt-0",e),...t}));Eo.displayName="CardContent";const Vh=y.forwardRef(({className:e,...t},n)=>i.jsx("div",{ref:n,className:Ie("flex items-center p-6 pt-0",e),...t}));Vh.displayName="CardFooter";const u_="flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",ne=y.forwardRef(({className:e,type:t,...n},r)=>i.jsx("input",{type:t,className:Ie(u_,e),ref:r,...n}));ne.displayName="Input";const V5=["instance","fetchInstances"],H5=async()=>(await bd.get("/instance/fetchInstances")).data,q5=e=>mt({...e,queryKey:V5,queryFn:()=>H5()});function nt(e,t){const n=Ob(),r=cF({mutationFn:e});return(s,o)=>r.mutateAsync(s,{onSuccess:async(l,u,d)=>{t?.invalidateKeys&&await Promise.all(t.invalidateKeys.map(f=>n.invalidateQueries({queryKey:f}))),o?.onSuccess?.(l,u,d)},onError(l,u,d){o?.onError?.(l,u,d)},onSettled(l,u,d,f){o?.onSettled?.(l,u,d,f)}})}const K5=async e=>(await bd.post("/instance/create",e)).data,W5=async e=>(await Ee.post(`/instance/restart/${e}`)).data,G5=async e=>(await Ee.delete(`/instance/logout/${e}`)).data,J5=async e=>(await bd.delete(`/instance/delete/${e}`)).data,Q5=async({instanceName:e,token:t,number:n})=>(await Ee.get(`/instance/connect/${e}`,{headers:{apikey:t},params:{number:n}})).data,Z5=async({instanceName:e,token:t,data:n})=>(await Ee.post(`/settings/set/${e}`,n,{headers:{apikey:t}})).data;function Hh(){const e=nt(Q5,{invalidateKeys:[["instance","fetchInstance"],["instance","fetchInstances"]]}),t=nt(Z5,{invalidateKeys:[["instance","fetchSettings"]]}),n=nt(J5,{invalidateKeys:[["instance","fetchInstance"],["instance","fetchInstances"]]}),r=nt(G5,{invalidateKeys:[["instance","fetchInstance"],["instance","fetchInstances"]]}),s=nt(W5,{invalidateKeys:[["instance","fetchInstance"],["instance","fetchInstances"]]}),o=nt(K5,{invalidateKeys:[["instance","fetchInstances"]]});return{connect:e,updateSettings:t,deleteInstance:n,logout:r,restart:s,createInstance:o}}var Ed=e=>e.type==="checkbox",Tl=e=>e instanceof Date,cr=e=>e==null;const d_=e=>typeof e=="object";var $n=e=>!cr(e)&&!Array.isArray(e)&&d_(e)&&!Tl(e),f_=e=>$n(e)&&e.target?Ed(e.target)?e.target.checked:e.target.value:e,Y5=e=>e.substring(0,e.search(/\.\d+(\.|$)/))||e,p_=(e,t)=>e.has(Y5(t)),X5=e=>{const t=e.constructor&&e.constructor.prototype;return $n(t)&&t.hasOwnProperty("isPrototypeOf")},jx=typeof window<"u"&&typeof window.HTMLElement<"u"&&typeof document<"u";function Er(e){let t;const n=Array.isArray(e);if(e instanceof Date)t=new Date(e);else if(e instanceof Set)t=new Set(e);else if(!(jx&&(e instanceof Blob||e instanceof FileList))&&(n||$n(e)))if(t=n?[]:{},!n&&!X5(e))t=e;else for(const r in e)e.hasOwnProperty(r)&&(t[r]=Er(e[r]));else return e;return t}var qh=e=>Array.isArray(e)?e.filter(Boolean):[],wn=e=>e===void 0,_e=(e,t,n)=>{if(!t||!$n(e))return n;const r=qh(t.split(/[,[\].]+?/)).reduce((s,o)=>cr(s)?s:s[o],e);return wn(r)||r===e?wn(e[t])?n:e[t]:r},Us=e=>typeof e=="boolean",Tx=e=>/^\w*$/.test(e),h_=e=>qh(e.replace(/["|']|\]/g,"").split(/\.|\[/)),qt=(e,t,n)=>{let r=-1;const s=Tx(t)?[t]:h_(t),o=s.length,l=o-1;for(;++rqe.useContext(g_),Gn=e=>{const{children:t,...n}=e;return qe.createElement(g_.Provider,{value:n},t)};var m_=(e,t,n,r=!0)=>{const s={defaultValues:t._defaultValues};for(const o in e)Object.defineProperty(s,o,{get:()=>{const l=o;return t._proxyFormState[l]!==Ss.all&&(t._proxyFormState[l]=!r||Ss.all),n&&(n[l]=!0),e[l]}});return s},Lr=e=>$n(e)&&!Object.keys(e).length,v_=(e,t,n,r)=>{n(e);const{name:s,...o}=e;return Lr(o)||Object.keys(o).length>=Object.keys(t).length||Object.keys(o).find(l=>t[l]===(!r||Ss.all))},ju=e=>Array.isArray(e)?e:[e],y_=(e,t,n)=>!e||!t||e===t||ju(e).some(r=>r&&(n?r===t:r.startsWith(t)||t.startsWith(r)));function Nx(e){const t=qe.useRef(e);t.current=e,qe.useEffect(()=>{const n=!e.disabled&&t.current.subject&&t.current.subject.subscribe({next:t.current.next});return()=>{n&&n.unsubscribe()}},[e.disabled])}function e6(e){const t=Kh(),{control:n=t.control,disabled:r,name:s,exact:o}=e||{},[l,u]=qe.useState(n._formState),d=qe.useRef(!0),f=qe.useRef({isDirty:!1,isLoading:!1,dirtyFields:!1,touchedFields:!1,validatingFields:!1,isValidating:!1,isValid:!1,errors:!1}),h=qe.useRef(s);return h.current=s,Nx({disabled:r,next:m=>d.current&&y_(h.current,m.name,o)&&v_(m,f.current,n._updateFormState)&&u({...n._formState,...m}),subject:n._subjects.state}),qe.useEffect(()=>(d.current=!0,f.current.isValid&&n._updateValid(!0),()=>{d.current=!1}),[n]),m_(l,n,f.current,!1)}var qs=e=>typeof e=="string",b_=(e,t,n,r,s)=>qs(e)?(r&&t.watch.add(e),_e(n,e,s)):Array.isArray(e)?e.map(o=>(r&&t.watch.add(o),_e(n,o))):(r&&(t.watchAll=!0),n);function t6(e){const t=Kh(),{control:n=t.control,name:r,defaultValue:s,disabled:o,exact:l}=e||{},u=qe.useRef(r);u.current=r,Nx({disabled:o,subject:n._subjects.values,next:h=>{y_(u.current,h.name,l)&&f(Er(b_(u.current,n._names,h.values||n._formValues,!1,s)))}});const[d,f]=qe.useState(n._getWatch(r,s));return qe.useEffect(()=>n._removeUnmounted()),d}function n6(e){const t=Kh(),{name:n,disabled:r,control:s=t.control,shouldUnregister:o}=e,l=p_(s._names.array,n),u=t6({control:s,name:n,defaultValue:_e(s._formValues,n,_e(s._defaultValues,n,e.defaultValue)),exact:!0}),d=e6({control:s,name:n}),f=qe.useRef(s.register(n,{...e.rules,value:u,...Us(e.disabled)?{disabled:e.disabled}:{}}));return qe.useEffect(()=>{const h=s._options.shouldUnregister||o,m=(g,x)=>{const b=_e(s._fields,g);b&&b._f&&(b._f.mount=x)};if(m(n,!0),h){const g=Er(_e(s._options.defaultValues,n));qt(s._defaultValues,n,g),wn(_e(s._formValues,n))&&qt(s._formValues,n,g)}return()=>{(l?h&&!s._state.action:h)?s.unregister(n):m(n,!1)}},[n,s,l,o]),qe.useEffect(()=>{_e(s._fields,n)&&s._updateDisabledField({disabled:r,fields:s._fields,name:n,value:_e(s._fields,n)._f.value})},[r,n,s]),{field:{name:n,value:u,...Us(r)||d.disabled?{disabled:d.disabled||r}:{},onChange:qe.useCallback(h=>f.current.onChange({target:{value:f_(h),name:n},type:Wp.CHANGE}),[n]),onBlur:qe.useCallback(()=>f.current.onBlur({target:{value:_e(s._formValues,n),name:n},type:Wp.BLUR}),[n,s]),ref:h=>{const m=_e(s._fields,n);m&&h&&(m._f.ref={focus:()=>h.focus(),select:()=>h.select(),setCustomValidity:g=>h.setCustomValidity(g),reportValidity:()=>h.reportValidity()})}},formState:d,fieldState:Object.defineProperties({},{invalid:{enumerable:!0,get:()=>!!_e(d.errors,n)},isDirty:{enumerable:!0,get:()=>!!_e(d.dirtyFields,n)},isTouched:{enumerable:!0,get:()=>!!_e(d.touchedFields,n)},isValidating:{enumerable:!0,get:()=>!!_e(d.validatingFields,n)},error:{enumerable:!0,get:()=>_e(d.errors,n)}})}}const r6=e=>e.render(n6(e));var x_=(e,t,n,r,s)=>t?{...n[e],types:{...n[e]&&n[e].types?n[e].types:{},[r]:s||!0}}:{},h1=e=>({isOnSubmit:!e||e===Ss.onSubmit,isOnBlur:e===Ss.onBlur,isOnChange:e===Ss.onChange,isOnAll:e===Ss.all,isOnTouch:e===Ss.onTouched}),g1=(e,t,n)=>!n&&(t.watchAll||t.watch.has(e)||[...t.watch].some(r=>e.startsWith(r)&&/^\.\w+/.test(e.slice(r.length))));const Tu=(e,t,n,r)=>{for(const s of n||Object.keys(e)){const o=_e(e,s);if(o){const{_f:l,...u}=o;if(l){if(l.refs&&l.refs[0]&&t(l.refs[0],s)&&!r)break;if(l.ref&&t(l.ref,l.name)&&!r)break;Tu(u,t)}else $n(u)&&Tu(u,t)}}};var s6=(e,t,n)=>{const r=ju(_e(e,n));return qt(r,"root",t[n]),qt(e,n,r),e},Mx=e=>e.type==="file",ga=e=>typeof e=="function",Gp=e=>{if(!jx)return!1;const t=e?e.ownerDocument:0;return e instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},vp=e=>qs(e),_x=e=>e.type==="radio",Jp=e=>e instanceof RegExp;const m1={value:!1,isValid:!1},v1={value:!0,isValid:!0};var w_=e=>{if(Array.isArray(e)){if(e.length>1){const t=e.filter(n=>n&&n.checked&&!n.disabled).map(n=>n.value);return{value:t,isValid:!!t.length}}return e[0].checked&&!e[0].disabled?e[0].attributes&&!wn(e[0].attributes.value)?wn(e[0].value)||e[0].value===""?v1:{value:e[0].value,isValid:!0}:v1:m1}return m1};const y1={isValid:!1,value:null};var S_=e=>Array.isArray(e)?e.reduce((t,n)=>n&&n.checked&&!n.disabled?{isValid:!0,value:n.value}:t,y1):y1;function b1(e,t,n="validate"){if(vp(e)||Array.isArray(e)&&e.every(vp)||Us(e)&&!e)return{type:n,message:vp(e)?e:"",ref:t}}var ml=e=>$n(e)&&!Jp(e)?e:{value:e,message:""},x1=async(e,t,n,r,s)=>{const{ref:o,refs:l,required:u,maxLength:d,minLength:f,min:h,max:m,pattern:g,validate:x,name:b,valueAsNumber:w,mount:C,disabled:k}=e._f,j=_e(t,b);if(!C||k)return{};const M=l?l[0]:o,_=V=>{r&&M.reportValidity&&(M.setCustomValidity(Us(V)?"":V||""),M.reportValidity())},R={},N=_x(o),O=Ed(o),D=N||O,z=(w||Mx(o))&&wn(o.value)&&wn(j)||Gp(o)&&o.value===""||j===""||Array.isArray(j)&&!j.length,Q=x_.bind(null,b,n,R),pe=(V,G,W,ie=go.maxLength,re=go.minLength)=>{const Y=V?G:W;R[b]={type:V?ie:re,message:Y,ref:o,...Q(V?ie:re,Y)}};if(s?!Array.isArray(j)||!j.length:u&&(!D&&(z||cr(j))||Us(j)&&!j||O&&!w_(l).isValid||N&&!S_(l).isValid)){const{value:V,message:G}=vp(u)?{value:!!u,message:u}:ml(u);if(V&&(R[b]={type:go.required,message:G,ref:M,...Q(go.required,G)},!n))return _(G),R}if(!z&&(!cr(h)||!cr(m))){let V,G;const W=ml(m),ie=ml(h);if(!cr(j)&&!isNaN(j)){const re=o.valueAsNumber||j&&+j;cr(W.value)||(V=re>W.value),cr(ie.value)||(G=renew Date(new Date().toDateString()+" "+he),H=o.type=="time",q=o.type=="week";qs(W.value)&&j&&(V=H?Y(j)>Y(W.value):q?j>W.value:re>new Date(W.value)),qs(ie.value)&&j&&(G=H?Y(j)+V.value,ie=!cr(G.value)&&j.length<+G.value;if((W||ie)&&(pe(W,V.message,G.message),!n))return _(R[b].message),R}if(g&&!z&&qs(j)){const{value:V,message:G}=ml(g);if(Jp(V)&&!j.match(V)&&(R[b]={type:go.pattern,message:G,ref:o,...Q(go.pattern,G)},!n))return _(G),R}if(x){if(ga(x)){const V=await x(j,t),G=b1(V,M);if(G&&(R[b]={...G,...Q(go.validate,G.message)},!n))return _(G.message),R}else if($n(x)){let V={};for(const G in x){if(!Lr(V)&&!n)break;const W=b1(await x[G](j,t),M,G);W&&(V={...W,...Q(G,W.message)},_(W.message),n&&(R[b]=V))}if(!Lr(V)&&(R[b]={ref:M,...V},!n))return R}}return _(!0),R};function o6(e,t){const n=t.slice(0,-1).length;let r=0;for(;r{let e=[];return{get observers(){return e},next:s=>{for(const o of e)o.next&&o.next(s)},subscribe:s=>(e.push(s),{unsubscribe:()=>{e=e.filter(o=>o!==s)}}),unsubscribe:()=>{e=[]}}},Qp=e=>cr(e)||!d_(e);function ui(e,t){if(Qp(e)||Qp(t))return e===t;if(Tl(e)&&Tl(t))return e.getTime()===t.getTime();const n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(const s of n){const o=e[s];if(!r.includes(s))return!1;if(s!=="ref"){const l=t[s];if(Tl(o)&&Tl(l)||$n(o)&&$n(l)||Array.isArray(o)&&Array.isArray(l)?!ui(o,l):o!==l)return!1}}return!0}var C_=e=>e.type==="select-multiple",i6=e=>_x(e)||Ed(e),_v=e=>Gp(e)&&e.isConnected,E_=e=>{for(const t in e)if(ga(e[t]))return!0;return!1};function Zp(e,t={}){const n=Array.isArray(e);if($n(e)||n)for(const r in e)Array.isArray(e[r])||$n(e[r])&&!E_(e[r])?(t[r]=Array.isArray(e[r])?[]:{},Zp(e[r],t[r])):cr(e[r])||(t[r]=!0);return t}function k_(e,t,n){const r=Array.isArray(e);if($n(e)||r)for(const s in e)Array.isArray(e[s])||$n(e[s])&&!E_(e[s])?wn(t)||Qp(n[s])?n[s]=Array.isArray(e[s])?Zp(e[s],[]):{...Zp(e[s])}:k_(e[s],cr(t)?{}:t[s],n[s]):n[s]=!ui(e[s],t[s]);return n}var Gf=(e,t)=>k_(e,t,Zp(t)),j_=(e,{valueAsNumber:t,valueAsDate:n,setValueAs:r})=>wn(e)?e:t?e===""?NaN:e&&+e:n&&qs(e)?new Date(e):r?r(e):e;function Rv(e){const t=e.ref;if(!(e.refs?e.refs.every(n=>n.disabled):t.disabled))return Mx(t)?t.files:_x(t)?S_(e.refs).value:C_(t)?[...t.selectedOptions].map(({value:n})=>n):Ed(t)?w_(e.refs).value:j_(wn(t.value)?e.ref.value:t.value,e)}var l6=(e,t,n,r)=>{const s={};for(const o of e){const l=_e(t,o);l&&qt(s,o,l._f)}return{criteriaMode:n,names:[...e],fields:s,shouldUseNativeValidation:r}},au=e=>wn(e)?e:Jp(e)?e.source:$n(e)?Jp(e.value)?e.value.source:e.value:e,c6=e=>e.mount&&(e.required||e.min||e.max||e.maxLength||e.minLength||e.pattern||e.validate);function w1(e,t,n){const r=_e(e,n);if(r||Tx(n))return{error:r,name:n};const s=n.split(".");for(;s.length;){const o=s.join("."),l=_e(t,o),u=_e(e,o);if(l&&!Array.isArray(l)&&n!==o)return{name:n};if(u&&u.type)return{name:o,error:u};s.pop()}return{name:n}}var u6=(e,t,n,r,s)=>s.isOnAll?!1:!n&&s.isOnTouch?!(t||e):(n?r.isOnBlur:s.isOnBlur)?!e:(n?r.isOnChange:s.isOnChange)?e:!0,d6=(e,t)=>!qh(_e(e,t)).length&&Dn(e,t);const f6={mode:Ss.onSubmit,reValidateMode:Ss.onChange,shouldFocusError:!0};function p6(e={}){let t={...f6,...e},n={submitCount:0,isDirty:!1,isLoading:ga(t.defaultValues),isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},validatingFields:{},errors:t.errors||{},disabled:t.disabled||!1},r={},s=$n(t.defaultValues)||$n(t.values)?Er(t.defaultValues||t.values)||{}:{},o=t.shouldUnregister?{}:Er(s),l={action:!1,mount:!1,watch:!1},u={mount:new Set,unMount:new Set,array:new Set,watch:new Set},d,f=0;const h={isDirty:!1,dirtyFields:!1,validatingFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1},m={values:Mv(),array:Mv(),state:Mv()},g=h1(t.mode),x=h1(t.reValidateMode),b=t.criteriaMode===Ss.all,w=L=>X=>{clearTimeout(f),f=setTimeout(L,X)},C=async L=>{if(h.isValid||L){const X=t.resolver?Lr((await D()).errors):await Q(r,!0);X!==n.isValid&&m.state.next({isValid:X})}},k=(L,X)=>{(h.isValidating||h.validatingFields)&&((L||Array.from(u.mount)).forEach(ue=>{ue&&(X?qt(n.validatingFields,ue,X):Dn(n.validatingFields,ue))}),m.state.next({validatingFields:n.validatingFields,isValidating:!Lr(n.validatingFields)}))},j=(L,X=[],ue,Ne,je=!0,Se=!0)=>{if(Ne&&ue){if(l.action=!0,Se&&Array.isArray(_e(r,L))){const Be=ue(_e(r,L),Ne.argA,Ne.argB);je&&qt(r,L,Be)}if(Se&&Array.isArray(_e(n.errors,L))){const Be=ue(_e(n.errors,L),Ne.argA,Ne.argB);je&&qt(n.errors,L,Be),d6(n.errors,L)}if(h.touchedFields&&Se&&Array.isArray(_e(n.touchedFields,L))){const Be=ue(_e(n.touchedFields,L),Ne.argA,Ne.argB);je&&qt(n.touchedFields,L,Be)}h.dirtyFields&&(n.dirtyFields=Gf(s,o)),m.state.next({name:L,isDirty:V(L,X),dirtyFields:n.dirtyFields,errors:n.errors,isValid:n.isValid})}else qt(o,L,X)},M=(L,X)=>{qt(n.errors,L,X),m.state.next({errors:n.errors})},_=L=>{n.errors=L,m.state.next({errors:n.errors,isValid:!1})},R=(L,X,ue,Ne)=>{const je=_e(r,L);if(je){const Se=_e(o,L,wn(ue)?_e(s,L):ue);wn(Se)||Ne&&Ne.defaultChecked||X?qt(o,L,X?Se:Rv(je._f)):ie(L,Se),l.mount&&C()}},N=(L,X,ue,Ne,je)=>{let Se=!1,Be=!1;const bt={name:L},Wt=!!(_e(r,L)&&_e(r,L)._f&&_e(r,L)._f.disabled);if(!ue||Ne){h.isDirty&&(Be=n.isDirty,n.isDirty=bt.isDirty=V(),Se=Be!==bt.isDirty);const yn=Wt||ui(_e(s,L),X);Be=!!(!Wt&&_e(n.dirtyFields,L)),yn||Wt?Dn(n.dirtyFields,L):qt(n.dirtyFields,L,!0),bt.dirtyFields=n.dirtyFields,Se=Se||h.dirtyFields&&Be!==!yn}if(ue){const yn=_e(n.touchedFields,L);yn||(qt(n.touchedFields,L,ue),bt.touchedFields=n.touchedFields,Se=Se||h.touchedFields&&yn!==ue)}return Se&&je&&m.state.next(bt),Se?bt:{}},O=(L,X,ue,Ne)=>{const je=_e(n.errors,L),Se=h.isValid&&Us(X)&&n.isValid!==X;if(e.delayError&&ue?(d=w(()=>M(L,ue)),d(e.delayError)):(clearTimeout(f),d=null,ue?qt(n.errors,L,ue):Dn(n.errors,L)),(ue?!ui(je,ue):je)||!Lr(Ne)||Se){const Be={...Ne,...Se&&Us(X)?{isValid:X}:{},errors:n.errors,name:L};n={...n,...Be},m.state.next(Be)}},D=async L=>{k(L,!0);const X=await t.resolver(o,t.context,l6(L||u.mount,r,t.criteriaMode,t.shouldUseNativeValidation));return k(L),X},z=async L=>{const{errors:X}=await D(L);if(L)for(const ue of L){const Ne=_e(X,ue);Ne?qt(n.errors,ue,Ne):Dn(n.errors,ue)}else n.errors=X;return X},Q=async(L,X,ue={valid:!0})=>{for(const Ne in L){const je=L[Ne];if(je){const{_f:Se,...Be}=je;if(Se){const bt=u.array.has(Se.name);k([Ne],!0);const Wt=await x1(je,o,b,t.shouldUseNativeValidation&&!X,bt);if(k([Ne]),Wt[Se.name]&&(ue.valid=!1,X))break;!X&&(_e(Wt,Se.name)?bt?s6(n.errors,Wt,Se.name):qt(n.errors,Se.name,Wt[Se.name]):Dn(n.errors,Se.name))}Be&&await Q(Be,X,ue)}}return ue.valid},pe=()=>{for(const L of u.unMount){const X=_e(r,L);X&&(X._f.refs?X._f.refs.every(ue=>!_v(ue)):!_v(X._f.ref))&&ge(L)}u.unMount=new Set},V=(L,X)=>(L&&X&&qt(o,L,X),!ui(A(),s)),G=(L,X,ue)=>b_(L,u,{...l.mount?o:wn(X)?s:qs(L)?{[L]:X}:X},ue,X),W=L=>qh(_e(l.mount?o:s,L,e.shouldUnregister?_e(s,L,[]):[])),ie=(L,X,ue={})=>{const Ne=_e(r,L);let je=X;if(Ne){const Se=Ne._f;Se&&(!Se.disabled&&qt(o,L,j_(X,Se)),je=Gp(Se.ref)&&cr(X)?"":X,C_(Se.ref)?[...Se.ref.options].forEach(Be=>Be.selected=je.includes(Be.value)):Se.refs?Ed(Se.ref)?Se.refs.length>1?Se.refs.forEach(Be=>(!Be.defaultChecked||!Be.disabled)&&(Be.checked=Array.isArray(je)?!!je.find(bt=>bt===Be.value):je===Be.value)):Se.refs[0]&&(Se.refs[0].checked=!!je):Se.refs.forEach(Be=>Be.checked=Be.value===je):Mx(Se.ref)?Se.ref.value="":(Se.ref.value=je,Se.ref.type||m.values.next({name:L,values:{...o}})))}(ue.shouldDirty||ue.shouldTouch)&&N(L,je,ue.shouldTouch,ue.shouldDirty,!0),ue.shouldValidate&&he(L)},re=(L,X,ue)=>{for(const Ne in X){const je=X[Ne],Se=`${L}.${Ne}`,Be=_e(r,Se);(u.array.has(L)||!Qp(je)||Be&&!Be._f)&&!Tl(je)?re(Se,je,ue):ie(Se,je,ue)}},Y=(L,X,ue={})=>{const Ne=_e(r,L),je=u.array.has(L),Se=Er(X);qt(o,L,Se),je?(m.array.next({name:L,values:{...o}}),(h.isDirty||h.dirtyFields)&&ue.shouldDirty&&m.state.next({name:L,dirtyFields:Gf(s,o),isDirty:V(L,Se)})):Ne&&!Ne._f&&!cr(Se)?re(L,Se,ue):ie(L,Se,ue),g1(L,u)&&m.state.next({...n}),m.values.next({name:l.mount?L:void 0,values:{...o}})},H=async L=>{l.mount=!0;const X=L.target;let ue=X.name,Ne=!0;const je=_e(r,ue),Se=()=>X.type?Rv(je._f):f_(L),Be=bt=>{Ne=Number.isNaN(bt)||bt===_e(o,ue,bt)};if(je){let bt,Wt;const yn=Se(),bn=L.type===Wp.BLUR||L.type===Wp.FOCUS_OUT,En=!c6(je._f)&&!t.resolver&&!_e(n.errors,ue)&&!je._f.deps||u6(bn,_e(n.touchedFields,ue),n.isSubmitted,x,g),gr=g1(ue,u,bn);qt(o,ue,yn),bn?(je._f.onBlur&&je._f.onBlur(L),d&&d(0)):je._f.onChange&&je._f.onChange(L);const Qn=N(ue,yn,bn,!1),ro=!Lr(Qn)||gr;if(!bn&&m.values.next({name:ue,type:L.type,values:{...o}}),En)return h.isValid&&C(),ro&&m.state.next({name:ue,...gr?{}:Qn});if(!bn&&gr&&m.state.next({...n}),t.resolver){const{errors:Bn}=await D([ue]);if(Be(yn),Ne){const Te=w1(n.errors,r,ue),ut=w1(Bn,r,Te.name||ue);bt=ut.error,ue=ut.name,Wt=Lr(Bn)}}else k([ue],!0),bt=(await x1(je,o,b,t.shouldUseNativeValidation))[ue],k([ue]),Be(yn),Ne&&(bt?Wt=!1:h.isValid&&(Wt=await Q(r,!0)));Ne&&(je._f.deps&&he(je._f.deps),O(ue,Wt,bt,Qn))}},q=(L,X)=>{if(_e(n.errors,X)&&L.focus)return L.focus(),1},he=async(L,X={})=>{let ue,Ne;const je=ju(L);if(t.resolver){const Se=await z(wn(L)?L:je);ue=Lr(Se),Ne=L?!je.some(Be=>_e(Se,Be)):ue}else L?(Ne=(await Promise.all(je.map(async Se=>{const Be=_e(r,Se);return await Q(Be&&Be._f?{[Se]:Be}:Be)}))).every(Boolean),!(!Ne&&!n.isValid)&&C()):Ne=ue=await Q(r);return m.state.next({...!qs(L)||h.isValid&&ue!==n.isValid?{}:{name:L},...t.resolver||!L?{isValid:ue}:{},errors:n.errors}),X.shouldFocus&&!Ne&&Tu(r,q,L?je:u.mount),Ne},A=L=>{const X={...l.mount?o:s};return wn(L)?X:qs(L)?_e(X,L):L.map(ue=>_e(X,ue))},F=(L,X)=>({invalid:!!_e((X||n).errors,L),isDirty:!!_e((X||n).dirtyFields,L),error:_e((X||n).errors,L),isValidating:!!_e(n.validatingFields,L),isTouched:!!_e((X||n).touchedFields,L)}),fe=L=>{L&&ju(L).forEach(X=>Dn(n.errors,X)),m.state.next({errors:L?n.errors:{}})},te=(L,X,ue)=>{const Ne=(_e(r,L,{_f:{}})._f||{}).ref,je=_e(n.errors,L)||{},{ref:Se,message:Be,type:bt,...Wt}=je;qt(n.errors,L,{...Wt,...X,ref:Ne}),m.state.next({name:L,errors:n.errors,isValid:!1}),ue&&ue.shouldFocus&&Ne&&Ne.focus&&Ne.focus()},de=(L,X)=>ga(L)?m.values.subscribe({next:ue=>L(G(void 0,X),ue)}):G(L,X,!0),ge=(L,X={})=>{for(const ue of L?ju(L):u.mount)u.mount.delete(ue),u.array.delete(ue),X.keepValue||(Dn(r,ue),Dn(o,ue)),!X.keepError&&Dn(n.errors,ue),!X.keepDirty&&Dn(n.dirtyFields,ue),!X.keepTouched&&Dn(n.touchedFields,ue),!X.keepIsValidating&&Dn(n.validatingFields,ue),!t.shouldUnregister&&!X.keepDefaultValue&&Dn(s,ue);m.values.next({values:{...o}}),m.state.next({...n,...X.keepDirty?{isDirty:V()}:{}}),!X.keepIsValid&&C()},Z=({disabled:L,name:X,field:ue,fields:Ne,value:je})=>{if(Us(L)&&l.mount||L){const Se=L?void 0:wn(je)?Rv(ue?ue._f:_e(Ne,X)._f):je;qt(o,X,Se),N(X,Se,!1,!1,!0)}},ye=(L,X={})=>{let ue=_e(r,L);const Ne=Us(X.disabled);return qt(r,L,{...ue||{},_f:{...ue&&ue._f?ue._f:{ref:{name:L}},name:L,mount:!0,...X}}),u.mount.add(L),ue?Z({field:ue,disabled:X.disabled,name:L,value:X.value}):R(L,!0,X.value),{...Ne?{disabled:X.disabled}:{},...t.progressive?{required:!!X.required,min:au(X.min),max:au(X.max),minLength:au(X.minLength),maxLength:au(X.maxLength),pattern:au(X.pattern)}:{},name:L,onChange:H,onBlur:H,ref:je=>{if(je){ye(L,X),ue=_e(r,L);const Se=wn(je.value)&&je.querySelectorAll&&je.querySelectorAll("input,select,textarea")[0]||je,Be=i6(Se),bt=ue._f.refs||[];if(Be?bt.find(Wt=>Wt===Se):Se===ue._f.ref)return;qt(r,L,{_f:{...ue._f,...Be?{refs:[...bt.filter(_v),Se,...Array.isArray(_e(s,L))?[{}]:[]],ref:{type:Se.type,name:L}}:{ref:Se}}}),R(L,!1,void 0,Se)}else ue=_e(r,L,{}),ue._f&&(ue._f.mount=!1),(t.shouldUnregister||X.shouldUnregister)&&!(p_(u.array,L)&&l.action)&&u.unMount.add(L)}}},Re=()=>t.shouldFocusError&&Tu(r,q,u.mount),$e=L=>{Us(L)&&(m.state.next({disabled:L}),Tu(r,(X,ue)=>{const Ne=_e(r,ue);Ne&&(X.disabled=Ne._f.disabled||L,Array.isArray(Ne._f.refs)&&Ne._f.refs.forEach(je=>{je.disabled=Ne._f.disabled||L}))},0,!1))},Ye=(L,X)=>async ue=>{let Ne;ue&&(ue.preventDefault&&ue.preventDefault(),ue.persist&&ue.persist());let je=Er(o);if(m.state.next({isSubmitting:!0}),t.resolver){const{errors:Se,values:Be}=await D();n.errors=Se,je=Be}else await Q(r);if(Dn(n.errors,"root"),Lr(n.errors)){m.state.next({errors:{}});try{await L(je,ue)}catch(Se){Ne=Se}}else X&&await X({...n.errors},ue),Re(),setTimeout(Re);if(m.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:Lr(n.errors)&&!Ne,submitCount:n.submitCount+1,errors:n.errors}),Ne)throw Ne},Fe=(L,X={})=>{_e(r,L)&&(wn(X.defaultValue)?Y(L,Er(_e(s,L))):(Y(L,X.defaultValue),qt(s,L,Er(X.defaultValue))),X.keepTouched||Dn(n.touchedFields,L),X.keepDirty||(Dn(n.dirtyFields,L),n.isDirty=X.defaultValue?V(L,Er(_e(s,L))):V()),X.keepError||(Dn(n.errors,L),h.isValid&&C()),m.state.next({...n}))},ft=(L,X={})=>{const ue=L?Er(L):s,Ne=Er(ue),je=Lr(L),Se=je?s:Ne;if(X.keepDefaultValues||(s=ue),!X.keepValues){if(X.keepDirtyValues)for(const Be of u.mount)_e(n.dirtyFields,Be)?qt(Se,Be,_e(o,Be)):Y(Be,_e(Se,Be));else{if(jx&&wn(L))for(const Be of u.mount){const bt=_e(r,Be);if(bt&&bt._f){const Wt=Array.isArray(bt._f.refs)?bt._f.refs[0]:bt._f.ref;if(Gp(Wt)){const yn=Wt.closest("form");if(yn){yn.reset();break}}}}r={}}o=e.shouldUnregister?X.keepDefaultValues?Er(s):{}:Er(Se),m.array.next({values:{...Se}}),m.values.next({values:{...Se}})}u={mount:X.keepDirtyValues?u.mount:new Set,unMount:new Set,array:new Set,watch:new Set,watchAll:!1,focus:""},l.mount=!h.isValid||!!X.keepIsValid||!!X.keepDirtyValues,l.watch=!!e.shouldUnregister,m.state.next({submitCount:X.keepSubmitCount?n.submitCount:0,isDirty:je?!1:X.keepDirty?n.isDirty:!!(X.keepDefaultValues&&!ui(L,s)),isSubmitted:X.keepIsSubmitted?n.isSubmitted:!1,dirtyFields:je?{}:X.keepDirtyValues?X.keepDefaultValues&&o?Gf(s,o):n.dirtyFields:X.keepDefaultValues&&L?Gf(s,L):X.keepDirty?n.dirtyFields:{},touchedFields:X.keepTouched?n.touchedFields:{},errors:X.keepErrors?n.errors:{},isSubmitSuccessful:X.keepIsSubmitSuccessful?n.isSubmitSuccessful:!1,isSubmitting:!1})},ln=(L,X)=>ft(ga(L)?L(o):L,X);return{control:{register:ye,unregister:ge,getFieldState:F,handleSubmit:Ye,setError:te,_executeSchema:D,_getWatch:G,_getDirty:V,_updateValid:C,_removeUnmounted:pe,_updateFieldArray:j,_updateDisabledField:Z,_getFieldArray:W,_reset:ft,_resetDefaultValues:()=>ga(t.defaultValues)&&t.defaultValues().then(L=>{ln(L,t.resetOptions),m.state.next({isLoading:!1})}),_updateFormState:L=>{n={...n,...L}},_disableForm:$e,_subjects:m,_proxyFormState:h,_setErrors:_,get _fields(){return r},get _formValues(){return o},get _state(){return l},set _state(L){l=L},get _defaultValues(){return s},get _names(){return u},set _names(L){u=L},get _formState(){return n},set _formState(L){n=L},get _options(){return t},set _options(L){t={...t,...L}}},trigger:he,register:ye,handleSubmit:Ye,watch:de,setValue:Y,getValues:A,reset:ln,resetField:Fe,clearErrors:fe,unregister:ge,setError:te,setFocus:(L,X={})=>{const ue=_e(r,L),Ne=ue&&ue._f;if(Ne){const je=Ne.refs?Ne.refs[0]:Ne.ref;je.focus&&(je.focus(),X.shouldSelect&&je.select())}},getFieldState:F}}function on(e={}){const t=qe.useRef(),n=qe.useRef(),[r,s]=qe.useState({isDirty:!1,isValidating:!1,isLoading:ga(e.defaultValues),isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},validatingFields:{},errors:e.errors||{},disabled:e.disabled||!1,defaultValues:ga(e.defaultValues)?void 0:e.defaultValues});t.current||(t.current={...p6(e),formState:r});const o=t.current.control;return o._options=e,Nx({subject:o._subjects.state,next:l=>{v_(l,o._proxyFormState,o._updateFormState,!0)&&s({...o._formState})}}),qe.useEffect(()=>o._disableForm(e.disabled),[o,e.disabled]),qe.useEffect(()=>{if(o._proxyFormState.isDirty){const l=o._getDirty();l!==r.isDirty&&o._subjects.state.next({isDirty:l})}},[o,r.isDirty]),qe.useEffect(()=>{e.values&&!ui(e.values,n.current)?(o._reset(e.values,o._options.resetOptions),n.current=e.values,s(l=>({...l}))):o._resetDefaultValues()},[e.values,o]),qe.useEffect(()=>{e.errors&&o._setErrors(e.errors)},[e.errors,o]),qe.useEffect(()=>{o._state.mount||(o._updateValid(),o._state.mount=!0),o._state.watch&&(o._state.watch=!1,o._subjects.state.next({...o._formState})),o._removeUnmounted()}),qe.useEffect(()=>{e.shouldUnregister&&o._subjects.values.next({values:o._getWatch()})},[e.shouldUnregister,o]),t.current.formState=m_(r,o),t.current}const S1=(e,t,n)=>{if(e&&"reportValidity"in e){const r=_e(n,t);e.setCustomValidity(r&&r.message||""),e.reportValidity()}},T_=(e,t)=>{for(const n in t.fields){const r=t.fields[n];r&&r.ref&&"reportValidity"in r.ref?S1(r.ref,n,e):r.refs&&r.refs.forEach(s=>S1(s,n,e))}},h6=(e,t)=>{t.shouldUseNativeValidation&&T_(e,t);const n={};for(const r in e){const s=_e(t.fields,r),o=Object.assign(e[r]||{},{ref:s&&s.ref});if(g6(t.names||Object.keys(e),r)){const l=Object.assign({},_e(n,r));qt(l,"root",o),qt(n,r,l)}else qt(n,r,o)}return n},g6=(e,t)=>e.some(n=>n.startsWith(t+"."));var m6=function(e,t){for(var n={};e.length;){var r=e[0],s=r.code,o=r.message,l=r.path.join(".");if(!n[l])if("unionErrors"in r){var u=r.unionErrors[0].errors[0];n[l]={message:u.message,type:u.code}}else n[l]={message:o,type:s};if("unionErrors"in r&&r.unionErrors.forEach(function(h){return h.errors.forEach(function(m){return e.push(m)})}),t){var d=n[l].types,f=d&&d[r.code];n[l]=x_(l,t,n,s,f?[].concat(f,r.message):r.message)}e.shift()}return n},an=function(e,t,n){return n===void 0&&(n={}),function(r,s,o){try{return Promise.resolve((function(l,u){try{var d=Promise.resolve(e[n.mode==="sync"?"parse":"parseAsync"](r,t)).then(function(f){return o.shouldUseNativeValidation&&T_({},o),{errors:{},values:n.raw?r:f}})}catch(f){return u(f)}return d&&d.then?d.then(void 0,u):d})(0,function(l){if((function(u){return Array.isArray(u?.errors)})(l))return{values:{},errors:h6(m6(l.errors,!o.shouldUseNativeValidation&&o.criteriaMode==="all"),o)};throw l}))}catch(l){return Promise.reject(l)}}},Wn=[];for(var Pv=0;Pv<256;++Pv)Wn.push((Pv+256).toString(16).slice(1));function v6(e,t=0){return(Wn[e[t+0]]+Wn[e[t+1]]+Wn[e[t+2]]+Wn[e[t+3]]+"-"+Wn[e[t+4]]+Wn[e[t+5]]+"-"+Wn[e[t+6]]+Wn[e[t+7]]+"-"+Wn[e[t+8]]+Wn[e[t+9]]+"-"+Wn[e[t+10]]+Wn[e[t+11]]+Wn[e[t+12]]+Wn[e[t+13]]+Wn[e[t+14]]+Wn[e[t+15]]).toLowerCase()}var Jf,y6=new Uint8Array(16);function b6(){if(!Jf&&(Jf=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!Jf))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Jf(y6)}var x6=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const C1={randomUUID:x6};function E1(e,t,n){if(C1.randomUUID&&!e)return C1.randomUUID();e=e||{};var r=e.random||(e.rng||b6)();return r[6]=r[6]&15|64,r[8]=r[8]&63|128,v6(r)}var Ot;(function(e){e.assertEqual=s=>s;function t(s){}e.assertIs=t;function n(s){throw new Error}e.assertNever=n,e.arrayToEnum=s=>{const o={};for(const l of s)o[l]=l;return o},e.getValidEnumValues=s=>{const o=e.objectKeys(s).filter(u=>typeof s[s[u]]!="number"),l={};for(const u of o)l[u]=s[u];return e.objectValues(l)},e.objectValues=s=>e.objectKeys(s).map(function(o){return s[o]}),e.objectKeys=typeof Object.keys=="function"?s=>Object.keys(s):s=>{const o=[];for(const l in s)Object.prototype.hasOwnProperty.call(s,l)&&o.push(l);return o},e.find=(s,o)=>{for(const l of s)if(o(l))return l},e.isInteger=typeof Number.isInteger=="function"?s=>Number.isInteger(s):s=>typeof s=="number"&&isFinite(s)&&Math.floor(s)===s;function r(s,o=" | "){return s.map(l=>typeof l=="string"?`'${l}'`:l).join(o)}e.joinValues=r,e.jsonStringifyReplacer=(s,o)=>typeof o=="bigint"?o.toString():o})(Ot||(Ot={}));var Gy;(function(e){e.mergeShapes=(t,n)=>({...t,...n})})(Gy||(Gy={}));const Le=Ot.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),pa=e=>{switch(typeof e){case"undefined":return Le.undefined;case"string":return Le.string;case"number":return isNaN(e)?Le.nan:Le.number;case"boolean":return Le.boolean;case"function":return Le.function;case"bigint":return Le.bigint;case"symbol":return Le.symbol;case"object":return Array.isArray(e)?Le.array:e===null?Le.null:e.then&&typeof e.then=="function"&&e.catch&&typeof e.catch=="function"?Le.promise:typeof Map<"u"&&e instanceof Map?Le.map:typeof Set<"u"&&e instanceof Set?Le.set:typeof Date<"u"&&e instanceof Date?Le.date:Le.object;default:return Le.unknown}},Ce=Ot.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]),w6=e=>JSON.stringify(e,null,2).replace(/"([^"]+)":/g,"$1:");class Hr extends Error{constructor(t){super(),this.issues=[],this.addIssue=r=>{this.issues=[...this.issues,r]},this.addIssues=(r=[])=>{this.issues=[...this.issues,...r]};const n=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,n):this.__proto__=n,this.name="ZodError",this.issues=t}get errors(){return this.issues}format(t){const n=t||function(o){return o.message},r={_errors:[]},s=o=>{for(const l of o.issues)if(l.code==="invalid_union")l.unionErrors.map(s);else if(l.code==="invalid_return_type")s(l.returnTypeError);else if(l.code==="invalid_arguments")s(l.argumentsError);else if(l.path.length===0)r._errors.push(n(l));else{let u=r,d=0;for(;dn.message){const n={},r=[];for(const s of this.issues)s.path.length>0?(n[s.path[0]]=n[s.path[0]]||[],n[s.path[0]].push(t(s))):r.push(t(s));return{formErrors:r,fieldErrors:n}}get formErrors(){return this.flatten()}}Hr.create=e=>new Hr(e);const Vl=(e,t)=>{let n;switch(e.code){case Ce.invalid_type:e.received===Le.undefined?n="Required":n=`Expected ${e.expected}, received ${e.received}`;break;case Ce.invalid_literal:n=`Invalid literal value, expected ${JSON.stringify(e.expected,Ot.jsonStringifyReplacer)}`;break;case Ce.unrecognized_keys:n=`Unrecognized key(s) in object: ${Ot.joinValues(e.keys,", ")}`;break;case Ce.invalid_union:n="Invalid input";break;case Ce.invalid_union_discriminator:n=`Invalid discriminator value. Expected ${Ot.joinValues(e.options)}`;break;case Ce.invalid_enum_value:n=`Invalid enum value. Expected ${Ot.joinValues(e.options)}, received '${e.received}'`;break;case Ce.invalid_arguments:n="Invalid function arguments";break;case Ce.invalid_return_type:n="Invalid function return type";break;case Ce.invalid_date:n="Invalid date";break;case Ce.invalid_string:typeof e.validation=="object"?"includes"in e.validation?(n=`Invalid input: must include "${e.validation.includes}"`,typeof e.validation.position=="number"&&(n=`${n} at one or more positions greater than or equal to ${e.validation.position}`)):"startsWith"in e.validation?n=`Invalid input: must start with "${e.validation.startsWith}"`:"endsWith"in e.validation?n=`Invalid input: must end with "${e.validation.endsWith}"`:Ot.assertNever(e.validation):e.validation!=="regex"?n=`Invalid ${e.validation}`:n="Invalid";break;case Ce.too_small:e.type==="array"?n=`Array must contain ${e.exact?"exactly":e.inclusive?"at least":"more than"} ${e.minimum} element(s)`:e.type==="string"?n=`String must contain ${e.exact?"exactly":e.inclusive?"at least":"over"} ${e.minimum} character(s)`:e.type==="number"?n=`Number must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${e.minimum}`:e.type==="date"?n=`Date must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(e.minimum))}`:n="Invalid input";break;case Ce.too_big:e.type==="array"?n=`Array must contain ${e.exact?"exactly":e.inclusive?"at most":"less than"} ${e.maximum} element(s)`:e.type==="string"?n=`String must contain ${e.exact?"exactly":e.inclusive?"at most":"under"} ${e.maximum} character(s)`:e.type==="number"?n=`Number must be ${e.exact?"exactly":e.inclusive?"less than or equal to":"less than"} ${e.maximum}`:e.type==="bigint"?n=`BigInt must be ${e.exact?"exactly":e.inclusive?"less than or equal to":"less than"} ${e.maximum}`:e.type==="date"?n=`Date must be ${e.exact?"exactly":e.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(e.maximum))}`:n="Invalid input";break;case Ce.custom:n="Invalid input";break;case Ce.invalid_intersection_types:n="Intersection results could not be merged";break;case Ce.not_multiple_of:n=`Number must be a multiple of ${e.multipleOf}`;break;case Ce.not_finite:n="Number must be finite";break;default:n=t.defaultError,Ot.assertNever(e)}return{message:n}};let N_=Vl;function S6(e){N_=e}function Yp(){return N_}const Xp=e=>{const{data:t,path:n,errorMaps:r,issueData:s}=e,o=[...n,...s.path||[]],l={...s,path:o};if(s.message!==void 0)return{...s,path:o,message:s.message};let u="";const d=r.filter(f=>!!f).slice().reverse();for(const f of d)u=f(l,{data:t,defaultError:u}).message;return{...s,path:o,message:u}},C6=[];function Ae(e,t){const n=Yp(),r=Xp({issueData:t,data:e.data,path:e.path,errorMaps:[e.common.contextualErrorMap,e.schemaErrorMap,n,n===Vl?void 0:Vl].filter(s=>!!s)});e.common.issues.push(r)}class sr{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(t,n){const r=[];for(const s of n){if(s.status==="aborted")return lt;s.status==="dirty"&&t.dirty(),r.push(s.value)}return{status:t.value,value:r}}static async mergeObjectAsync(t,n){const r=[];for(const s of n){const o=await s.key,l=await s.value;r.push({key:o,value:l})}return sr.mergeObjectSync(t,r)}static mergeObjectSync(t,n){const r={};for(const s of n){const{key:o,value:l}=s;if(o.status==="aborted"||l.status==="aborted")return lt;o.status==="dirty"&&t.dirty(),l.status==="dirty"&&t.dirty(),o.value!=="__proto__"&&(typeof l.value<"u"||s.alwaysSet)&&(r[o.value]=l.value)}return{status:t.value,value:r}}}const lt=Object.freeze({status:"aborted"}),Nl=e=>({status:"dirty",value:e}),fr=e=>({status:"valid",value:e}),Jy=e=>e.status==="aborted",Qy=e=>e.status==="dirty",Hu=e=>e.status==="valid",qu=e=>typeof Promise<"u"&&e instanceof Promise;function eh(e,t,n,r){if(typeof t=="function"?e!==t||!0:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t.get(e)}function M_(e,t,n,r,s){if(typeof t=="function"?e!==t||!0:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return t.set(e,n),n}var Ze;(function(e){e.errToObj=t=>typeof t=="string"?{message:t}:t||{},e.toString=t=>typeof t=="string"?t:t?.message})(Ze||(Ze={}));var yu,bu;class Qs{constructor(t,n,r,s){this._cachedPath=[],this.parent=t,this.data=n,this._path=r,this._key=s}get path(){return this._cachedPath.length||(this._key instanceof Array?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}const k1=(e,t)=>{if(Hu(t))return{success:!0,data:t.value};if(!e.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;const n=new Hr(e.common.issues);return this._error=n,this._error}}};function yt(e){if(!e)return{};const{errorMap:t,invalid_type_error:n,required_error:r,description:s}=e;if(t&&(n||r))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return t?{errorMap:t,description:s}:{errorMap:(l,u)=>{var d,f;const{message:h}=e;return l.code==="invalid_enum_value"?{message:h??u.defaultError}:typeof u.data>"u"?{message:(d=h??r)!==null&&d!==void 0?d:u.defaultError}:l.code!=="invalid_type"?{message:u.defaultError}:{message:(f=h??n)!==null&&f!==void 0?f:u.defaultError}},description:s}}class St{constructor(t){this.spa=this.safeParseAsync,this._def=t,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this)}get description(){return this._def.description}_getType(t){return pa(t.data)}_getOrReturnCtx(t,n){return n||{common:t.parent.common,data:t.data,parsedType:pa(t.data),schemaErrorMap:this._def.errorMap,path:t.path,parent:t.parent}}_processInputParams(t){return{status:new sr,ctx:{common:t.parent.common,data:t.data,parsedType:pa(t.data),schemaErrorMap:this._def.errorMap,path:t.path,parent:t.parent}}}_parseSync(t){const n=this._parse(t);if(qu(n))throw new Error("Synchronous parse encountered promise.");return n}_parseAsync(t){const n=this._parse(t);return Promise.resolve(n)}parse(t,n){const r=this.safeParse(t,n);if(r.success)return r.data;throw r.error}safeParse(t,n){var r;const s={common:{issues:[],async:(r=n?.async)!==null&&r!==void 0?r:!1,contextualErrorMap:n?.errorMap},path:n?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:t,parsedType:pa(t)},o=this._parseSync({data:t,path:s.path,parent:s});return k1(s,o)}async parseAsync(t,n){const r=await this.safeParseAsync(t,n);if(r.success)return r.data;throw r.error}async safeParseAsync(t,n){const r={common:{issues:[],contextualErrorMap:n?.errorMap,async:!0},path:n?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:t,parsedType:pa(t)},s=this._parse({data:t,path:r.path,parent:r}),o=await(qu(s)?s:Promise.resolve(s));return k1(r,o)}refine(t,n){const r=s=>typeof n=="string"||typeof n>"u"?{message:n}:typeof n=="function"?n(s):n;return this._refinement((s,o)=>{const l=t(s),u=()=>o.addIssue({code:Ce.custom,...r(s)});return typeof Promise<"u"&&l instanceof Promise?l.then(d=>d?!0:(u(),!1)):l?!0:(u(),!1)})}refinement(t,n){return this._refinement((r,s)=>t(r)?!0:(s.addIssue(typeof n=="function"?n(r,s):n),!1))}_refinement(t){return new Ms({schema:this,typeName:it.ZodEffects,effect:{type:"refinement",refinement:t}})}superRefine(t){return this._refinement(t)}optional(){return Ws.create(this,this._def)}nullable(){return ka.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return ks.create(this,this._def)}promise(){return ql.create(this,this._def)}or(t){return Ju.create([this,t],this._def)}and(t){return Qu.create(this,t,this._def)}transform(t){return new Ms({...yt(this._def),schema:this,typeName:it.ZodEffects,effect:{type:"transform",transform:t}})}default(t){const n=typeof t=="function"?t:()=>t;return new td({...yt(this._def),innerType:this,defaultValue:n,typeName:it.ZodDefault})}brand(){return new Rx({typeName:it.ZodBranded,type:this,...yt(this._def)})}catch(t){const n=typeof t=="function"?t:()=>t;return new nd({...yt(this._def),innerType:this,catchValue:n,typeName:it.ZodCatch})}describe(t){const n=this.constructor;return new n({...this._def,description:t})}pipe(t){return kd.create(this,t)}readonly(){return rd.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const E6=/^c[^\s-]{8,}$/i,k6=/^[0-9a-z]+$/,j6=/^[0-9A-HJKMNP-TV-Z]{26}$/,T6=/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i,N6=/^[a-z0-9_-]{21}$/i,M6=/^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/,_6=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,R6="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let Ov;const P6=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,O6=/^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/,I6=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,__="((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))",A6=new RegExp(`^${__}$`);function R_(e){let t="([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d";return e.precision?t=`${t}\\.\\d{${e.precision}}`:e.precision==null&&(t=`${t}(\\.\\d+)?`),t}function D6(e){return new RegExp(`^${R_(e)}$`)}function P_(e){let t=`${__}T${R_(e)}`;const n=[];return n.push(e.local?"Z?":"Z"),e.offset&&n.push("([+-]\\d{2}:?\\d{2})"),t=`${t}(${n.join("|")})`,new RegExp(`^${t}$`)}function F6(e,t){return!!((t==="v4"||!t)&&P6.test(e)||(t==="v6"||!t)&&O6.test(e))}class Cs extends St{_parse(t){if(this._def.coerce&&(t.data=String(t.data)),this._getType(t)!==Le.string){const o=this._getOrReturnCtx(t);return Ae(o,{code:Ce.invalid_type,expected:Le.string,received:o.parsedType}),lt}const r=new sr;let s;for(const o of this._def.checks)if(o.kind==="min")t.data.lengtho.value&&(s=this._getOrReturnCtx(t,s),Ae(s,{code:Ce.too_big,maximum:o.value,type:"string",inclusive:!0,exact:!1,message:o.message}),r.dirty());else if(o.kind==="length"){const l=t.data.length>o.value,u=t.data.lengtht.test(s),{validation:n,code:Ce.invalid_string,...Ze.errToObj(r)})}_addCheck(t){return new Cs({...this._def,checks:[...this._def.checks,t]})}email(t){return this._addCheck({kind:"email",...Ze.errToObj(t)})}url(t){return this._addCheck({kind:"url",...Ze.errToObj(t)})}emoji(t){return this._addCheck({kind:"emoji",...Ze.errToObj(t)})}uuid(t){return this._addCheck({kind:"uuid",...Ze.errToObj(t)})}nanoid(t){return this._addCheck({kind:"nanoid",...Ze.errToObj(t)})}cuid(t){return this._addCheck({kind:"cuid",...Ze.errToObj(t)})}cuid2(t){return this._addCheck({kind:"cuid2",...Ze.errToObj(t)})}ulid(t){return this._addCheck({kind:"ulid",...Ze.errToObj(t)})}base64(t){return this._addCheck({kind:"base64",...Ze.errToObj(t)})}ip(t){return this._addCheck({kind:"ip",...Ze.errToObj(t)})}datetime(t){var n,r;return typeof t=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:t}):this._addCheck({kind:"datetime",precision:typeof t?.precision>"u"?null:t?.precision,offset:(n=t?.offset)!==null&&n!==void 0?n:!1,local:(r=t?.local)!==null&&r!==void 0?r:!1,...Ze.errToObj(t?.message)})}date(t){return this._addCheck({kind:"date",message:t})}time(t){return typeof t=="string"?this._addCheck({kind:"time",precision:null,message:t}):this._addCheck({kind:"time",precision:typeof t?.precision>"u"?null:t?.precision,...Ze.errToObj(t?.message)})}duration(t){return this._addCheck({kind:"duration",...Ze.errToObj(t)})}regex(t,n){return this._addCheck({kind:"regex",regex:t,...Ze.errToObj(n)})}includes(t,n){return this._addCheck({kind:"includes",value:t,position:n?.position,...Ze.errToObj(n?.message)})}startsWith(t,n){return this._addCheck({kind:"startsWith",value:t,...Ze.errToObj(n)})}endsWith(t,n){return this._addCheck({kind:"endsWith",value:t,...Ze.errToObj(n)})}min(t,n){return this._addCheck({kind:"min",value:t,...Ze.errToObj(n)})}max(t,n){return this._addCheck({kind:"max",value:t,...Ze.errToObj(n)})}length(t,n){return this._addCheck({kind:"length",value:t,...Ze.errToObj(n)})}nonempty(t){return this.min(1,Ze.errToObj(t))}trim(){return new Cs({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new Cs({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new Cs({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(t=>t.kind==="datetime")}get isDate(){return!!this._def.checks.find(t=>t.kind==="date")}get isTime(){return!!this._def.checks.find(t=>t.kind==="time")}get isDuration(){return!!this._def.checks.find(t=>t.kind==="duration")}get isEmail(){return!!this._def.checks.find(t=>t.kind==="email")}get isURL(){return!!this._def.checks.find(t=>t.kind==="url")}get isEmoji(){return!!this._def.checks.find(t=>t.kind==="emoji")}get isUUID(){return!!this._def.checks.find(t=>t.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(t=>t.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(t=>t.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(t=>t.kind==="cuid2")}get isULID(){return!!this._def.checks.find(t=>t.kind==="ulid")}get isIP(){return!!this._def.checks.find(t=>t.kind==="ip")}get isBase64(){return!!this._def.checks.find(t=>t.kind==="base64")}get minLength(){let t=null;for(const n of this._def.checks)n.kind==="min"&&(t===null||n.value>t)&&(t=n.value);return t}get maxLength(){let t=null;for(const n of this._def.checks)n.kind==="max"&&(t===null||n.value{var t;return new Cs({checks:[],typeName:it.ZodString,coerce:(t=e?.coerce)!==null&&t!==void 0?t:!1,...yt(e)})};function L6(e,t){const n=(e.toString().split(".")[1]||"").length,r=(t.toString().split(".")[1]||"").length,s=n>r?n:r,o=parseInt(e.toFixed(s).replace(".","")),l=parseInt(t.toFixed(s).replace(".",""));return o%l/Math.pow(10,s)}class Sa extends St{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(t){if(this._def.coerce&&(t.data=Number(t.data)),this._getType(t)!==Le.number){const o=this._getOrReturnCtx(t);return Ae(o,{code:Ce.invalid_type,expected:Le.number,received:o.parsedType}),lt}let r;const s=new sr;for(const o of this._def.checks)o.kind==="int"?Ot.isInteger(t.data)||(r=this._getOrReturnCtx(t,r),Ae(r,{code:Ce.invalid_type,expected:"integer",received:"float",message:o.message}),s.dirty()):o.kind==="min"?(o.inclusive?t.datao.value:t.data>=o.value)&&(r=this._getOrReturnCtx(t,r),Ae(r,{code:Ce.too_big,maximum:o.value,type:"number",inclusive:o.inclusive,exact:!1,message:o.message}),s.dirty()):o.kind==="multipleOf"?L6(t.data,o.value)!==0&&(r=this._getOrReturnCtx(t,r),Ae(r,{code:Ce.not_multiple_of,multipleOf:o.value,message:o.message}),s.dirty()):o.kind==="finite"?Number.isFinite(t.data)||(r=this._getOrReturnCtx(t,r),Ae(r,{code:Ce.not_finite,message:o.message}),s.dirty()):Ot.assertNever(o);return{status:s.value,value:t.data}}gte(t,n){return this.setLimit("min",t,!0,Ze.toString(n))}gt(t,n){return this.setLimit("min",t,!1,Ze.toString(n))}lte(t,n){return this.setLimit("max",t,!0,Ze.toString(n))}lt(t,n){return this.setLimit("max",t,!1,Ze.toString(n))}setLimit(t,n,r,s){return new Sa({...this._def,checks:[...this._def.checks,{kind:t,value:n,inclusive:r,message:Ze.toString(s)}]})}_addCheck(t){return new Sa({...this._def,checks:[...this._def.checks,t]})}int(t){return this._addCheck({kind:"int",message:Ze.toString(t)})}positive(t){return this._addCheck({kind:"min",value:0,inclusive:!1,message:Ze.toString(t)})}negative(t){return this._addCheck({kind:"max",value:0,inclusive:!1,message:Ze.toString(t)})}nonpositive(t){return this._addCheck({kind:"max",value:0,inclusive:!0,message:Ze.toString(t)})}nonnegative(t){return this._addCheck({kind:"min",value:0,inclusive:!0,message:Ze.toString(t)})}multipleOf(t,n){return this._addCheck({kind:"multipleOf",value:t,message:Ze.toString(n)})}finite(t){return this._addCheck({kind:"finite",message:Ze.toString(t)})}safe(t){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:Ze.toString(t)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:Ze.toString(t)})}get minValue(){let t=null;for(const n of this._def.checks)n.kind==="min"&&(t===null||n.value>t)&&(t=n.value);return t}get maxValue(){let t=null;for(const n of this._def.checks)n.kind==="max"&&(t===null||n.valuet.kind==="int"||t.kind==="multipleOf"&&Ot.isInteger(t.value))}get isFinite(){let t=null,n=null;for(const r of this._def.checks){if(r.kind==="finite"||r.kind==="int"||r.kind==="multipleOf")return!0;r.kind==="min"?(n===null||r.value>n)&&(n=r.value):r.kind==="max"&&(t===null||r.valuenew Sa({checks:[],typeName:it.ZodNumber,coerce:e?.coerce||!1,...yt(e)});class Ca extends St{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(t){if(this._def.coerce&&(t.data=BigInt(t.data)),this._getType(t)!==Le.bigint){const o=this._getOrReturnCtx(t);return Ae(o,{code:Ce.invalid_type,expected:Le.bigint,received:o.parsedType}),lt}let r;const s=new sr;for(const o of this._def.checks)o.kind==="min"?(o.inclusive?t.datao.value:t.data>=o.value)&&(r=this._getOrReturnCtx(t,r),Ae(r,{code:Ce.too_big,type:"bigint",maximum:o.value,inclusive:o.inclusive,message:o.message}),s.dirty()):o.kind==="multipleOf"?t.data%o.value!==BigInt(0)&&(r=this._getOrReturnCtx(t,r),Ae(r,{code:Ce.not_multiple_of,multipleOf:o.value,message:o.message}),s.dirty()):Ot.assertNever(o);return{status:s.value,value:t.data}}gte(t,n){return this.setLimit("min",t,!0,Ze.toString(n))}gt(t,n){return this.setLimit("min",t,!1,Ze.toString(n))}lte(t,n){return this.setLimit("max",t,!0,Ze.toString(n))}lt(t,n){return this.setLimit("max",t,!1,Ze.toString(n))}setLimit(t,n,r,s){return new Ca({...this._def,checks:[...this._def.checks,{kind:t,value:n,inclusive:r,message:Ze.toString(s)}]})}_addCheck(t){return new Ca({...this._def,checks:[...this._def.checks,t]})}positive(t){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:Ze.toString(t)})}negative(t){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:Ze.toString(t)})}nonpositive(t){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:Ze.toString(t)})}nonnegative(t){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:Ze.toString(t)})}multipleOf(t,n){return this._addCheck({kind:"multipleOf",value:t,message:Ze.toString(n)})}get minValue(){let t=null;for(const n of this._def.checks)n.kind==="min"&&(t===null||n.value>t)&&(t=n.value);return t}get maxValue(){let t=null;for(const n of this._def.checks)n.kind==="max"&&(t===null||n.value{var t;return new Ca({checks:[],typeName:it.ZodBigInt,coerce:(t=e?.coerce)!==null&&t!==void 0?t:!1,...yt(e)})};class Ku extends St{_parse(t){if(this._def.coerce&&(t.data=!!t.data),this._getType(t)!==Le.boolean){const r=this._getOrReturnCtx(t);return Ae(r,{code:Ce.invalid_type,expected:Le.boolean,received:r.parsedType}),lt}return fr(t.data)}}Ku.create=e=>new Ku({typeName:it.ZodBoolean,coerce:e?.coerce||!1,...yt(e)});class Ti extends St{_parse(t){if(this._def.coerce&&(t.data=new Date(t.data)),this._getType(t)!==Le.date){const o=this._getOrReturnCtx(t);return Ae(o,{code:Ce.invalid_type,expected:Le.date,received:o.parsedType}),lt}if(isNaN(t.data.getTime())){const o=this._getOrReturnCtx(t);return Ae(o,{code:Ce.invalid_date}),lt}const r=new sr;let s;for(const o of this._def.checks)o.kind==="min"?t.data.getTime()o.value&&(s=this._getOrReturnCtx(t,s),Ae(s,{code:Ce.too_big,message:o.message,inclusive:!0,exact:!1,maximum:o.value,type:"date"}),r.dirty()):Ot.assertNever(o);return{status:r.value,value:new Date(t.data.getTime())}}_addCheck(t){return new Ti({...this._def,checks:[...this._def.checks,t]})}min(t,n){return this._addCheck({kind:"min",value:t.getTime(),message:Ze.toString(n)})}max(t,n){return this._addCheck({kind:"max",value:t.getTime(),message:Ze.toString(n)})}get minDate(){let t=null;for(const n of this._def.checks)n.kind==="min"&&(t===null||n.value>t)&&(t=n.value);return t!=null?new Date(t):null}get maxDate(){let t=null;for(const n of this._def.checks)n.kind==="max"&&(t===null||n.valuenew Ti({checks:[],coerce:e?.coerce||!1,typeName:it.ZodDate,...yt(e)});class th extends St{_parse(t){if(this._getType(t)!==Le.symbol){const r=this._getOrReturnCtx(t);return Ae(r,{code:Ce.invalid_type,expected:Le.symbol,received:r.parsedType}),lt}return fr(t.data)}}th.create=e=>new th({typeName:it.ZodSymbol,...yt(e)});class Wu extends St{_parse(t){if(this._getType(t)!==Le.undefined){const r=this._getOrReturnCtx(t);return Ae(r,{code:Ce.invalid_type,expected:Le.undefined,received:r.parsedType}),lt}return fr(t.data)}}Wu.create=e=>new Wu({typeName:it.ZodUndefined,...yt(e)});class Gu extends St{_parse(t){if(this._getType(t)!==Le.null){const r=this._getOrReturnCtx(t);return Ae(r,{code:Ce.invalid_type,expected:Le.null,received:r.parsedType}),lt}return fr(t.data)}}Gu.create=e=>new Gu({typeName:it.ZodNull,...yt(e)});class Hl extends St{constructor(){super(...arguments),this._any=!0}_parse(t){return fr(t.data)}}Hl.create=e=>new Hl({typeName:it.ZodAny,...yt(e)});class mi extends St{constructor(){super(...arguments),this._unknown=!0}_parse(t){return fr(t.data)}}mi.create=e=>new mi({typeName:it.ZodUnknown,...yt(e)});class Ro extends St{_parse(t){const n=this._getOrReturnCtx(t);return Ae(n,{code:Ce.invalid_type,expected:Le.never,received:n.parsedType}),lt}}Ro.create=e=>new Ro({typeName:it.ZodNever,...yt(e)});class nh extends St{_parse(t){if(this._getType(t)!==Le.undefined){const r=this._getOrReturnCtx(t);return Ae(r,{code:Ce.invalid_type,expected:Le.void,received:r.parsedType}),lt}return fr(t.data)}}nh.create=e=>new nh({typeName:it.ZodVoid,...yt(e)});class ks extends St{_parse(t){const{ctx:n,status:r}=this._processInputParams(t),s=this._def;if(n.parsedType!==Le.array)return Ae(n,{code:Ce.invalid_type,expected:Le.array,received:n.parsedType}),lt;if(s.exactLength!==null){const l=n.data.length>s.exactLength.value,u=n.data.lengths.maxLength.value&&(Ae(n,{code:Ce.too_big,maximum:s.maxLength.value,type:"array",inclusive:!0,exact:!1,message:s.maxLength.message}),r.dirty()),n.common.async)return Promise.all([...n.data].map((l,u)=>s.type._parseAsync(new Qs(n,l,n.path,u)))).then(l=>sr.mergeArray(r,l));const o=[...n.data].map((l,u)=>s.type._parseSync(new Qs(n,l,n.path,u)));return sr.mergeArray(r,o)}get element(){return this._def.type}min(t,n){return new ks({...this._def,minLength:{value:t,message:Ze.toString(n)}})}max(t,n){return new ks({...this._def,maxLength:{value:t,message:Ze.toString(n)}})}length(t,n){return new ks({...this._def,exactLength:{value:t,message:Ze.toString(n)}})}nonempty(t){return this.min(1,t)}}ks.create=(e,t)=>new ks({type:e,minLength:null,maxLength:null,exactLength:null,typeName:it.ZodArray,...yt(t)});function El(e){if(e instanceof gn){const t={};for(const n in e.shape){const r=e.shape[n];t[n]=Ws.create(El(r))}return new gn({...e._def,shape:()=>t})}else return e instanceof ks?new ks({...e._def,type:El(e.element)}):e instanceof Ws?Ws.create(El(e.unwrap())):e instanceof ka?ka.create(El(e.unwrap())):e instanceof Zs?Zs.create(e.items.map(t=>El(t))):e}class gn extends St{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;const t=this._def.shape(),n=Ot.objectKeys(t);return this._cached={shape:t,keys:n}}_parse(t){if(this._getType(t)!==Le.object){const f=this._getOrReturnCtx(t);return Ae(f,{code:Ce.invalid_type,expected:Le.object,received:f.parsedType}),lt}const{status:r,ctx:s}=this._processInputParams(t),{shape:o,keys:l}=this._getCached(),u=[];if(!(this._def.catchall instanceof Ro&&this._def.unknownKeys==="strip"))for(const f in s.data)l.includes(f)||u.push(f);const d=[];for(const f of l){const h=o[f],m=s.data[f];d.push({key:{status:"valid",value:f},value:h._parse(new Qs(s,m,s.path,f)),alwaysSet:f in s.data})}if(this._def.catchall instanceof Ro){const f=this._def.unknownKeys;if(f==="passthrough")for(const h of u)d.push({key:{status:"valid",value:h},value:{status:"valid",value:s.data[h]}});else if(f==="strict")u.length>0&&(Ae(s,{code:Ce.unrecognized_keys,keys:u}),r.dirty());else if(f!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const f=this._def.catchall;for(const h of u){const m=s.data[h];d.push({key:{status:"valid",value:h},value:f._parse(new Qs(s,m,s.path,h)),alwaysSet:h in s.data})}}return s.common.async?Promise.resolve().then(async()=>{const f=[];for(const h of d){const m=await h.key,g=await h.value;f.push({key:m,value:g,alwaysSet:h.alwaysSet})}return f}).then(f=>sr.mergeObjectSync(r,f)):sr.mergeObjectSync(r,d)}get shape(){return this._def.shape()}strict(t){return Ze.errToObj,new gn({...this._def,unknownKeys:"strict",...t!==void 0?{errorMap:(n,r)=>{var s,o,l,u;const d=(l=(o=(s=this._def).errorMap)===null||o===void 0?void 0:o.call(s,n,r).message)!==null&&l!==void 0?l:r.defaultError;return n.code==="unrecognized_keys"?{message:(u=Ze.errToObj(t).message)!==null&&u!==void 0?u:d}:{message:d}}}:{}})}strip(){return new gn({...this._def,unknownKeys:"strip"})}passthrough(){return new gn({...this._def,unknownKeys:"passthrough"})}extend(t){return new gn({...this._def,shape:()=>({...this._def.shape(),...t})})}merge(t){return new gn({unknownKeys:t._def.unknownKeys,catchall:t._def.catchall,shape:()=>({...this._def.shape(),...t._def.shape()}),typeName:it.ZodObject})}setKey(t,n){return this.augment({[t]:n})}catchall(t){return new gn({...this._def,catchall:t})}pick(t){const n={};return Ot.objectKeys(t).forEach(r=>{t[r]&&this.shape[r]&&(n[r]=this.shape[r])}),new gn({...this._def,shape:()=>n})}omit(t){const n={};return Ot.objectKeys(this.shape).forEach(r=>{t[r]||(n[r]=this.shape[r])}),new gn({...this._def,shape:()=>n})}deepPartial(){return El(this)}partial(t){const n={};return Ot.objectKeys(this.shape).forEach(r=>{const s=this.shape[r];t&&!t[r]?n[r]=s:n[r]=s.optional()}),new gn({...this._def,shape:()=>n})}required(t){const n={};return Ot.objectKeys(this.shape).forEach(r=>{if(t&&!t[r])n[r]=this.shape[r];else{let o=this.shape[r];for(;o instanceof Ws;)o=o._def.innerType;n[r]=o}}),new gn({...this._def,shape:()=>n})}keyof(){return O_(Ot.objectKeys(this.shape))}}gn.create=(e,t)=>new gn({shape:()=>e,unknownKeys:"strip",catchall:Ro.create(),typeName:it.ZodObject,...yt(t)});gn.strictCreate=(e,t)=>new gn({shape:()=>e,unknownKeys:"strict",catchall:Ro.create(),typeName:it.ZodObject,...yt(t)});gn.lazycreate=(e,t)=>new gn({shape:e,unknownKeys:"strip",catchall:Ro.create(),typeName:it.ZodObject,...yt(t)});class Ju extends St{_parse(t){const{ctx:n}=this._processInputParams(t),r=this._def.options;function s(o){for(const u of o)if(u.result.status==="valid")return u.result;for(const u of o)if(u.result.status==="dirty")return n.common.issues.push(...u.ctx.common.issues),u.result;const l=o.map(u=>new Hr(u.ctx.common.issues));return Ae(n,{code:Ce.invalid_union,unionErrors:l}),lt}if(n.common.async)return Promise.all(r.map(async o=>{const l={...n,common:{...n.common,issues:[]},parent:null};return{result:await o._parseAsync({data:n.data,path:n.path,parent:l}),ctx:l}})).then(s);{let o;const l=[];for(const d of r){const f={...n,common:{...n.common,issues:[]},parent:null},h=d._parseSync({data:n.data,path:n.path,parent:f});if(h.status==="valid")return h;h.status==="dirty"&&!o&&(o={result:h,ctx:f}),f.common.issues.length&&l.push(f.common.issues)}if(o)return n.common.issues.push(...o.ctx.common.issues),o.result;const u=l.map(d=>new Hr(d));return Ae(n,{code:Ce.invalid_union,unionErrors:u}),lt}}get options(){return this._def.options}}Ju.create=(e,t)=>new Ju({options:e,typeName:it.ZodUnion,...yt(t)});const mo=e=>e instanceof Yu?mo(e.schema):e instanceof Ms?mo(e.innerType()):e instanceof Xu?[e.value]:e instanceof Ea?e.options:e instanceof ed?Ot.objectValues(e.enum):e instanceof td?mo(e._def.innerType):e instanceof Wu?[void 0]:e instanceof Gu?[null]:e instanceof Ws?[void 0,...mo(e.unwrap())]:e instanceof ka?[null,...mo(e.unwrap())]:e instanceof Rx||e instanceof rd?mo(e.unwrap()):e instanceof nd?mo(e._def.innerType):[];class Wh extends St{_parse(t){const{ctx:n}=this._processInputParams(t);if(n.parsedType!==Le.object)return Ae(n,{code:Ce.invalid_type,expected:Le.object,received:n.parsedType}),lt;const r=this.discriminator,s=n.data[r],o=this.optionsMap.get(s);return o?n.common.async?o._parseAsync({data:n.data,path:n.path,parent:n}):o._parseSync({data:n.data,path:n.path,parent:n}):(Ae(n,{code:Ce.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[r]}),lt)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(t,n,r){const s=new Map;for(const o of n){const l=mo(o.shape[t]);if(!l.length)throw new Error(`A discriminator value for key \`${t}\` could not be extracted from all schema options`);for(const u of l){if(s.has(u))throw new Error(`Discriminator property ${String(t)} has duplicate value ${String(u)}`);s.set(u,o)}}return new Wh({typeName:it.ZodDiscriminatedUnion,discriminator:t,options:n,optionsMap:s,...yt(r)})}}function Zy(e,t){const n=pa(e),r=pa(t);if(e===t)return{valid:!0,data:e};if(n===Le.object&&r===Le.object){const s=Ot.objectKeys(t),o=Ot.objectKeys(e).filter(u=>s.indexOf(u)!==-1),l={...e,...t};for(const u of o){const d=Zy(e[u],t[u]);if(!d.valid)return{valid:!1};l[u]=d.data}return{valid:!0,data:l}}else if(n===Le.array&&r===Le.array){if(e.length!==t.length)return{valid:!1};const s=[];for(let o=0;o{if(Jy(o)||Jy(l))return lt;const u=Zy(o.value,l.value);return u.valid?((Qy(o)||Qy(l))&&n.dirty(),{status:n.value,value:u.data}):(Ae(r,{code:Ce.invalid_intersection_types}),lt)};return r.common.async?Promise.all([this._def.left._parseAsync({data:r.data,path:r.path,parent:r}),this._def.right._parseAsync({data:r.data,path:r.path,parent:r})]).then(([o,l])=>s(o,l)):s(this._def.left._parseSync({data:r.data,path:r.path,parent:r}),this._def.right._parseSync({data:r.data,path:r.path,parent:r}))}}Qu.create=(e,t,n)=>new Qu({left:e,right:t,typeName:it.ZodIntersection,...yt(n)});class Zs extends St{_parse(t){const{status:n,ctx:r}=this._processInputParams(t);if(r.parsedType!==Le.array)return Ae(r,{code:Ce.invalid_type,expected:Le.array,received:r.parsedType}),lt;if(r.data.lengththis._def.items.length&&(Ae(r,{code:Ce.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),n.dirty());const o=[...r.data].map((l,u)=>{const d=this._def.items[u]||this._def.rest;return d?d._parse(new Qs(r,l,r.path,u)):null}).filter(l=>!!l);return r.common.async?Promise.all(o).then(l=>sr.mergeArray(n,l)):sr.mergeArray(n,o)}get items(){return this._def.items}rest(t){return new Zs({...this._def,rest:t})}}Zs.create=(e,t)=>{if(!Array.isArray(e))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new Zs({items:e,typeName:it.ZodTuple,rest:null,...yt(t)})};class Zu extends St{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(t){const{status:n,ctx:r}=this._processInputParams(t);if(r.parsedType!==Le.object)return Ae(r,{code:Ce.invalid_type,expected:Le.object,received:r.parsedType}),lt;const s=[],o=this._def.keyType,l=this._def.valueType;for(const u in r.data)s.push({key:o._parse(new Qs(r,u,r.path,u)),value:l._parse(new Qs(r,r.data[u],r.path,u)),alwaysSet:u in r.data});return r.common.async?sr.mergeObjectAsync(n,s):sr.mergeObjectSync(n,s)}get element(){return this._def.valueType}static create(t,n,r){return n instanceof St?new Zu({keyType:t,valueType:n,typeName:it.ZodRecord,...yt(r)}):new Zu({keyType:Cs.create(),valueType:t,typeName:it.ZodRecord,...yt(n)})}}class rh extends St{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(t){const{status:n,ctx:r}=this._processInputParams(t);if(r.parsedType!==Le.map)return Ae(r,{code:Ce.invalid_type,expected:Le.map,received:r.parsedType}),lt;const s=this._def.keyType,o=this._def.valueType,l=[...r.data.entries()].map(([u,d],f)=>({key:s._parse(new Qs(r,u,r.path,[f,"key"])),value:o._parse(new Qs(r,d,r.path,[f,"value"]))}));if(r.common.async){const u=new Map;return Promise.resolve().then(async()=>{for(const d of l){const f=await d.key,h=await d.value;if(f.status==="aborted"||h.status==="aborted")return lt;(f.status==="dirty"||h.status==="dirty")&&n.dirty(),u.set(f.value,h.value)}return{status:n.value,value:u}})}else{const u=new Map;for(const d of l){const f=d.key,h=d.value;if(f.status==="aborted"||h.status==="aborted")return lt;(f.status==="dirty"||h.status==="dirty")&&n.dirty(),u.set(f.value,h.value)}return{status:n.value,value:u}}}}rh.create=(e,t,n)=>new rh({valueType:t,keyType:e,typeName:it.ZodMap,...yt(n)});class Ni extends St{_parse(t){const{status:n,ctx:r}=this._processInputParams(t);if(r.parsedType!==Le.set)return Ae(r,{code:Ce.invalid_type,expected:Le.set,received:r.parsedType}),lt;const s=this._def;s.minSize!==null&&r.data.sizes.maxSize.value&&(Ae(r,{code:Ce.too_big,maximum:s.maxSize.value,type:"set",inclusive:!0,exact:!1,message:s.maxSize.message}),n.dirty());const o=this._def.valueType;function l(d){const f=new Set;for(const h of d){if(h.status==="aborted")return lt;h.status==="dirty"&&n.dirty(),f.add(h.value)}return{status:n.value,value:f}}const u=[...r.data.values()].map((d,f)=>o._parse(new Qs(r,d,r.path,f)));return r.common.async?Promise.all(u).then(d=>l(d)):l(u)}min(t,n){return new Ni({...this._def,minSize:{value:t,message:Ze.toString(n)}})}max(t,n){return new Ni({...this._def,maxSize:{value:t,message:Ze.toString(n)}})}size(t,n){return this.min(t,n).max(t,n)}nonempty(t){return this.min(1,t)}}Ni.create=(e,t)=>new Ni({valueType:e,minSize:null,maxSize:null,typeName:it.ZodSet,...yt(t)});class Ol extends St{constructor(){super(...arguments),this.validate=this.implement}_parse(t){const{ctx:n}=this._processInputParams(t);if(n.parsedType!==Le.function)return Ae(n,{code:Ce.invalid_type,expected:Le.function,received:n.parsedType}),lt;function r(u,d){return Xp({data:u,path:n.path,errorMaps:[n.common.contextualErrorMap,n.schemaErrorMap,Yp(),Vl].filter(f=>!!f),issueData:{code:Ce.invalid_arguments,argumentsError:d}})}function s(u,d){return Xp({data:u,path:n.path,errorMaps:[n.common.contextualErrorMap,n.schemaErrorMap,Yp(),Vl].filter(f=>!!f),issueData:{code:Ce.invalid_return_type,returnTypeError:d}})}const o={errorMap:n.common.contextualErrorMap},l=n.data;if(this._def.returns instanceof ql){const u=this;return fr(async function(...d){const f=new Hr([]),h=await u._def.args.parseAsync(d,o).catch(x=>{throw f.addIssue(r(d,x)),f}),m=await Reflect.apply(l,this,h);return await u._def.returns._def.type.parseAsync(m,o).catch(x=>{throw f.addIssue(s(m,x)),f})})}else{const u=this;return fr(function(...d){const f=u._def.args.safeParse(d,o);if(!f.success)throw new Hr([r(d,f.error)]);const h=Reflect.apply(l,this,f.data),m=u._def.returns.safeParse(h,o);if(!m.success)throw new Hr([s(h,m.error)]);return m.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...t){return new Ol({...this._def,args:Zs.create(t).rest(mi.create())})}returns(t){return new Ol({...this._def,returns:t})}implement(t){return this.parse(t)}strictImplement(t){return this.parse(t)}static create(t,n,r){return new Ol({args:t||Zs.create([]).rest(mi.create()),returns:n||mi.create(),typeName:it.ZodFunction,...yt(r)})}}class Yu extends St{get schema(){return this._def.getter()}_parse(t){const{ctx:n}=this._processInputParams(t);return this._def.getter()._parse({data:n.data,path:n.path,parent:n})}}Yu.create=(e,t)=>new Yu({getter:e,typeName:it.ZodLazy,...yt(t)});class Xu extends St{_parse(t){if(t.data!==this._def.value){const n=this._getOrReturnCtx(t);return Ae(n,{received:n.data,code:Ce.invalid_literal,expected:this._def.value}),lt}return{status:"valid",value:t.data}}get value(){return this._def.value}}Xu.create=(e,t)=>new Xu({value:e,typeName:it.ZodLiteral,...yt(t)});function O_(e,t){return new Ea({values:e,typeName:it.ZodEnum,...yt(t)})}class Ea extends St{constructor(){super(...arguments),yu.set(this,void 0)}_parse(t){if(typeof t.data!="string"){const n=this._getOrReturnCtx(t),r=this._def.values;return Ae(n,{expected:Ot.joinValues(r),received:n.parsedType,code:Ce.invalid_type}),lt}if(eh(this,yu)||M_(this,yu,new Set(this._def.values)),!eh(this,yu).has(t.data)){const n=this._getOrReturnCtx(t),r=this._def.values;return Ae(n,{received:n.data,code:Ce.invalid_enum_value,options:r}),lt}return fr(t.data)}get options(){return this._def.values}get enum(){const t={};for(const n of this._def.values)t[n]=n;return t}get Values(){const t={};for(const n of this._def.values)t[n]=n;return t}get Enum(){const t={};for(const n of this._def.values)t[n]=n;return t}extract(t,n=this._def){return Ea.create(t,{...this._def,...n})}exclude(t,n=this._def){return Ea.create(this.options.filter(r=>!t.includes(r)),{...this._def,...n})}}yu=new WeakMap;Ea.create=O_;class ed extends St{constructor(){super(...arguments),bu.set(this,void 0)}_parse(t){const n=Ot.getValidEnumValues(this._def.values),r=this._getOrReturnCtx(t);if(r.parsedType!==Le.string&&r.parsedType!==Le.number){const s=Ot.objectValues(n);return Ae(r,{expected:Ot.joinValues(s),received:r.parsedType,code:Ce.invalid_type}),lt}if(eh(this,bu)||M_(this,bu,new Set(Ot.getValidEnumValues(this._def.values))),!eh(this,bu).has(t.data)){const s=Ot.objectValues(n);return Ae(r,{received:r.data,code:Ce.invalid_enum_value,options:s}),lt}return fr(t.data)}get enum(){return this._def.values}}bu=new WeakMap;ed.create=(e,t)=>new ed({values:e,typeName:it.ZodNativeEnum,...yt(t)});class ql extends St{unwrap(){return this._def.type}_parse(t){const{ctx:n}=this._processInputParams(t);if(n.parsedType!==Le.promise&&n.common.async===!1)return Ae(n,{code:Ce.invalid_type,expected:Le.promise,received:n.parsedType}),lt;const r=n.parsedType===Le.promise?n.data:Promise.resolve(n.data);return fr(r.then(s=>this._def.type.parseAsync(s,{path:n.path,errorMap:n.common.contextualErrorMap})))}}ql.create=(e,t)=>new ql({type:e,typeName:it.ZodPromise,...yt(t)});class Ms extends St{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===it.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(t){const{status:n,ctx:r}=this._processInputParams(t),s=this._def.effect||null,o={addIssue:l=>{Ae(r,l),l.fatal?n.abort():n.dirty()},get path(){return r.path}};if(o.addIssue=o.addIssue.bind(o),s.type==="preprocess"){const l=s.transform(r.data,o);if(r.common.async)return Promise.resolve(l).then(async u=>{if(n.value==="aborted")return lt;const d=await this._def.schema._parseAsync({data:u,path:r.path,parent:r});return d.status==="aborted"?lt:d.status==="dirty"||n.value==="dirty"?Nl(d.value):d});{if(n.value==="aborted")return lt;const u=this._def.schema._parseSync({data:l,path:r.path,parent:r});return u.status==="aborted"?lt:u.status==="dirty"||n.value==="dirty"?Nl(u.value):u}}if(s.type==="refinement"){const l=u=>{const d=s.refinement(u,o);if(r.common.async)return Promise.resolve(d);if(d instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return u};if(r.common.async===!1){const u=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});return u.status==="aborted"?lt:(u.status==="dirty"&&n.dirty(),l(u.value),{status:n.value,value:u.value})}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(u=>u.status==="aborted"?lt:(u.status==="dirty"&&n.dirty(),l(u.value).then(()=>({status:n.value,value:u.value}))))}if(s.type==="transform")if(r.common.async===!1){const l=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});if(!Hu(l))return l;const u=s.transform(l.value,o);if(u instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:n.value,value:u}}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(l=>Hu(l)?Promise.resolve(s.transform(l.value,o)).then(u=>({status:n.value,value:u})):l);Ot.assertNever(s)}}Ms.create=(e,t,n)=>new Ms({schema:e,typeName:it.ZodEffects,effect:t,...yt(n)});Ms.createWithPreprocess=(e,t,n)=>new Ms({schema:t,effect:{type:"preprocess",transform:e},typeName:it.ZodEffects,...yt(n)});class Ws extends St{_parse(t){return this._getType(t)===Le.undefined?fr(void 0):this._def.innerType._parse(t)}unwrap(){return this._def.innerType}}Ws.create=(e,t)=>new Ws({innerType:e,typeName:it.ZodOptional,...yt(t)});class ka extends St{_parse(t){return this._getType(t)===Le.null?fr(null):this._def.innerType._parse(t)}unwrap(){return this._def.innerType}}ka.create=(e,t)=>new ka({innerType:e,typeName:it.ZodNullable,...yt(t)});class td extends St{_parse(t){const{ctx:n}=this._processInputParams(t);let r=n.data;return n.parsedType===Le.undefined&&(r=this._def.defaultValue()),this._def.innerType._parse({data:r,path:n.path,parent:n})}removeDefault(){return this._def.innerType}}td.create=(e,t)=>new td({innerType:e,typeName:it.ZodDefault,defaultValue:typeof t.default=="function"?t.default:()=>t.default,...yt(t)});class nd extends St{_parse(t){const{ctx:n}=this._processInputParams(t),r={...n,common:{...n.common,issues:[]}},s=this._def.innerType._parse({data:r.data,path:r.path,parent:{...r}});return qu(s)?s.then(o=>({status:"valid",value:o.status==="valid"?o.value:this._def.catchValue({get error(){return new Hr(r.common.issues)},input:r.data})})):{status:"valid",value:s.status==="valid"?s.value:this._def.catchValue({get error(){return new Hr(r.common.issues)},input:r.data})}}removeCatch(){return this._def.innerType}}nd.create=(e,t)=>new nd({innerType:e,typeName:it.ZodCatch,catchValue:typeof t.catch=="function"?t.catch:()=>t.catch,...yt(t)});class sh extends St{_parse(t){if(this._getType(t)!==Le.nan){const r=this._getOrReturnCtx(t);return Ae(r,{code:Ce.invalid_type,expected:Le.nan,received:r.parsedType}),lt}return{status:"valid",value:t.data}}}sh.create=e=>new sh({typeName:it.ZodNaN,...yt(e)});const $6=Symbol("zod_brand");class Rx extends St{_parse(t){const{ctx:n}=this._processInputParams(t),r=n.data;return this._def.type._parse({data:r,path:n.path,parent:n})}unwrap(){return this._def.type}}class kd extends St{_parse(t){const{status:n,ctx:r}=this._processInputParams(t);if(r.common.async)return(async()=>{const o=await this._def.in._parseAsync({data:r.data,path:r.path,parent:r});return o.status==="aborted"?lt:o.status==="dirty"?(n.dirty(),Nl(o.value)):this._def.out._parseAsync({data:o.value,path:r.path,parent:r})})();{const s=this._def.in._parseSync({data:r.data,path:r.path,parent:r});return s.status==="aborted"?lt:s.status==="dirty"?(n.dirty(),{status:"dirty",value:s.value}):this._def.out._parseSync({data:s.value,path:r.path,parent:r})}}static create(t,n){return new kd({in:t,out:n,typeName:it.ZodPipeline})}}class rd extends St{_parse(t){const n=this._def.innerType._parse(t),r=s=>(Hu(s)&&(s.value=Object.freeze(s.value)),s);return qu(n)?n.then(s=>r(s)):r(n)}unwrap(){return this._def.innerType}}rd.create=(e,t)=>new rd({innerType:e,typeName:it.ZodReadonly,...yt(t)});function I_(e,t={},n){return e?Hl.create().superRefine((r,s)=>{var o,l;if(!e(r)){const u=typeof t=="function"?t(r):typeof t=="string"?{message:t}:t,d=(l=(o=u.fatal)!==null&&o!==void 0?o:n)!==null&&l!==void 0?l:!0,f=typeof u=="string"?{message:u}:u;s.addIssue({code:"custom",...f,fatal:d})}}):Hl.create()}const B6={object:gn.lazycreate};var it;(function(e){e.ZodString="ZodString",e.ZodNumber="ZodNumber",e.ZodNaN="ZodNaN",e.ZodBigInt="ZodBigInt",e.ZodBoolean="ZodBoolean",e.ZodDate="ZodDate",e.ZodSymbol="ZodSymbol",e.ZodUndefined="ZodUndefined",e.ZodNull="ZodNull",e.ZodAny="ZodAny",e.ZodUnknown="ZodUnknown",e.ZodNever="ZodNever",e.ZodVoid="ZodVoid",e.ZodArray="ZodArray",e.ZodObject="ZodObject",e.ZodUnion="ZodUnion",e.ZodDiscriminatedUnion="ZodDiscriminatedUnion",e.ZodIntersection="ZodIntersection",e.ZodTuple="ZodTuple",e.ZodRecord="ZodRecord",e.ZodMap="ZodMap",e.ZodSet="ZodSet",e.ZodFunction="ZodFunction",e.ZodLazy="ZodLazy",e.ZodLiteral="ZodLiteral",e.ZodEnum="ZodEnum",e.ZodEffects="ZodEffects",e.ZodNativeEnum="ZodNativeEnum",e.ZodOptional="ZodOptional",e.ZodNullable="ZodNullable",e.ZodDefault="ZodDefault",e.ZodCatch="ZodCatch",e.ZodPromise="ZodPromise",e.ZodBranded="ZodBranded",e.ZodPipeline="ZodPipeline",e.ZodReadonly="ZodReadonly"})(it||(it={}));const z6=(e,t={message:`Input not instance of ${e.name}`})=>I_(n=>n instanceof e,t),A_=Cs.create,D_=Sa.create,U6=sh.create,V6=Ca.create,F_=Ku.create,H6=Ti.create,q6=th.create,K6=Wu.create,W6=Gu.create,G6=Hl.create,J6=mi.create,Q6=Ro.create,Z6=nh.create,Y6=ks.create,X6=gn.create,e8=gn.strictCreate,t8=Ju.create,n8=Wh.create,r8=Qu.create,s8=Zs.create,o8=Zu.create,a8=rh.create,i8=Ni.create,l8=Ol.create,c8=Yu.create,u8=Xu.create,d8=Ea.create,f8=ed.create,p8=ql.create,j1=Ms.create,h8=Ws.create,g8=ka.create,m8=Ms.createWithPreprocess,v8=kd.create,y8=()=>A_().optional(),b8=()=>D_().optional(),x8=()=>F_().optional(),w8={string:(e=>Cs.create({...e,coerce:!0})),number:(e=>Sa.create({...e,coerce:!0})),boolean:(e=>Ku.create({...e,coerce:!0})),bigint:(e=>Ca.create({...e,coerce:!0})),date:(e=>Ti.create({...e,coerce:!0}))},S8=lt;var P=Object.freeze({__proto__:null,defaultErrorMap:Vl,setErrorMap:S6,getErrorMap:Yp,makeIssue:Xp,EMPTY_PATH:C6,addIssueToContext:Ae,ParseStatus:sr,INVALID:lt,DIRTY:Nl,OK:fr,isAborted:Jy,isDirty:Qy,isValid:Hu,isAsync:qu,get util(){return Ot},get objectUtil(){return Gy},ZodParsedType:Le,getParsedType:pa,ZodType:St,datetimeRegex:P_,ZodString:Cs,ZodNumber:Sa,ZodBigInt:Ca,ZodBoolean:Ku,ZodDate:Ti,ZodSymbol:th,ZodUndefined:Wu,ZodNull:Gu,ZodAny:Hl,ZodUnknown:mi,ZodNever:Ro,ZodVoid:nh,ZodArray:ks,ZodObject:gn,ZodUnion:Ju,ZodDiscriminatedUnion:Wh,ZodIntersection:Qu,ZodTuple:Zs,ZodRecord:Zu,ZodMap:rh,ZodSet:Ni,ZodFunction:Ol,ZodLazy:Yu,ZodLiteral:Xu,ZodEnum:Ea,ZodNativeEnum:ed,ZodPromise:ql,ZodEffects:Ms,ZodTransformer:Ms,ZodOptional:Ws,ZodNullable:ka,ZodDefault:td,ZodCatch:nd,ZodNaN:sh,BRAND:$6,ZodBranded:Rx,ZodPipeline:kd,ZodReadonly:rd,custom:I_,Schema:St,ZodSchema:St,late:B6,get ZodFirstPartyTypeKind(){return it},coerce:w8,any:G6,array:Y6,bigint:V6,boolean:F_,date:H6,discriminatedUnion:n8,effect:j1,enum:d8,function:l8,instanceof:z6,intersection:r8,lazy:c8,literal:u8,map:a8,nan:U6,nativeEnum:f8,never:Q6,null:W6,nullable:g8,number:D_,object:X6,oboolean:x8,onumber:b8,optional:h8,ostring:y8,pipeline:v8,preprocess:m8,promise:p8,record:o8,set:i8,strictObject:e8,string:A_,symbol:q6,transformer:j1,tuple:s8,undefined:K6,union:t8,unknown:J6,void:Z6,NEVER:S8,ZodIssueCode:Ce,quotelessJson:w6,ZodError:Hr}),L_=y.createContext({dragDropManager:void 0}),os;(function(e){e.SOURCE="SOURCE",e.TARGET="TARGET"})(os||(os={}));function gt(e,t){for(var n=arguments.length,r=new Array(n>2?n-2:0),s=2;s-1})}var T8={type:Px,payload:{clientOffset:null,sourceClientOffset:null}};function N8(e){return function(){var n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{publishSource:!0},s=r.publishSource,o=s===void 0?!0:s,l=r.clientOffset,u=r.getSourceClientOffset,d=e.getMonitor(),f=e.getRegistry();e.dispatch(T1(l)),M8(n,d,f);var h=P8(n,d);if(h===null){e.dispatch(T8);return}var m=null;if(l){if(!u)throw new Error("getSourceClientOffset must be defined");_8(u),m=u(h)}e.dispatch(T1(l,m));var g=f.getSource(h),x=g.beginDrag(d,h);if(x!=null){R8(x),f.pinSource(h);var b=f.getSourceType(h);return{type:Gh,payload:{itemType:b,item:x,sourceId:h,clientOffset:l||null,sourceClientOffset:m||null,isSourcePublic:!!o}}}}}function M8(e,t,n){gt(!t.isDragging(),"Cannot call beginDrag while dragging."),e.forEach(function(r){gt(n.getSource(r),"Expected sourceIds to be registered.")})}function _8(e){gt(typeof e=="function","When clientOffset is provided, getSourceClientOffset must be a function.")}function R8(e){gt($_(e),"Item must be an object.")}function P8(e,t){for(var n=null,r=e.length-1;r>=0;r--)if(t.canDragSource(e[r])){n=e[r];break}return n}function O8(e){return function(){var n=e.getMonitor();if(n.isDragging())return{type:Ox}}}function Yy(e,t){return t===null?e===null:Array.isArray(e)?e.some(function(n){return n===t}):e===t}function I8(e){return function(n){var r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},s=r.clientOffset;A8(n);var o=n.slice(0),l=e.getMonitor(),u=e.getRegistry();D8(o,l,u);var d=l.getItemType();return F8(o,u,d),L8(o,l,u),{type:Jh,payload:{targetIds:o,clientOffset:s||null}}}}function A8(e){gt(Array.isArray(e),"Expected targetIds to be an array.")}function D8(e,t,n){gt(t.isDragging(),"Cannot call hover while not dragging."),gt(!t.didDrop(),"Cannot call hover after drop.");for(var r=0;r=0;r--){var s=e[r],o=t.getTargetType(s);Yy(o,n)||e.splice(r,1)}}function L8(e,t,n){e.forEach(function(r){var s=n.getTarget(r);s.hover(t,r)})}function N1(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(s){return Object.getOwnPropertyDescriptor(e,s).enumerable})),n.push.apply(n,r)}return n}function M1(e){for(var t=1;t0&&arguments[0]!==void 0?arguments[0]:{},r=e.getMonitor(),s=e.getRegistry();z8(r);var o=H8(r);o.forEach(function(l,u){var d=U8(l,u,s,r),f={type:Qh,payload:{dropResult:M1(M1({},n),d)}};e.dispatch(f)})}}function z8(e){gt(e.isDragging(),"Cannot call drop while not dragging."),gt(!e.didDrop(),"Cannot call drop twice during one drag operation.")}function U8(e,t,n,r){var s=n.getTarget(e),o=s?s.drop(r,e):void 0;return V8(o),typeof o>"u"&&(o=t===0?{}:r.getDropResult()),o}function V8(e){gt(typeof e>"u"||$_(e),"Drop result must either be an object or undefined.")}function H8(e){var t=e.getTargetIds().filter(e.canDropOnTarget,e);return t.reverse(),t}function q8(e){return function(){var n=e.getMonitor(),r=e.getRegistry();K8(n);var s=n.getSourceId();if(s!=null){var o=r.getSource(s,!0);o.endDrag(n,s),r.unpinSource()}return{type:Zh}}}function K8(e){gt(e.isDragging(),"Cannot call endDrag while not dragging.")}function W8(e){return{beginDrag:N8(e),publishDragSource:O8(e),hover:I8(e),drop:B8(e),endDrag:q8(e)}}function G8(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function J8(e,t){for(var n=0;n0;r.backend&&(s&&!r.isSetUp?(r.backend.setup(),r.isSetUp=!0):!s&&r.isSetUp&&(r.backend.teardown(),r.isSetUp=!1))}),this.store=t,this.monitor=n,t.subscribe(this.handleRefCountChange)}return Q8(e,[{key:"receiveBackend",value:function(n){this.backend=n}},{key:"getMonitor",value:function(){return this.monitor}},{key:"getBackend",value:function(){return this.backend}},{key:"getRegistry",value:function(){return this.monitor.registry}},{key:"getActions",value:function(){var n=this,r=this.store.dispatch;function s(l){return function(){for(var u=arguments.length,d=new Array(u),f=0;f"u"&&(n=t,t=void 0),typeof n<"u"){if(typeof n!="function")throw new Error(ns(1));return n(B_)(e,t)}if(typeof e!="function")throw new Error(ns(2));var s=e,o=t,l=[],u=l,d=!1;function f(){u===l&&(u=l.slice())}function h(){if(d)throw new Error(ns(3));return o}function m(w){if(typeof w!="function")throw new Error(ns(4));if(d)throw new Error(ns(5));var C=!0;return f(),u.push(w),function(){if(C){if(d)throw new Error(ns(6));C=!1,f();var j=u.indexOf(w);u.splice(j,1),l=null}}}function g(w){if(!Y8(w))throw new Error(ns(7));if(typeof w.type>"u")throw new Error(ns(8));if(d)throw new Error(ns(9));try{d=!0,o=s(o,w)}finally{d=!1}for(var C=l=u,k=0;k2&&arguments[2]!==void 0?arguments[2]:X8;if(e.length!==t.length)return!1;for(var r=0;r0&&arguments[0]!==void 0?arguments[0]:A1,t=arguments.length>1?arguments[1]:void 0,n=t.payload;switch(t.type){case Px:case Gh:return{initialSourceClientOffset:n.sourceClientOffset,initialClientOffset:n.clientOffset,clientOffset:n.clientOffset};case Jh:return eV(e.clientOffset,n.clientOffset)?e:I1(I1({},e),{},{clientOffset:n.clientOffset});case Zh:case Qh:return A1;default:return e}}var Ix="dnd-core/ADD_SOURCE",Ax="dnd-core/ADD_TARGET",Dx="dnd-core/REMOVE_SOURCE",Yh="dnd-core/REMOVE_TARGET";function sV(e){return{type:Ix,payload:{sourceId:e}}}function oV(e){return{type:Ax,payload:{targetId:e}}}function aV(e){return{type:Dx,payload:{sourceId:e}}}function iV(e){return{type:Yh,payload:{targetId:e}}}function D1(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(s){return Object.getOwnPropertyDescriptor(e,s).enumerable})),n.push.apply(n,r)}return n}function rs(e){for(var t=1;t0&&arguments[0]!==void 0?arguments[0]:cV,t=arguments.length>1?arguments[1]:void 0,n=t.payload;switch(t.type){case Gh:return rs(rs({},e),{},{itemType:n.itemType,item:n.item,sourceId:n.sourceId,isSourcePublic:n.isSourcePublic,dropResult:null,didDrop:!1});case Ox:return rs(rs({},e),{},{isSourcePublic:!0});case Jh:return rs(rs({},e),{},{targetIds:n.targetIds});case Yh:return e.targetIds.indexOf(n.targetId)===-1?e:rs(rs({},e),{},{targetIds:E8(e.targetIds,n.targetId)});case Qh:return rs(rs({},e),{},{dropResult:n.dropResult,didDrop:!0,targetIds:[]});case Zh:return rs(rs({},e),{},{itemType:null,item:null,sourceId:null,dropResult:null,didDrop:!1,isSourcePublic:null,targetIds:[]});default:return e}}function dV(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0,t=arguments.length>1?arguments[1]:void 0;switch(t.type){case Ix:case Ax:return e+1;case Dx:case Yh:return e-1;default:return e}}var oh=[],Fx=[];oh.__IS_NONE__=!0;Fx.__IS_ALL__=!0;function fV(e,t){if(e===oh)return!1;if(e===Fx||typeof t>"u")return!0;var n=j8(t,e);return n.length>0}function pV(){var e=arguments.length>1?arguments[1]:void 0;switch(e.type){case Jh:break;case Ix:case Ax:case Yh:case Dx:return oh;case Gh:case Ox:case Zh:case Qh:default:return Fx}var t=e.payload,n=t.targetIds,r=n===void 0?[]:n,s=t.prevTargetIds,o=s===void 0?[]:s,l=k8(r,o),u=l.length>0||!tV(r,o);if(!u)return oh;var d=o[o.length-1],f=r[r.length-1];return d!==f&&(d&&l.push(d),f&&l.push(f)),l}function hV(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0;return e+1}function F1(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(s){return Object.getOwnPropertyDescriptor(e,s).enumerable})),n.push.apply(n,r)}return n}function L1(e){for(var t=1;t0&&arguments[0]!==void 0?arguments[0]:{},t=arguments.length>1?arguments[1]:void 0;return{dirtyHandlerIds:pV(e.dirtyHandlerIds,{type:t.type,payload:L1(L1({},t.payload),{},{prevTargetIds:C8(e,"dragOperation.targetIds",[])})}),dragOffset:rV(e.dragOffset,t),refCount:dV(e.refCount,t),dragOperation:uV(e.dragOperation,t),stateId:hV(e.stateId)}}function vV(e,t){return{x:e.x+t.x,y:e.y+t.y}}function z_(e,t){return{x:e.x-t.x,y:e.y-t.y}}function yV(e){var t=e.clientOffset,n=e.initialClientOffset,r=e.initialSourceClientOffset;return!t||!n||!r?null:z_(vV(t,r),n)}function bV(e){var t=e.clientOffset,n=e.initialClientOffset;return!t||!n?null:z_(t,n)}function xV(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function wV(e,t){for(var n=0;n1&&arguments[1]!==void 0?arguments[1]:{handlerIds:void 0},o=s.handlerIds;gt(typeof n=="function","listener must be a function."),gt(typeof o>"u"||Array.isArray(o),"handlerIds, when specified, must be an array of strings.");var l=this.store.getState().stateId,u=function(){var f=r.store.getState(),h=f.stateId;try{var m=h===l||h===l+1&&!fV(f.dirtyHandlerIds,o);m||n()}finally{l=h}};return this.store.subscribe(u)}},{key:"subscribeToOffsetChange",value:function(n){var r=this;gt(typeof n=="function","listener must be a function.");var s=this.store.getState().dragOffset,o=function(){var u=r.store.getState().dragOffset;u!==s&&(s=u,n())};return this.store.subscribe(o)}},{key:"canDragSource",value:function(n){if(!n)return!1;var r=this.registry.getSource(n);return gt(r,"Expected to find a valid source. sourceId=".concat(n)),this.isDragging()?!1:r.canDrag(this,n)}},{key:"canDropOnTarget",value:function(n){if(!n)return!1;var r=this.registry.getTarget(n);if(gt(r,"Expected to find a valid target. targetId=".concat(n)),!this.isDragging()||this.didDrop())return!1;var s=this.registry.getTargetType(n),o=this.getItemType();return Yy(s,o)&&r.canDrop(this,n)}},{key:"isDragging",value:function(){return!!this.getItemType()}},{key:"isDraggingSource",value:function(n){if(!n)return!1;var r=this.registry.getSource(n,!0);if(gt(r,"Expected to find a valid source. sourceId=".concat(n)),!this.isDragging()||!this.isSourcePublic())return!1;var s=this.registry.getSourceType(n),o=this.getItemType();return s!==o?!1:r.isDragging(this,n)}},{key:"isOverTarget",value:function(n){var r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{shallow:!1};if(!n)return!1;var s=r.shallow;if(!this.isDragging())return!1;var o=this.registry.getTargetType(n),l=this.getItemType();if(l&&!Yy(o,l))return!1;var u=this.getTargetIds();if(!u.length)return!1;var d=u.indexOf(n);return s?d===u.length-1:d>-1}},{key:"getItemType",value:function(){return this.store.getState().dragOperation.itemType}},{key:"getItem",value:function(){return this.store.getState().dragOperation.item}},{key:"getSourceId",value:function(){return this.store.getState().dragOperation.sourceId}},{key:"getTargetIds",value:function(){return this.store.getState().dragOperation.targetIds}},{key:"getDropResult",value:function(){return this.store.getState().dragOperation.dropResult}},{key:"didDrop",value:function(){return this.store.getState().dragOperation.didDrop}},{key:"isSourcePublic",value:function(){return!!this.store.getState().dragOperation.isSourcePublic}},{key:"getInitialClientOffset",value:function(){return this.store.getState().dragOffset.initialClientOffset}},{key:"getInitialSourceClientOffset",value:function(){return this.store.getState().dragOffset.initialSourceClientOffset}},{key:"getClientOffset",value:function(){return this.store.getState().dragOffset.clientOffset}},{key:"getSourceClientOffset",value:function(){return yV(this.store.getState().dragOffset)}},{key:"getDifferenceFromInitialOffset",value:function(){return bV(this.store.getState().dragOffset)}}]),e})(),EV=0;function kV(){return EV++}function bp(e){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?bp=function(n){return typeof n}:bp=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},bp(e)}function jV(e){gt(typeof e.canDrag=="function","Expected canDrag to be a function."),gt(typeof e.beginDrag=="function","Expected beginDrag to be a function."),gt(typeof e.endDrag=="function","Expected endDrag to be a function.")}function TV(e){gt(typeof e.canDrop=="function","Expected canDrop to be a function."),gt(typeof e.hover=="function","Expected hover to be a function."),gt(typeof e.drop=="function","Expected beginDrag to be a function.")}function Xy(e,t){if(t&&Array.isArray(e)){e.forEach(function(n){return Xy(n,!1)});return}gt(typeof e=="string"||bp(e)==="symbol",t?"Type can only be a string, a symbol, or an array of either.":"Type can only be a string or a symbol.")}const B1=typeof global<"u"?global:self,U_=B1.MutationObserver||B1.WebKitMutationObserver;function V_(e){return function(){const n=setTimeout(s,0),r=setInterval(s,50);function s(){clearTimeout(n),clearInterval(r),e()}}}function NV(e){let t=1;const n=new U_(e),r=document.createTextNode("");return n.observe(r,{characterData:!0}),function(){t=-t,r.data=t}}const MV=typeof U_=="function"?NV:V_;class _V{enqueueTask(t){const{queue:n,requestFlush:r}=this;n.length||(r(),this.flushing=!0),n[n.length]=t}constructor(){this.queue=[],this.pendingErrors=[],this.flushing=!1,this.index=0,this.capacity=1024,this.flush=()=>{const{queue:t}=this;for(;this.indexthis.capacity){for(let r=0,s=t.length-this.index;r{this.pendingErrors.push(t),this.requestErrorThrow()},this.requestFlush=MV(this.flush),this.requestErrorThrow=V_(()=>{if(this.pendingErrors.length)throw this.pendingErrors.shift()})}}class RV{call(){try{this.task&&this.task()}catch(t){this.onError(t)}finally{this.task=null,this.release(this)}}constructor(t,n){this.onError=t,this.release=n,this.task=null}}class PV{create(t){const n=this.freeTasks,r=n.length?n.pop():new RV(this.onError,s=>n[n.length]=s);return r.task=t,r}constructor(t){this.onError=t,this.freeTasks=[]}}const H_=new _V,OV=new PV(H_.registerPendingError);function IV(e){H_.enqueueTask(OV.create(e))}function AV(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function DV(e,t){for(var n=0;ne.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&arguments[1]!==void 0?arguments[1]:!1;gt(this.isSourceId(n),"Expected a valid source ID.");var s=r&&n===this.pinnedSourceId,o=s?this.pinnedSource:this.dragSources.get(n);return o}},{key:"getTarget",value:function(n){return gt(this.isTargetId(n),"Expected a valid target ID."),this.dropTargets.get(n)}},{key:"getSourceType",value:function(n){return gt(this.isSourceId(n),"Expected a valid source ID."),this.types.get(n)}},{key:"getTargetType",value:function(n){return gt(this.isTargetId(n),"Expected a valid target ID."),this.types.get(n)}},{key:"isSourceId",value:function(n){var r=U1(n);return r===os.SOURCE}},{key:"isTargetId",value:function(n){var r=U1(n);return r===os.TARGET}},{key:"removeSource",value:function(n){var r=this;gt(this.getSource(n),"Expected an existing source."),this.store.dispatch(aV(n)),IV(function(){r.dragSources.delete(n),r.types.delete(n)})}},{key:"removeTarget",value:function(n){gt(this.getTarget(n),"Expected an existing target."),this.store.dispatch(iV(n)),this.dropTargets.delete(n),this.types.delete(n)}},{key:"pinSource",value:function(n){var r=this.getSource(n);gt(r,"Expected an existing source."),this.pinnedSourceId=n,this.pinnedSource=r}},{key:"unpinSource",value:function(){gt(this.pinnedSource,"No source is pinned at the time."),this.pinnedSourceId=null,this.pinnedSource=null}},{key:"addHandler",value:function(n,r,s){var o=VV(n);return this.types.set(o,r),n===os.SOURCE?this.dragSources.set(o,s):n===os.TARGET&&this.dropTargets.set(o,s),o}}]),e})();function qV(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:void 0,n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},r=arguments.length>3&&arguments[3]!==void 0?arguments[3]:!1,s=KV(r),o=new CV(s,new HV(s)),l=new Z8(s,o),u=e(l,t,n);return l.receiveBackend(u),l}function KV(e){var t=typeof window<"u"&&window.__REDUX_DEVTOOLS_EXTENSION__;return B_(mV,e&&t&&t({name:"dnd-core",instanceId:"dnd-core"}))}var WV=["children"];function GV(e,t){return YV(e)||ZV(e,t)||QV(e,t)||JV()}function JV(){throw new TypeError(`Invalid attempt to destructure non-iterable instance. In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function QV(e,t){if(e){if(typeof e=="string")return H1(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if(n==="Object"&&e.constructor&&(n=e.constructor.name),n==="Map"||n==="Set")return Array.from(e);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return H1(e,t)}}function H1(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=0)&&Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=e[r])}return n}function eH(e,t){if(e==null)return{};var n={},r=Object.keys(e),s,o;for(o=0;o=0)&&(n[s]=e[s]);return n}var q1=0,xp=Symbol.for("__REACT_DND_CONTEXT_INSTANCE__"),tH=y.memo(function(t){var n=t.children,r=XV(t,WV),s=nH(r),o=GV(s,2),l=o[0],u=o[1];return y.useEffect(function(){if(u){var d=q_();return++q1,function(){--q1===0&&(d[xp]=null)}}},[]),i.jsx(L_.Provider,Object.assign({value:l},{children:n}),void 0)});function nH(e){if("manager"in e){var t={dragDropManager:e.manager};return[t,!1]}var n=rH(e.backend,e.context,e.options,e.debugMode),r=!e.context;return[n,r]}function rH(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:q_(),n=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=t;return s[xp]||(s[xp]={dragDropManager:qV(e,t,n,r)}),s[xp]}function q_(){return typeof global<"u"?global:window}function sH(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function oH(e,t){for(var n=0;n, or turn it into a ")+"drag source or a drop target itself.")}}function pH(e){return function(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:null,n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:null;if(!y.isValidElement(t)){var r=t;return e(r,n),r}var s=t;fH(s);var o=n?function(l){return e(l,n)}:e;return hH(s,o)}}function K_(e){var t={};return Object.keys(e).forEach(function(n){var r=e[n];if(n.endsWith("Ref"))t[n]=e[n];else{var s=pH(r);t[n]=function(){return s}}}),t}function G1(e,t){typeof e=="function"?e(t):e.current=t}function hH(e,t){var n=e.ref;return gt(typeof n!="string","Cannot connect React DnD to an element with an existing string ref. Please convert it to use a callback ref instead, or wrap it into a or
. Read more: https://reactjs.org/docs/refs-and-the-dom.html#callback-refs"),n?y.cloneElement(e,{ref:function(s){G1(n,s),G1(t,s)}}):y.cloneElement(e,{ref:t})}function wp(e){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?wp=function(n){return typeof n}:wp=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},wp(e)}function eb(e){return e!==null&&wp(e)==="object"&&Object.prototype.hasOwnProperty.call(e,"current")}function tb(e,t,n,r){var s=void 0;if(s!==void 0)return!!s;if(e===t)return!0;if(typeof e!="object"||!e||typeof t!="object"||!t)return!1;var o=Object.keys(e),l=Object.keys(t);if(o.length!==l.length)return!1;for(var u=Object.prototype.hasOwnProperty.bind(t),d=0;de.length)&&(t=e.length);for(var n=0,r=new Array(t);ne.length)&&(t=e.length);for(var n=0,r=new Array(t);ne.length)&&(t=e.length);for(var n=0,r=new Array(t);ne.length)&&(t=e.length);for(var n=0,r=new Array(t);ne.length)&&(t=e.length);for(var n=0,r=new Array(t);n0}},{key:"leave",value:function(n){var r=this.entered.length;return this.entered=Eq(this.entered.filter(this.isNodeInDocument),n),r>0&&this.entered.length===0}},{key:"reset",value:function(){this.entered=[]}}]),e})(),_q=J_(function(){return/firefox/i.test(navigator.userAgent)}),Q_=J_(function(){return!!window.safari});function Rq(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function Pq(e,t){for(var n=0;nn)h=m-1;else return s[m]}d=Math.max(0,h);var x=n-r[d],b=x*x;return s[d]+o[d]*x+l[d]*b+u[d]*x*b}}]),e})(),Iq=1;function Z_(e){var t=e.nodeType===Iq?e:e.parentElement;if(!t)return null;var n=t.getBoundingClientRect(),r=n.top,s=n.left;return{x:s,y:r}}function Qf(e){return{x:e.clientX,y:e.clientY}}function Aq(e){var t;return e.nodeName==="IMG"&&(_q()||!((t=document.documentElement)!==null&&t!==void 0&&t.contains(e)))}function Dq(e,t,n,r){var s=e?t.width:n,o=e?t.height:r;return Q_()&&e&&(o/=window.devicePixelRatio,s/=window.devicePixelRatio),{dragPreviewWidth:s,dragPreviewHeight:o}}function Fq(e,t,n,r,s){var o=Aq(t),l=o?e:t,u=Z_(l),d={x:n.x-u.x,y:n.y-u.y},f=e.offsetWidth,h=e.offsetHeight,m=r.anchorX,g=r.anchorY,x=Dq(o,t,f,h),b=x.dragPreviewWidth,w=x.dragPreviewHeight,C=function(){var O=new nE([0,.5,1],[d.y,d.y/h*w,d.y+w-h]),D=O.interpolate(g);return Q_()&&o&&(D+=(window.devicePixelRatio-1)*w),D},k=function(){var O=new nE([0,.5,1],[d.x,d.x/f*b,d.x+b-f]);return O.interpolate(m)},j=s.offsetX,M=s.offsetY,_=j===0||j,R=M===0||M;return{x:_?j:k(),y:R?M:C()}}var Y_="__NATIVE_FILE__",X_="__NATIVE_URL__",eR="__NATIVE_TEXT__",tR="__NATIVE_HTML__";const rE=Object.freeze(Object.defineProperty({__proto__:null,FILE:Y_,HTML:tR,TEXT:eR,URL:X_},Symbol.toStringTag,{value:"Module"}));function $v(e,t,n){var r=t.reduce(function(s,o){return s||e.getData(o)},"");return r??n}var yl;function Zf(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var rb=(yl={},Zf(yl,Y_,{exposeProperties:{files:function(t){return Array.prototype.slice.call(t.files)},items:function(t){return t.items},dataTransfer:function(t){return t}},matchesTypes:["Files"]}),Zf(yl,tR,{exposeProperties:{html:function(t,n){return $v(t,n,"")},dataTransfer:function(t){return t}},matchesTypes:["Html","text/html"]}),Zf(yl,X_,{exposeProperties:{urls:function(t,n){return $v(t,n,"").split(` `)},dataTransfer:function(t){return t}},matchesTypes:["Url","text/uri-list"]}),Zf(yl,eR,{exposeProperties:{text:function(t,n){return $v(t,n,"")},dataTransfer:function(t){return t}},matchesTypes:["Text","text/plain"]}),yl);function Lq(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function $q(e,t){for(var n=0;n-1})})[0]||null}function Vq(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function Hq(e,t){for(var n=0;n0&&s.actions.hover(l,{clientOffset:Qf(o)});var u=l.some(function(d){return s.monitor.canDropOnTarget(d)});u&&(o.preventDefault(),o.dataTransfer&&(o.dataTransfer.dropEffect=s.getCurrentDropEffect()))}}),jt(this,"handleTopDragOverCapture",function(){s.dragOverTargetIds=[]}),jt(this,"handleTopDragOver",function(o){var l=s.dragOverTargetIds;if(s.dragOverTargetIds=[],!s.monitor.isDragging()){o.preventDefault(),o.dataTransfer&&(o.dataTransfer.dropEffect="none");return}s.altKeyPressed=o.altKey,s.lastClientOffset=Qf(o),s.hoverRafId===null&&typeof requestAnimationFrame<"u"&&(s.hoverRafId=requestAnimationFrame(function(){s.monitor.isDragging()&&s.actions.hover(l||[],{clientOffset:s.lastClientOffset}),s.hoverRafId=null}));var u=(l||[]).some(function(d){return s.monitor.canDropOnTarget(d)});u?(o.preventDefault(),o.dataTransfer&&(o.dataTransfer.dropEffect=s.getCurrentDropEffect())):s.isDraggingNativeItem()?o.preventDefault():(o.preventDefault(),o.dataTransfer&&(o.dataTransfer.dropEffect="none"))}),jt(this,"handleTopDragLeaveCapture",function(o){s.isDraggingNativeItem()&&o.preventDefault();var l=s.enterLeaveCounter.leave(o.target);l&&s.isDraggingNativeItem()&&setTimeout(function(){return s.endDragNativeItem()},0)}),jt(this,"handleTopDropCapture",function(o){if(s.dropTargetIds=[],s.isDraggingNativeItem()){var l;o.preventDefault(),(l=s.currentNativeSource)===null||l===void 0||l.loadDataTransfer(o.dataTransfer)}else Bv(o.dataTransfer)&&o.preventDefault();s.enterLeaveCounter.reset()}),jt(this,"handleTopDrop",function(o){var l=s.dropTargetIds;s.dropTargetIds=[],s.actions.hover(l,{clientOffset:Qf(o)}),s.actions.drop({dropEffect:s.getCurrentDropEffect()}),s.isDraggingNativeItem()?s.endDragNativeItem():s.monitor.isDragging()&&s.actions.endDrag()}),jt(this,"handleSelectStart",function(o){var l=o.target;typeof l.dragDrop=="function"&&(l.tagName==="INPUT"||l.tagName==="SELECT"||l.tagName==="TEXTAREA"||l.isContentEditable||(o.preventDefault(),l.dragDrop()))}),this.options=new Kq(n,r),this.actions=t.getActions(),this.monitor=t.getMonitor(),this.registry=t.getRegistry(),this.enterLeaveCounter=new Mq(this.isNodeInDocument)}return Jq(e,[{key:"profile",value:function(){var n,r;return{sourcePreviewNodes:this.sourcePreviewNodes.size,sourcePreviewNodeOptions:this.sourcePreviewNodeOptions.size,sourceNodeOptions:this.sourceNodeOptions.size,sourceNodes:this.sourceNodes.size,dragStartSourceIds:((n=this.dragStartSourceIds)===null||n===void 0?void 0:n.length)||0,dropTargetIds:this.dropTargetIds.length,dragEnterTargetIds:this.dragEnterTargetIds.length,dragOverTargetIds:((r=this.dragOverTargetIds)===null||r===void 0?void 0:r.length)||0}}},{key:"window",get:function(){return this.options.window}},{key:"document",get:function(){return this.options.document}},{key:"rootElement",get:function(){return this.options.rootElement}},{key:"setup",value:function(){var n=this.rootElement;if(n!==void 0){if(n.__isReactDndBackendSetUp)throw new Error("Cannot have two HTML5 backends at the same time.");n.__isReactDndBackendSetUp=!0,this.addEventListeners(n)}}},{key:"teardown",value:function(){var n=this.rootElement;if(n!==void 0&&(n.__isReactDndBackendSetUp=!1,this.removeEventListeners(this.rootElement),this.clearCurrentDragSourceNode(),this.asyncEndDragFrameId)){var r;(r=this.window)===null||r===void 0||r.cancelAnimationFrame(this.asyncEndDragFrameId)}}},{key:"connectDragPreview",value:function(n,r,s){var o=this;return this.sourcePreviewNodeOptions.set(n,s),this.sourcePreviewNodes.set(n,r),function(){o.sourcePreviewNodes.delete(n),o.sourcePreviewNodeOptions.delete(n)}}},{key:"connectDragSource",value:function(n,r,s){var o=this;this.sourceNodes.set(n,r),this.sourceNodeOptions.set(n,s);var l=function(f){return o.handleDragStart(f,n)},u=function(f){return o.handleSelectStart(f)};return r.setAttribute("draggable","true"),r.addEventListener("dragstart",l),r.addEventListener("selectstart",u),function(){o.sourceNodes.delete(n),o.sourceNodeOptions.delete(n),r.removeEventListener("dragstart",l),r.removeEventListener("selectstart",u),r.setAttribute("draggable","false")}}},{key:"connectDropTarget",value:function(n,r){var s=this,o=function(f){return s.handleDragEnter(f,n)},l=function(f){return s.handleDragOver(f,n)},u=function(f){return s.handleDrop(f,n)};return r.addEventListener("dragenter",o),r.addEventListener("dragover",l),r.addEventListener("drop",u),function(){r.removeEventListener("dragenter",o),r.removeEventListener("dragover",l),r.removeEventListener("drop",u)}}},{key:"addEventListeners",value:function(n){n.addEventListener&&(n.addEventListener("dragstart",this.handleTopDragStart),n.addEventListener("dragstart",this.handleTopDragStartCapture,!0),n.addEventListener("dragend",this.handleTopDragEndCapture,!0),n.addEventListener("dragenter",this.handleTopDragEnter),n.addEventListener("dragenter",this.handleTopDragEnterCapture,!0),n.addEventListener("dragleave",this.handleTopDragLeaveCapture,!0),n.addEventListener("dragover",this.handleTopDragOver),n.addEventListener("dragover",this.handleTopDragOverCapture,!0),n.addEventListener("drop",this.handleTopDrop),n.addEventListener("drop",this.handleTopDropCapture,!0))}},{key:"removeEventListeners",value:function(n){n.removeEventListener&&(n.removeEventListener("dragstart",this.handleTopDragStart),n.removeEventListener("dragstart",this.handleTopDragStartCapture,!0),n.removeEventListener("dragend",this.handleTopDragEndCapture,!0),n.removeEventListener("dragenter",this.handleTopDragEnter),n.removeEventListener("dragenter",this.handleTopDragEnterCapture,!0),n.removeEventListener("dragleave",this.handleTopDragLeaveCapture,!0),n.removeEventListener("dragover",this.handleTopDragOver),n.removeEventListener("dragover",this.handleTopDragOverCapture,!0),n.removeEventListener("drop",this.handleTopDrop),n.removeEventListener("drop",this.handleTopDropCapture,!0))}},{key:"getCurrentSourceNodeOptions",value:function(){var n=this.monitor.getSourceId(),r=this.sourceNodeOptions.get(n);return aE({dropEffect:this.altKeyPressed?"copy":"move"},r||{})}},{key:"getCurrentDropEffect",value:function(){return this.isDraggingNativeItem()?"copy":this.getCurrentSourceNodeOptions().dropEffect}},{key:"getCurrentSourcePreviewNodeOptions",value:function(){var n=this.monitor.getSourceId(),r=this.sourcePreviewNodeOptions.get(n);return aE({anchorX:.5,anchorY:.5,captureDraggingState:!1},r||{})}},{key:"isDraggingNativeItem",value:function(){var n=this.monitor.getItemType();return Object.keys(rE).some(function(r){return rE[r]===n})}},{key:"beginDragNativeItem",value:function(n,r){this.clearCurrentDragSourceNode(),this.currentNativeSource=Uq(n,r),this.currentNativeHandle=this.registry.addSource(n,this.currentNativeSource),this.actions.beginDrag([this.currentNativeHandle])}},{key:"setCurrentDragSourceNode",value:function(n){var r=this;this.clearCurrentDragSourceNode(),this.currentDragSourceNode=n;var s=1e3;this.mouseMoveTimeoutTimer=setTimeout(function(){var o;return(o=r.rootElement)===null||o===void 0?void 0:o.addEventListener("mousemove",r.endDragIfSourceWasRemovedFromDOM,!0)},s)}},{key:"clearCurrentDragSourceNode",value:function(){if(this.currentDragSourceNode){if(this.currentDragSourceNode=null,this.rootElement){var n;(n=this.window)===null||n===void 0||n.clearTimeout(this.mouseMoveTimeoutTimer||void 0),this.rootElement.removeEventListener("mousemove",this.endDragIfSourceWasRemovedFromDOM,!0)}return this.mouseMoveTimeoutTimer=null,!0}return!1}},{key:"handleDragStart",value:function(n,r){n.defaultPrevented||(this.dragStartSourceIds||(this.dragStartSourceIds=[]),this.dragStartSourceIds.unshift(r))}},{key:"handleDragEnter",value:function(n,r){this.dragEnterTargetIds.unshift(r)}},{key:"handleDragOver",value:function(n,r){this.dragOverTargetIds===null&&(this.dragOverTargetIds=[]),this.dragOverTargetIds.unshift(r)}},{key:"handleDrop",value:function(n,r){this.dropTargetIds.unshift(r)}}]),e})(),Zq=function(t,n,r){return new Qq(t,n,r)},Yq=Object.create,nR=Object.defineProperty,Xq=Object.getOwnPropertyDescriptor,rR=Object.getOwnPropertyNames,e7=Object.getPrototypeOf,t7=Object.prototype.hasOwnProperty,n7=(e,t)=>function(){return t||(0,e[rR(e)[0]])((t={exports:{}}).exports,t),t.exports},r7=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of rR(t))!t7.call(e,s)&&s!==n&&nR(e,s,{get:()=>t[s],enumerable:!(r=Xq(t,s))||r.enumerable});return e},sR=(e,t,n)=>(n=e!=null?Yq(e7(e)):{},r7(nR(n,"default",{value:e,enumerable:!0}),e)),oR=n7({"node_modules/classnames/index.js"(e,t){(function(){var n={}.hasOwnProperty;function r(){for(var s=[],o=0;o-1}var dK=uK,fK=9007199254740991,pK=/^(?:0|[1-9]\d*)$/;function hK(e,t){var n=typeof e;return t=t??fK,!!t&&(n=="number"||n!="symbol"&&pK.test(e))&&e>-1&&e%1==0&&e-1&&e%1==0&&e<=vK}var fR=yK;function bK(e){return e!=null&&fR(e.length)&&!uR(e)}var xK=bK,wK=Object.prototype;function SK(e){var t=e&&e.constructor,n=typeof t=="function"&&t.prototype||wK;return e===n}var CK=SK;function EK(e,t){for(var n=-1,r=Array(e);++n-1}var t9=e9;function n9(e,t){var n=this.__data__,r=Xh(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this}var r9=n9;function dc(e){var t=-1,n=e==null?0:e.length;for(this.clear();++tu))return!1;var f=o.get(e),h=o.get(t);if(f&&h)return f==t&&h==e;var m=-1,g=!0,x=n&uG?new bR:void 0;for(o.set(e,t),o.set(t,e);++m":">",'"':""","'":"'"},VG=S9(UG),HG=VG,CR=/[&<>"']/g,qG=RegExp(CR.source);function KG(e){return e=yR(e),e&&qG.test(e)?e.replace(CR,HG):e}var WG=KG,ER=/[\\^$.*+?()[\]{}|]/g,GG=RegExp(ER.source);function JG(e){return e=yR(e),e&&GG.test(e)?e.replace(ER,"\\$&"):e}var QG=JG;function ZG(e,t){return $G(e,t)}var YG=ZG,XG=1/0,eJ=Al&&1/Lx(new Al([,-0]))[1]==XG?function(e){return new Al(e)}:tK,tJ=eJ,nJ=200;function rJ(e,t,n){var r=-1,s=dK,o=e.length,l=!0,u=[],d=u;if(n)l=!1,s=zG;else if(o>=nJ){var f=t?null:tJ(e);if(f)return Lx(f);l=!1,s=xR,d=new bR}else d=t?[]:u;e:for(;++ri.jsx("button",{className:e.classNames.clearAll,onClick:e.onClick,children:"Clear all"}),lJ=iJ,cJ=(e,t)=>{const n=t.offsetHeight,r=e.offsetHeight,s=e.offsetTop-t.scrollTop;s+r>=n?t.scrollTop+=s-n+r:s<0&&(t.scrollTop+=s)},lb=(e,t,n,r)=>typeof r=="function"?r(e):e.length>=t&&n,uJ=e=>{const t=y.createRef(),{labelField:n,minQueryLength:r,isFocused:s,classNames:o,selectedIndex:l,query:u}=e;y.useEffect(()=>{if(!t.current)return;const m=t.current.querySelector(`.${o.activeSuggestion}`);m&&cJ(m,t.current)},[l]);const d=(m,g)=>{const x=g.trim().replace(/[-\\^$*+?.()|[\]{}]/g,"\\$&"),{[n]:b}=m;return{__html:b.replace(RegExp(x,"gi"),w=>`${WG(w)}`)}},f=(m,g)=>typeof e.renderSuggestion=="function"?e.renderSuggestion(m,g):i.jsx("span",{dangerouslySetInnerHTML:d(m,g)}),h=e.suggestions.map((m,g)=>i.jsx("li",{onMouseDown:e.handleClick.bind(null,g),onTouchStart:e.handleClick.bind(null,g),onMouseOver:e.handleHover.bind(null,g),className:g===e.selectedIndex?e.classNames.activeSuggestion:"",children:f(m,e.query)},g));return h.length===0||!lb(u,r||2,s,e.shouldRenderSuggestions)?null:i.jsx("div",{ref:t,className:o.suggestions,"data-testid":"suggestions",children:i.jsxs("ul",{children:[" ",h," "]})})},dJ=(e,t)=>{const{query:n,minQueryLength:r=2,isFocused:s,suggestions:o}=t;return!!(e.isFocused===s&&YG(e.suggestions,o)&&lb(n,r,s,t.shouldRenderSuggestions)===lb(e.query,e.minQueryLength??2,e.isFocused,e.shouldRenderSuggestions)&&e.selectedIndex===t.selectedIndex)},fJ=y.memo(uJ,dJ),pJ=fJ,hJ=sR(oR()),gJ=sR(oR());function mJ(e){const t=e.map(r=>{const s=r-48*Math.floor(r/48);return String.fromCharCode(96<=r?s:r)}).join(""),n=QG(t);return new RegExp(`[${n}]+`)}function vJ(e){switch(e){case Vs.ENTER:return[10,13];case Vs.TAB:return 9;case Vs.COMMA:return 188;case Vs.SPACE:return 32;case Vs.SEMICOLON:return 186;default:return 0}}function PE(e){const{moveTag:t,readOnly:n,allowDragDrop:r}=e;return t!==void 0&&!n&&r}function yJ(e){const{readOnly:t,allowDragDrop:n}=e;return!t&&n}var bJ=e=>{const{readOnly:t,removeComponent:n,onRemove:r,className:s,tag:o,index:l}=e,u=f=>{if(Il.ENTER.includes(f.keyCode)||f.keyCode===Il.SPACE){f.preventDefault(),f.stopPropagation();return}f.keyCode===Il.BACKSPACE&&r(f)};if(t)return i.jsx("span",{});const d=`Tag at index ${l} with value ${o.id} focussed. Press backspace to remove`;if(n){const f=n;return i.jsx(f,{"data-testid":"remove",onRemove:r,onKeyDown:u,className:s,"aria-label":d,tag:o,index:l})}return i.jsx("button",{"data-testid":"remove",onClick:r,onKeyDown:u,className:s,type:"button","aria-label":d,children:i.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 512 512",height:"12",width:"12",fill:"#fff",children:i.jsx("path",{d:"M376.6 84.5c11.3-13.6 9.5-33.8-4.1-45.1s-33.8-9.5-45.1 4.1L192 206 56.6 43.5C45.3 29.9 25.1 28.1 11.5 39.4S-3.9 70.9 7.4 84.5L150.3 256 7.4 427.5c-11.3 13.6-9.5 33.8 4.1 45.1s33.8 9.5 45.1-4.1L192 306 327.4 468.5c11.3 13.6 31.5 15.4 45.1 4.1s15.4-31.5 4.1-45.1L233.7 256 376.6 84.5z"})})})},xJ=bJ,OE={TAG:"tag"},wJ=e=>{const t=y.useRef(null),{readOnly:n=!1,tag:r,classNames:s,index:o,moveTag:l,allowDragDrop:u=!0,labelField:d="text",tags:f}=e,[{isDragging:h},m]=iq(()=>({type:OE.TAG,collect:C=>({isDragging:!!C.isDragging()}),item:e,canDrag:()=>PE({moveTag:l,readOnly:n,allowDragDrop:u})}),[f]),[,g]=Cq(()=>({accept:OE.TAG,drop:C=>{const k=C.index,j=o;k!==j&&e?.moveTag?.(k,j)},canDrop:C=>yJ(C)}),[f]);m(g(t));const x=e.tag[d],{className:b=""}=r,w=h?0:1;return i.jsxs("span",{ref:t,className:(0,gJ.default)("tag-wrapper",s.tag,b),style:{opacity:w,cursor:PE({moveTag:l,readOnly:n,allowDragDrop:u})?"move":"auto"},"data-testid":"tag",onClick:e.onTagClicked,onTouchStart:e.onTagClicked,children:[x,i.jsx(xJ,{tag:e.tag,className:s.remove,removeComponent:e.removeComponent,onRemove:e.onDelete,readOnly:n,index:o})]})},SJ=e=>{const{autofocus:t,autoFocus:n,readOnly:r,labelField:s,allowDeleteFromEmptyInput:o,allowAdditionFromPaste:l,allowDragDrop:u,minQueryLength:d,shouldRenderSuggestions:f,removeComponent:h,autocomplete:m,inline:g,maxTags:x,allowUnique:b,editable:w,placeholder:C,delimiters:k,separators:j,tags:M,inputFieldPosition:_,inputProps:R,classNames:N,maxLength:O,inputValue:D,clearAll:z}=e,[Q,pe]=y.useState(e.suggestions),[V,G]=y.useState(""),[W,ie]=y.useState(!1),[re,Y]=y.useState(-1),[H,q]=y.useState(!1),[he,A]=y.useState(""),[F,fe]=y.useState(-1),[te,de]=y.useState(""),ge=y.createRef(),Z=y.useRef(null),ye=y.useRef(null);y.useEffect(()=>{k.length&&console.warn("[Deprecation] The delimiters prop is deprecated and will be removed in v7.x.x, please use separators instead. If you have any concerns regarding this, please share your thoughts in https://github.com/react-tags/react-tags/issues/960")},[]),y.useEffect(()=>{typeof g<"u"&&console.warn("[Deprecation] The inline attribute is deprecated and will be removed in v7.x.x, please use inputFieldPosition instead.")},[g]),y.useEffect(()=>{typeof t<"u"&&console.warn("[Deprecated] autofocus prop will be removed in 7.x so please migrate to autoFocus prop."),(t||n&&t!==!1)&&!r&&Ye()},[n,n,r]),y.useEffect(()=>{vn()},[V,e.suggestions]);const Re=Te=>{let ut=e.suggestions.slice();if(b){const mr=M.map(vr=>vr.id.trim().toLowerCase());ut=ut.filter(vr=>!mr.includes(vr.id.toLowerCase()))}if(e.handleFilterSuggestions)return e.handleFilterSuggestions(Te,ut);const It=ut.filter(mr=>$e(Te,mr)===0),Tn=ut.filter(mr=>$e(Te,mr)>0);return It.concat(Tn)},$e=(Te,ut)=>ut[s].toLowerCase().indexOf(Te.toLowerCase()),Ye=()=>{G(""),Z.current&&(Z.current.value="",Z.current.focus())},Fe=(Te,ut)=>{ut.preventDefault(),ut.stopPropagation();const It=M.slice();It.length!==0&&(de(""),e?.handleDelete?.(Te,ut),ft(Te,It))},ft=(Te,ut)=>{if(!ge?.current)return;const It=ge.current.querySelectorAll(".ReactTags__remove");let Tn="";Te===0&&ut.length>1?(Tn=`Tag at index ${Te} with value ${ut[Te].id} deleted. Tag at index 0 with value ${ut[1].id} focussed. Press backspace to remove`,It[0].focus()):Te>0?(Tn=`Tag at index ${Te} with value ${ut[Te].id} deleted. Tag at index ${Te-1} with value ${ut[Te-1].id} focussed. Press backspace to remove`,It[Te-1].focus()):(Tn=`Tag at index ${Te} with value ${ut[Te].id} deleted. Input focussed. Press enter to add a new tag`,Z.current?.focus()),A(Tn)},ln=(Te,ut,It)=>{r||(w&&(fe(Te),G(ut[s]),ye.current?.focus()),e.handleTagClick?.(Te,It))},Sn=Te=>{e.handleInputChange&&e.handleInputChange(Te.target.value,Te);const ut=Te.target.value.trim();G(ut)},vn=()=>{const Te=Re(V);pe(Te),Y(re>=Te.length?Te.length-1:re)},Cn=Te=>{const ut=Te.target.value;e.handleInputFocus&&e.handleInputFocus(ut,Te),ie(!0)},L=Te=>{const ut=Te.target.value;e.handleInputBlur&&(e.handleInputBlur(ut,Te),Z.current&&(Z.current.value="")),ie(!1),fe(-1)},X=Te=>{if(Te.key==="Escape"&&(Te.preventDefault(),Te.stopPropagation(),Y(-1),q(!1),pe([]),fe(-1)),(j.indexOf(Te.key)!==-1||k.indexOf(Te.keyCode)!==-1)&&!Te.shiftKey){(Te.keyCode!==Il.TAB||V!=="")&&Te.preventDefault();const ut=H&&re!==-1?Q[re]:{id:V.trim(),[s]:V.trim(),className:""};Object.keys(ut)&&je(ut)}Te.key==="Backspace"&&V===""&&(o||_===cu.INLINE)&&Fe(M.length-1,Te),Te.keyCode===Il.UP_ARROW&&(Te.preventDefault(),Y(re<=0?Q.length-1:re-1),q(!0)),Te.keyCode===Il.DOWN_ARROW&&(Te.preventDefault(),q(!0),Q.length===0?Y(-1):Y((re+1)%Q.length))},ue=()=>x&&M.length>=x,Ne=Te=>{if(!l)return;if(ue()){de(lE.TAG_LIMIT),Ye();return}de(""),Te.preventDefault();const ut=Te.clipboardData||window.clipboardData,It=ut.getData("text"),{maxLength:Tn=It.length}=e,mr=Math.min(Tn,It.length),vr=ut.getData("text").substr(0,mr);let Gr=k;j.length&&(Gr=[],j.forEach(Rr=>{const Uo=vJ(Rr);Array.isArray(Uo)?Gr=[...Gr,...Uo]:Gr.push(Uo)}));const Jr=mJ(Gr),_r=vr.split(Jr).map(Rr=>Rr.trim());aJ(_r).forEach(Rr=>je({id:Rr.trim(),[s]:Rr.trim(),className:""}))},je=Te=>{if(!Te.id||!Te[s])return;if(F===-1){if(ue()){de(lE.TAG_LIMIT),Ye();return}de("")}const ut=M.map(It=>It.id.toLowerCase());if(!(b&&ut.indexOf(Te.id.trim().toLowerCase())>=0)){if(m){const It=Re(Te[s]);console.warn("[Deprecation] The autocomplete prop will be removed in 7.x to simplify the integration and make it more intutive. If you have any concerns regarding this, please share your thoughts in https://github.com/react-tags/react-tags/issues/949"),(m===1&&It.length===1||m===!0&&It.length)&&(Te=It[0])}F!==-1&&e.onTagUpdate?e.onTagUpdate(F,Te):e?.handleAddition?.(Te),G(""),q(!1),Y(-1),fe(-1),Ye()}},Se=Te=>{je(Q[Te])},Be=()=>{e.onClearAll&&e.onClearAll(),de(""),Ye()},bt=Te=>{Y(Te),q(!0)},Wt=(Te,ut)=>{const It=M[Te];e?.handleDrag?.(It,Te,ut)},bn=(()=>{const Te={...iE,...e.classNames};return M.map((ut,It)=>i.jsx(y.Fragment,{children:F===It?i.jsx("div",{className:Te.editTagInput,children:i.jsx("input",{ref:Tn=>{ye.current=Tn},onFocus:Cn,value:V,onChange:Sn,onKeyDown:X,onBlur:L,className:Te.editTagInputField,onPaste:Ne,"data-testid":"tag-edit"})}):i.jsx(wJ,{index:It,tag:ut,tags:M,labelField:s,onDelete:Tn=>Fe(It,Tn),moveTag:u?Wt:void 0,removeComponent:h,onTagClicked:Tn=>ln(It,ut,Tn),readOnly:r,classNames:Te,allowDragDrop:u})},It))})(),En={...iE,...N},{name:gr,id:Qn}=e,ro=g===!1?cu.BOTTOM:_,Bn=r?null:i.jsxs("div",{className:En.tagInput,children:[i.jsx("input",{...R,ref:Te=>{Z.current=Te},className:En.tagInputField,type:"text",placeholder:C,"aria-label":C,onFocus:Cn,onBlur:L,onChange:Sn,onKeyDown:X,onPaste:Ne,name:gr,id:Qn,maxLength:O,value:D,"data-automation":"input","data-testid":"input"}),i.jsx(pJ,{query:V.trim(),suggestions:Q,labelField:s,selectedIndex:re,handleClick:Se,handleHover:bt,minQueryLength:d,shouldRenderSuggestions:f,isFocused:W,classNames:En,renderSuggestion:e.renderSuggestion}),z&&M.length>0&&i.jsx(lJ,{classNames:En,onClick:Be}),te&&i.jsxs("div",{"data-testid":"error",className:"ReactTags__error",children:[i.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 512 512",height:"24",width:"24",fill:"#e03131",children:i.jsx("path",{d:"M256 32c14.2 0 27.3 7.5 34.5 19.8l216 368c7.3 12.4 7.3 27.7 .2 40.1S486.3 480 472 480H40c-14.3 0-27.6-7.7-34.7-20.1s-7-27.8 .2-40.1l216-368C228.7 39.5 241.8 32 256 32zm0 128c-13.3 0-24 10.7-24 24V296c0 13.3 10.7 24 24 24s24-10.7 24-24V184c0-13.3-10.7-24-24-24zm32 224a32 32 0 1 0 -64 0 32 32 0 1 0 64 0z"})}),te]})]});return i.jsxs("div",{className:(0,hJ.default)(En.tags,"react-tags-wrapper"),ref:ge,children:[i.jsx("p",{role:"alert",className:"sr-only",style:{position:"absolute",overflow:"hidden",clip:"rect(0 0 0 0)",margin:"-1px",padding:0,width:"1px",height:"1px",border:0},children:he}),ro===cu.TOP&&Bn,i.jsxs("div",{className:En.selected,children:[bn,ro===cu.INLINE&&Bn]}),ro===cu.BOTTOM&&Bn]})},CJ=SJ,EJ=e=>{const{placeholder:t=s7,labelField:n=o7,suggestions:r=[],delimiters:s=[],separators:o=e.delimiters?.length?[]:[Vs.ENTER,Vs.TAB],autofocus:l,autoFocus:u=!0,inline:d,inputFieldPosition:f="inline",allowDeleteFromEmptyInput:h=!1,allowAdditionFromPaste:m=!0,autocomplete:g=!1,readOnly:x=!1,allowUnique:b=!0,allowDragDrop:w=!0,tags:C=[],inputProps:k={},editable:j=!1,clearAll:M=!1,handleDelete:_,handleAddition:R,onTagUpdate:N,handleDrag:O,handleFilterSuggestions:D,handleTagClick:z,handleInputChange:Q,handleInputFocus:pe,handleInputBlur:V,minQueryLength:G,shouldRenderSuggestions:W,removeComponent:ie,onClearAll:re,classNames:Y,name:H,id:q,maxLength:he,inputValue:A,maxTags:F,renderSuggestion:fe}=e;return i.jsx(CJ,{placeholder:t,labelField:n,suggestions:r,delimiters:s,separators:o,autofocus:l,autoFocus:u,inline:d,inputFieldPosition:f,allowDeleteFromEmptyInput:h,allowAdditionFromPaste:m,autocomplete:g,readOnly:x,allowUnique:b,allowDragDrop:w,tags:C,inputProps:k,editable:j,clearAll:M,handleDelete:_,handleAddition:R,onTagUpdate:N,handleDrag:O,handleFilterSuggestions:D,handleTagClick:z,handleInputChange:Q,handleInputFocus:pe,handleInputBlur:V,minQueryLength:G,shouldRenderSuggestions:W,removeComponent:ie,onClearAll:re,classNames:Y,name:H,id:q,maxLength:he,inputValue:A,maxTags:F,renderSuggestion:fe})},kJ=({...e})=>i.jsx(tH,{backend:Zq,children:i.jsx(EJ,{...e})});/*! Bundled license information: classnames/index.js: (*! Copyright (c) 2018 Jed Watson. Licensed under the MIT License (MIT), see http://jedwatson.github.io/classnames *) lodash-es/lodash.js: (** * @license * Lodash (Custom Build) * Build: `lodash modularize exports="es" -o ./` * Copyright OpenJS Foundation and other contributors * Released under MIT license * Based on Underscore.js 1.8.3 * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors *) */var jJ="Label",kR=y.forwardRef((e,t)=>i.jsx(rt.label,{...e,ref:t,onMouseDown:n=>{n.target.closest("button, input, select, textarea")||(e.onMouseDown?.(n),!n.defaultPrevented&&n.detail>1&&n.preventDefault())}}));kR.displayName=jJ;var jR=kR;const TJ=jh("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),TR=y.forwardRef(({className:e,...t},n)=>i.jsx(jR,{ref:n,className:Ie(TJ(),e),...t}));TR.displayName=jR.displayName;function NR(e){const t=y.useRef({value:e,previous:e});return y.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}var NJ="VisuallyHidden",MR=y.forwardRef((e,t)=>i.jsx(rt.span,{...e,ref:t,style:{position:"absolute",border:0,width:1,height:1,padding:0,margin:-1,overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",wordWrap:"normal",...e.style}}));MR.displayName=NJ;var MJ=[" ","Enter","ArrowUp","ArrowDown"],_J=[" ","Enter"],jd="Select",[ng,rg,RJ]=Kb(jd),[hc]=us(jd,[RJ,Oh]),sg=Oh(),[PJ,Ia]=hc(jd),[OJ,IJ]=hc(jd),_R=e=>{const{__scopeSelect:t,children:n,open:r,defaultOpen:s,onOpenChange:o,value:l,defaultValue:u,onValueChange:d,dir:f,name:h,autoComplete:m,disabled:g,required:x}=e,b=sg(t),[w,C]=y.useState(null),[k,j]=y.useState(null),[M,_]=y.useState(!1),R=xd(f),[N=!1,O]=ya({prop:r,defaultProp:s,onChange:o}),[D,z]=ya({prop:l,defaultProp:u,onChange:d}),Q=y.useRef(null),pe=w?!!w.closest("form"):!0,[V,G]=y.useState(new Set),W=Array.from(V).map(ie=>ie.props.value).join(";");return i.jsx(ZT,{...b,children:i.jsxs(PJ,{required:x,scope:t,trigger:w,onTriggerChange:C,valueNode:k,onValueNodeChange:j,valueNodeHasChildren:M,onValueNodeHasChildrenChange:_,contentId:Es(),value:D,onValueChange:z,open:N,onOpenChange:O,dir:R,triggerPointerDownPosRef:Q,disabled:g,children:[i.jsx(ng.Provider,{scope:t,children:i.jsx(OJ,{scope:e.__scopeSelect,onNativeOptionAdd:y.useCallback(ie=>{G(re=>new Set(re).add(ie))},[]),onNativeOptionRemove:y.useCallback(ie=>{G(re=>{const Y=new Set(re);return Y.delete(ie),Y})},[]),children:n})}),pe?i.jsxs(tP,{"aria-hidden":!0,required:x,tabIndex:-1,name:h,autoComplete:m,value:D,onChange:ie=>z(ie.target.value),disabled:g,children:[D===void 0?i.jsx("option",{value:""}):null,Array.from(V)]},W):null]})})};_R.displayName=jd;var RR="SelectTrigger",PR=y.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...s}=e,o=sg(n),l=Ia(RR,n),u=l.disabled||r,d=Rt(t,l.onTriggerChange),f=rg(n),[h,m,g]=nP(b=>{const w=f().filter(j=>!j.disabled),C=w.find(j=>j.value===l.value),k=rP(w,b,C);k!==void 0&&l.onValueChange(k.value)}),x=()=>{u||(l.onOpenChange(!0),g())};return i.jsx(YT,{asChild:!0,...o,children:i.jsx(rt.button,{type:"button",role:"combobox","aria-controls":l.contentId,"aria-expanded":l.open,"aria-required":l.required,"aria-autocomplete":"none",dir:l.dir,"data-state":l.open?"open":"closed",disabled:u,"data-disabled":u?"":void 0,"data-placeholder":eP(l.value)?"":void 0,...s,ref:d,onClick:Ue(s.onClick,b=>{b.currentTarget.focus()}),onPointerDown:Ue(s.onPointerDown,b=>{const w=b.target;w.hasPointerCapture(b.pointerId)&&w.releasePointerCapture(b.pointerId),b.button===0&&b.ctrlKey===!1&&(x(),l.triggerPointerDownPosRef.current={x:Math.round(b.pageX),y:Math.round(b.pageY)},b.preventDefault())}),onKeyDown:Ue(s.onKeyDown,b=>{const w=h.current!=="";!(b.ctrlKey||b.altKey||b.metaKey)&&b.key.length===1&&m(b.key),!(w&&b.key===" ")&&MJ.includes(b.key)&&(x(),b.preventDefault())})})})});PR.displayName=RR;var OR="SelectValue",IR=y.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:s,children:o,placeholder:l="",...u}=e,d=Ia(OR,n),{onValueNodeHasChildrenChange:f}=d,h=o!==void 0,m=Rt(t,d.onValueNodeChange);return Ln(()=>{f(h)},[f,h]),i.jsx(rt.span,{...u,ref:m,style:{pointerEvents:"none"},children:eP(d.value)?i.jsx(i.Fragment,{children:l}):o})});IR.displayName=OR;var AJ="SelectIcon",AR=y.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...s}=e;return i.jsx(rt.span,{"aria-hidden":!0,...s,ref:t,children:r||"▼"})});AR.displayName=AJ;var DJ="SelectPortal",DR=e=>i.jsx(Ih,{asChild:!0,...e});DR.displayName=DJ;var _i="SelectContent",FR=y.forwardRef((e,t)=>{const n=Ia(_i,e.__scopeSelect),[r,s]=y.useState();if(Ln(()=>{s(new DocumentFragment)},[]),!n.open){const o=r;return o?Ma.createPortal(i.jsx(LR,{scope:e.__scopeSelect,children:i.jsx(ng.Slot,{scope:e.__scopeSelect,children:i.jsx("div",{children:e.children})})}),o):null}return i.jsx($R,{...e,ref:t})});FR.displayName=_i;var vo=10,[LR,Aa]=hc(_i),FJ="SelectContentImpl",$R=y.forwardRef((e,t)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:s,onEscapeKeyDown:o,onPointerDownOutside:l,side:u,sideOffset:d,align:f,alignOffset:h,arrowPadding:m,collisionBoundary:g,collisionPadding:x,sticky:b,hideWhenDetached:w,avoidCollisions:C,...k}=e,j=Ia(_i,n),[M,_]=y.useState(null),[R,N]=y.useState(null),O=Rt(t,Z=>_(Z)),[D,z]=y.useState(null),[Q,pe]=y.useState(null),V=rg(n),[G,W]=y.useState(!1),ie=y.useRef(!1);y.useEffect(()=>{if(M)return nx(M)},[M]),Wb();const re=y.useCallback(Z=>{const[ye,...Re]=V().map(Fe=>Fe.ref.current),[$e]=Re.slice(-1),Ye=document.activeElement;for(const Fe of Z)if(Fe===Ye||(Fe?.scrollIntoView({block:"nearest"}),Fe===ye&&R&&(R.scrollTop=0),Fe===$e&&R&&(R.scrollTop=R.scrollHeight),Fe?.focus(),document.activeElement!==Ye))return},[V,R]),Y=y.useCallback(()=>re([D,M]),[re,D,M]);y.useEffect(()=>{G&&Y()},[G,Y]);const{onOpenChange:H,triggerPointerDownPosRef:q}=j;y.useEffect(()=>{if(M){let Z={x:0,y:0};const ye=$e=>{Z={x:Math.abs(Math.round($e.pageX)-(q.current?.x??0)),y:Math.abs(Math.round($e.pageY)-(q.current?.y??0))}},Re=$e=>{Z.x<=10&&Z.y<=10?$e.preventDefault():M.contains($e.target)||H(!1),document.removeEventListener("pointermove",ye),q.current=null};return q.current!==null&&(document.addEventListener("pointermove",ye),document.addEventListener("pointerup",Re,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",ye),document.removeEventListener("pointerup",Re,{capture:!0})}}},[M,H,q]),y.useEffect(()=>{const Z=()=>H(!1);return window.addEventListener("blur",Z),window.addEventListener("resize",Z),()=>{window.removeEventListener("blur",Z),window.removeEventListener("resize",Z)}},[H]);const[he,A]=nP(Z=>{const ye=V().filter(Ye=>!Ye.disabled),Re=ye.find(Ye=>Ye.ref.current===document.activeElement),$e=rP(ye,Z,Re);$e&&setTimeout(()=>$e.ref.current.focus())}),F=y.useCallback((Z,ye,Re)=>{const $e=!ie.current&&!Re;(j.value!==void 0&&j.value===ye||$e)&&(z(Z),$e&&(ie.current=!0))},[j.value]),fe=y.useCallback(()=>M?.focus(),[M]),te=y.useCallback((Z,ye,Re)=>{const $e=!ie.current&&!Re;(j.value!==void 0&&j.value===ye||$e)&&pe(Z)},[j.value]),de=r==="popper"?cb:BR,ge=de===cb?{side:u,sideOffset:d,align:f,alignOffset:h,arrowPadding:m,collisionBoundary:g,collisionPadding:x,sticky:b,hideWhenDetached:w,avoidCollisions:C}:{};return i.jsx(LR,{scope:n,content:M,viewport:R,onViewportChange:N,itemRefCallback:F,selectedItem:D,onItemLeave:fe,itemTextRefCallback:te,focusSelectedItem:Y,selectedItemText:Q,position:r,isPositioned:G,searchRef:he,children:i.jsx(Lh,{as:No,allowPinchZoom:!0,children:i.jsx(_h,{asChild:!0,trapped:j.open,onMountAutoFocus:Z=>{Z.preventDefault()},onUnmountAutoFocus:Ue(s,Z=>{j.trigger?.focus({preventScroll:!0}),Z.preventDefault()}),children:i.jsx(Mh,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:o,onPointerDownOutside:l,onFocusOutside:Z=>Z.preventDefault(),onDismiss:()=>j.onOpenChange(!1),children:i.jsx(de,{role:"listbox",id:j.contentId,"data-state":j.open?"open":"closed",dir:j.dir,onContextMenu:Z=>Z.preventDefault(),...k,...ge,onPlaced:()=>W(!0),ref:O,style:{display:"flex",flexDirection:"column",outline:"none",...k.style},onKeyDown:Ue(k.onKeyDown,Z=>{const ye=Z.ctrlKey||Z.altKey||Z.metaKey;if(Z.key==="Tab"&&Z.preventDefault(),!ye&&Z.key.length===1&&A(Z.key),["ArrowUp","ArrowDown","Home","End"].includes(Z.key)){let $e=V().filter(Ye=>!Ye.disabled).map(Ye=>Ye.ref.current);if(["ArrowUp","End"].includes(Z.key)&&($e=$e.slice().reverse()),["ArrowUp","ArrowDown"].includes(Z.key)){const Ye=Z.target,Fe=$e.indexOf(Ye);$e=$e.slice(Fe+1)}setTimeout(()=>re($e)),Z.preventDefault()}})})})})})})});$R.displayName=FJ;var LJ="SelectItemAlignedPosition",BR=y.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...s}=e,o=Ia(_i,n),l=Aa(_i,n),[u,d]=y.useState(null),[f,h]=y.useState(null),m=Rt(t,O=>h(O)),g=rg(n),x=y.useRef(!1),b=y.useRef(!0),{viewport:w,selectedItem:C,selectedItemText:k,focusSelectedItem:j}=l,M=y.useCallback(()=>{if(o.trigger&&o.valueNode&&u&&f&&w&&C&&k){const O=o.trigger.getBoundingClientRect(),D=f.getBoundingClientRect(),z=o.valueNode.getBoundingClientRect(),Q=k.getBoundingClientRect();if(o.dir!=="rtl"){const Ye=Q.left-D.left,Fe=z.left-Ye,ft=O.left-Fe,ln=O.width+ft,Sn=Math.max(ln,D.width),vn=window.innerWidth-vo,Cn=Ky(Fe,[vo,vn-Sn]);u.style.minWidth=ln+"px",u.style.left=Cn+"px"}else{const Ye=D.right-Q.right,Fe=window.innerWidth-z.right-Ye,ft=window.innerWidth-O.right-Fe,ln=O.width+ft,Sn=Math.max(ln,D.width),vn=window.innerWidth-vo,Cn=Ky(Fe,[vo,vn-Sn]);u.style.minWidth=ln+"px",u.style.right=Cn+"px"}const pe=g(),V=window.innerHeight-vo*2,G=w.scrollHeight,W=window.getComputedStyle(f),ie=parseInt(W.borderTopWidth,10),re=parseInt(W.paddingTop,10),Y=parseInt(W.borderBottomWidth,10),H=parseInt(W.paddingBottom,10),q=ie+re+G+H+Y,he=Math.min(C.offsetHeight*5,q),A=window.getComputedStyle(w),F=parseInt(A.paddingTop,10),fe=parseInt(A.paddingBottom,10),te=O.top+O.height/2-vo,de=V-te,ge=C.offsetHeight/2,Z=C.offsetTop+ge,ye=ie+re+Z,Re=q-ye;if(ye<=te){const Ye=C===pe[pe.length-1].ref.current;u.style.bottom="0px";const Fe=f.clientHeight-w.offsetTop-w.offsetHeight,ft=Math.max(de,ge+(Ye?fe:0)+Fe+Y),ln=ye+ft;u.style.height=ln+"px"}else{const Ye=C===pe[0].ref.current;u.style.top="0px";const ft=Math.max(te,ie+w.offsetTop+(Ye?F:0)+ge)+Re;u.style.height=ft+"px",w.scrollTop=ye-te+w.offsetTop}u.style.margin=`${vo}px 0`,u.style.minHeight=he+"px",u.style.maxHeight=V+"px",r?.(),requestAnimationFrame(()=>x.current=!0)}},[g,o.trigger,o.valueNode,u,f,w,C,k,o.dir,r]);Ln(()=>M(),[M]);const[_,R]=y.useState();Ln(()=>{f&&R(window.getComputedStyle(f).zIndex)},[f]);const N=y.useCallback(O=>{O&&b.current===!0&&(M(),j?.(),b.current=!1)},[M,j]);return i.jsx(BJ,{scope:n,contentWrapper:u,shouldExpandOnScrollRef:x,onScrollButtonChange:N,children:i.jsx("div",{ref:d,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:_},children:i.jsx(rt.div,{...s,ref:m,style:{boxSizing:"border-box",maxHeight:"100%",...s.style}})})})});BR.displayName=LJ;var $J="SelectPopperPosition",cb=y.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:s=vo,...o}=e,l=sg(n);return i.jsx(XT,{...l,...o,ref:t,align:r,collisionPadding:s,style:{boxSizing:"border-box",...o.style,"--radix-select-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-select-content-available-width":"var(--radix-popper-available-width)","--radix-select-content-available-height":"var(--radix-popper-available-height)","--radix-select-trigger-width":"var(--radix-popper-anchor-width)","--radix-select-trigger-height":"var(--radix-popper-anchor-height)"}})});cb.displayName=$J;var[BJ,$x]=hc(_i,{}),ub="SelectViewport",zR=y.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...s}=e,o=Aa(ub,n),l=$x(ub,n),u=Rt(t,o.onViewportChange),d=y.useRef(0);return i.jsxs(i.Fragment,{children:[i.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}"},nonce:r}),i.jsx(ng.Slot,{scope:n,children:i.jsx(rt.div,{"data-radix-select-viewport":"",role:"presentation",...s,ref:u,style:{position:"relative",flex:1,overflow:"auto",...s.style},onScroll:Ue(s.onScroll,f=>{const h=f.currentTarget,{contentWrapper:m,shouldExpandOnScrollRef:g}=l;if(g?.current&&m){const x=Math.abs(d.current-h.scrollTop);if(x>0){const b=window.innerHeight-vo*2,w=parseFloat(m.style.minHeight),C=parseFloat(m.style.height),k=Math.max(w,C);if(k0?_:0,m.style.justifyContent="flex-end")}}}d.current=h.scrollTop})})})]})});zR.displayName=ub;var UR="SelectGroup",[zJ,UJ]=hc(UR),VJ=y.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,s=Es();return i.jsx(zJ,{scope:n,id:s,children:i.jsx(rt.div,{role:"group","aria-labelledby":s,...r,ref:t})})});VJ.displayName=UR;var VR="SelectLabel",HR=y.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,s=UJ(VR,n);return i.jsx(rt.div,{id:s.id,...r,ref:t})});HR.displayName=VR;var ih="SelectItem",[HJ,qR]=hc(ih),KR=y.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:s=!1,textValue:o,...l}=e,u=Ia(ih,n),d=Aa(ih,n),f=u.value===r,[h,m]=y.useState(o??""),[g,x]=y.useState(!1),b=Rt(t,k=>d.itemRefCallback?.(k,r,s)),w=Es(),C=()=>{s||(u.onValueChange(r),u.onOpenChange(!1))};if(r==="")throw new Error("A must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return i.jsx(HJ,{scope:n,value:r,disabled:s,textId:w,isSelected:f,onItemTextChange:y.useCallback(k=>{m(j=>j||(k?.textContent??"").trim())},[]),children:i.jsx(ng.ItemSlot,{scope:n,value:r,disabled:s,textValue:h,children:i.jsx(rt.div,{role:"option","aria-labelledby":w,"data-highlighted":g?"":void 0,"aria-selected":f&&g,"data-state":f?"checked":"unchecked","aria-disabled":s||void 0,"data-disabled":s?"":void 0,tabIndex:s?void 0:-1,...l,ref:b,onFocus:Ue(l.onFocus,()=>x(!0)),onBlur:Ue(l.onBlur,()=>x(!1)),onPointerUp:Ue(l.onPointerUp,C),onPointerMove:Ue(l.onPointerMove,k=>{s?d.onItemLeave?.():k.currentTarget.focus({preventScroll:!0})}),onPointerLeave:Ue(l.onPointerLeave,k=>{k.currentTarget===document.activeElement&&d.onItemLeave?.()}),onKeyDown:Ue(l.onKeyDown,k=>{d.searchRef?.current!==""&&k.key===" "||(_J.includes(k.key)&&C(),k.key===" "&&k.preventDefault())})})})})});KR.displayName=ih;var xu="SelectItemText",WR=y.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:s,...o}=e,l=Ia(xu,n),u=Aa(xu,n),d=qR(xu,n),f=IJ(xu,n),[h,m]=y.useState(null),g=Rt(t,k=>m(k),d.onItemTextChange,k=>u.itemTextRefCallback?.(k,d.value,d.disabled)),x=h?.textContent,b=y.useMemo(()=>i.jsx("option",{value:d.value,disabled:d.disabled,children:x},d.value),[d.disabled,d.value,x]),{onNativeOptionAdd:w,onNativeOptionRemove:C}=f;return Ln(()=>(w(b),()=>C(b)),[w,C,b]),i.jsxs(i.Fragment,{children:[i.jsx(rt.span,{id:d.textId,...o,ref:g}),d.isSelected&&l.valueNode&&!l.valueNodeHasChildren?Ma.createPortal(o.children,l.valueNode):null]})});WR.displayName=xu;var GR="SelectItemIndicator",JR=y.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return qR(GR,n).isSelected?i.jsx(rt.span,{"aria-hidden":!0,...r,ref:t}):null});JR.displayName=GR;var db="SelectScrollUpButton",QR=y.forwardRef((e,t)=>{const n=Aa(db,e.__scopeSelect),r=$x(db,e.__scopeSelect),[s,o]=y.useState(!1),l=Rt(t,r.onScrollButtonChange);return Ln(()=>{if(n.viewport&&n.isPositioned){let u=function(){const f=d.scrollTop>0;o(f)};const d=n.viewport;return u(),d.addEventListener("scroll",u),()=>d.removeEventListener("scroll",u)}},[n.viewport,n.isPositioned]),s?i.jsx(YR,{...e,ref:l,onAutoScroll:()=>{const{viewport:u,selectedItem:d}=n;u&&d&&(u.scrollTop=u.scrollTop-d.offsetHeight)}}):null});QR.displayName=db;var fb="SelectScrollDownButton",ZR=y.forwardRef((e,t)=>{const n=Aa(fb,e.__scopeSelect),r=$x(fb,e.__scopeSelect),[s,o]=y.useState(!1),l=Rt(t,r.onScrollButtonChange);return Ln(()=>{if(n.viewport&&n.isPositioned){let u=function(){const f=d.scrollHeight-d.clientHeight,h=Math.ceil(d.scrollTop)d.removeEventListener("scroll",u)}},[n.viewport,n.isPositioned]),s?i.jsx(YR,{...e,ref:l,onAutoScroll:()=>{const{viewport:u,selectedItem:d}=n;u&&d&&(u.scrollTop=u.scrollTop+d.offsetHeight)}}):null});ZR.displayName=fb;var YR=y.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...s}=e,o=Aa("SelectScrollButton",n),l=y.useRef(null),u=rg(n),d=y.useCallback(()=>{l.current!==null&&(window.clearInterval(l.current),l.current=null)},[]);return y.useEffect(()=>()=>d(),[d]),Ln(()=>{u().find(h=>h.ref.current===document.activeElement)?.ref.current?.scrollIntoView({block:"nearest"})},[u]),i.jsx(rt.div,{"aria-hidden":!0,...s,ref:t,style:{flexShrink:0,...s.style},onPointerDown:Ue(s.onPointerDown,()=>{l.current===null&&(l.current=window.setInterval(r,50))}),onPointerMove:Ue(s.onPointerMove,()=>{o.onItemLeave?.(),l.current===null&&(l.current=window.setInterval(r,50))}),onPointerLeave:Ue(s.onPointerLeave,()=>{d()})})}),qJ="SelectSeparator",XR=y.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return i.jsx(rt.div,{"aria-hidden":!0,...r,ref:t})});XR.displayName=qJ;var pb="SelectArrow",KJ=y.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,s=sg(n),o=Ia(pb,n),l=Aa(pb,n);return o.open&&l.position==="popper"?i.jsx(eN,{...s,...r,ref:t}):null});KJ.displayName=pb;function eP(e){return e===""||e===void 0}var tP=y.forwardRef((e,t)=>{const{value:n,...r}=e,s=y.useRef(null),o=Rt(t,s),l=NR(n);return y.useEffect(()=>{const u=s.current,d=window.HTMLSelectElement.prototype,h=Object.getOwnPropertyDescriptor(d,"value").set;if(l!==n&&h){const m=new Event("change",{bubbles:!0});h.call(u,n),u.dispatchEvent(m)}},[l,n]),i.jsx(MR,{asChild:!0,children:i.jsx("select",{...r,ref:o,defaultValue:n})})});tP.displayName="BubbleSelect";function nP(e){const t=Rn(e),n=y.useRef(""),r=y.useRef(0),s=y.useCallback(l=>{const u=n.current+l;t(u),(function d(f){n.current=f,window.clearTimeout(r.current),f!==""&&(r.current=window.setTimeout(()=>d(""),1e3))})(u)},[t]),o=y.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return y.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,s,o]}function rP(e,t,n){const s=t.length>1&&Array.from(t).every(f=>f===t[0])?t[0]:t,o=n?e.indexOf(n):-1;let l=WJ(e,Math.max(o,0));s.length===1&&(l=l.filter(f=>f!==n));const d=l.find(f=>f.textValue.toLowerCase().startsWith(s.toLowerCase()));return d!==n?d:void 0}function WJ(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var GJ=_R,sP=PR,JJ=IR,QJ=AR,ZJ=DR,oP=FR,YJ=zR,aP=HR,iP=KR,XJ=WR,eQ=JR,lP=QR,cP=ZR,uP=XR;const tQ=GJ,nQ=JJ,dP=y.forwardRef(({className:e,children:t,...n},r)=>i.jsxs(sP,{ref:r,className:Ie("flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-default disabled:opacity-50 [&>span]:line-clamp-1",e),...n,children:[t,i.jsx(QJ,{asChild:!0,children:i.jsx(Nh,{className:"h-4 w-4 opacity-50"})})]}));dP.displayName=sP.displayName;const fP=y.forwardRef(({className:e,...t},n)=>i.jsx(lP,{ref:n,className:Ie("flex cursor-default items-center justify-center py-1",e),...t,children:i.jsx(G$,{className:"h-4 w-4"})}));fP.displayName=lP.displayName;const pP=y.forwardRef(({className:e,...t},n)=>i.jsx(cP,{ref:n,className:Ie("flex cursor-default items-center justify-center py-1",e),...t,children:i.jsx(Nh,{className:"h-4 w-4"})}));pP.displayName=cP.displayName;const hP=y.forwardRef(({className:e,children:t,position:n="popper",...r},s)=>i.jsx(ZJ,{children:i.jsxs(oP,{ref:s,className:Ie("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:n,...r,children:[i.jsx(fP,{}),i.jsx(YJ,{className:Ie("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),i.jsx(pP,{})]})}));hP.displayName=oP.displayName;const rQ=y.forwardRef(({className:e,...t},n)=>i.jsx(aP,{ref:n,className:Ie("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));rQ.displayName=aP.displayName;const gP=y.forwardRef(({className:e,children:t,...n},r)=>i.jsxs(iP,{ref:r,className:Ie("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[i.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:i.jsx(eQ,{children:i.jsx(fT,{className:"h-4 w-4"})})}),i.jsx(XJ,{children:t})]}));gP.displayName=iP.displayName;const sQ=y.forwardRef(({className:e,...t},n)=>i.jsx(uP,{ref:n,className:Ie("-mx-1 my-1 h-px bg-muted",e),...t}));sQ.displayName=uP.displayName;var Bx="Switch",[oQ]=us(Bx),[aQ,iQ]=oQ(Bx),mP=y.forwardRef((e,t)=>{const{__scopeSwitch:n,name:r,checked:s,defaultChecked:o,required:l,disabled:u,value:d="on",onCheckedChange:f,...h}=e,[m,g]=y.useState(null),x=Rt(t,j=>g(j)),b=y.useRef(!1),w=m?!!m.closest("form"):!0,[C=!1,k]=ya({prop:s,defaultProp:o,onChange:f});return i.jsxs(aQ,{scope:n,checked:C,disabled:u,children:[i.jsx(rt.button,{type:"button",role:"switch","aria-checked":C,"aria-required":l,"data-state":bP(C),"data-disabled":u?"":void 0,disabled:u,value:d,...h,ref:x,onClick:Ue(e.onClick,j=>{k(M=>!M),w&&(b.current=j.isPropagationStopped(),b.current||j.stopPropagation())})}),w&&i.jsx(lQ,{control:m,bubbles:!b.current,name:r,value:d,checked:C,required:l,disabled:u,style:{transform:"translateX(-100%)"}})]})});mP.displayName=Bx;var vP="SwitchThumb",yP=y.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,s=iQ(vP,n);return i.jsx(rt.span,{"data-state":bP(s.checked),"data-disabled":s.disabled?"":void 0,...r,ref:t})});yP.displayName=vP;var lQ=e=>{const{control:t,checked:n,bubbles:r=!0,...s}=e,o=y.useRef(null),l=NR(n),u=zT(t);return y.useEffect(()=>{const d=o.current,f=window.HTMLInputElement.prototype,m=Object.getOwnPropertyDescriptor(f,"checked").set;if(l!==n&&m){const g=new Event("click",{bubbles:r});m.call(d,n),d.dispatchEvent(g)}},[l,n,r]),i.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:n,...s,tabIndex:-1,ref:o,style:{...e.style,...u,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})};function bP(e){return e?"checked":"unchecked"}var xP=mP,cQ=yP;const gc=y.forwardRef(({className:e,...t},n)=>i.jsx(xP,{className:Ie("peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-slate-400",e),...t,ref:n,children:i.jsx(cQ,{className:Ie("pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0")})}));gc.displayName=xP.displayName;const Fo=Gn,wP=y.createContext({}),Lo=({...e})=>i.jsx(wP.Provider,{value:{name:e.name},children:i.jsx(r6,{...e})}),og=()=>{const e=y.useContext(wP),t=y.useContext(SP),{getFieldState:n,formState:r}=Kh(),s=n(e.name,r);if(!e)throw new Error("useFormField should be used within ");const{id:o}=t;return{id:o,name:e.name,formItemId:`${o}-form-item`,formDescriptionId:`${o}-form-item-description`,formMessageId:`${o}-form-item-message`,...s}},SP=y.createContext({}),no=y.forwardRef(({className:e,...t},n)=>{const r=y.useId();return i.jsx(SP.Provider,{value:{id:r},children:i.jsx("div",{ref:n,className:Ie("space-y-2",e),...t})})});no.displayName="FormItem";const Nr=y.forwardRef(({className:e,...t},n)=>{const{error:r,formItemId:s}=og();return i.jsx(TR,{ref:n,className:Ie(r&&"text-rose-600",e),htmlFor:s,...t})});Nr.displayName="FormLabel";const _s=y.forwardRef(({...e},t)=>{const{error:n,formItemId:r,formDescriptionId:s,formMessageId:o}=og();return i.jsx(No,{ref:t,id:r,"aria-describedby":n?`${s} ${o}`:`${s}`,"aria-invalid":!!n,...e})});_s.displayName="FormControl";const ag=y.forwardRef(({className:e,...t},n)=>{const{formDescriptionId:r}=og();return i.jsx("p",{ref:n,id:r,className:Ie("text-sm text-muted-foreground",e),...t})});ag.displayName="FormDescription";const Td=y.forwardRef(({className:e,children:t,...n},r)=>{const{error:s,formMessageId:o}=og(),l=s?String(s?.message):t;return l?i.jsx("p",{ref:r,id:o,className:Ie("text-sm font-medium text-rose-600",e),...n,children:l}):null});Td.displayName="FormMessage";const le=({name:e,label:t,children:n,required:r,readOnly:s,className:o,...l})=>i.jsx(Lo,{...l,name:e,render:({field:u})=>i.jsxs(no,{className:o,children:[t&&i.jsxs(Nr,{children:[t,r&&i.jsx("span",{className:"ml-2 text-rose-600",children:"*"})]}),i.jsx(_s,{children:y.isValidElement(n)&&y.cloneElement(n,{...u,value:u.value??"",required:r,readOnly:s,checked:u.value,onCheckedChange:u.onChange})}),i.jsx(Td,{})]})}),Pe=({name:e,label:t,required:n,className:r,helper:s,reverse:o,...l})=>i.jsx(Lo,{...l,name:e,render:({field:u})=>i.jsxs(no,{className:Ie("flex items-center gap-3",o&&"flex-row-reverse justify-end",r),children:[i.jsx("div",{className:"flex flex-col gap-2",children:t&&i.jsxs(Nr,{children:[i.jsxs("p",{className:"break-all",children:[t,n&&i.jsx("span",{className:"ml-2 text-rose-600",children:"*"})]}),s&&i.jsx(ag,{className:"mt-2",children:s})]})}),i.jsx(_s,{children:i.jsx(gc,{checked:u.value,onCheckedChange:u.onChange,required:n})}),i.jsx(Td,{})]})}),Jt=({name:e,label:t,helper:n,required:r,options:s,placeholder:o,disabled:l,...u})=>i.jsx(Lo,{...u,name:e,render:({field:d})=>i.jsxs(no,{children:[t&&i.jsxs(Nr,{children:[t,r&&i.jsx("span",{className:"ml-2 text-rose-600",children:"*"})]}),i.jsx(_s,{children:i.jsxs(tQ,{onValueChange:d.onChange,defaultValue:d.value,disabled:l,children:[i.jsx(_s,{children:i.jsx(dP,{children:i.jsx(nQ,{placeholder:o})})}),i.jsx(hP,{children:s.map(f=>i.jsx(gP,{value:f.value,children:f.label},f.value))})]})}),n&&i.jsx(ag,{children:n}),i.jsx(Td,{})]})}),Da=({name:e,label:t,helper:n,required:r,placeholder:s,...o})=>i.jsx(Lo,{...o,name:e,render:({field:l})=>{let u=[];return Array.isArray(l.value)&&(u=l.value),i.jsxs(no,{children:[t&&i.jsxs(Nr,{children:[t,r&&i.jsx("span",{className:"ml-2 text-rose-600",children:"*"})]}),i.jsx(_s,{children:i.jsx(kJ,{tags:u.map(d=>({id:d,text:d,className:""})),handleDelete:d=>l.onChange(u.filter((f,h)=>h!==d)),handleAddition:d=>l.onChange([...u,d.id]),inputFieldPosition:"bottom",placeholder:s,autoFocus:!1,allowDragDrop:!1,separators:[Vs.ENTER,Vs.TAB,Vs.COMMA],classNames:{tags:"tagsClass",tagInput:"tagInputClass",tagInputField:u_,selected:"my-2 flex flex-wrap gap-2",tag:"flex items-center gap-2 px-2 py-1 bg-primary/30 rounded-md text-xs",remove:"[&>svg]:fill-rose-600 hover:[&>svg]:fill-rose-700",suggestions:"suggestionsClass",activeSuggestion:"activeSuggestionClass",editTagInput:"editTagInputClass",editTagInputField:"editTagInputFieldClass",clearAll:"clearAllClass"}})}),n&&i.jsx(ag,{children:n}),i.jsx(Td,{})]})}}),Kv=P.string().optional().transform(e=>e===""?void 0:e),uQ=P.object({name:P.string(),token:Kv,number:Kv,businessId:Kv,integration:P.enum(["WHATSAPP-BUSINESS","WHATSAPP-BAILEYS","EVOLUTION"])});function dQ({resetTable:e}){const{t}=Ve(),{createInstance:n}=Hh(),[r,s]=y.useState(!1),o=[{value:"WHATSAPP-BAILEYS",label:t("instance.form.integration.baileys")},{value:"WHATSAPP-BUSINESS",label:t("instance.form.integration.whatsapp")},{value:"EVOLUTION",label:t("instance.form.integration.evolution")}],l=on({resolver:an(uQ),defaultValues:{name:"",integration:"WHATSAPP-BAILEYS",token:E1().replace("-","").toUpperCase(),number:"",businessId:""}}),u=l.watch("integration"),d=async h=>{try{const m={instanceName:h.name,integration:h.integration,token:h.token===""?null:h.token,number:h.number===""?null:h.number,businessId:h.businessId===""?null:h.businessId};await n(m),me.success(t("toast.instance.created")),s(!1),f(),e()}catch(m){console.error("Error:",m),me.error(`Error : ${m?.response?.data?.response?.message}`)}},f=()=>{l.reset({name:"",integration:"WHATSAPP-BAILEYS",token:E1().replace("-","").toLocaleUpperCase(),number:"",businessId:""})};return i.jsxs(Pt,{open:r,onOpenChange:s,children:[i.jsx(Bt,{asChild:!0,children:i.jsxs(se,{variant:"default",size:"sm",children:[t("instance.button.create")," ",i.jsx(cs,{size:"18"})]})}),i.jsxs(Nt,{className:"sm:max-w-[650px]",onCloseAutoFocus:f,children:[i.jsx(Mt,{children:i.jsx(zt,{children:t("instance.modal.title")})}),i.jsx(Gn,{...l,children:i.jsxs("form",{onSubmit:l.handleSubmit(d),className:"grid gap-4 py-4",children:[i.jsx(le,{required:!0,name:"name",label:t("instance.form.name"),children:i.jsx(ne,{})}),i.jsx(Jt,{name:"integration",label:t("instance.form.integration.label"),options:o}),i.jsx(le,{required:!0,name:"token",label:t("instance.form.token"),children:i.jsx(ne,{})}),i.jsx(le,{name:"number",label:t("instance.form.number"),children:i.jsx(ne,{type:"tel"})}),u==="WHATSAPP-BUSINESS"&&i.jsx(le,{required:!0,name:"businessId",label:t("instance.form.businessId"),children:i.jsx(ne,{})}),i.jsx(Yt,{children:i.jsx(se,{type:"submit",children:t("instance.button.save")})})]})})]})]})}function bo(e,t,{checkForDefaultPrevented:n=!0}={}){return function(s){if(e?.(s),n===!1||!s.defaultPrevented)return t?.(s)}}function IE(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function CP(...e){return t=>{let n=!1;const r=e.map(s=>{const o=IE(s,t);return!n&&typeof o=="function"&&(n=!0),o});if(n)return()=>{for(let s=0;s{const{scope:g,children:x,...b}=m,w=g?.[e]?.[d]||u,C=y.useMemo(()=>b,Object.values(b));return i.jsx(w.Provider,{value:C,children:x})};f.displayName=o+"Provider";function h(m,g){const x=g?.[e]?.[d]||u,b=y.useContext(x);if(b)return b;if(l!==void 0)return l;throw new Error(`\`${m}\` must be used within \`${o}\``)}return[f,h]}const s=()=>{const o=n.map(l=>y.createContext(l));return function(u){const d=u?.[e]||o;return y.useMemo(()=>({[`__scope${e}`]:{...u,[e]:d}}),[u,d])}};return s.scopeName=e,[r,fQ(s,...t)]}function fQ(...e){const t=e[0];if(e.length===1)return t;const n=()=>{const r=e.map(s=>({useScope:s(),scopeName:s.scopeName}));return function(o){const l=r.reduce((u,{useScope:d,scopeName:f})=>{const m=d(o)[`__scope${f}`];return{...u,...m}},{});return y.useMemo(()=>({[`__scope${t.scopeName}`]:l}),[l])}};return n.scopeName=t.scopeName,n}function pQ(e){const t=hQ(e),n=y.forwardRef((r,s)=>{const{children:o,...l}=r,u=y.Children.toArray(o),d=u.find(mQ);if(d){const f=d.props.children,h=u.map(m=>m===d?y.Children.count(f)>1?y.Children.only(null):y.isValidElement(f)?f.props.children:null:m);return i.jsx(t,{...l,ref:s,children:y.isValidElement(f)?y.cloneElement(f,void 0,h):null})}return i.jsx(t,{...l,ref:s,children:o})});return n.displayName=`${e}.Slot`,n}function hQ(e){const t=y.forwardRef((n,r)=>{const{children:s,...o}=n;if(y.isValidElement(s)){const l=yQ(s),u=vQ(o,s.props);return s.type!==y.Fragment&&(u.ref=r?CP(r,l):l),y.cloneElement(s,u)}return y.Children.count(s)>1?y.Children.only(null):null});return t.displayName=`${e}.SlotClone`,t}var kP=Symbol("radix.slottable");function gQ(e){const t=({children:n})=>i.jsx(i.Fragment,{children:n});return t.displayName=`${e}.Slottable`,t.__radixId=kP,t}function mQ(e){return y.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===kP}function vQ(e,t){const n={...t};for(const r in t){const s=e[r],o=t[r];/^on[A-Z]/.test(r)?s&&o?n[r]=(...u)=>{const d=o(...u);return s(...u),d}:s&&(n[r]=s):r==="style"?n[r]={...s,...o}:r==="className"&&(n[r]=[s,o].filter(Boolean).join(" "))}return{...e,...n}}function yQ(e){let t=Object.getOwnPropertyDescriptor(e.props,"ref")?.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=Object.getOwnPropertyDescriptor(e,"ref")?.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}var bQ=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Fa=bQ.reduce((e,t)=>{const n=pQ(`Primitive.${t}`),r=y.forwardRef((s,o)=>{const{asChild:l,...u}=s,d=l?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),i.jsx(d,{...u,ref:o})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function xQ(e,t){e&&Ma.flushSync(()=>e.dispatchEvent(t))}function ig(e){const t=y.useRef(e);return y.useEffect(()=>{t.current=e}),y.useMemo(()=>(...n)=>t.current?.(...n),[])}function wQ(e,t=globalThis?.document){const n=ig(e);y.useEffect(()=>{const r=s=>{s.key==="Escape"&&n(s)};return t.addEventListener("keydown",r,{capture:!0}),()=>t.removeEventListener("keydown",r,{capture:!0})},[n,t])}var SQ="DismissableLayer",hb="dismissableLayer.update",CQ="dismissableLayer.pointerDownOutside",EQ="dismissableLayer.focusOutside",AE,jP=y.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),TP=y.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:s,onFocusOutside:o,onInteractOutside:l,onDismiss:u,...d}=e,f=y.useContext(jP),[h,m]=y.useState(null),g=h?.ownerDocument??globalThis?.document,[,x]=y.useState({}),b=Ui(t,O=>m(O)),w=Array.from(f.layers),[C]=[...f.layersWithOutsidePointerEventsDisabled].slice(-1),k=w.indexOf(C),j=h?w.indexOf(h):-1,M=f.layersWithOutsidePointerEventsDisabled.size>0,_=j>=k,R=TQ(O=>{const D=O.target,z=[...f.branches].some(Q=>Q.contains(D));!_||z||(s?.(O),l?.(O),O.defaultPrevented||u?.())},g),N=NQ(O=>{const D=O.target;[...f.branches].some(Q=>Q.contains(D))||(o?.(O),l?.(O),O.defaultPrevented||u?.())},g);return wQ(O=>{j===f.layers.size-1&&(r?.(O),!O.defaultPrevented&&u&&(O.preventDefault(),u()))},g),y.useEffect(()=>{if(h)return n&&(f.layersWithOutsidePointerEventsDisabled.size===0&&(AE=g.body.style.pointerEvents,g.body.style.pointerEvents="none"),f.layersWithOutsidePointerEventsDisabled.add(h)),f.layers.add(h),DE(),()=>{n&&f.layersWithOutsidePointerEventsDisabled.size===1&&(g.body.style.pointerEvents=AE)}},[h,g,n,f]),y.useEffect(()=>()=>{h&&(f.layers.delete(h),f.layersWithOutsidePointerEventsDisabled.delete(h),DE())},[h,f]),y.useEffect(()=>{const O=()=>x({});return document.addEventListener(hb,O),()=>document.removeEventListener(hb,O)},[]),i.jsx(Fa.div,{...d,ref:b,style:{pointerEvents:M?_?"auto":"none":void 0,...e.style},onFocusCapture:bo(e.onFocusCapture,N.onFocusCapture),onBlurCapture:bo(e.onBlurCapture,N.onBlurCapture),onPointerDownCapture:bo(e.onPointerDownCapture,R.onPointerDownCapture)})});TP.displayName=SQ;var kQ="DismissableLayerBranch",jQ=y.forwardRef((e,t)=>{const n=y.useContext(jP),r=y.useRef(null),s=Ui(t,r);return y.useEffect(()=>{const o=r.current;if(o)return n.branches.add(o),()=>{n.branches.delete(o)}},[n.branches]),i.jsx(Fa.div,{...e,ref:s})});jQ.displayName=kQ;function TQ(e,t=globalThis?.document){const n=ig(e),r=y.useRef(!1),s=y.useRef(()=>{});return y.useEffect(()=>{const o=u=>{if(u.target&&!r.current){let d=function(){NP(CQ,n,f,{discrete:!0})};const f={originalEvent:u};u.pointerType==="touch"?(t.removeEventListener("click",s.current),s.current=d,t.addEventListener("click",s.current,{once:!0})):d()}else t.removeEventListener("click",s.current);r.current=!1},l=window.setTimeout(()=>{t.addEventListener("pointerdown",o)},0);return()=>{window.clearTimeout(l),t.removeEventListener("pointerdown",o),t.removeEventListener("click",s.current)}},[t,n]),{onPointerDownCapture:()=>r.current=!0}}function NQ(e,t=globalThis?.document){const n=ig(e),r=y.useRef(!1);return y.useEffect(()=>{const s=o=>{o.target&&!r.current&&NP(EQ,n,{originalEvent:o},{discrete:!1})};return t.addEventListener("focusin",s),()=>t.removeEventListener("focusin",s)},[t,n]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function DE(){const e=new CustomEvent(hb);document.dispatchEvent(e)}function NP(e,t,n,{discrete:r}){const s=n.originalEvent.target,o=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:n});t&&s.addEventListener(e,t,{once:!0}),r?xQ(s,o):s.dispatchEvent(o)}var Ta=globalThis?.document?y.useLayoutEffect:()=>{},MQ=Yl[" useId ".trim().toString()]||(()=>{}),_Q=0;function RQ(e){const[t,n]=y.useState(MQ());return Ta(()=>{n(r=>r??String(_Q++))},[e]),t?`radix-${t}`:""}var PQ="Arrow",MP=y.forwardRef((e,t)=>{const{children:n,width:r=10,height:s=5,...o}=e;return i.jsx(Fa.svg,{...o,ref:t,width:r,height:s,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:i.jsx("polygon",{points:"0,0 30,0 15,10"})})});MP.displayName=PQ;var OQ=MP;function IQ(e){const[t,n]=y.useState(void 0);return Ta(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(s=>{if(!Array.isArray(s)||!s.length)return;const o=s[0];let l,u;if("borderBoxSize"in o){const d=o.borderBoxSize,f=Array.isArray(d)?d[0]:d;l=f.inlineSize,u=f.blockSize}else l=e.offsetWidth,u=e.offsetHeight;n({width:l,height:u})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else n(void 0)},[e]),t}var zx="Popper",[_P,RP]=EP(zx),[AQ,PP]=_P(zx),OP=e=>{const{__scopePopper:t,children:n}=e,[r,s]=y.useState(null);return i.jsx(AQ,{scope:t,anchor:r,onAnchorChange:s,children:n})};OP.displayName=zx;var IP="PopperAnchor",AP=y.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...s}=e,o=PP(IP,n),l=y.useRef(null),u=Ui(t,l),d=y.useRef(null);return y.useEffect(()=>{const f=d.current;d.current=r?.current||l.current,f!==d.current&&o.onAnchorChange(d.current)}),r?null:i.jsx(Fa.div,{...s,ref:u})});AP.displayName=IP;var Ux="PopperContent",[DQ,FQ]=_P(Ux),DP=y.forwardRef((e,t)=>{const{__scopePopper:n,side:r="bottom",sideOffset:s=0,align:o="center",alignOffset:l=0,arrowPadding:u=0,avoidCollisions:d=!0,collisionBoundary:f=[],collisionPadding:h=0,sticky:m="partial",hideWhenDetached:g=!1,updatePositionStrategy:x="optimized",onPlaced:b,...w}=e,C=PP(Ux,n),[k,j]=y.useState(null),M=Ui(t,Z=>j(Z)),[_,R]=y.useState(null),N=IQ(_),O=N?.width??0,D=N?.height??0,z=r+(o!=="center"?"-"+o:""),Q=typeof h=="number"?h:{top:0,right:0,bottom:0,left:0,...h},pe=Array.isArray(f)?f:[f],V=pe.length>0,G={padding:Q,boundary:pe.filter($Q),altBoundary:V},{refs:W,floatingStyles:ie,placement:re,isPositioned:Y,middlewareData:H}=PT({strategy:"fixed",placement:z,whileElementsMounted:(...Z)=>_T(...Z,{animationFrame:x==="always"}),elements:{reference:C.anchor},middleware:[OT({mainAxis:s+D,alignmentAxis:l}),d&&IT({mainAxis:!0,crossAxis:!1,limiter:m==="partial"?AT():void 0,...G}),d&&DT({...G}),FT({...G,apply:({elements:Z,rects:ye,availableWidth:Re,availableHeight:$e})=>{const{width:Ye,height:Fe}=ye.reference,ft=Z.floating.style;ft.setProperty("--radix-popper-available-width",`${Re}px`),ft.setProperty("--radix-popper-available-height",`${$e}px`),ft.setProperty("--radix-popper-anchor-width",`${Ye}px`),ft.setProperty("--radix-popper-anchor-height",`${Fe}px`)}}),_&&$T({element:_,padding:u}),BQ({arrowWidth:O,arrowHeight:D}),g&<({strategy:"referenceHidden",...G})]}),[q,he]=$P(re),A=ig(b);Ta(()=>{Y&&A?.()},[Y,A]);const F=H.arrow?.x,fe=H.arrow?.y,te=H.arrow?.centerOffset!==0,[de,ge]=y.useState();return Ta(()=>{k&&ge(window.getComputedStyle(k).zIndex)},[k]),i.jsx("div",{ref:W.setFloating,"data-radix-popper-content-wrapper":"",style:{...ie,transform:Y?ie.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:de,"--radix-popper-transform-origin":[H.transformOrigin?.x,H.transformOrigin?.y].join(" "),...H.hide?.referenceHidden&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:i.jsx(DQ,{scope:n,placedSide:q,onArrowChange:R,arrowX:F,arrowY:fe,shouldHideArrow:te,children:i.jsx(Fa.div,{"data-side":q,"data-align":he,...w,ref:M,style:{...w.style,animation:Y?void 0:"none"}})})})});DP.displayName=Ux;var FP="PopperArrow",LQ={top:"bottom",right:"left",bottom:"top",left:"right"},LP=y.forwardRef(function(t,n){const{__scopePopper:r,...s}=t,o=FQ(FP,r),l=LQ[o.placedSide];return i.jsx("span",{ref:o.onArrowChange,style:{position:"absolute",left:o.arrowX,top:o.arrowY,[l]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[o.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[o.placedSide],visibility:o.shouldHideArrow?"hidden":void 0},children:i.jsx(OQ,{...s,ref:n,style:{...s.style,display:"block"}})})});LP.displayName=FP;function $Q(e){return e!==null}var BQ=e=>({name:"transformOrigin",options:e,fn(t){const{placement:n,rects:r,middlewareData:s}=t,l=s.arrow?.centerOffset!==0,u=l?0:e.arrowWidth,d=l?0:e.arrowHeight,[f,h]=$P(n),m={start:"0%",center:"50%",end:"100%"}[h],g=(s.arrow?.x??0)+u/2,x=(s.arrow?.y??0)+d/2;let b="",w="";return f==="bottom"?(b=l?m:`${g}px`,w=`${-d}px`):f==="top"?(b=l?m:`${g}px`,w=`${r.floating.height+d}px`):f==="right"?(b=`${-d}px`,w=l?m:`${x}px`):f==="left"&&(b=`${r.floating.width+d}px`,w=l?m:`${x}px`),{data:{x:b,y:w}}}});function $P(e){const[t,n="center"]=e.split("-");return[t,n]}var zQ=OP,UQ=AP,VQ=DP,HQ=LP,qQ="Portal",BP=y.forwardRef((e,t)=>{const{container:n,...r}=e,[s,o]=y.useState(!1);Ta(()=>o(!0),[]);const l=n||s&&globalThis?.document?.body;return l?Ib.createPortal(i.jsx(Fa.div,{...r,ref:t}),l):null});BP.displayName=qQ;function KQ(e,t){return y.useReducer((n,r)=>t[n][r]??n,e)}var Vx=e=>{const{present:t,children:n}=e,r=WQ(t),s=typeof n=="function"?n({present:r.isPresent}):y.Children.only(n),o=Ui(r.ref,GQ(s));return typeof n=="function"||r.isPresent?y.cloneElement(s,{ref:o}):null};Vx.displayName="Presence";function WQ(e){const[t,n]=y.useState(),r=y.useRef(null),s=y.useRef(e),o=y.useRef("none"),l=e?"mounted":"unmounted",[u,d]=KQ(l,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return y.useEffect(()=>{const f=Xf(r.current);o.current=u==="mounted"?f:"none"},[u]),Ta(()=>{const f=r.current,h=s.current;if(h!==e){const g=o.current,x=Xf(f);e?d("MOUNT"):x==="none"||f?.display==="none"?d("UNMOUNT"):d(h&&g!==x?"ANIMATION_OUT":"UNMOUNT"),s.current=e}},[e,d]),Ta(()=>{if(t){let f;const h=t.ownerDocument.defaultView??window,m=x=>{const w=Xf(r.current).includes(CSS.escape(x.animationName));if(x.target===t&&w&&(d("ANIMATION_END"),!s.current)){const C=t.style.animationFillMode;t.style.animationFillMode="forwards",f=h.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=C)})}},g=x=>{x.target===t&&(o.current=Xf(r.current))};return t.addEventListener("animationstart",g),t.addEventListener("animationcancel",m),t.addEventListener("animationend",m),()=>{h.clearTimeout(f),t.removeEventListener("animationstart",g),t.removeEventListener("animationcancel",m),t.removeEventListener("animationend",m)}}else d("ANIMATION_END")},[t,d]),{isPresent:["mounted","unmountSuspended"].includes(u),ref:y.useCallback(f=>{r.current=f?getComputedStyle(f):null,n(f)},[])}}function Xf(e){return e?.animationName||"none"}function GQ(e){let t=Object.getOwnPropertyDescriptor(e.props,"ref")?.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=Object.getOwnPropertyDescriptor(e,"ref")?.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}var JQ=Yl[" useInsertionEffect ".trim().toString()]||Ta;function QQ({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[s,o,l]=ZQ({defaultProp:t,onChange:n}),u=e!==void 0,d=u?e:s;{const h=y.useRef(e!==void 0);y.useEffect(()=>{const m=h.current;m!==u&&console.warn(`${r} is changing from ${m?"controlled":"uncontrolled"} to ${u?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),h.current=u},[u,r])}const f=y.useCallback(h=>{if(u){const m=YQ(h)?h(e):h;m!==e&&l.current?.(m)}else o(h)},[u,e,o,l]);return[d,f]}function ZQ({defaultProp:e,onChange:t}){const[n,r]=y.useState(e),s=y.useRef(n),o=y.useRef(t);return JQ(()=>{o.current=t},[t]),y.useEffect(()=>{s.current!==n&&(o.current?.(n),s.current=n)},[n,s]),[n,r,o]}function YQ(e){return typeof e=="function"}var XQ=Object.freeze({position:"absolute",border:0,width:1,height:1,padding:0,margin:-1,overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",wordWrap:"normal"}),eZ="VisuallyHidden",zP=y.forwardRef((e,t)=>i.jsx(Fa.span,{...e,ref:t,style:{...XQ,...e.style}}));zP.displayName=eZ;var tZ=zP,[lg]=EP("Tooltip",[RP]),cg=RP(),UP="TooltipProvider",nZ=700,gb="tooltip.open",[rZ,Hx]=lg(UP),VP=e=>{const{__scopeTooltip:t,delayDuration:n=nZ,skipDelayDuration:r=300,disableHoverableContent:s=!1,children:o}=e,l=y.useRef(!0),u=y.useRef(!1),d=y.useRef(0);return y.useEffect(()=>{const f=d.current;return()=>window.clearTimeout(f)},[]),i.jsx(rZ,{scope:t,isOpenDelayedRef:l,delayDuration:n,onOpen:y.useCallback(()=>{window.clearTimeout(d.current),l.current=!1},[]),onClose:y.useCallback(()=>{window.clearTimeout(d.current),d.current=window.setTimeout(()=>l.current=!0,r)},[r]),isPointerInTransitRef:u,onPointerInTransitChange:y.useCallback(f=>{u.current=f},[]),disableHoverableContent:s,children:o})};VP.displayName=UP;var id="Tooltip",[sZ,Nd]=lg(id),HP=e=>{const{__scopeTooltip:t,children:n,open:r,defaultOpen:s,onOpenChange:o,disableHoverableContent:l,delayDuration:u}=e,d=Hx(id,e.__scopeTooltip),f=cg(t),[h,m]=y.useState(null),g=RQ(),x=y.useRef(0),b=l??d.disableHoverableContent,w=u??d.delayDuration,C=y.useRef(!1),[k,j]=QQ({prop:r,defaultProp:s??!1,onChange:O=>{O?(d.onOpen(),document.dispatchEvent(new CustomEvent(gb))):d.onClose(),o?.(O)},caller:id}),M=y.useMemo(()=>k?C.current?"delayed-open":"instant-open":"closed",[k]),_=y.useCallback(()=>{window.clearTimeout(x.current),x.current=0,C.current=!1,j(!0)},[j]),R=y.useCallback(()=>{window.clearTimeout(x.current),x.current=0,j(!1)},[j]),N=y.useCallback(()=>{window.clearTimeout(x.current),x.current=window.setTimeout(()=>{C.current=!0,j(!0),x.current=0},w)},[w,j]);return y.useEffect(()=>()=>{x.current&&(window.clearTimeout(x.current),x.current=0)},[]),i.jsx(zQ,{...f,children:i.jsx(sZ,{scope:t,contentId:g,open:k,stateAttribute:M,trigger:h,onTriggerChange:m,onTriggerEnter:y.useCallback(()=>{d.isOpenDelayedRef.current?N():_()},[d.isOpenDelayedRef,N,_]),onTriggerLeave:y.useCallback(()=>{b?R():(window.clearTimeout(x.current),x.current=0)},[R,b]),onOpen:_,onClose:R,disableHoverableContent:b,children:n})})};HP.displayName=id;var mb="TooltipTrigger",qP=y.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,s=Nd(mb,n),o=Hx(mb,n),l=cg(n),u=y.useRef(null),d=Ui(t,u,s.onTriggerChange),f=y.useRef(!1),h=y.useRef(!1),m=y.useCallback(()=>f.current=!1,[]);return y.useEffect(()=>()=>document.removeEventListener("pointerup",m),[m]),i.jsx(UQ,{asChild:!0,...l,children:i.jsx(Fa.button,{"aria-describedby":s.open?s.contentId:void 0,"data-state":s.stateAttribute,...r,ref:d,onPointerMove:bo(e.onPointerMove,g=>{g.pointerType!=="touch"&&!h.current&&!o.isPointerInTransitRef.current&&(s.onTriggerEnter(),h.current=!0)}),onPointerLeave:bo(e.onPointerLeave,()=>{s.onTriggerLeave(),h.current=!1}),onPointerDown:bo(e.onPointerDown,()=>{s.open&&s.onClose(),f.current=!0,document.addEventListener("pointerup",m,{once:!0})}),onFocus:bo(e.onFocus,()=>{f.current||s.onOpen()}),onBlur:bo(e.onBlur,s.onClose),onClick:bo(e.onClick,s.onClose)})})});qP.displayName=mb;var qx="TooltipPortal",[oZ,aZ]=lg(qx,{forceMount:void 0}),KP=e=>{const{__scopeTooltip:t,forceMount:n,children:r,container:s}=e,o=Nd(qx,t);return i.jsx(oZ,{scope:t,forceMount:n,children:i.jsx(Vx,{present:n||o.open,children:i.jsx(BP,{asChild:!0,container:s,children:r})})})};KP.displayName=qx;var Wl="TooltipContent",WP=y.forwardRef((e,t)=>{const n=aZ(Wl,e.__scopeTooltip),{forceMount:r=n.forceMount,side:s="top",...o}=e,l=Nd(Wl,e.__scopeTooltip);return i.jsx(Vx,{present:r||l.open,children:l.disableHoverableContent?i.jsx(GP,{side:s,...o,ref:t}):i.jsx(iZ,{side:s,...o,ref:t})})}),iZ=y.forwardRef((e,t)=>{const n=Nd(Wl,e.__scopeTooltip),r=Hx(Wl,e.__scopeTooltip),s=y.useRef(null),o=Ui(t,s),[l,u]=y.useState(null),{trigger:d,onClose:f}=n,h=s.current,{onPointerInTransitChange:m}=r,g=y.useCallback(()=>{u(null),m(!1)},[m]),x=y.useCallback((b,w)=>{const C=b.currentTarget,k={x:b.clientX,y:b.clientY},j=dZ(k,C.getBoundingClientRect()),M=fZ(k,j),_=pZ(w.getBoundingClientRect()),R=gZ([...M,..._]);u(R),m(!0)},[m]);return y.useEffect(()=>()=>g(),[g]),y.useEffect(()=>{if(d&&h){const b=C=>x(C,h),w=C=>x(C,d);return d.addEventListener("pointerleave",b),h.addEventListener("pointerleave",w),()=>{d.removeEventListener("pointerleave",b),h.removeEventListener("pointerleave",w)}}},[d,h,x,g]),y.useEffect(()=>{if(l){const b=w=>{const C=w.target,k={x:w.clientX,y:w.clientY},j=d?.contains(C)||h?.contains(C),M=!hZ(k,l);j?g():M&&(g(),f())};return document.addEventListener("pointermove",b),()=>document.removeEventListener("pointermove",b)}},[d,h,l,f,g]),i.jsx(GP,{...e,ref:o})}),[lZ,cZ]=lg(id,{isInside:!1}),uZ=gQ("TooltipContent"),GP=y.forwardRef((e,t)=>{const{__scopeTooltip:n,children:r,"aria-label":s,onEscapeKeyDown:o,onPointerDownOutside:l,...u}=e,d=Nd(Wl,n),f=cg(n),{onClose:h}=d;return y.useEffect(()=>(document.addEventListener(gb,h),()=>document.removeEventListener(gb,h)),[h]),y.useEffect(()=>{if(d.trigger){const m=g=>{g.target?.contains(d.trigger)&&h()};return window.addEventListener("scroll",m,{capture:!0}),()=>window.removeEventListener("scroll",m,{capture:!0})}},[d.trigger,h]),i.jsx(TP,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:o,onPointerDownOutside:l,onFocusOutside:m=>m.preventDefault(),onDismiss:h,children:i.jsxs(VQ,{"data-state":d.stateAttribute,...f,...u,ref:t,style:{...u.style,"--radix-tooltip-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-tooltip-content-available-width":"var(--radix-popper-available-width)","--radix-tooltip-content-available-height":"var(--radix-popper-available-height)","--radix-tooltip-trigger-width":"var(--radix-popper-anchor-width)","--radix-tooltip-trigger-height":"var(--radix-popper-anchor-height)"},children:[i.jsx(uZ,{children:r}),i.jsx(lZ,{scope:n,isInside:!0,children:i.jsx(tZ,{id:d.contentId,role:"tooltip",children:s||r})})]})})});WP.displayName=Wl;var JP="TooltipArrow",QP=y.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,s=cg(n);return cZ(JP,n).isInside?null:i.jsx(HQ,{...s,...r,ref:t})});QP.displayName=JP;function dZ(e,t){const n=Math.abs(t.top-e.y),r=Math.abs(t.bottom-e.y),s=Math.abs(t.right-e.x),o=Math.abs(t.left-e.x);switch(Math.min(n,r,s,o)){case o:return"left";case s:return"right";case n:return"top";case r:return"bottom";default:throw new Error("unreachable")}}function fZ(e,t,n=5){const r=[];switch(t){case"top":r.push({x:e.x-n,y:e.y+n},{x:e.x+n,y:e.y+n});break;case"bottom":r.push({x:e.x-n,y:e.y-n},{x:e.x+n,y:e.y-n});break;case"left":r.push({x:e.x+n,y:e.y-n},{x:e.x+n,y:e.y+n});break;case"right":r.push({x:e.x-n,y:e.y-n},{x:e.x-n,y:e.y+n});break}return r}function pZ(e){const{top:t,right:n,bottom:r,left:s}=e;return[{x:s,y:t},{x:n,y:t},{x:n,y:r},{x:s,y:r}]}function hZ(e,t){const{x:n,y:r}=e;let s=!1;for(let o=0,l=t.length-1;or!=g>r&&n<(m-f)*(r-h)/(g-h)+f&&(s=!s)}return s}function gZ(e){const t=e.slice();return t.sort((n,r)=>n.xr.x?1:n.yr.y?1:0),mZ(t)}function mZ(e){if(e.length<=1)return e.slice();const t=[];for(let r=0;r=2;){const o=t[t.length-1],l=t[t.length-2];if((o.x-l.x)*(s.y-l.y)>=(o.y-l.y)*(s.x-l.x))t.pop();else break}t.push(s)}t.pop();const n=[];for(let r=e.length-1;r>=0;r--){const s=e[r];for(;n.length>=2;){const o=n[n.length-1],l=n[n.length-2];if((o.x-l.x)*(s.y-l.y)>=(o.y-l.y)*(s.x-l.x))n.pop();else break}n.push(s)}return n.pop(),t.length===1&&n.length===1&&t[0].x===n[0].x&&t[0].y===n[0].y?t:t.concat(n)}var vZ=VP,yZ=HP,bZ=qP,xZ=KP,wZ=WP,SZ=QP;function FE({content:e,children:t,side:n="top"}){return i.jsx(vZ,{delayDuration:200,children:i.jsxs(yZ,{children:[i.jsx(bZ,{asChild:!0,children:t}),i.jsx(xZ,{children:i.jsxs(wZ,{side:n,className:` rounded px-3 py-1.5 text-sm z-50 border shadow-lg bg-gray-100 text-gray-900 border-gray-300 dark:bg-gray-800 dark:text-gray-100 dark:border-gray-700 `,children:[e,i.jsx(SZ,{className:"fill-gray-100 dark:fill-gray-800",width:18,height:9})]})})]})})}function CZ(){const{t:e}=Ve(),[t,n]=y.useState(null),{deleteInstance:r,logout:s}=Hh(),{data:o,refetch:l}=q5(),[u,d]=y.useState([]),[f,h]=y.useState("all"),[m,g]=y.useState(""),x=async()=>{await l()},b=async k=>{n(null),d([...u,k]);try{try{await s(k)}catch(j){console.error("Error logout:",j)}await r(k),await new Promise(j=>setTimeout(j,1e3)),x()}catch(j){console.error("Error instance delete:",j),me.error(`Error : ${j?.response?.data?.response?.message}`)}finally{d(u.filter(j=>j!==k))}},w=y.useMemo(()=>{let k=o?[...o]:[];return f!=="all"&&(k=k.filter(j=>j.connectionStatus===f)),m!==""&&(k=k.filter(j=>j.name.toLowerCase().includes(m.toLowerCase()))),k},[o,m,f]),C=[{value:"all",label:e("status.all")},{value:"close",label:e("status.closed")},{value:"connecting",label:e("status.connecting")},{value:"open",label:e("status.open")}];return i.jsxs("div",{className:"my-4 px-4",children:[i.jsxs("div",{className:"flex w-full items-center justify-between",children:[i.jsx("h2",{className:"text-lg",children:e("dashboard.title")}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx(se,{variant:"outline",size:"icon",children:i.jsx(Ip,{onClick:x,size:"20"})}),i.jsx(dQ,{resetTable:x})]})]}),i.jsxs("div",{className:"my-4 flex items-center justify-between gap-3 px-4",children:[i.jsx("div",{className:"flex-1",children:i.jsx(ne,{placeholder:e("dashboard.search"),value:m,onChange:k=>g(k.target.value)})}),i.jsxs(Kr,{children:[i.jsx(Wr,{asChild:!0,children:i.jsxs(se,{variant:"secondary",children:[e("dashboard.status")," ",i.jsx(J$,{size:"15"})]})}),i.jsx(hr,{children:C.map(k=>i.jsx(aM,{checked:f===k.value,onCheckedChange:j=>{j&&h(k.value)},children:k.label},k.value))})]})]}),i.jsx("main",{className:"grid gap-6 sm:grid-cols-2 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4",children:w.length>0&&Array.isArray(w)?w.map(k=>i.jsxs(So,{children:[i.jsx(Co,{children:i.jsxs(Fu,{to:`/manager/instance/${k.id}/dashboard`,className:"flex w-full flex-row items-center justify-between gap-4",children:[i.jsx(FE,{content:k.name,side:"top",children:i.jsx("h3",{className:"text-wrap font-semibold truncate",children:k.name})}),i.jsx(FE,{content:e("dashboard.settings"),side:"top",children:i.jsx(se,{variant:"ghost",size:"icon",children:i.jsx(Oo,{className:"card-icon",size:"20"})})})]})}),i.jsxs(Eo,{className:"flex-1 space-y-6",children:[i.jsx(c_,{token:k.token}),i.jsxs("div",{className:"flex w-full flex-wrap",children:[i.jsx("div",{className:"flex flex-1 gap-2",children:k.profileName&&i.jsxs(i.Fragment,{children:[i.jsx(Ei,{children:i.jsx(ki,{src:k.profilePicUrl,alt:""})}),i.jsxs("div",{className:"space-y-1",children:[i.jsx("strong",{children:k.profileName}),i.jsx("p",{className:"text-sm text-muted-foreground",children:k.ownerJid&&k.ownerJid.split("@")[0]})]})]})}),i.jsxs("div",{className:"flex items-center justify-end gap-4 text-sm",children:[i.jsxs("div",{className:"flex flex-col items-center justify-center gap-1",children:[i.jsx(pT,{className:"text-muted-foreground",size:"20"}),i.jsx("span",{children:new Intl.NumberFormat("pt-BR").format(k?._count?.Contact||0)})]}),i.jsxs("div",{className:"flex flex-col items-center justify-center gap-1",children:[i.jsx(Bl,{className:"text-muted-foreground",size:"20"}),i.jsx("span",{children:new Intl.NumberFormat("pt-BR").format(k?._count?.Message||0)})]})]})]})]}),i.jsxs(Vh,{className:"justify-between",children:[i.jsx(l_,{status:k.connectionStatus}),i.jsx(se,{variant:"destructive",size:"sm",onClick:()=>n(k.name),disabled:u.includes(k.name),children:u.includes(k.name)?i.jsx("span",{children:e("button.deleting")}):i.jsx("span",{children:e("button.delete")})})]})]},k.id)):i.jsx("p",{children:e("dashboard.instancesNotFound")})}),!!t&&i.jsx(Pt,{onOpenChange:()=>n(null),open:!0,children:i.jsxs(Nt,{children:[i.jsx($M,{}),i.jsx(Mt,{children:e("modal.delete.title")}),i.jsx("p",{children:e("modal.delete.message",{instanceName:t})}),i.jsx(Yt,{children:i.jsxs("div",{className:"flex items-center gap-4",children:[i.jsx(se,{onClick:()=>n(null),size:"sm",variant:"outline",children:e("button.cancel")}),i.jsx(se,{onClick:()=>b(t),variant:"destructive",children:e("button.delete")})]})})]})})]})}const{createElement:Gl,createContext:EZ,forwardRef:ZP,useCallback:Fr,useContext:YP,useEffect:vi,useImperativeHandle:XP,useLayoutEffect:kZ,useMemo:jZ,useRef:kr,useState:Mu}=Yl,LE=Yl.useId,TZ=kZ,ug=EZ(null);ug.displayName="PanelGroupContext";const yi=TZ,NZ=typeof LE=="function"?LE:()=>null;let MZ=0;function Kx(e=null){const t=NZ(),n=kr(e||t||null);return n.current===null&&(n.current=""+MZ++),e??n.current}function eO({children:e,className:t="",collapsedSize:n,collapsible:r,defaultSize:s,forwardedRef:o,id:l,maxSize:u,minSize:d,onCollapse:f,onExpand:h,onResize:m,order:g,style:x,tagName:b="div",...w}){const C=YP(ug);if(C===null)throw Error("Panel components must be rendered within a PanelGroup container");const{collapsePanel:k,expandPanel:j,getPanelSize:M,getPanelStyle:_,groupId:R,isPanelCollapsed:N,reevaluatePanelConstraints:O,registerPanel:D,resizePanel:z,unregisterPanel:Q}=C,pe=Kx(l),V=kr({callbacks:{onCollapse:f,onExpand:h,onResize:m},constraints:{collapsedSize:n,collapsible:r,defaultSize:s,maxSize:u,minSize:d},id:pe,idIsFromProps:l!==void 0,order:g});kr({didLogMissingDefaultSizeWarning:!1}),yi(()=>{const{callbacks:W,constraints:ie}=V.current,re={...ie};V.current.id=pe,V.current.idIsFromProps=l!==void 0,V.current.order=g,W.onCollapse=f,W.onExpand=h,W.onResize=m,ie.collapsedSize=n,ie.collapsible=r,ie.defaultSize=s,ie.maxSize=u,ie.minSize=d,(re.collapsedSize!==ie.collapsedSize||re.collapsible!==ie.collapsible||re.maxSize!==ie.maxSize||re.minSize!==ie.minSize)&&O(V.current,re)}),yi(()=>{const W=V.current;return D(W),()=>{Q(W)}},[g,pe,D,Q]),XP(o,()=>({collapse:()=>{k(V.current)},expand:W=>{j(V.current,W)},getId(){return pe},getSize(){return M(V.current)},isCollapsed(){return N(V.current)},isExpanded(){return!N(V.current)},resize:W=>{z(V.current,W)}}),[k,j,M,N,pe,z]);const G=_(V.current,s);return Gl(b,{...w,children:e,className:t,id:l,style:{...G,...x},"data-panel":"","data-panel-collapsible":r||void 0,"data-panel-group-id":R,"data-panel-id":pe,"data-panel-size":parseFloat(""+G.flexGrow).toFixed(1)})}const tO=ZP((e,t)=>Gl(eO,{...e,forwardedRef:t}));eO.displayName="Panel";tO.displayName="forwardRef(Panel)";let vb=null,di=null;function _Z(e,t){if(t){const n=(t&aO)!==0,r=(t&iO)!==0,s=(t&lO)!==0,o=(t&cO)!==0;if(n)return s?"se-resize":o?"ne-resize":"e-resize";if(r)return s?"sw-resize":o?"nw-resize":"w-resize";if(s)return"s-resize";if(o)return"n-resize"}switch(e){case"horizontal":return"ew-resize";case"intersection":return"move";case"vertical":return"ns-resize"}}function RZ(){di!==null&&(document.head.removeChild(di),vb=null,di=null)}function Wv(e,t){const n=_Z(e,t);vb!==n&&(vb=n,di===null&&(di=document.createElement("style"),document.head.appendChild(di)),di.innerHTML=`*{cursor: ${n}!important;}`)}function nO(e){return e.type==="keydown"}function rO(e){return e.type.startsWith("pointer")}function sO(e){return e.type.startsWith("mouse")}function dg(e){if(rO(e)){if(e.isPrimary)return{x:e.clientX,y:e.clientY}}else if(sO(e))return{x:e.clientX,y:e.clientY};return{x:1/0,y:1/0}}function PZ(){if(typeof matchMedia=="function")return matchMedia("(pointer:coarse)").matches?"coarse":"fine"}function OZ(e,t,n){return e.xt.x&&e.yt.y}function IZ(e,t){if(e===t)throw new Error("Cannot compare node with itself");const n={a:zE(e),b:zE(t)};let r;for(;n.a.at(-1)===n.b.at(-1);)e=n.a.pop(),t=n.b.pop(),r=e;kt(r,"Stacking order can only be calculated for elements with a common ancestor");const s={a:BE($E(n.a)),b:BE($E(n.b))};if(s.a===s.b){const o=r.childNodes,l={a:n.a.at(-1),b:n.b.at(-1)};let u=o.length;for(;u--;){const d=o[u];if(d===l.a)return 1;if(d===l.b)return-1}}return Math.sign(s.a-s.b)}const AZ=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function DZ(e){var t;const n=getComputedStyle((t=oO(e))!==null&&t!==void 0?t:e).display;return n==="flex"||n==="inline-flex"}function FZ(e){const t=getComputedStyle(e);return!!(t.position==="fixed"||t.zIndex!=="auto"&&(t.position!=="static"||DZ(e))||+t.opacity<1||"transform"in t&&t.transform!=="none"||"webkitTransform"in t&&t.webkitTransform!=="none"||"mixBlendMode"in t&&t.mixBlendMode!=="normal"||"filter"in t&&t.filter!=="none"||"webkitFilter"in t&&t.webkitFilter!=="none"||"isolation"in t&&t.isolation==="isolate"||AZ.test(t.willChange)||t.webkitOverflowScrolling==="touch")}function $E(e){let t=e.length;for(;t--;){const n=e[t];if(kt(n,"Missing node"),FZ(n))return n}return null}function BE(e){return e&&Number(getComputedStyle(e).zIndex)||0}function zE(e){const t=[];for(;e;)t.push(e),e=oO(e);return t}function oO(e){const{parentNode:t}=e;return t&&t instanceof ShadowRoot?t.host:t}const aO=1,iO=2,lO=4,cO=8,LZ=PZ()==="coarse";let js=[],ld=!1,ha=new Map,fg=new Map;const cd=new Set;function $Z(e,t,n,r,s){var o;const{ownerDocument:l}=t,u={direction:n,element:t,hitAreaMargins:r,setResizeHandlerState:s},d=(o=ha.get(l))!==null&&o!==void 0?o:0;return ha.set(l,d+1),cd.add(u),lh(),function(){var h;fg.delete(e),cd.delete(u);const m=(h=ha.get(l))!==null&&h!==void 0?h:1;if(ha.set(l,m-1),lh(),m===1&&ha.delete(l),js.includes(u)){const g=js.indexOf(u);g>=0&&js.splice(g,1),Gx()}}}function UE(e){const{target:t}=e,{x:n,y:r}=dg(e);ld=!0,Wx({target:t,x:n,y:r}),lh(),js.length>0&&(ch("down",e),e.preventDefault(),e.stopPropagation())}function du(e){const{x:t,y:n}=dg(e);if(e.buttons===0&&(ld=!1,ch("up",e)),!ld){const{target:r}=e;Wx({target:r,x:t,y:n})}ch("move",e),Gx(),js.length>0&&e.preventDefault()}function bl(e){const{target:t}=e,{x:n,y:r}=dg(e);fg.clear(),ld=!1,js.length>0&&e.preventDefault(),ch("up",e),Wx({target:t,x:n,y:r}),Gx(),lh()}function Wx({target:e,x:t,y:n}){js.splice(0);let r=null;e instanceof HTMLElement&&(r=e),cd.forEach(s=>{const{element:o,hitAreaMargins:l}=s,u=o.getBoundingClientRect(),{bottom:d,left:f,right:h,top:m}=u,g=LZ?l.coarse:l.fine;if(t>=f-g&&t<=h+g&&n>=m-g&&n<=d+g){if(r!==null&&o!==r&&!o.contains(r)&&!r.contains(o)&&IZ(r,o)>0){let b=r,w=!1;for(;b&&!b.contains(o);){if(OZ(b.getBoundingClientRect(),u)){w=!0;break}b=b.parentElement}if(w)return}js.push(s)}})}function Gv(e,t){fg.set(e,t)}function Gx(){let e=!1,t=!1;js.forEach(r=>{const{direction:s}=r;s==="horizontal"?e=!0:t=!0});let n=0;fg.forEach(r=>{n|=r}),e&&t?Wv("intersection",n):e?Wv("horizontal",n):t?Wv("vertical",n):RZ()}function lh(){ha.forEach((e,t)=>{const{body:n}=t;n.removeEventListener("contextmenu",bl),n.removeEventListener("pointerdown",UE),n.removeEventListener("pointerleave",du),n.removeEventListener("pointermove",du)}),window.removeEventListener("pointerup",bl),window.removeEventListener("pointercancel",bl),cd.size>0&&(ld?(js.length>0&&ha.forEach((e,t)=>{const{body:n}=t;e>0&&(n.addEventListener("contextmenu",bl),n.addEventListener("pointerleave",du),n.addEventListener("pointermove",du))}),window.addEventListener("pointerup",bl),window.addEventListener("pointercancel",bl)):ha.forEach((e,t)=>{const{body:n}=t;e>0&&(n.addEventListener("pointerdown",UE,{capture:!0}),n.addEventListener("pointermove",du))}))}function ch(e,t){cd.forEach(n=>{const{setResizeHandlerState:r}=n,s=js.includes(n);r(e,s,t)})}function kt(e,t){if(!e)throw console.error(t),Error(t)}const Jx=10;function Ri(e,t,n=Jx){return e.toFixed(n)===t.toFixed(n)?0:e>t?1:-1}function xo(e,t,n=Jx){return Ri(e,t,n)===0}function $r(e,t,n){return Ri(e,t,n)===0}function BZ(e,t,n){if(e.length!==t.length)return!1;for(let r=0;r0&&(e=e<0?0-k:k)}}}{const m=e<0?u:d,g=n[m];kt(g,`No panel constraints found for index ${m}`);const{collapsedSize:x=0,collapsible:b,minSize:w=0}=g;if(b){const C=t[m];if(kt(C!=null,`Previous layout not found for panel index ${m}`),$r(C,w)){const k=C-x;Ri(k,Math.abs(e))>0&&(e=e<0?0-k:k)}}}}{const m=e<0?1:-1;let g=e<0?d:u,x=0;for(;;){const w=t[g];kt(w!=null,`Previous layout not found for panel index ${g}`);const k=Ml({panelConstraints:n,panelIndex:g,size:100})-w;if(x+=k,g+=m,g<0||g>=n.length)break}const b=Math.min(Math.abs(e),Math.abs(x));e=e<0?0-b:b}{let g=e<0?u:d;for(;g>=0&&g=0))break;e<0?g--:g++}}if(BZ(s,l))return s;{const m=e<0?d:u,g=t[m];kt(g!=null,`Previous layout not found for panel index ${m}`);const x=g+f,b=Ml({panelConstraints:n,panelIndex:m,size:x});if(l[m]=b,!$r(b,x)){let w=x-b,k=e<0?d:u;for(;k>=0&&k0?k--:k++}}}const h=l.reduce((m,g)=>g+m,0);return $r(h,100)?l:s}function zZ({layout:e,panelsArray:t,pivotIndices:n}){let r=0,s=100,o=0,l=0;const u=n[0];kt(u!=null,"No pivot index found"),t.forEach((m,g)=>{const{constraints:x}=m,{maxSize:b=100,minSize:w=0}=x;g===u?(r=w,s=b):(o+=w,l+=b)});const d=Math.min(s,100-o),f=Math.max(r,100-l),h=e[u];return{valueMax:d,valueMin:f,valueNow:h}}function ud(e,t=document){return Array.from(t.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${e}"]`))}function uO(e,t,n=document){const s=ud(e,n).findIndex(o=>o.getAttribute("data-panel-resize-handle-id")===t);return s??null}function dO(e,t,n){const r=uO(e,t,n);return r!=null?[r,r+1]:[-1,-1]}function fO(e,t=document){var n;if(t instanceof HTMLElement&&(t==null||(n=t.dataset)===null||n===void 0?void 0:n.panelGroupId)==e)return t;const r=t.querySelector(`[data-panel-group][data-panel-group-id="${e}"]`);return r||null}function pg(e,t=document){const n=t.querySelector(`[data-panel-resize-handle-id="${e}"]`);return n||null}function UZ(e,t,n,r=document){var s,o,l,u;const d=pg(t,r),f=ud(e,r),h=d?f.indexOf(d):-1,m=(s=(o=n[h])===null||o===void 0?void 0:o.id)!==null&&s!==void 0?s:null,g=(l=(u=n[h+1])===null||u===void 0?void 0:u.id)!==null&&l!==void 0?l:null;return[m,g]}function VZ({committedValuesRef:e,eagerValuesRef:t,groupId:n,layout:r,panelDataArray:s,panelGroupElement:o,setLayout:l}){kr({didWarnAboutMissingResizeHandle:!1}),yi(()=>{if(!o)return;const u=ud(n,o);for(let d=0;d{u.forEach((d,f)=>{d.removeAttribute("aria-controls"),d.removeAttribute("aria-valuemax"),d.removeAttribute("aria-valuemin"),d.removeAttribute("aria-valuenow")})}},[n,r,s,o]),vi(()=>{if(!o)return;const u=t.current;kt(u,"Eager values not found");const{panelDataArray:d}=u,f=fO(n,o);kt(f!=null,`No group found for id "${n}"`);const h=ud(n,o);kt(h,`No resize handles found for group id "${n}"`);const m=h.map(g=>{const x=g.getAttribute("data-panel-resize-handle-id");kt(x,"Resize handle element has no handle id attribute");const[b,w]=UZ(n,x,d,o);if(b==null||w==null)return()=>{};const C=k=>{if(!k.defaultPrevented)switch(k.key){case"Enter":{k.preventDefault();const j=d.findIndex(M=>M.id===b);if(j>=0){const M=d[j];kt(M,`No panel data found for index ${j}`);const _=r[j],{collapsedSize:R=0,collapsible:N,minSize:O=0}=M.constraints;if(_!=null&&N){const D=wu({delta:$r(_,R)?O-R:R-_,initialLayout:r,panelConstraints:d.map(z=>z.constraints),pivotIndices:dO(n,x,o),prevLayout:r,trigger:"keyboard"});r!==D&&l(D)}}break}}};return g.addEventListener("keydown",C),()=>{g.removeEventListener("keydown",C)}});return()=>{m.forEach(g=>g())}},[o,e,t,n,r,s,l])}function VE(e,t){if(e.length!==t.length)return!1;for(let n=0;no.constraints);let r=0,s=100;for(let o=0;o{const o=e[s];kt(o,`Panel data not found for index ${s}`);const{callbacks:l,constraints:u,id:d}=o,{collapsedSize:f=0,collapsible:h}=u,m=n[d];if(m==null||r!==m){n[d]=r;const{onCollapse:g,onExpand:x,onResize:b}=l;b&&b(r,m),h&&(g||x)&&(x&&(m==null||xo(m,f))&&!xo(r,f)&&x(),g&&(m==null||!xo(m,f))&&xo(r,f)&&g())}})}function ep(e,t){if(e.length!==t.length)return!1;for(let n=0;n{n!==null&&clearTimeout(n),n=setTimeout(()=>{e(...s)},t)}}function HE(e){try{if(typeof localStorage<"u")e.getItem=t=>localStorage.getItem(t),e.setItem=(t,n)=>{localStorage.setItem(t,n)};else throw new Error("localStorage not supported in this environment")}catch(t){console.error(t),e.getItem=()=>null,e.setItem=()=>{}}}function hO(e){return`react-resizable-panels:${e}`}function gO(e){return e.map(t=>{const{constraints:n,id:r,idIsFromProps:s,order:o}=t;return s?r:o?`${o}:${JSON.stringify(n)}`:JSON.stringify(n)}).sort((t,n)=>t.localeCompare(n)).join(",")}function mO(e,t){try{const n=hO(e),r=t.getItem(n);if(r){const s=JSON.parse(r);if(typeof s=="object"&&s!=null)return s}}catch{}return null}function JZ(e,t,n){var r,s;const o=(r=mO(e,n))!==null&&r!==void 0?r:{},l=gO(t);return(s=o[l])!==null&&s!==void 0?s:null}function QZ(e,t,n,r,s){var o;const l=hO(e),u=gO(t),d=(o=mO(e,s))!==null&&o!==void 0?o:{};d[u]={expandToSizes:Object.fromEntries(n.entries()),layout:r};try{s.setItem(l,JSON.stringify(d))}catch(f){console.error(f)}}function qE({layout:e,panelConstraints:t}){const n=[...e],r=n.reduce((o,l)=>o+l,0);if(n.length!==t.length)throw Error(`Invalid ${t.length} panel layout: ${n.map(o=>`${o}%`).join(", ")}`);if(!$r(r,100))for(let o=0;o(HE(Su),Su.getItem(e)),setItem:(e,t)=>{HE(Su),Su.setItem(e,t)}},KE={};function vO({autoSaveId:e=null,children:t,className:n="",direction:r,forwardedRef:s,id:o=null,onLayout:l=null,keyboardResizeBy:u=null,storage:d=Su,style:f,tagName:h="div",...m}){const g=Kx(o),x=kr(null),[b,w]=Mu(null),[C,k]=Mu([]),j=kr({}),M=kr(new Map),_=kr(0),R=kr({autoSaveId:e,direction:r,dragState:b,id:g,keyboardResizeBy:u,onLayout:l,storage:d}),N=kr({layout:C,panelDataArray:[],panelDataArrayChanged:!1});kr({didLogIdAndOrderWarning:!1,didLogPanelConstraintsWarning:!1,prevPanelIds:[]}),XP(s,()=>({getId:()=>R.current.id,getLayout:()=>{const{layout:F}=N.current;return F},setLayout:F=>{const{onLayout:fe}=R.current,{layout:te,panelDataArray:de}=N.current,ge=qE({layout:F,panelConstraints:de.map(Z=>Z.constraints)});VE(te,ge)||(k(ge),N.current.layout=ge,fe&&fe(ge),xl(de,ge,j.current))}}),[]),yi(()=>{R.current.autoSaveId=e,R.current.direction=r,R.current.dragState=b,R.current.id=g,R.current.onLayout=l,R.current.storage=d}),VZ({committedValuesRef:R,eagerValuesRef:N,groupId:g,layout:C,panelDataArray:N.current.panelDataArray,setLayout:k,panelGroupElement:x.current}),vi(()=>{const{panelDataArray:F}=N.current;if(e){if(C.length===0||C.length!==F.length)return;let fe=KE[e];fe==null&&(fe=GZ(QZ,ZZ),KE[e]=fe);const te=[...F],de=new Map(M.current);fe(e,te,de,C,d)}},[e,C,d]),vi(()=>{});const O=Fr(F=>{const{onLayout:fe}=R.current,{layout:te,panelDataArray:de}=N.current;if(F.constraints.collapsible){const ge=de.map($e=>$e.constraints),{collapsedSize:Z=0,panelSize:ye,pivotIndices:Re}=ri(de,F,te);if(kt(ye!=null,`Panel size not found for panel "${F.id}"`),!xo(ye,Z)){M.current.set(F.id,ye);const Ye=kl(de,F)===de.length-1?ye-Z:Z-ye,Fe=wu({delta:Ye,initialLayout:te,panelConstraints:ge,pivotIndices:Re,prevLayout:te,trigger:"imperative-api"});ep(te,Fe)||(k(Fe),N.current.layout=Fe,fe&&fe(Fe),xl(de,Fe,j.current))}}},[]),D=Fr((F,fe)=>{const{onLayout:te}=R.current,{layout:de,panelDataArray:ge}=N.current;if(F.constraints.collapsible){const Z=ge.map(ft=>ft.constraints),{collapsedSize:ye=0,panelSize:Re=0,minSize:$e=0,pivotIndices:Ye}=ri(ge,F,de),Fe=fe??$e;if(xo(Re,ye)){const ft=M.current.get(F.id),ln=ft!=null&&ft>=Fe?ft:Fe,vn=kl(ge,F)===ge.length-1?Re-ln:ln-Re,Cn=wu({delta:vn,initialLayout:de,panelConstraints:Z,pivotIndices:Ye,prevLayout:de,trigger:"imperative-api"});ep(de,Cn)||(k(Cn),N.current.layout=Cn,te&&te(Cn),xl(ge,Cn,j.current))}}},[]),z=Fr(F=>{const{layout:fe,panelDataArray:te}=N.current,{panelSize:de}=ri(te,F,fe);return kt(de!=null,`Panel size not found for panel "${F.id}"`),de},[]),Q=Fr((F,fe)=>{const{panelDataArray:te}=N.current,de=kl(te,F);return WZ({defaultSize:fe,dragState:b,layout:C,panelData:te,panelIndex:de})},[b,C]),pe=Fr(F=>{const{layout:fe,panelDataArray:te}=N.current,{collapsedSize:de=0,collapsible:ge,panelSize:Z}=ri(te,F,fe);return kt(Z!=null,`Panel size not found for panel "${F.id}"`),ge===!0&&xo(Z,de)},[]),V=Fr(F=>{const{layout:fe,panelDataArray:te}=N.current,{collapsedSize:de=0,collapsible:ge,panelSize:Z}=ri(te,F,fe);return kt(Z!=null,`Panel size not found for panel "${F.id}"`),!ge||Ri(Z,de)>0},[]),G=Fr(F=>{const{panelDataArray:fe}=N.current;fe.push(F),fe.sort((te,de)=>{const ge=te.order,Z=de.order;return ge==null&&Z==null?0:ge==null?-1:Z==null?1:ge-Z}),N.current.panelDataArrayChanged=!0},[]);yi(()=>{if(N.current.panelDataArrayChanged){N.current.panelDataArrayChanged=!1;const{autoSaveId:F,onLayout:fe,storage:te}=R.current,{layout:de,panelDataArray:ge}=N.current;let Z=null;if(F){const Re=JZ(F,ge,te);Re&&(M.current=new Map(Object.entries(Re.expandToSizes)),Z=Re.layout)}Z==null&&(Z=KZ({panelDataArray:ge}));const ye=qE({layout:Z,panelConstraints:ge.map(Re=>Re.constraints)});VE(de,ye)||(k(ye),N.current.layout=ye,fe&&fe(ye),xl(ge,ye,j.current))}}),yi(()=>{const F=N.current;return()=>{F.layout=[]}},[]);const W=Fr(F=>function(te){te.preventDefault();const de=x.current;if(!de)return()=>null;const{direction:ge,dragState:Z,id:ye,keyboardResizeBy:Re,onLayout:$e}=R.current,{layout:Ye,panelDataArray:Fe}=N.current,{initialLayout:ft}=Z??{},ln=dO(ye,F,de);let Sn=qZ(te,F,ge,Z,Re,de);const vn=ge==="horizontal";document.dir==="rtl"&&vn&&(Sn=-Sn);const Cn=Fe.map(ue=>ue.constraints),L=wu({delta:Sn,initialLayout:ft??Ye,panelConstraints:Cn,pivotIndices:ln,prevLayout:Ye,trigger:nO(te)?"keyboard":"mouse-or-touch"}),X=!ep(Ye,L);(rO(te)||sO(te))&&_.current!=Sn&&(_.current=Sn,X?Gv(F,0):vn?Gv(F,Sn<0?aO:iO):Gv(F,Sn<0?lO:cO)),X&&(k(L),N.current.layout=L,$e&&$e(L),xl(Fe,L,j.current))},[]),ie=Fr((F,fe)=>{const{onLayout:te}=R.current,{layout:de,panelDataArray:ge}=N.current,Z=ge.map(ft=>ft.constraints),{panelSize:ye,pivotIndices:Re}=ri(ge,F,de);kt(ye!=null,`Panel size not found for panel "${F.id}"`);const Ye=kl(ge,F)===ge.length-1?ye-fe:fe-ye,Fe=wu({delta:Ye,initialLayout:de,panelConstraints:Z,pivotIndices:Re,prevLayout:de,trigger:"imperative-api"});ep(de,Fe)||(k(Fe),N.current.layout=Fe,te&&te(Fe),xl(ge,Fe,j.current))},[]),re=Fr((F,fe)=>{const{layout:te,panelDataArray:de}=N.current,{collapsedSize:ge=0,collapsible:Z}=fe,{collapsedSize:ye=0,collapsible:Re,maxSize:$e=100,minSize:Ye=0}=F.constraints,{panelSize:Fe}=ri(de,F,te);Fe!=null&&(Z&&Re&&xo(Fe,ge)?xo(ge,ye)||ie(F,ye):Fe$e&&ie(F,$e))},[ie]),Y=Fr((F,fe)=>{const{direction:te}=R.current,{layout:de}=N.current;if(!x.current)return;const ge=pg(F,x.current);kt(ge,`Drag handle element not found for id "${F}"`);const Z=pO(te,fe);w({dragHandleId:F,dragHandleRect:ge.getBoundingClientRect(),initialCursorPosition:Z,initialLayout:de})},[]),H=Fr(()=>{w(null)},[]),q=Fr(F=>{const{panelDataArray:fe}=N.current,te=kl(fe,F);te>=0&&(fe.splice(te,1),delete j.current[F.id],N.current.panelDataArrayChanged=!0)},[]),he=jZ(()=>({collapsePanel:O,direction:r,dragState:b,expandPanel:D,getPanelSize:z,getPanelStyle:Q,groupId:g,isPanelCollapsed:pe,isPanelExpanded:V,reevaluatePanelConstraints:re,registerPanel:G,registerResizeHandle:W,resizePanel:ie,startDragging:Y,stopDragging:H,unregisterPanel:q,panelGroupElement:x.current}),[O,b,r,D,z,Q,g,pe,V,re,G,W,ie,Y,H,q]),A={display:"flex",flexDirection:r==="horizontal"?"row":"column",height:"100%",overflow:"hidden",width:"100%"};return Gl(ug.Provider,{value:he},Gl(h,{...m,children:t,className:n,id:o,ref:x,style:{...A,...f},"data-panel-group":"","data-panel-group-direction":r,"data-panel-group-id":g}))}const yO=ZP((e,t)=>Gl(vO,{...e,forwardedRef:t}));vO.displayName="PanelGroup";yO.displayName="forwardRef(PanelGroup)";function kl(e,t){return e.findIndex(n=>n===t||n.id===t.id)}function ri(e,t,n){const r=kl(e,t),o=r===e.length-1?[r-1,r]:[r,r+1],l=n[r];return{...t.constraints,panelSize:l,pivotIndices:o}}function YZ({disabled:e,handleId:t,resizeHandler:n,panelGroupElement:r}){vi(()=>{if(e||n==null||r==null)return;const s=pg(t,r);if(s==null)return;const o=l=>{if(!l.defaultPrevented)switch(l.key){case"ArrowDown":case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"End":case"Home":{l.preventDefault(),n(l);break}case"F6":{l.preventDefault();const u=s.getAttribute("data-panel-group-id");kt(u,`No group element found for id "${u}"`);const d=ud(u,r),f=uO(u,t,r);kt(f!==null,`No resize element found for id "${t}"`);const h=l.shiftKey?f>0?f-1:d.length-1:f+1{s.removeEventListener("keydown",o)}},[r,e,t,n])}function bO({children:e=null,className:t="",disabled:n=!1,hitAreaMargins:r,id:s,onBlur:o,onDragging:l,onFocus:u,style:d={},tabIndex:f=0,tagName:h="div",...m}){var g,x;const b=kr(null),w=kr({onDragging:l});vi(()=>{w.current.onDragging=l});const C=YP(ug);if(C===null)throw Error("PanelResizeHandle components must be rendered within a PanelGroup container");const{direction:k,groupId:j,registerResizeHandle:M,startDragging:_,stopDragging:R,panelGroupElement:N}=C,O=Kx(s),[D,z]=Mu("inactive"),[Q,pe]=Mu(!1),[V,G]=Mu(null),W=kr({state:D});yi(()=>{W.current.state=D}),vi(()=>{if(n)G(null);else{const H=M(O);G(()=>H)}},[n,O,M]);const ie=(g=r?.coarse)!==null&&g!==void 0?g:15,re=(x=r?.fine)!==null&&x!==void 0?x:5;return vi(()=>{if(n||V==null)return;const H=b.current;return kt(H,"Element ref not attached"),$Z(O,H,k,{coarse:ie,fine:re},(he,A,F)=>{if(A)switch(he){case"down":{z("drag"),_(O,F);const{onDragging:fe}=w.current;fe&&fe(!0);break}case"move":{const{state:fe}=W.current;fe!=="drag"&&z("hover"),V(F);break}case"up":{z("hover"),R();const{onDragging:fe}=w.current;fe&&fe(!1);break}}else z("inactive")})},[ie,k,n,re,M,O,V,_,R]),YZ({disabled:n,handleId:O,resizeHandler:V,panelGroupElement:N}),Gl(h,{...m,children:e,className:t,id:s,onBlur:()=>{pe(!1),o?.()},onFocus:()=>{pe(!0),u?.()},ref:b,role:"separator",style:{...{touchAction:"none",userSelect:"none"},...d},tabIndex:f,"data-panel-group-direction":k,"data-panel-group-id":j,"data-resize-handle":"","data-resize-handle-active":D==="drag"?"pointer":Q?"keyboard":void 0,"data-resize-handle-state":D,"data-panel-resize-handle-enabled":!n,"data-panel-resize-handle-id":O})}bO.displayName="PanelResizeHandle";const $o=({className:e,...t})=>i.jsx(yO,{className:Ie("flex h-full w-full data-[panel-group-direction=vertical]:flex-col",e),...t}),Hn=tO,Bo=({withHandle:e,className:t,...n})=>i.jsx(bO,{className:Ie("relative flex w-px items-center justify-center bg-border after:absolute after:inset-y-0 after:left-1/2 after:w-1 after:-translate-x-1/2 after:bg-border focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-1 data-[panel-group-direction=vertical]:h-px data-[panel-group-direction=vertical]:w-full data-[panel-group-direction=vertical]:after:left-0 data-[panel-group-direction=vertical]:after:h-1 data-[panel-group-direction=vertical]:after:w-full data-[panel-group-direction=vertical]:after:-translate-y-1/2 data-[panel-group-direction=vertical]:after:translate-x-0 [&[data-panel-group-direction=vertical]>div]:rotate-90",t),...n,children:e&&i.jsx("div",{className:"z-10 flex h-4 w-3 items-center justify-center rounded-sm border bg-border",children:i.jsx(lB,{className:"h-2.5 w-2.5"})})});var Qx="Tabs",[XZ]=us(Qx,[Dh]),xO=Dh(),[eY,Zx]=XZ(Qx),wO=y.forwardRef((e,t)=>{const{__scopeTabs:n,value:r,onValueChange:s,defaultValue:o,orientation:l="horizontal",dir:u,activationMode:d="automatic",...f}=e,h=xd(u),[m,g]=ya({prop:r,onChange:s,defaultProp:o});return i.jsx(eY,{scope:n,baseId:Es(),value:m,onValueChange:g,orientation:l,dir:h,activationMode:d,children:i.jsx(rt.div,{dir:h,"data-orientation":l,...f,ref:t})})});wO.displayName=Qx;var SO="TabsList",CO=y.forwardRef((e,t)=>{const{__scopeTabs:n,loop:r=!0,...s}=e,o=Zx(SO,n),l=xO(n);return i.jsx(aN,{asChild:!0,...l,orientation:o.orientation,dir:o.dir,loop:r,children:i.jsx(rt.div,{role:"tablist","aria-orientation":o.orientation,...s,ref:t})})});CO.displayName=SO;var EO="TabsTrigger",kO=y.forwardRef((e,t)=>{const{__scopeTabs:n,value:r,disabled:s=!1,...o}=e,l=Zx(EO,n),u=xO(n),d=NO(l.baseId,r),f=MO(l.baseId,r),h=r===l.value;return i.jsx(iN,{asChild:!0,...u,focusable:!s,active:h,children:i.jsx(rt.button,{type:"button",role:"tab","aria-selected":h,"aria-controls":f,"data-state":h?"active":"inactive","data-disabled":s?"":void 0,disabled:s,id:d,...o,ref:t,onMouseDown:Ue(e.onMouseDown,m=>{!s&&m.button===0&&m.ctrlKey===!1?l.onValueChange(r):m.preventDefault()}),onKeyDown:Ue(e.onKeyDown,m=>{[" ","Enter"].includes(m.key)&&l.onValueChange(r)}),onFocus:Ue(e.onFocus,()=>{const m=l.activationMode!=="manual";!h&&!s&&m&&l.onValueChange(r)})})})});kO.displayName=EO;var jO="TabsContent",TO=y.forwardRef((e,t)=>{const{__scopeTabs:n,value:r,forceMount:s,children:o,...l}=e,u=Zx(jO,n),d=NO(u.baseId,r),f=MO(u.baseId,r),h=r===u.value,m=y.useRef(h);return y.useEffect(()=>{const g=requestAnimationFrame(()=>m.current=!1);return()=>cancelAnimationFrame(g)},[]),i.jsx(Mr,{present:s||h,children:({present:g})=>i.jsx(rt.div,{"data-state":h?"active":"inactive","data-orientation":u.orientation,role:"tabpanel","aria-labelledby":d,hidden:!g,id:f,tabIndex:0,...l,ref:t,style:{...e.style,animationDuration:m.current?"0s":void 0},children:g&&o})})});TO.displayName=jO;function NO(e,t){return`${e}-trigger-${t}`}function MO(e,t){return`${e}-content-${t}`}var tY=wO,_O=CO,RO=kO,PO=TO;const Yx=tY,hg=y.forwardRef(({className:e,...t},n)=>i.jsx(_O,{ref:n,className:Ie("inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground",e),...t}));hg.displayName=_O.displayName;const Jl=y.forwardRef(({className:e,...t},n)=>i.jsx(RO,{ref:n,className:Ie("inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm",e),...t}));Jl.displayName=RO.displayName;const Ql=y.forwardRef(({className:e,...t},n)=>i.jsx(PO,{ref:n,className:Ie("mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",e),...t}));Ql.displayName=PO.displayName;const nY=e=>["chats","findChats",JSON.stringify(e)],rY=async({instanceName:e})=>(await Ee.post(`/chat/findChats/${e}`,{where:{}})).data,sY=e=>{const{instanceName:t,...n}=e;return mt({...n,queryKey:nY({instanceName:t}),queryFn:()=>rY({instanceName:t}),enabled:!!t})};function zo(e){const t=o=>typeof window<"u"?window.matchMedia(o).matches:!1,[n,r]=y.useState(t(e));function s(){r(t(e))}return y.useEffect(()=>{const o=window.matchMedia(e);return s(),o.addListener?o.addListener(s):o.addEventListener("change",s),()=>{o.removeListener?o.removeListener(s):o.removeEventListener("change",s)}},[e]),n}const Ys=Object.create(null);Ys.open="0";Ys.close="1";Ys.ping="2";Ys.pong="3";Ys.message="4";Ys.upgrade="5";Ys.noop="6";const Cp=Object.create(null);Object.keys(Ys).forEach(e=>{Cp[Ys[e]]=e});const yb={type:"error",data:"parser error"},OO=typeof Blob=="function"||typeof Blob<"u"&&Object.prototype.toString.call(Blob)==="[object BlobConstructor]",IO=typeof ArrayBuffer=="function",AO=e=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(e):e&&e.buffer instanceof ArrayBuffer,Xx=({type:e,data:t},n,r)=>OO&&t instanceof Blob?n?r(t):WE(t,r):IO&&(t instanceof ArrayBuffer||AO(t))?n?r(t):WE(new Blob([t]),r):r(Ys[e]+(t||"")),WE=(e,t)=>{const n=new FileReader;return n.onload=function(){const r=n.result.split(",")[1];t("b"+(r||""))},n.readAsDataURL(e)};function GE(e){return e instanceof Uint8Array?e:e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}let Jv;function oY(e,t){if(OO&&e.data instanceof Blob)return e.data.arrayBuffer().then(GE).then(t);if(IO&&(e.data instanceof ArrayBuffer||AO(e.data)))return t(GE(e.data));Xx(e,!1,n=>{Jv||(Jv=new TextEncoder),t(Jv.encode(n))})}const JE="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Cu=typeof Uint8Array>"u"?[]:new Uint8Array(256);for(let e=0;e{let t=e.length*.75,n=e.length,r,s=0,o,l,u,d;e[e.length-1]==="="&&(t--,e[e.length-2]==="="&&t--);const f=new ArrayBuffer(t),h=new Uint8Array(f);for(r=0;r>4,h[s++]=(l&15)<<4|u>>2,h[s++]=(u&3)<<6|d&63;return f},iY=typeof ArrayBuffer=="function",ew=(e,t)=>{if(typeof e!="string")return{type:"message",data:DO(e,t)};const n=e.charAt(0);return n==="b"?{type:"message",data:lY(e.substring(1),t)}:Cp[n]?e.length>1?{type:Cp[n],data:e.substring(1)}:{type:Cp[n]}:yb},lY=(e,t)=>{if(iY){const n=aY(e);return DO(n,t)}else return{base64:!0,data:e}},DO=(e,t)=>{switch(t){case"blob":return e instanceof Blob?e:new Blob([e]);case"arraybuffer":default:return e instanceof ArrayBuffer?e:e.buffer}},FO="",cY=(e,t)=>{const n=e.length,r=new Array(n);let s=0;e.forEach((o,l)=>{Xx(o,!1,u=>{r[l]=u,++s===n&&t(r.join(FO))})})},uY=(e,t)=>{const n=e.split(FO),r=[];for(let s=0;s{const r=n.length;let s;if(r<126)s=new Uint8Array(1),new DataView(s.buffer).setUint8(0,r);else if(r<65536){s=new Uint8Array(3);const o=new DataView(s.buffer);o.setUint8(0,126),o.setUint16(1,r)}else{s=new Uint8Array(9);const o=new DataView(s.buffer);o.setUint8(0,127),o.setBigUint64(1,BigInt(r))}e.data&&typeof e.data!="string"&&(s[0]|=128),t.enqueue(s),t.enqueue(n)})}})}let Qv;function tp(e){return e.reduce((t,n)=>t+n.length,0)}function np(e,t){if(e[0].length===t)return e.shift();const n=new Uint8Array(t);let r=0;for(let s=0;sMath.pow(2,21)-1){u.enqueue(yb);break}s=h*Math.pow(2,32)+f.getUint32(4),r=3}else{if(tp(n)e){u.enqueue(yb);break}}}})}const LO=4;function Pn(e){if(e)return pY(e)}function pY(e){for(var t in Pn.prototype)e[t]=Pn.prototype[t];return e}Pn.prototype.on=Pn.prototype.addEventListener=function(e,t){return this._callbacks=this._callbacks||{},(this._callbacks["$"+e]=this._callbacks["$"+e]||[]).push(t),this};Pn.prototype.once=function(e,t){function n(){this.off(e,n),t.apply(this,arguments)}return n.fn=t,this.on(e,n),this};Pn.prototype.off=Pn.prototype.removeListener=Pn.prototype.removeAllListeners=Pn.prototype.removeEventListener=function(e,t){if(this._callbacks=this._callbacks||{},arguments.length==0)return this._callbacks={},this;var n=this._callbacks["$"+e];if(!n)return this;if(arguments.length==1)return delete this._callbacks["$"+e],this;for(var r,s=0;sPromise.resolve().then(t):(t,n)=>n(t,0),as=typeof self<"u"?self:typeof window<"u"?window:Function("return this")(),hY="arraybuffer";function $O(e,...t){return t.reduce((n,r)=>(e.hasOwnProperty(r)&&(n[r]=e[r]),n),{})}const gY=as.setTimeout,mY=as.clearTimeout;function mg(e,t){t.useNativeTimers?(e.setTimeoutFn=gY.bind(as),e.clearTimeoutFn=mY.bind(as)):(e.setTimeoutFn=as.setTimeout.bind(as),e.clearTimeoutFn=as.clearTimeout.bind(as))}const vY=1.33;function yY(e){return typeof e=="string"?bY(e):Math.ceil((e.byteLength||e.size)*vY)}function bY(e){let t=0,n=0;for(let r=0,s=e.length;r=57344?n+=3:(r++,n+=4);return n}function BO(){return Date.now().toString(36).substring(3)+Math.random().toString(36).substring(2,5)}function xY(e){let t="";for(let n in e)e.hasOwnProperty(n)&&(t.length&&(t+="&"),t+=encodeURIComponent(n)+"="+encodeURIComponent(e[n]));return t}function wY(e){let t={},n=e.split("&");for(let r=0,s=n.length;r{this.readyState="paused",t()};if(this._polling||!this.writable){let r=0;this._polling&&(r++,this.once("pollComplete",function(){--r||n()})),this.writable||(r++,this.once("drain",function(){--r||n()}))}else n()}_poll(){this._polling=!0,this.doPoll(),this.emitReserved("poll")}onData(t){const n=r=>{if(this.readyState==="opening"&&r.type==="open"&&this.onOpen(),r.type==="close")return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(r)};uY(t,this.socket.binaryType).forEach(n),this.readyState!=="closed"&&(this._polling=!1,this.emitReserved("pollComplete"),this.readyState==="open"&&this._poll())}doClose(){const t=()=>{this.write([{type:"close"}])};this.readyState==="open"?t():this.once("open",t)}write(t){this.writable=!1,cY(t,n=>{this.doWrite(n,()=>{this.writable=!0,this.emitReserved("drain")})})}uri(){const t=this.opts.secure?"https":"http",n=this.query||{};return this.opts.timestampRequests!==!1&&(n[this.opts.timestampParam]=BO()),!this.supportsBinary&&!n.sid&&(n.b64=1),this.createUri(t,n)}}let zO=!1;try{zO=typeof XMLHttpRequest<"u"&&"withCredentials"in new XMLHttpRequest}catch{}const EY=zO;function kY(){}class jY extends CY{constructor(t){if(super(t),typeof location<"u"){const n=location.protocol==="https:";let r=location.port;r||(r=n?"443":"80"),this.xd=typeof location<"u"&&t.hostname!==location.hostname||r!==t.port}}doWrite(t,n){const r=this.request({method:"POST",data:t});r.on("success",n),r.on("error",(s,o)=>{this.onError("xhr post error",s,o)})}doPoll(){const t=this.request();t.on("data",this.onData.bind(this)),t.on("error",(n,r)=>{this.onError("xhr poll error",n,r)}),this.pollXhr=t}}let Dl=class Ep extends Pn{constructor(t,n,r){super(),this.createRequest=t,mg(this,r),this._opts=r,this._method=r.method||"GET",this._uri=n,this._data=r.data!==void 0?r.data:null,this._create()}_create(){var t;const n=$O(this._opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");n.xdomain=!!this._opts.xd;const r=this._xhr=this.createRequest(n);try{r.open(this._method,this._uri,!0);try{if(this._opts.extraHeaders){r.setDisableHeaderCheck&&r.setDisableHeaderCheck(!0);for(let s in this._opts.extraHeaders)this._opts.extraHeaders.hasOwnProperty(s)&&r.setRequestHeader(s,this._opts.extraHeaders[s])}}catch{}if(this._method==="POST")try{r.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch{}try{r.setRequestHeader("Accept","*/*")}catch{}(t=this._opts.cookieJar)===null||t===void 0||t.addCookies(r),"withCredentials"in r&&(r.withCredentials=this._opts.withCredentials),this._opts.requestTimeout&&(r.timeout=this._opts.requestTimeout),r.onreadystatechange=()=>{var s;r.readyState===3&&((s=this._opts.cookieJar)===null||s===void 0||s.parseCookies(r.getResponseHeader("set-cookie"))),r.readyState===4&&(r.status===200||r.status===1223?this._onLoad():this.setTimeoutFn(()=>{this._onError(typeof r.status=="number"?r.status:0)},0))},r.send(this._data)}catch(s){this.setTimeoutFn(()=>{this._onError(s)},0);return}typeof document<"u"&&(this._index=Ep.requestsCount++,Ep.requests[this._index]=this)}_onError(t){this.emitReserved("error",t,this._xhr),this._cleanup(!0)}_cleanup(t){if(!(typeof this._xhr>"u"||this._xhr===null)){if(this._xhr.onreadystatechange=kY,t)try{this._xhr.abort()}catch{}typeof document<"u"&&delete Ep.requests[this._index],this._xhr=null}}_onLoad(){const t=this._xhr.responseText;t!==null&&(this.emitReserved("data",t),this.emitReserved("success"),this._cleanup())}abort(){this._cleanup()}};Dl.requestsCount=0;Dl.requests={};if(typeof document<"u"){if(typeof attachEvent=="function")attachEvent("onunload",QE);else if(typeof addEventListener=="function"){const e="onpagehide"in as?"pagehide":"unload";addEventListener(e,QE,!1)}}function QE(){for(let e in Dl.requests)Dl.requests.hasOwnProperty(e)&&Dl.requests[e].abort()}const TY=(function(){const e=UO({xdomain:!1});return e&&e.responseType!==null})();class NY extends jY{constructor(t){super(t);const n=t&&t.forceBase64;this.supportsBinary=TY&&!n}request(t={}){return Object.assign(t,{xd:this.xd},this.opts),new Dl(UO,this.uri(),t)}}function UO(e){const t=e.xdomain;try{if(typeof XMLHttpRequest<"u"&&(!t||EY))return new XMLHttpRequest}catch{}if(!t)try{return new as[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP")}catch{}}const VO=typeof navigator<"u"&&typeof navigator.product=="string"&&navigator.product.toLowerCase()==="reactnative";class MY extends tw{get name(){return"websocket"}doOpen(){const t=this.uri(),n=this.opts.protocols,r=VO?{}:$O(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(r.headers=this.opts.extraHeaders);try{this.ws=this.createSocket(t,n,r)}catch(s){return this.emitReserved("error",s)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=t=>this.onClose({description:"websocket connection closed",context:t}),this.ws.onmessage=t=>this.onData(t.data),this.ws.onerror=t=>this.onError("websocket error",t)}write(t){this.writable=!1;for(let n=0;n{try{this.doWrite(r,o)}catch{}s&&gg(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){typeof this.ws<"u"&&(this.ws.onerror=()=>{},this.ws.close(),this.ws=null)}uri(){const t=this.opts.secure?"wss":"ws",n=this.query||{};return this.opts.timestampRequests&&(n[this.opts.timestampParam]=BO()),this.supportsBinary||(n.b64=1),this.createUri(t,n)}}const Zv=as.WebSocket||as.MozWebSocket;class _Y extends MY{createSocket(t,n,r){return VO?new Zv(t,n,r):n?new Zv(t,n):new Zv(t)}doWrite(t,n){this.ws.send(n)}}class RY extends tw{get name(){return"webtransport"}doOpen(){try{this._transport=new WebTransport(this.createUri("https"),this.opts.transportOptions[this.name])}catch(t){return this.emitReserved("error",t)}this._transport.closed.then(()=>{this.onClose()}).catch(t=>{this.onError("webtransport error",t)}),this._transport.ready.then(()=>{this._transport.createBidirectionalStream().then(t=>{const n=fY(Number.MAX_SAFE_INTEGER,this.socket.binaryType),r=t.readable.pipeThrough(n).getReader(),s=dY();s.readable.pipeTo(t.writable),this._writer=s.writable.getWriter();const o=()=>{r.read().then(({done:u,value:d})=>{u||(this.onPacket(d),o())}).catch(u=>{})};o();const l={type:"open"};this.query.sid&&(l.data=`{"sid":"${this.query.sid}"}`),this._writer.write(l).then(()=>this.onOpen())})})}write(t){this.writable=!1;for(let n=0;n{s&&gg(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){var t;(t=this._transport)===null||t===void 0||t.close()}}const PY={websocket:_Y,webtransport:RY,polling:NY},OY=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,IY=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function bb(e){if(e.length>8e3)throw"URI too long";const t=e,n=e.indexOf("["),r=e.indexOf("]");n!=-1&&r!=-1&&(e=e.substring(0,n)+e.substring(n,r).replace(/:/g,";")+e.substring(r,e.length));let s=OY.exec(e||""),o={},l=14;for(;l--;)o[IY[l]]=s[l]||"";return n!=-1&&r!=-1&&(o.source=t,o.host=o.host.substring(1,o.host.length-1).replace(/;/g,":"),o.authority=o.authority.replace("[","").replace("]","").replace(/;/g,":"),o.ipv6uri=!0),o.pathNames=AY(o,o.path),o.queryKey=DY(o,o.query),o}function AY(e,t){const n=/\/{2,9}/g,r=t.replace(n,"/").split("/");return(t.slice(0,1)=="/"||t.length===0)&&r.splice(0,1),t.slice(-1)=="/"&&r.splice(r.length-1,1),r}function DY(e,t){const n={};return t.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(r,s,o){s&&(n[s]=o)}),n}const xb=typeof addEventListener=="function"&&typeof removeEventListener=="function",kp=[];xb&&addEventListener("offline",()=>{kp.forEach(e=>e())},!1);class va extends Pn{constructor(t,n){if(super(),this.binaryType=hY,this.writeBuffer=[],this._prevBufferLen=0,this._pingInterval=-1,this._pingTimeout=-1,this._maxPayload=-1,this._pingTimeoutTime=1/0,t&&typeof t=="object"&&(n=t,t=null),t){const r=bb(t);n.hostname=r.host,n.secure=r.protocol==="https"||r.protocol==="wss",n.port=r.port,r.query&&(n.query=r.query)}else n.host&&(n.hostname=bb(n.host).host);mg(this,n),this.secure=n.secure!=null?n.secure:typeof location<"u"&&location.protocol==="https:",n.hostname&&!n.port&&(n.port=this.secure?"443":"80"),this.hostname=n.hostname||(typeof location<"u"?location.hostname:"localhost"),this.port=n.port||(typeof location<"u"&&location.port?location.port:this.secure?"443":"80"),this.transports=[],this._transportsByName={},n.transports.forEach(r=>{const s=r.prototype.name;this.transports.push(s),this._transportsByName[s]=r}),this.opts=Object.assign({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,timestampParam:"t",rememberUpgrade:!1,addTrailingSlash:!0,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!1},n),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),typeof this.opts.query=="string"&&(this.opts.query=wY(this.opts.query)),xb&&(this.opts.closeOnBeforeunload&&(this._beforeunloadEventListener=()=>{this.transport&&(this.transport.removeAllListeners(),this.transport.close())},addEventListener("beforeunload",this._beforeunloadEventListener,!1)),this.hostname!=="localhost"&&(this._offlineEventListener=()=>{this._onClose("transport close",{description:"network connection lost"})},kp.push(this._offlineEventListener))),this.opts.withCredentials&&(this._cookieJar=void 0),this._open()}createTransport(t){const n=Object.assign({},this.opts.query);n.EIO=LO,n.transport=t,this.id&&(n.sid=this.id);const r=Object.assign({},this.opts,{query:n,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[t]);return new this._transportsByName[t](r)}_open(){if(this.transports.length===0){this.setTimeoutFn(()=>{this.emitReserved("error","No transports available")},0);return}const t=this.opts.rememberUpgrade&&va.priorWebsocketSuccess&&this.transports.indexOf("websocket")!==-1?"websocket":this.transports[0];this.readyState="opening";const n=this.createTransport(t);n.open(),this.setTransport(n)}setTransport(t){this.transport&&this.transport.removeAllListeners(),this.transport=t,t.on("drain",this._onDrain.bind(this)).on("packet",this._onPacket.bind(this)).on("error",this._onError.bind(this)).on("close",n=>this._onClose("transport close",n))}onOpen(){this.readyState="open",va.priorWebsocketSuccess=this.transport.name==="websocket",this.emitReserved("open"),this.flush()}_onPacket(t){if(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing")switch(this.emitReserved("packet",t),this.emitReserved("heartbeat"),t.type){case"open":this.onHandshake(JSON.parse(t.data));break;case"ping":this._sendPacket("pong"),this.emitReserved("ping"),this.emitReserved("pong"),this._resetPingTimeout();break;case"error":const n=new Error("server error");n.code=t.data,this._onError(n);break;case"message":this.emitReserved("data",t.data),this.emitReserved("message",t.data);break}}onHandshake(t){this.emitReserved("handshake",t),this.id=t.sid,this.transport.query.sid=t.sid,this._pingInterval=t.pingInterval,this._pingTimeout=t.pingTimeout,this._maxPayload=t.maxPayload,this.onOpen(),this.readyState!=="closed"&&this._resetPingTimeout()}_resetPingTimeout(){this.clearTimeoutFn(this._pingTimeoutTimer);const t=this._pingInterval+this._pingTimeout;this._pingTimeoutTime=Date.now()+t,this._pingTimeoutTimer=this.setTimeoutFn(()=>{this._onClose("ping timeout")},t),this.opts.autoUnref&&this._pingTimeoutTimer.unref()}_onDrain(){this.writeBuffer.splice(0,this._prevBufferLen),this._prevBufferLen=0,this.writeBuffer.length===0?this.emitReserved("drain"):this.flush()}flush(){if(this.readyState!=="closed"&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length){const t=this._getWritablePackets();this.transport.send(t),this._prevBufferLen=t.length,this.emitReserved("flush")}}_getWritablePackets(){if(!(this._maxPayload&&this.transport.name==="polling"&&this.writeBuffer.length>1))return this.writeBuffer;let n=1;for(let r=0;r0&&n>this._maxPayload)return this.writeBuffer.slice(0,r);n+=2}return this.writeBuffer}_hasPingExpired(){if(!this._pingTimeoutTime)return!0;const t=Date.now()>this._pingTimeoutTime;return t&&(this._pingTimeoutTime=0,gg(()=>{this._onClose("ping timeout")},this.setTimeoutFn)),t}write(t,n,r){return this._sendPacket("message",t,n,r),this}send(t,n,r){return this._sendPacket("message",t,n,r),this}_sendPacket(t,n,r,s){if(typeof n=="function"&&(s=n,n=void 0),typeof r=="function"&&(s=r,r=null),this.readyState==="closing"||this.readyState==="closed")return;r=r||{},r.compress=r.compress!==!1;const o={type:t,data:n,options:r};this.emitReserved("packetCreate",o),this.writeBuffer.push(o),s&&this.once("flush",s),this.flush()}close(){const t=()=>{this._onClose("forced close"),this.transport.close()},n=()=>{this.off("upgrade",n),this.off("upgradeError",n),t()},r=()=>{this.once("upgrade",n),this.once("upgradeError",n)};return(this.readyState==="opening"||this.readyState==="open")&&(this.readyState="closing",this.writeBuffer.length?this.once("drain",()=>{this.upgrading?r():t()}):this.upgrading?r():t()),this}_onError(t){if(va.priorWebsocketSuccess=!1,this.opts.tryAllTransports&&this.transports.length>1&&this.readyState==="opening")return this.transports.shift(),this._open();this.emitReserved("error",t),this._onClose("transport error",t)}_onClose(t,n){if(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing"){if(this.clearTimeoutFn(this._pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),xb&&(this._beforeunloadEventListener&&removeEventListener("beforeunload",this._beforeunloadEventListener,!1),this._offlineEventListener)){const r=kp.indexOf(this._offlineEventListener);r!==-1&&kp.splice(r,1)}this.readyState="closed",this.id=null,this.emitReserved("close",t,n),this.writeBuffer=[],this._prevBufferLen=0}}}va.protocol=LO;class FY extends va{constructor(){super(...arguments),this._upgrades=[]}onOpen(){if(super.onOpen(),this.readyState==="open"&&this.opts.upgrade)for(let t=0;t{r||(n.send([{type:"ping",data:"probe"}]),n.once("packet",m=>{if(!r)if(m.type==="pong"&&m.data==="probe"){if(this.upgrading=!0,this.emitReserved("upgrading",n),!n)return;va.priorWebsocketSuccess=n.name==="websocket",this.transport.pause(()=>{r||this.readyState!=="closed"&&(h(),this.setTransport(n),n.send([{type:"upgrade"}]),this.emitReserved("upgrade",n),n=null,this.upgrading=!1,this.flush())})}else{const g=new Error("probe error");g.transport=n.name,this.emitReserved("upgradeError",g)}}))};function o(){r||(r=!0,h(),n.close(),n=null)}const l=m=>{const g=new Error("probe error: "+m);g.transport=n.name,o(),this.emitReserved("upgradeError",g)};function u(){l("transport closed")}function d(){l("socket closed")}function f(m){n&&m.name!==n.name&&o()}const h=()=>{n.removeListener("open",s),n.removeListener("error",l),n.removeListener("close",u),this.off("close",d),this.off("upgrading",f)};n.once("open",s),n.once("error",l),n.once("close",u),this.once("close",d),this.once("upgrading",f),this._upgrades.indexOf("webtransport")!==-1&&t!=="webtransport"?this.setTimeoutFn(()=>{r||n.open()},200):n.open()}onHandshake(t){this._upgrades=this._filterUpgrades(t.upgrades),super.onHandshake(t)}_filterUpgrades(t){const n=[];for(let r=0;rPY[s]).filter(s=>!!s)),super(t,r)}};function $Y(e,t="",n){let r=e;n=n||typeof location<"u"&&location,e==null&&(e=n.protocol+"//"+n.host),typeof e=="string"&&(e.charAt(0)==="/"&&(e.charAt(1)==="/"?e=n.protocol+e:e=n.host+e),/^(https?|wss?):\/\//.test(e)||(typeof n<"u"?e=n.protocol+"//"+e:e="https://"+e),r=bb(e)),r.port||(/^(http|ws)$/.test(r.protocol)?r.port="80":/^(http|ws)s$/.test(r.protocol)&&(r.port="443")),r.path=r.path||"/";const o=r.host.indexOf(":")!==-1?"["+r.host+"]":r.host;return r.id=r.protocol+"://"+o+":"+r.port+t,r.href=r.protocol+"://"+o+(n&&n.port===r.port?"":":"+r.port),r}const BY=typeof ArrayBuffer=="function",zY=e=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(e):e.buffer instanceof ArrayBuffer,HO=Object.prototype.toString,UY=typeof Blob=="function"||typeof Blob<"u"&&HO.call(Blob)==="[object BlobConstructor]",VY=typeof File=="function"||typeof File<"u"&&HO.call(File)==="[object FileConstructor]";function nw(e){return BY&&(e instanceof ArrayBuffer||zY(e))||UY&&e instanceof Blob||VY&&e instanceof File}function jp(e,t){if(!e||typeof e!="object")return!1;if(Array.isArray(e)){for(let n=0,r=e.length;n=0&&e.num{delete this.acks[t];for(let u=0;u{this.io.clearTimeoutFn(o),n.apply(this,u)};l.withError=!0,this.acks[t]=l}emitWithAck(t,...n){return new Promise((r,s)=>{const o=(l,u)=>l?s(l):r(u);o.withError=!0,n.push(o),this.emit(t,...n)})}_addToQueue(t){let n;typeof t[t.length-1]=="function"&&(n=t.pop());const r={id:this._queueSeq++,tryCount:0,pending:!1,args:t,flags:Object.assign({fromQueue:!0},this.flags)};t.push((s,...o)=>r!==this._queue[0]?void 0:(s!==null?r.tryCount>this._opts.retries&&(this._queue.shift(),n&&n(s)):(this._queue.shift(),n&&n(null,...o)),r.pending=!1,this._drainQueue())),this._queue.push(r),this._drainQueue()}_drainQueue(t=!1){if(!this.connected||this._queue.length===0)return;const n=this._queue[0];n.pending&&!t||(n.pending=!0,n.tryCount++,this.flags=n.flags,this.emit.apply(this,n.args))}packet(t){t.nsp=this.nsp,this.io._packet(t)}onopen(){typeof this.auth=="function"?this.auth(t=>{this._sendConnectPacket(t)}):this._sendConnectPacket(this.auth)}_sendConnectPacket(t){this.packet({type:_t.CONNECT,data:this._pid?Object.assign({pid:this._pid,offset:this._lastOffset},t):t})}onerror(t){this.connected||this.emitReserved("connect_error",t)}onclose(t,n){this.connected=!1,delete this.id,this.emitReserved("disconnect",t,n),this._clearAcks()}_clearAcks(){Object.keys(this.acks).forEach(t=>{if(!this.sendBuffer.some(r=>String(r.id)===t)){const r=this.acks[t];delete this.acks[t],r.withError&&r.call(this,new Error("socket has been disconnected"))}})}onpacket(t){if(t.nsp===this.nsp)switch(t.type){case _t.CONNECT:t.data&&t.data.sid?this.onconnect(t.data.sid,t.data.pid):this.emitReserved("connect_error",new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));break;case _t.EVENT:case _t.BINARY_EVENT:this.onevent(t);break;case _t.ACK:case _t.BINARY_ACK:this.onack(t);break;case _t.DISCONNECT:this.ondisconnect();break;case _t.CONNECT_ERROR:this.destroy();const r=new Error(t.data.message);r.data=t.data.data,this.emitReserved("connect_error",r);break}}onevent(t){const n=t.data||[];t.id!=null&&n.push(this.ack(t.id)),this.connected?this.emitEvent(n):this.receiveBuffer.push(Object.freeze(n))}emitEvent(t){if(this._anyListeners&&this._anyListeners.length){const n=this._anyListeners.slice();for(const r of n)r.apply(this,t)}super.emit.apply(this,t),this._pid&&t.length&&typeof t[t.length-1]=="string"&&(this._lastOffset=t[t.length-1])}ack(t){const n=this;let r=!1;return function(...s){r||(r=!0,n.packet({type:_t.ACK,id:t,data:s}))}}onack(t){const n=this.acks[t.id];typeof n=="function"&&(delete this.acks[t.id],n.withError&&t.data.unshift(null),n.apply(this,t.data))}onconnect(t,n){this.id=t,this.recovered=n&&this._pid===n,this._pid=n,this.connected=!0,this.emitBuffered(),this.emitReserved("connect"),this._drainQueue(!0)}emitBuffered(){this.receiveBuffer.forEach(t=>this.emitEvent(t)),this.receiveBuffer=[],this.sendBuffer.forEach(t=>{this.notifyOutgoingListeners(t),this.packet(t)}),this.sendBuffer=[]}ondisconnect(){this.destroy(),this.onclose("io server disconnect")}destroy(){this.subs&&(this.subs.forEach(t=>t()),this.subs=void 0),this.io._destroy(this)}disconnect(){return this.connected&&this.packet({type:_t.DISCONNECT}),this.destroy(),this.connected&&this.onclose("io client disconnect"),this}close(){return this.disconnect()}compress(t){return this.flags.compress=t,this}get volatile(){return this.flags.volatile=!0,this}timeout(t){return this.flags.timeout=t,this}onAny(t){return this._anyListeners=this._anyListeners||[],this._anyListeners.push(t),this}prependAny(t){return this._anyListeners=this._anyListeners||[],this._anyListeners.unshift(t),this}offAny(t){if(!this._anyListeners)return this;if(t){const n=this._anyListeners;for(let r=0;r0&&e.jitter<=1?e.jitter:0,this.attempts=0}mc.prototype.duration=function(){var e=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var t=Math.random(),n=Math.floor(t*this.jitter*e);e=(Math.floor(t*10)&1)==0?e-n:e+n}return Math.min(e,this.max)|0};mc.prototype.reset=function(){this.attempts=0};mc.prototype.setMin=function(e){this.ms=e};mc.prototype.setMax=function(e){this.max=e};mc.prototype.setJitter=function(e){this.jitter=e};class Cb extends Pn{constructor(t,n){var r;super(),this.nsps={},this.subs=[],t&&typeof t=="object"&&(n=t,t=void 0),n=n||{},n.path=n.path||"/socket.io",this.opts=n,mg(this,n),this.reconnection(n.reconnection!==!1),this.reconnectionAttempts(n.reconnectionAttempts||1/0),this.reconnectionDelay(n.reconnectionDelay||1e3),this.reconnectionDelayMax(n.reconnectionDelayMax||5e3),this.randomizationFactor((r=n.randomizationFactor)!==null&&r!==void 0?r:.5),this.backoff=new mc({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(n.timeout==null?2e4:n.timeout),this._readyState="closed",this.uri=t;const s=n.parser||QY;this.encoder=new s.Encoder,this.decoder=new s.Decoder,this._autoConnect=n.autoConnect!==!1,this._autoConnect&&this.open()}reconnection(t){return arguments.length?(this._reconnection=!!t,t||(this.skipReconnect=!0),this):this._reconnection}reconnectionAttempts(t){return t===void 0?this._reconnectionAttempts:(this._reconnectionAttempts=t,this)}reconnectionDelay(t){var n;return t===void 0?this._reconnectionDelay:(this._reconnectionDelay=t,(n=this.backoff)===null||n===void 0||n.setMin(t),this)}randomizationFactor(t){var n;return t===void 0?this._randomizationFactor:(this._randomizationFactor=t,(n=this.backoff)===null||n===void 0||n.setJitter(t),this)}reconnectionDelayMax(t){var n;return t===void 0?this._reconnectionDelayMax:(this._reconnectionDelayMax=t,(n=this.backoff)===null||n===void 0||n.setMax(t),this)}timeout(t){return arguments.length?(this._timeout=t,this):this._timeout}maybeReconnectOnOpen(){!this._reconnecting&&this._reconnection&&this.backoff.attempts===0&&this.reconnect()}open(t){if(~this._readyState.indexOf("open"))return this;this.engine=new LY(this.uri,this.opts);const n=this.engine,r=this;this._readyState="opening",this.skipReconnect=!1;const s=xs(n,"open",function(){r.onopen(),t&&t()}),o=u=>{this.cleanup(),this._readyState="closed",this.emitReserved("error",u),t?t(u):this.maybeReconnectOnOpen()},l=xs(n,"error",o);if(this._timeout!==!1){const u=this._timeout,d=this.setTimeoutFn(()=>{s(),o(new Error("timeout")),n.close()},u);this.opts.autoUnref&&d.unref(),this.subs.push(()=>{this.clearTimeoutFn(d)})}return this.subs.push(s),this.subs.push(l),this}connect(t){return this.open(t)}onopen(){this.cleanup(),this._readyState="open",this.emitReserved("open");const t=this.engine;this.subs.push(xs(t,"ping",this.onping.bind(this)),xs(t,"data",this.ondata.bind(this)),xs(t,"error",this.onerror.bind(this)),xs(t,"close",this.onclose.bind(this)),xs(this.decoder,"decoded",this.ondecoded.bind(this)))}onping(){this.emitReserved("ping")}ondata(t){try{this.decoder.add(t)}catch(n){this.onclose("parse error",n)}}ondecoded(t){gg(()=>{this.emitReserved("packet",t)},this.setTimeoutFn)}onerror(t){this.emitReserved("error",t)}socket(t,n){let r=this.nsps[t];return r?this._autoConnect&&!r.active&&r.connect():(r=new qO(this,t,n),this.nsps[t]=r),r}_destroy(t){const n=Object.keys(this.nsps);for(const r of n)if(this.nsps[r].active)return;this._close()}_packet(t){const n=this.encoder.encode(t);for(let r=0;rt()),this.subs.length=0,this.decoder.destroy()}_close(){this.skipReconnect=!0,this._reconnecting=!1,this.onclose("forced close")}disconnect(){return this._close()}onclose(t,n){var r;this.cleanup(),(r=this.engine)===null||r===void 0||r.close(),this.backoff.reset(),this._readyState="closed",this.emitReserved("close",t,n),this._reconnection&&!this.skipReconnect&&this.reconnect()}reconnect(){if(this._reconnecting||this.skipReconnect)return this;const t=this;if(this.backoff.attempts>=this._reconnectionAttempts)this.backoff.reset(),this.emitReserved("reconnect_failed"),this._reconnecting=!1;else{const n=this.backoff.duration();this._reconnecting=!0;const r=this.setTimeoutFn(()=>{t.skipReconnect||(this.emitReserved("reconnect_attempt",t.backoff.attempts),!t.skipReconnect&&t.open(s=>{s?(t._reconnecting=!1,t.reconnect(),this.emitReserved("reconnect_error",s)):t.onreconnect()}))},n);this.opts.autoUnref&&r.unref(),this.subs.push(()=>{this.clearTimeoutFn(r)})}}onreconnect(){const t=this.backoff.attempts;this._reconnecting=!1,this.backoff.reset(),this.emitReserved("reconnect",t)}}const fu={};function Tp(e,t){typeof e=="object"&&(t=e,e=void 0),t=t||{};const n=$Y(e,t.path||"/socket.io"),r=n.source,s=n.id,o=n.path,l=fu[s]&&o in fu[s].nsps,u=t.forceNew||t["force new connection"]||t.multiplex===!1||l;let d;return u?d=new Cb(r,t):(fu[s]||(fu[s]=new Cb(r,t)),d=fu[s]),n.query&&!t.query&&(t.query=n.queryKey),d.socket(n.path,t)}Object.assign(Tp,{Manager:Cb,Socket:qO,io:Tp,connect:Tp});const _u=new Map,sw=e=>{if(_u.has(e)){const n=_u.get(e);return YE(n)}const t=Tp(e,{transports:["websocket","polling"],autoConnect:!1,reconnection:!0,reconnectionAttempts:5,reconnectionDelay:1e3,timeout:2e4});return _u.set(e,t),t.on("connect",()=>{console.log(`✅ WebSocket connected to ${e}`)}),t.on("disconnect",n=>{console.log(`❌ WebSocket disconnected from ${e}:`,n)}),t.on("connect_error",n=>{console.error(`🚫 WebSocket connection error to ${e}:`,n)}),t.on("reconnect",n=>{console.log(`🔄 WebSocket reconnected to ${e} after ${n} attempts`)}),t.on("reconnect_error",n=>{console.error(`🔄❌ WebSocket reconnection error to ${e}:`,n)}),YE(t)},ow=e=>{for(const[t,n]of _u.entries())if(n===e||e._socket===n){console.log(`🔌 Disconnecting socket for ${t}`),n.disconnect(),_u.delete(t);break}},YE=e=>({on:(t,n)=>{e.on(t,n)},off:t=>{e.off(t)},connect:()=>{e.connected||e.connect()},disconnect:()=>{e.disconnect()}}),bi=y.forwardRef(({className:e,...t},n)=>i.jsx("textarea",{className:Ie("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),ref:n,...t}));bi.displayName="Textarea";const YY=e=>["chats","findChats",JSON.stringify(e)],XY=async({instanceName:e,remoteJid:t})=>{const n=await Ee.post(`/chat/findChats/${e}`,{where:{remoteJid:t}});return Array.isArray(n.data)?n.data[0]:n.data},eX=e=>{const{instanceName:t,remoteJid:n,...r}=e;return mt({...r,queryKey:YY({instanceName:t,remoteJid:n}),queryFn:()=>XY({instanceName:t,remoteJid:n}),enabled:!!t&&!!n})},tX=e=>["chats","findMessages",JSON.stringify(e)],nX=async({instanceName:e,remoteJid:t})=>{const n=await Ee.post(`/chat/findMessages/${e}`,{where:{key:{remoteJid:t}}});return n.data?.messages?.records?n.data.messages.records:n.data},rX=e=>{const{instanceName:t,remoteJid:n,...r}=e;return mt({...r,queryKey:tX({instanceName:t,remoteJid:n}),queryFn:()=>nX({instanceName:t,remoteJid:n}),enabled:!!t&&!!n})},sX=async({instanceName:e,token:t,data:n})=>(await Ee.post(`/message/sendText/${e}`,n,{headers:{apikey:t,"content-type":"application/json"}})).data,oX=async({instanceName:e,token:t,data:n})=>{try{const r={number:n.number,mediatype:n.mediaMessage.mediatype,mimetype:n.mediaMessage.mimetype,caption:n.mediaMessage.caption,media:n.mediaMessage.media,fileName:n.mediaMessage.fileName};return(await Ee.post(`/message/sendMedia/${e}`,r,{headers:{apikey:t,"content-type":"application/json"}})).data}catch(r){throw console.error("Erro ao enviar mídia:",r),r}},aX=async({instanceName:e,token:t,data:n})=>{try{const r={number:n.number,audioMessage:{audio:n.audioMessage.audio},options:n.options};return(await Ee.post(`/message/sendWhatsAppAudio/${e}`,r,{headers:{apikey:t,"content-type":"application/json"}})).data}catch(r){throw console.error("Erro ao enviar áudio:",r),r}};function KO(){return{sendText:nt(sX,{invalidateKeys:[["chats","findMessages"],["chats","findChats"]]})}}function WO(){return{sendMedia:nt(oX)}}function iX(){return{sendAudio:nt(aX)}}const GO=y.createContext({backgroundColor:"",textForegroundColor:"",primaryColor:"",fromMeBubbleColor:"",fromMeForegroundColor:"",fromOtherBubbleColor:"",fromOtherForegroundColor:"",fromMeQuotedBubbleColor:"",fromOtherQuotedBubbleColor:"",inputBackgroundColor:"",inputTextForegroundColor:"",inputIconsMainColor:""});function lX({children:e}){const[t]=hd(),{theme:n}=tc(),r=t.get("backgroundColor"),s=t.get("textForegroundColor"),o=t.get("primaryColor"),l=t.get("fromMeBubbleColor"),u=t.get("fromMeForegroundColor"),d=t.get("fromOtherBubbleColor"),f=t.get("fromOtherForegroundColor"),h=t.get("fromMeQuotedBubbleColor"),m=t.get("fromOtherQuotedBubbleColor"),g=t.get("inputBackgroundColor"),x=t.get("inputTextForegroundColor"),b=t.get("inputIconsMainColor"),w=()=>n==="dark"?"#0f0f0f":"#faf9fa",C=()=>n==="dark"?"#faf9fa":"#020202",k=()=>n==="dark"?"#0b332a":"#e0f0f0",j=()=>n==="dark"?"#0b332a":"#c8fff2",M=()=>n==="dark"?"#ffffff":"#020202",_=()=>n==="dark"?"#1d2724":"#e0f0f0",R=()=>n==="dark"?"#ffffff":"#020202",N=()=>n==="dark"?"#161616":"#e0f0f0",O=()=>n==="dark"?"#faf9fa":"#020202",D=()=>n==="dark"?"#1f463d":"#aff7e6",z=()=>n==="dark"?"#0f1413":"#d2e2e2",Q=()=>n==="dark"?"#0e6451":"#0b332a";return i.jsx(GO.Provider,{value:{backgroundColor:r||w(),textForegroundColor:s||C(),primaryColor:o||k(),fromMeBubbleColor:l||j(),fromMeForegroundColor:u||M(),fromOtherBubbleColor:d||_(),fromOtherForegroundColor:f||R(),fromMeQuotedBubbleColor:h||D(),fromOtherQuotedBubbleColor:m||z(),inputBackgroundColor:g||N(),inputTextForegroundColor:x||O(),inputIconsMainColor:b||Q()},children:e})}const La=()=>y.useContext(GO),JO=({setSelectedMedia:e})=>{const{t}=Ve(),{inputIconsMainColor:n}=La(),r=y.useRef(null),s=y.useRef(null),[o,l]=y.useState(!1),u=m=>{const g=m.target.files?.[0];if(!g){e(null);return}const x=g.type.split("/")[0],b=g.size/(1024*1024);switch(x){case"audio":if(b>16){me.error(t("chat.media.errors.audioSize"));return}break;case"image":if(b>5){me.error(t("chat.media.errors.imageSize"));return}break;case"video":if(b>16){me.error(t("chat.media.errors.videoSize"));return}break;case"application":case"text":if(b>100){me.error(t("chat.media.errors.documentSize"));return}break;default:me.error(t("chat.media.errors.unsupportedType"));return}e(g)},d=m=>{m.preventDefault(),r.current&&r.current.click()},f=m=>{m.preventDefault(),s.current&&s.current.click()},h=["text/plain","application/pdf","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/vnd.ms-powerpoint","application/vnd.openxmlformats-officedocument.presentationml.presentation","application/zip","application/x-rar-compressed","application/x-7z-compressed"];return i.jsx(i.Fragment,{children:i.jsxs(Kr,{open:o,onOpenChange:l,children:[i.jsx(Wr,{asChild:!0,children:i.jsxs(se,{type:"button",variant:"ghost",size:"icon",className:"rounded-full p-2",children:[i.jsx(cs,{className:"h-6 w-6",style:{color:n}}),i.jsx("span",{className:"sr-only",children:t("chat.media.attach")})]})}),i.jsxs(hr,{align:"end",children:[i.jsx("input",{ref:s,type:"file",accept:h.join(", "),onChange:u,className:"hidden"}),i.jsxs(wt,{onClick:f,children:[i.jsx(rB,{className:"mr-2 h-4 w-4"}),t("chat.media.document")]}),i.jsx("input",{ref:r,type:"file",accept:"image/*, video/*",onChange:u,className:"hidden"}),i.jsxs(wt,{onClick:d,children:[i.jsx(uB,{className:"mr-2 h-4 w-4"}),t("chat.media.photosAndVideos")]})]})]})})},QO=({selectedMedia:e,setSelectedMedia:t})=>{const{t:n}=Ve(),r=()=>{t(null)},s=l=>l.type.includes("image")?i.jsx("img",{className:"w-80 rounded-lg",src:URL.createObjectURL(l),alt:n("chat.media.selectedMedia.imageAlt"),style:{maxHeight:"400px",objectFit:"contain"}}):l.type.includes("video")?i.jsx("div",{className:"flex items-center justify-center",children:i.jsx("video",{className:"w-80 rounded-lg object-cover",src:URL.createObjectURL(l),controls:!0})}):i.jsx("div",{className:"flex items-center justify-center",children:i.jsxs("span",{className:"flex items-center gap-2",children:[i.jsx(Hb,{className:"h-6 w-6"}),n("chat.media.selectedMedia.file")]})}),o=l=>{const u=["B","KB","MB","GB","TB"];let d=0;for(;l>1024;)l/=1024,d++;return`${l.toFixed(2)} ${u[d]}`};return i.jsxs("div",{className:"relative flex items-center rounded-lg bg-[#e0f0f0] dark:bg-[#1d2724] dark:text-white",children:[i.jsx("div",{className:"absolute h-full w-1 rounded-l-lg bg-blue-700 dark:bg-blue-300"}),i.jsxs("div",{className:"flex w-full flex-col items-center justify-center gap-6 p-4 pl-4",children:[e&&s(e),i.jsxs("div",{className:"flex flex-col items-center justify-center gap-2",children:[i.jsx("span",{className:"text-sm font-medium",children:e?.name||n("chat.media.selectedMedia.selectedFile")}),i.jsx("span",{className:"text-xs text-gray-500",children:o(e?.size||0)})]})]}),i.jsx(se,{size:"icon",variant:"ghost",className:"ml-auto h-10 w-10 rounded-full",onClick:r,children:i.jsx(qb,{className:"h-6 w-6"})})]})},XE=e=>{const t=new Date,n=new Date(t);n.setDate(n.getDate()-1);const r=new Date(e);return r.toDateString()===t.toDateString()?"Hoje":r.toDateString()===n.toDateString()?"Ontem":Math.floor((t.getTime()-r.getTime())/(1e3*60*60*24))<7?r.toLocaleDateString("pt-BR",{weekday:"long"}):r.toLocaleDateString("pt-BR",{day:"2-digit",month:"2-digit",year:"numeric"})},Yv=e=>{try{if(!e.messageTimestamp)return new Date;if(typeof e.messageTimestamp=="object"){const n=[e.messageTimestamp.low,e.messageTimestamp.seconds,e.messageTimestamp.timestamp,e.messageTimestamp.time,e.messageTimestamp.value].find(r=>typeof r=="number"&&!isNaN(r))||Date.now()/1e3;return new Date(n*1e3)}else if(isNaN(Number(e.messageTimestamp))){if(typeof e.messageTimestamp=="string"&&e.messageTimestamp.includes("T"))return new Date(e.messageTimestamp)}else{const t=Number(e.messageTimestamp);return t>1e12?new Date(t):new Date(t*1e3)}return new Date}catch{return new Date}},cX=({date:e})=>i.jsx("div",{className:"flex items-center justify-center py-4",children:i.jsx("div",{className:"rounded-full bg-muted px-3 py-1",children:i.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:e})})}),uX=e=>{if(!e)return"";if(typeof e=="string")try{const t=JSON.parse(e);return t.conversation||t.text||e}catch{return e}return typeof e=="object"?e.conversation||e.text||"":String(e)},ek=({message:e})=>{const t=e.messageType;switch(t){case"conversation":if(e.message.contactMessage){const d=e.message.contactMessage;return i.jsxs("div",{className:"p-3 bg-muted rounded-lg max-w-xs",children:[i.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[i.jsx("div",{className:"text-xl",children:"👤"}),i.jsx("span",{className:"font-medium",children:"Contact"})]}),d.displayName&&i.jsx("p",{className:"text-sm font-medium",children:d.displayName}),d.vcard&&i.jsx("p",{className:"text-xs text-muted-foreground",children:"Contact card"})]})}if(e.message.locationMessage){const d=e.message.locationMessage;return i.jsxs("div",{className:"p-3 bg-muted rounded-lg max-w-xs",children:[i.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[i.jsx("div",{className:"text-xl",children:"📍"}),i.jsx("span",{className:"font-medium",children:"Location"})]}),d.name&&i.jsx("p",{className:"text-sm font-medium",children:d.name}),d.address&&i.jsx("p",{className:"text-xs text-muted-foreground",children:d.address}),d.degreesLatitude&&d.degreesLongitude&&i.jsx("a",{href:`https://maps.google.com/?q=${d.degreesLatitude},${d.degreesLongitude}`,target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline text-sm mt-1 inline-block",children:"View on Maps"})]})}return i.jsx("span",{children:uX(e.message)});case"extendedTextMessage":return i.jsx("span",{children:e.message.conversation??e.message.extendedTextMessage?.text});case"imageMessage":const r=(e.message.base64?e.message.base64.startsWith("data:")?e.message.base64:`data:image/jpeg;base64,${e.message.base64}`:null)||e.message.mediaUrl;return i.jsxs("div",{className:"flex flex-col gap-2",children:[r?i.jsx("img",{src:r,alt:"Image",className:"rounded-lg max-w-full h-auto",style:{maxWidth:"400px",maxHeight:"400px",objectFit:"contain"},loading:"lazy"}):i.jsxs("div",{className:"rounded bg-muted p-4 max-w-xs",children:[i.jsx("p",{className:"text-center text-muted-foreground",children:"Image couldn't be loaded"}),i.jsx("p",{className:"text-center text-xs text-muted-foreground mt-1",children:"Missing base64 data and mediaUrl"})]}),e.message.imageMessage?.caption&&i.jsx("p",{className:"text-sm",children:e.message.imageMessage.caption})]});case"videoMessage":const o=(e.message.base64?e.message.base64.startsWith("data:")?e.message.base64:`data:video/mp4;base64,${e.message.base64}`:null)||e.message.mediaUrl;return i.jsxs("div",{className:"flex flex-col gap-2",children:[o?i.jsx("video",{src:o,controls:!0,className:"rounded-lg max-w-full h-auto",style:{maxWidth:"400px",maxHeight:"400px"}}):i.jsxs("div",{className:"rounded bg-muted p-4 max-w-xs",children:[i.jsx("p",{className:"text-center text-muted-foreground",children:"Video couldn't be loaded"}),i.jsx("p",{className:"text-center text-xs text-muted-foreground mt-1",children:"Missing base64 data and mediaUrl"})]}),e.message.videoMessage?.caption&&i.jsx("p",{className:"text-sm",children:e.message.videoMessage.caption})]});case"audioMessage":const u=(e.message.base64?e.message.base64.startsWith("data:")?e.message.base64:`data:audio/mpeg;base64,${e.message.base64}`:null)||e.message.mediaUrl;return u?i.jsxs("audio",{controls:!0,className:"w-full max-w-xs",children:[i.jsx("source",{src:u,type:"audio/mpeg"}),"Your browser does not support the audio element."]}):i.jsxs("div",{className:"rounded bg-muted p-4 max-w-xs",children:[i.jsx("p",{className:"text-center text-muted-foreground",children:"Audio couldn't be loaded"}),i.jsx("p",{className:"text-center text-xs text-muted-foreground mt-1",children:"Missing base64 data and mediaUrl"})]});case"documentMessage":return i.jsxs("div",{className:"flex items-center gap-2 p-3 bg-muted rounded-lg max-w-xs",children:[i.jsx("div",{className:"text-2xl",children:"📄"}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("p",{className:"font-medium truncate",children:e.message.documentMessage?.fileName||"Document"}),e.message.documentMessage?.fileLength&&i.jsxs("p",{className:"text-xs text-muted-foreground",children:[(e.message.documentMessage.fileLength/1024/1024).toFixed(2)," MB"]})]})]});case"stickerMessage":return i.jsx("img",{src:e.message.mediaUrl,alt:"Sticker",className:"max-w-32 max-h-32 object-contain"});default:return i.jsx("div",{className:"text-xs text-muted-foreground bg-muted p-2 rounded max-w-xs",children:i.jsxs("details",{children:[i.jsxs("summary",{children:["Unknown message type: ",t]}),i.jsx("pre",{className:"mt-2 whitespace-pre-wrap break-all text-xs",children:JSON.stringify(e.message,null,2)})]})})}};function ZO({textareaRef:e,handleTextareaChange:t,textareaHeight:n,lastMessageRef:r,scrollToBottom:s}){const{instance:o}=ct(),[l,u]=y.useState(""),[d,f]=y.useState(!1),[h,m]=y.useState(null),[g,x]=y.useState([]),{sendText:b}=KO(),{sendMedia:w}=WO(),{remoteJid:C}=ls(),k=async()=>{if(!(!l.trim()||!C||!o?.name||!o?.token||d))try{f(!0),await b({instanceName:o.name,token:o.token,data:{number:C,text:l.trim()}}),u(""),e.current&&(e.current.value="",t())}catch(G){console.error("Error sending message:",G)}finally{f(!1)}},j=async()=>{if(!(!h||!C||!o?.name||!o?.token||d))try{f(!0);const G=await new Promise((W,ie)=>{const re=new FileReader;re.readAsDataURL(h),re.onload=()=>{const H=re.result.split(",")[1];W(H)},re.onerror=ie});await w({instanceName:o.name,token:o.token,data:{number:C,mediaMessage:{mediatype:h.type.split("/")[0]==="application"?"document":h.type.split("/")[0],mimetype:h.type,caption:l.trim(),media:G,fileName:h.name}}}),m(null),u(""),e.current&&(e.current.value="",t())}catch(G){console.error("Error sending media:",G)}finally{f(!1)}},M=async()=>{h?await j():await k()},_=G=>{G.key==="Enter"&&!G.shiftKey&&(G.preventDefault(),M())},R=G=>{u(G.target.value),t()},{data:N}=eX({remoteJid:C,instanceName:o?.name}),{data:O,isSuccess:D}=rX({remoteJid:C,instanceName:o?.name}),z=y.useMemo(()=>{if(!O)return g;const G=new Map;return O.forEach(W=>G.set(W.key.id,W)),g.forEach(W=>{G.set(W.key.id,W)}),Array.from(G.values())},[O,g]);y.useEffect(()=>{if(!o?.name||!C)return;const G=dr(jn.API_URL);if(!G){console.error("API URL not found in localStorage");return}const W=sw(G),ie=(Y,H)=>{if(!o||H.instance!==o.name||H?.data?.key?.remoteJid!==C)return;const q=H.data;x(he=>{const A=he.findIndex(F=>F.key.id===q.key.id);if(A!==-1){const F=[...he];return F[A]=q,F}else return[...he,q]})},re=Y=>{o&&Y.instance===o.name&&console.log("Received message status update:",Y)};return W.on("messages.upsert",Y=>{ie("messages.upsert",Y)}),W.on("send.message",Y=>{ie("send.message",Y)}),W.on("messages.update",Y=>{re(Y)}),W.connect(),()=>{W.off("messages.upsert"),W.off("send.message"),W.off("messages.update"),ow(W)}},[o?.name,C]);const Q=y.useMemo(()=>{if(!z)return[];const G=[...z].sort((Y,H)=>{const q=Yv(Y).getTime(),he=Yv(H).getTime();return q-he}),W=[];let ie="",re=[];return G.forEach(Y=>{const q=Yv(Y).toDateString();q!==ie?(re.length>0&&W.push({date:XE(new Date(ie)),messages:re}),ie=q,re=[Y]):re.push(Y)}),re.length>0&&W.push({date:XE(new Date(ie)),messages:re}),W},[z]);y.useEffect(()=>{D&&z&&s()},[D,z,s]),y.useEffect(()=>{m(null),u(""),x([]),e.current&&(e.current.value="",t())},[C]);const pe=G=>i.jsx("div",{className:"bubble-right",children:i.jsx("div",{className:"flex items-start gap-4 self-end",children:i.jsx("div",{className:"grid gap-1",children:i.jsx("div",{className:"bubble",children:i.jsx(ek,{message:G})})})})},G.id),V=G=>i.jsx("div",{className:"bubble-left",children:i.jsx("div",{className:"flex items-start gap-4",children:i.jsx("div",{className:"grid gap-1",children:i.jsx("div",{className:"bubble",children:i.jsx(ek,{message:G})})})})},G.id);return i.jsxs("div",{className:"flex h-full flex-col",children:[i.jsx("div",{className:"sticky top-0 bg-background border-b border-border p-3",children:i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsxs(Ei,{className:"h-10 w-10",children:[i.jsx(ki,{src:N?.profilePicUrl,alt:N?.pushName||N?.remoteJid?.split("@")[0]}),i.jsx(Up,{className:"bg-slate-700 text-slate-300 border border-slate-600",children:i.jsx(Ap,{className:"h-5 w-5"})})]}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("div",{className:"font-medium text-sm truncate",children:N?.pushName||N?.remoteJid?.split("@")[0]}),i.jsx("div",{className:"text-xs text-muted-foreground truncate",children:N?.remoteJid?.split("@")[0]})]}),i.jsxs(dx,{children:[i.jsx(fx,{asChild:!0,children:i.jsx(se,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0",children:i.jsx(Nh,{className:"h-4 w-4"})})}),i.jsxs(hr,{align:"start",className:"max-w-[300px]",children:[i.jsxs(wt,{className:"items-start gap-2",children:[i.jsx(wB,{className:"mr-2 h-4 w-4 shrink-0 translate-y-1"}),i.jsxs("div",{children:[i.jsx("div",{className:"font-medium",children:"GPT-4"}),i.jsx("div",{className:"text-muted-foreground/80",children:"With DALL-E, browsing and analysis. Limit 40 messages / 3 hours"})]})]}),i.jsx(Xs,{}),i.jsxs(wt,{className:"items-start gap-2",children:[i.jsx(mT,{className:"mr-2 h-4 w-4 shrink-0 translate-y-1"}),i.jsxs("div",{children:[i.jsx("div",{className:"font-medium",children:"GPT-3"}),i.jsx("div",{className:"text-muted-foreground/80",children:"Great for everyday tasks"})]})]})]})]})]})}),i.jsxs("div",{className:"message-container mx-auto flex max-w-4xl flex-1 flex-col gap-2 overflow-y-auto px-2",children:[Q.map((G,W)=>i.jsxs("div",{children:[i.jsx(cX,{date:G.date}),i.jsx("div",{className:"flex flex-col gap-2",children:G.messages.map(ie=>ie.key.fromMe?pe(ie):V(ie))})]},W)),i.jsx("div",{ref:r})]}),i.jsxs("div",{className:"sticky bottom-0 mx-auto flex w-full max-w-2xl flex-col gap-1.5 bg-background px-2 py-2",children:[h&&i.jsx(QO,{selectedMedia:h,setSelectedMedia:m}),i.jsxs("div",{className:"flex items-center rounded-3xl border border-border bg-background px-2 py-1",children:[o&&i.jsx(JO,{instance:o,setSelectedMedia:m}),i.jsx(bi,{placeholder:"Enviar mensagem...",name:"message",id:"message",rows:1,ref:e,value:l,onChange:R,onKeyDown:_,disabled:d,style:{height:n},className:"min-h-0 w-full resize-none border-none p-3 focus-visible:outline-none focus-visible:ring-0 focus-visible:ring-transparent focus-visible:ring-offset-0 focus-visible:ring-offset-transparent"}),i.jsxs(se,{type:"button",size:"icon",onClick:M,disabled:!l.trim()&&!h||d,className:"rounded-full p-2 disabled:opacity-50",children:[i.jsx(Th,{className:"h-6 w-6"}),i.jsx("span",{className:"sr-only",children:"Enviar"})]})]})]})]})}const dX=e=>e.split("@")[0];function tk(){const e=zo("(min-width: 768px)"),t=y.useRef(null),[n]=y.useState("auto"),r=y.useRef(null),{instance:s}=ct(),[o,l]=y.useState([]),{data:u,isSuccess:d}=sY({instanceName:s?.name}),f=qe.useMemo(()=>{if(!u)return o;const C=new Map;return u.forEach(k=>C.set(k.remoteJid,k)),o.forEach(k=>{const j=C.get(k.remoteJid);j?C.set(k.remoteJid,{...j,...k}):C.set(k.remoteJid,k)}),Array.from(C.values())},[u,o]),{instanceId:h,remoteJid:m}=ls(),g=dn();y.useEffect(()=>{if(!s?.name)return;const C=dr(jn.API_URL);if(!C){console.error("API URL not found in localStorage");return}const k=sw(C),j=(M,_)=>{if(!s||_.instance!==s.name)return;const R=_?.data?.key?.remoteJid;R&&l(N=>{const O=N.findIndex(z=>z.remoteJid===R),D={id:R,remoteJid:R,pushName:_?.data?.pushName||dX(R),profilePicUrl:_?.data?.key?.profilePictureUrl||"",..._?.data};if(O!==-1){const z=[...N];return z[O]={...z[O],...D},z}else return[...N,D]})};return k.on("messages.upsert",M=>{j("messages.upsert",M)}),k.on("send.message",M=>{j("send.message",M)}),k.connect(),()=>{k.off("messages.upsert"),k.off("send.message"),ow(k)}},[s?.name]);const x=y.useCallback(()=>{t.current&&t.current.scrollIntoView({})},[]),b=()=>{if(r.current){r.current.style.height="auto";const C=r.current.scrollHeight,j=parseInt(getComputedStyle(r.current).lineHeight)*10;r.current.style.height=`${Math.min(C,j)}px`}};y.useEffect(()=>{d&&x()},[d,x]);const w=C=>{g(`/manager/instance/${h}/chat/${C}`)};return i.jsx("div",{className:"h-[calc(100vh-160px)] overflow-hidden",children:i.jsxs($o,{direction:e?"horizontal":"vertical",className:"h-full",children:[i.jsx(Hn,{defaultSize:20,children:i.jsxs("div",{className:"hidden h-full flex-col bg-background text-foreground md:flex",children:[i.jsx("div",{className:"flex-shrink-0 p-2",children:i.jsxs(se,{variant:"ghost",className:"w-full justify-start gap-2 px-2 text-left",children:[i.jsx("div",{className:"flex h-7 w-7 items-center justify-center rounded-full",children:i.jsx(Bl,{className:"h-4 w-4"})}),i.jsx("div",{className:"grow overflow-hidden text-ellipsis whitespace-nowrap text-sm",children:"Chat"}),i.jsx(cs,{className:"h-4 w-4"})]})}),i.jsxs(Yx,{defaultValue:"contacts",className:"flex flex-col flex-1 min-h-0",children:[i.jsxs(hg,{className:"tabs-chat flex-shrink-0",children:[i.jsx(Jl,{value:"contacts",children:"Contatos"}),i.jsx(Jl,{value:"groups",children:"Grupos"})]}),i.jsx(Ql,{value:"contacts",className:"flex-1 overflow-hidden",children:i.jsx("div",{className:"h-full overflow-auto",children:i.jsxs("div",{className:"grid gap-1 p-2 text-foreground",children:[i.jsx("div",{className:"px-2 text-xs font-medium text-muted-foreground",children:"Contatos"}),u?.map(C=>C.remoteJid.includes("@s.whatsapp.net")&&i.jsxs(Fu,{to:"#",onClick:()=>w(C.remoteJid),className:`chat-item flex items-center overflow-hidden truncate whitespace-nowrap rounded-md border-b border-gray-600/50 p-2 text-sm transition-colors hover:bg-muted/50 ${m===C.remoteJid?"active":""}`,children:[i.jsx("span",{className:"chat-avatar mr-2",children:i.jsxs(Ei,{className:"h-8 w-8",children:[i.jsx(ki,{src:C.profilePicUrl,alt:C.pushName||C.remoteJid.split("@")[0]}),i.jsx(Up,{className:"bg-slate-700 text-slate-300 border border-slate-600",children:i.jsx(Ap,{className:"h-5 w-5"})})]})}),i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsx("span",{className:"chat-title block font-medium",children:C.pushName||C.remoteJid.split("@")[0]}),i.jsx("span",{className:"chat-description block text-xs text-gray-500",children:C.remoteJid.split("@")[0]})]})]},C.id))]})})}),i.jsx(Ql,{value:"groups",className:"flex-1 overflow-hidden",children:i.jsx("div",{className:"h-full overflow-auto",children:i.jsx("div",{className:"grid gap-1 p-2 text-foreground",children:f?.map(C=>C.remoteJid.includes("@g.us")&&i.jsxs(Fu,{to:"#",onClick:()=>w(C.remoteJid),className:`chat-item flex items-center overflow-hidden truncate whitespace-nowrap rounded-md border-b border-gray-600/50 p-2 text-sm transition-colors hover:bg-muted/50 ${m===C.remoteJid?"active":""}`,children:[i.jsx("span",{className:"chat-avatar mr-2",children:i.jsxs(Ei,{className:"h-8 w-8",children:[i.jsx(ki,{src:C.profilePicUrl,alt:C.pushName||C.remoteJid.split("@")[0]}),i.jsx(Up,{className:"bg-slate-700 text-slate-300 border border-slate-600",children:i.jsx(Ap,{className:"h-5 w-5"})})]})}),i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsx("span",{className:"chat-title block font-medium",children:C.pushName||C.remoteJid.split("@")[0]}),i.jsx("span",{className:"chat-description block text-xs text-gray-500",children:C.remoteJid})]})]},C.id))})})})]})]})}),i.jsx(Bo,{withHandle:!0,className:"border border-black"}),i.jsx(Hn,{children:m&&i.jsx(ZO,{textareaRef:r,handleTextareaChange:b,textareaHeight:n,lastMessageRef:t,scrollToBottom:x})})]})})}const fX=e=>["chatwoot","fetchChatwoot",JSON.stringify(e)],pX=async({instanceName:e,token:t})=>(await Ee.get(`/chatwoot/find/${e}`,{headers:{apiKey:t}})).data,hX=e=>{const{instanceName:t,token:n,...r}=e;return mt({...r,queryKey:fX({instanceName:t,token:n}),queryFn:()=>pX({instanceName:t,token:n}),enabled:!!t})},gX=async({instanceName:e,token:t,data:n})=>(await Ee.post(`/chatwoot/set/${e}`,n,{headers:{apikey:t}})).data;function mX(){return{createChatwoot:nt(gX,{invalidateKeys:[["chatwoot","fetchChatwoot"]]})}}const rp=P.string().optional().transform(e=>e===""?void 0:e),vX=P.object({enabled:P.boolean(),accountId:P.string(),token:P.string(),url:P.string(),signMsg:P.boolean().optional(),signDelimiter:rp,nameInbox:rp,organization:rp,logo:rp,reopenConversation:P.boolean().optional(),conversationPending:P.boolean().optional(),mergeBrazilContacts:P.boolean().optional(),importContacts:P.boolean().optional(),importMessages:P.boolean().optional(),daysLimitImportMessages:P.coerce.number().optional(),autoCreate:P.boolean(),ignoreJids:P.array(P.string()).default([])});function yX(){const{t:e}=Ve(),{instance:t}=ct(),[,n]=y.useState(!1),{createChatwoot:r}=mX(),{data:s}=hX({instanceName:t?.name,token:t?.token}),o=on({resolver:an(vX),defaultValues:{enabled:!0,accountId:"",token:"",url:"",signMsg:!0,signDelimiter:"\\n",nameInbox:"",organization:"",logo:"",reopenConversation:!0,conversationPending:!1,mergeBrazilContacts:!0,importContacts:!1,importMessages:!1,daysLimitImportMessages:7,autoCreate:!0,ignoreJids:[]}});y.useEffect(()=>{if(s){o.setValue("ignoreJids",s.ignoreJids||[]);const u={enabled:s.enabled,accountId:s.accountId,token:s.token,url:s.url,signMsg:s.signMsg||!1,signDelimiter:s.signDelimiter||"\\n",nameInbox:s.nameInbox||"",organization:s.organization||"",logo:s.logo||"",reopenConversation:s.reopenConversation||!1,conversationPending:s.conversationPending||!1,mergeBrazilContacts:s.mergeBrazilContacts||!1,importContacts:s.importContacts||!1,importMessages:s.importMessages||!1,daysLimitImportMessages:s.daysLimitImportMessages||7,autoCreate:s.autoCreate||!1,ignoreJids:s.ignoreJids};o.reset(u)}},[s,o]);const l=async u=>{if(!t)return;n(!0);const d={enabled:u.enabled,accountId:u.accountId,token:u.token,url:u.url,signMsg:u.signMsg||!1,signDelimiter:u.signDelimiter||"\\n",nameInbox:u.nameInbox||"",organization:u.organization||"",logo:u.logo||"",reopenConversation:u.reopenConversation||!1,conversationPending:u.conversationPending||!1,mergeBrazilContacts:u.mergeBrazilContacts||!1,importContacts:u.importContacts||!1,importMessages:u.importMessages||!1,daysLimitImportMessages:u.daysLimitImportMessages||7,autoCreate:u.autoCreate,ignoreJids:u.ignoreJids};await r({instanceName:t.name,token:t.token,data:d},{onSuccess:()=>{me.success(e("chatwoot.toast.success"))},onError:f=>{console.error(e("chatwoot.toast.error"),f),rT(f)?me.error(`Error: ${f?.response?.data?.response?.message}`):me.error(e("chatwoot.toast.error"))},onSettled:()=>{n(!1)}})};return i.jsx(i.Fragment,{children:i.jsx(Fo,{...o,children:i.jsxs("form",{onSubmit:o.handleSubmit(l),className:"w-full space-y-6",children:[i.jsxs("div",{children:[i.jsx("h3",{className:"mb-1 text-lg font-medium",children:e("chatwoot.title")}),i.jsx(Oa,{className:"my-4"}),i.jsxs("div",{className:"mx-4 space-y-2 divide-y [&>*]:px-4 [&>*]:py-2",children:[i.jsx(Pe,{name:"enabled",label:e("chatwoot.form.enabled.label"),className:"w-full justify-between",helper:e("chatwoot.form.enabled.description")}),i.jsx(le,{name:"url",label:e("chatwoot.form.url.label"),children:i.jsx(ne,{})}),i.jsx(le,{name:"accountId",label:e("chatwoot.form.accountId.label"),children:i.jsx(ne,{})}),i.jsx(le,{name:"token",label:e("chatwoot.form.token.label"),children:i.jsx(ne,{type:"password"})}),i.jsx(Pe,{name:"signMsg",label:e("chatwoot.form.signMsg.label"),className:"w-full justify-between",helper:e("chatwoot.form.signMsg.description")}),i.jsx(le,{name:"signDelimiter",label:e("chatwoot.form.signDelimiter.label"),children:i.jsx(ne,{})}),i.jsx(le,{name:"nameInbox",label:e("chatwoot.form.nameInbox.label"),children:i.jsx(ne,{})}),i.jsx(le,{name:"organization",label:e("chatwoot.form.organization.label"),children:i.jsx(ne,{})}),i.jsx(le,{name:"logo",label:e("chatwoot.form.logo.label"),children:i.jsx(ne,{})}),i.jsx(Pe,{name:"conversationPending",label:e("chatwoot.form.conversationPending.label"),className:"w-full justify-between",helper:e("chatwoot.form.conversationPending.description")}),i.jsx(Pe,{name:"reopenConversation",label:e("chatwoot.form.reopenConversation.label"),className:"w-full justify-between",helper:e("chatwoot.form.reopenConversation.description")}),i.jsx(Pe,{name:"importContacts",label:e("chatwoot.form.importContacts.label"),className:"w-full justify-between",helper:e("chatwoot.form.importContacts.description")}),i.jsx(Pe,{name:"importMessages",label:e("chatwoot.form.importMessages.label"),className:"w-full justify-between",helper:e("chatwoot.form.importMessages.description")}),i.jsx(le,{name:"daysLimitImportMessages",label:e("chatwoot.form.daysLimitImportMessages.label"),children:i.jsx(ne,{type:"number"})}),i.jsx(Da,{name:"ignoreJids",label:e("chatwoot.form.ignoreJids.label"),placeholder:e("chatwoot.form.ignoreJids.placeholder")}),i.jsx(Pe,{name:"autoCreate",label:e("chatwoot.form.autoCreate.label"),className:"w-full justify-between",helper:e("chatwoot.form.autoCreate.description")})]})]}),i.jsx("div",{className:"mx-4 flex justify-end",children:i.jsx(se,{type:"submit",children:e("chatwoot.button.save")})})]})})})}var wl={},Xv={exports:{}},ey,nk;function bX(){if(nk)return ey;nk=1;var e="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED";return ey=e,ey}var ty,rk;function xX(){if(rk)return ty;rk=1;var e=bX();function t(){}function n(){}return n.resetWarningCache=t,ty=function(){function r(l,u,d,f,h,m){if(m!==e){var g=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw g.name="Invariant Violation",g}}r.isRequired=r;function s(){return r}var o={array:r,bigint:r,bool:r,func:r,number:r,object:r,string:r,symbol:r,any:r,arrayOf:s,element:r,elementType:r,instanceOf:s,node:r,objectOf:s,oneOf:s,oneOfType:s,shape:s,exact:s,checkPropTypes:n,resetWarningCache:t};return o.PropTypes=o,o},ty}var sk;function YO(){return sk||(sk=1,Xv.exports=xX()()),Xv.exports}var ny,ok;function XO(){return ok||(ok=1,ny={L:1,M:0,Q:3,H:2}),ny}var ry,ak;function eI(){return ak||(ak=1,ry={MODE_NUMBER:1,MODE_ALPHA_NUM:2,MODE_8BIT_BYTE:4,MODE_KANJI:8}),ry}var sy,ik;function wX(){if(ik)return sy;ik=1;var e=eI();function t(n){this.mode=e.MODE_8BIT_BYTE,this.data=n}return t.prototype={getLength:function(n){return this.data.length},write:function(n){for(var r=0;r>>7-t%8&1)==1},put:function(t,n){for(var r=0;r>>n-r-1&1)==1)},getLengthInBits:function(){return this.length},putBit:function(t){var n=Math.floor(this.length/8);this.buffer.length<=n&&this.buffer.push(0),t&&(this.buffer[n]|=128>>>this.length%8),this.length++}},ay=e,ay}var iy,uk;function tI(){if(uk)return iy;uk=1;for(var e={glog:function(n){if(n<1)throw new Error("glog("+n+")");return e.LOG_TABLE[n]},gexp:function(n){for(;n<0;)n+=255;for(;n>=256;)n-=255;return e.EXP_TABLE[n]},EXP_TABLE:new Array(256),LOG_TABLE:new Array(256)},t=0;t<8;t++)e.EXP_TABLE[t]=1<=0;)l^=s.G15<=0;)l^=s.G18<>>=1;return l},getPatternPosition:function(o){return s.PATTERN_POSITION_TABLE[o-1]},getMask:function(o,l,u){switch(o){case r.PATTERN000:return(l+u)%2==0;case r.PATTERN001:return l%2==0;case r.PATTERN010:return u%3==0;case r.PATTERN011:return(l+u)%3==0;case r.PATTERN100:return(Math.floor(l/2)+Math.floor(u/3))%2==0;case r.PATTERN101:return l*u%2+l*u%3==0;case r.PATTERN110:return(l*u%2+l*u%3)%2==0;case r.PATTERN111:return(l*u%3+(l+u)%2)%2==0;default:throw new Error("bad maskPattern:"+o)}},getErrorCorrectPolynomial:function(o){for(var l=new t([1],0),u=0;u5&&(u+=3+h-5)}for(var d=0;d=7&&this.setupTypeNumber(u),this.dataCache==null&&(this.dataCache=o.createData(this.typeNumber,this.errorCorrectLevel,this.dataList)),this.mapData(this.dataCache,d)},l.setupPositionProbePattern=function(u,d){for(var f=-1;f<=7;f++)if(!(u+f<=-1||this.moduleCount<=u+f))for(var h=-1;h<=7;h++)d+h<=-1||this.moduleCount<=d+h||(0<=f&&f<=6&&(h==0||h==6)||0<=h&&h<=6&&(f==0||f==6)||2<=f&&f<=4&&2<=h&&h<=4?this.modules[u+f][d+h]=!0:this.modules[u+f][d+h]=!1)},l.getBestMaskPattern=function(){for(var u=0,d=0,f=0;f<8;f++){this.makeImpl(!0,f);var h=r.getLostPoint(this);(f==0||u>h)&&(u=h,d=f)}return d},l.createMovieClip=function(u,d,f){var h=u.createEmptyMovieClip(d,f),m=1;this.make();for(var g=0;g>f&1)==1;this.modules[Math.floor(f/3)][f%3+this.moduleCount-8-3]=h}for(var f=0;f<18;f++){var h=!u&&(d>>f&1)==1;this.modules[f%3+this.moduleCount-8-3][Math.floor(f/3)]=h}},l.setupTypeInfo=function(u,d){for(var f=this.errorCorrectLevel<<3|d,h=r.getBCHTypeInfo(f),m=0;m<15;m++){var g=!u&&(h>>m&1)==1;m<6?this.modules[m][8]=g:m<8?this.modules[m+1][8]=g:this.modules[this.moduleCount-15+m][8]=g}for(var m=0;m<15;m++){var g=!u&&(h>>m&1)==1;m<8?this.modules[8][this.moduleCount-m-1]=g:m<9?this.modules[8][15-m-1+1]=g:this.modules[8][15-m-1]=g}this.modules[this.moduleCount-8][8]=!u},l.mapData=function(u,d){for(var f=-1,h=this.moduleCount-1,m=7,g=0,x=this.moduleCount-1;x>0;x-=2)for(x==6&&x--;;){for(var b=0;b<2;b++)if(this.modules[h][x-b]==null){var w=!1;g>>m&1)==1);var C=r.getMask(d,h,x-b);C&&(w=!w),this.modules[h][x-b]=w,m--,m==-1&&(g++,m=7)}if(h+=f,h<0||this.moduleCount<=h){h-=f,f=-f;break}}},o.PAD0=236,o.PAD1=17,o.createData=function(u,d,f){for(var h=t.getRSBlocks(u,d),m=new n,g=0;gb*8)throw new Error("code length overflow. ("+m.getLengthInBits()+">"+b*8+")");for(m.getLengthInBits()+4<=b*8&&m.put(0,4);m.getLengthInBits()%8!=0;)m.putBit(!1);for(;!(m.getLengthInBits()>=b*8||(m.put(o.PAD0,8),m.getLengthInBits()>=b*8));)m.put(o.PAD1,8);return o.createBytes(m,h)},o.createBytes=function(u,d){for(var f=0,h=0,m=0,g=new Array(d.length),x=new Array(d.length),b=0;b=0?_.get(R):0}}for(var N=0,k=0;k=0||Object.prototype.hasOwnProperty.call(f,g)&&(m[g]=f[g]);return m}var u={bgColor:n.default.oneOfType([n.default.object,n.default.string]).isRequired,bgD:n.default.string.isRequired,fgColor:n.default.oneOfType([n.default.object,n.default.string]).isRequired,fgD:n.default.string.isRequired,size:n.default.number.isRequired,title:n.default.string,viewBoxSize:n.default.number.isRequired,xmlns:n.default.string},d=(0,r.forwardRef)(function(f,h){var m=f.bgColor,g=f.bgD,x=f.fgD,b=f.fgColor,w=f.size,C=f.title,k=f.viewBoxSize,j=f.xmlns,M=j===void 0?"http://www.w3.org/2000/svg":j,_=l(f,["bgColor","bgD","fgD","fgColor","size","title","viewBoxSize","xmlns"]);return s.default.createElement("svg",e({},_,{height:w,ref:h,viewBox:"0 0 "+k+" "+k,width:w,xmlns:M}),C?s.default.createElement("title",null,C):null,s.default.createElement("path",{d:g,fill:m}),s.default.createElement("path",{d:x,fill:b}))});return d.displayName="QRCodeSvg",d.propTypes=u,sp.default=d,sp}var gk;function TX(){if(gk)return wl;gk=1,Object.defineProperty(wl,"__esModule",{value:!0}),wl.QRCode=void 0;var e=Object.assign||function(w){for(var C=1;C=0||Object.prototype.hasOwnProperty.call(w,j)&&(k[j]=w[j]);return k}var x={bgColor:n.default.oneOfType([n.default.object,n.default.string]),fgColor:n.default.oneOfType([n.default.object,n.default.string]),level:n.default.string,size:n.default.number,value:n.default.string.isRequired},b=(0,u.forwardRef)(function(w,C){var k=w.bgColor,j=k===void 0?"#FFFFFF":k,M=w.fgColor,_=M===void 0?"#000000":M,R=w.level,N=R===void 0?"L":R,O=w.size,D=O===void 0?256:O,z=w.value,Q=g(w,["bgColor","fgColor","level","size","value"]),pe=new l.default(-1,s.default[N]);pe.addData(z),pe.make();var V=pe.modules;return d.default.createElement(h.default,e({},Q,{bgColor:j,bgD:V.map(function(G,W){return G.map(function(ie,re){return ie?"":"M "+re+" "+W+" l 1 0 0 1 -1 0 Z"}).join(" ")}).join(" "),fgColor:_,fgD:V.map(function(G,W){return G.map(function(ie,re){return ie?"M "+re+" "+W+" l 1 0 0 1 -1 0 Z":""}).join(" ")}).join(" "),ref:C,size:D,viewBoxSize:V.length}))});return wl.QRCode=b,b.displayName="QRCode",b.propTypes=x,wl.default=b,wl}var NX=TX();const MX=fd(NX),_X=jh("relative w-full rounded-lg border px-4 py-3 text-sm [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground [&>svg~*]:pl-7 space-y-1 [&_strong]:text-foreground",{variants:{variant:{default:"border-zinc-500/20 bg-zinc-50/50 dark:border-zinc-500/30 dark:bg-zinc-500/10 text-zinc-900 dark:text-zinc-300 [&>svg]:text-zinc-400 dark:[&>svg]:text-zinc-300",destructive:"border-red-500/20 bg-red-50/50 dark:border-red-500/30 dark:bg-red-500/10 text-red-900 dark:text-red-200 [&>svg]:text-red-600 dark:[&>svg]:text-red-400/80",warning:"border-amber-500/20 bg-amber-50/50 dark:border-amber-500/30 dark:bg-amber-500/10 text-amber-900 dark:text-amber-200 [&>svg]:text-amber-500",info:"border-sky-500/20 bg-sky-50/50 dark:border-sky-500/30 dark:bg-sky-500/10 text-sky-900 dark:text-sky-200 [&>svg]:text-sky-500",success:"border-emerald-500/20 bg-emerald-50/50 dark:border-emerald-500/30 dark:bg-emerald-500/10 text-emerald-900 dark:text-emerald-200 [&>svg]:text-emerald-600 dark:[&>svg]:text-emerald-400/80"}},defaultVariants:{variant:"default"}}),rI=y.forwardRef(({className:e,variant:t,...n},r)=>i.jsx("div",{ref:r,role:"alert",className:Ie(_X({variant:t}),e),...n}));rI.displayName="Alert";const sI=y.forwardRef(({className:e,...t},n)=>i.jsx("h5",{ref:n,className:Ie("font-medium leading-none tracking-tight",e),...t}));sI.displayName="AlertTitle";const RX=y.forwardRef(({className:e,...t},n)=>i.jsx("div",{ref:n,className:Ie("text-sm [&_p]:leading-relaxed",e),...t}));RX.displayName="AlertDescription";const On=({size:e=45,className:t,...n})=>i.jsx("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",height:"100vh"},children:i.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:e,height:e,...n,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:Ie("animate-spin",t),children:i.jsx("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})})});function PX(){const{t:e,i18n:t}=Ve(),n=new Intl.NumberFormat(t.language),[r,s]=y.useState(null),[o,l]=y.useState(""),u=dr(jn.TOKEN),{theme:d}=tc(),{connect:f,logout:h,restart:m}=Hh(),{instance:g,reloadInstance:x}=ct();y.useEffect(()=>{g&&(localStorage.setItem(jn.INSTANCE_ID,g.id),localStorage.setItem(jn.INSTANCE_NAME,g.name),localStorage.setItem(jn.INSTANCE_TOKEN,g.token))},[g]);const b=async()=>{await x()},w=async R=>{try{await m(R),await x()}catch(N){console.error("Error:",N)}},C=async R=>{try{await h(R),await x()}catch(N){console.error("Error:",N)}},k=async(R,N)=>{try{if(s(null),!u){console.error("Token not found.");return}if(N){const O=await f({instanceName:R,token:u,number:g?.number});l(O.pairingCode)}else{const O=await f({instanceName:R,token:u});s(O.code)}}catch(O){console.error("Error:",O)}},j=async()=>{s(null),l(""),await x()},M=y.useMemo(()=>g?{contacts:g._count?.Contact||0,chats:g._count?.Chat||0,messages:g._count?.Message||0}:{contacts:0,chats:0,messages:0},[g]),_=y.useMemo(()=>d==="dark"?"#fff":d==="light"?"#000":"#189d68",[d]);return g?i.jsxs("main",{className:"flex flex-col gap-8",children:[i.jsx("section",{children:i.jsxs(So,{children:[i.jsx(Co,{children:i.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[i.jsx("h2",{className:"break-all text-lg font-semibold",children:g.name}),i.jsx(l_,{status:g.connectionStatus})]})}),i.jsxs(Eo,{className:"flex flex-col items-start space-y-6",children:[i.jsx("div",{className:"flex w-full flex-1",children:i.jsx(c_,{token:g.token})}),g.profileName&&i.jsxs("div",{className:"flex flex-1 gap-2",children:[i.jsx(Ei,{children:i.jsx(ki,{src:g.profilePicUrl,alt:""})}),i.jsxs("div",{className:"space-y-1",children:[i.jsx("strong",{children:g.profileName}),i.jsx("p",{className:"break-all text-sm text-muted-foreground",children:g.ownerJid})]})]}),g.connectionStatus!=="open"&&i.jsxs(rI,{variant:"warning",className:"flex flex-wrap items-center justify-between gap-3",children:[i.jsx(sI,{className:"text-lg font-bold tracking-wide",children:e("instance.dashboard.alert")}),i.jsxs(Pt,{children:[i.jsx(Bt,{onClick:()=>k(g.name,!1),asChild:!0,children:i.jsx(se,{variant:"warning",children:e("instance.dashboard.button.qrcode.label")})}),i.jsxs(Nt,{onCloseAutoFocus:j,children:[i.jsx(Mt,{children:e("instance.dashboard.button.qrcode.title")}),i.jsx("div",{className:"flex items-center justify-center",children:r&&i.jsx(MX,{value:r,size:256,bgColor:"transparent",fgColor:_,className:"rounded-sm"})})]})]}),g.number&&i.jsxs(Pt,{children:[i.jsx(Bt,{className:"connect-code-button",onClick:()=>k(g.name,!0),children:e("instance.dashboard.button.pairingCode.label")}),i.jsx(Nt,{onCloseAutoFocus:j,children:i.jsx(Mt,{children:i.jsx(eo,{children:o?i.jsxs("div",{className:"py-3",children:[i.jsx("p",{className:"text-center",children:i.jsx("strong",{children:e("instance.dashboard.button.pairingCode.title")})}),i.jsxs("p",{className:"pairing-code text-center",children:[o.substring(0,4),"-",o.substring(4,8)]})]}):i.jsx(On,{})})})})]})]})]}),i.jsxs(Vh,{className:"flex flex-wrap items-center justify-end gap-3",children:[i.jsx(se,{variant:"outline",className:"refresh-button",size:"icon",onClick:b,children:i.jsx(Ip,{size:"20"})}),i.jsx(se,{className:"action-button",variant:"secondary",onClick:()=>w(g.name),children:e("instance.dashboard.button.restart").toUpperCase()}),i.jsx(se,{variant:"destructive",onClick:()=>C(g.name),disabled:g.connectionStatus==="close",children:e("instance.dashboard.button.disconnect").toUpperCase()})]})]})}),i.jsxs("section",{className:"grid grid-cols-[repeat(auto-fit,_minmax(15rem,_1fr))] gap-6",children:[i.jsxs(So,{className:"instance-card",children:[i.jsx(Co,{children:i.jsxs(gi,{className:"flex items-center gap-2",children:[i.jsx(pT,{size:"20"}),e("instance.dashboard.contacts")]})}),i.jsx(Eo,{children:n.format(M.contacts)})]}),i.jsxs(So,{className:"instance-card",children:[i.jsx(Co,{children:i.jsxs(gi,{className:"flex items-center gap-2",children:[i.jsx(jB,{size:"20"}),e("instance.dashboard.chats")]})}),i.jsx(Eo,{children:n.format(M.chats)})]}),i.jsxs(So,{className:"instance-card",children:[i.jsx(Co,{children:i.jsxs(gi,{className:"flex items-center gap-2",children:[i.jsx(Bl,{size:"20"}),e("instance.dashboard.messages")]})}),i.jsx(Eo,{children:n.format(M.messages)})]})]})]}):i.jsx(On,{})}var OX="Separator",mk="horizontal",IX=["horizontal","vertical"],oI=y.forwardRef((e,t)=>{const{decorative:n,orientation:r=mk,...s}=e,o=AX(r)?r:mk,u=n?{role:"none"}:{"aria-orientation":o==="vertical"?o:void 0,role:"separator"};return i.jsx(rt.div,{"data-orientation":o,...u,...s,ref:t})});oI.displayName=OX;function AX(e){return IX.includes(e)}var aI=oI;const $t=y.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},s)=>i.jsx(aI,{ref:s,decorative:n,orientation:t,className:Ie("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));$t.displayName=aI.displayName;const DX=e=>["dify","fetchDify",JSON.stringify(e)],FX=async({instanceName:e,token:t})=>(await Ee.get(`/dify/find/${e}`,{headers:{apikey:t}})).data,iI=e=>{const{instanceName:t,token:n,...r}=e;return mt({...r,queryKey:DX({instanceName:t,token:n}),queryFn:()=>FX({instanceName:t,token:n}),enabled:!!t&&(e.enabled??!0)})},LX=async({instanceName:e,token:t,data:n})=>(await Ee.post(`/dify/create/${e}`,n,{headers:{apikey:t}})).data,$X=async({instanceName:e,difyId:t,data:n})=>(await Ee.put(`/dify/update/${t}/${e}`,n)).data,BX=async({instanceName:e,difyId:t})=>(await Ee.delete(`/dify/delete/${t}/${e}`)).data,zX=async({instanceName:e,token:t,data:n})=>(await Ee.post(`/dify/settings/${e}`,n,{headers:{apikey:t}})).data,UX=async({instanceName:e,token:t,remoteJid:n,status:r})=>(await Ee.post(`/dify/changeStatus/${e}`,{remoteJid:n,status:r},{headers:{apikey:t}})).data;function vg(){const e=nt(zX,{invalidateKeys:[["dify","fetchDefaultSettings"]]}),t=nt(UX,{invalidateKeys:[["dify","getDify"],["dify","fetchSessions"]]}),n=nt(BX,{invalidateKeys:[["dify","getDify"],["dify","fetchDify"],["dify","fetchSessions"]]}),r=nt($X,{invalidateKeys:[["dify","getDify"],["dify","fetchDify"],["dify","fetchSessions"]]}),s=nt(LX,{invalidateKeys:[["dify","fetchDify"]]});return{setDefaultSettingsDify:e,changeStatusDify:t,deleteDify:n,updateDify:r,createDify:s}}const VX=e=>["dify","fetchDefaultSettings",JSON.stringify(e)],HX=async({instanceName:e,token:t})=>(await Ee.get(`/dify/fetchSettings/${e}`,{headers:{apikey:t}})).data,qX=e=>{const{instanceName:t,token:n,...r}=e;return mt({...r,queryKey:VX({instanceName:t,token:n}),queryFn:()=>HX({instanceName:t,token:n}),enabled:!!t})},KX=P.object({expire:P.string(),keywordFinish:P.string(),delayMessage:P.string(),unknownMessage:P.string(),listeningFromMe:P.boolean(),stopBotFromMe:P.boolean(),keepOpen:P.boolean(),debounceTime:P.string(),ignoreJids:P.array(P.string()).default([]),difyIdFallback:P.union([P.null(),P.string()]).optional(),splitMessages:P.boolean(),timePerChar:P.string()});function WX(){const{t:e}=Ve(),{instance:t}=ct(),{setDefaultSettingsDify:n}=vg(),[r,s]=y.useState(!1),{data:o,refetch:l}=iI({instanceName:t?.name,token:t?.token,enabled:r}),{data:u,refetch:d}=qX({instanceName:t?.name,token:t?.token}),f=on({resolver:an(KX),defaultValues:{expire:"0",keywordFinish:e("dify.form.examples.keywordFinish"),delayMessage:"1000",unknownMessage:e("dify.form.examples.unknownMessage"),listeningFromMe:!1,stopBotFromMe:!1,keepOpen:!1,debounceTime:"0",ignoreJids:[],difyIdFallback:void 0,splitMessages:!1,timePerChar:"0"}});y.useEffect(()=>{u&&f.reset({expire:u?.expire?u.expire.toString():"0",keywordFinish:u.keywordFinish,delayMessage:u.delayMessage?u.delayMessage.toString():"0",unknownMessage:u.unknownMessage,listeningFromMe:u.listeningFromMe,stopBotFromMe:u.stopBotFromMe,keepOpen:u.keepOpen,debounceTime:u.debounceTime?u.debounceTime.toString():"0",ignoreJids:u.ignoreJids,difyIdFallback:u.difyIdFallback,splitMessages:u.splitMessages,timePerChar:u.timePerChar?u.timePerChar.toString():"0"})},[u]);const h=async g=>{try{if(!t||!t.name)throw new Error("instance not found.");const x={expire:parseInt(g.expire),keywordFinish:g.keywordFinish,delayMessage:parseInt(g.delayMessage),unknownMessage:g.unknownMessage,listeningFromMe:g.listeningFromMe,stopBotFromMe:g.stopBotFromMe,keepOpen:g.keepOpen,debounceTime:parseInt(g.debounceTime),difyIdFallback:g.difyIdFallback||void 0,ignoreJids:g.ignoreJids,splitMessages:g.splitMessages,timePerChar:parseInt(g.timePerChar)};await n({instanceName:t.name,token:t.token,data:x}),me.success(e("dify.toast.defaultSettings.success"))}catch(x){console.error("Error:",x),me.error(`Error: ${x?.response?.data?.response?.message}`)}};function m(){d(),l()}return i.jsxs(Pt,{open:r,onOpenChange:s,children:[i.jsx(Bt,{asChild:!0,children:i.jsxs(se,{variant:"secondary",size:"sm",children:[i.jsx(Oo,{size:16,className:"mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:e("dify.defaultSettings")})]})}),i.jsxs(Nt,{className:"overflow-y-auto sm:max-h-[600px] sm:max-w-[740px]",onCloseAutoFocus:m,children:[i.jsx(Mt,{children:i.jsx(zt,{children:e("dify.defaultSettings")})}),i.jsx(Gn,{...f,children:i.jsxs("form",{className:"w-full space-y-6",onSubmit:f.handleSubmit(h),children:[i.jsx("div",{children:i.jsxs("div",{className:"space-y-4",children:[i.jsx(Jt,{name:"difyIdFallback",label:e("dify.form.difyIdFallback.label"),options:o?.filter(g=>!!g.id).map(g=>({label:g.description,value:g.id}))??[]}),i.jsx(le,{name:"expire",label:e("dify.form.expire.label"),children:i.jsx(ne,{type:"number"})}),i.jsx(le,{name:"keywordFinish",label:e("dify.form.keywordFinish.label"),children:i.jsx(ne,{})}),i.jsx(le,{name:"delayMessage",label:e("dify.form.delayMessage.label"),children:i.jsx(ne,{type:"number"})}),i.jsx(le,{name:"unknownMessage",label:e("dify.form.unknownMessage.label"),children:i.jsx(ne,{})}),i.jsx(Pe,{name:"listeningFromMe",label:e("dify.form.listeningFromMe.label"),reverse:!0}),i.jsx(Pe,{name:"stopBotFromMe",label:e("dify.form.stopBotFromMe.label"),reverse:!0}),i.jsx(Pe,{name:"keepOpen",label:e("dify.form.keepOpen.label"),reverse:!0}),i.jsx(le,{name:"debounceTime",label:e("dify.form.debounceTime.label"),children:i.jsx(ne,{type:"number"})}),i.jsx(Pe,{name:"splitMessages",label:e("dify.form.splitMessages.label"),reverse:!0}),i.jsx(le,{name:"timePerChar",label:e("dify.form.timePerChar.label"),children:i.jsx(ne,{type:"number"})}),i.jsx(Da,{name:"ignoreJids",label:e("dify.form.ignoreJids.label"),placeholder:e("dify.form.ignoreJids.placeholder")})]})}),i.jsx(Yt,{children:i.jsx(se,{type:"submit",children:e("dify.button.save")})})]})})]})]})}/** * table-core * * Copyright (c) TanStack * * This source code is licensed under the MIT license found in the * LICENSE.md file in the root directory of this source tree. * * @license MIT */function ma(e,t){return typeof e=="function"?e(t):e}function qr(e,t){return n=>{t.setState(r=>({...r,[e]:ma(n,r[e])}))}}function yg(e){return e instanceof Function}function GX(e){return Array.isArray(e)&&e.every(t=>typeof t=="number")}function lI(e,t){const n=[],r=s=>{s.forEach(o=>{n.push(o);const l=t(o);l!=null&&l.length&&r(l)})};return r(e),n}function ot(e,t,n){let r=[],s;return o=>{let l;n.key&&n.debug&&(l=Date.now());const u=e(o);if(!(u.length!==r.length||u.some((h,m)=>r[m]!==h)))return s;r=u;let f;if(n.key&&n.debug&&(f=Date.now()),s=t(...u),n==null||n.onChange==null||n.onChange(s),n.key&&n.debug&&n!=null&&n.debug()){const h=Math.round((Date.now()-l)*100)/100,m=Math.round((Date.now()-f)*100)/100,g=m/16,x=(b,w)=>{for(b=String(b);b.length{var s;return(s=e?.debugAll)!=null?s:e[t]},key:!1,onChange:r}}function JX(e,t,n,r){const s=()=>{var l;return(l=o.getValue())!=null?l:e.options.renderFallbackValue},o={id:`${t.id}_${n.id}`,row:t,column:n,getValue:()=>t.getValue(r),renderValue:s,getContext:ot(()=>[e,n,t,o],(l,u,d,f)=>({table:l,column:u,row:d,cell:f,getValue:f.getValue,renderValue:f.renderValue}),at(e.options,"debugCells"))};return e._features.forEach(l=>{l.createCell==null||l.createCell(o,n,t,e)},{}),o}function QX(e,t,n,r){var s,o;const u={...e._getDefaultColumnDef(),...t},d=u.accessorKey;let f=(s=(o=u.id)!=null?o:d?typeof String.prototype.replaceAll=="function"?d.replaceAll(".","_"):d.replace(/\./g,"_"):void 0)!=null?s:typeof u.header=="string"?u.header:void 0,h;if(u.accessorFn?h=u.accessorFn:d&&(d.includes(".")?h=g=>{let x=g;for(const w of d.split(".")){var b;x=(b=x)==null?void 0:b[w]}return x}:h=g=>g[u.accessorKey]),!f)throw new Error;let m={id:`${String(f)}`,accessorFn:h,parent:r,depth:n,columnDef:u,columns:[],getFlatColumns:ot(()=>[!0],()=>{var g;return[m,...(g=m.columns)==null?void 0:g.flatMap(x=>x.getFlatColumns())]},at(e.options,"debugColumns")),getLeafColumns:ot(()=>[e._getOrderColumnsFn()],g=>{var x;if((x=m.columns)!=null&&x.length){let b=m.columns.flatMap(w=>w.getLeafColumns());return g(b)}return[m]},at(e.options,"debugColumns"))};for(const g of e._features)g.createColumn==null||g.createColumn(m,e);return m}const nr="debugHeaders";function vk(e,t,n){var r;let o={id:(r=n.id)!=null?r:t.id,column:t,index:n.index,isPlaceholder:!!n.isPlaceholder,placeholderId:n.placeholderId,depth:n.depth,subHeaders:[],colSpan:0,rowSpan:0,headerGroup:null,getLeafHeaders:()=>{const l=[],u=d=>{d.subHeaders&&d.subHeaders.length&&d.subHeaders.map(u),l.push(d)};return u(o),l},getContext:()=>({table:e,header:o,column:t})};return e._features.forEach(l=>{l.createHeader==null||l.createHeader(o,e)}),o}const ZX={createTable:e=>{e.getHeaderGroups=ot(()=>[e.getAllColumns(),e.getVisibleLeafColumns(),e.getState().columnPinning.left,e.getState().columnPinning.right],(t,n,r,s)=>{var o,l;const u=(o=r?.map(m=>n.find(g=>g.id===m)).filter(Boolean))!=null?o:[],d=(l=s?.map(m=>n.find(g=>g.id===m)).filter(Boolean))!=null?l:[],f=n.filter(m=>!(r!=null&&r.includes(m.id))&&!(s!=null&&s.includes(m.id)));return op(t,[...u,...f,...d],e)},at(e.options,nr)),e.getCenterHeaderGroups=ot(()=>[e.getAllColumns(),e.getVisibleLeafColumns(),e.getState().columnPinning.left,e.getState().columnPinning.right],(t,n,r,s)=>(n=n.filter(o=>!(r!=null&&r.includes(o.id))&&!(s!=null&&s.includes(o.id))),op(t,n,e,"center")),at(e.options,nr)),e.getLeftHeaderGroups=ot(()=>[e.getAllColumns(),e.getVisibleLeafColumns(),e.getState().columnPinning.left],(t,n,r)=>{var s;const o=(s=r?.map(l=>n.find(u=>u.id===l)).filter(Boolean))!=null?s:[];return op(t,o,e,"left")},at(e.options,nr)),e.getRightHeaderGroups=ot(()=>[e.getAllColumns(),e.getVisibleLeafColumns(),e.getState().columnPinning.right],(t,n,r)=>{var s;const o=(s=r?.map(l=>n.find(u=>u.id===l)).filter(Boolean))!=null?s:[];return op(t,o,e,"right")},at(e.options,nr)),e.getFooterGroups=ot(()=>[e.getHeaderGroups()],t=>[...t].reverse(),at(e.options,nr)),e.getLeftFooterGroups=ot(()=>[e.getLeftHeaderGroups()],t=>[...t].reverse(),at(e.options,nr)),e.getCenterFooterGroups=ot(()=>[e.getCenterHeaderGroups()],t=>[...t].reverse(),at(e.options,nr)),e.getRightFooterGroups=ot(()=>[e.getRightHeaderGroups()],t=>[...t].reverse(),at(e.options,nr)),e.getFlatHeaders=ot(()=>[e.getHeaderGroups()],t=>t.map(n=>n.headers).flat(),at(e.options,nr)),e.getLeftFlatHeaders=ot(()=>[e.getLeftHeaderGroups()],t=>t.map(n=>n.headers).flat(),at(e.options,nr)),e.getCenterFlatHeaders=ot(()=>[e.getCenterHeaderGroups()],t=>t.map(n=>n.headers).flat(),at(e.options,nr)),e.getRightFlatHeaders=ot(()=>[e.getRightHeaderGroups()],t=>t.map(n=>n.headers).flat(),at(e.options,nr)),e.getCenterLeafHeaders=ot(()=>[e.getCenterFlatHeaders()],t=>t.filter(n=>{var r;return!((r=n.subHeaders)!=null&&r.length)}),at(e.options,nr)),e.getLeftLeafHeaders=ot(()=>[e.getLeftFlatHeaders()],t=>t.filter(n=>{var r;return!((r=n.subHeaders)!=null&&r.length)}),at(e.options,nr)),e.getRightLeafHeaders=ot(()=>[e.getRightFlatHeaders()],t=>t.filter(n=>{var r;return!((r=n.subHeaders)!=null&&r.length)}),at(e.options,nr)),e.getLeafHeaders=ot(()=>[e.getLeftHeaderGroups(),e.getCenterHeaderGroups(),e.getRightHeaderGroups()],(t,n,r)=>{var s,o,l,u,d,f;return[...(s=(o=t[0])==null?void 0:o.headers)!=null?s:[],...(l=(u=n[0])==null?void 0:u.headers)!=null?l:[],...(d=(f=r[0])==null?void 0:f.headers)!=null?d:[]].map(h=>h.getLeafHeaders()).flat()},at(e.options,nr))}};function op(e,t,n,r){var s,o;let l=0;const u=function(g,x){x===void 0&&(x=1),l=Math.max(l,x),g.filter(b=>b.getIsVisible()).forEach(b=>{var w;(w=b.columns)!=null&&w.length&&u(b.columns,x+1)},0)};u(e);let d=[];const f=(g,x)=>{const b={depth:x,id:[r,`${x}`].filter(Boolean).join("_"),headers:[]},w=[];g.forEach(C=>{const k=[...w].reverse()[0],j=C.column.depth===b.depth;let M,_=!1;if(j&&C.column.parent?M=C.column.parent:(M=C.column,_=!0),k&&k?.column===M)k.subHeaders.push(C);else{const R=vk(n,M,{id:[r,x,M.id,C?.id].filter(Boolean).join("_"),isPlaceholder:_,placeholderId:_?`${w.filter(N=>N.column===M).length}`:void 0,depth:x,index:w.length});R.subHeaders.push(C),w.push(R)}b.headers.push(C),C.headerGroup=b}),d.push(b),x>0&&f(w,x-1)},h=t.map((g,x)=>vk(n,g,{depth:l,index:x}));f(h,l-1),d.reverse();const m=g=>g.filter(b=>b.column.getIsVisible()).map(b=>{let w=0,C=0,k=[0];b.subHeaders&&b.subHeaders.length?(k=[],m(b.subHeaders).forEach(M=>{let{colSpan:_,rowSpan:R}=M;w+=_,k.push(R)})):w=1;const j=Math.min(...k);return C=C+j,b.colSpan=w,b.rowSpan=C,{colSpan:w,rowSpan:C}});return m((s=(o=d[0])==null?void 0:o.headers)!=null?s:[]),d}const bg=(e,t,n,r,s,o,l)=>{let u={id:t,index:r,original:n,depth:s,parentId:l,_valuesCache:{},_uniqueValuesCache:{},getValue:d=>{if(u._valuesCache.hasOwnProperty(d))return u._valuesCache[d];const f=e.getColumn(d);if(f!=null&&f.accessorFn)return u._valuesCache[d]=f.accessorFn(u.original,r),u._valuesCache[d]},getUniqueValues:d=>{if(u._uniqueValuesCache.hasOwnProperty(d))return u._uniqueValuesCache[d];const f=e.getColumn(d);if(f!=null&&f.accessorFn)return f.columnDef.getUniqueValues?(u._uniqueValuesCache[d]=f.columnDef.getUniqueValues(u.original,r),u._uniqueValuesCache[d]):(u._uniqueValuesCache[d]=[u.getValue(d)],u._uniqueValuesCache[d])},renderValue:d=>{var f;return(f=u.getValue(d))!=null?f:e.options.renderFallbackValue},subRows:o??[],getLeafRows:()=>lI(u.subRows,d=>d.subRows),getParentRow:()=>u.parentId?e.getRow(u.parentId,!0):void 0,getParentRows:()=>{let d=[],f=u;for(;;){const h=f.getParentRow();if(!h)break;d.push(h),f=h}return d.reverse()},getAllCells:ot(()=>[e.getAllLeafColumns()],d=>d.map(f=>JX(e,u,f,f.id)),at(e.options,"debugRows")),_getAllCellsByColumnId:ot(()=>[u.getAllCells()],d=>d.reduce((f,h)=>(f[h.column.id]=h,f),{}),at(e.options,"debugRows"))};for(let d=0;d{e._getFacetedRowModel=t.options.getFacetedRowModel&&t.options.getFacetedRowModel(t,e.id),e.getFacetedRowModel=()=>e._getFacetedRowModel?e._getFacetedRowModel():t.getPreFilteredRowModel(),e._getFacetedUniqueValues=t.options.getFacetedUniqueValues&&t.options.getFacetedUniqueValues(t,e.id),e.getFacetedUniqueValues=()=>e._getFacetedUniqueValues?e._getFacetedUniqueValues():new Map,e._getFacetedMinMaxValues=t.options.getFacetedMinMaxValues&&t.options.getFacetedMinMaxValues(t,e.id),e.getFacetedMinMaxValues=()=>{if(e._getFacetedMinMaxValues)return e._getFacetedMinMaxValues()}}},cI=(e,t,n)=>{var r;const s=n.toLowerCase();return!!(!((r=e.getValue(t))==null||(r=r.toString())==null||(r=r.toLowerCase())==null)&&r.includes(s))};cI.autoRemove=e=>Ts(e);const uI=(e,t,n)=>{var r;return!!(!((r=e.getValue(t))==null||(r=r.toString())==null)&&r.includes(n))};uI.autoRemove=e=>Ts(e);const dI=(e,t,n)=>{var r;return((r=e.getValue(t))==null||(r=r.toString())==null?void 0:r.toLowerCase())===n?.toLowerCase()};dI.autoRemove=e=>Ts(e);const fI=(e,t,n)=>{var r;return(r=e.getValue(t))==null?void 0:r.includes(n)};fI.autoRemove=e=>Ts(e)||!(e!=null&&e.length);const pI=(e,t,n)=>!n.some(r=>{var s;return!((s=e.getValue(t))!=null&&s.includes(r))});pI.autoRemove=e=>Ts(e)||!(e!=null&&e.length);const hI=(e,t,n)=>n.some(r=>{var s;return(s=e.getValue(t))==null?void 0:s.includes(r)});hI.autoRemove=e=>Ts(e)||!(e!=null&&e.length);const gI=(e,t,n)=>e.getValue(t)===n;gI.autoRemove=e=>Ts(e);const mI=(e,t,n)=>e.getValue(t)==n;mI.autoRemove=e=>Ts(e);const aw=(e,t,n)=>{let[r,s]=n;const o=e.getValue(t);return o>=r&&o<=s};aw.resolveFilterValue=e=>{let[t,n]=e,r=typeof t!="number"?parseFloat(t):t,s=typeof n!="number"?parseFloat(n):n,o=t===null||Number.isNaN(r)?-1/0:r,l=n===null||Number.isNaN(s)?1/0:s;if(o>l){const u=o;o=l,l=u}return[o,l]};aw.autoRemove=e=>Ts(e)||Ts(e[0])&&Ts(e[1]);const yo={includesString:cI,includesStringSensitive:uI,equalsString:dI,arrIncludes:fI,arrIncludesAll:pI,arrIncludesSome:hI,equals:gI,weakEquals:mI,inNumberRange:aw};function Ts(e){return e==null||e===""}const XX={getDefaultColumnDef:()=>({filterFn:"auto"}),getInitialState:e=>({columnFilters:[],...e}),getDefaultOptions:e=>({onColumnFiltersChange:qr("columnFilters",e),filterFromLeafRows:!1,maxLeafRowFilterDepth:100}),createColumn:(e,t)=>{e.getAutoFilterFn=()=>{const n=t.getCoreRowModel().flatRows[0],r=n?.getValue(e.id);return typeof r=="string"?yo.includesString:typeof r=="number"?yo.inNumberRange:typeof r=="boolean"||r!==null&&typeof r=="object"?yo.equals:Array.isArray(r)?yo.arrIncludes:yo.weakEquals},e.getFilterFn=()=>{var n,r;return yg(e.columnDef.filterFn)?e.columnDef.filterFn:e.columnDef.filterFn==="auto"?e.getAutoFilterFn():(n=(r=t.options.filterFns)==null?void 0:r[e.columnDef.filterFn])!=null?n:yo[e.columnDef.filterFn]},e.getCanFilter=()=>{var n,r,s;return((n=e.columnDef.enableColumnFilter)!=null?n:!0)&&((r=t.options.enableColumnFilters)!=null?r:!0)&&((s=t.options.enableFilters)!=null?s:!0)&&!!e.accessorFn},e.getIsFiltered=()=>e.getFilterIndex()>-1,e.getFilterValue=()=>{var n;return(n=t.getState().columnFilters)==null||(n=n.find(r=>r.id===e.id))==null?void 0:n.value},e.getFilterIndex=()=>{var n,r;return(n=(r=t.getState().columnFilters)==null?void 0:r.findIndex(s=>s.id===e.id))!=null?n:-1},e.setFilterValue=n=>{t.setColumnFilters(r=>{const s=e.getFilterFn(),o=r?.find(h=>h.id===e.id),l=ma(n,o?o.value:void 0);if(yk(s,l,e)){var u;return(u=r?.filter(h=>h.id!==e.id))!=null?u:[]}const d={id:e.id,value:l};if(o){var f;return(f=r?.map(h=>h.id===e.id?d:h))!=null?f:[]}return r!=null&&r.length?[...r,d]:[d]})}},createRow:(e,t)=>{e.columnFilters={},e.columnFiltersMeta={}},createTable:e=>{e.setColumnFilters=t=>{const n=e.getAllLeafColumns(),r=s=>{var o;return(o=ma(t,s))==null?void 0:o.filter(l=>{const u=n.find(d=>d.id===l.id);if(u){const d=u.getFilterFn();if(yk(d,l.value,u))return!1}return!0})};e.options.onColumnFiltersChange==null||e.options.onColumnFiltersChange(r)},e.resetColumnFilters=t=>{var n,r;e.setColumnFilters(t?[]:(n=(r=e.initialState)==null?void 0:r.columnFilters)!=null?n:[])},e.getPreFilteredRowModel=()=>e.getCoreRowModel(),e.getFilteredRowModel=()=>(!e._getFilteredRowModel&&e.options.getFilteredRowModel&&(e._getFilteredRowModel=e.options.getFilteredRowModel(e)),e.options.manualFiltering||!e._getFilteredRowModel?e.getPreFilteredRowModel():e._getFilteredRowModel())}};function yk(e,t,n){return(e&&e.autoRemove?e.autoRemove(t,n):!1)||typeof t>"u"||typeof t=="string"&&!t}const eee=(e,t,n)=>n.reduce((r,s)=>{const o=s.getValue(e);return r+(typeof o=="number"?o:0)},0),tee=(e,t,n)=>{let r;return n.forEach(s=>{const o=s.getValue(e);o!=null&&(r>o||r===void 0&&o>=o)&&(r=o)}),r},nee=(e,t,n)=>{let r;return n.forEach(s=>{const o=s.getValue(e);o!=null&&(r=o)&&(r=o)}),r},ree=(e,t,n)=>{let r,s;return n.forEach(o=>{const l=o.getValue(e);l!=null&&(r===void 0?l>=l&&(r=s=l):(r>l&&(r=l),s{let n=0,r=0;if(t.forEach(s=>{let o=s.getValue(e);o!=null&&(o=+o)>=o&&(++n,r+=o)}),n)return r/n},oee=(e,t)=>{if(!t.length)return;const n=t.map(o=>o.getValue(e));if(!GX(n))return;if(n.length===1)return n[0];const r=Math.floor(n.length/2),s=n.sort((o,l)=>o-l);return n.length%2!==0?s[r]:(s[r-1]+s[r])/2},aee=(e,t)=>Array.from(new Set(t.map(n=>n.getValue(e))).values()),iee=(e,t)=>new Set(t.map(n=>n.getValue(e))).size,lee=(e,t)=>t.length,dy={sum:eee,min:tee,max:nee,extent:ree,mean:see,median:oee,unique:aee,uniqueCount:iee,count:lee},cee={getDefaultColumnDef:()=>({aggregatedCell:e=>{var t,n;return(t=(n=e.getValue())==null||n.toString==null?void 0:n.toString())!=null?t:null},aggregationFn:"auto"}),getInitialState:e=>({grouping:[],...e}),getDefaultOptions:e=>({onGroupingChange:qr("grouping",e),groupedColumnMode:"reorder"}),createColumn:(e,t)=>{e.toggleGrouping=()=>{t.setGrouping(n=>n!=null&&n.includes(e.id)?n.filter(r=>r!==e.id):[...n??[],e.id])},e.getCanGroup=()=>{var n,r;return((n=e.columnDef.enableGrouping)!=null?n:!0)&&((r=t.options.enableGrouping)!=null?r:!0)&&(!!e.accessorFn||!!e.columnDef.getGroupingValue)},e.getIsGrouped=()=>{var n;return(n=t.getState().grouping)==null?void 0:n.includes(e.id)},e.getGroupedIndex=()=>{var n;return(n=t.getState().grouping)==null?void 0:n.indexOf(e.id)},e.getToggleGroupingHandler=()=>{const n=e.getCanGroup();return()=>{n&&e.toggleGrouping()}},e.getAutoAggregationFn=()=>{const n=t.getCoreRowModel().flatRows[0],r=n?.getValue(e.id);if(typeof r=="number")return dy.sum;if(Object.prototype.toString.call(r)==="[object Date]")return dy.extent},e.getAggregationFn=()=>{var n,r;if(!e)throw new Error;return yg(e.columnDef.aggregationFn)?e.columnDef.aggregationFn:e.columnDef.aggregationFn==="auto"?e.getAutoAggregationFn():(n=(r=t.options.aggregationFns)==null?void 0:r[e.columnDef.aggregationFn])!=null?n:dy[e.columnDef.aggregationFn]}},createTable:e=>{e.setGrouping=t=>e.options.onGroupingChange==null?void 0:e.options.onGroupingChange(t),e.resetGrouping=t=>{var n,r;e.setGrouping(t?[]:(n=(r=e.initialState)==null?void 0:r.grouping)!=null?n:[])},e.getPreGroupedRowModel=()=>e.getFilteredRowModel(),e.getGroupedRowModel=()=>(!e._getGroupedRowModel&&e.options.getGroupedRowModel&&(e._getGroupedRowModel=e.options.getGroupedRowModel(e)),e.options.manualGrouping||!e._getGroupedRowModel?e.getPreGroupedRowModel():e._getGroupedRowModel())},createRow:(e,t)=>{e.getIsGrouped=()=>!!e.groupingColumnId,e.getGroupingValue=n=>{if(e._groupingValuesCache.hasOwnProperty(n))return e._groupingValuesCache[n];const r=t.getColumn(n);return r!=null&&r.columnDef.getGroupingValue?(e._groupingValuesCache[n]=r.columnDef.getGroupingValue(e.original),e._groupingValuesCache[n]):e.getValue(n)},e._groupingValuesCache={}},createCell:(e,t,n,r)=>{e.getIsGrouped=()=>t.getIsGrouped()&&t.id===n.groupingColumnId,e.getIsPlaceholder=()=>!e.getIsGrouped()&&t.getIsGrouped(),e.getIsAggregated=()=>{var s;return!e.getIsGrouped()&&!e.getIsPlaceholder()&&!!((s=n.subRows)!=null&&s.length)}}};function uee(e,t,n){if(!(t!=null&&t.length)||!n)return e;const r=e.filter(o=>!t.includes(o.id));return n==="remove"?r:[...t.map(o=>e.find(l=>l.id===o)).filter(Boolean),...r]}const dee={getInitialState:e=>({columnOrder:[],...e}),getDefaultOptions:e=>({onColumnOrderChange:qr("columnOrder",e)}),createColumn:(e,t)=>{e.getIndex=ot(n=>[Ru(t,n)],n=>n.findIndex(r=>r.id===e.id),at(t.options,"debugColumns")),e.getIsFirstColumn=n=>{var r;return((r=Ru(t,n)[0])==null?void 0:r.id)===e.id},e.getIsLastColumn=n=>{var r;const s=Ru(t,n);return((r=s[s.length-1])==null?void 0:r.id)===e.id}},createTable:e=>{e.setColumnOrder=t=>e.options.onColumnOrderChange==null?void 0:e.options.onColumnOrderChange(t),e.resetColumnOrder=t=>{var n;e.setColumnOrder(t?[]:(n=e.initialState.columnOrder)!=null?n:[])},e._getOrderColumnsFn=ot(()=>[e.getState().columnOrder,e.getState().grouping,e.options.groupedColumnMode],(t,n,r)=>s=>{let o=[];if(!(t!=null&&t.length))o=s;else{const l=[...t],u=[...s];for(;u.length&&l.length;){const d=l.shift(),f=u.findIndex(h=>h.id===d);f>-1&&o.push(u.splice(f,1)[0])}o=[...o,...u]}return uee(o,n,r)},at(e.options,"debugTable"))}},fy=()=>({left:[],right:[]}),fee={getInitialState:e=>({columnPinning:fy(),...e}),getDefaultOptions:e=>({onColumnPinningChange:qr("columnPinning",e)}),createColumn:(e,t)=>{e.pin=n=>{const r=e.getLeafColumns().map(s=>s.id).filter(Boolean);t.setColumnPinning(s=>{var o,l;if(n==="right"){var u,d;return{left:((u=s?.left)!=null?u:[]).filter(m=>!(r!=null&&r.includes(m))),right:[...((d=s?.right)!=null?d:[]).filter(m=>!(r!=null&&r.includes(m))),...r]}}if(n==="left"){var f,h;return{left:[...((f=s?.left)!=null?f:[]).filter(m=>!(r!=null&&r.includes(m))),...r],right:((h=s?.right)!=null?h:[]).filter(m=>!(r!=null&&r.includes(m)))}}return{left:((o=s?.left)!=null?o:[]).filter(m=>!(r!=null&&r.includes(m))),right:((l=s?.right)!=null?l:[]).filter(m=>!(r!=null&&r.includes(m)))}})},e.getCanPin=()=>e.getLeafColumns().some(r=>{var s,o,l;return((s=r.columnDef.enablePinning)!=null?s:!0)&&((o=(l=t.options.enableColumnPinning)!=null?l:t.options.enablePinning)!=null?o:!0)}),e.getIsPinned=()=>{const n=e.getLeafColumns().map(u=>u.id),{left:r,right:s}=t.getState().columnPinning,o=n.some(u=>r?.includes(u)),l=n.some(u=>s?.includes(u));return o?"left":l?"right":!1},e.getPinnedIndex=()=>{var n,r;const s=e.getIsPinned();return s?(n=(r=t.getState().columnPinning)==null||(r=r[s])==null?void 0:r.indexOf(e.id))!=null?n:-1:0}},createRow:(e,t)=>{e.getCenterVisibleCells=ot(()=>[e._getAllVisibleCells(),t.getState().columnPinning.left,t.getState().columnPinning.right],(n,r,s)=>{const o=[...r??[],...s??[]];return n.filter(l=>!o.includes(l.column.id))},at(t.options,"debugRows")),e.getLeftVisibleCells=ot(()=>[e._getAllVisibleCells(),t.getState().columnPinning.left],(n,r)=>(r??[]).map(o=>n.find(l=>l.column.id===o)).filter(Boolean).map(o=>({...o,position:"left"})),at(t.options,"debugRows")),e.getRightVisibleCells=ot(()=>[e._getAllVisibleCells(),t.getState().columnPinning.right],(n,r)=>(r??[]).map(o=>n.find(l=>l.column.id===o)).filter(Boolean).map(o=>({...o,position:"right"})),at(t.options,"debugRows"))},createTable:e=>{e.setColumnPinning=t=>e.options.onColumnPinningChange==null?void 0:e.options.onColumnPinningChange(t),e.resetColumnPinning=t=>{var n,r;return e.setColumnPinning(t?fy():(n=(r=e.initialState)==null?void 0:r.columnPinning)!=null?n:fy())},e.getIsSomeColumnsPinned=t=>{var n;const r=e.getState().columnPinning;if(!t){var s,o;return!!((s=r.left)!=null&&s.length||(o=r.right)!=null&&o.length)}return!!((n=r[t])!=null&&n.length)},e.getLeftLeafColumns=ot(()=>[e.getAllLeafColumns(),e.getState().columnPinning.left],(t,n)=>(n??[]).map(r=>t.find(s=>s.id===r)).filter(Boolean),at(e.options,"debugColumns")),e.getRightLeafColumns=ot(()=>[e.getAllLeafColumns(),e.getState().columnPinning.right],(t,n)=>(n??[]).map(r=>t.find(s=>s.id===r)).filter(Boolean),at(e.options,"debugColumns")),e.getCenterLeafColumns=ot(()=>[e.getAllLeafColumns(),e.getState().columnPinning.left,e.getState().columnPinning.right],(t,n,r)=>{const s=[...n??[],...r??[]];return t.filter(o=>!s.includes(o.id))},at(e.options,"debugColumns"))}},ap={size:150,minSize:20,maxSize:Number.MAX_SAFE_INTEGER},py=()=>({startOffset:null,startSize:null,deltaOffset:null,deltaPercentage:null,isResizingColumn:!1,columnSizingStart:[]}),pee={getDefaultColumnDef:()=>ap,getInitialState:e=>({columnSizing:{},columnSizingInfo:py(),...e}),getDefaultOptions:e=>({columnResizeMode:"onEnd",columnResizeDirection:"ltr",onColumnSizingChange:qr("columnSizing",e),onColumnSizingInfoChange:qr("columnSizingInfo",e)}),createColumn:(e,t)=>{e.getSize=()=>{var n,r,s;const o=t.getState().columnSizing[e.id];return Math.min(Math.max((n=e.columnDef.minSize)!=null?n:ap.minSize,(r=o??e.columnDef.size)!=null?r:ap.size),(s=e.columnDef.maxSize)!=null?s:ap.maxSize)},e.getStart=ot(n=>[n,Ru(t,n),t.getState().columnSizing],(n,r)=>r.slice(0,e.getIndex(n)).reduce((s,o)=>s+o.getSize(),0),at(t.options,"debugColumns")),e.getAfter=ot(n=>[n,Ru(t,n),t.getState().columnSizing],(n,r)=>r.slice(e.getIndex(n)+1).reduce((s,o)=>s+o.getSize(),0),at(t.options,"debugColumns")),e.resetSize=()=>{t.setColumnSizing(n=>{let{[e.id]:r,...s}=n;return s})},e.getCanResize=()=>{var n,r;return((n=e.columnDef.enableResizing)!=null?n:!0)&&((r=t.options.enableColumnResizing)!=null?r:!0)},e.getIsResizing=()=>t.getState().columnSizingInfo.isResizingColumn===e.id},createHeader:(e,t)=>{e.getSize=()=>{let n=0;const r=s=>{if(s.subHeaders.length)s.subHeaders.forEach(r);else{var o;n+=(o=s.column.getSize())!=null?o:0}};return r(e),n},e.getStart=()=>{if(e.index>0){const n=e.headerGroup.headers[e.index-1];return n.getStart()+n.getSize()}return 0},e.getResizeHandler=n=>{const r=t.getColumn(e.column.id),s=r?.getCanResize();return o=>{if(!r||!s||(o.persist==null||o.persist(),hy(o)&&o.touches&&o.touches.length>1))return;const l=e.getSize(),u=e?e.getLeafHeaders().map(k=>[k.column.id,k.column.getSize()]):[[r.id,r.getSize()]],d=hy(o)?Math.round(o.touches[0].clientX):o.clientX,f={},h=(k,j)=>{typeof j=="number"&&(t.setColumnSizingInfo(M=>{var _,R;const N=t.options.columnResizeDirection==="rtl"?-1:1,O=(j-((_=M?.startOffset)!=null?_:0))*N,D=Math.max(O/((R=M?.startSize)!=null?R:0),-.999999);return M.columnSizingStart.forEach(z=>{let[Q,pe]=z;f[Q]=Math.round(Math.max(pe+pe*D,0)*100)/100}),{...M,deltaOffset:O,deltaPercentage:D}}),(t.options.columnResizeMode==="onChange"||k==="end")&&t.setColumnSizing(M=>({...M,...f})))},m=k=>h("move",k),g=k=>{h("end",k),t.setColumnSizingInfo(j=>({...j,isResizingColumn:!1,startOffset:null,startSize:null,deltaOffset:null,deltaPercentage:null,columnSizingStart:[]}))},x=n||typeof document<"u"?document:null,b={moveHandler:k=>m(k.clientX),upHandler:k=>{x?.removeEventListener("mousemove",b.moveHandler),x?.removeEventListener("mouseup",b.upHandler),g(k.clientX)}},w={moveHandler:k=>(k.cancelable&&(k.preventDefault(),k.stopPropagation()),m(k.touches[0].clientX),!1),upHandler:k=>{var j;x?.removeEventListener("touchmove",w.moveHandler),x?.removeEventListener("touchend",w.upHandler),k.cancelable&&(k.preventDefault(),k.stopPropagation()),g((j=k.touches[0])==null?void 0:j.clientX)}},C=hee()?{passive:!1}:!1;hy(o)?(x?.addEventListener("touchmove",w.moveHandler,C),x?.addEventListener("touchend",w.upHandler,C)):(x?.addEventListener("mousemove",b.moveHandler,C),x?.addEventListener("mouseup",b.upHandler,C)),t.setColumnSizingInfo(k=>({...k,startOffset:d,startSize:l,deltaOffset:0,deltaPercentage:0,columnSizingStart:u,isResizingColumn:r.id}))}}},createTable:e=>{e.setColumnSizing=t=>e.options.onColumnSizingChange==null?void 0:e.options.onColumnSizingChange(t),e.setColumnSizingInfo=t=>e.options.onColumnSizingInfoChange==null?void 0:e.options.onColumnSizingInfoChange(t),e.resetColumnSizing=t=>{var n;e.setColumnSizing(t?{}:(n=e.initialState.columnSizing)!=null?n:{})},e.resetHeaderSizeInfo=t=>{var n;e.setColumnSizingInfo(t?py():(n=e.initialState.columnSizingInfo)!=null?n:py())},e.getTotalSize=()=>{var t,n;return(t=(n=e.getHeaderGroups()[0])==null?void 0:n.headers.reduce((r,s)=>r+s.getSize(),0))!=null?t:0},e.getLeftTotalSize=()=>{var t,n;return(t=(n=e.getLeftHeaderGroups()[0])==null?void 0:n.headers.reduce((r,s)=>r+s.getSize(),0))!=null?t:0},e.getCenterTotalSize=()=>{var t,n;return(t=(n=e.getCenterHeaderGroups()[0])==null?void 0:n.headers.reduce((r,s)=>r+s.getSize(),0))!=null?t:0},e.getRightTotalSize=()=>{var t,n;return(t=(n=e.getRightHeaderGroups()[0])==null?void 0:n.headers.reduce((r,s)=>r+s.getSize(),0))!=null?t:0}}};let ip=null;function hee(){if(typeof ip=="boolean")return ip;let e=!1;try{const t={get passive(){return e=!0,!1}},n=()=>{};window.addEventListener("test",n,t),window.removeEventListener("test",n)}catch{e=!1}return ip=e,ip}function hy(e){return e.type==="touchstart"}const gee={getInitialState:e=>({columnVisibility:{},...e}),getDefaultOptions:e=>({onColumnVisibilityChange:qr("columnVisibility",e)}),createColumn:(e,t)=>{e.toggleVisibility=n=>{e.getCanHide()&&t.setColumnVisibility(r=>({...r,[e.id]:n??!e.getIsVisible()}))},e.getIsVisible=()=>{var n,r;const s=e.columns;return(n=s.length?s.some(o=>o.getIsVisible()):(r=t.getState().columnVisibility)==null?void 0:r[e.id])!=null?n:!0},e.getCanHide=()=>{var n,r;return((n=e.columnDef.enableHiding)!=null?n:!0)&&((r=t.options.enableHiding)!=null?r:!0)},e.getToggleVisibilityHandler=()=>n=>{e.toggleVisibility==null||e.toggleVisibility(n.target.checked)}},createRow:(e,t)=>{e._getAllVisibleCells=ot(()=>[e.getAllCells(),t.getState().columnVisibility],n=>n.filter(r=>r.column.getIsVisible()),at(t.options,"debugRows")),e.getVisibleCells=ot(()=>[e.getLeftVisibleCells(),e.getCenterVisibleCells(),e.getRightVisibleCells()],(n,r,s)=>[...n,...r,...s],at(t.options,"debugRows"))},createTable:e=>{const t=(n,r)=>ot(()=>[r(),r().filter(s=>s.getIsVisible()).map(s=>s.id).join("_")],s=>s.filter(o=>o.getIsVisible==null?void 0:o.getIsVisible()),at(e.options,"debugColumns"));e.getVisibleFlatColumns=t("getVisibleFlatColumns",()=>e.getAllFlatColumns()),e.getVisibleLeafColumns=t("getVisibleLeafColumns",()=>e.getAllLeafColumns()),e.getLeftVisibleLeafColumns=t("getLeftVisibleLeafColumns",()=>e.getLeftLeafColumns()),e.getRightVisibleLeafColumns=t("getRightVisibleLeafColumns",()=>e.getRightLeafColumns()),e.getCenterVisibleLeafColumns=t("getCenterVisibleLeafColumns",()=>e.getCenterLeafColumns()),e.setColumnVisibility=n=>e.options.onColumnVisibilityChange==null?void 0:e.options.onColumnVisibilityChange(n),e.resetColumnVisibility=n=>{var r;e.setColumnVisibility(n?{}:(r=e.initialState.columnVisibility)!=null?r:{})},e.toggleAllColumnsVisible=n=>{var r;n=(r=n)!=null?r:!e.getIsAllColumnsVisible(),e.setColumnVisibility(e.getAllLeafColumns().reduce((s,o)=>({...s,[o.id]:n||!(o.getCanHide!=null&&o.getCanHide())}),{}))},e.getIsAllColumnsVisible=()=>!e.getAllLeafColumns().some(n=>!(n.getIsVisible!=null&&n.getIsVisible())),e.getIsSomeColumnsVisible=()=>e.getAllLeafColumns().some(n=>n.getIsVisible==null?void 0:n.getIsVisible()),e.getToggleAllColumnsVisibilityHandler=()=>n=>{var r;e.toggleAllColumnsVisible((r=n.target)==null?void 0:r.checked)}}};function Ru(e,t){return t?t==="center"?e.getCenterVisibleLeafColumns():t==="left"?e.getLeftVisibleLeafColumns():e.getRightVisibleLeafColumns():e.getVisibleLeafColumns()}const mee={createTable:e=>{e._getGlobalFacetedRowModel=e.options.getFacetedRowModel&&e.options.getFacetedRowModel(e,"__global__"),e.getGlobalFacetedRowModel=()=>e.options.manualFiltering||!e._getGlobalFacetedRowModel?e.getPreFilteredRowModel():e._getGlobalFacetedRowModel(),e._getGlobalFacetedUniqueValues=e.options.getFacetedUniqueValues&&e.options.getFacetedUniqueValues(e,"__global__"),e.getGlobalFacetedUniqueValues=()=>e._getGlobalFacetedUniqueValues?e._getGlobalFacetedUniqueValues():new Map,e._getGlobalFacetedMinMaxValues=e.options.getFacetedMinMaxValues&&e.options.getFacetedMinMaxValues(e,"__global__"),e.getGlobalFacetedMinMaxValues=()=>{if(e._getGlobalFacetedMinMaxValues)return e._getGlobalFacetedMinMaxValues()}}},vee={getInitialState:e=>({globalFilter:void 0,...e}),getDefaultOptions:e=>({onGlobalFilterChange:qr("globalFilter",e),globalFilterFn:"auto",getColumnCanGlobalFilter:t=>{var n;const r=(n=e.getCoreRowModel().flatRows[0])==null||(n=n._getAllCellsByColumnId()[t.id])==null?void 0:n.getValue();return typeof r=="string"||typeof r=="number"}}),createColumn:(e,t)=>{e.getCanGlobalFilter=()=>{var n,r,s,o;return((n=e.columnDef.enableGlobalFilter)!=null?n:!0)&&((r=t.options.enableGlobalFilter)!=null?r:!0)&&((s=t.options.enableFilters)!=null?s:!0)&&((o=t.options.getColumnCanGlobalFilter==null?void 0:t.options.getColumnCanGlobalFilter(e))!=null?o:!0)&&!!e.accessorFn}},createTable:e=>{e.getGlobalAutoFilterFn=()=>yo.includesString,e.getGlobalFilterFn=()=>{var t,n;const{globalFilterFn:r}=e.options;return yg(r)?r:r==="auto"?e.getGlobalAutoFilterFn():(t=(n=e.options.filterFns)==null?void 0:n[r])!=null?t:yo[r]},e.setGlobalFilter=t=>{e.options.onGlobalFilterChange==null||e.options.onGlobalFilterChange(t)},e.resetGlobalFilter=t=>{e.setGlobalFilter(t?void 0:e.initialState.globalFilter)}}},yee={getInitialState:e=>({expanded:{},...e}),getDefaultOptions:e=>({onExpandedChange:qr("expanded",e),paginateExpandedRows:!0}),createTable:e=>{let t=!1,n=!1;e._autoResetExpanded=()=>{var r,s;if(!t){e._queue(()=>{t=!0});return}if((r=(s=e.options.autoResetAll)!=null?s:e.options.autoResetExpanded)!=null?r:!e.options.manualExpanding){if(n)return;n=!0,e._queue(()=>{e.resetExpanded(),n=!1})}},e.setExpanded=r=>e.options.onExpandedChange==null?void 0:e.options.onExpandedChange(r),e.toggleAllRowsExpanded=r=>{r??!e.getIsAllRowsExpanded()?e.setExpanded(!0):e.setExpanded({})},e.resetExpanded=r=>{var s,o;e.setExpanded(r?{}:(s=(o=e.initialState)==null?void 0:o.expanded)!=null?s:{})},e.getCanSomeRowsExpand=()=>e.getPrePaginationRowModel().flatRows.some(r=>r.getCanExpand()),e.getToggleAllRowsExpandedHandler=()=>r=>{r.persist==null||r.persist(),e.toggleAllRowsExpanded()},e.getIsSomeRowsExpanded=()=>{const r=e.getState().expanded;return r===!0||Object.values(r).some(Boolean)},e.getIsAllRowsExpanded=()=>{const r=e.getState().expanded;return typeof r=="boolean"?r===!0:!(!Object.keys(r).length||e.getRowModel().flatRows.some(s=>!s.getIsExpanded()))},e.getExpandedDepth=()=>{let r=0;return(e.getState().expanded===!0?Object.keys(e.getRowModel().rowsById):Object.keys(e.getState().expanded)).forEach(o=>{const l=o.split(".");r=Math.max(r,l.length)}),r},e.getPreExpandedRowModel=()=>e.getSortedRowModel(),e.getExpandedRowModel=()=>(!e._getExpandedRowModel&&e.options.getExpandedRowModel&&(e._getExpandedRowModel=e.options.getExpandedRowModel(e)),e.options.manualExpanding||!e._getExpandedRowModel?e.getPreExpandedRowModel():e._getExpandedRowModel())},createRow:(e,t)=>{e.toggleExpanded=n=>{t.setExpanded(r=>{var s;const o=r===!0?!0:!!(r!=null&&r[e.id]);let l={};if(r===!0?Object.keys(t.getRowModel().rowsById).forEach(u=>{l[u]=!0}):l=r,n=(s=n)!=null?s:!o,!o&&n)return{...l,[e.id]:!0};if(o&&!n){const{[e.id]:u,...d}=l;return d}return r})},e.getIsExpanded=()=>{var n;const r=t.getState().expanded;return!!((n=t.options.getIsRowExpanded==null?void 0:t.options.getIsRowExpanded(e))!=null?n:r===!0||r?.[e.id])},e.getCanExpand=()=>{var n,r,s;return(n=t.options.getRowCanExpand==null?void 0:t.options.getRowCanExpand(e))!=null?n:((r=t.options.enableExpanding)!=null?r:!0)&&!!((s=e.subRows)!=null&&s.length)},e.getIsAllParentsExpanded=()=>{let n=!0,r=e;for(;n&&r.parentId;)r=t.getRow(r.parentId,!0),n=r.getIsExpanded();return n},e.getToggleExpandedHandler=()=>{const n=e.getCanExpand();return()=>{n&&e.toggleExpanded()}}}},Eb=0,kb=10,gy=()=>({pageIndex:Eb,pageSize:kb}),bee={getInitialState:e=>({...e,pagination:{...gy(),...e?.pagination}}),getDefaultOptions:e=>({onPaginationChange:qr("pagination",e)}),createTable:e=>{let t=!1,n=!1;e._autoResetPageIndex=()=>{var r,s;if(!t){e._queue(()=>{t=!0});return}if((r=(s=e.options.autoResetAll)!=null?s:e.options.autoResetPageIndex)!=null?r:!e.options.manualPagination){if(n)return;n=!0,e._queue(()=>{e.resetPageIndex(),n=!1})}},e.setPagination=r=>{const s=o=>ma(r,o);return e.options.onPaginationChange==null?void 0:e.options.onPaginationChange(s)},e.resetPagination=r=>{var s;e.setPagination(r?gy():(s=e.initialState.pagination)!=null?s:gy())},e.setPageIndex=r=>{e.setPagination(s=>{let o=ma(r,s.pageIndex);const l=typeof e.options.pageCount>"u"||e.options.pageCount===-1?Number.MAX_SAFE_INTEGER:e.options.pageCount-1;return o=Math.max(0,Math.min(o,l)),{...s,pageIndex:o}})},e.resetPageIndex=r=>{var s,o;e.setPageIndex(r?Eb:(s=(o=e.initialState)==null||(o=o.pagination)==null?void 0:o.pageIndex)!=null?s:Eb)},e.resetPageSize=r=>{var s,o;e.setPageSize(r?kb:(s=(o=e.initialState)==null||(o=o.pagination)==null?void 0:o.pageSize)!=null?s:kb)},e.setPageSize=r=>{e.setPagination(s=>{const o=Math.max(1,ma(r,s.pageSize)),l=s.pageSize*s.pageIndex,u=Math.floor(l/o);return{...s,pageIndex:u,pageSize:o}})},e.setPageCount=r=>e.setPagination(s=>{var o;let l=ma(r,(o=e.options.pageCount)!=null?o:-1);return typeof l=="number"&&(l=Math.max(-1,l)),{...s,pageCount:l}}),e.getPageOptions=ot(()=>[e.getPageCount()],r=>{let s=[];return r&&r>0&&(s=[...new Array(r)].fill(null).map((o,l)=>l)),s},at(e.options,"debugTable")),e.getCanPreviousPage=()=>e.getState().pagination.pageIndex>0,e.getCanNextPage=()=>{const{pageIndex:r}=e.getState().pagination,s=e.getPageCount();return s===-1?!0:s===0?!1:re.setPageIndex(r=>r-1),e.nextPage=()=>e.setPageIndex(r=>r+1),e.firstPage=()=>e.setPageIndex(0),e.lastPage=()=>e.setPageIndex(e.getPageCount()-1),e.getPrePaginationRowModel=()=>e.getExpandedRowModel(),e.getPaginationRowModel=()=>(!e._getPaginationRowModel&&e.options.getPaginationRowModel&&(e._getPaginationRowModel=e.options.getPaginationRowModel(e)),e.options.manualPagination||!e._getPaginationRowModel?e.getPrePaginationRowModel():e._getPaginationRowModel()),e.getPageCount=()=>{var r;return(r=e.options.pageCount)!=null?r:Math.ceil(e.getRowCount()/e.getState().pagination.pageSize)},e.getRowCount=()=>{var r;return(r=e.options.rowCount)!=null?r:e.getPrePaginationRowModel().rows.length}}},my=()=>({top:[],bottom:[]}),xee={getInitialState:e=>({rowPinning:my(),...e}),getDefaultOptions:e=>({onRowPinningChange:qr("rowPinning",e)}),createRow:(e,t)=>{e.pin=(n,r,s)=>{const o=r?e.getLeafRows().map(d=>{let{id:f}=d;return f}):[],l=s?e.getParentRows().map(d=>{let{id:f}=d;return f}):[],u=new Set([...l,e.id,...o]);t.setRowPinning(d=>{var f,h;if(n==="bottom"){var m,g;return{top:((m=d?.top)!=null?m:[]).filter(w=>!(u!=null&&u.has(w))),bottom:[...((g=d?.bottom)!=null?g:[]).filter(w=>!(u!=null&&u.has(w))),...Array.from(u)]}}if(n==="top"){var x,b;return{top:[...((x=d?.top)!=null?x:[]).filter(w=>!(u!=null&&u.has(w))),...Array.from(u)],bottom:((b=d?.bottom)!=null?b:[]).filter(w=>!(u!=null&&u.has(w)))}}return{top:((f=d?.top)!=null?f:[]).filter(w=>!(u!=null&&u.has(w))),bottom:((h=d?.bottom)!=null?h:[]).filter(w=>!(u!=null&&u.has(w)))}})},e.getCanPin=()=>{var n;const{enableRowPinning:r,enablePinning:s}=t.options;return typeof r=="function"?r(e):(n=r??s)!=null?n:!0},e.getIsPinned=()=>{const n=[e.id],{top:r,bottom:s}=t.getState().rowPinning,o=n.some(u=>r?.includes(u)),l=n.some(u=>s?.includes(u));return o?"top":l?"bottom":!1},e.getPinnedIndex=()=>{var n,r;const s=e.getIsPinned();if(!s)return-1;const o=(n=s==="top"?t.getTopRows():t.getBottomRows())==null?void 0:n.map(l=>{let{id:u}=l;return u});return(r=o?.indexOf(e.id))!=null?r:-1}},createTable:e=>{e.setRowPinning=t=>e.options.onRowPinningChange==null?void 0:e.options.onRowPinningChange(t),e.resetRowPinning=t=>{var n,r;return e.setRowPinning(t?my():(n=(r=e.initialState)==null?void 0:r.rowPinning)!=null?n:my())},e.getIsSomeRowsPinned=t=>{var n;const r=e.getState().rowPinning;if(!t){var s,o;return!!((s=r.top)!=null&&s.length||(o=r.bottom)!=null&&o.length)}return!!((n=r[t])!=null&&n.length)},e._getPinnedRows=(t,n,r)=>{var s;return((s=e.options.keepPinnedRows)==null||s?(n??[]).map(l=>{const u=e.getRow(l,!0);return u.getIsAllParentsExpanded()?u:null}):(n??[]).map(l=>t.find(u=>u.id===l))).filter(Boolean).map(l=>({...l,position:r}))},e.getTopRows=ot(()=>[e.getRowModel().rows,e.getState().rowPinning.top],(t,n)=>e._getPinnedRows(t,n,"top"),at(e.options,"debugRows")),e.getBottomRows=ot(()=>[e.getRowModel().rows,e.getState().rowPinning.bottom],(t,n)=>e._getPinnedRows(t,n,"bottom"),at(e.options,"debugRows")),e.getCenterRows=ot(()=>[e.getRowModel().rows,e.getState().rowPinning.top,e.getState().rowPinning.bottom],(t,n,r)=>{const s=new Set([...n??[],...r??[]]);return t.filter(o=>!s.has(o.id))},at(e.options,"debugRows"))}},wee={getInitialState:e=>({rowSelection:{},...e}),getDefaultOptions:e=>({onRowSelectionChange:qr("rowSelection",e),enableRowSelection:!0,enableMultiRowSelection:!0,enableSubRowSelection:!0}),createTable:e=>{e.setRowSelection=t=>e.options.onRowSelectionChange==null?void 0:e.options.onRowSelectionChange(t),e.resetRowSelection=t=>{var n;return e.setRowSelection(t?{}:(n=e.initialState.rowSelection)!=null?n:{})},e.toggleAllRowsSelected=t=>{e.setRowSelection(n=>{t=typeof t<"u"?t:!e.getIsAllRowsSelected();const r={...n},s=e.getPreGroupedRowModel().flatRows;return t?s.forEach(o=>{o.getCanSelect()&&(r[o.id]=!0)}):s.forEach(o=>{delete r[o.id]}),r})},e.toggleAllPageRowsSelected=t=>e.setRowSelection(n=>{const r=typeof t<"u"?t:!e.getIsAllPageRowsSelected(),s={...n};return e.getRowModel().rows.forEach(o=>{jb(s,o.id,r,!0,e)}),s}),e.getPreSelectedRowModel=()=>e.getCoreRowModel(),e.getSelectedRowModel=ot(()=>[e.getState().rowSelection,e.getCoreRowModel()],(t,n)=>Object.keys(t).length?vy(e,n):{rows:[],flatRows:[],rowsById:{}},at(e.options,"debugTable")),e.getFilteredSelectedRowModel=ot(()=>[e.getState().rowSelection,e.getFilteredRowModel()],(t,n)=>Object.keys(t).length?vy(e,n):{rows:[],flatRows:[],rowsById:{}},at(e.options,"debugTable")),e.getGroupedSelectedRowModel=ot(()=>[e.getState().rowSelection,e.getSortedRowModel()],(t,n)=>Object.keys(t).length?vy(e,n):{rows:[],flatRows:[],rowsById:{}},at(e.options,"debugTable")),e.getIsAllRowsSelected=()=>{const t=e.getFilteredRowModel().flatRows,{rowSelection:n}=e.getState();let r=!!(t.length&&Object.keys(n).length);return r&&t.some(s=>s.getCanSelect()&&!n[s.id])&&(r=!1),r},e.getIsAllPageRowsSelected=()=>{const t=e.getPaginationRowModel().flatRows.filter(s=>s.getCanSelect()),{rowSelection:n}=e.getState();let r=!!t.length;return r&&t.some(s=>!n[s.id])&&(r=!1),r},e.getIsSomeRowsSelected=()=>{var t;const n=Object.keys((t=e.getState().rowSelection)!=null?t:{}).length;return n>0&&n{const t=e.getPaginationRowModel().flatRows;return e.getIsAllPageRowsSelected()?!1:t.filter(n=>n.getCanSelect()).some(n=>n.getIsSelected()||n.getIsSomeSelected())},e.getToggleAllRowsSelectedHandler=()=>t=>{e.toggleAllRowsSelected(t.target.checked)},e.getToggleAllPageRowsSelectedHandler=()=>t=>{e.toggleAllPageRowsSelected(t.target.checked)}},createRow:(e,t)=>{e.toggleSelected=(n,r)=>{const s=e.getIsSelected();t.setRowSelection(o=>{var l;if(n=typeof n<"u"?n:!s,e.getCanSelect()&&s===n)return o;const u={...o};return jb(u,e.id,n,(l=r?.selectChildren)!=null?l:!0,t),u})},e.getIsSelected=()=>{const{rowSelection:n}=t.getState();return iw(e,n)},e.getIsSomeSelected=()=>{const{rowSelection:n}=t.getState();return Tb(e,n)==="some"},e.getIsAllSubRowsSelected=()=>{const{rowSelection:n}=t.getState();return Tb(e,n)==="all"},e.getCanSelect=()=>{var n;return typeof t.options.enableRowSelection=="function"?t.options.enableRowSelection(e):(n=t.options.enableRowSelection)!=null?n:!0},e.getCanSelectSubRows=()=>{var n;return typeof t.options.enableSubRowSelection=="function"?t.options.enableSubRowSelection(e):(n=t.options.enableSubRowSelection)!=null?n:!0},e.getCanMultiSelect=()=>{var n;return typeof t.options.enableMultiRowSelection=="function"?t.options.enableMultiRowSelection(e):(n=t.options.enableMultiRowSelection)!=null?n:!0},e.getToggleSelectedHandler=()=>{const n=e.getCanSelect();return r=>{var s;n&&e.toggleSelected((s=r.target)==null?void 0:s.checked)}}}},jb=(e,t,n,r,s)=>{var o;const l=s.getRow(t,!0);n?(l.getCanMultiSelect()||Object.keys(e).forEach(u=>delete e[u]),l.getCanSelect()&&(e[t]=!0)):delete e[t],r&&(o=l.subRows)!=null&&o.length&&l.getCanSelectSubRows()&&l.subRows.forEach(u=>jb(e,u.id,n,r,s))};function vy(e,t){const n=e.getState().rowSelection,r=[],s={},o=function(l,u){return l.map(d=>{var f;const h=iw(d,n);if(h&&(r.push(d),s[d.id]=d),(f=d.subRows)!=null&&f.length&&(d={...d,subRows:o(d.subRows)}),h)return d}).filter(Boolean)};return{rows:o(t.rows),flatRows:r,rowsById:s}}function iw(e,t){var n;return(n=t[e.id])!=null?n:!1}function Tb(e,t,n){var r;if(!((r=e.subRows)!=null&&r.length))return!1;let s=!0,o=!1;return e.subRows.forEach(l=>{if(!(o&&!s)&&(l.getCanSelect()&&(iw(l,t)?o=!0:s=!1),l.subRows&&l.subRows.length)){const u=Tb(l,t);u==="all"?o=!0:(u==="some"&&(o=!0),s=!1)}}),s?"all":o?"some":!1}const Nb=/([0-9]+)/gm,See=(e,t,n)=>vI(Na(e.getValue(n)).toLowerCase(),Na(t.getValue(n)).toLowerCase()),Cee=(e,t,n)=>vI(Na(e.getValue(n)),Na(t.getValue(n))),Eee=(e,t,n)=>lw(Na(e.getValue(n)).toLowerCase(),Na(t.getValue(n)).toLowerCase()),kee=(e,t,n)=>lw(Na(e.getValue(n)),Na(t.getValue(n))),jee=(e,t,n)=>{const r=e.getValue(n),s=t.getValue(n);return r>s?1:rlw(e.getValue(n),t.getValue(n));function lw(e,t){return e===t?0:e>t?1:-1}function Na(e){return typeof e=="number"?isNaN(e)||e===1/0||e===-1/0?"":String(e):typeof e=="string"?e:""}function vI(e,t){const n=e.split(Nb).filter(Boolean),r=t.split(Nb).filter(Boolean);for(;n.length&&r.length;){const s=n.shift(),o=r.shift(),l=parseInt(s,10),u=parseInt(o,10),d=[l,u].sort();if(isNaN(d[0])){if(s>o)return 1;if(o>s)return-1;continue}if(isNaN(d[1]))return isNaN(l)?-1:1;if(l>u)return 1;if(u>l)return-1}return n.length-r.length}const pu={alphanumeric:See,alphanumericCaseSensitive:Cee,text:Eee,textCaseSensitive:kee,datetime:jee,basic:Tee},Nee={getInitialState:e=>({sorting:[],...e}),getDefaultColumnDef:()=>({sortingFn:"auto",sortUndefined:1}),getDefaultOptions:e=>({onSortingChange:qr("sorting",e),isMultiSortEvent:t=>t.shiftKey}),createColumn:(e,t)=>{e.getAutoSortingFn=()=>{const n=t.getFilteredRowModel().flatRows.slice(10);let r=!1;for(const s of n){const o=s?.getValue(e.id);if(Object.prototype.toString.call(o)==="[object Date]")return pu.datetime;if(typeof o=="string"&&(r=!0,o.split(Nb).length>1))return pu.alphanumeric}return r?pu.text:pu.basic},e.getAutoSortDir=()=>{const n=t.getFilteredRowModel().flatRows[0];return typeof n?.getValue(e.id)=="string"?"asc":"desc"},e.getSortingFn=()=>{var n,r;if(!e)throw new Error;return yg(e.columnDef.sortingFn)?e.columnDef.sortingFn:e.columnDef.sortingFn==="auto"?e.getAutoSortingFn():(n=(r=t.options.sortingFns)==null?void 0:r[e.columnDef.sortingFn])!=null?n:pu[e.columnDef.sortingFn]},e.toggleSorting=(n,r)=>{const s=e.getNextSortingOrder(),o=typeof n<"u"&&n!==null;t.setSorting(l=>{const u=l?.find(x=>x.id===e.id),d=l?.findIndex(x=>x.id===e.id);let f=[],h,m=o?n:s==="desc";if(l!=null&&l.length&&e.getCanMultiSort()&&r?u?h="toggle":h="add":l!=null&&l.length&&d!==l.length-1?h="replace":u?h="toggle":h="replace",h==="toggle"&&(o||s||(h="remove")),h==="add"){var g;f=[...l,{id:e.id,desc:m}],f.splice(0,f.length-((g=t.options.maxMultiSortColCount)!=null?g:Number.MAX_SAFE_INTEGER))}else h==="toggle"?f=l.map(x=>x.id===e.id?{...x,desc:m}:x):h==="remove"?f=l.filter(x=>x.id!==e.id):f=[{id:e.id,desc:m}];return f})},e.getFirstSortDir=()=>{var n,r;return((n=(r=e.columnDef.sortDescFirst)!=null?r:t.options.sortDescFirst)!=null?n:e.getAutoSortDir()==="desc")?"desc":"asc"},e.getNextSortingOrder=n=>{var r,s;const o=e.getFirstSortDir(),l=e.getIsSorted();return l?l!==o&&((r=t.options.enableSortingRemoval)==null||r)&&(!(n&&(s=t.options.enableMultiRemove)!=null)||s)?!1:l==="desc"?"asc":"desc":o},e.getCanSort=()=>{var n,r;return((n=e.columnDef.enableSorting)!=null?n:!0)&&((r=t.options.enableSorting)!=null?r:!0)&&!!e.accessorFn},e.getCanMultiSort=()=>{var n,r;return(n=(r=e.columnDef.enableMultiSort)!=null?r:t.options.enableMultiSort)!=null?n:!!e.accessorFn},e.getIsSorted=()=>{var n;const r=(n=t.getState().sorting)==null?void 0:n.find(s=>s.id===e.id);return r?r.desc?"desc":"asc":!1},e.getSortIndex=()=>{var n,r;return(n=(r=t.getState().sorting)==null?void 0:r.findIndex(s=>s.id===e.id))!=null?n:-1},e.clearSorting=()=>{t.setSorting(n=>n!=null&&n.length?n.filter(r=>r.id!==e.id):[])},e.getToggleSortingHandler=()=>{const n=e.getCanSort();return r=>{n&&(r.persist==null||r.persist(),e.toggleSorting==null||e.toggleSorting(void 0,e.getCanMultiSort()?t.options.isMultiSortEvent==null?void 0:t.options.isMultiSortEvent(r):!1))}}},createTable:e=>{e.setSorting=t=>e.options.onSortingChange==null?void 0:e.options.onSortingChange(t),e.resetSorting=t=>{var n,r;e.setSorting(t?[]:(n=(r=e.initialState)==null?void 0:r.sorting)!=null?n:[])},e.getPreSortedRowModel=()=>e.getGroupedRowModel(),e.getSortedRowModel=()=>(!e._getSortedRowModel&&e.options.getSortedRowModel&&(e._getSortedRowModel=e.options.getSortedRowModel(e)),e.options.manualSorting||!e._getSortedRowModel?e.getPreSortedRowModel():e._getSortedRowModel())}},Mee=[ZX,gee,dee,fee,YX,XX,mee,vee,Nee,cee,yee,bee,xee,wee,pee];function _ee(e){var t,n;const r=[...Mee,...(t=e._features)!=null?t:[]];let s={_features:r};const o=s._features.reduce((g,x)=>Object.assign(g,x.getDefaultOptions==null?void 0:x.getDefaultOptions(s)),{}),l=g=>s.options.mergeOptions?s.options.mergeOptions(o,g):{...o,...g};let d={...{},...(n=e.initialState)!=null?n:{}};s._features.forEach(g=>{var x;d=(x=g.getInitialState==null?void 0:g.getInitialState(d))!=null?x:d});const f=[];let h=!1;const m={_features:r,options:{...o,...e},initialState:d,_queue:g=>{f.push(g),h||(h=!0,Promise.resolve().then(()=>{for(;f.length;)f.shift()();h=!1}).catch(x=>setTimeout(()=>{throw x})))},reset:()=>{s.setState(s.initialState)},setOptions:g=>{const x=ma(g,s.options);s.options=l(x)},getState:()=>s.options.state,setState:g=>{s.options.onStateChange==null||s.options.onStateChange(g)},_getRowId:(g,x,b)=>{var w;return(w=s.options.getRowId==null?void 0:s.options.getRowId(g,x,b))!=null?w:`${b?[b.id,x].join("."):x}`},getCoreRowModel:()=>(s._getCoreRowModel||(s._getCoreRowModel=s.options.getCoreRowModel(s)),s._getCoreRowModel()),getRowModel:()=>s.getPaginationRowModel(),getRow:(g,x)=>{let b=(x?s.getPrePaginationRowModel():s.getRowModel()).rowsById[g];if(!b&&(b=s.getCoreRowModel().rowsById[g],!b))throw new Error;return b},_getDefaultColumnDef:ot(()=>[s.options.defaultColumn],g=>{var x;return g=(x=g)!=null?x:{},{header:b=>{const w=b.header.column.columnDef;return w.accessorKey?w.accessorKey:w.accessorFn?w.id:null},cell:b=>{var w,C;return(w=(C=b.renderValue())==null||C.toString==null?void 0:C.toString())!=null?w:null},...s._features.reduce((b,w)=>Object.assign(b,w.getDefaultColumnDef==null?void 0:w.getDefaultColumnDef()),{}),...g}},at(e,"debugColumns")),_getColumnDefs:()=>s.options.columns,getAllColumns:ot(()=>[s._getColumnDefs()],g=>{const x=function(b,w,C){return C===void 0&&(C=0),b.map(k=>{const j=QX(s,k,C,w),M=k;return j.columns=M.columns?x(M.columns,j,C+1):[],j})};return x(g)},at(e,"debugColumns")),getAllFlatColumns:ot(()=>[s.getAllColumns()],g=>g.flatMap(x=>x.getFlatColumns()),at(e,"debugColumns")),_getAllFlatColumnsById:ot(()=>[s.getAllFlatColumns()],g=>g.reduce((x,b)=>(x[b.id]=b,x),{}),at(e,"debugColumns")),getAllLeafColumns:ot(()=>[s.getAllColumns(),s._getOrderColumnsFn()],(g,x)=>{let b=g.flatMap(w=>w.getLeafColumns());return x(b)},at(e,"debugColumns")),getColumn:g=>s._getAllFlatColumnsById()[g]};Object.assign(s,m);for(let g=0;got(()=>[e.options.data],t=>{const n={rows:[],flatRows:[],rowsById:{}},r=function(s,o,l){o===void 0&&(o=0);const u=[];for(let f=0;fe._autoResetPageIndex()))}function Pee(e,t,n){return n.options.filterFromLeafRows?Oee(e,t,n):Iee(e,t,n)}function Oee(e,t,n){var r;const s=[],o={},l=(r=n.options.maxLeafRowFilterDepth)!=null?r:100,u=function(d,f){f===void 0&&(f=0);const h=[];for(let g=0;got(()=>[e.getPreFilteredRowModel(),e.getState().columnFilters,e.getState().globalFilter],(t,n,r)=>{if(!t.rows.length||!(n!=null&&n.length)&&!r){for(let g=0;g{var x;const b=e.getColumn(g.id);if(!b)return;const w=b.getFilterFn();w&&s.push({id:g.id,filterFn:w,resolvedValue:(x=w.resolveFilterValue==null?void 0:w.resolveFilterValue(g.value))!=null?x:g.value})});const l=(n??[]).map(g=>g.id),u=e.getGlobalFilterFn(),d=e.getAllLeafColumns().filter(g=>g.getCanGlobalFilter());r&&u&&d.length&&(l.push("__global__"),d.forEach(g=>{var x;o.push({id:g.id,filterFn:u,resolvedValue:(x=u.resolveFilterValue==null?void 0:u.resolveFilterValue(r))!=null?x:r})}));let f,h;for(let g=0;g{x.columnFiltersMeta[w]=C})}if(o.length){for(let b=0;b{x.columnFiltersMeta[w]=C})){x.columnFilters.__global__=!0;break}}x.columnFilters.__global__!==!0&&(x.columnFilters.__global__=!1)}}const m=g=>{for(let x=0;xe._autoResetPageIndex()))}function Dee(){return e=>ot(()=>[e.getState().grouping,e.getPreGroupedRowModel()],(t,n)=>{if(!n.rows.length||!t.length)return n.rows.forEach(d=>{d.depth=0,d.parentId=void 0}),n;const r=t.filter(d=>e.getColumn(d)),s=[],o={},l=function(d,f,h){if(f===void 0&&(f=0),f>=r.length)return d.map(b=>(b.depth=f,s.push(b),o[b.id]=b,b.subRows&&(b.subRows=l(b.subRows,f+1,b.id)),b));const m=r[f],g=Fee(d,m);return Array.from(g.entries()).map((b,w)=>{let[C,k]=b,j=`${m}:${C}`;j=h?`${h}>${j}`:j;const M=l(k,f+1,j);M.forEach(N=>{N.parentId=j});const _=f?lI(k,N=>N.subRows):k,R=bg(e,j,_[0].original,w,f,void 0,h);return Object.assign(R,{groupingColumnId:m,groupingValue:C,subRows:M,leafRows:_,getValue:N=>{if(r.includes(N)){if(R._valuesCache.hasOwnProperty(N))return R._valuesCache[N];if(k[0]){var O;R._valuesCache[N]=(O=k[0].getValue(N))!=null?O:void 0}return R._valuesCache[N]}if(R._groupingValuesCache.hasOwnProperty(N))return R._groupingValuesCache[N];const D=e.getColumn(N),z=D?.getAggregationFn();if(z)return R._groupingValuesCache[N]=z(N,_,k),R._groupingValuesCache[N]}}),M.forEach(N=>{s.push(N),o[N.id]=N}),R})},u=l(n.rows,0);return u.forEach(d=>{s.push(d),o[d.id]=d}),{rows:u,flatRows:s,rowsById:o}},at(e.options,"debugTable","getGroupedRowModel",()=>{e._queue(()=>{e._autoResetExpanded(),e._autoResetPageIndex()})}))}function Fee(e,t){const n=new Map;return e.reduce((r,s)=>{const o=`${s.getGroupingValue(t)}`,l=r.get(o);return l?l.push(s):r.set(o,[s]),r},n)}function Lee(){return e=>ot(()=>[e.getState().sorting,e.getPreSortedRowModel()],(t,n)=>{if(!n.rows.length||!(t!=null&&t.length))return n;const r=e.getState().sorting,s=[],o=r.filter(d=>{var f;return(f=e.getColumn(d.id))==null?void 0:f.getCanSort()}),l={};o.forEach(d=>{const f=e.getColumn(d.id);f&&(l[d.id]={sortUndefined:f.columnDef.sortUndefined,invertSorting:f.columnDef.invertSorting,sortingFn:f.getSortingFn()})});const u=d=>{const f=d.map(h=>({...h}));return f.sort((h,m)=>{for(let x=0;x{var m;s.push(h),(m=h.subRows)!=null&&m.length&&(h.subRows=u(h.subRows))}),f};return{rows:u(n.rows),flatRows:s,rowsById:n.rowsById}},at(e.options,"debugTable","getSortedRowModel",()=>e._autoResetPageIndex()))}/** * react-table * * Copyright (c) TanStack * * This source code is licensed under the MIT license found in the * LICENSE.md file in the root directory of this source tree. * * @license MIT */function bk(e,t){return e?$ee(e)?y.createElement(e,t):e:null}function $ee(e){return Bee(e)||typeof e=="function"||zee(e)}function Bee(e){return typeof e=="function"&&(()=>{const t=Object.getPrototypeOf(e);return t.prototype&&t.prototype.isReactComponent})()}function zee(e){return typeof e=="object"&&typeof e.$$typeof=="symbol"&&["react.memo","react.forward_ref"].includes(e.$$typeof.description)}function Uee(e){const t={state:{},onStateChange:()=>{},renderFallbackValue:null,...e},[n]=y.useState(()=>({current:_ee(t)})),[r,s]=y.useState(()=>n.current.initialState);return n.current.setOptions(o=>({...o,...e,state:{...r,...e.state},onStateChange:l=>{s(l),e.onStateChange==null||e.onStateChange(l)}})),n.current}const yI=y.forwardRef(({className:e,...t},n)=>i.jsx("div",{className:"relative w-full overflow-auto",children:i.jsx("table",{ref:n,className:Ie("w-full caption-bottom text-sm",e),...t})}));yI.displayName="Table";const bI=y.forwardRef(({className:e,...t},n)=>i.jsx("thead",{ref:n,className:Ie("[&_tr]:border-b",e),...t}));bI.displayName="TableHeader";const xI=y.forwardRef(({className:e,...t},n)=>i.jsx("tbody",{ref:n,className:Ie("[&_tr:last-child]:border-0",e),...t}));xI.displayName="TableBody";const Vee=y.forwardRef(({className:e,...t},n)=>i.jsx("tfoot",{ref:n,className:Ie("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",e),...t}));Vee.displayName="TableFooter";const Eu=y.forwardRef(({className:e,...t},n)=>i.jsx("tr",{ref:n,className:Ie("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",e),...t}));Eu.displayName="TableRow";const wI=y.forwardRef(({className:e,...t},n)=>i.jsx("th",{ref:n,className:Ie("h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0",e),...t}));wI.displayName="TableHead";const Np=y.forwardRef(({className:e,...t},n)=>i.jsx("td",{ref:n,className:Ie("p-4 align-middle [&:has([role=checkbox])]:pr-0",e),...t}));Np.displayName="TableCell";const Hee=y.forwardRef(({className:e,...t},n)=>i.jsx("caption",{ref:n,className:Ie("mt-4 text-sm text-muted-foreground",e),...t}));Hee.displayName="TableCaption";function $a({columns:e,data:t,isLoading:n,loadingMessage:r,noResultsMessage:s,enableHeaders:o=!0,className:l,highlightedRows:u,...d}){const f=Uee({...d,data:t,columns:e,getCoreRowModel:Ree(),getFilteredRowModel:Aee(),getGroupedRowModel:Dee(),getSortedRowModel:Lee()});return i.jsx("div",{className:Ie("rounded-md border",l),children:i.jsxs(yI,{children:[o&&i.jsx(bI,{children:f.getHeaderGroups().map(h=>i.jsx(Eu,{children:h.headers.map(m=>i.jsx(wI,{children:m.isPlaceholder?null:bk(m.column.columnDef.header,m.getContext())},m.id))},h.id))}),i.jsx(xI,{children:n?i.jsx(Eu,{children:i.jsx(Np,{colSpan:e.length,className:"h-24 text-center text-muted-foreground",children:r??"Carregando..."})}):i.jsx(i.Fragment,{children:f.getRowModel().rows?.length?f.getRowModel().rows.map(h=>i.jsx(Eu,{"data-state":h.getIsSelected()?"selected":u?.includes(h.id)?"highlighted":"",children:h.getVisibleCells().map(m=>i.jsx(Np,{children:bk(m.column.columnDef.cell,m.getContext())},m.id))},h.id)):i.jsx(Eu,{children:i.jsx(Np,{colSpan:e.length,className:"h-24 text-center",children:s??"Nenhum resultado encontrado!"})})})})]})})}const qee=e=>["dify","fetchSessions",JSON.stringify(e)],Kee=async({difyId:e,instanceName:t})=>(await Ee.get(`/dify/fetchSessions/${e}/${t}`)).data,Wee=e=>{const{difyId:t,instanceName:n,...r}=e;return mt({...r,queryKey:qee({difyId:t,instanceName:n}),queryFn:()=>Kee({difyId:t,instanceName:n}),enabled:!!n&&!!t&&(e.enabled??!0),staleTime:1e3*10})};function SI({difyId:e}){const{t}=Ve(),{instance:n}=ct(),{changeStatusDify:r}=vg(),[s,o]=y.useState([]),{data:l,refetch:u}=Wee({difyId:e,instanceName:n?.name}),[d,f]=y.useState(!1),[h,m]=y.useState("");function g(){u()}const x=async(w,C)=>{try{if(!n)return;await r({instanceName:n.name,token:n.token,remoteJid:w,status:C}),me.success(t("dify.toast.success.status")),g()}catch(k){console.error("Error:",k),me.error(`Error : ${k?.response?.data?.response?.message}`)}},b=[{accessorKey:"remoteJid",header:()=>i.jsx("div",{className:"text-center",children:t("dify.sessions.table.remoteJid")}),cell:({row:w})=>i.jsx("div",{children:w.getValue("remoteJid")})},{accessorKey:"pushName",header:()=>i.jsx("div",{className:"text-center",children:t("dify.sessions.table.pushName")}),cell:({row:w})=>i.jsx("div",{children:w.getValue("pushName")})},{accessorKey:"sessionId",header:()=>i.jsx("div",{className:"text-center",children:t("dify.sessions.table.sessionId")}),cell:({row:w})=>i.jsx("div",{children:w.getValue("sessionId")})},{accessorKey:"status",header:()=>i.jsx("div",{className:"text-center",children:t("dify.sessions.table.status")}),cell:({row:w})=>i.jsx("div",{children:w.getValue("status")})},{id:"actions",enableHiding:!1,cell:({row:w})=>{const C=w.original;return i.jsxs(Kr,{children:[i.jsx(Wr,{asChild:!0,children:i.jsxs(se,{variant:"ghost",className:"h-8 w-8 p-0",children:[i.jsx("span",{className:"sr-only",children:t("dify.sessions.table.actions.title")}),i.jsx(Pa,{className:"h-4 w-4"})]})}),i.jsxs(hr,{align:"end",children:[i.jsx(Ao,{children:t("dify.sessions.table.actions.title")}),i.jsx(Xs,{}),C.status!=="opened"&&i.jsxs(wt,{onClick:()=>x(C.remoteJid,"opened"),children:[i.jsx(Fi,{className:"mr-2 h-4 w-4"}),t("dify.sessions.table.actions.open")]}),C.status!=="paused"&&C.status!=="closed"&&i.jsxs(wt,{onClick:()=>x(C.remoteJid,"paused"),children:[i.jsx(Di,{className:"mr-2 h-4 w-4"}),t("dify.sessions.table.actions.pause")]}),C.status!=="closed"&&i.jsxs(wt,{onClick:()=>x(C.remoteJid,"closed"),children:[i.jsx(Oi,{className:"mr-2 h-4 w-4"}),t("dify.sessions.table.actions.close")]}),i.jsxs(wt,{onClick:()=>x(C.remoteJid,"delete"),children:[i.jsx(Ii,{className:"mr-2 h-4 w-4"}),t("dify.sessions.table.actions.delete")]})]})]})}}];return i.jsxs(Pt,{open:d,onOpenChange:f,children:[i.jsx(Bt,{asChild:!0,children:i.jsxs(se,{variant:"secondary",size:"sm",children:[i.jsx(Ai,{size:16,className:"mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:t("dify.sessions.label")})]})}),i.jsxs(Nt,{className:"overflow-y-auto sm:max-w-[950px]",onCloseAutoFocus:g,children:[i.jsx(Mt,{children:i.jsx(zt,{children:t("dify.sessions.label")})}),i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between gap-6 p-5",children:[i.jsx(ne,{placeholder:t("dify.sessions.search"),value:h,onChange:w=>m(w.target.value)}),i.jsx(se,{variant:"outline",onClick:g,size:"icon",children:i.jsx(Li,{})})]}),i.jsx($a,{columns:b,data:l??[],onSortingChange:o,state:{sorting:s,globalFilter:h},onGlobalFilterChange:m,enableGlobalFilter:!0,noResultsMessage:t("dify.sessions.table.none")})]})]})]})}const Gee=P.object({enabled:P.boolean(),description:P.string(),botType:P.string(),apiUrl:P.string(),apiKey:P.string(),triggerType:P.string(),triggerOperator:P.string().optional(),triggerValue:P.string().optional(),expire:P.coerce.number().optional(),keywordFinish:P.string().optional(),delayMessage:P.coerce.number().optional(),unknownMessage:P.string().optional(),listeningFromMe:P.boolean().optional(),stopBotFromMe:P.boolean().optional(),keepOpen:P.boolean().optional(),debounceTime:P.coerce.number().optional(),splitMessages:P.boolean().optional(),timePerChar:P.coerce.number().optional()});function CI({initialData:e,onSubmit:t,handleDelete:n,difyId:r,isModal:s=!1,isLoading:o=!1,openDeletionDialog:l=!1,setOpenDeletionDialog:u=()=>{}}){const{t:d}=Ve(),f=on({resolver:an(Gee),defaultValues:e||{enabled:!0,description:"",botType:"chatBot",apiUrl:"",apiKey:"",triggerType:"keyword",triggerOperator:"contains",triggerValue:"",expire:0,keywordFinish:"",delayMessage:0,unknownMessage:"",listeningFromMe:!1,stopBotFromMe:!1,keepOpen:!1,debounceTime:0,splitMessages:!1,timePerChar:0}}),h=f.watch("triggerType");return i.jsx(Gn,{...f,children:i.jsxs("form",{onSubmit:f.handleSubmit(t),className:"w-full space-y-6",children:[i.jsxs("div",{className:"space-y-4",children:[i.jsx(Pe,{name:"enabled",label:d("dify.form.enabled.label"),reverse:!0}),i.jsx(le,{name:"description",label:d("dify.form.description.label"),required:!0,children:i.jsx(ne,{})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:d("dify.form.difySettings.label")}),i.jsx($t,{})]}),i.jsx(Jt,{name:"botType",label:d("dify.form.botType.label"),options:[{label:d("dify.form.botType.chatBot"),value:"chatBot"},{label:d("dify.form.botType.textGenerator"),value:"textGenerator"},{label:d("dify.form.botType.agent"),value:"agent"},{label:d("dify.form.botType.workflow"),value:"workflow"}]}),i.jsx(le,{name:"apiUrl",label:d("dify.form.apiUrl.label"),required:!0,children:i.jsx(ne,{})}),i.jsx(le,{name:"apiKey",label:d("dify.form.apiKey.label"),required:!0,children:i.jsx(ne,{type:"password"})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:d("dify.form.triggerSettings.label")}),i.jsx($t,{})]}),i.jsx(Jt,{name:"triggerType",label:d("dify.form.triggerType.label"),options:[{label:d("dify.form.triggerType.keyword"),value:"keyword"},{label:d("dify.form.triggerType.all"),value:"all"},{label:d("dify.form.triggerType.advanced"),value:"advanced"},{label:d("dify.form.triggerType.none"),value:"none"}]}),h==="keyword"&&i.jsxs(i.Fragment,{children:[i.jsx(Jt,{name:"triggerOperator",label:d("dify.form.triggerOperator.label"),options:[{label:d("dify.form.triggerOperator.contains"),value:"contains"},{label:d("dify.form.triggerOperator.equals"),value:"equals"},{label:d("dify.form.triggerOperator.startsWith"),value:"startsWith"},{label:d("dify.form.triggerOperator.endsWith"),value:"endsWith"},{label:d("dify.form.triggerOperator.regex"),value:"regex"}]}),i.jsx(le,{name:"triggerValue",label:d("dify.form.triggerValue.label"),children:i.jsx(ne,{})})]}),h==="advanced"&&i.jsx(le,{name:"triggerValue",label:d("dify.form.triggerConditions.label"),children:i.jsx(ne,{})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:d("dify.form.generalSettings.label")}),i.jsx($t,{})]}),i.jsx(le,{name:"expire",label:d("dify.form.expire.label"),children:i.jsx(ne,{type:"number"})}),i.jsx(le,{name:"keywordFinish",label:d("dify.form.keywordFinish.label"),children:i.jsx(ne,{})}),i.jsx(le,{name:"delayMessage",label:d("dify.form.delayMessage.label"),children:i.jsx(ne,{type:"number"})}),i.jsx(le,{name:"unknownMessage",label:d("dify.form.unknownMessage.label"),children:i.jsx(ne,{})}),i.jsx(Pe,{name:"listeningFromMe",label:d("dify.form.listeningFromMe.label"),reverse:!0}),i.jsx(Pe,{name:"stopBotFromMe",label:d("dify.form.stopBotFromMe.label"),reverse:!0}),i.jsx(Pe,{name:"keepOpen",label:d("dify.form.keepOpen.label"),reverse:!0}),i.jsx(le,{name:"debounceTime",label:d("dify.form.debounceTime.label"),children:i.jsx(ne,{type:"number"})}),i.jsx(Pe,{name:"splitMessages",label:d("dify.form.splitMessages.label"),reverse:!0}),f.watch("splitMessages")&&i.jsx(le,{name:"timePerChar",label:d("dify.form.timePerChar.label"),children:i.jsx(ne,{type:"number"})})]}),s&&i.jsx(Yt,{children:i.jsx(se,{disabled:o,type:"submit",children:d(o?"dify.button.saving":"dify.button.save")})}),!s&&i.jsxs("div",{children:[i.jsx(SI,{difyId:r}),i.jsxs("div",{className:"mt-5 flex items-center gap-3",children:[i.jsxs(Pt,{open:l,onOpenChange:u,children:[i.jsx(Bt,{asChild:!0,children:i.jsx(se,{variant:"destructive",size:"sm",children:d("dify.button.delete")})}),i.jsx(Nt,{children:i.jsxs(Mt,{children:[i.jsx(zt,{children:d("modal.delete.title")}),i.jsx(eo,{children:d("modal.delete.messageSingle")}),i.jsxs(Yt,{children:[i.jsx(se,{size:"sm",variant:"outline",onClick:()=>u(!1),children:d("button.cancel")}),i.jsx(se,{variant:"destructive",onClick:n,children:d("button.delete")})]})]})})]}),i.jsx(se,{disabled:o,type:"submit",children:d(o?"dify.button.saving":"dify.button.update")})]})]})]})})}function Jee({resetTable:e}){const{t}=Ve(),{instance:n}=ct(),[r,s]=y.useState(!1),[o,l]=y.useState(!1),{createDify:u}=vg(),d=async f=>{try{if(!n||!n.name)throw new Error("instance not found");s(!0);const h={enabled:f.enabled,description:f.description,botType:f.botType,apiUrl:f.apiUrl,apiKey:f.apiKey,triggerType:f.triggerType,triggerOperator:f.triggerOperator||"",triggerValue:f.triggerValue||"",expire:f.expire||0,keywordFinish:f.keywordFinish||"",delayMessage:f.delayMessage||0,unknownMessage:f.unknownMessage||"",listeningFromMe:f.listeningFromMe||!1,stopBotFromMe:f.stopBotFromMe||!1,keepOpen:f.keepOpen||!1,debounceTime:f.debounceTime||0,splitMessages:f.splitMessages||!1,timePerChar:f.timePerChar||0};await u({instanceName:n.name,token:n.token,data:h}),me.success(t("dify.toast.success.create")),l(!1),e()}catch(h){console.error("Error:",h),me.error(`Error: ${h?.response?.data?.response?.message}`)}finally{s(!1)}};return i.jsxs(Pt,{open:o,onOpenChange:l,children:[i.jsx(Bt,{asChild:!0,children:i.jsxs(se,{size:"sm",children:[i.jsx(cs,{size:16,className:"mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:t("dify.button.create")})]})}),i.jsxs(Nt,{className:"overflow-y-auto sm:max-h-[600px] sm:max-w-[740px]",children:[i.jsx(Mt,{children:i.jsx(zt,{children:t("dify.form.title")})}),i.jsx(CI,{onSubmit:d,isModal:!0,isLoading:r})]})]})}const Qee=e=>["dify","getDify",JSON.stringify(e)],Zee=async({difyId:e,instanceName:t})=>(await Ee.get(`/dify/fetch/${e}/${t}`)).data,Yee=e=>{const{difyId:t,instanceName:n,...r}=e;return mt({...r,queryKey:Qee({difyId:t,instanceName:n}),queryFn:()=>Zee({difyId:t,instanceName:n}),enabled:!!n&&!!t&&(e.enabled??!0)})};function Xee({difyId:e,resetTable:t}){const{t:n}=Ve(),{instance:r}=ct(),s=dn(),[o,l]=y.useState(!1),{deleteDify:u,updateDify:d}=vg(),{data:f,isLoading:h}=Yee({difyId:e,instanceName:r?.name}),m=y.useMemo(()=>({enabled:!!f?.enabled,description:f?.description??"",botType:f?.botType??"",apiUrl:f?.apiUrl??"",apiKey:f?.apiKey??"",triggerType:f?.triggerType??"",triggerOperator:f?.triggerOperator??"",triggerValue:f?.triggerValue??"",expire:f?.expire??0,keywordFinish:f?.keywordFinish??"",delayMessage:f?.delayMessage??0,unknownMessage:f?.unknownMessage??"",listeningFromMe:!!f?.listeningFromMe,stopBotFromMe:!!f?.stopBotFromMe,keepOpen:!!f?.keepOpen,debounceTime:f?.debounceTime??0,splitMessages:f?.splitMessages??!1,timePerChar:f?.timePerChar??0}),[f?.apiKey,f?.apiUrl,f?.botType,f?.debounceTime,f?.delayMessage,f?.description,f?.enabled,f?.expire,f?.keepOpen,f?.keywordFinish,f?.listeningFromMe,f?.stopBotFromMe,f?.triggerOperator,f?.triggerType,f?.triggerValue,f?.unknownMessage,f?.splitMessages,f?.timePerChar]),g=async b=>{try{if(r&&r.name&&e){const w={enabled:b.enabled,description:b.description,botType:b.botType,apiUrl:b.apiUrl,apiKey:b.apiKey,triggerType:b.triggerType,triggerOperator:b.triggerOperator||"",triggerValue:b.triggerValue||"",expire:b.expire||0,keywordFinish:b.keywordFinish||"",delayMessage:b.delayMessage||1e3,unknownMessage:b.unknownMessage||"",listeningFromMe:b.listeningFromMe||!1,stopBotFromMe:b.stopBotFromMe||!1,keepOpen:b.keepOpen||!1,debounceTime:b.debounceTime||0,splitMessages:b.splitMessages||!1,timePerChar:b.timePerChar||0};await d({instanceName:r.name,difyId:e,data:w}),me.success(n("dify.toast.success.update")),t(),s(`/manager/instance/${r.id}/dify/${e}`)}else console.error("Token not found")}catch(w){console.error("Error:",w),me.error(`Error: ${w?.response?.data?.response?.message}`)}},x=async()=>{try{r&&r.name&&e?(await u({instanceName:r.name,difyId:e}),me.success(n("dify.toast.success.delete")),l(!1),t(),s(`/manager/instance/${r.id}/dify`)):console.error("instance not found")}catch(b){console.error("Erro ao excluir dify:",b)}};return h?i.jsx(On,{}):i.jsx("div",{className:"m-4",children:i.jsx(CI,{initialData:m,onSubmit:g,difyId:e,handleDelete:x,isModal:!1,isLoading:h,openDeletionDialog:o,setOpenDeletionDialog:l})})}function xk(){const{t:e}=Ve(),t=zo("(min-width: 768px)"),{instance:n}=ct(),{difyId:r}=ls(),{data:s,refetch:o,isLoading:l}=iI({instanceName:n?.name}),u=dn(),d=h=>{n&&u(`/manager/instance/${n.id}/dify/${h}`)},f=()=>{o()};return i.jsxs("main",{className:"pt-5",children:[i.jsxs("div",{className:"mb-1 flex items-center justify-between",children:[i.jsx("h3",{className:"text-lg font-medium",children:e("dify.title")}),i.jsxs("div",{className:"flex items-center justify-end gap-2",children:[i.jsx(SI,{}),i.jsx(WX,{}),i.jsx(Jee,{resetTable:f})]})]}),i.jsx($t,{className:"my-4"}),i.jsxs($o,{direction:t?"horizontal":"vertical",children:[i.jsx(Hn,{defaultSize:35,className:"pr-4",children:i.jsx("div",{className:"flex flex-col gap-3",children:l?i.jsx(On,{}):i.jsx(i.Fragment,{children:s&&s.length>0&&Array.isArray(s)?s.map(h=>i.jsxs(se,{className:"flex h-auto flex-col items-start justify-start",onClick:()=>d(`${h.id}`),variant:r===h.id?"secondary":"outline",children:[i.jsx("h4",{className:"text-base",children:h.description||h.id}),i.jsx("p",{className:"text-sm font-normal text-muted-foreground",children:h.botType})]},h.id)):i.jsx(se,{variant:"link",children:e("dify.table.none")})})})}),r&&i.jsxs(i.Fragment,{children:[i.jsx(Bo,{withHandle:!0,className:"border border-border"}),i.jsx(Hn,{children:i.jsx(Xee,{difyId:r,resetTable:f})})]})]})]})}const EI=y.createContext({instance:null,isLoading:!0,error:null});function ete({children:e}){const[t]=hd(),[n,r]=y.useState(null),[s,o]=y.useState(!0),[l,u]=y.useState(null);return y.useEffect(()=>{(async()=>{const f=t.get("token"),h=t.get("instanceName"),m=t.get("apiUrl");if(!f||!h||!m){u("Token, instanceName e apiUrl são obrigatórios"),o(!1);return}try{const g=m.endsWith("/")?m.slice(0,-1):m;localStorage.setItem(jn.API_URL,g),localStorage.setItem(jn.INSTANCE_TOKEN,f);const{data:x}=await sn.get(`${g}/instance/fetchInstances?instanceName=${h}`,{headers:{apikey:f}});console.log("API Response:",x),x&&Array.isArray(x)&&x.length>0?r(x[0]):u("Instância não encontrada")}catch{u("Erro ao validar token ou buscar instância")}finally{o(!1)}})()},[t]),i.jsx(EI.Provider,{value:{instance:n,isLoading:s,error:l},children:e})}const cw=()=>y.useContext(EI),uw=y.createContext({}),tte=({children:e})=>{const[t,n]=y.useState(null);return i.jsx(uw.Provider,{value:{replyingMessage:t,setReplyingMessage:n},children:e})},nte=e=>{const t=Math.floor(e/60),n=e%60,r=t<10?`${t}`:t,s=n<10?`0${n}`:n;return`${r}:${s}`},wk=200,rte=({imageMessage:e})=>i.jsxs("div",{className:"flex flex-col gap-2",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("img",{src:e?.mediaUrl,alt:"Quoted message",width:100,height:100}),i.jsx(cB,{className:"mr-2 h-4 w-4 text-muted-foreground"})]}),i.jsx("span",{className:"inline-block max-w-40 overflow-hidden overflow-ellipsis whitespace-nowrap text-sm text-muted-foreground",children:e.caption})]}),ste=({videoMessage:e})=>i.jsxs("div",{className:"flex flex-col gap-2",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("img",{src:e?.mediaUrl,alt:"Quoted message",width:100,height:100}),i.jsx(TB,{className:"mr-2 h-4 w-4 text-muted-foreground"})]}),i.jsx("span",{className:"inline-block max-w-40 overflow-hidden overflow-ellipsis whitespace-nowrap text-sm text-muted-foreground",children:e.caption})]}),ote=({audioMessage:e})=>i.jsxs("div",{className:"flex flex-col gap-2",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(hT,{className:"h-6 w-6 text-muted-foreground"}),i.jsx("span",{className:"text-sm text-muted-foreground",children:nte(e.seconds)})]}),i.jsx("span",{className:"inline-block max-w-40 overflow-hidden overflow-ellipsis whitespace-nowrap text-sm text-muted-foreground",children:e.fileName})]}),ate=({stickerMessage:e})=>i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("img",{src:e.mediaUrl,alt:"Sticker",width:100,height:100}),i.jsx(CB,{className:"h-6 w-6 text-muted-foreground"})]}),ite=({documentMessage:e})=>i.jsx("div",{className:"flex flex-col gap-2",children:i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Hb,{className:"h-6 w-6 text-muted-foreground"}),i.jsx("span",{className:"text-sm text-muted-foreground",children:e.fileName})]})}),lte=({documentMessage:e})=>i.jsxs("div",{className:"flex flex-col gap-2",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Hb,{className:"h-6 w-6 text-muted-foreground"}),i.jsx("span",{className:"text-sm text-muted-foreground",children:e.fileName})]}),i.jsx("span",{className:"inline-block max-w-40 overflow-hidden overflow-ellipsis whitespace-nowrap text-sm text-muted-foreground",children:e.caption})]}),cte=({contactMessage:e})=>i.jsx("div",{className:"flex flex-col gap-2",children:i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Ap,{className:"h-6 w-6 text-muted-foreground"}),i.jsx("span",{className:"text-sm text-muted-foreground",children:e.displayName})]})}),ute=({locationMessage:e})=>i.jsxs("div",{className:"flex flex-col gap-2",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(yB,{className:"h-6 w-6 text-muted-foreground"}),i.jsx("span",{className:"text-sm text-muted-foreground",children:e.name})]}),i.jsx("span",{className:"inline-block max-w-40 text-sm text-muted-foreground",children:e.address})]}),dte=({conversation:e})=>i.jsx("span",{className:"overflow-hidden text-ellipsis whitespace-nowrap text-sm text-muted-foreground",children:e.length>wk?`${e.substring(0,wk)}...`:e}),fte=({chat:e})=>{const{replyingMessage:t,setReplyingMessage:n}=y.useContext(uw),r=()=>{n(null)},s=f=>f?.conversation?f.conversation:f?.viewOnceMessage?.message?.interactiveMessage?.body?.text?f.viewOnceMessage.message.interactiveMessage.body.text:"",o=()=>t?.key.fromMe?"Você":e?.pushName,l=()=>{if(t?.messageType==="imageMessage")return i.jsx(rte,{imageMessage:{caption:t?.message.imageMessage.caption,mediaUrl:t?.message.mediaUrl}});if(t?.messageType==="videoMessage")return i.jsx(ste,{videoMessage:{caption:t?.message.videoMessage.caption,mediaUrl:t?.message.mediaUrl}});if(t?.messageType==="audioMessage")return i.jsx(ote,{audioMessage:t?.message.audioMessage});if(t?.messageType==="stickerMessage")return i.jsx(ate,{stickerMessage:t?.message});if(t?.messageType==="documentMessage")return i.jsx(ite,{documentMessage:{name:t?.message.documentMessage.name,mediaUrl:t?.message.mediaUrl}});if(t?.messageType==="documentWithCaptionMessage")return i.jsx(lte,{documentMessage:{name:t?.message.documentWithCaptionMessage.message.documentMessage.name,caption:t?.message.documentWithCaptionMessage.message.documentMessage.caption,mediaUrl:t?.message.mediaUrl}});if(t?.messageType==="contactMessage")return i.jsx(cte,{contactMessage:t?.message.contactMessage});if(t?.messageType==="locationMessage")return i.jsx(ute,{locationMessage:t?.message.locationMessage});if(t?.messageType==="conversation"||t?.messageType==="interactiveMessage"||t?.messageType==="extendedTextMessage")return i.jsx(dte,{conversation:s(t?.message)})},{inputIconsMainColor:u,inputBackgroundColor:d}=La();return i.jsxs("div",{className:"relative flex items-center overflow-hidden rounded-lg dark:text-white",style:{backgroundColor:d},children:[i.jsx("div",{className:`absolute h-full w-1 rounded-l-lg ${t?.key.fromMe?"bg-blue-700 dark:bg-blue-300":"bg-blue-100"}`}),i.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-2 p-2 pl-4",children:[i.jsx("span",{className:`text-sm font-bold ${t?.key.fromMe?"text-blue-700 dark:text-blue-300":"text-blue-600"}`,children:o()}),l()]}),i.jsx(se,{size:"icon",variant:"ghost",className:"ml-auto h-10 w-10 shrink-0 rounded-full",onClick:r,style:{backgroundColor:d,color:u},children:i.jsx(qb,{className:"h-6 w-6"})})]})},yy=[{name:"Smileys",icon:gT,emojis:["😀","😃","😄","😁","😆","😅","😂","🤣","😊","😇"]},{name:"Natureza",icon:HC,emojis:["🌿","🌱","🌳","🌴","🌵","🌷","🌸","🌹","🌺","🌻"]},{name:"Comida",icon:HC,emojis:["🍎","🍐","🍊","🍋","🍌","🍉","🍇","🍓","🍒","🍑"]},{name:"Atividades",icon:Y$,emojis:["⚽️","🏀","🏈","⚾️","🎾","🏐","🏉","🎱","🏓","🏸"]},{name:"Viagem",icon:K$,emojis:["🚗","🚕","🚙","🚌","🚎","🏎","🚓","🚑","🚒","🚐"]},{name:"Objetos",icon:gB,emojis:["💡","🔦","🕯","🧳","⌛️","⏳","🌡","🧪","🧬","🔬"]},{name:"Símbolos",icon:oB,emojis:["❤️","🧡","💛","💚","💙","💜","🖤","🤍","🤎","💔"]}];function pte({handleEmojiClick:e}){const{inputIconsMainColor:t}=La(),n=r=>yy.find(o=>o.name===r)?.emojis||[];return i.jsxs(Kr,{children:[i.jsx(Wr,{asChild:!0,children:i.jsxs(se,{type:"button",variant:"ghost",size:"icon",className:"rounded-full p-2",children:[i.jsx(gT,{className:"h-6 w-6",style:{color:t}}),i.jsx("span",{className:"sr-only",children:"Emojis"})]})}),i.jsx(hr,{className:"bg-background p-2",align:"end",children:i.jsxs(Yx,{defaultValue:"Smileys",className:"w-full",children:[i.jsx(hg,{className:"grid grid-cols-8 gap-2",children:yy.map(r=>i.jsx(Jl,{value:r.name,children:i.jsx(r.icon,{className:"h-5 w-5"})},r.name))}),yy.map(r=>i.jsx(Ql,{value:r.name,children:i.jsx("div",{className:"grid grid-cols-8 gap-2",children:n(r.name).map((s,o)=>i.jsx(se,{variant:"ghost",className:"h-12 p-2 text-2xl",onClick:()=>e(s),children:s},o))})},r.name))]})})]})}const hte=({isSendingMessage:e,isRecording:t,audioBlob:n,elapsedTime:r,startRecording:s,stopRecording:o,clearRecording:l,sendAudioMessage:u,disabled:d})=>{const{inputIconsMainColor:f}=La();return i.jsxs("div",{className:"flex items-center gap-2",children:[t&&i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(se,{type:"button",size:"icon",variant:"ghost",className:"rounded-full p-2",onClick:o,children:i.jsx(SB,{className:"h-6 w-6 text-[#b03f3f]"})}),i.jsxs("span",{children:[r,"s"]})]}),n&&i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(se,{type:"button",size:"icon",variant:"ghost",className:"rounded-full p-2",disabled:e,onClick:l,children:i.jsx(kB,{className:"h-6 w-6 text-[#b03f3f]"})}),i.jsx("audio",{controls:!0,src:URL.createObjectURL(n)})]}),i.jsx(se,{type:"button",size:"icon",variant:"ghost",className:"rounded-full p-2",disabled:e||t||d,onClick:n?u:s,children:e?i.jsx(On,{className:"h-6 w-6",style:{color:f}}):n?i.jsx(Th,{className:"h-6 w-6",style:{color:f}}):i.jsx(hT,{className:"h-6 w-6",style:{color:f}})})]})},gte=({isSendingMessage:e,sendMessage:t,disabled:n})=>{const{inputIconsMainColor:r}=La();return i.jsx(se,{type:"button",size:"icon",variant:"ghost",className:"rounded-full p-2",onClick:t,disabled:e||n,children:e?i.jsx(On,{className:"h-6 w-6",style:{color:r}}):i.jsx(Th,{className:"h-6 w-6",style:{color:r}})})},mte=({chat:e})=>{const[t]=hd(),{inputBackgroundColor:n,inputTextForegroundColor:r}=La(),s=t.get("remoteJid"),{instance:o}=cw(),{sendText:l}=KO(),{sendMedia:u}=WO(),{sendAudio:d}=iX(),{replyingMessage:f,setReplyingMessage:h}=y.useContext(uw),m=y.useRef(null),g=y.useRef(null),x=y.useRef(null),[b,w]=y.useState(""),[C,k]=y.useState(!1),[j,M]=y.useState(null),[_,R]=y.useState(!1),[N,O]=y.useState(null),[D,z]=y.useState(0),{t:Q}=Ve();y.useEffect(()=>{h(null),M(null)},[s,h,M]);const pe=te=>{if(w(te.target.value),m.current){m.current.style.height="auto";const de=m.current.scrollHeight,Z=parseInt(getComputedStyle(m.current).lineHeight)*10;m.current.style.height=`${Math.min(de,Z)}px`}},V=te=>{if(w(de=>de+te),m.current){m.current.style.height="auto";const de=m.current.scrollHeight,Z=parseInt(getComputedStyle(m.current).lineHeight)*10;m.current.style.height=`${Math.min(de,Z)}px`}},G=async()=>{try{R(!0);const te=await navigator.mediaDevices.getUserMedia({audio:{channelCount:1,sampleRate:44100,echoCancellation:!0,noiseSuppression:!0}});let de="";const ge=["audio/aac","audio/mp4","audio/mpeg","audio/amr","audio/ogg","audio/opus"];for(const Re of ge)if(MediaRecorder.isTypeSupported(Re)){de=Re;break}if(!de)throw new Error("Nenhum formato aceito pela Meta disponível");const Z=new MediaRecorder(te,{mimeType:de,audioBitsPerSecond:128e3});x.current=Z;const ye=[];Z.ondataavailable=Re=>{Re.data.size>0&&ye.push(Re.data)},Z.onstop=()=>{const Re=new Blob(ye,{type:de}),$e=new File([Re],`audio.${de.split("/")[1]}`,{type:de,lastModified:Date.now()});O($e)},Z.start(),g.current=setInterval(()=>{z(Re=>Re+1)},1e3)}catch(te){console.error("Erro ao iniciar gravação:",te),me.error(Q("chat.toast.recordingError")),R(!1)}},W=()=>{x.current&&(x.current.stop(),g.current&&clearInterval(g.current),R(!1))},ie=()=>{O(null),z(0)},re=te=>{console.error("Error to send message",te),me.error(rT(te)?`${Q("chat.toast.error")}: ${te?.response?.data?.response?.message}`:Q("chat.toast.sendError"))},Y=()=>{k(!1),h(null)},H=async()=>{if(!o?.name||!o?.token||!s)return;const te={instanceName:o.name,token:o.token,data:{number:s,text:b}};await l(te,{onSuccess:()=>{w(""),m.current&&(m.current.style.height="auto")},onError:re,onSettled:Y})},q=async()=>{if(!(!o?.name||!o?.token||!j||!s)){k(!0);try{const te=await new Promise((ge,Z)=>{const ye=new FileReader;ye.readAsDataURL(j),ye.onload=()=>{const $e=ye.result.split(",")[1];ge($e)},ye.onerror=Z}),de={instanceName:o.name,token:o.token,data:{number:s,mediaMessage:{mediatype:j.type.split("/")[0]==="application"?"document":j.type.split("/")[0],mimetype:j.type,caption:b,media:te,fileName:j.name}}};await u(de,{onSuccess:()=>{M(null),w(""),m.current&&(m.current.style.height="auto")},onError:re,onSettled:Y})}catch(te){console.error("Error converting media to base64:",te),re(te),k(!1)}}},he=async()=>{if(!(!o?.name||!o?.token||!N||!s)){k(!0);try{const te=await new Promise((ge,Z)=>{const ye=new FileReader;ye.readAsDataURL(N),ye.onload=()=>{const $e=ye.result.split(",")[1];ge($e)},ye.onerror=Z}),de={instanceName:o.name,token:o.token,data:{number:s,audioMessage:{audio:te}}};await d(de,{onSuccess:()=>{O(null),z(0)},onError:re,onSettled:Y})}catch(te){console.error("Error converting audio to base64:",te),re(te),k(!1)}}},A=async()=>{k(!0),j?await q():await H()},F=()=>!b&&!j?i.jsx(hte,{isSendingMessage:C,isRecording:_,audioBlob:N,elapsedTime:D,startRecording:G,stopRecording:W,clearRecording:ie,sendAudioMessage:he}):i.jsx(gte,{isSendingMessage:C,sendMessage:A}),fe=()=>_||N?F():i.jsxs(i.Fragment,{children:[i.jsx(pte,{handleEmojiClick:V}),i.jsx(JO,{instance:o,setSelectedMedia:M}),i.jsx(bi,{placeholder:Q("chat.message.placeholder"),name:"message",id:"message",rows:1,ref:m,value:b,onChange:pe,onKeyDown:te=>{!te.shiftKey&&te.key==="Enter"&&!C&&(te.preventDefault(),A())},className:"min-h-0 w-full resize-none rounded-lg border-none p-3 focus-visible:outline-none focus-visible:ring-0 focus-visible:ring-transparent focus-visible:ring-offset-0 focus-visible:ring-offset-transparent",style:{backgroundColor:n,color:r}}),F()]});return o?i.jsxs("div",{className:"input-container",children:[j&&i.jsx(QO,{selectedMedia:j,setSelectedMedia:M}),f&&i.jsx(fte,{chat:e}),i.jsx("div",{className:`flex items-end ${(_||N)&&"justify-end"} rounded-3xl px-4 py-1`,style:{backgroundColor:n,color:r},children:fe()})]}):i.jsx("div",{className:"flex h-full items-center justify-center",children:i.jsx("p",{className:"text-muted-foreground",children:Q("chat.noInstance")||"Nenhuma instância selecionada"})})},vte=P.object({remoteJid:P.string().min(1)});function yte({onSuccess:e}){const{t}=Ve(),{primaryColor:n}=La(),r=on({resolver:an(vte),defaultValues:{remoteJid:""}}),s=o=>{e(o)};return i.jsx(Fo,{...r,children:i.jsxs("form",{onSubmit:r.handleSubmit(s),children:[i.jsx(Lo,{control:r.control,name:"remoteJid",render:({field:o})=>i.jsxs(no,{children:[i.jsx(Nr,{children:t("chat.newChat.contact")}),i.jsx(_s,{children:i.jsx(ne,{type:"text",placeholder:t("chat.newChat.placeholder"),...o})})]})}),i.jsx("div",{className:"flex justify-end",children:i.jsx(se,{type:"submit",className:"mt-4",style:{backgroundColor:n},children:t("chat.newChat.submit")})})]})})}function bte({isOpen:e,setIsOpen:t}){const[n]=hd(),{t:r}=Ve(),s=dn(),o=l=>{const u=new URLSearchParams(n);u.set("remoteJid",l.remoteJid),s(`/manager/embed-chat?${u.toString()}`),t(!1)};return i.jsx(Pt,{open:e,onOpenChange:t,children:i.jsxs(Nt,{className:"max-w-2xl",children:[i.jsxs(Mt,{children:[i.jsx(zt,{children:r("chat.newChat.title")}),i.jsx(eo,{children:r("chat.newChat.description")})]}),i.jsx(yte,{onSuccess:o})]})})}const by=e=>e?e.replace("@s.whatsapp.net","").replace("@g.us",""):"";function xte(){const[e]=hd(),{backgroundColor:t,textForegroundColor:n,primaryColor:r}=La(),s=zo("(min-width: 768px)"),{t:o}=Ve(),l=dn(),u=e.get("token"),{remoteJid:d}=ls(),f=d||e.get("remoteJid"),[h,m]=y.useState([]),g=y.useRef(null),x=y.useRef(null),[b,w]=y.useState(null),[C,k]=y.useState(!1),{instance:j}=cw(),M=R=>{const N=new URLSearchParams(e);l(`/manager/embed-chat/${encodeURIComponent(R.remoteJid||R.id)}?${N.toString()}`)};y.useEffect(()=>{if(!j?.name)return;let R=!0;return(async()=>{try{const{data:O}=await Ee.post(`/chat/findChats/${j.name}`,{where:{}},{headers:{apikey:u||j.token}});R&&m(O||[])}catch(O){R&&(console.error("Erro ao buscar chats:",O),me.error("Erro ao buscar chats"))}})(),()=>{R=!1}},[j?.name,u]),y.useEffect(()=>{if(!j)return;const R=dr(jn.API_URL);if(!R){console.error("API URL not found in localStorage");return}const N=localStorage.getItem("accessToken");u&&localStorage.setItem("accessToken",u);const O=sw(R);function D(z,Q){j&&Q.instance===j.name&&m(pe=>{const V=Q?.data?.key?.remoteJid,G=pe.findIndex(re=>re.remoteJid&&re.remoteJid===V||re.id&&re.id===V),W=G!==-1?pe[G]:null,ie={id:V,remoteJid:V,pushName:W?.pushName||Q?.data?.pushName||by(V),profilePicUrl:W?.profilePicUrl||Q?.data?.key?.profilePictureUrl||"https://as2.ftcdn.net/jpg/05/89/93/27/1000_F_589932782_vQAEAZhHnq1QCGu5ikwrYaQD0Mmurm0N.jpg",updatedAt:new Date().toISOString(),labels:W?.labels||[],createdAt:W?.createdAt||new Date().toISOString(),instanceId:j.id};if(G!==-1){const re=[...pe];return re[G]={...W,updatedAt:ie.updatedAt},re}else return[...pe,ie]})}return O.on("messages.upsert",z=>{D("messages.upsert",z)}),O.on("send.message",z=>{D("send.message",z)}),O.on("messages.update",z=>{}),O.connect(),()=>{O.off("messages.upsert"),O.off("send.message"),O.off("messages.update"),ow(O),u?localStorage.setItem("accessToken",N||""):localStorage.removeItem("accessToken")}},[j,f,u]),y.useEffect(()=>{if(f){const R=h.find(N=>N.id===f);w(R||null)}},[f,h]);const _={backgroundColor:t,color:n};return i.jsx("div",{className:"relative h-full",style:_,children:i.jsxs($o,{direction:s?"horizontal":"vertical",children:[i.jsx(Hn,{defaultSize:30,minSize:20,maxSize:60,children:i.jsxs("div",{className:"hidden flex-col gap-2 text-foreground md:flex",style:_,children:[i.jsx("div",{className:"sticky top-0 p-2",children:i.jsxs(se,{variant:"ghost",className:"w-full justify-start gap-2 px-2 text-left",onClick:()=>k(!0),style:{backgroundColor:r,color:n},children:[i.jsx("div",{className:"flex h-7 w-7 items-center justify-center rounded-full",children:i.jsx(Bl,{className:"h-4 w-4"})}),i.jsx("div",{className:"grow overflow-hidden text-ellipsis whitespace-nowrap text-sm",children:o("chat.title")}),i.jsx(cs,{className:"h-4 w-4"})]})}),i.jsxs(Yx,{defaultValue:"contacts",children:[i.jsxs(hg,{className:"tabs-chat",children:[i.jsx(Jl,{value:"contacts",className:"data-[state=active]:bg-primary data-[state=active]:text-primary-foreground",style:{"--primary":r||"#e2e8f0","--primary-foreground":n||"#000000"},children:o("chat.contacts")}),i.jsx(Jl,{value:"groups",className:"data-[state=active]:bg-primary data-[state=active]:text-primary-foreground",style:{"--primary":r||"#e2e8f0","--primary-foreground":n||"#000000"},children:o("chat.groups")})]}),i.jsx(Ql,{value:"contacts",children:i.jsx("div",{className:"contacts-container",children:i.jsxs("div",{className:"grid gap-1 p-2 text-foreground",children:[i.jsx("div",{className:"px-2 text-xs font-medium text-muted-foreground",children:o("chat.contacts")}),h?.sort((R,N)=>new Date(N.lastMessage.messageTimestamp).getTime()-new Date(R.lastMessage.messageTimestamp).getTime()).map(R=>R?.id&&!R.id.includes("@g.us")&&i.jsxs("div",{onClick:()=>M(R),className:"chat-item flex cursor-pointer items-center overflow-hidden rounded-md p-2 text-sm transition-colors",style:{backgroundColor:f===R.id?r:""},children:[i.jsx("span",{className:"chat-avatar mr-2",children:i.jsx("img",{src:R.profilePicUrl||"https://as2.ftcdn.net/jpg/05/89/93/27/1000_F_589932782_vQAEAZhHnq1QCGu5ikwrYaQD0Mmurm0N.jpg",alt:"Avatar",className:"h-12 w-12 rounded-full"})}),i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("span",{className:"chat-title font-medium",style:{color:n},children:R.pushName||by(R.id)}),i.jsx("span",{className:"text-xs",style:{color:n}})]}),i.jsxs("div",{className:"flex items-center gap-1",children:[i.jsxs("span",{className:"text-xs font-bold",style:{color:n},children:[o("chat.recent"),":"," "]}),i.jsx("span",{className:"block truncate text-xs",style:{color:n}})]})]})]},R.id))]})})}),i.jsx(Ql,{value:"groups",children:i.jsx("div",{className:"contacts-container",children:i.jsxs("div",{className:"grid gap-1 p-2 text-foreground",children:[i.jsx("div",{className:"px-2 text-xs font-medium text-muted-foreground",children:o("chat.groups")}),h?.sort((R,N)=>new Date(N.lastMessage.messageTimestamp).getTime()-new Date(R.lastMessage.messageTimestamp).getTime()).map(R=>R?.id&&R.id.includes("@g.us")&&i.jsxs("div",{onClick:()=>M(R),className:"chat-item flex cursor-pointer items-center overflow-hidden rounded-md p-2 text-sm transition-colors",style:{backgroundColor:f===R.id?r:""},children:[i.jsx("span",{className:"chat-avatar mr-2",children:i.jsx("img",{src:R.profilePicUrl||"https://as2.ftcdn.net/jpg/05/89/93/27/1000_F_589932782_vQAEAZhHnq1QCGu5ikwrYaQD0Mmurm0N.jpg",alt:"Avatar",className:"h-12 w-12 rounded-full"})}),i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("span",{className:"chat-title font-medium",children:R.pushName}),i.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400"})]}),i.jsxs("div",{className:"flex items-center gap-1",children:[i.jsxs("span",{className:"text-xs font-bold text-gray-500 dark:text-gray-400",children:[o("chat.recent")," "]}),i.jsx("span",{className:"block truncate text-xs text-gray-500"})]})]})]},R.id))]})})})]})]})}),i.jsx(Bo,{withHandle:!0}),i.jsxs(Hn,{style:_,children:[f&&i.jsx(tte,{children:i.jsxs("div",{className:"flex h-full flex-col justify-between",style:_,children:[i.jsx("div",{className:"flex items-center gap-3 p-3",children:i.jsxs("div",{className:"flex flex-1 items-center gap-3",children:[i.jsx("img",{src:b?.profilePicUrl||"https://as2.ftcdn.net/jpg/05/89/93/27/1000_F_589932782_vQAEAZhHnq1QCGu5ikwrYaQD0Mmurm0N.jpg",alt:"Avatar",className:"h-10 w-10 rounded-full"}),i.jsx("div",{className:"flex flex-col",children:i.jsx("span",{className:"font-medium",children:b?.pushName||by(f)})})]})}),i.jsx(ZO,{textareaRef:g,handleTextareaChange:()=>{},textareaHeight:"auto",lastMessageRef:x,scrollToBottom:()=>{x.current&&x.current.scrollIntoView({behavior:"smooth"})}}),i.jsx(mte,{chat:b})]})}),i.jsx(bte,{isOpen:C,setIsOpen:k})]})]})})}function wte(){const{instance:e,isLoading:t,error:n}=cw();return t?i.jsx("div",{className:"flex h-screen items-center justify-center",children:i.jsx(On,{})}):n?i.jsx("div",{className:"flex h-screen items-center justify-center",children:i.jsx("div",{className:"rounded-md bg-red-50 p-4 dark:bg-red-900",children:i.jsx("span",{className:"text-red-800 dark:text-red-200",children:n})})}):e?i.jsx("div",{className:"h-screen",children:i.jsx(xte,{})}):null}function Sk(){return i.jsx(Yk,{client:_j,children:i.jsx(VM,{children:i.jsx(ete,{children:i.jsx(lX,{children:i.jsx(wte,{})})})})})}const Ste=e=>["evoai","fetchEvoai",JSON.stringify(e)],Cte=async({instanceName:e,token:t})=>(await Ee.get(`/evoai/find/${e}`,{headers:{apikey:t}})).data,kI=e=>{const{instanceName:t,token:n,...r}=e;return mt({...r,queryKey:Ste({instanceName:t,token:n}),queryFn:()=>Cte({instanceName:t,token:n}),enabled:!!t&&(e.enabled??!0)})},Ete=async({instanceName:e,token:t,data:n})=>(await Ee.post(`/evoai/create/${e}`,n,{headers:{apikey:t}})).data,kte=async({instanceName:e,evoaiId:t,data:n})=>(await Ee.put(`/evoai/update/${t}/${e}`,n)).data,jte=async({instanceName:e,evoaiId:t})=>(await Ee.delete(`/evoai/delete/${t}/${e}`)).data,Tte=async({instanceName:e,token:t,data:n})=>(await Ee.post(`/evoai/settings/${e}`,n,{headers:{apikey:t}})).data,Nte=async({instanceName:e,token:t,remoteJid:n,status:r})=>(await Ee.post(`/evoai/changeStatus/${e}`,{remoteJid:n,status:r},{headers:{apikey:t}})).data;function xg(){const e=nt(Tte,{invalidateKeys:[["evoai","fetchDefaultSettings"]]}),t=nt(Nte,{invalidateKeys:[["evoai","getEvoai"],["evoai","fetchSessions"]]}),n=nt(jte,{invalidateKeys:[["evoai","getEvoai"],["evoai","fetchEvoai"],["evoai","fetchSessions"]]}),r=nt(kte,{invalidateKeys:[["evoai","getEvoai"],["evoai","fetchEvoai"],["evoai","fetchSessions"]]}),s=nt(Ete,{invalidateKeys:[["evoai","fetchEvoai"]]});return{setDefaultSettingsEvoai:e,changeStatusEvoai:t,deleteEvoai:n,updateEvoai:r,createEvoai:s}}const Mte=e=>["evoai","fetchDefaultSettings",JSON.stringify(e)],_te=async({instanceName:e,token:t})=>(await Ee.get(`/evoai/fetchSettings/${e}`,{headers:{apikey:t}})).data,Rte=e=>{const{instanceName:t,token:n,...r}=e;return mt({...r,queryKey:Mte({instanceName:t,token:n}),queryFn:()=>_te({instanceName:t,token:n}),enabled:!!t})},Pte=P.object({expire:P.string(),keywordFinish:P.string(),delayMessage:P.string(),unknownMessage:P.string(),listeningFromMe:P.boolean(),stopBotFromMe:P.boolean(),keepOpen:P.boolean(),debounceTime:P.string(),ignoreJids:P.array(P.string()).default([]),evoaiIdFallback:P.union([P.null(),P.string()]).optional(),splitMessages:P.boolean(),timePerChar:P.string()});function Ote(){const{t:e}=Ve(),{instance:t}=ct(),{setDefaultSettingsEvoai:n}=xg(),[r,s]=y.useState(!1),{data:o,refetch:l}=kI({instanceName:t?.name,token:t?.token,enabled:r}),{data:u,refetch:d}=Rte({instanceName:t?.name,token:t?.token}),f=on({resolver:an(Pte),defaultValues:{expire:"0",keywordFinish:e("evoai.form.examples.keywordFinish"),delayMessage:"1000",unknownMessage:e("evoai.form.examples.unknownMessage"),listeningFromMe:!1,stopBotFromMe:!1,keepOpen:!1,debounceTime:"0",ignoreJids:[],evoaiIdFallback:void 0,splitMessages:!1,timePerChar:"0"}});y.useEffect(()=>{u&&f.reset({expire:u?.expire?u.expire.toString():"0",keywordFinish:u.keywordFinish,delayMessage:u.delayMessage?u.delayMessage.toString():"0",unknownMessage:u.unknownMessage,listeningFromMe:u.listeningFromMe,stopBotFromMe:u.stopBotFromMe,keepOpen:u.keepOpen,debounceTime:u.debounceTime?u.debounceTime.toString():"0",ignoreJids:u.ignoreJids,evoaiIdFallback:u.evoaiIdFallback,splitMessages:u.splitMessages,timePerChar:u.timePerChar?u.timePerChar.toString():"0"})},[u]);const h=async g=>{try{if(!t||!t.name)throw new Error("instance not found.");const x={expire:parseInt(g.expire),keywordFinish:g.keywordFinish,delayMessage:parseInt(g.delayMessage),unknownMessage:g.unknownMessage,listeningFromMe:g.listeningFromMe,stopBotFromMe:g.stopBotFromMe,keepOpen:g.keepOpen,debounceTime:parseInt(g.debounceTime),evoaiIdFallback:g.evoaiIdFallback||void 0,ignoreJids:g.ignoreJids,splitMessages:g.splitMessages,timePerChar:parseInt(g.timePerChar)};await n({instanceName:t.name,token:t.token,data:x}),me.success(e("evoai.toast.defaultSettings.success"))}catch(x){console.error("Error:",x),me.error(`Error: ${x?.response?.data?.response?.message}`)}};function m(){d(),l()}return i.jsxs(Pt,{open:r,onOpenChange:s,children:[i.jsx(Bt,{asChild:!0,children:i.jsxs(se,{variant:"secondary",size:"sm",children:[i.jsx(Oo,{size:16,className:"mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:e("evoai.defaultSettings")})]})}),i.jsxs(Nt,{className:"overflow-y-auto sm:max-h-[600px] sm:max-w-[740px]",onCloseAutoFocus:m,children:[i.jsx(Mt,{children:i.jsx(zt,{children:e("evoai.defaultSettings")})}),i.jsx(Gn,{...f,children:i.jsxs("form",{className:"w-full space-y-6",onSubmit:f.handleSubmit(h),children:[i.jsx("div",{children:i.jsxs("div",{className:"space-y-4",children:[i.jsx(Jt,{name:"evoaiIdFallback",label:e("evoai.form.evoaiIdFallback.label"),options:o?.filter(g=>!!g.id).map(g=>({label:g.description,value:g.id}))??[]}),i.jsx(le,{name:"expire",label:e("evoai.form.expire.label"),children:i.jsx(ne,{type:"number"})}),i.jsx(le,{name:"keywordFinish",label:e("evoai.form.keywordFinish.label"),children:i.jsx(ne,{})}),i.jsx(le,{name:"delayMessage",label:e("evoai.form.delayMessage.label"),children:i.jsx(ne,{type:"number"})}),i.jsx(le,{name:"unknownMessage",label:e("evoai.form.unknownMessage.label"),children:i.jsx(ne,{})}),i.jsx(Pe,{name:"listeningFromMe",label:e("evoai.form.listeningFromMe.label"),reverse:!0}),i.jsx(Pe,{name:"stopBotFromMe",label:e("evoai.form.stopBotFromMe.label"),reverse:!0}),i.jsx(Pe,{name:"keepOpen",label:e("evoai.form.keepOpen.label"),reverse:!0}),i.jsx(le,{name:"debounceTime",label:e("evoai.form.debounceTime.label"),children:i.jsx(ne,{type:"number"})}),i.jsx(Pe,{name:"splitMessages",label:e("evoai.form.splitMessages.label"),reverse:!0}),i.jsx(le,{name:"timePerChar",label:e("evoai.form.timePerChar.label"),children:i.jsx(ne,{type:"number"})}),i.jsx(Da,{name:"ignoreJids",label:e("evoai.form.ignoreJids.label"),placeholder:e("evoai.form.ignoreJids.placeholder")})]})}),i.jsx(Yt,{children:i.jsx(se,{type:"submit",children:e("evoai.button.save")})})]})})]})]})}const Ite=e=>["evoai","fetchSessions",JSON.stringify(e)],Ate=async({evoaiId:e,instanceName:t})=>(await Ee.get(`/evoai/fetchSessions/${e}/${t}`)).data,Dte=e=>{const{evoaiId:t,instanceName:n,...r}=e;return mt({...r,queryKey:Ite({evoaiId:t,instanceName:n}),queryFn:()=>Ate({evoaiId:t,instanceName:n}),enabled:!!n&&!!t&&(e.enabled??!0),staleTime:1e3*10})};function jI({evoaiId:e}){const{t}=Ve(),{instance:n}=ct(),{changeStatusEvoai:r}=xg(),[s,o]=y.useState([]),{data:l,refetch:u}=Dte({evoaiId:e,instanceName:n?.name}),[d,f]=y.useState(!1),[h,m]=y.useState("");function g(){u()}const x=async(w,C)=>{try{if(!n)return;await r({instanceName:n.name,token:n.token,remoteJid:w,status:C}),me.success(t("evoai.toast.success.status")),g()}catch(k){console.error("Error:",k),me.error(`Error : ${k?.response?.data?.response?.message}`)}},b=[{accessorKey:"remoteJid",header:()=>i.jsx("div",{className:"text-center",children:t("evoai.sessions.table.remoteJid")}),cell:({row:w})=>i.jsx("div",{children:w.getValue("remoteJid")})},{accessorKey:"pushName",header:()=>i.jsx("div",{className:"text-center",children:t("evoai.sessions.table.pushName")}),cell:({row:w})=>i.jsx("div",{children:w.getValue("pushName")})},{accessorKey:"sessionId",header:()=>i.jsx("div",{className:"text-center",children:t("evoai.sessions.table.sessionId")}),cell:({row:w})=>i.jsx("div",{children:w.getValue("sessionId")})},{accessorKey:"status",header:()=>i.jsx("div",{className:"text-center",children:t("evoai.sessions.table.status")}),cell:({row:w})=>i.jsx("div",{children:w.getValue("status")})},{id:"actions",enableHiding:!1,cell:({row:w})=>{const C=w.original;return i.jsxs(Kr,{children:[i.jsx(Wr,{asChild:!0,children:i.jsxs(se,{variant:"ghost",className:"h-8 w-8 p-0",children:[i.jsx("span",{className:"sr-only",children:t("evoai.sessions.table.actions.title")}),i.jsx(Pa,{className:"h-4 w-4"})]})}),i.jsxs(hr,{align:"end",children:[i.jsx(Ao,{children:t("evoai.sessions.table.actions.title")}),i.jsx(Xs,{}),C.status!=="opened"&&i.jsxs(wt,{onClick:()=>x(C.remoteJid,"opened"),children:[i.jsx(Fi,{className:"mr-2 h-4 w-4"}),t("evoai.sessions.table.actions.open")]}),C.status!=="paused"&&C.status!=="closed"&&i.jsxs(wt,{onClick:()=>x(C.remoteJid,"paused"),children:[i.jsx(Di,{className:"mr-2 h-4 w-4"}),t("evoai.sessions.table.actions.pause")]}),C.status!=="closed"&&i.jsxs(wt,{onClick:()=>x(C.remoteJid,"closed"),children:[i.jsx(Oi,{className:"mr-2 h-4 w-4"}),t("evoai.sessions.table.actions.close")]}),i.jsxs(wt,{onClick:()=>x(C.remoteJid,"delete"),children:[i.jsx(Ii,{className:"mr-2 h-4 w-4"}),t("evoai.sessions.table.actions.delete")]})]})]})}}];return i.jsxs(Pt,{open:d,onOpenChange:f,children:[i.jsx(Bt,{asChild:!0,children:i.jsxs(se,{variant:"secondary",size:"sm",children:[i.jsx(Ai,{size:16,className:"mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:t("evoai.sessions.label")})]})}),i.jsxs(Nt,{className:"overflow-y-auto sm:max-w-[950px]",onCloseAutoFocus:g,children:[i.jsx(Mt,{children:i.jsx(zt,{children:t("evoai.sessions.label")})}),i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between gap-6 p-5",children:[i.jsx(ne,{placeholder:t("evoai.sessions.search"),value:h,onChange:w=>m(w.target.value)}),i.jsx(se,{variant:"outline",onClick:g,size:"icon",children:i.jsx(Li,{})})]}),i.jsx($a,{columns:b,data:l??[],onSortingChange:o,state:{sorting:s,globalFilter:h},onGlobalFilterChange:m,enableGlobalFilter:!0,noResultsMessage:t("evoai.sessions.table.none")})]})]})]})}const Fte=P.object({enabled:P.boolean(),description:P.string(),agentUrl:P.string(),apiKey:P.string(),triggerType:P.string(),triggerOperator:P.string().optional(),triggerValue:P.string().optional(),expire:P.coerce.number().optional(),keywordFinish:P.string().optional(),delayMessage:P.coerce.number().optional(),unknownMessage:P.string().optional(),listeningFromMe:P.boolean().optional(),stopBotFromMe:P.boolean().optional(),keepOpen:P.boolean().optional(),debounceTime:P.coerce.number().optional(),splitMessages:P.boolean().optional(),timePerChar:P.coerce.number().optional()});function TI({initialData:e,onSubmit:t,handleDelete:n,evoaiId:r,isModal:s=!1,isLoading:o=!1,openDeletionDialog:l=!1,setOpenDeletionDialog:u=()=>{}}){const{t:d}=Ve(),f=on({resolver:an(Fte),defaultValues:e||{enabled:!0,description:"",agentUrl:"",apiKey:"",triggerType:"keyword",triggerOperator:"contains",triggerValue:"",expire:0,keywordFinish:"",delayMessage:0,unknownMessage:"",listeningFromMe:!1,stopBotFromMe:!1,keepOpen:!1,debounceTime:0,splitMessages:!1,timePerChar:0}}),h=f.watch("triggerType");return i.jsx(Gn,{...f,children:i.jsxs("form",{onSubmit:f.handleSubmit(t),className:"w-full space-y-6",children:[i.jsxs("div",{className:"space-y-4",children:[i.jsx(Pe,{name:"enabled",label:d("evoai.form.enabled.label"),reverse:!0}),i.jsx(le,{name:"description",label:d("evoai.form.description.label"),children:i.jsx(ne,{})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:d("evoai.form.evoaiSettings.label")}),i.jsx($t,{})]}),i.jsx(le,{name:"agentUrl",label:d("evoai.form.agentUrl.label"),required:!0,children:i.jsx(ne,{})}),i.jsx(le,{name:"apiKey",label:d("evoai.form.apiKey.label"),className:"flex-1",children:i.jsx(ne,{type:"password"})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:d("evoai.form.triggerSettings.label")}),i.jsx($t,{})]}),i.jsx(Jt,{name:"triggerType",label:d("evoai.form.triggerType.label"),options:[{label:d("evoai.form.triggerType.keyword"),value:"keyword"},{label:d("evoai.form.triggerType.all"),value:"all"},{label:d("evoai.form.triggerType.advanced"),value:"advanced"},{label:d("evoai.form.triggerType.none"),value:"none"}]}),h==="keyword"&&i.jsxs(i.Fragment,{children:[i.jsx(Jt,{name:"triggerOperator",label:d("evoai.form.triggerOperator.label"),options:[{label:d("evoai.form.triggerOperator.contains"),value:"contains"},{label:d("evoai.form.triggerOperator.equals"),value:"equals"},{label:d("evoai.form.triggerOperator.startsWith"),value:"startsWith"},{label:d("evoai.form.triggerOperator.endsWith"),value:"endsWith"},{label:d("evoai.form.triggerOperator.regex"),value:"regex"}]}),i.jsx(le,{name:"triggerValue",label:d("evoai.form.triggerValue.label"),children:i.jsx(ne,{})})]}),h==="advanced"&&i.jsx(le,{name:"triggerValue",label:d("evoai.form.triggerConditions.label"),children:i.jsx(ne,{})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:d("evoai.form.generalSettings.label")}),i.jsx($t,{})]}),i.jsx(le,{name:"expire",label:d("evoai.form.expire.label"),children:i.jsx(ne,{type:"number"})}),i.jsx(le,{name:"keywordFinish",label:d("evoai.form.keywordFinish.label"),children:i.jsx(ne,{})}),i.jsx(le,{name:"delayMessage",label:d("evoai.form.delayMessage.label"),children:i.jsx(ne,{type:"number"})}),i.jsx(le,{name:"unknownMessage",label:d("evoai.form.unknownMessage.label"),children:i.jsx(ne,{})}),i.jsx(Pe,{name:"listeningFromMe",label:d("evoai.form.listeningFromMe.label"),reverse:!0}),i.jsx(Pe,{name:"stopBotFromMe",label:d("evoai.form.stopBotFromMe.label"),reverse:!0}),i.jsx(Pe,{name:"keepOpen",label:d("evoai.form.keepOpen.label"),reverse:!0}),i.jsx(le,{name:"debounceTime",label:d("evoai.form.debounceTime.label"),children:i.jsx(ne,{type:"number"})}),i.jsx(Pe,{name:"splitMessages",label:d("evoai.form.splitMessages.label"),reverse:!0}),f.watch("splitMessages")&&i.jsx(le,{name:"timePerChar",label:d("evoai.form.timePerChar.label"),children:i.jsx(ne,{type:"number"})})]}),s&&i.jsx(Yt,{children:i.jsx(se,{disabled:o,type:"submit",children:d(o?"evoai.button.saving":"evoai.button.save")})}),!s&&i.jsxs("div",{children:[i.jsx(jI,{evoaiId:r}),i.jsxs("div",{className:"mt-5 flex items-center gap-3",children:[i.jsxs(Pt,{open:l,onOpenChange:u,children:[i.jsx(Bt,{asChild:!0,children:i.jsx(se,{variant:"destructive",size:"sm",children:d("evoai.button.delete")})}),i.jsx(Nt,{children:i.jsxs(Mt,{children:[i.jsx(zt,{children:d("modal.delete.title")}),i.jsx(eo,{children:d("modal.delete.messageSingle")}),i.jsxs(Yt,{children:[i.jsx(se,{size:"sm",variant:"outline",onClick:()=>u(!1),children:d("button.cancel")}),i.jsx(se,{variant:"destructive",onClick:n,children:d("button.delete")})]})]})})]}),i.jsx(se,{disabled:o,type:"submit",children:d(o?"evoai.button.saving":"evoai.button.update")})]})]})]})})}function Lte({resetTable:e}){const{t}=Ve(),{instance:n}=ct(),[r,s]=y.useState(!1),[o,l]=y.useState(!1),{createEvoai:u}=xg(),d=async f=>{try{if(!n||!n.name)throw new Error("instance not found");s(!0);const h={enabled:f.enabled,description:f.description,agentUrl:f.agentUrl,apiKey:f.apiKey,triggerType:f.triggerType,triggerOperator:f.triggerOperator||"",triggerValue:f.triggerValue||"",expire:f.expire||0,keywordFinish:f.keywordFinish||"",delayMessage:f.delayMessage||0,unknownMessage:f.unknownMessage||"",listeningFromMe:f.listeningFromMe||!1,stopBotFromMe:f.stopBotFromMe||!1,keepOpen:f.keepOpen||!1,debounceTime:f.debounceTime||0,splitMessages:f.splitMessages||!1,timePerChar:f.timePerChar||0};await u({instanceName:n.name,token:n.token,data:h}),me.success(t("evoai.toast.success.create")),l(!1),e()}catch(h){console.error("Error:",h),me.error(`Error: ${h?.response?.data?.response?.message}`)}finally{s(!1)}};return i.jsxs(Pt,{open:o,onOpenChange:l,children:[i.jsx(Bt,{asChild:!0,children:i.jsxs(se,{size:"sm",children:[i.jsx(cs,{size:16,className:"mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:t("evoai.button.create")})]})}),i.jsxs(Nt,{className:"overflow-y-auto sm:max-h-[600px] sm:max-w-[740px]",children:[i.jsx(Mt,{children:i.jsx(zt,{children:t("evoai.form.title")})}),i.jsx(TI,{onSubmit:d,isModal:!0,isLoading:r})]})]})}const $te=e=>["evoai","getEvoai",JSON.stringify(e)],Bte=async({evoaiId:e,instanceName:t})=>(await Ee.get(`/evoai/fetch/${e}/${t}`)).data,zte=e=>{const{evoaiId:t,instanceName:n,...r}=e;return mt({...r,queryKey:$te({evoaiId:t,instanceName:n}),queryFn:()=>Bte({evoaiId:t,instanceName:n}),enabled:!!n&&!!t&&(e.enabled??!0)})};function Ute({evoaiId:e,resetTable:t}){const{t:n}=Ve(),{instance:r}=ct(),s=dn(),[o,l]=y.useState(!1),{deleteEvoai:u,updateEvoai:d}=xg(),{data:f,isLoading:h}=zte({evoaiId:e,instanceName:r?.name}),m=y.useMemo(()=>({enabled:!!f?.enabled,description:f?.description??"",agentUrl:f?.agentUrl??"",apiKey:f?.apiKey??"",triggerType:f?.triggerType??"",triggerOperator:f?.triggerOperator??"",triggerValue:f?.triggerValue??"",expire:f?.expire??0,keywordFinish:f?.keywordFinish??"",delayMessage:f?.delayMessage??0,unknownMessage:f?.unknownMessage??"",listeningFromMe:!!f?.listeningFromMe,stopBotFromMe:!!f?.stopBotFromMe,keepOpen:!!f?.keepOpen,debounceTime:f?.debounceTime??0,splitMessages:f?.splitMessages??!1,timePerChar:f?.timePerChar??0}),[f?.agentUrl,f?.apiKey,f?.debounceTime,f?.delayMessage,f?.description,f?.enabled,f?.expire,f?.keepOpen,f?.keywordFinish,f?.listeningFromMe,f?.stopBotFromMe,f?.triggerOperator,f?.triggerType,f?.triggerValue,f?.unknownMessage,f?.splitMessages,f?.timePerChar]),g=async b=>{try{if(r&&r.name&&e){const w={enabled:b.enabled,description:b.description,agentUrl:b.agentUrl,apiKey:b.apiKey,triggerType:b.triggerType,triggerOperator:b.triggerOperator||"",triggerValue:b.triggerValue||"",expire:b.expire||0,keywordFinish:b.keywordFinish||"",delayMessage:b.delayMessage||1e3,unknownMessage:b.unknownMessage||"",listeningFromMe:b.listeningFromMe||!1,stopBotFromMe:b.stopBotFromMe||!1,keepOpen:b.keepOpen||!1,debounceTime:b.debounceTime||0,splitMessages:b.splitMessages||!1,timePerChar:b.timePerChar||0};await d({instanceName:r.name,evoaiId:e,data:w}),me.success(n("evoai.toast.success.update")),t(),s(`/manager/instance/${r.id}/evoai/${e}`)}else console.error("Token not found")}catch(w){console.error("Error:",w),me.error(`Error: ${w?.response?.data?.response?.message}`)}},x=async()=>{try{r&&r.name&&e?(await u({instanceName:r.name,evoaiId:e}),me.success(n("evoai.toast.success.delete")),l(!1),t(),s(`/manager/instance/${r.id}/evoai`)):console.error("instance not found")}catch(b){console.error("Erro ao excluir evoai:",b)}};return h?i.jsx(On,{}):i.jsx("div",{className:"m-4",children:i.jsx(TI,{initialData:m,onSubmit:g,evoaiId:e,handleDelete:x,isModal:!1,isLoading:h,openDeletionDialog:o,setOpenDeletionDialog:l})})}function Ck(){const{t:e}=Ve(),t=zo("(min-width: 768px)"),{instance:n}=ct(),{evoaiId:r}=ls(),{data:s,refetch:o,isLoading:l}=kI({instanceName:n?.name}),u=dn(),d=h=>{n&&u(`/manager/instance/${n.id}/evoai/${h}`)},f=()=>{o()};return i.jsxs("main",{className:"pt-5",children:[i.jsxs("div",{className:"mb-1 flex items-center justify-between",children:[i.jsx("h3",{className:"text-lg font-medium",children:e("evoai.title")}),i.jsxs("div",{className:"flex items-center justify-end gap-2",children:[i.jsx(jI,{}),i.jsx(Ote,{}),i.jsx(Lte,{resetTable:f})]})]}),i.jsx($t,{className:"my-4"}),i.jsxs($o,{direction:t?"horizontal":"vertical",children:[i.jsx(Hn,{defaultSize:35,className:"pr-4",children:i.jsx("div",{className:"flex flex-col gap-3",children:l?i.jsx(On,{}):i.jsx(i.Fragment,{children:s&&s.length>0&&Array.isArray(s)?s.map(h=>i.jsx(se,{className:"flex h-auto flex-col items-start justify-start",onClick:()=>d(`${h.id}`),variant:r===h.id?"secondary":"outline",children:i.jsx("h4",{className:"text-base",children:h.description||h.id})},h.id)):i.jsx(se,{variant:"link",children:e("evoai.table.none")})})})}),r&&i.jsxs(i.Fragment,{children:[i.jsx(Bo,{withHandle:!0,className:"border border-border"}),i.jsx(Hn,{children:i.jsx(Ute,{evoaiId:r,resetTable:f})})]})]})]})}const Vte=e=>["evolutionBot","findEvolutionBot",JSON.stringify(e)],Hte=async({instanceName:e,token:t})=>(await Ee.get(`/evolutionBot/find/${e}`,{headers:{apiKey:t}})).data,NI=e=>{const{instanceName:t,token:n,...r}=e;return mt({...r,queryKey:Vte({instanceName:t}),queryFn:()=>Hte({instanceName:t,token:n}),enabled:!!t&&(e.enabled??!0)})},qte=e=>["evolutionBot","fetchDefaultSettings",JSON.stringify(e)],Kte=async({instanceName:e,token:t})=>{const n=await Ee.get(`/evolutionBot/fetchSettings/${e}`,{headers:{apiKey:t}});return Array.isArray(n.data)?n.data[0]:n.data},Wte=e=>{const{instanceName:t,token:n,...r}=e;return mt({...r,queryKey:qte({instanceName:t}),queryFn:()=>Kte({instanceName:t,token:n}),enabled:!!t&&(e.enabled??!0)})},Gte=async({instanceName:e,token:t,data:n})=>(await Ee.post(`/evolutionBot/create/${e}`,n,{headers:{apikey:t}})).data,Jte=async({instanceName:e,token:t,evolutionBotId:n,data:r})=>(await Ee.put(`/evolutionBot/update/${n}/${e}`,r,{headers:{apikey:t}})).data,Qte=async({instanceName:e,evolutionBotId:t})=>(await Ee.delete(`/evolutionBot/delete/${t}/${e}`)).data,Zte=async({instanceName:e,token:t,data:n})=>(await Ee.post(`/evolutionBot/settings/${e}`,n,{headers:{apikey:t}})).data,Yte=async({instanceName:e,token:t,remoteJid:n,status:r})=>(await Ee.post(`/evolutionBot/changeStatus/${e}`,{remoteJid:n,status:r},{headers:{apikey:t}})).data;function wg(){const e=nt(Zte,{invalidateKeys:[["evolutionBot","fetchDefaultSettings"]]}),t=nt(Yte,{invalidateKeys:[["evolutionBot","getEvolutionBot"],["evolutionBot","fetchSessions"]]}),n=nt(Qte,{invalidateKeys:[["evolutionBot","getEvolutionBot"],["evolutionBot","findEvolutionBot"],["evolutionBot","fetchSessions"]]}),r=nt(Jte,{invalidateKeys:[["evolutionBot","getEvolutionBot"],["evolutionBot","findEvolutionBot"],["evolutionBot","fetchSessions"]]}),s=nt(Gte,{invalidateKeys:[["evolutionBot","findEvolutionBot"]]});return{setDefaultSettingsEvolutionBot:e,changeStatusEvolutionBot:t,deleteEvolutionBot:n,updateEvolutionBot:r,createEvolutionBot:s}}const Xte=P.object({expire:P.string(),keywordFinish:P.string(),delayMessage:P.string(),unknownMessage:P.string(),listeningFromMe:P.boolean(),stopBotFromMe:P.boolean(),keepOpen:P.boolean(),debounceTime:P.string(),ignoreJids:P.array(P.string()).default([]),botIdFallback:P.union([P.null(),P.string()]).optional(),splitMessages:P.boolean(),timePerChar:P.string()});function ene(){const{t:e}=Ve(),{instance:t}=ct(),[n,r]=y.useState(!1),{data:s,refetch:o}=Wte({instanceName:t?.name,enabled:n}),{data:l,refetch:u}=NI({instanceName:t?.name,enabled:n}),{setDefaultSettingsEvolutionBot:d}=wg(),f=on({resolver:an(Xte),defaultValues:{expire:"0",keywordFinish:e("evolutionBot.form.examples.keywordFinish"),delayMessage:"1000",unknownMessage:e("evolutionBot.form.examples.unknownMessage"),listeningFromMe:!1,stopBotFromMe:!1,keepOpen:!1,debounceTime:"0",ignoreJids:[],botIdFallback:void 0,splitMessages:!1,timePerChar:"0"}});y.useEffect(()=>{s&&f.reset({expire:s?.expire?s.expire.toString():"0",keywordFinish:s.keywordFinish,delayMessage:s.delayMessage?s.delayMessage.toString():"0",unknownMessage:s.unknownMessage,listeningFromMe:s.listeningFromMe,stopBotFromMe:s.stopBotFromMe,keepOpen:s.keepOpen,debounceTime:s.debounceTime?s.debounceTime.toString():"0",ignoreJids:s.ignoreJids,botIdFallback:s.botIdFallback,splitMessages:s.splitMessages,timePerChar:s.timePerChar?s.timePerChar.toString():"0"})},[s]);const h=async g=>{try{if(!t||!t.name)throw new Error("instance not found.");const x={expire:parseInt(g.expire),keywordFinish:g.keywordFinish,delayMessage:parseInt(g.delayMessage),unknownMessage:g.unknownMessage,listeningFromMe:g.listeningFromMe,stopBotFromMe:g.stopBotFromMe,keepOpen:g.keepOpen,debounceTime:parseInt(g.debounceTime),botIdFallback:g.botIdFallback||void 0,ignoreJids:g.ignoreJids,splitMessages:g.splitMessages,timePerChar:parseInt(g.timePerChar)};await d({instanceName:t.name,token:t.token,data:x}),me.success(e("evolutionBot.toast.defaultSettings.success"))}catch(x){console.error("Error:",x),me.error(`Error: ${x?.response?.data?.response?.message}`)}};function m(){o(),u()}return i.jsxs(Pt,{open:n,onOpenChange:r,children:[i.jsx(Bt,{asChild:!0,children:i.jsxs(se,{variant:"secondary",size:"sm",children:[i.jsx(Oo,{size:16,className:"mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:e("evolutionBot.defaultSettings")})]})}),i.jsxs(Nt,{className:"overflow-y-auto sm:max-h-[600px] sm:max-w-[740px]",onCloseAutoFocus:m,children:[i.jsx(Mt,{children:i.jsx(zt,{children:e("evolutionBot.defaultSettings")})}),i.jsx(Gn,{...f,children:i.jsxs("form",{className:"w-full space-y-6",onSubmit:f.handleSubmit(h),children:[i.jsx("div",{children:i.jsxs("div",{className:"space-y-4",children:[i.jsx(Jt,{name:"botIdFallback",label:e("evolutionBot.form.botIdFallback.label"),options:l?.filter(g=>!!g.id).map(g=>({label:g.description,value:g.id}))??[]}),i.jsx(le,{name:"expire",label:e("evolutionBot.form.expire.label"),children:i.jsx(ne,{type:"number"})}),i.jsx(le,{name:"keywordFinish",label:e("evolutionBot.form.keywordFinish.label"),children:i.jsx(ne,{})}),i.jsx(le,{name:"delayMessage",label:e("evolutionBot.form.delayMessage.label"),children:i.jsx(ne,{type:"number"})}),i.jsx(le,{name:"unknownMessage",label:e("evolutionBot.form.unknownMessage.label"),children:i.jsx(ne,{})}),i.jsx(Pe,{name:"listeningFromMe",label:e("evolutionBot.form.listeningFromMe.label"),reverse:!0}),i.jsx(Pe,{name:"stopBotFromMe",label:e("evolutionBot.form.stopBotFromMe.label"),reverse:!0}),i.jsx(Pe,{name:"keepOpen",label:e("evolutionBot.form.keepOpen.label"),reverse:!0}),i.jsx(le,{name:"debounceTime",label:e("evolutionBot.form.debounceTime.label"),children:i.jsx(ne,{type:"number"})}),i.jsx(Pe,{name:"splitMessages",label:e("evolutionBot.form.splitMessages.label"),reverse:!0}),f.watch("splitMessages")&&i.jsx(le,{name:"timePerChar",label:e("evolutionBot.form.timePerChar.label"),children:i.jsx(ne,{type:"number"})}),i.jsx(Da,{name:"ignoreJids",label:e("evolutionBot.form.ignoreJids.label"),placeholder:e("evolutionBot.form.ignoreJids.placeholder")})]})}),i.jsx(Yt,{children:i.jsx(se,{type:"submit",children:e("evolutionBot.button.save")})})]})})]})]})}const tne=e=>["evolutionBot","fetchSessions",JSON.stringify(e)],nne=async({instanceName:e,evolutionBotId:t,token:n})=>(await Ee.get(`/evolutionBot/fetchSessions/${t}/${e}`,{headers:{apiKey:n}})).data,rne=e=>{const{instanceName:t,token:n,evolutionBotId:r,...s}=e;return mt({...s,queryKey:tne({instanceName:t}),queryFn:()=>nne({instanceName:t,token:n,evolutionBotId:r}),enabled:!!t&&!!r&&(e.enabled??!0)})};function MI({evolutionBotId:e}){const{t}=Ve(),{instance:n}=ct(),[r,s]=y.useState([]),[o,l]=y.useState(!1),[u,d]=y.useState(""),{data:f,refetch:h}=rne({instanceName:n?.name,evolutionBotId:e,enabled:o}),{changeStatusEvolutionBot:m}=wg();function g(){h()}const x=async(w,C)=>{try{if(!n)return;await m({instanceName:n.name,token:n.token,remoteJid:w,status:C}),me.success(t("evolutionBot.toast.success.status")),g()}catch(k){console.error("Error:",k),me.error(`Error : ${k?.response?.data?.response?.message}`)}},b=[{accessorKey:"remoteJid",header:()=>i.jsx("div",{className:"text-center",children:t("evolutionBot.sessions.table.remoteJid")}),cell:({row:w})=>i.jsx("div",{children:w.getValue("remoteJid")})},{accessorKey:"pushName",header:()=>i.jsx("div",{className:"text-center",children:t("evolutionBot.sessions.table.pushName")}),cell:({row:w})=>i.jsx("div",{children:w.getValue("pushName")})},{accessorKey:"sessionId",header:()=>i.jsx("div",{className:"text-center",children:t("evolutionBot.sessions.table.sessionId")}),cell:({row:w})=>i.jsx("div",{children:w.getValue("sessionId")})},{accessorKey:"status",header:()=>i.jsx("div",{className:"text-center",children:t("evolutionBot.sessions.table.status")}),cell:({row:w})=>i.jsx("div",{children:w.getValue("status")})},{id:"actions",enableHiding:!1,cell:({row:w})=>{const C=w.original;return i.jsxs(Kr,{children:[i.jsx(Wr,{asChild:!0,children:i.jsxs(se,{variant:"ghost",className:"h-8 w-8 p-0",children:[i.jsx("span",{className:"sr-only",children:t("evolutionBot.sessions.table.actions.title")}),i.jsx(Pa,{className:"h-4 w-4"})]})}),i.jsxs(hr,{align:"end",children:[i.jsx(Ao,{children:t("evolutionBot.sessions.table.actions.title")}),i.jsx(Xs,{}),C.status!=="opened"&&i.jsxs(wt,{onClick:()=>x(C.remoteJid,"opened"),children:[i.jsx(Fi,{className:"mr-2 h-4 w-4"}),t("evolutionBot.sessions.table.actions.open")]}),C.status!=="paused"&&C.status!=="closed"&&i.jsxs(wt,{onClick:()=>x(C.remoteJid,"paused"),children:[i.jsx(Di,{className:"mr-2 h-4 w-4"}),t("evolutionBot.sessions.table.actions.pause")]}),C.status!=="closed"&&i.jsxs(wt,{onClick:()=>x(C.remoteJid,"closed"),children:[i.jsx(Oi,{className:"mr-2 h-4 w-4"}),t("evolutionBot.sessions.table.actions.close")]}),i.jsxs(wt,{onClick:()=>x(C.remoteJid,"delete"),children:[i.jsx(Ii,{className:"mr-2 h-4 w-4"}),t("evolutionBot.sessions.table.actions.delete")]})]})]})}}];return i.jsxs(Pt,{open:o,onOpenChange:l,children:[i.jsx(Bt,{asChild:!0,children:i.jsxs(se,{variant:"secondary",size:"sm",children:[i.jsx(Ai,{size:16,className:"mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:t("evolutionBot.sessions.label")})]})}),i.jsxs(Nt,{className:"overflow-y-auto sm:max-w-[950px]",onCloseAutoFocus:g,children:[i.jsx(Mt,{children:i.jsx(zt,{children:t("evolutionBot.sessions.label")})}),i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between gap-6 p-5",children:[i.jsx(ne,{placeholder:t("evolutionBot.sessions.search"),value:u,onChange:w=>d(w.target.value)}),i.jsx(se,{variant:"outline",onClick:g,size:"icon",children:i.jsx(Li,{})})]}),i.jsx($a,{columns:b,data:f??[],onSortingChange:s,state:{sorting:r,globalFilter:u},onGlobalFilterChange:d,enableGlobalFilter:!0,noResultsMessage:t("evolutionBot.sessions.table.none")})]})]})]})}const sne=P.object({enabled:P.boolean(),description:P.string(),apiUrl:P.string(),apiKey:P.string().optional(),triggerType:P.string(),triggerOperator:P.string().optional(),triggerValue:P.string().optional(),expire:P.coerce.number().optional(),keywordFinish:P.string().optional(),delayMessage:P.coerce.number().optional(),unknownMessage:P.string().optional(),listeningFromMe:P.boolean().optional(),stopBotFromMe:P.boolean().optional(),keepOpen:P.boolean().optional(),debounceTime:P.coerce.number().optional(),splitMessages:P.boolean().optional(),timePerChar:P.coerce.number().optional()});function _I({initialData:e,onSubmit:t,handleDelete:n,evolutionBotId:r,isModal:s=!1,isLoading:o=!1,openDeletionDialog:l=!1,setOpenDeletionDialog:u=()=>{}}){const{t:d}=Ve(),f=on({resolver:an(sne),defaultValues:e||{enabled:!0,description:"",apiUrl:"",apiKey:"",triggerType:"keyword",triggerOperator:"contains",triggerValue:"",expire:0,keywordFinish:"",delayMessage:0,unknownMessage:"",listeningFromMe:!1,stopBotFromMe:!1,keepOpen:!1,debounceTime:0,splitMessages:!1,timePerChar:0}}),h=f.watch("triggerType");return i.jsx(Gn,{...f,children:i.jsxs("form",{onSubmit:f.handleSubmit(t),className:"w-full space-y-6",children:[i.jsxs("div",{className:"space-y-4",children:[i.jsx(Pe,{name:"enabled",label:d("evolutionBot.form.enabled.label"),reverse:!0}),i.jsx(le,{name:"description",label:d("evolutionBot.form.description.label"),required:!0,children:i.jsx(ne,{})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:d("evolutionBot.form.evolutionBotSettings.label")}),i.jsx($t,{})]}),i.jsx(le,{name:"apiUrl",label:d("evolutionBot.form.apiUrl.label"),required:!0,children:i.jsx(ne,{})}),i.jsx(le,{name:"apiKey",label:d("evolutionBot.form.apiKey.label"),children:i.jsx(ne,{type:"password"})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:d("evolutionBot.form.triggerSettings.label")}),i.jsx($t,{})]}),i.jsx(Jt,{name:"triggerType",label:d("evolutionBot.form.triggerType.label"),options:[{label:d("evolutionBot.form.triggerType.keyword"),value:"keyword"},{label:d("evolutionBot.form.triggerType.all"),value:"all"},{label:d("evolutionBot.form.triggerType.advanced"),value:"advanced"},{label:d("evolutionBot.form.triggerType.none"),value:"none"}]}),h==="keyword"&&i.jsxs(i.Fragment,{children:[i.jsx(Jt,{name:"triggerOperator",label:d("evolutionBot.form.triggerOperator.label"),options:[{label:d("evolutionBot.form.triggerOperator.contains"),value:"contains"},{label:d("evolutionBot.form.triggerOperator.equals"),value:"equals"},{label:d("evolutionBot.form.triggerOperator.startsWith"),value:"startsWith"},{label:d("evolutionBot.form.triggerOperator.endsWith"),value:"endsWith"},{label:d("evolutionBot.form.triggerOperator.regex"),value:"regex"}]}),i.jsx(le,{name:"triggerValue",label:d("evolutionBot.form.triggerValue.label"),children:i.jsx(ne,{})})]}),h==="advanced"&&i.jsx(le,{name:"triggerValue",label:d("evolutionBot.form.triggerConditions.label"),children:i.jsx(ne,{})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:d("evolutionBot.form.generalSettings.label")}),i.jsx($t,{})]}),i.jsx(le,{name:"expire",label:d("evolutionBot.form.expire.label"),children:i.jsx(ne,{type:"number"})}),i.jsx(le,{name:"keywordFinish",label:d("evolutionBot.form.keywordFinish.label"),children:i.jsx(ne,{})}),i.jsx(le,{name:"delayMessage",label:d("evolutionBot.form.delayMessage.label"),children:i.jsx(ne,{type:"number"})}),i.jsx(le,{name:"unknownMessage",label:d("evolutionBot.form.unknownMessage.label"),children:i.jsx(ne,{})}),i.jsx(Pe,{name:"listeningFromMe",label:d("evolutionBot.form.listeningFromMe.label"),reverse:!0}),i.jsx(Pe,{name:"stopBotFromMe",label:d("evolutionBot.form.stopBotFromMe.label"),reverse:!0}),i.jsx(Pe,{name:"keepOpen",label:d("evolutionBot.form.keepOpen.label"),reverse:!0}),i.jsx(le,{name:"debounceTime",label:d("evolutionBot.form.debounceTime.label"),children:i.jsx(ne,{type:"number"})}),i.jsx(Pe,{name:"splitMessages",label:d("evolutionBot.form.splitMessages.label"),reverse:!0}),f.watch("splitMessages")&&i.jsx(le,{name:"timePerChar",label:d("evolutionBot.form.timePerChar.label"),children:i.jsx(ne,{type:"number"})})]}),s&&i.jsx(Yt,{children:i.jsx(se,{disabled:o,type:"submit",children:d(o?"evolutionBot.button.saving":"evolutionBot.button.save")})}),!s&&i.jsxs("div",{children:[i.jsx(MI,{evolutionBotId:r}),i.jsxs("div",{className:"mt-5 flex items-center gap-3",children:[i.jsxs(Pt,{open:l,onOpenChange:u,children:[i.jsx(Bt,{asChild:!0,children:i.jsx(se,{variant:"destructive",size:"sm",children:d("dify.button.delete")})}),i.jsx(Nt,{children:i.jsxs(Mt,{children:[i.jsx(zt,{children:d("modal.delete.title")}),i.jsx(eo,{children:d("modal.delete.messageSingle")}),i.jsxs(Yt,{children:[i.jsx(se,{size:"sm",variant:"outline",onClick:()=>u(!1),children:d("button.cancel")}),i.jsx(se,{variant:"destructive",onClick:n,children:d("button.delete")})]})]})})]}),i.jsx(se,{disabled:o,type:"submit",children:d(o?"evolutionBot.button.saving":"evolutionBot.button.update")})]})]})]})})}function one({resetTable:e}){const{t}=Ve(),{instance:n}=ct(),[r,s]=y.useState(!1),[o,l]=y.useState(!1),{createEvolutionBot:u}=wg(),d=async f=>{try{if(!n||!n.name)throw new Error("instance not found");s(!0);const h={enabled:f.enabled,description:f.description,apiUrl:f.apiUrl,apiKey:f.apiKey,triggerType:f.triggerType,triggerOperator:f.triggerOperator||"",triggerValue:f.triggerValue||"",expire:f.expire||0,keywordFinish:f.keywordFinish||"",delayMessage:f.delayMessage||0,unknownMessage:f.unknownMessage||"",listeningFromMe:f.listeningFromMe||!1,stopBotFromMe:f.stopBotFromMe||!1,keepOpen:f.keepOpen||!1,debounceTime:f.debounceTime||0,splitMessages:f.splitMessages||!1,timePerChar:f.timePerChar?f.timePerChar:0};await u({instanceName:n.name,token:n.token,data:h}),me.success(t("evolutionBot.toast.success.create")),l(!1),e()}catch(h){console.error("Error:",h),me.error(`Error: ${h?.response?.data?.response?.message}`)}finally{s(!1)}};return i.jsxs(Pt,{open:o,onOpenChange:l,children:[i.jsx(Bt,{asChild:!0,children:i.jsxs(se,{size:"sm",children:[i.jsx(cs,{size:16,className:"mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:t("evolutionBot.button.create")})]})}),i.jsxs(Nt,{className:"overflow-y-auto sm:max-h-[600px] sm:max-w-[740px]",children:[i.jsx(Mt,{children:i.jsx(zt,{children:t("evolutionBot.form.title")})}),i.jsx(_I,{onSubmit:d,isModal:!0,isLoading:r})]})]})}const ane=e=>["evolutionBot","getEvolutionBot",JSON.stringify(e)],ine=async({instanceName:e,token:t,evolutionBotId:n})=>{const r=await Ee.get(`/evolutionBot/fetch/${n}/${e}`,{headers:{apiKey:t}});return Array.isArray(r.data)?r.data[0]:r.data},lne=e=>{const{instanceName:t,token:n,evolutionBotId:r,...s}=e;return mt({...s,queryKey:ane({instanceName:t}),queryFn:()=>ine({instanceName:t,token:n,evolutionBotId:r}),enabled:!!t&&!!r&&(e.enabled??!0)})};function cne({evolutionBotId:e,resetTable:t}){const{t:n}=Ve(),{instance:r}=ct(),s=dn(),[o,l]=y.useState(!1),{deleteEvolutionBot:u,updateEvolutionBot:d}=wg(),{data:f,isLoading:h}=lne({instanceName:r?.name,evolutionBotId:e}),m=y.useMemo(()=>({enabled:f?.enabled??!0,description:f?.description??"",apiUrl:f?.apiUrl??"",apiKey:f?.apiKey??"",triggerType:f?.triggerType??"",triggerOperator:f?.triggerOperator??"",triggerValue:f?.triggerValue,expire:f?.expire??0,keywordFinish:f?.keywordFinish,delayMessage:f?.delayMessage??0,unknownMessage:f?.unknownMessage,listeningFromMe:f?.listeningFromMe,stopBotFromMe:!!f?.stopBotFromMe,keepOpen:!!f?.keepOpen,debounceTime:f?.debounceTime??0,splitMessages:f?.splitMessages??!1,timePerChar:f?.timePerChar?f?.timePerChar:0}),[f?.apiKey,f?.apiUrl,f?.debounceTime,f?.delayMessage,f?.description,f?.enabled,f?.expire,f?.keepOpen,f?.keywordFinish,f?.listeningFromMe,f?.stopBotFromMe,f?.triggerOperator,f?.triggerType,f?.triggerValue,f?.unknownMessage,f?.splitMessages,f?.timePerChar]),g=async b=>{try{if(r&&r.name&&e){const w={enabled:b.enabled,description:b.description,apiUrl:b.apiUrl,apiKey:b.apiKey,triggerType:b.triggerType,triggerOperator:b.triggerOperator||"",triggerValue:b.triggerValue||"",expire:b.expire||0,keywordFinish:b.keywordFinish||"",delayMessage:b.delayMessage||1e3,unknownMessage:b.unknownMessage||"",listeningFromMe:b.listeningFromMe||!1,stopBotFromMe:b.stopBotFromMe||!1,keepOpen:b.keepOpen||!1,debounceTime:b.debounceTime||0,splitMessages:b.splitMessages||!1,timePerChar:b.timePerChar?b.timePerChar:0};await d({instanceName:r.name,evolutionBotId:e,data:w}),me.success(n("evolutionBot.toast.success.update")),t(),s(`/manager/instance/${r.id}/evolutionBot/${e}`)}else console.error("Token not found")}catch(w){console.error("Error:",w),me.error(`Error: ${w?.response?.data?.response?.message}`)}},x=async()=>{try{r&&r.name&&e?(await u({instanceName:r.name,evolutionBotId:e}),me.success(n("evolutionBot.toast.success.delete")),l(!1),t(),s(`/manager/instance/${r.id}/evolutionBot`)):console.error("instance not found")}catch(b){console.error("Erro ao excluir evolutionBot:",b)}};return h?i.jsx(On,{}):i.jsx("div",{className:"m-4",children:i.jsx(_I,{initialData:m,onSubmit:g,evolutionBotId:e,handleDelete:x,isModal:!1,openDeletionDialog:o,setOpenDeletionDialog:l})})}function Ek(){const{t:e}=Ve(),t=zo("(min-width: 768px)"),{instance:n}=ct(),{evolutionBotId:r}=ls(),{data:s,isLoading:o,refetch:l}=NI({instanceName:n?.name}),u=dn(),d=h=>{n&&u(`/manager/instance/${n.id}/evolutionBot/${h}`)},f=()=>{l()};return i.jsxs("main",{className:"pt-5",children:[i.jsxs("div",{className:"mb-1 flex items-center justify-between",children:[i.jsx("h3",{className:"text-lg font-medium",children:e("evolutionBot.title")}),i.jsxs("div",{className:"flex items-center justify-end gap-2",children:[i.jsx(MI,{}),i.jsx(ene,{}),i.jsx(one,{resetTable:f})]})]}),i.jsx($t,{className:"my-4"}),i.jsxs($o,{direction:t?"horizontal":"vertical",children:[i.jsx(Hn,{defaultSize:35,className:"pr-4",children:i.jsx("div",{className:"flex flex-col gap-3",children:o?i.jsx(On,{}):i.jsx(i.Fragment,{children:s&&s.length>0&&Array.isArray(s)?s.map(h=>i.jsx(se,{className:"flex h-auto flex-col items-start justify-start",onClick:()=>d(`${h.id}`),variant:r===h.id?"secondary":"outline",children:i.jsx("h4",{className:"text-base",children:h.description||h.id})},h.id)):i.jsx(se,{variant:"link",children:e("evolutionBot.table.none")})})})}),r&&i.jsxs(i.Fragment,{children:[i.jsx(Bo,{withHandle:!0,className:"border border-border"}),i.jsx(Hn,{children:i.jsx(cne,{evolutionBotId:r,resetTable:f})})]})]})]})}const une=e=>["flowise","findFlowise",JSON.stringify(e)],dne=async({instanceName:e,token:t})=>(await Ee.get(`/flowise/find/${e}`,{headers:{apiKey:t}})).data,RI=e=>{const{instanceName:t,token:n,...r}=e;return mt({...r,queryKey:une({instanceName:t}),queryFn:()=>dne({instanceName:t,token:n}),enabled:!!t&&(e.enabled??!0)})},fne=e=>["flowise","fetchDefaultSettings",JSON.stringify(e)],pne=async({instanceName:e,token:t})=>{const n=await Ee.get(`/flowise/fetchSettings/${e}`,{headers:{apiKey:t}});return Array.isArray(n.data)?n.data[0]:n.data},hne=e=>{const{instanceName:t,token:n,...r}=e;return mt({...r,queryKey:fne({instanceName:t}),queryFn:()=>pne({instanceName:t,token:n}),enabled:!!t&&(e.enabled??!0)})},gne=async({instanceName:e,token:t,data:n})=>(await Ee.post(`/flowise/create/${e}`,n,{headers:{apikey:t}})).data,mne=async({instanceName:e,flowiseId:t,data:n})=>(await Ee.put(`/flowise/update/${t}/${e}`,n)).data,vne=async({instanceName:e,flowiseId:t})=>(await Ee.delete(`/flowise/delete/${t}/${e}`)).data,yne=async({instanceName:e,token:t,remoteJid:n,status:r})=>(await Ee.post(`/flowise/changeStatus/${e}`,{remoteJid:n,status:r},{headers:{apikey:t}})).data,bne=async({instanceName:e,token:t,data:n})=>(await Ee.post(`/flowise/settings/${e}`,n,{headers:{apikey:t}})).data;function Sg(){const e=nt(bne,{invalidateKeys:[["flowise","fetchDefaultSettings"]]}),t=nt(yne,{invalidateKeys:[["flowise","getFlowise"],["flowise","fetchSessions"]]}),n=nt(vne,{invalidateKeys:[["flowise","getFlowise"],["flowise","findFlowise"],["flowise","fetchSessions"]]}),r=nt(mne,{invalidateKeys:[["flowise","getFlowise"],["flowise","findFlowise"],["flowise","fetchSessions"]]}),s=nt(gne,{invalidateKeys:[["flowise","findFlowise"]]});return{setDefaultSettingsFlowise:e,changeStatusFlowise:t,deleteFlowise:n,updateFlowise:r,createFlowise:s}}const xne=P.object({expire:P.string(),keywordFinish:P.string(),delayMessage:P.string(),unknownMessage:P.string(),listeningFromMe:P.boolean(),stopBotFromMe:P.boolean(),keepOpen:P.boolean(),debounceTime:P.string(),ignoreJids:P.array(P.string()).default([]),flowiseIdFallback:P.union([P.null(),P.string()]).optional(),splitMessages:P.boolean(),timePerChar:P.string()});function wne(){const{t:e}=Ve(),{instance:t}=ct(),{setDefaultSettingsFlowise:n}=Sg(),[r,s]=y.useState(!1),{data:o,refetch:l}=hne({instanceName:t?.name,enabled:r}),{data:u,refetch:d}=RI({instanceName:t?.name,enabled:r}),f=on({resolver:an(xne),defaultValues:{expire:"0",keywordFinish:e("flowise.form.examples.keywordFinish"),delayMessage:"1000",unknownMessage:e("flowise.form.examples.unknownMessage"),listeningFromMe:!1,stopBotFromMe:!1,keepOpen:!1,debounceTime:"0",ignoreJids:[],flowiseIdFallback:void 0,splitMessages:!1,timePerChar:"0"}});y.useEffect(()=>{o&&f.reset({expire:o?.expire?o.expire.toString():"0",keywordFinish:o.keywordFinish,delayMessage:o.delayMessage?o.delayMessage.toString():"0",unknownMessage:o.unknownMessage,listeningFromMe:o.listeningFromMe,stopBotFromMe:o.stopBotFromMe,keepOpen:o.keepOpen,debounceTime:o.debounceTime?o.debounceTime.toString():"0",ignoreJids:o.ignoreJids,flowiseIdFallback:o.flowiseIdFallback,splitMessages:o.splitMessages,timePerChar:o.timePerChar?o.timePerChar.toString():"0"})},[o]);const h=async g=>{try{if(!t||!t.name)throw new Error("instance not found.");const x={expire:parseInt(g.expire),keywordFinish:g.keywordFinish,delayMessage:parseInt(g.delayMessage),unknownMessage:g.unknownMessage,listeningFromMe:g.listeningFromMe,stopBotFromMe:g.stopBotFromMe,keepOpen:g.keepOpen,debounceTime:parseInt(g.debounceTime),flowiseIdFallback:g.flowiseIdFallback||void 0,ignoreJids:g.ignoreJids,splitMessages:g.splitMessages,timePerChar:parseInt(g.timePerChar)};await n({instanceName:t.name,token:t.token,data:x}),me.success(e("flowise.toast.defaultSettings.success"))}catch(x){console.error("Error:",x),me.error(`Error: ${x?.response?.data?.response?.message}`)}};function m(){l(),d()}return i.jsxs(Pt,{open:r,onOpenChange:s,children:[i.jsx(Bt,{asChild:!0,children:i.jsxs(se,{variant:"secondary",size:"sm",children:[i.jsx(Oo,{size:16,className:"mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:e("flowise.defaultSettings")})]})}),i.jsxs(Nt,{className:"overflow-y-auto sm:max-h-[600px] sm:max-w-[740px]",onCloseAutoFocus:m,children:[i.jsx(Mt,{children:i.jsx(zt,{children:e("flowise.defaultSettings")})}),i.jsx(Gn,{...f,children:i.jsxs("form",{className:"w-full space-y-6",onSubmit:f.handleSubmit(h),children:[i.jsx("div",{children:i.jsxs("div",{className:"space-y-4",children:[i.jsx(Jt,{name:"flowiseIdFallback",label:e("flowise.form.flowiseIdFallback.label"),options:u?.filter(g=>!!g.id).map(g=>({label:g.description,value:g.id}))??[]}),i.jsx(le,{name:"expire",label:e("flowise.form.expire.label"),children:i.jsx(ne,{type:"number"})}),i.jsx(le,{name:"keywordFinish",label:e("flowise.form.keywordFinish.label"),children:i.jsx(ne,{})}),i.jsx(le,{name:"delayMessage",label:e("flowise.form.delayMessage.label"),children:i.jsx(ne,{type:"number"})}),i.jsx(le,{name:"unknownMessage",label:e("flowise.form.unknownMessage.label"),children:i.jsx(ne,{})}),i.jsx(Pe,{name:"listeningFromMe",label:e("flowise.form.listeningFromMe.label"),reverse:!0}),i.jsx(Pe,{name:"stopBotFromMe",label:e("flowise.form.stopBotFromMe.label"),reverse:!0}),i.jsx(Pe,{name:"keepOpen",label:e("flowise.form.keepOpen.label"),reverse:!0}),i.jsx(le,{name:"debounceTime",label:e("flowise.form.debounceTime.label"),children:i.jsx(ne,{type:"number"})}),i.jsx(Pe,{name:"splitMessages",label:e("flowise.form.splitMessages.label"),reverse:!0}),f.watch("splitMessages")&&i.jsx(le,{name:"timePerChar",label:e("flowise.form.timePerChar.label"),children:i.jsx(ne,{type:"number"})}),i.jsx(Da,{name:"ignoreJids",label:e("flowise.form.ignoreJids.label"),placeholder:e("flowise.form.ignoreJids.placeholder")})]})}),i.jsx(Yt,{children:i.jsx(se,{type:"submit",children:e("flowise.button.save")})})]})})]})]})}const Sne=e=>["flowise","fetchSessions",JSON.stringify(e)],Cne=async({instanceName:e,flowiseId:t,token:n})=>(await Ee.get(`/flowise/fetchSessions/${t}/${e}`,{headers:{apiKey:n}})).data,Ene=e=>{const{instanceName:t,token:n,flowiseId:r,...s}=e;return mt({...s,queryKey:Sne({instanceName:t}),queryFn:()=>Cne({instanceName:t,token:n,flowiseId:r}),enabled:!!t&&!!r&&(e.enabled??!0)})};function PI({flowiseId:e}){const{t}=Ve(),{instance:n}=ct(),{changeStatusFlowise:r}=Sg(),[s,o]=y.useState([]),[l,u]=y.useState(!1),[d,f]=y.useState(""),{data:h,refetch:m}=Ene({instanceName:n?.name,flowiseId:e,enabled:l});function g(){m()}const x=async(w,C)=>{try{if(!n)return;await r({instanceName:n.name,token:n.token,remoteJid:w,status:C}),me.success(t("flowise.toast.success.status")),g()}catch(k){console.error("Error:",k),me.error(`Error : ${k?.response?.data?.response?.message}`)}},b=[{accessorKey:"remoteJid",header:()=>i.jsx("div",{className:"text-center",children:t("flowise.sessions.table.remoteJid")}),cell:({row:w})=>i.jsx("div",{children:w.getValue("remoteJid")})},{accessorKey:"pushName",header:()=>i.jsx("div",{className:"text-center",children:t("flowise.sessions.table.pushName")}),cell:({row:w})=>i.jsx("div",{children:w.getValue("pushName")})},{accessorKey:"sessionId",header:()=>i.jsx("div",{className:"text-center",children:t("flowise.sessions.table.sessionId")}),cell:({row:w})=>i.jsx("div",{children:w.getValue("sessionId")})},{accessorKey:"status",header:()=>i.jsx("div",{className:"text-center",children:t("flowise.sessions.table.status")}),cell:({row:w})=>i.jsx("div",{children:w.getValue("status")})},{id:"actions",enableHiding:!1,cell:({row:w})=>{const C=w.original;return i.jsxs(Kr,{children:[i.jsx(Wr,{asChild:!0,children:i.jsxs(se,{variant:"ghost",className:"h-8 w-8 p-0",children:[i.jsx("span",{className:"sr-only",children:t("flowise.sessions.table.actions.title")}),i.jsx(Pa,{className:"h-4 w-4"})]})}),i.jsxs(hr,{align:"end",children:[i.jsx(Ao,{children:t("flowise.sessions.table.actions.title")}),i.jsx(Xs,{}),C.status!=="opened"&&i.jsxs(wt,{onClick:()=>x(C.remoteJid,"opened"),children:[i.jsx(Fi,{className:"mr-2 h-4 w-4"}),t("flowise.sessions.table.actions.open")]}),C.status!=="paused"&&C.status!=="closed"&&i.jsxs(wt,{onClick:()=>x(C.remoteJid,"paused"),children:[i.jsx(Di,{className:"mr-2 h-4 w-4"}),t("flowise.sessions.table.actions.pause")]}),C.status!=="closed"&&i.jsxs(wt,{onClick:()=>x(C.remoteJid,"closed"),children:[i.jsx(Oi,{className:"mr-2 h-4 w-4"}),t("flowise.sessions.table.actions.close")]}),i.jsxs(wt,{onClick:()=>x(C.remoteJid,"delete"),children:[i.jsx(Ii,{className:"mr-2 h-4 w-4"}),t("flowise.sessions.table.actions.delete")]})]})]})}}];return i.jsxs(Pt,{open:l,onOpenChange:u,children:[i.jsx(Bt,{asChild:!0,children:i.jsxs(se,{variant:"secondary",size:"sm",children:[i.jsx(Ai,{size:16,className:"mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:t("flowise.sessions.label")})]})}),i.jsxs(Nt,{className:"overflow-y-auto sm:max-w-[950px]",onCloseAutoFocus:g,children:[i.jsx(Mt,{children:i.jsx(zt,{children:t("flowise.sessions.label")})}),i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between gap-6 p-5",children:[i.jsx(ne,{placeholder:t("flowise.sessions.search"),value:d,onChange:w=>f(w.target.value)}),i.jsx(se,{variant:"outline",onClick:g,size:"icon",children:i.jsx(Li,{})})]}),i.jsx($a,{columns:b,data:h??[],onSortingChange:o,state:{sorting:s,globalFilter:d},onGlobalFilterChange:f,enableGlobalFilter:!0,noResultsMessage:t("flowise.sessions.table.none")})]})]})]})}const kne=P.object({enabled:P.boolean(),description:P.string(),apiUrl:P.string(),apiKey:P.string().optional(),triggerType:P.string(),triggerOperator:P.string().optional(),triggerValue:P.string().optional(),expire:P.coerce.number().optional(),keywordFinish:P.string().optional(),delayMessage:P.coerce.number().optional(),unknownMessage:P.string().optional(),listeningFromMe:P.boolean().optional(),stopBotFromMe:P.boolean().optional(),keepOpen:P.boolean().optional(),debounceTime:P.coerce.number().optional(),splitMessages:P.boolean().optional(),timePerChar:P.coerce.number().optional()});function OI({initialData:e,onSubmit:t,handleDelete:n,flowiseId:r,isModal:s=!1,isLoading:o=!1,openDeletionDialog:l=!1,setOpenDeletionDialog:u=()=>{}}){const{t:d}=Ve(),f=on({resolver:an(kne),defaultValues:e||{enabled:!0,description:"",apiUrl:"",apiKey:"",triggerType:"keyword",triggerOperator:"contains",triggerValue:"",expire:0,keywordFinish:"",delayMessage:0,unknownMessage:"",listeningFromMe:!1,stopBotFromMe:!1,keepOpen:!1,debounceTime:0,splitMessages:!1,timePerChar:0}}),h=f.watch("triggerType");return i.jsx(Gn,{...f,children:i.jsxs("form",{onSubmit:f.handleSubmit(t),className:"w-full space-y-6",children:[i.jsxs("div",{className:"space-y-4",children:[i.jsx(Pe,{name:"enabled",label:d("flowise.form.enabled.label"),reverse:!0}),i.jsx(le,{name:"description",label:d("flowise.form.description.label"),required:!0,children:i.jsx(ne,{})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:d("flowise.form.flowiseSettings.label")}),i.jsx($t,{})]}),i.jsx(le,{name:"apiUrl",label:d("flowise.form.apiUrl.label"),required:!0,children:i.jsx(ne,{})}),i.jsx(le,{name:"apiKey",label:d("flowise.form.apiKey.label"),children:i.jsx(ne,{type:"password"})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:d("flowise.form.triggerSettings.label")}),i.jsx($t,{})]}),i.jsx(Jt,{name:"triggerType",label:d("flowise.form.triggerType.label"),options:[{label:d("flowise.form.triggerType.keyword"),value:"keyword"},{label:d("flowise.form.triggerType.all"),value:"all"},{label:d("flowise.form.triggerType.advanced"),value:"advanced"},{label:d("flowise.form.triggerType.none"),value:"none"}]}),h==="keyword"&&i.jsxs(i.Fragment,{children:[i.jsx(Jt,{name:"triggerOperator",label:d("flowise.form.triggerOperator.label"),options:[{label:d("flowise.form.triggerOperator.contains"),value:"contains"},{label:d("flowise.form.triggerOperator.equals"),value:"equals"},{label:d("flowise.form.triggerOperator.startsWith"),value:"startsWith"},{label:d("flowise.form.triggerOperator.endsWith"),value:"endsWith"},{label:d("flowise.form.triggerOperator.regex"),value:"regex"}]}),i.jsx(le,{name:"triggerValue",label:d("flowise.form.triggerValue.label"),children:i.jsx(ne,{})})]}),h==="advanced"&&i.jsx(le,{name:"triggerValue",label:d("flowise.form.triggerConditions.label"),children:i.jsx(ne,{})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:d("flowise.form.generalSettings.label")}),i.jsx($t,{})]}),i.jsx(le,{name:"expire",label:d("flowise.form.expire.label"),children:i.jsx(ne,{type:"number"})}),i.jsx(le,{name:"keywordFinish",label:d("flowise.form.keywordFinish.label"),children:i.jsx(ne,{})}),i.jsx(le,{name:"delayMessage",label:d("flowise.form.delayMessage.label"),children:i.jsx(ne,{type:"number"})}),i.jsx(le,{name:"unknownMessage",label:d("flowise.form.unknownMessage.label"),children:i.jsx(ne,{})}),i.jsx(Pe,{name:"listeningFromMe",label:d("flowise.form.listeningFromMe.label"),reverse:!0}),i.jsx(Pe,{name:"stopBotFromMe",label:d("flowise.form.stopBotFromMe.label"),reverse:!0}),i.jsx(Pe,{name:"keepOpen",label:d("flowise.form.keepOpen.label"),reverse:!0}),i.jsx(le,{name:"debounceTime",label:d("flowise.form.debounceTime.label"),children:i.jsx(ne,{type:"number"})}),i.jsx(Pe,{name:"splitMessages",label:d("flowise.form.splitMessages.label"),reverse:!0}),f.watch("splitMessages")&&i.jsx(le,{name:"timePerChar",label:d("flowise.form.timePerChar.label"),children:i.jsx(ne,{type:"number"})})]}),s&&i.jsx(Yt,{children:i.jsx(se,{disabled:o,type:"submit",children:d(o?"flowise.button.saving":"flowise.button.save")})}),!s&&i.jsxs("div",{children:[i.jsx(PI,{flowiseId:r}),i.jsxs("div",{className:"mt-5 flex items-center gap-3",children:[i.jsxs(Pt,{open:l,onOpenChange:u,children:[i.jsx(Bt,{asChild:!0,children:i.jsx(se,{variant:"destructive",size:"sm",children:d("dify.button.delete")})}),i.jsx(Nt,{children:i.jsxs(Mt,{children:[i.jsx(zt,{children:d("modal.delete.title")}),i.jsx(eo,{children:d("modal.delete.messageSingle")}),i.jsxs(Yt,{children:[i.jsx(se,{size:"sm",variant:"outline",onClick:()=>u(!1),children:d("button.cancel")}),i.jsx(se,{variant:"destructive",onClick:n,children:d("button.delete")})]})]})})]}),i.jsx(se,{disabled:o,type:"submit",children:d(o?"flowise.button.saving":"flowise.button.update")})]})]})]})})}function jne({resetTable:e}){const{t}=Ve(),{instance:n}=ct(),{createFlowise:r}=Sg(),[s,o]=y.useState(!1),[l,u]=y.useState(!1),d=async f=>{try{if(!n||!n.name)throw new Error("instance not found");o(!0);const h={enabled:f.enabled,description:f.description,apiUrl:f.apiUrl,apiKey:f.apiKey,triggerType:f.triggerType,triggerOperator:f.triggerOperator||"",triggerValue:f.triggerValue||"",expire:f.expire||0,keywordFinish:f.keywordFinish||"",delayMessage:f.delayMessage||0,unknownMessage:f.unknownMessage||"",listeningFromMe:f.listeningFromMe||!1,stopBotFromMe:f.stopBotFromMe||!1,keepOpen:f.keepOpen||!1,debounceTime:f.debounceTime||0,splitMessages:f.splitMessages||!1,timePerChar:f.timePerChar||0};await r({instanceName:n.name,token:n.token,data:h}),me.success(t("flowise.toast.success.create")),u(!1),e()}catch(h){console.error("Error:",h),me.error(`Error: ${h?.response?.data?.response?.message}`)}finally{o(!1)}};return i.jsxs(Pt,{open:l,onOpenChange:u,children:[i.jsx(Bt,{asChild:!0,children:i.jsxs(se,{size:"sm",children:[i.jsx(cs,{size:16,className:"mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:t("flowise.button.create")})]})}),i.jsxs(Nt,{className:"overflow-y-auto sm:max-h-[600px] sm:max-w-[740px]",children:[i.jsx(Mt,{children:i.jsx(zt,{children:t("flowise.form.title")})}),i.jsx(OI,{onSubmit:d,isModal:!0,isLoading:s})]})]})}const Tne=e=>["flowise","getFlowise",JSON.stringify(e)],Nne=async({instanceName:e,token:t,flowiseId:n})=>{const r=await Ee.get(`/flowise/fetch/${n}/${e}`,{headers:{apiKey:t}});return Array.isArray(r.data)?r.data[0]:r.data},Mne=e=>{const{instanceName:t,token:n,flowiseId:r,...s}=e;return mt({...s,queryKey:Tne({instanceName:t}),queryFn:()=>Nne({instanceName:t,token:n,flowiseId:r}),enabled:!!t&&!!r&&(e.enabled??!0)})};function _ne({flowiseId:e,resetTable:t}){const{t:n}=Ve(),{instance:r}=ct(),s=dn(),[o,l]=y.useState(!1),{deleteFlowise:u,updateFlowise:d}=Sg(),{data:f,isLoading:h}=Mne({instanceName:r?.name,flowiseId:e}),m=y.useMemo(()=>({enabled:f?.enabled??!0,description:f?.description??"",apiUrl:f?.apiUrl??"",apiKey:f?.apiKey??"",triggerType:f?.triggerType??"",triggerOperator:f?.triggerOperator??"",triggerValue:f?.triggerValue,expire:f?.expire??0,keywordFinish:f?.keywordFinish,delayMessage:f?.delayMessage??0,unknownMessage:f?.unknownMessage,listeningFromMe:f?.listeningFromMe,stopBotFromMe:f?.stopBotFromMe,keepOpen:f?.keepOpen,debounceTime:f?.debounceTime??0,splitMessages:f?.splitMessages??!1,timePerChar:f?.timePerChar??0}),[f?.apiKey,f?.apiUrl,f?.debounceTime,f?.delayMessage,f?.description,f?.enabled,f?.expire,f?.keepOpen,f?.keywordFinish,f?.listeningFromMe,f?.stopBotFromMe,f?.triggerOperator,f?.triggerType,f?.triggerValue,f?.unknownMessage,f?.splitMessages,f?.timePerChar]),g=async b=>{try{if(r&&r.name&&e){const w={enabled:b.enabled,description:b.description,apiUrl:b.apiUrl,apiKey:b.apiKey,triggerType:b.triggerType,triggerOperator:b.triggerOperator||"",triggerValue:b.triggerValue||"",expire:b.expire||0,keywordFinish:b.keywordFinish||"",delayMessage:b.delayMessage||1e3,unknownMessage:b.unknownMessage||"",listeningFromMe:b.listeningFromMe||!1,stopBotFromMe:b.stopBotFromMe||!1,keepOpen:b.keepOpen||!1,debounceTime:b.debounceTime||0,splitMessages:b.splitMessages||!1,timePerChar:b.timePerChar||0};await d({instanceName:r.name,flowiseId:e,data:w}),me.success(n("flowise.toast.success.update")),t(),s(`/manager/instance/${r.id}/flowise/${e}`)}else console.error("Token not found")}catch(w){console.error("Error:",w),me.error(`Error: ${w?.response?.data?.response?.message}`)}},x=async()=>{try{r&&r.name&&e?(await u({instanceName:r.name,flowiseId:e}),me.success(n("flowise.toast.success.delete")),l(!1),t(),s(`/manager/instance/${r.id}/flowise`)):console.error("instance not found")}catch(b){console.error("Erro ao excluir dify:",b)}};return h?i.jsx(On,{}):i.jsx("div",{className:"m-4",children:i.jsx(OI,{initialData:m,onSubmit:g,flowiseId:e,handleDelete:x,isModal:!1,isLoading:h,openDeletionDialog:o,setOpenDeletionDialog:l})})}function kk(){const{t:e}=Ve(),t=zo("(min-width: 768px)"),{instance:n}=ct(),{flowiseId:r}=ls(),{data:s,isLoading:o,refetch:l}=RI({instanceName:n?.name}),u=dn(),d=h=>{n&&u(`/manager/instance/${n.id}/flowise/${h}`)},f=()=>{l()};return i.jsxs("main",{className:"pt-5",children:[i.jsxs("div",{className:"mb-1 flex items-center justify-between",children:[i.jsx("h3",{className:"text-lg font-medium",children:e("flowise.title")}),i.jsxs("div",{className:"flex items-center justify-end gap-2",children:[i.jsx(PI,{}),i.jsx(wne,{}),i.jsx(jne,{resetTable:f})]})]}),i.jsx($t,{className:"my-4"}),i.jsxs($o,{direction:t?"horizontal":"vertical",children:[i.jsx(Hn,{defaultSize:35,className:"pr-4",children:i.jsx("div",{className:"flex flex-col gap-3",children:o?i.jsx(On,{}):i.jsx(i.Fragment,{children:s&&s.length>0&&Array.isArray(s)?s.map(h=>i.jsx(se,{className:"flex h-auto flex-col items-start justify-start",onClick:()=>d(`${h.id}`),variant:r===h.id?"secondary":"outline",children:i.jsx("h4",{className:"text-base",children:h.description||h.id})},h.id)):i.jsx(se,{variant:"link",children:e("flowise.table.none")})})})}),r&&i.jsxs(i.Fragment,{children:[i.jsx(Bo,{withHandle:!0,className:"border border-border"}),i.jsx(Hn,{children:i.jsx(_ne,{flowiseId:r,resetTable:f})})]})]})]})}const Rne=e=>["n8n","fetchN8n",JSON.stringify(e)],Pne=async({instanceName:e,token:t})=>(await Ee.get(`/n8n/find/${e}`,{headers:{apikey:t}})).data,II=e=>{const{instanceName:t,token:n,...r}=e;return mt({...r,queryKey:Rne({instanceName:t,token:n}),queryFn:()=>Pne({instanceName:t,token:n}),enabled:!!t&&(e.enabled??!0)})},One=async({instanceName:e,token:t,data:n})=>(await Ee.post(`/n8n/create/${e}`,n,{headers:{apikey:t}})).data,Ine=async({instanceName:e,n8nId:t,data:n})=>(await Ee.put(`/n8n/update/${t}/${e}`,n)).data,Ane=async({instanceName:e,n8nId:t})=>(await Ee.delete(`/n8n/delete/${t}/${e}`)).data,Dne=async({instanceName:e,token:t,data:n})=>(await Ee.post(`/n8n/settings/${e}`,n,{headers:{apikey:t}})).data,Fne=async({instanceName:e,token:t,remoteJid:n,status:r})=>(await Ee.post(`/n8n/changeStatus/${e}`,{remoteJid:n,status:r},{headers:{apikey:t}})).data;function Cg(){const e=nt(Dne,{invalidateKeys:[["n8n","fetchDefaultSettings"]]}),t=nt(Fne,{invalidateKeys:[["n8n","getN8n"],["n8n","fetchSessions"]]}),n=nt(Ane,{invalidateKeys:[["n8n","getN8n"],["n8n","fetchN8n"],["n8n","fetchSessions"]]}),r=nt(Ine,{invalidateKeys:[["n8n","getN8n"],["n8n","fetchN8n"],["n8n","fetchSessions"]]}),s=nt(One,{invalidateKeys:[["n8n","fetchN8n"]]});return{setDefaultSettingsN8n:e,changeStatusN8n:t,deleteN8n:n,updateN8n:r,createN8n:s}}const Lne=e=>["n8n","fetchDefaultSettings",JSON.stringify(e)],$ne=async({instanceName:e,token:t})=>(await Ee.get(`/n8n/fetchSettings/${e}`,{headers:{apikey:t}})).data,Bne=e=>{const{instanceName:t,token:n,...r}=e;return mt({...r,queryKey:Lne({instanceName:t,token:n}),queryFn:()=>$ne({instanceName:t,token:n}),enabled:!!t})},zne=P.object({expire:P.string(),keywordFinish:P.string(),delayMessage:P.string(),unknownMessage:P.string(),listeningFromMe:P.boolean(),stopBotFromMe:P.boolean(),keepOpen:P.boolean(),debounceTime:P.string(),ignoreJids:P.array(P.string()).default([]),n8nIdFallback:P.union([P.null(),P.string()]).optional(),splitMessages:P.boolean(),timePerChar:P.string()});function Une(){const{t:e}=Ve(),{instance:t}=ct(),{setDefaultSettingsN8n:n}=Cg(),[r,s]=y.useState(!1),{data:o,refetch:l}=II({instanceName:t?.name,token:t?.token,enabled:r}),{data:u,refetch:d}=Bne({instanceName:t?.name,token:t?.token}),f=on({resolver:an(zne),defaultValues:{expire:"0",keywordFinish:e("n8n.form.examples.keywordFinish"),delayMessage:"1000",unknownMessage:e("n8n.form.examples.unknownMessage"),listeningFromMe:!1,stopBotFromMe:!1,keepOpen:!1,debounceTime:"0",ignoreJids:[],n8nIdFallback:void 0,splitMessages:!1,timePerChar:"0"}});y.useEffect(()=>{u&&f.reset({expire:u?.expire?u.expire.toString():"0",keywordFinish:u.keywordFinish,delayMessage:u.delayMessage?u.delayMessage.toString():"0",unknownMessage:u.unknownMessage,listeningFromMe:u.listeningFromMe,stopBotFromMe:u.stopBotFromMe,keepOpen:u.keepOpen,debounceTime:u.debounceTime?u.debounceTime.toString():"0",ignoreJids:u.ignoreJids,n8nIdFallback:u.n8nIdFallback,splitMessages:u.splitMessages,timePerChar:u.timePerChar?u.timePerChar.toString():"0"})},[u]);const h=async g=>{try{if(!t||!t.name)throw new Error("instance not found.");const x={expire:parseInt(g.expire),keywordFinish:g.keywordFinish,delayMessage:parseInt(g.delayMessage),unknownMessage:g.unknownMessage,listeningFromMe:g.listeningFromMe,stopBotFromMe:g.stopBotFromMe,keepOpen:g.keepOpen,debounceTime:parseInt(g.debounceTime),n8nIdFallback:g.n8nIdFallback||void 0,ignoreJids:g.ignoreJids,splitMessages:g.splitMessages,timePerChar:parseInt(g.timePerChar)};await n({instanceName:t.name,token:t.token,data:x}),me.success(e("n8n.toast.defaultSettings.success"))}catch(x){console.error("Error:",x),me.error(`Error: ${x?.response?.data?.response?.message}`)}};function m(){d(),l()}return i.jsxs(Pt,{open:r,onOpenChange:s,children:[i.jsx(Bt,{asChild:!0,children:i.jsxs(se,{variant:"secondary",size:"sm",children:[i.jsx(Oo,{size:16,className:"mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:e("n8n.defaultSettings")})]})}),i.jsxs(Nt,{className:"overflow-y-auto sm:max-h-[600px] sm:max-w-[740px]",onCloseAutoFocus:m,children:[i.jsx(Mt,{children:i.jsx(zt,{children:e("n8n.defaultSettings")})}),i.jsx(Gn,{...f,children:i.jsxs("form",{className:"w-full space-y-6",onSubmit:f.handleSubmit(h),children:[i.jsx("div",{children:i.jsxs("div",{className:"space-y-4",children:[i.jsx(Jt,{name:"n8nIdFallback",label:e("n8n.form.n8nIdFallback.label"),options:o?.filter(g=>!!g.id).map(g=>({label:g.description,value:g.id}))??[]}),i.jsx(le,{name:"expire",label:e("n8n.form.expire.label"),children:i.jsx(ne,{type:"number"})}),i.jsx(le,{name:"keywordFinish",label:e("n8n.form.keywordFinish.label"),children:i.jsx(ne,{})}),i.jsx(le,{name:"delayMessage",label:e("n8n.form.delayMessage.label"),children:i.jsx(ne,{type:"number"})}),i.jsx(le,{name:"unknownMessage",label:e("n8n.form.unknownMessage.label"),children:i.jsx(ne,{})}),i.jsx(Pe,{name:"listeningFromMe",label:e("n8n.form.listeningFromMe.label"),reverse:!0}),i.jsx(Pe,{name:"stopBotFromMe",label:e("n8n.form.stopBotFromMe.label"),reverse:!0}),i.jsx(Pe,{name:"keepOpen",label:e("n8n.form.keepOpen.label"),reverse:!0}),i.jsx(le,{name:"debounceTime",label:e("n8n.form.debounceTime.label"),children:i.jsx(ne,{type:"number"})}),i.jsx(Pe,{name:"splitMessages",label:e("n8n.form.splitMessages.label"),reverse:!0}),i.jsx(le,{name:"timePerChar",label:e("n8n.form.timePerChar.label"),children:i.jsx(ne,{type:"number"})}),i.jsx(Da,{name:"ignoreJids",label:e("n8n.form.ignoreJids.label"),placeholder:e("n8n.form.ignoreJids.placeholder")})]})}),i.jsx(Yt,{children:i.jsx(se,{type:"submit",children:e("n8n.button.save")})})]})})]})]})}const Vne=e=>["n8n","fetchSessions",JSON.stringify(e)],Hne=async({n8nId:e,instanceName:t})=>(await Ee.get(`/n8n/fetchSessions/${e}/${t}`)).data,qne=e=>{const{n8nId:t,instanceName:n,...r}=e;return mt({...r,queryKey:Vne({n8nId:t,instanceName:n}),queryFn:()=>Hne({n8nId:t,instanceName:n}),enabled:!!n&&!!t&&(e.enabled??!0),staleTime:1e3*10})};function AI({n8nId:e}){const{t}=Ve(),{instance:n}=ct(),{changeStatusN8n:r}=Cg(),[s,o]=y.useState([]),{data:l,refetch:u}=qne({n8nId:e,instanceName:n?.name}),[d,f]=y.useState(!1),[h,m]=y.useState("");function g(){u()}const x=async(w,C)=>{try{if(!n)return;await r({instanceName:n.name,token:n.token,remoteJid:w,status:C}),me.success(t("n8n.toast.success.status")),g()}catch(k){console.error("Error:",k),me.error(`Error : ${k?.response?.data?.response?.message}`)}},b=[{accessorKey:"remoteJid",header:()=>i.jsx("div",{className:"text-center",children:t("n8n.sessions.table.remoteJid")}),cell:({row:w})=>i.jsx("div",{children:w.getValue("remoteJid")})},{accessorKey:"pushName",header:()=>i.jsx("div",{className:"text-center",children:t("n8n.sessions.table.pushName")}),cell:({row:w})=>i.jsx("div",{children:w.getValue("pushName")})},{accessorKey:"sessionId",header:()=>i.jsx("div",{className:"text-center",children:t("n8n.sessions.table.sessionId")}),cell:({row:w})=>i.jsx("div",{children:w.getValue("sessionId")})},{accessorKey:"status",header:()=>i.jsx("div",{className:"text-center",children:t("n8n.sessions.table.status")}),cell:({row:w})=>i.jsx("div",{children:w.getValue("status")})},{id:"actions",enableHiding:!1,cell:({row:w})=>{const C=w.original;return i.jsxs(Kr,{children:[i.jsx(Wr,{asChild:!0,children:i.jsxs(se,{variant:"ghost",className:"h-8 w-8 p-0",children:[i.jsx("span",{className:"sr-only",children:t("n8n.sessions.table.actions.title")}),i.jsx(Pa,{className:"h-4 w-4"})]})}),i.jsxs(hr,{align:"end",children:[i.jsx(Ao,{children:t("n8n.sessions.table.actions.title")}),i.jsx(Xs,{}),C.status!=="opened"&&i.jsxs(wt,{onClick:()=>x(C.remoteJid,"opened"),children:[i.jsx(Fi,{className:"mr-2 h-4 w-4"}),t("n8n.sessions.table.actions.open")]}),C.status!=="paused"&&C.status!=="closed"&&i.jsxs(wt,{onClick:()=>x(C.remoteJid,"paused"),children:[i.jsx(Di,{className:"mr-2 h-4 w-4"}),t("n8n.sessions.table.actions.pause")]}),C.status!=="closed"&&i.jsxs(wt,{onClick:()=>x(C.remoteJid,"closed"),children:[i.jsx(Oi,{className:"mr-2 h-4 w-4"}),t("n8n.sessions.table.actions.close")]}),i.jsxs(wt,{onClick:()=>x(C.remoteJid,"delete"),children:[i.jsx(Ii,{className:"mr-2 h-4 w-4"}),t("n8n.sessions.table.actions.delete")]})]})]})}}];return i.jsxs(Pt,{open:d,onOpenChange:f,children:[i.jsx(Bt,{asChild:!0,children:i.jsxs(se,{variant:"secondary",size:"sm",children:[i.jsx(Ai,{size:16,className:"mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:t("n8n.sessions.label")})]})}),i.jsxs(Nt,{className:"overflow-y-auto sm:max-w-[950px]",onCloseAutoFocus:g,children:[i.jsx(Mt,{children:i.jsx(zt,{children:t("n8n.sessions.label")})}),i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between gap-6 p-5",children:[i.jsx(ne,{placeholder:t("n8n.sessions.search"),value:h,onChange:w=>m(w.target.value)}),i.jsx(se,{variant:"outline",onClick:g,size:"icon",children:i.jsx(Li,{})})]}),i.jsx($a,{columns:b,data:l??[],onSortingChange:o,state:{sorting:s,globalFilter:h},onGlobalFilterChange:m,enableGlobalFilter:!0,noResultsMessage:t("n8n.sessions.table.none")})]})]})]})}const Kne=P.object({enabled:P.boolean(),description:P.string(),webhookUrl:P.string(),basicAuthUser:P.string(),basicAuthPass:P.string(),triggerType:P.string(),triggerOperator:P.string().optional(),triggerValue:P.string().optional(),expire:P.coerce.number().optional(),keywordFinish:P.string().optional(),delayMessage:P.coerce.number().optional(),unknownMessage:P.string().optional(),listeningFromMe:P.boolean().optional(),stopBotFromMe:P.boolean().optional(),keepOpen:P.boolean().optional(),debounceTime:P.coerce.number().optional(),splitMessages:P.boolean().optional(),timePerChar:P.coerce.number().optional()});function DI({initialData:e,onSubmit:t,handleDelete:n,n8nId:r,isModal:s=!1,isLoading:o=!1,openDeletionDialog:l=!1,setOpenDeletionDialog:u=()=>{}}){const{t:d}=Ve(),f=on({resolver:an(Kne),defaultValues:e||{enabled:!0,description:"",webhookUrl:"",basicAuthUser:"",basicAuthPass:"",triggerType:"keyword",triggerOperator:"contains",triggerValue:"",expire:0,keywordFinish:"",delayMessage:0,unknownMessage:"",listeningFromMe:!1,stopBotFromMe:!1,keepOpen:!1,debounceTime:0,splitMessages:!1,timePerChar:0}}),h=f.watch("triggerType");return i.jsx(Gn,{...f,children:i.jsxs("form",{onSubmit:f.handleSubmit(t),className:"w-full space-y-6",children:[i.jsxs("div",{className:"space-y-4",children:[i.jsx(Pe,{name:"enabled",label:d("n8n.form.enabled.label"),reverse:!0}),i.jsx(le,{name:"description",label:d("n8n.form.description.label"),children:i.jsx(ne,{})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:d("n8n.form.n8nSettings.label")}),i.jsx($t,{})]}),i.jsx(le,{name:"webhookUrl",label:d("n8n.form.webhookUrl.label"),required:!0,children:i.jsx(ne,{})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:d("n8n.form.basicAuth.label")}),i.jsx($t,{})]}),i.jsxs("div",{className:"flex w-full flex-row gap-4",children:[i.jsx(le,{name:"basicAuthUser",label:d("n8n.form.basicAuthUser.label"),className:"flex-1",children:i.jsx(ne,{})}),i.jsx(le,{name:"basicAuthPass",label:d("n8n.form.basicAuthPass.label"),className:"flex-1",children:i.jsx(ne,{type:"password"})})]}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:d("n8n.form.triggerSettings.label")}),i.jsx($t,{})]}),i.jsx(Jt,{name:"triggerType",label:d("n8n.form.triggerType.label"),options:[{label:d("n8n.form.triggerType.keyword"),value:"keyword"},{label:d("n8n.form.triggerType.all"),value:"all"},{label:d("n8n.form.triggerType.advanced"),value:"advanced"},{label:d("n8n.form.triggerType.none"),value:"none"}]}),h==="keyword"&&i.jsxs(i.Fragment,{children:[i.jsx(Jt,{name:"triggerOperator",label:d("n8n.form.triggerOperator.label"),options:[{label:d("n8n.form.triggerOperator.contains"),value:"contains"},{label:d("n8n.form.triggerOperator.equals"),value:"equals"},{label:d("n8n.form.triggerOperator.startsWith"),value:"startsWith"},{label:d("n8n.form.triggerOperator.endsWith"),value:"endsWith"},{label:d("n8n.form.triggerOperator.regex"),value:"regex"}]}),i.jsx(le,{name:"triggerValue",label:d("n8n.form.triggerValue.label"),children:i.jsx(ne,{})})]}),h==="advanced"&&i.jsx(le,{name:"triggerValue",label:d("n8n.form.triggerConditions.label"),children:i.jsx(ne,{})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:d("n8n.form.generalSettings.label")}),i.jsx($t,{})]}),i.jsx(le,{name:"expire",label:d("n8n.form.expire.label"),children:i.jsx(ne,{type:"number"})}),i.jsx(le,{name:"keywordFinish",label:d("n8n.form.keywordFinish.label"),children:i.jsx(ne,{})}),i.jsx(le,{name:"delayMessage",label:d("n8n.form.delayMessage.label"),children:i.jsx(ne,{type:"number"})}),i.jsx(le,{name:"unknownMessage",label:d("n8n.form.unknownMessage.label"),children:i.jsx(ne,{})}),i.jsx(Pe,{name:"listeningFromMe",label:d("n8n.form.listeningFromMe.label"),reverse:!0}),i.jsx(Pe,{name:"stopBotFromMe",label:d("n8n.form.stopBotFromMe.label"),reverse:!0}),i.jsx(Pe,{name:"keepOpen",label:d("n8n.form.keepOpen.label"),reverse:!0}),i.jsx(le,{name:"debounceTime",label:d("n8n.form.debounceTime.label"),children:i.jsx(ne,{type:"number"})}),i.jsx(Pe,{name:"splitMessages",label:d("n8n.form.splitMessages.label"),reverse:!0}),f.watch("splitMessages")&&i.jsx(le,{name:"timePerChar",label:d("n8n.form.timePerChar.label"),children:i.jsx(ne,{type:"number"})})]}),s&&i.jsx(Yt,{children:i.jsx(se,{disabled:o,type:"submit",children:d(o?"n8n.button.saving":"n8n.button.save")})}),!s&&i.jsxs("div",{children:[i.jsx(AI,{n8nId:r}),i.jsxs("div",{className:"mt-5 flex items-center gap-3",children:[i.jsxs(Pt,{open:l,onOpenChange:u,children:[i.jsx(Bt,{asChild:!0,children:i.jsx(se,{variant:"destructive",size:"sm",children:d("n8n.button.delete")})}),i.jsx(Nt,{children:i.jsxs(Mt,{children:[i.jsx(zt,{children:d("modal.delete.title")}),i.jsx(eo,{children:d("modal.delete.messageSingle")}),i.jsxs(Yt,{children:[i.jsx(se,{size:"sm",variant:"outline",onClick:()=>u(!1),children:d("button.cancel")}),i.jsx(se,{variant:"destructive",onClick:n,children:d("button.delete")})]})]})})]}),i.jsx(se,{disabled:o,type:"submit",children:d(o?"n8n.button.saving":"n8n.button.update")})]})]})]})})}function Wne({resetTable:e}){const{t}=Ve(),{instance:n}=ct(),[r,s]=y.useState(!1),[o,l]=y.useState(!1),{createN8n:u}=Cg(),d=async f=>{try{if(!n||!n.name)throw new Error("instance not found");s(!0);const h={enabled:f.enabled,description:f.description,webhookUrl:f.webhookUrl,basicAuthUser:f.basicAuthUser,basicAuthPass:f.basicAuthPass,triggerType:f.triggerType,triggerOperator:f.triggerOperator||"",triggerValue:f.triggerValue||"",expire:f.expire||0,keywordFinish:f.keywordFinish||"",delayMessage:f.delayMessage||0,unknownMessage:f.unknownMessage||"",listeningFromMe:f.listeningFromMe||!1,stopBotFromMe:f.stopBotFromMe||!1,keepOpen:f.keepOpen||!1,debounceTime:f.debounceTime||0,splitMessages:f.splitMessages||!1,timePerChar:f.timePerChar||0};await u({instanceName:n.name,token:n.token,data:h}),me.success(t("n8n.toast.success.create")),l(!1),e()}catch(h){console.error("Error:",h),me.error(`Error: ${h?.response?.data?.response?.message}`)}finally{s(!1)}};return i.jsxs(Pt,{open:o,onOpenChange:l,children:[i.jsx(Bt,{asChild:!0,children:i.jsxs(se,{size:"sm",children:[i.jsx(cs,{size:16,className:"mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:t("n8n.button.create")})]})}),i.jsxs(Nt,{className:"overflow-y-auto sm:max-h-[600px] sm:max-w-[740px]",children:[i.jsx(Mt,{children:i.jsx(zt,{children:t("n8n.form.title")})}),i.jsx(DI,{onSubmit:d,isModal:!0,isLoading:r})]})]})}const Gne=e=>["n8n","getN8n",JSON.stringify(e)],Jne=async({n8nId:e,instanceName:t})=>(await Ee.get(`/n8n/fetch/${e}/${t}`)).data,Qne=e=>{const{n8nId:t,instanceName:n,...r}=e;return mt({...r,queryKey:Gne({n8nId:t,instanceName:n}),queryFn:()=>Jne({n8nId:t,instanceName:n}),enabled:!!n&&!!t&&(e.enabled??!0)})};function Zne({n8nId:e,resetTable:t}){const{t:n}=Ve(),{instance:r}=ct(),s=dn(),[o,l]=y.useState(!1),{deleteN8n:u,updateN8n:d}=Cg(),{data:f,isLoading:h}=Qne({n8nId:e,instanceName:r?.name}),m=y.useMemo(()=>({enabled:!!f?.enabled,description:f?.description??"",webhookUrl:f?.webhookUrl??"",basicAuthUser:f?.basicAuthUser??"",basicAuthPass:f?.basicAuthPass??"",triggerType:f?.triggerType??"",triggerOperator:f?.triggerOperator??"",triggerValue:f?.triggerValue??"",expire:f?.expire??0,keywordFinish:f?.keywordFinish??"",delayMessage:f?.delayMessage??0,unknownMessage:f?.unknownMessage??"",listeningFromMe:!!f?.listeningFromMe,stopBotFromMe:!!f?.stopBotFromMe,keepOpen:!!f?.keepOpen,debounceTime:f?.debounceTime??0,splitMessages:f?.splitMessages??!1,timePerChar:f?.timePerChar??0}),[f?.webhookUrl,f?.basicAuthUser,f?.basicAuthPass,f?.debounceTime,f?.delayMessage,f?.description,f?.enabled,f?.expire,f?.keepOpen,f?.keywordFinish,f?.listeningFromMe,f?.stopBotFromMe,f?.triggerOperator,f?.triggerType,f?.triggerValue,f?.unknownMessage,f?.splitMessages,f?.timePerChar]),g=async b=>{try{if(r&&r.name&&e){const w={enabled:b.enabled,description:b.description,webhookUrl:b.webhookUrl,basicAuthUser:b.basicAuthUser,basicAuthPass:b.basicAuthPass,triggerType:b.triggerType,triggerOperator:b.triggerOperator||"",triggerValue:b.triggerValue||"",expire:b.expire||0,keywordFinish:b.keywordFinish||"",delayMessage:b.delayMessage||1e3,unknownMessage:b.unknownMessage||"",listeningFromMe:b.listeningFromMe||!1,stopBotFromMe:b.stopBotFromMe||!1,keepOpen:b.keepOpen||!1,debounceTime:b.debounceTime||0,splitMessages:b.splitMessages||!1,timePerChar:b.timePerChar||0};await d({instanceName:r.name,n8nId:e,data:w}),me.success(n("n8n.toast.success.update")),t(),s(`/manager/instance/${r.id}/n8n/${e}`)}else console.error("Token not found")}catch(w){console.error("Error:",w),me.error(`Error: ${w?.response?.data?.response?.message}`)}},x=async()=>{try{r&&r.name&&e?(await u({instanceName:r.name,n8nId:e}),me.success(n("n8n.toast.success.delete")),l(!1),t(),s(`/manager/instance/${r.id}/n8n`)):console.error("instance not found")}catch(b){console.error("Erro ao excluir n8n:",b)}};return h?i.jsx(On,{}):i.jsx("div",{className:"m-4",children:i.jsx(DI,{initialData:m,onSubmit:g,n8nId:e,handleDelete:x,isModal:!1,isLoading:h,openDeletionDialog:o,setOpenDeletionDialog:l})})}function jk(){const{t:e}=Ve(),t=zo("(min-width: 768px)"),{instance:n}=ct(),{n8nId:r}=ls(),{data:s,refetch:o,isLoading:l}=II({instanceName:n?.name}),u=dn(),d=h=>{n&&u(`/manager/instance/${n.id}/n8n/${h}`)},f=()=>{o()};return i.jsxs("main",{className:"pt-5",children:[i.jsxs("div",{className:"mb-1 flex items-center justify-between",children:[i.jsx("h3",{className:"text-lg font-medium",children:e("n8n.title")}),i.jsxs("div",{className:"flex items-center justify-end gap-2",children:[i.jsx(AI,{}),i.jsx(Une,{}),i.jsx(Wne,{resetTable:f})]})]}),i.jsx($t,{className:"my-4"}),i.jsxs($o,{direction:t?"horizontal":"vertical",children:[i.jsx(Hn,{defaultSize:35,className:"pr-4",children:i.jsx("div",{className:"flex flex-col gap-3",children:l?i.jsx(On,{}):i.jsx(i.Fragment,{children:s&&s.length>0&&Array.isArray(s)?s.map(h=>i.jsx(se,{className:"flex h-auto flex-col items-start justify-start",onClick:()=>d(`${h.id}`),variant:r===h.id?"secondary":"outline",children:i.jsx("h4",{className:"text-base",children:h.description||h.id})},h.id)):i.jsx(se,{variant:"link",children:e("n8n.table.none")})})})}),r&&i.jsxs(i.Fragment,{children:[i.jsx(Bo,{withHandle:!0,className:"border border-border"}),i.jsx(Hn,{children:i.jsx(Zne,{n8nId:r,resetTable:f})})]})]})]})}const Yne=e=>["openai","findOpenai",JSON.stringify(e)],Xne=async({instanceName:e,token:t})=>(await Ee.get(`/openai/find/${e}`,{headers:{apiKey:t}})).data,FI=e=>{const{instanceName:t,token:n,...r}=e;return mt({...r,queryKey:Yne({instanceName:t}),queryFn:()=>Xne({instanceName:t,token:n}),enabled:!!t&&(e.enabled??!0)})},ere=e=>["openai","findOpenaiCreds",JSON.stringify(e)],tre=async({instanceName:e,token:t})=>(await Ee.get(`/openai/creds/${e}`,{headers:{apiKey:t}})).data,dw=e=>{const{instanceName:t,token:n,...r}=e;return mt({staleTime:1e3*60*60*6,...r,queryKey:ere({instanceName:t}),queryFn:()=>tre({instanceName:t,token:n}),enabled:!!t&&(e.enabled??!0)})},nre=async({instanceName:e,token:t,data:n})=>(await Ee.post(`/openai/creds/${e}`,n,{headers:{apikey:t}})).data,rre=async({openaiCredsId:e,instanceName:t})=>(await Ee.delete(`/openai/creds/${e}/${t}`)).data,sre=async({instanceName:e,token:t,data:n})=>(await Ee.post(`/openai/create/${e}`,n,{headers:{apikey:t}})).data,ore=async({instanceName:e,token:t,openaiId:n,data:r})=>(await Ee.put(`/openai/update/${n}/${e}`,r,{headers:{apikey:t}})).data,are=async({instanceName:e,token:t,openaiId:n})=>(await Ee.delete(`/openai/delete/${n}/${e}`,{headers:{apikey:t}})).data,ire=async({instanceName:e,token:t,data:n})=>(await Ee.post(`/openai/settings/${e}`,n,{headers:{apikey:t}})).data,lre=async({instanceName:e,token:t,remoteJid:n,status:r})=>(await Ee.post(`/openai/changeStatus/${e}`,{remoteJid:n,status:r},{headers:{apikey:t}})).data;function Md(){const e=nt(ire,{invalidateKeys:[["openai","fetchDefaultSettings"]]}),t=nt(lre,{invalidateKeys:[["openai","getOpenai"],["openai","fetchSessions"]]}),n=nt(are,{invalidateKeys:[["openai","getOpenai"],["openai","findOpenai"],["openai","fetchSessions"]]}),r=nt(ore,{invalidateKeys:[["openai","getOpenai"],["openai","findOpenai"],["openai","fetchSessions"]]}),s=nt(sre,{invalidateKeys:[["openai","findOpenai"]]}),o=nt(nre,{invalidateKeys:[["openai","findOpenaiCreds"]]}),l=nt(rre,{invalidateKeys:[["openai","findOpenaiCreds"]]});return{setDefaultSettingsOpenai:e,changeStatusOpenai:t,deleteOpenai:n,updateOpenai:r,createOpenai:s,createOpenaiCreds:o,deleteOpenaiCreds:l}}const cre=P.object({name:P.string(),apiKey:P.string()});function LI({onCredentialsUpdate:e,showText:t=!0}){const{t:n}=Ve(),{instance:r}=ct(),{createOpenaiCreds:s,deleteOpenaiCreds:o}=Md(),[l,u]=y.useState(!1),[d,f]=y.useState([]),{data:h}=dw({instanceName:r?.name,enabled:l}),m=on({resolver:an(cre),defaultValues:{name:"",apiKey:""}}),g=async w=>{try{if(!r||!r.name)throw new Error("instance not found.");const C={name:w.name,apiKey:w.apiKey};await s({instanceName:r.name,token:r.token,data:C}),me.success(n("openai.toast.success.credentialsCreate")),m.reset(),e&&e()}catch(C){console.error("Error:",C),me.error(`Error: ${C?.response?.data?.response?.message}`)}},x=async w=>{if(!r?.name){me.error("Instance not found.");return}try{await o({openaiCredsId:w,instanceName:r?.name}),me.success(n("openai.toast.success.credentialsDelete")),e&&e()}catch(C){console.error("Error:",C),me.error(`Error: ${C?.response?.data?.response?.message}`)}},b=[{accessorKey:"name",header:({column:w})=>i.jsxs(se,{variant:"ghost",onClick:()=>w.toggleSorting(w.getIsSorted()==="asc"),children:[n("openai.credentials.table.name"),i.jsx(q$,{className:"ml-2 h-4 w-4"})]}),cell:({row:w})=>i.jsx("div",{children:w.getValue("name")})},{accessorKey:"apiKey",header:()=>i.jsx("div",{className:"text-right",children:n("openai.credentials.table.apiKey")}),cell:({row:w})=>i.jsxs("div",{children:[`${w.getValue("apiKey")}`.slice(0,20),"..."]})},{id:"actions",enableHiding:!1,cell:({row:w})=>{const C=w.original;return i.jsxs(Kr,{children:[i.jsx(Wr,{asChild:!0,children:i.jsxs(se,{variant:"ghost",className:"h-8 w-8 p-0",children:[i.jsx("span",{className:"sr-only",children:n("openai.credentials.table.actions.title")}),i.jsx(Pa,{className:"h-4 w-4"})]})}),i.jsxs(hr,{align:"end",children:[i.jsx(Ao,{children:n("openai.credentials.table.actions.title")}),i.jsx(Xs,{}),i.jsx(wt,{onClick:()=>x(C.id),children:n("openai.credentials.table.actions.delete")})]})]})}}];return i.jsxs(Pt,{open:l,onOpenChange:u,children:[i.jsx(Bt,{asChild:!0,children:i.jsx(se,{variant:"secondary",size:"sm",type:"button",children:t?i.jsxs(i.Fragment,{children:[i.jsx(mB,{size:16,className:"mr-1"}),i.jsx("span",{className:"hidden md:inline",children:n("openai.credentials.title")})]}):i.jsx(cs,{size:16})})}),i.jsxs(Nt,{className:"overflow-y-auto sm:max-h-[600px] sm:max-w-[740px]",children:[i.jsx(Mt,{children:i.jsx(zt,{children:n("openai.credentials.title")})}),i.jsx(Gn,{...m,children:i.jsx("div",{onClick:w=>w.stopPropagation(),onSubmit:w=>w.stopPropagation(),onKeyDown:w=>w.stopPropagation(),children:i.jsxs("form",{onSubmit:w=>{w.preventDefault(),w.stopPropagation(),m.handleSubmit(g)(w)},className:"w-full space-y-6",children:[i.jsx("div",{children:i.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[i.jsx(le,{name:"name",label:n("openai.credentials.table.name"),children:i.jsx(ne,{})}),i.jsx(le,{name:"apiKey",label:n("openai.credentials.table.apiKey"),children:i.jsx(ne,{type:"password"})})]})}),i.jsx(Yt,{children:i.jsx(se,{type:"submit",children:n("openai.button.save")})})]})})}),i.jsx($t,{}),i.jsx("div",{children:i.jsx($a,{columns:b,data:h??[],onSortingChange:f,state:{sorting:d},noResultsMessage:n("openai.credentials.table.none")})})]})]})}const ure=e=>["openai","fetchDefaultSettings",JSON.stringify(e)],dre=async({instanceName:e,token:t})=>{const n=await Ee.get(`/openai/fetchSettings/${e}`,{headers:{apiKey:t}});return Array.isArray(n.data)?n.data[0]:n.data},fre=e=>{const{instanceName:t,token:n,...r}=e;return mt({...r,queryKey:ure({instanceName:t}),queryFn:()=>dre({instanceName:t,token:n}),enabled:!!t&&(e.enabled??!0)})},pre=P.object({openaiCredsId:P.string(),expire:P.coerce.number(),keywordFinish:P.string(),delayMessage:P.coerce.number().default(0),unknownMessage:P.string(),listeningFromMe:P.boolean(),stopBotFromMe:P.boolean(),keepOpen:P.boolean(),debounceTime:P.coerce.number(),speechToText:P.boolean(),ignoreJids:P.array(P.string()).default([]),openaiIdFallback:P.union([P.null(),P.string()]).optional(),splitMessages:P.boolean().optional(),timePerChar:P.coerce.number().optional()});function hre(){const{t:e}=Ve(),{instance:t}=ct(),{setDefaultSettingsOpenai:n}=Md(),[r,s]=y.useState(!1),{data:o,refetch:l}=fre({instanceName:t?.name,enabled:r}),{data:u,refetch:d}=FI({instanceName:t?.name,enabled:r}),{data:f}=dw({instanceName:t?.name,enabled:r}),h=on({resolver:an(pre),defaultValues:{openaiCredsId:"",expire:0,keywordFinish:e("openai.form.examples.keywordFinish"),delayMessage:1e3,unknownMessage:e("openai.form.examples.unknownMessage"),listeningFromMe:!1,stopBotFromMe:!1,keepOpen:!1,debounceTime:0,speechToText:!1,ignoreJids:[],openaiIdFallback:void 0,splitMessages:!1,timePerChar:0}});y.useEffect(()=>{o&&h.reset({openaiCredsId:o.openaiCredsId,expire:o?.expire??0,keywordFinish:o.keywordFinish,delayMessage:o.delayMessage??0,unknownMessage:o.unknownMessage,listeningFromMe:o.listeningFromMe,stopBotFromMe:o.stopBotFromMe,keepOpen:o.keepOpen,debounceTime:o.debounceTime??0,speechToText:o.speechToText,ignoreJids:o.ignoreJids,openaiIdFallback:o.openaiIdFallback,splitMessages:o.splitMessages,timePerChar:o.timePerChar??0})},[o]);const m=async x=>{try{if(!t||!t.name)throw new Error("instance not found.");const b={openaiCredsId:x.openaiCredsId,expire:x.expire,keywordFinish:x.keywordFinish,delayMessage:x.delayMessage,unknownMessage:x.unknownMessage,listeningFromMe:x.listeningFromMe,stopBotFromMe:x.stopBotFromMe,keepOpen:x.keepOpen,debounceTime:x.debounceTime,speechToText:x.speechToText,openaiIdFallback:x.openaiIdFallback||void 0,ignoreJids:x.ignoreJids,splitMessages:x.splitMessages,timePerChar:x.timePerChar};await n({instanceName:t.name,token:t.token,data:b}),me.success(e("openai.toast.defaultSettings.success"))}catch(b){console.error("Error:",b),me.error(`Error: ${b?.response?.data?.response?.message}`)}};function g(){l(),d()}return i.jsxs(Pt,{open:r,onOpenChange:s,children:[i.jsx(Bt,{asChild:!0,children:i.jsxs(se,{variant:"secondary",size:"sm",children:[i.jsx(Oo,{size:16,className:"mr-1"}),i.jsx("span",{className:"hidden md:inline",children:e("openai.defaultSettings")})]})}),i.jsxs(Nt,{className:"overflow-y-auto sm:max-h-[600px] sm:max-w-[740px]",onCloseAutoFocus:g,children:[i.jsx(Mt,{children:i.jsx(zt,{children:e("openai.defaultSettings")})}),i.jsx(Gn,{...h,children:i.jsxs("form",{className:"w-full space-y-6",onSubmit:h.handleSubmit(m),children:[i.jsx("div",{children:i.jsxs("div",{className:"space-y-4",children:[i.jsx(Jt,{name:"openaiCredsId",label:e("openai.form.openaiCredsId.label"),options:f?.filter(x=>!!x.id).map(x=>({label:x.name?x.name:x.apiKey.substring(0,15)+"...",value:x.id}))||[]}),i.jsx(Jt,{name:"openaiIdFallback",label:e("openai.form.openaiIdFallback.label"),options:u?.filter(x=>!!x.id).map(x=>({label:x.description,value:x.id}))??[]}),i.jsx(le,{name:"expire",label:e("openai.form.expire.label"),children:i.jsx(ne,{type:"number"})}),i.jsx(le,{name:"keywordFinish",label:e("openai.form.keywordFinish.label"),children:i.jsx(ne,{})}),i.jsx(le,{name:"delayMessage",label:e("openai.form.delayMessage.label"),children:i.jsx(ne,{type:"number"})}),i.jsx(le,{name:"unknownMessage",label:e("openai.form.unknownMessage.label"),children:i.jsx(ne,{})}),i.jsx(Pe,{name:"listeningFromMe",label:e("openai.form.listeningFromMe.label"),reverse:!0}),i.jsx(Pe,{name:"stopBotFromMe",label:e("openai.form.stopBotFromMe.label"),reverse:!0}),i.jsx(Pe,{name:"keepOpen",label:e("openai.form.keepOpen.label"),reverse:!0}),i.jsx(Pe,{name:"speechToText",label:e("openai.form.speechToText.label"),reverse:!0}),i.jsx(le,{name:"debounceTime",label:e("openai.form.debounceTime.label"),children:i.jsx(ne,{type:"number"})}),i.jsx(Pe,{name:"splitMessages",label:e("openai.form.splitMessages.label"),reverse:!0}),h.watch("splitMessages")&&i.jsx(le,{name:"timePerChar",label:e("openai.form.timePerChar.label"),children:i.jsx(ne,{type:"number"})}),i.jsx(Da,{name:"ignoreJids",label:e("openai.form.ignoreJids.label"),placeholder:e("openai.form.ignoreJids.placeholder")})]})}),i.jsx(Yt,{children:i.jsx(se,{type:"submit",children:e("openai.button.save")})})]})})]})]})}const gre=e=>["openai","getModels",JSON.stringify(e)],mre=async({instanceName:e,openaiCredsId:t,token:n})=>{const r=t?{openaiCredsId:t}:{};return(await Ee.get(`/openai/getModels/${e}`,{headers:{apiKey:n},params:r})).data},vre=e=>{const{instanceName:t,openaiCredsId:n,token:r,...s}=e;return mt({staleTime:1e3*60*60*6,...s,queryKey:gre({instanceName:t,openaiCredsId:n}),queryFn:()=>mre({instanceName:t,openaiCredsId:n,token:r}),enabled:!!t&&!!n&&(e.enabled??!0)})},yre=e=>["openai","fetchSessions",JSON.stringify(e)],bre=async({instanceName:e,openaiId:t,token:n})=>(await Ee.get(`/openai/fetchSessions/${t}/${e}`,{headers:{apiKey:n}})).data,xre=e=>{const{instanceName:t,token:n,openaiId:r,...s}=e;return mt({...s,queryKey:yre({instanceName:t}),queryFn:()=>bre({instanceName:t,token:n,openaiId:r}),enabled:!!t&&!!r&&(e.enabled??!0)})};function $I({openaiId:e}){const{t}=Ve(),{instance:n}=ct(),{changeStatusOpenai:r}=Md(),[s,o]=y.useState([]),[l,u]=y.useState(!1),{data:d,refetch:f}=xre({instanceName:n?.name,openaiId:e,enabled:l}),[h,m]=y.useState("");function g(){f()}const x=async(w,C)=>{try{if(!n)return;await r({instanceName:n.name,token:n.token,remoteJid:w,status:C}),me.success(t("openai.toast.success.status")),g()}catch(k){console.error("Error:",k),me.error(`Error : ${k?.response?.data?.response?.message}`)}},b=[{accessorKey:"remoteJid",header:()=>i.jsx("div",{className:"text-center",children:t("openai.sessions.table.remoteJid")}),cell:({row:w})=>i.jsx("div",{children:w.getValue("remoteJid")})},{accessorKey:"pushName",header:()=>i.jsx("div",{className:"text-center",children:t("openai.sessions.table.pushName")}),cell:({row:w})=>i.jsx("div",{children:w.getValue("pushName")})},{accessorKey:"sessionId",header:()=>i.jsx("div",{className:"text-center",children:t("openai.sessions.table.sessionId")}),cell:({row:w})=>i.jsx("div",{children:w.getValue("sessionId")})},{accessorKey:"status",header:()=>i.jsx("div",{className:"text-center",children:t("openai.sessions.table.status")}),cell:({row:w})=>i.jsx("div",{children:w.getValue("status")})},{id:"actions",enableHiding:!1,cell:({row:w})=>{const C=w.original;return i.jsxs(Kr,{children:[i.jsx(Wr,{asChild:!0,children:i.jsxs(se,{variant:"ghost",size:"icon",children:[i.jsx("span",{className:"sr-only",children:t("openai.sessions.table.actions.title")}),i.jsx(Pa,{className:"h-4 w-4"})]})}),i.jsxs(hr,{align:"end",children:[i.jsx(Ao,{children:t("openai.sessions.table.actions.title")}),i.jsx(Xs,{}),C.status!=="opened"&&i.jsxs(wt,{onClick:()=>x(C.remoteJid,"opened"),children:[i.jsx(Fi,{className:"mr-2 h-4 w-4"}),t("openai.sessions.table.actions.open")]}),C.status!=="paused"&&C.status!=="closed"&&i.jsxs(wt,{onClick:()=>x(C.remoteJid,"paused"),children:[i.jsx(Di,{className:"mr-2 h-4 w-4"}),t("openai.sessions.table.actions.pause")]}),C.status!=="closed"&&i.jsxs(wt,{onClick:()=>x(C.remoteJid,"closed"),children:[i.jsx(Oi,{className:"mr-2 h-4 w-4"}),t("openai.sessions.table.actions.close")]}),i.jsxs(wt,{onClick:()=>x(C.remoteJid,"delete"),children:[i.jsx(Ii,{className:"mr-2 h-4 w-4"}),t("openai.sessions.table.actions.delete")]})]})]})}}];return i.jsxs(Pt,{open:l,onOpenChange:u,children:[i.jsx(Bt,{asChild:!0,children:i.jsxs(se,{variant:"secondary",size:"sm",children:[i.jsx(Ai,{size:16,className:"mr-1"}),i.jsx("span",{className:"hidden md:inline",children:t("openai.sessions.label")})]})}),i.jsxs(Nt,{className:"overflow-y-auto sm:max-w-[950px]",onCloseAutoFocus:g,children:[i.jsx(Mt,{children:i.jsx(zt,{children:t("openai.sessions.label")})}),i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between gap-6 p-5",children:[i.jsx(ne,{placeholder:t("openai.sessions.search"),value:h,onChange:w=>m(w.target.value)}),i.jsx(se,{variant:"outline",onClick:g,size:"icon",children:i.jsx(Li,{size:16})})]}),i.jsx($a,{columns:b,data:d??[],onSortingChange:o,state:{sorting:s,globalFilter:h},onGlobalFilterChange:m,enableGlobalFilter:!0,noResultsMessage:t("openai.sessions.table.none")})]})]})]})}const wre=P.object({enabled:P.boolean(),description:P.string(),openaiCredsId:P.string(),botType:P.string(),assistantId:P.string().optional(),functionUrl:P.string().optional(),model:P.string().optional(),systemMessages:P.string().optional(),assistantMessages:P.string().optional(),userMessages:P.string().optional(),maxTokens:P.coerce.number().optional(),triggerType:P.string(),triggerOperator:P.string().optional(),triggerValue:P.string().optional(),expire:P.coerce.number().optional(),keywordFinish:P.string().optional(),delayMessage:P.coerce.number().optional(),unknownMessage:P.string().optional(),listeningFromMe:P.boolean().optional(),stopBotFromMe:P.boolean().optional(),keepOpen:P.boolean().optional(),debounceTime:P.coerce.number().optional(),splitMessages:P.boolean().optional(),timePerChar:P.coerce.number().optional()});function BI({initialData:e,onSubmit:t,handleDelete:n,openaiId:r,isModal:s=!1,isLoading:o=!1,openDeletionDialog:l=!1,setOpenDeletionDialog:u=()=>{},open:d}){const{t:f}=Ve(),{instance:h}=ct(),[m,g]=y.useState(!1),{data:x,refetch:b}=dw({instanceName:h?.name,enabled:d}),w=on({resolver:an(wre),defaultValues:e||{enabled:!0,description:"",openaiCredsId:"",botType:"assistant",assistantId:"",functionUrl:"",model:"",systemMessages:"",assistantMessages:"",userMessages:"",maxTokens:0,triggerType:"keyword",triggerOperator:"contains",triggerValue:"",expire:0,keywordFinish:"",delayMessage:0,unknownMessage:"",listeningFromMe:!1,stopBotFromMe:!1,keepOpen:!1,debounceTime:0,splitMessages:!1,timePerChar:0}}),C=w.watch("botType"),k=w.watch("triggerType"),j=w.watch("openaiCredsId"),{data:M,isLoading:_,refetch:R}=vre({instanceName:h?.name,openaiCredsId:j,token:h?.token,enabled:m&&!!j}),N=()=>{j&&(g(!0),R())},O=()=>{b()};return i.jsx(Gn,{...w,children:i.jsxs("form",{onSubmit:w.handleSubmit(t),className:"w-full space-y-6",children:[i.jsxs("div",{className:"space-y-4",children:[i.jsx(Pe,{name:"enabled",label:f("openai.form.enabled.label"),reverse:!0}),i.jsx(le,{name:"description",label:f("openai.form.description.label"),required:!0,children:i.jsx(ne,{})}),i.jsx("div",{className:"space-y-2",children:i.jsxs("div",{className:"flex items-end gap-2",children:[i.jsx("div",{className:"flex-1",children:i.jsx(Jt,{name:"openaiCredsId",label:f("openai.form.openaiCredsId.label"),required:!0,options:x?.filter(D=>!!D.id).map(D=>({label:D.name?D.name:D.apiKey.substring(0,15)+"...",value:D.id}))??[]})}),i.jsx(LI,{onCredentialsUpdate:O,showText:!1})]})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:f("openai.form.openaiSettings.label")}),i.jsx($t,{})]}),i.jsx(Jt,{name:"botType",label:f("openai.form.botType.label"),required:!0,options:[{label:f("openai.form.botType.assistant"),value:"assistant"},{label:f("openai.form.botType.chatCompletion"),value:"chatCompletion"}]}),C==="assistant"&&i.jsxs(i.Fragment,{children:[i.jsx(le,{name:"assistantId",label:f("openai.form.assistantId.label"),required:!0,children:i.jsx(ne,{})}),i.jsx(le,{name:"functionUrl",label:f("openai.form.functionUrl.label"),required:!0,children:i.jsx(ne,{})})]}),C==="chatCompletion"&&i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"space-y-2",children:i.jsxs("div",{className:"flex items-end gap-2",children:[i.jsx("div",{className:"flex-1",children:i.jsx(Jt,{name:"model",label:f("openai.form.model.label"),required:!0,disabled:!M||M.length===0,options:M?.map(D=>({label:D.id,value:D.id}))??[]})}),i.jsx(se,{type:"button",variant:"outline",size:"sm",disabled:!j||_,onClick:N,className:"mb-2",children:_?i.jsxs(i.Fragment,{children:[i.jsx(Ip,{className:"mr-2 h-4 w-4 animate-spin"}),f("openai.button.loading")]}):i.jsxs(i.Fragment,{children:[i.jsx(Ip,{className:"mr-2 h-4 w-4"}),f("openai.button.loadModels")]})})]})}),i.jsx(le,{name:"systemMessages",label:f("openai.form.systemMessages.label"),children:i.jsx(bi,{})}),i.jsx(le,{name:"assistantMessages",label:f("openai.form.assistantMessages.label"),children:i.jsx(bi,{})}),i.jsx(le,{name:"userMessages",label:f("openai.form.userMessages.label"),children:i.jsx(bi,{})}),i.jsx(le,{name:"maxTokens",label:f("openai.form.maxTokens.label"),children:i.jsx(ne,{type:"number"})})]}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:f("openai.form.triggerSettings.label")}),i.jsx($t,{})]}),i.jsx(Jt,{name:"triggerType",label:f("openai.form.triggerType.label"),required:!0,options:[{label:f("openai.form.triggerType.keyword"),value:"keyword"},{label:f("openai.form.triggerType.all"),value:"all"},{label:f("openai.form.triggerType.advanced"),value:"advanced"},{label:f("openai.form.triggerType.none"),value:"none"}]}),k==="keyword"&&i.jsxs(i.Fragment,{children:[i.jsx(Jt,{name:"triggerOperator",label:f("openai.form.triggerOperator.label"),required:!0,options:[{label:f("openai.form.triggerOperator.contains"),value:"contains"},{label:f("openai.form.triggerOperator.equals"),value:"equals"},{label:f("openai.form.triggerOperator.startsWith"),value:"startsWith"},{label:f("openai.form.triggerOperator.endsWith"),value:"endsWith"},{label:f("openai.form.triggerOperator.regex"),value:"regex"}]}),i.jsx(le,{name:"triggerValue",label:f("openai.form.triggerValue.label"),required:!0,children:i.jsx(ne,{})})]}),k==="advanced"&&i.jsx(le,{name:"triggerValue",label:f("openai.form.triggerConditions.label"),required:!0,children:i.jsx(ne,{})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:f("openai.form.generalSettings.label")}),i.jsx($t,{})]}),i.jsx(le,{name:"expire",label:f("openai.form.expire.label"),children:i.jsx(ne,{type:"number"})}),i.jsx(le,{name:"keywordFinish",label:f("openai.form.keywordFinish.label"),children:i.jsx(ne,{})}),i.jsx(le,{name:"delayMessage",label:f("openai.form.delayMessage.label"),children:i.jsx(ne,{type:"number"})}),i.jsx(le,{name:"unknownMessage",label:f("openai.form.unknownMessage.label"),children:i.jsx(ne,{})}),i.jsx(Pe,{name:"listeningFromMe",label:f("openai.form.listeningFromMe.label"),reverse:!0}),i.jsx(Pe,{name:"stopBotFromMe",label:f("openai.form.stopBotFromMe.label"),reverse:!0}),i.jsx(Pe,{name:"keepOpen",label:f("openai.form.keepOpen.label"),reverse:!0}),i.jsx(le,{name:"debounceTime",label:f("openai.form.debounceTime.label"),children:i.jsx(ne,{type:"number"})}),i.jsx(Pe,{name:"splitMessages",label:f("openai.form.splitMessages.label"),reverse:!0}),w.watch("splitMessages")&&i.jsx(le,{name:"timePerChar",label:f("openai.form.timePerChar.label"),children:i.jsx(ne,{type:"number"})})]}),s&&i.jsx(Yt,{children:i.jsx(se,{disabled:o,type:"submit",children:f(o?"openai.button.saving":"openai.button.save")})}),!s&&i.jsxs("div",{children:[i.jsx($I,{openaiId:r}),i.jsxs("div",{className:"mt-5 flex items-center gap-3",children:[i.jsxs(Pt,{open:l,onOpenChange:u,children:[i.jsx(Bt,{asChild:!0,children:i.jsx(se,{variant:"destructive",size:"sm",children:f("dify.button.delete")})}),i.jsx(Nt,{children:i.jsxs(Mt,{children:[i.jsx(zt,{children:f("modal.delete.title")}),i.jsx(eo,{children:f("modal.delete.messageSingle")}),i.jsxs(Yt,{children:[i.jsx(se,{size:"sm",variant:"outline",onClick:()=>u(!1),children:f("button.cancel")}),i.jsx(se,{variant:"destructive",onClick:n,children:f("button.delete")})]})]})})]}),i.jsx(se,{disabled:o,type:"submit",children:f(o?"openai.button.saving":"openai.button.update")})]})]})]})})}function Sre({resetTable:e}){const{t}=Ve(),{instance:n}=ct(),{createOpenai:r}=Md(),[s,o]=y.useState(!1),[l,u]=y.useState(!1),d=async f=>{try{if(!n||!n.name)throw new Error("instance not found");o(!0);const h={enabled:f.enabled,description:f.description,openaiCredsId:f.openaiCredsId,botType:f.botType,assistantId:f.assistantId||"",functionUrl:f.functionUrl||"",model:f.model||"",systemMessages:[f.systemMessages||""],assistantMessages:[f.assistantMessages||""],userMessages:[f.userMessages||""],maxTokens:f.maxTokens||0,triggerType:f.triggerType,triggerOperator:f.triggerOperator||"",triggerValue:f.triggerValue||"",expire:f.expire||0,keywordFinish:f.keywordFinish||"",delayMessage:f.delayMessage||0,unknownMessage:f.unknownMessage||"",listeningFromMe:f.listeningFromMe||!1,stopBotFromMe:f.stopBotFromMe||!1,keepOpen:f.keepOpen||!1,debounceTime:f.debounceTime||0,splitMessages:f.splitMessages||!1,timePerChar:f.timePerChar||0};await r({instanceName:n.name,token:n.token,data:h}),me.success(t("openai.toast.success.create")),u(!1),e()}catch(h){console.error("Error:",h),me.error(`Error: ${h?.response?.data?.response?.message}`)}finally{o(!1)}};return i.jsxs(Pt,{open:l,onOpenChange:u,children:[i.jsx(Bt,{asChild:!0,children:i.jsxs(se,{size:"sm",children:[i.jsx(cs,{size:16,className:"mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:t("openai.button.create")})]})}),i.jsxs(Nt,{className:"overflow-y-auto sm:max-h-[600px] sm:max-w-[740px]",children:[i.jsx(Mt,{children:i.jsx(zt,{children:t("openai.form.title")})}),i.jsx(BI,{onSubmit:d,isModal:!0,isLoading:s,open:l})]})]})}const Cre=e=>["openai","getOpenai",JSON.stringify(e)],Ere=async({instanceName:e,token:t,openaiId:n})=>{const r=await Ee.get(`/openai/fetch/${n}/${e}`,{headers:{apiKey:t}});return Array.isArray(r.data)?r.data[0]:r.data},kre=e=>{const{instanceName:t,token:n,openaiId:r,...s}=e;return mt({...s,queryKey:Cre({instanceName:t}),queryFn:()=>Ere({instanceName:t,token:n,openaiId:r}),enabled:!!t&&!!r&&(e.enabled??!0)})};function jre({openaiId:e,resetTable:t}){const{t:n}=Ve(),{instance:r}=ct(),s=dn(),[o,l]=y.useState(!1),{deleteOpenai:u,updateOpenai:d}=Md(),{data:f,isLoading:h}=kre({instanceName:r?.name,openaiId:e}),m=y.useMemo(()=>({enabled:f?.enabled??!0,description:f?.description??"",openaiCredsId:f?.openaiCredsId??"",botType:f?.botType??"",assistantId:f?.assistantId||"",functionUrl:f?.functionUrl||"",model:f?.model||"",systemMessages:Array.isArray(f?.systemMessages)?f?.systemMessages.join(", "):f?.systemMessages||"",assistantMessages:Array.isArray(f?.assistantMessages)?f?.assistantMessages.join(", "):f?.assistantMessages||"",userMessages:Array.isArray(f?.userMessages)?f?.userMessages.join(", "):f?.userMessages||"",maxTokens:f?.maxTokens||0,triggerType:f?.triggerType||"",triggerOperator:f?.triggerOperator||"",triggerValue:f?.triggerValue,expire:f?.expire||0,keywordFinish:f?.keywordFinish,delayMessage:f?.delayMessage||0,unknownMessage:f?.unknownMessage,listeningFromMe:f?.listeningFromMe,stopBotFromMe:f?.stopBotFromMe,keepOpen:f?.keepOpen,debounceTime:f?.debounceTime||0,splitMessages:f?.splitMessages||!1,timePerChar:f?.timePerChar||0}),[f?.assistantId,f?.assistantMessages,f?.botType,f?.debounceTime,f?.delayMessage,f?.description,f?.enabled,f?.expire,f?.functionUrl,f?.keepOpen,f?.keywordFinish,f?.listeningFromMe,f?.maxTokens,f?.model,f?.openaiCredsId,f?.stopBotFromMe,f?.systemMessages,f?.triggerOperator,f?.triggerType,f?.triggerValue,f?.unknownMessage,f?.userMessages,f?.splitMessages,f?.timePerChar]),g=async b=>{try{if(r&&r.name&&e){const w={enabled:b.enabled,description:b.description,openaiCredsId:b.openaiCredsId,botType:b.botType,assistantId:b.assistantId||"",functionUrl:b.functionUrl||"",model:b.model||"",systemMessages:[b.systemMessages||""],assistantMessages:[b.assistantMessages||""],userMessages:[b.userMessages||""],maxTokens:b.maxTokens||0,triggerType:b.triggerType,triggerOperator:b.triggerOperator||"",triggerValue:b.triggerValue||"",expire:b.expire||0,keywordFinish:b.keywordFinish||"",delayMessage:b.delayMessage||1e3,unknownMessage:b.unknownMessage||"",listeningFromMe:b.listeningFromMe||!1,stopBotFromMe:b.stopBotFromMe||!1,keepOpen:b.keepOpen||!1,debounceTime:b.debounceTime||0,splitMessages:b.splitMessages||!1,timePerChar:b.timePerChar||0};await d({instanceName:r.name,openaiId:e,data:w}),me.success(n("openai.toast.success.update")),t(),s(`/manager/instance/${r.id}/openai/${e}`)}else console.error("Token not found")}catch(w){console.error("Error:",w),me.error(`Error: ${w?.response?.data?.response?.message}`)}},x=async()=>{try{r&&r.name&&e?(await u({instanceName:r.name,openaiId:e}),me.success(n("openai.toast.success.delete")),l(!1),t(),s(`/manager/instance/${r.id}/openai`)):console.error("instance not found")}catch(b){console.error("Erro ao excluir dify:",b)}};return h?i.jsx(On,{}):i.jsx("div",{className:"m-4",children:i.jsx(BI,{initialData:m,onSubmit:g,openaiId:e,handleDelete:x,isModal:!1,isLoading:h,openDeletionDialog:o,setOpenDeletionDialog:l})})}function Tk(){const{t:e}=Ve(),t=zo("(min-width: 768px)"),{instance:n}=ct(),{botId:r}=ls(),{data:s,isLoading:o,refetch:l}=FI({instanceName:n?.name}),u=dn(),d=h=>{n&&u(`/manager/instance/${n.id}/openai/${h}`)},f=()=>{l()};return i.jsxs("main",{className:"pt-5",children:[i.jsxs("div",{className:"mb-1 flex items-center justify-between",children:[i.jsx("h3",{className:"text-lg font-medium",children:e("openai.title")}),i.jsxs("div",{className:"flex items-center justify-end gap-2",children:[i.jsx($I,{}),i.jsx(hre,{}),i.jsx(LI,{}),i.jsx(Sre,{resetTable:f})]})]}),i.jsx($t,{className:"my-4"}),i.jsxs($o,{direction:t?"horizontal":"vertical",children:[i.jsx(Hn,{defaultSize:35,className:"pr-4",children:i.jsx("div",{className:"flex flex-col gap-3",children:o?i.jsx(On,{}):i.jsx(i.Fragment,{children:s&&s.length>0&&Array.isArray(s)?s.map(h=>i.jsxs(se,{className:"flex h-auto flex-col items-start justify-start",onClick:()=>d(`${h.id}`),variant:r===h.id?"secondary":"outline",children:[i.jsx("h4",{className:"text-base",children:h.description||h.id}),i.jsx("p",{className:"text-sm font-normal text-muted-foreground",children:h.botType})]},h.id)):i.jsx(se,{variant:"link",children:e("openai.table.none")})})})}),r&&i.jsxs(i.Fragment,{children:[i.jsx(Bo,{withHandle:!0,className:"border border-border"}),i.jsx(Hn,{children:i.jsx(jre,{openaiId:r,resetTable:f})})]})]})]})}const Tre=e=>["proxy","fetchProxy",JSON.stringify(e)],Nre=async({instanceName:e,token:t})=>(await Ee.get(`/proxy/find/${e}`,{headers:{apiKey:t}})).data,Mre=e=>{const{instanceName:t,token:n,...r}=e;return mt({...r,queryKey:Tre({instanceName:t,token:n}),queryFn:()=>Nre({instanceName:t,token:n}),enabled:!!t})},_re=async({instanceName:e,token:t,data:n})=>(await Ee.post(`/proxy/set/${e}`,n,{headers:{apikey:t}})).data;function Rre(){return{createProxy:nt(_re,{invalidateKeys:[["proxy","fetchProxy"]]})}}const Pre=P.object({enabled:P.boolean(),host:P.string(),port:P.string(),protocol:P.string(),username:P.string(),password:P.string()});function Ore(){const{t:e}=Ve(),{instance:t}=ct(),[n,r]=y.useState(!1),{createProxy:s}=Rre(),{data:o}=Mre({instanceName:t?.name}),l=on({resolver:an(Pre),defaultValues:{enabled:!1,host:"",port:"",protocol:"http",username:"",password:""}});y.useEffect(()=>{o&&l.reset({enabled:o.enabled,host:o.host,port:o.port,protocol:o.protocol,username:o.username,password:o.password})},[o]);const u=async d=>{if(t){r(!0);try{const f={enabled:d.enabled,host:d.host,port:d.port,protocol:d.protocol,username:d.username,password:d.password};await s({instanceName:t.name,token:t.token,data:f}),me.success(e("proxy.toast.success"))}catch(f){console.error(e("proxy.toast.error"),f),me.error(`Error : ${f?.response?.data?.response?.message}`)}finally{r(!1)}}};return i.jsx(i.Fragment,{children:i.jsx(Fo,{...l,children:i.jsx("form",{onSubmit:l.handleSubmit(u),className:"w-full space-y-6",children:i.jsxs("div",{children:[i.jsx("h3",{className:"mb-1 text-lg font-medium",children:e("proxy.title")}),i.jsx(Oa,{className:"my-4"}),i.jsxs("div",{className:"mx-4 space-y-2 divide-y [&>*]:p-4",children:[i.jsx(Pe,{name:"enabled",label:e("proxy.form.enabled.label"),className:"w-full justify-between",helper:e("proxy.form.enabled.description")}),i.jsxs("div",{className:"grid gap-4 sm:grid-cols-[10rem_1fr_10rem] md:gap-8",children:[i.jsx(le,{name:"protocol",label:e("proxy.form.protocol.label"),children:i.jsx(ne,{})}),i.jsx(le,{name:"host",label:e("proxy.form.host.label"),children:i.jsx(ne,{})}),i.jsx(le,{name:"port",label:e("proxy.form.port.label"),children:i.jsx(ne,{type:"number"})})]}),i.jsxs("div",{className:"grid gap-4 sm:grid-cols-2 md:gap-8",children:[i.jsx(le,{name:"username",label:e("proxy.form.username.label"),children:i.jsx(ne,{})}),i.jsx(le,{name:"password",label:e("proxy.form.password.label"),children:i.jsx(ne,{type:"password"})})]}),i.jsx("div",{className:"flex justify-end px-4 pt-6",children:i.jsx(se,{type:"submit",disabled:n,children:e(n?"proxy.button.saving":"proxy.button.save")})})]})]})})})})}const Ire=e=>["rabbitmq","fetchRabbitmq",JSON.stringify(e)],Are=async({instanceName:e,token:t})=>(await Ee.get(`/rabbitmq/find/${e}`,{headers:{apiKey:t}})).data,Dre=e=>{const{instanceName:t,token:n,...r}=e;return mt({...r,queryKey:Ire({instanceName:t,token:n}),queryFn:()=>Are({instanceName:t,token:n}),enabled:!!t})},Fre=async({instanceName:e,token:t,data:n})=>(await Ee.post(`/rabbitmq/set/${e}`,{rabbitmq:n},{headers:{apikey:t}})).data;function Lre(){return{createRabbitmq:nt(Fre,{invalidateKeys:[["rabbitmq","fetchRabbitmq"]]})}}const $re=P.object({enabled:P.boolean(),events:P.array(P.string())});function Bre(){const{t:e}=Ve(),{instance:t}=ct(),[n,r]=y.useState(!1),{createRabbitmq:s}=Lre(),{data:o}=Dre({instanceName:t?.name,token:t?.token}),l=on({resolver:an($re),defaultValues:{enabled:!1,events:[]}});y.useEffect(()=>{o&&l.reset({enabled:o.enabled,events:o.events})},[o]);const u=async m=>{if(t){r(!0);try{const g={enabled:m.enabled,events:m.events};await s({instanceName:t.name,token:t.token,data:g}),me.success(e("rabbitmq.toast.success"))}catch(g){console.error(e("rabbitmq.toast.error"),g),me.error(`Error: ${g?.response?.data?.response?.message}`)}finally{r(!1)}}},d=["APPLICATION_STARTUP","QRCODE_UPDATED","MESSAGES_SET","MESSAGES_UPSERT","MESSAGES_UPDATE","MESSAGES_DELETE","SEND_MESSAGE","CONTACTS_SET","CONTACTS_UPSERT","CONTACTS_UPDATE","PRESENCE_UPDATE","CHATS_SET","CHATS_UPSERT","CHATS_UPDATE","CHATS_DELETE","GROUPS_UPSERT","GROUP_UPDATE","GROUP_PARTICIPANTS_UPDATE","CONNECTION_UPDATE","REMOVE_INSTANCE","LOGOUT_INSTANCE","LABELS_EDIT","LABELS_ASSOCIATION","CALL","TYPEBOT_START","TYPEBOT_CHANGE_STATUS"],f=()=>{l.setValue("events",d)},h=()=>{l.setValue("events",[])};return i.jsx(i.Fragment,{children:i.jsx(Fo,{...l,children:i.jsx("form",{onSubmit:l.handleSubmit(u),className:"w-full space-y-6",children:i.jsxs("div",{children:[i.jsx("h3",{className:"mb-1 text-lg font-medium",children:e("rabbitmq.title")}),i.jsx(Oa,{className:"my-4"}),i.jsxs("div",{className:"mx-4 space-y-2 divide-y [&>*]:p-4",children:[i.jsx(Pe,{name:"enabled",label:e("rabbitmq.form.enabled.label"),className:"w-full justify-between",helper:e("rabbitmq.form.enabled.description")}),i.jsxs("div",{className:"mb-4 flex justify-between",children:[i.jsx(se,{variant:"outline",type:"button",onClick:f,children:e("button.markAll")}),i.jsx(se,{variant:"outline",type:"button",onClick:h,children:e("button.unMarkAll")})]}),i.jsx(Lo,{control:l.control,name:"events",render:({field:m})=>i.jsxs(no,{className:"flex flex-col",children:[i.jsx(Nr,{className:"my-2 text-lg",children:e("rabbitmq.form.events.label")}),i.jsx(_s,{children:i.jsx("div",{className:"flex flex-col gap-2 space-y-1 divide-y",children:d.sort((g,x)=>g.localeCompare(x)).map(g=>i.jsxs("div",{className:"flex items-center justify-between gap-3 pt-3",children:[i.jsx(Nr,{className:Ie("break-all",m.value.includes(g)?"text-foreground":"text-muted-foreground"),children:g}),i.jsx(gc,{checked:m.value.includes(g),onCheckedChange:x=>{x?m.onChange([...m.value,g]):m.onChange(m.value.filter(b=>b!==g))}})]},g))})})]})})]}),i.jsx("div",{className:"mx-4 flex justify-end pt-6",children:i.jsx(se,{type:"submit",disabled:n,children:e(n?"rabbitmq.button.saving":"rabbitmq.button.save")})})]})})})})}const zre=e=>["instance","fetchSettings",JSON.stringify(e)],Ure=async({instanceName:e,token:t})=>(await Ee.get(`/settings/find/${e}`,{headers:{apikey:t}})).data,Vre=e=>{const{instanceName:t,token:n,...r}=e;return mt({...r,queryKey:zre({instanceName:t,token:n}),queryFn:()=>Ure({instanceName:t,token:n}),enabled:!!t})},Hre=P.object({rejectCall:P.boolean(),msgCall:P.string().optional(),groupsIgnore:P.boolean(),alwaysOnline:P.boolean(),readMessages:P.boolean(),syncFullHistory:P.boolean(),readStatus:P.boolean()});function qre(){const{t:e}=Ve(),[t,n]=y.useState(!1),{instance:r}=ct(),{updateSettings:s}=Hh(),{data:o,isLoading:l}=Vre({instanceName:r?.name,token:r?.token}),u=on({resolver:an(Hre),defaultValues:{rejectCall:!1,msgCall:"",groupsIgnore:!1,alwaysOnline:!1,readMessages:!1,syncFullHistory:!1,readStatus:!1}});y.useEffect(()=>{o&&u.reset({rejectCall:o.rejectCall,msgCall:o.msgCall||"",groupsIgnore:o.groupsIgnore,alwaysOnline:o.alwaysOnline,readMessages:o.readMessages,syncFullHistory:o.syncFullHistory,readStatus:o.readStatus})},[u,o]);const d=async m=>{try{if(!r||!r.name)throw new Error("instance not found");n(!0);const g={rejectCall:m.rejectCall,msgCall:m.msgCall,groupsIgnore:m.groupsIgnore,alwaysOnline:m.alwaysOnline,readMessages:m.readMessages,syncFullHistory:m.syncFullHistory,readStatus:m.readStatus};await s({instanceName:r.name,token:r.token,data:g}),me.success(e("settings.toast.success"))}catch(g){console.error(e("settings.toast.success"),g),me.error(e("settings.toast.error"))}finally{n(!1)}},f=[{name:"groupsIgnore",label:e("settings.form.groupsIgnore.label"),description:e("settings.form.groupsIgnore.description")},{name:"alwaysOnline",label:e("settings.form.alwaysOnline.label"),description:e("settings.form.alwaysOnline.description")},{name:"readMessages",label:e("settings.form.readMessages.label"),description:e("settings.form.readMessages.description")},{name:"syncFullHistory",label:e("settings.form.syncFullHistory.label"),description:e("settings.form.syncFullHistory.description")},{name:"readStatus",label:e("settings.form.readStatus.label"),description:e("settings.form.readStatus.description")}],h=u.watch("rejectCall");return l?i.jsx(On,{}):i.jsx(i.Fragment,{children:i.jsx(Fo,{...u,children:i.jsx("form",{onSubmit:u.handleSubmit(d),className:"w-full space-y-6",children:i.jsxs("div",{children:[i.jsx("h3",{className:"mb-1 text-lg font-medium",children:e("settings.title")}),i.jsx($t,{className:"my-4"}),i.jsxs("div",{className:"mx-4 space-y-2 divide-y",children:[i.jsxs("div",{className:"flex flex-col p-4",children:[i.jsx(Pe,{name:"rejectCall",label:e("settings.form.rejectCall.label"),className:"w-full justify-between",helper:e("settings.form.rejectCall.description")}),h&&i.jsx("div",{className:"mr-16 mt-2",children:i.jsx(le,{name:"msgCall",children:i.jsx(bi,{placeholder:e("settings.form.msgCall.description")})})})]}),f.map(m=>i.jsx("div",{className:"flex p-4",children:i.jsx(Pe,{name:m.name,label:m.label,className:"w-full justify-between",helper:m.description})},m.name)),i.jsx("div",{className:"flex justify-end pt-6",children:i.jsx(se,{type:"submit",disabled:t,children:e(t?"settings.button.saving":"settings.button.save")})})]})]})})})})}const Kre=e=>["sqs","fetchSqs",JSON.stringify(e)],Wre=async({instanceName:e,token:t})=>(await Ee.get(`/sqs/find/${e}`,{headers:{apiKey:t}})).data,Gre=e=>{const{instanceName:t,token:n,...r}=e;return mt({...r,queryKey:Kre({instanceName:t,token:n}),queryFn:()=>Wre({instanceName:t,token:n}),enabled:!!t})},Jre=async({instanceName:e,token:t,data:n})=>(await Ee.post(`/sqs/set/${e}`,{sqs:n},{headers:{apikey:t}})).data;function Qre(){return{createSqs:nt(Jre,{invalidateKeys:[["sqs","fetchSqs"]]})}}const Zre=P.object({enabled:P.boolean(),events:P.array(P.string())});function Yre(){const{t:e}=Ve(),{instance:t}=ct(),[n,r]=y.useState(!1),{createSqs:s}=Qre(),{data:o}=Gre({instanceName:t?.name,token:t?.token}),l=on({resolver:an(Zre),defaultValues:{enabled:!1,events:[]}});y.useEffect(()=>{o&&l.reset({enabled:o.enabled,events:o.events})},[o]);const u=async m=>{if(t){r(!0);try{const g={enabled:m.enabled,events:m.events};await s({instanceName:t.name,token:t.token,data:g}),me.success(e("sqs.toast.success"))}catch(g){console.error(e("sqs.toast.error"),g),me.error(`Error: ${g?.response?.data?.response?.message}`)}finally{r(!1)}}},d=["APPLICATION_STARTUP","QRCODE_UPDATED","MESSAGES_SET","MESSAGES_UPSERT","MESSAGES_UPDATE","MESSAGES_DELETE","SEND_MESSAGE","CONTACTS_SET","CONTACTS_UPSERT","CONTACTS_UPDATE","PRESENCE_UPDATE","CHATS_SET","CHATS_UPSERT","CHATS_UPDATE","CHATS_DELETE","GROUPS_UPSERT","GROUP_UPDATE","GROUP_PARTICIPANTS_UPDATE","CONNECTION_UPDATE","REMOVE_INSTANCE","LOGOUT_INSTANCE","LABELS_EDIT","LABELS_ASSOCIATION","CALL","TYPEBOT_START","TYPEBOT_CHANGE_STATUS"],f=()=>{l.setValue("events",d)},h=()=>{l.setValue("events",[])};return i.jsx(i.Fragment,{children:i.jsx(Fo,{...l,children:i.jsx("form",{onSubmit:l.handleSubmit(u),className:"w-full space-y-6",children:i.jsxs("div",{children:[i.jsx("h3",{className:"mb-1 text-lg font-medium",children:e("sqs.title")}),i.jsx(Oa,{className:"my-4"}),i.jsxs("div",{className:"mx-4 space-y-2 divide-y [&>*]:p-4",children:[i.jsx(Pe,{name:"enabled",label:e("sqs.form.enabled.label"),className:"w-full justify-between",helper:e("sqs.form.enabled.description")}),i.jsxs("div",{className:"mb-4 flex justify-between",children:[i.jsx(se,{variant:"outline",type:"button",onClick:f,children:e("button.markAll")}),i.jsx(se,{variant:"outline",type:"button",onClick:h,children:e("button.unMarkAll")})]}),i.jsx(Lo,{control:l.control,name:"events",render:({field:m})=>i.jsxs(no,{className:"flex flex-col",children:[i.jsx(Nr,{className:"my-2 text-lg",children:e("sqs.form.events.label")}),i.jsx(_s,{children:i.jsx("div",{className:"flex flex-col gap-2 space-y-1 divide-y",children:d.sort((g,x)=>g.localeCompare(x)).map(g=>i.jsxs("div",{className:"flex items-center justify-between gap-3 pt-3",children:[i.jsx(Nr,{className:Ie("break-all",m.value.includes(g)?"text-foreground":"text-muted-foreground"),children:g}),i.jsx(gc,{checked:m.value.includes(g),onCheckedChange:x=>{x?m.onChange([...m.value,g]):m.onChange(m.value.filter(b=>b!==g))}})]},g))})})]})})]}),i.jsx("div",{className:"mx-4 flex justify-end pt-6",children:i.jsx(se,{type:"submit",disabled:n,children:e(n?"sqs.button.saving":"sqs.button.save")})})]})})})})}const Xre=e=>["typebot","findTypebot",JSON.stringify(e)],ese=async({instanceName:e,token:t})=>(await Ee.get(`/typebot/find/${e}`,{headers:{apiKey:t}})).data,zI=e=>{const{instanceName:t,token:n,...r}=e;return mt({...r,queryKey:Xre({instanceName:t}),queryFn:()=>ese({instanceName:t,token:n}),enabled:!!t&&(e.enabled??!0)})},tse=e=>["typebot","fetchDefaultSettings",JSON.stringify(e)],nse=async({instanceName:e,token:t})=>{const n=await Ee.get(`/typebot/fetchSettings/${e}`,{headers:{apiKey:t}});return Array.isArray(n.data)?n.data[0]:n.data},rse=e=>{const{instanceName:t,token:n,...r}=e;return mt({...r,queryKey:tse({instanceName:t}),queryFn:()=>nse({instanceName:t,token:n}),enabled:!!t&&(e.enabled??!0)})},sse=async({instanceName:e,token:t,data:n})=>(await Ee.post(`/typebot/create/${e}`,n,{headers:{apikey:t}})).data,ose=async({instanceName:e,token:t,typebotId:n,data:r})=>(await Ee.put(`/typebot/update/${n}/${e}`,r,{headers:{apikey:t}})).data,ase=async({instanceName:e,typebotId:t})=>(await Ee.delete(`/typebot/delete/${t}/${e}`)).data,ise=async({instanceName:e,token:t,data:n})=>(await Ee.post(`/typebot/settings/${e}`,n,{headers:{apikey:t}})).data,lse=async({instanceName:e,token:t,remoteJid:n,status:r})=>(await Ee.post(`/typebot/changeStatus/${e}`,{remoteJid:n,status:r},{headers:{apikey:t}})).data;function Eg(){const e=nt(ise,{invalidateKeys:[["typebot","fetchDefaultSettings"]]}),t=nt(lse,{invalidateKeys:[["typebot","getTypebot"],["typebot","fetchSessions"]]}),n=nt(ase,{invalidateKeys:[["typebot","getTypebot"],["typebot","findTypebot"],["typebot","fetchSessions"]]}),r=nt(ose,{invalidateKeys:[["typebot","getTypebot"],["typebot","findTypebot"],["typebot","fetchSessions"]]}),s=nt(sse,{invalidateKeys:[["typebot","findTypebot"]]});return{setDefaultSettingsTypebot:e,changeStatusTypebot:t,deleteTypebot:n,updateTypebot:r,createTypebot:s}}const cse=P.object({expire:P.coerce.number(),keywordFinish:P.string(),delayMessage:P.coerce.number(),unknownMessage:P.string(),listeningFromMe:P.boolean(),stopBotFromMe:P.boolean(),keepOpen:P.boolean(),debounceTime:P.coerce.number()});function use(){const{t:e}=Ve(),{instance:t}=ct(),[n,r]=y.useState(!1),{setDefaultSettingsTypebot:s}=Eg(),{data:o,refetch:l}=rse({instanceName:t?.name,token:t?.token,enabled:n}),{data:u,refetch:d}=zI({instanceName:t?.name,token:t?.token,enabled:n}),f=on({resolver:an(cse),defaultValues:{expire:0,keywordFinish:e("typebot.form.examples.keywordFinish"),delayMessage:1e3,unknownMessage:e("typebot.form.examples.unknownMessage"),listeningFromMe:!1,stopBotFromMe:!1,keepOpen:!1,debounceTime:0}});y.useEffect(()=>{o&&f.reset({expire:o?.expire??0,keywordFinish:o.keywordFinish,delayMessage:o.delayMessage??0,unknownMessage:o.unknownMessage,listeningFromMe:o.listeningFromMe,stopBotFromMe:o.stopBotFromMe,keepOpen:o.keepOpen,debounceTime:o.debounceTime??0})},[o]);const h=async g=>{try{if(!t||!t.name)throw new Error("instance not found.");const x={expire:g.expire,keywordFinish:g.keywordFinish,delayMessage:g.delayMessage,unknownMessage:g.unknownMessage,listeningFromMe:g.listeningFromMe,stopBotFromMe:g.stopBotFromMe,keepOpen:g.keepOpen,debounceTime:g.debounceTime};await s({instanceName:t.name,token:t.token,data:x}),me.success(e("typebot.toast.defaultSettings.success"))}catch(x){console.error(e("typebot.toast.defaultSettings.error"),x),me.error(`Error: ${x?.response?.data?.response?.message}`)}};function m(){l(),d()}return i.jsxs(Pt,{open:n,onOpenChange:r,children:[i.jsx(Bt,{asChild:!0,children:i.jsxs(se,{variant:"secondary",size:"sm",children:[i.jsx(Oo,{size:16,className:"mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:e("typebot.button.defaultSettings")})]})}),i.jsxs(Nt,{className:"overflow-y-auto sm:max-h-[600px] sm:max-w-[740px]",onCloseAutoFocus:m,children:[i.jsx(Mt,{children:i.jsx(zt,{children:e("typebot.modal.defaultSettings.title")})}),i.jsx(Gn,{...f,children:i.jsxs("form",{className:"w-full space-y-6",onSubmit:f.handleSubmit(h),children:[i.jsx("div",{children:i.jsxs("div",{className:"space-y-4",children:[i.jsx(Jt,{name:"typebotIdFallback",label:e("typebot.form.typebotIdFallback.label"),options:u?.filter(g=>!!g.id).map(g=>({label:g.typebot,value:g.description}))??[]}),i.jsx(le,{name:"expire",label:e("typebot.form.expire.label"),children:i.jsx(ne,{type:"number"})}),i.jsx(le,{name:"keywordFinish",label:e("typebot.form.keywordFinish.label"),children:i.jsx(ne,{})}),i.jsx(le,{name:"delayMessage",label:e("typebot.form.delayMessage.label"),children:i.jsx(ne,{type:"number"})}),i.jsx(le,{name:"unknownMessage",label:e("typebot.form.unknownMessage.label"),children:i.jsx(ne,{})}),i.jsx(Pe,{name:"listeningFromMe",label:e("typebot.form.listeningFromMe.label"),reverse:!0}),i.jsx(Pe,{name:"stopBotFromMe",label:e("typebot.form.stopBotFromMe.label"),reverse:!0}),i.jsx(Pe,{name:"keepOpen",label:e("typebot.form.keepOpen.label"),reverse:!0}),i.jsx(le,{name:"debounceTime",label:e("typebot.form.debounceTime.label"),children:i.jsx(ne,{type:"number"})}),i.jsx(Da,{name:"ignoreJids",label:e("typebot.form.ignoreJids.label"),placeholder:e("typebot.form.ignoreJids.placeholder")})]})}),i.jsx(Yt,{children:i.jsx(se,{type:"submit",children:e("typebot.button.save")})})]})})]})]})}const dse=e=>["typebot","fetchSessions",JSON.stringify(e)],fse=async({instanceName:e,typebotId:t,token:n})=>(await Ee.get(`/typebot/fetchSessions/${t}/${e}`,{headers:{apiKey:n}})).data,pse=e=>{const{instanceName:t,token:n,typebotId:r,...s}=e;return mt({...s,queryKey:dse({instanceName:t}),queryFn:()=>fse({instanceName:t,token:n,typebotId:r}),enabled:!!t&&!!r&&(e.enabled??!0)})};function UI({typebotId:e}){const{t}=Ve(),{instance:n}=ct(),[r,s]=y.useState([]),[o,l]=y.useState(!1),[u,d]=y.useState(""),{changeStatusTypebot:f}=Eg(),{data:h,refetch:m}=pse({instanceName:n?.name,token:n?.token,typebotId:e});function g(){m()}const x=async(w,C)=>{try{if(!n)return;await f({instanceName:n.name,token:n.token,remoteJid:w,status:C}),me.success(t("typebot.toast.success.status")),g()}catch(k){console.error("Error:",k),me.error(`Error : ${k?.response?.data?.response?.message}`)}},b=[{accessorKey:"remoteJid",header:()=>i.jsx("div",{className:"text-center",children:t("typebot.sessions.table.remoteJid")}),cell:({row:w})=>i.jsx("div",{children:w.getValue("remoteJid")})},{accessorKey:"pushName",header:()=>i.jsx("div",{className:"text-center",children:t("typebot.sessions.table.pushName")}),cell:({row:w})=>i.jsx("div",{children:w.getValue("pushName")})},{accessorKey:"sessionId",header:()=>i.jsx("div",{className:"text-center",children:t("typebot.sessions.table.sessionId")}),cell:({row:w})=>i.jsx("div",{children:w.getValue("sessionId")})},{accessorKey:"status",header:()=>i.jsx("div",{className:"text-center",children:t("typebot.sessions.table.status")}),cell:({row:w})=>i.jsx("div",{children:w.getValue("status")})},{id:"actions",enableHiding:!1,cell:({row:w})=>{const C=w.original;return i.jsxs(Kr,{children:[i.jsx(Wr,{asChild:!0,children:i.jsxs(se,{variant:"ghost",className:"h-8 w-8 p-0",children:[i.jsx("span",{className:"sr-only",children:t("typebot.sessions.table.actions.title")}),i.jsx(Pa,{className:"h-4 w-4"})]})}),i.jsxs(hr,{align:"end",children:[i.jsx(Ao,{children:"Actions"}),i.jsx(Xs,{}),C.status!=="opened"&&i.jsxs(wt,{onClick:()=>x(C.remoteJid,"opened"),children:[i.jsx(Fi,{className:"mr-2 h-4 w-4"}),t("typebot.sessions.table.actions.open")]}),C.status!=="paused"&&C.status!=="closed"&&i.jsxs(wt,{onClick:()=>x(C.remoteJid,"paused"),children:[i.jsx(Di,{className:"mr-2 h-4 w-4"}),t("typebot.sessions.table.actions.pause")]}),C.status!=="closed"&&i.jsxs(wt,{onClick:()=>x(C.remoteJid,"closed"),children:[i.jsx(Oi,{className:"mr-2 h-4 w-4"}),t("typebot.sessions.table.actions.close")]}),i.jsxs(wt,{onClick:()=>x(C.remoteJid,"delete"),children:[i.jsx(Ii,{className:"mr-2 h-4 w-4"}),t("typebot.sessions.table.actions.delete")]})]})]})}}];return i.jsxs(Pt,{open:o,onOpenChange:l,children:[i.jsx(Bt,{asChild:!0,children:i.jsxs(se,{variant:"secondary",size:"sm",children:[i.jsx(Ai,{size:16,className:"mr-1"})," ",i.jsx("span",{className:"hidden sm:inline",children:t("typebot.sessions.label")})]})}),i.jsxs(Nt,{className:"overflow-y-auto sm:max-w-[950px]",onCloseAutoFocus:g,children:[i.jsx(Mt,{children:i.jsx(zt,{children:t("typebot.sessions.label")})}),i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between gap-6 p-5",children:[i.jsx(ne,{placeholder:t("typebot.sessions.search"),value:u,onChange:w=>d(w.target.value)}),i.jsx(se,{variant:"outline",onClick:g,size:"icon",children:i.jsx(Li,{size:16})})]}),i.jsx($a,{columns:b,data:h??[],onSortingChange:s,state:{sorting:r,globalFilter:u},onGlobalFilterChange:d,enableGlobalFilter:!0,noResultsMessage:t("typebot.sessions.table.none")})]})]})]})}const hse=P.object({enabled:P.boolean(),description:P.string(),url:P.string(),typebot:P.string().optional(),triggerType:P.string(),triggerOperator:P.string().optional(),triggerValue:P.string().optional(),expire:P.coerce.number().optional(),keywordFinish:P.string().optional(),delayMessage:P.coerce.number().optional(),unknownMessage:P.string().optional(),listeningFromMe:P.boolean().optional(),stopBotFromMe:P.boolean().optional(),keepOpen:P.boolean().optional(),debounceTime:P.coerce.number().optional()});function VI({initialData:e,onSubmit:t,handleDelete:n,typebotId:r,isModal:s=!1,isLoading:o=!1,openDeletionDialog:l=!1,setOpenDeletionDialog:u=()=>{}}){const{t:d}=Ve(),f=on({resolver:an(hse),defaultValues:e||{enabled:!0,description:"",url:"",typebot:"",triggerType:"keyword",triggerOperator:"contains",triggerValue:"",expire:0,keywordFinish:"",delayMessage:0,unknownMessage:"",listeningFromMe:!1,stopBotFromMe:!1,keepOpen:!1,debounceTime:0}}),h=f.watch("triggerType");return i.jsx(Gn,{...f,children:i.jsxs("form",{onSubmit:f.handleSubmit(t),className:"w-full space-y-6",children:[i.jsxs("div",{className:"space-y-4",children:[i.jsx(Pe,{name:"enabled",label:d("typebot.form.enabled.label"),reverse:!0}),i.jsx(le,{name:"description",label:d("typebot.form.description.label"),required:!0,children:i.jsx(ne,{})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:d("typebot.form.typebotSettings.label")}),i.jsx($t,{})]}),i.jsx(le,{name:"url",label:d("typebot.form.url.label"),required:!0,children:i.jsx(ne,{})}),i.jsx(le,{name:"typebot",label:d("typebot.form.typebot.label"),children:i.jsx(ne,{})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:d("typebot.form.triggerSettings.label")}),i.jsx($t,{})]}),i.jsx(Jt,{name:"triggerType",label:d("typebot.form.triggerType.label"),options:[{label:d("typebot.form.triggerType.keyword"),value:"keyword"},{label:d("typebot.form.triggerType.all"),value:"all"},{label:d("typebot.form.triggerType.advanced"),value:"advanced"},{label:d("typebot.form.triggerType.none"),value:"none"}]}),h==="keyword"&&i.jsxs(i.Fragment,{children:[i.jsx(Jt,{name:"triggerOperator",label:d("typebot.form.triggerOperator.label"),options:[{label:d("typebot.form.triggerOperator.contains"),value:"contains"},{label:d("typebot.form.triggerOperator.equals"),value:"equals"},{label:d("typebot.form.triggerOperator.startsWith"),value:"startsWith"},{label:d("typebot.form.triggerOperator.endsWith"),value:"endsWith"},{label:d("typebot.form.triggerOperator.regex"),value:"regex"}]}),i.jsx(le,{name:"triggerValue",label:d("typebot.form.triggerValue.label"),children:i.jsx(ne,{})})]}),h==="advanced"&&i.jsx(le,{name:"triggerValue",label:d("typebot.form.triggerConditions.label"),children:i.jsx(ne,{})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:d("typebot.form.generalSettings.label")}),i.jsx($t,{})]}),i.jsx(le,{name:"expire",label:d("typebot.form.expire.label"),children:i.jsx(ne,{type:"number"})}),i.jsx(le,{name:"keywordFinish",label:d("typebot.form.keywordFinish.label"),children:i.jsx(ne,{})}),i.jsx(le,{name:"delayMessage",label:d("typebot.form.delayMessage.label"),children:i.jsx(ne,{type:"number"})}),i.jsx(le,{name:"unknownMessage",label:d("typebot.form.unknownMessage.label"),children:i.jsx(ne,{})}),i.jsx(Pe,{name:"listeningFromMe",label:d("typebot.form.listeningFromMe.label"),reverse:!0}),i.jsx(Pe,{name:"stopBotFromMe",label:d("typebot.form.stopBotFromMe.label"),reverse:!0}),i.jsx(Pe,{name:"keepOpen",label:d("typebot.form.keepOpen.label"),reverse:!0}),i.jsx(le,{name:"debounceTime",label:d("typebot.form.debounceTime.label"),children:i.jsx(ne,{type:"number"})})]}),s&&i.jsx(Yt,{children:i.jsx(se,{disabled:o,type:"submit",children:d(o?"typebot.button.saving":"typebot.button.save")})}),!s&&i.jsxs("div",{children:[i.jsx(UI,{typebotId:r}),i.jsxs("div",{className:"mt-5 flex items-center gap-3",children:[i.jsxs(Pt,{open:l,onOpenChange:u,children:[i.jsx(Bt,{asChild:!0,children:i.jsx(se,{variant:"destructive",size:"sm",children:d("dify.button.delete")})}),i.jsx(Nt,{children:i.jsxs(Mt,{children:[i.jsx(zt,{children:d("modal.delete.title")}),i.jsx(eo,{children:d("modal.delete.messageSingle")}),i.jsxs(Yt,{children:[i.jsx(se,{size:"sm",variant:"outline",onClick:()=>u(!1),children:d("button.cancel")}),i.jsx(se,{variant:"destructive",onClick:n,children:d("button.delete")})]})]})})]}),i.jsx(se,{disabled:o,type:"submit",children:d(o?"typebot.button.saving":"typebot.button.update")})]})]})]})})}function gse({resetTable:e}){const{t}=Ve(),{instance:n}=ct(),{createTypebot:r}=Eg(),[s,o]=y.useState(!1),[l,u]=y.useState(!1),d=async f=>{try{if(!n||!n.name)throw new Error("instance not found");o(!0);const h={enabled:f.enabled,description:f.description,url:f.url,typebot:f.typebot||"",triggerType:f.triggerType,triggerOperator:f.triggerOperator||"",triggerValue:f.triggerValue||"",expire:f.expire||0,keywordFinish:f.keywordFinish||"",delayMessage:f.delayMessage||0,unknownMessage:f.unknownMessage||"",listeningFromMe:f.listeningFromMe||!1,stopBotFromMe:f.stopBotFromMe||!1,keepOpen:f.keepOpen||!1,debounceTime:f.debounceTime||0};await r({instanceName:n.name,token:n.token,data:h}),me.success(t("typebot.toast.success.create")),u(!1),e()}catch(h){console.error("Error:",h),me.error(`Error: ${h?.response?.data?.response?.message}`)}finally{o(!1)}};return i.jsxs(Pt,{open:l,onOpenChange:u,children:[i.jsx(Bt,{asChild:!0,children:i.jsxs(se,{size:"sm",children:[i.jsx(cs,{size:16,className:"mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:t("typebot.button.create")})]})}),i.jsxs(Nt,{className:"overflow-y-auto sm:max-h-[600px] sm:max-w-[740px]",children:[i.jsx(Mt,{children:i.jsx(zt,{children:t("typebot.form.title")})}),i.jsx(VI,{onSubmit:d,isModal:!0,isLoading:s})]})]})}const mse=e=>["typebot","getTypebot",JSON.stringify(e)],vse=async({instanceName:e,token:t,typebotId:n})=>{const r=await Ee.get(`/typebot/fetch/${n}/${e}`,{headers:{apiKey:t}});return Array.isArray(r.data)?r.data[0]:r.data},yse=e=>{const{instanceName:t,token:n,typebotId:r,...s}=e;return mt({...s,queryKey:mse({instanceName:t}),queryFn:()=>vse({instanceName:t,token:n,typebotId:r}),enabled:!!t&&!!r&&(e.enabled??!0)})};function bse({typebotId:e,resetTable:t}){const{t:n}=Ve(),{instance:r}=ct(),s=dn(),[o,l]=y.useState(!1),{deleteTypebot:u,updateTypebot:d}=Eg(),{data:f,isLoading:h}=yse({instanceName:r?.name,typebotId:e}),m=y.useMemo(()=>({enabled:!!f?.enabled,description:f?.description??"",url:f?.url??"",typebot:f?.typebot??"",triggerType:f?.triggerType??"",triggerOperator:f?.triggerOperator??"",triggerValue:f?.triggerValue,expire:f?.expire??0,keywordFinish:f?.keywordFinish,delayMessage:f?.delayMessage??0,unknownMessage:f?.unknownMessage,listeningFromMe:!!f?.listeningFromMe,stopBotFromMe:!!f?.stopBotFromMe,keepOpen:!!f?.keepOpen,debounceTime:f?.debounceTime??0}),[f?.debounceTime,f?.delayMessage,f?.description,f?.enabled,f?.expire,f?.keepOpen,f?.keywordFinish,f?.listeningFromMe,f?.stopBotFromMe,f?.triggerOperator,f?.triggerType,f?.triggerValue,f?.typebot,f?.unknownMessage,f?.url]),g=async b=>{try{if(r&&r.name&&e){const w={enabled:b.enabled,description:b.description,url:b.url,typebot:b.typebot||"",triggerType:b.triggerType,triggerOperator:b.triggerOperator||"",triggerValue:b.triggerValue||"",expire:b.expire||0,keywordFinish:b.keywordFinish||"",delayMessage:b.delayMessage||1e3,unknownMessage:b.unknownMessage||"",listeningFromMe:b.listeningFromMe||!1,stopBotFromMe:b.stopBotFromMe||!1,keepOpen:b.keepOpen||!1,debounceTime:b.debounceTime||0};await d({instanceName:r.name,typebotId:e,data:w}),me.success(n("typebot.toast.success.update")),t(),s(`/manager/instance/${r.id}/typebot/${e}`)}else console.error("Token not found")}catch(w){console.error("Error:",w),me.error(`Error: ${w?.response?.data?.response?.message}`)}},x=async()=>{try{r&&r.name&&e?(await u({instanceName:r.name,typebotId:e}),me.success(n("typebot.toast.success.delete")),l(!1),t(),s(`/manager/instance/${r.id}/typebot`)):console.error("instance not found")}catch(b){console.error("Erro ao excluir dify:",b)}};return h?i.jsx(On,{}):i.jsx("div",{className:"m-4",children:i.jsx(VI,{initialData:m,onSubmit:g,typebotId:e,handleDelete:x,isModal:!1,isLoading:h,openDeletionDialog:o,setOpenDeletionDialog:l})})}function Nk(){const{t:e}=Ve(),t=zo("(min-width: 768px)"),{instance:n}=ct(),{typebotId:r}=ls(),{data:s,isLoading:o,refetch:l}=zI({instanceName:n?.name,token:n?.token}),u=dn(),d=h=>{n&&u(`/manager/instance/${n.id}/typebot/${h}`)},f=()=>{l()};return i.jsxs("main",{className:"pt-5",children:[i.jsxs("div",{className:"mb-1 flex items-center justify-between",children:[i.jsx("h3",{className:"text-lg font-medium",children:e("typebot.title")}),i.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[i.jsx(UI,{}),i.jsx(use,{}),i.jsx(gse,{resetTable:f})]})]}),i.jsx($t,{className:"my-4"}),i.jsxs($o,{direction:t?"horizontal":"vertical",children:[i.jsx(Hn,{defaultSize:35,className:"pr-4",children:i.jsx("div",{className:"flex flex-col gap-3",children:o?i.jsx(On,{}):i.jsx(i.Fragment,{children:s&&s.length>0&&Array.isArray(s)?s.map(h=>i.jsx(se,{className:"flex h-auto flex-col items-start justify-start",onClick:()=>d(`${h.id}`),variant:r===h.id?"secondary":"outline",children:h.description?i.jsxs(i.Fragment,{children:[i.jsx("h4",{className:"text-base",children:h.description}),i.jsxs("p",{className:"text-wrap text-sm font-normal text-muted-foreground",children:[h.url," - ",h.typebot]})]}):i.jsxs(i.Fragment,{children:[i.jsx("h4",{className:"text-base",children:h.url}),i.jsx("p",{className:"text-wrap text-sm font-normal text-muted-foreground",children:h.typebot})]})},h.id)):i.jsx(se,{variant:"link",children:e("typebot.table.none")})})})}),r&&i.jsxs(i.Fragment,{children:[i.jsx(Bo,{withHandle:!0,className:"border border-black"}),i.jsx(Hn,{children:i.jsx(bse,{typebotId:r,resetTable:f})})]})]})]})}const xse=e=>["webhook","fetchWebhook",JSON.stringify(e)],wse=async({instanceName:e,token:t})=>(await Ee.get(`/webhook/find/${e}`,{headers:{apiKey:t}})).data,Sse=e=>{const{instanceName:t,token:n,...r}=e;return mt({...r,queryKey:xse({instanceName:t,token:n}),queryFn:()=>wse({instanceName:t,token:n}),enabled:!!t})},Cse=async({instanceName:e,token:t,data:n})=>(await Ee.post(`/webhook/set/${e}`,{webhook:n},{headers:{apikey:t}})).data;function Ese(){return{createWebhook:nt(Cse,{invalidateKeys:[["webhook","fetchWebhook"]]})}}const kse=P.object({enabled:P.boolean(),url:P.string().url("Invalid URL format"),events:P.array(P.string()),base64:P.boolean(),byEvents:P.boolean()});function jse(){const{t:e}=Ve(),{instance:t}=ct(),[n,r]=y.useState(!1),{createWebhook:s}=Ese(),{data:o}=Sse({instanceName:t?.name,token:t?.token}),l=on({resolver:an(kse),defaultValues:{enabled:!1,url:"",events:[],base64:!1,byEvents:!1}});y.useEffect(()=>{o&&l.reset({enabled:o.enabled,url:o.url,events:o.events,base64:o.webhookBase64,byEvents:o.webhookByEvents})},[o]);const u=async m=>{if(t){r(!0);try{const g={enabled:m.enabled,url:m.url,events:m.events,base64:m.base64,byEvents:m.byEvents};await s({instanceName:t.name,token:t.token,data:g}),me.success(e("webhook.toast.success"))}catch(g){console.error(e("webhook.toast.error"),g),me.error(`Error: ${g?.response?.data?.response?.message}`)}finally{r(!1)}}},d=["APPLICATION_STARTUP","QRCODE_UPDATED","MESSAGES_SET","MESSAGES_UPSERT","MESSAGES_UPDATE","MESSAGES_DELETE","SEND_MESSAGE","CONTACTS_SET","CONTACTS_UPSERT","CONTACTS_UPDATE","PRESENCE_UPDATE","CHATS_SET","CHATS_UPSERT","CHATS_UPDATE","CHATS_DELETE","GROUPS_UPSERT","GROUP_UPDATE","GROUP_PARTICIPANTS_UPDATE","CONNECTION_UPDATE","REMOVE_INSTANCE","LOGOUT_INSTANCE","LABELS_EDIT","LABELS_ASSOCIATION","CALL","TYPEBOT_START","TYPEBOT_CHANGE_STATUS"],f=()=>{l.setValue("events",d)},h=()=>{l.setValue("events",[])};return i.jsx(i.Fragment,{children:i.jsx(Fo,{...l,children:i.jsx("form",{onSubmit:l.handleSubmit(u),className:"w-full space-y-6",children:i.jsxs("div",{children:[i.jsx("h3",{className:"mb-1 text-lg font-medium",children:e("webhook.title")}),i.jsx(Oa,{className:"my-4"}),i.jsxs("div",{className:"mx-4 space-y-2 divide-y [&>*]:p-4",children:[i.jsx(Pe,{name:"enabled",label:e("webhook.form.enabled.label"),className:"w-full justify-between",helper:e("webhook.form.enabled.description")}),i.jsx(le,{name:"url",label:"URL",children:i.jsx(ne,{})}),i.jsx(Pe,{name:"byEvents",label:e("webhook.form.byEvents.label"),className:"w-full justify-between",helper:e("webhook.form.byEvents.description")}),i.jsx(Pe,{name:"base64",label:e("webhook.form.base64.label"),className:"w-full justify-between",helper:e("webhook.form.base64.description")}),i.jsxs("div",{className:"mb-4 flex justify-between",children:[i.jsx(se,{variant:"outline",type:"button",onClick:f,children:e("button.markAll")}),i.jsx(se,{variant:"outline",type:"button",onClick:h,children:e("button.unMarkAll")})]}),i.jsx(Lo,{control:l.control,name:"events",render:({field:m})=>i.jsxs(no,{className:"flex flex-col",children:[i.jsx(Nr,{className:"my-2 text-lg",children:e("webhook.form.events.label")}),i.jsx(_s,{children:i.jsx("div",{className:"flex flex-col gap-2 space-y-1 divide-y",children:d.sort((g,x)=>g.localeCompare(x)).map(g=>i.jsxs("div",{className:"flex items-center justify-between gap-3 pt-3",children:[i.jsx(Nr,{className:Ie("break-all",m.value.includes(g)?"text-foreground":"text-muted-foreground"),children:g}),i.jsx(gc,{checked:m.value.includes(g),onCheckedChange:x=>{x?m.onChange([...m.value,g]):m.onChange(m.value.filter(b=>b!==g))}})]},g))})})]})})]}),i.jsx("div",{className:"mx-4 flex justify-end pt-6",children:i.jsx(se,{type:"submit",disabled:n,children:e(n?"webhook.button.saving":"webhook.button.save")})})]})})})})}const Tse=e=>["websocket","fetchWebsocket",JSON.stringify(e)],Nse=async({instanceName:e,token:t})=>(await Ee.get(`/websocket/find/${e}`,{headers:{apiKey:t}})).data,Mse=e=>{const{instanceName:t,token:n,...r}=e;return mt({...r,queryKey:Tse({instanceName:t,token:n}),queryFn:()=>Nse({instanceName:t,token:n}),enabled:!!t})},_se=async({instanceName:e,token:t,data:n})=>(await Ee.post(`/websocket/set/${e}`,{websocket:n},{headers:{apikey:t}})).data;function Rse(){return{createWebsocket:nt(_se,{invalidateKeys:[["websocket","fetchWebsocket"]]})}}const Pse=P.object({enabled:P.boolean(),events:P.array(P.string())});function Ose(){const{t:e}=Ve(),{instance:t}=ct(),[n,r]=y.useState(!1),{createWebsocket:s}=Rse(),{data:o}=Mse({instanceName:t?.name,token:t?.token}),l=on({resolver:an(Pse),defaultValues:{enabled:!1,events:[]}});y.useEffect(()=>{o&&l.reset({enabled:o.enabled,events:o.events})},[o]);const u=async m=>{if(t){r(!0);try{const g={enabled:m.enabled,events:m.events};await s({instanceName:t.name,token:t.token,data:g}),me.success(e("websocket.toast.success"))}catch(g){console.error(e("websocket.toast.error"),g),me.error(`Error: ${g?.response?.data?.response?.message}`)}finally{r(!1)}}},d=["APPLICATION_STARTUP","QRCODE_UPDATED","MESSAGES_SET","MESSAGES_UPSERT","MESSAGES_UPDATE","MESSAGES_DELETE","SEND_MESSAGE","CONTACTS_SET","CONTACTS_UPSERT","CONTACTS_UPDATE","PRESENCE_UPDATE","CHATS_SET","CHATS_UPSERT","CHATS_UPDATE","CHATS_DELETE","GROUPS_UPSERT","GROUP_UPDATE","GROUP_PARTICIPANTS_UPDATE","CONNECTION_UPDATE","REMOVE_INSTANCE","LOGOUT_INSTANCE","LABELS_EDIT","LABELS_ASSOCIATION","CALL","TYPEBOT_START","TYPEBOT_CHANGE_STATUS"],f=()=>{l.setValue("events",d)},h=()=>{l.setValue("events",[])};return i.jsx(i.Fragment,{children:i.jsx(Fo,{...l,children:i.jsx("form",{onSubmit:l.handleSubmit(u),className:"w-full space-y-6",children:i.jsxs("div",{children:[i.jsx("h3",{className:"mb-1 text-lg font-medium",children:e("websocket.title")}),i.jsx(Oa,{className:"my-4"}),i.jsxs("div",{className:"mx-4 space-y-2 divide-y [&>*]:p-4",children:[i.jsx(Pe,{name:"enabled",label:e("websocket.form.enabled.label"),className:"w-full justify-between",helper:e("websocket.form.enabled.description")}),i.jsxs("div",{className:"mb-4 flex justify-between",children:[i.jsx(se,{variant:"outline",type:"button",onClick:f,children:e("button.markAll")}),i.jsx(se,{variant:"outline",type:"button",onClick:h,children:e("button.unMarkAll")})]}),i.jsx(Lo,{control:l.control,name:"events",render:({field:m})=>i.jsxs(no,{className:"flex flex-col",children:[i.jsx(Nr,{className:"my-2 text-lg",children:e("websocket.form.events.label")}),i.jsx(_s,{children:i.jsx("div",{className:"flex flex-col gap-2 space-y-1 divide-y",children:d.sort((g,x)=>g.localeCompare(x)).map(g=>i.jsxs("div",{className:"flex items-center justify-between gap-3 pt-3",children:[i.jsx(Nr,{className:Ie("break-all",m.value.includes(g)?"text-foreground":"text-muted-foreground"),children:g}),i.jsx(gc,{checked:m.value.includes(g),onCheckedChange:x=>{x?m.onChange([...m.value,g]):m.onChange(m.value.filter(b=>b!==g))}})]},g))})})]})})]}),i.jsx("div",{className:"mx-4 flex justify-end pt-6",children:i.jsx(se,{type:"submit",disabled:n,children:e(n?"websocket.button.saving":"websocket.button.save")})})]})})})})}const Ise=async({url:e,token:t})=>{try{const{data:n}=await sn.post(`${e}/verify-creds`,{},{headers:{apikey:t}});return Rj({facebookAppId:n.facebookAppId,facebookConfigId:n.facebookConfigId,facebookUserToken:n.facebookUserToken}),n}catch{return null}},Ase=P.object({serverUrl:P.string({required_error:"serverUrl is required"}).url("URL inválida"),apiKey:P.string({required_error:"ApiKey is required"})});function Dse(){const{t:e}=Ve(),t=dn(),{theme:n}=tc(),r=on({resolver:an(Ase),defaultValues:{serverUrl:window.location.protocol+"//"+window.location.host,apiKey:""}}),s=async o=>{const l=await sT({url:o.serverUrl});if(!l||!l.version){Pj(),r.setError("serverUrl",{type:"manual",message:e("login.message.invalidServer")});return}if(!await Ise({token:o.apiKey,url:o.serverUrl})){r.setError("apiKey",{type:"manual",message:e("login.message.invalidCredentials")});return}Rj({version:l.version,clientName:l.clientName,url:o.serverUrl,token:o.apiKey}),t("/manager/")};return i.jsxs("div",{className:"flex min-h-screen flex-col",children:[i.jsx("div",{className:"flex items-center justify-center pt-2",children:i.jsx("img",{className:"h-10",src:n==="dark"?"https://evolution-api.com/files/evo/evolution-logo-white.svg":"https://evolution-api.com/files/evo/evolution-logo.svg",alt:"logo"})}),i.jsx("div",{className:"flex flex-1 items-center justify-center p-8",children:i.jsxs(So,{className:"b-none w-[350px] shadow-none",children:[i.jsxs(Co,{children:[i.jsx(gi,{className:"text-center",children:e("login.title")}),i.jsx(Kp,{className:"text-center",children:e("login.description")})]}),i.jsx(Fo,{...r,children:i.jsxs("form",{onSubmit:r.handleSubmit(s),children:[i.jsx(Eo,{children:i.jsxs("div",{className:"grid w-full items-center gap-4",children:[i.jsx(le,{required:!0,name:"serverUrl",label:e("login.form.serverUrl"),children:i.jsx(ne,{})}),i.jsx(le,{required:!0,name:"apiKey",label:e("login.form.apiKey"),children:i.jsx(ne,{type:"password"})})]})}),i.jsx(Vh,{className:"flex justify-center",children:i.jsx(se,{className:"w-full",type:"submit",children:e("login.button.login")})})]})})]})}),i.jsx(Vb,{})]})}function Fse(){const e=dn(),{theme:t}=tc(),n=()=>{e("/manager")};return i.jsxs("div",{className:"min-h-screen bg-background",children:[i.jsxs("header",{className:"flex items-center justify-between px-4 py-2",children:[i.jsx("div",{className:"flex items-center",children:i.jsx("img",{src:t==="dark"?"https://evolution-api.com/files/evo/evolution-logo-white.svg":"https://evolution-api.com/files/evo/evolution-logo.svg",alt:"Evolution API Logo",className:"h-8"})}),i.jsxs("div",{className:"flex items-center gap-4",children:[i.jsx(iM,{}),i.jsx(lM,{})]})]}),i.jsx("div",{className:"container mx-auto px-4 py-16",children:i.jsxs("div",{className:"max-w-4xl mx-auto",children:[i.jsxs("div",{className:"text-center mb-12",children:[i.jsx("div",{className:"flex items-center justify-center mb-6",children:i.jsx("img",{src:t==="dark"?"https://evolution-api.com/files/evo/evolution-logo-white.svg":"https://evolution-api.com/files/evo/evolution-logo.svg",alt:"Evolution Manager Logo",className:"h-10"})}),i.jsx("h1",{className:"text-4xl font-bold text-foreground mb-4",children:"Evolution Manager v2"}),i.jsx("p",{className:"text-xl text-muted-foreground mb-6",children:"Modern web interface for Evolution API management"}),i.jsx(vu,{variant:"secondary",className:"text-sm px-3 py-1",children:"Version 2.0.0"})]}),i.jsxs(So,{className:"mb-8",children:[i.jsxs(Co,{children:[i.jsxs(gi,{className:"flex items-center gap-2",children:[i.jsx(xB,{className:"w-5 h-5 text-primary"}),"Welcome to Evolution Manager"]}),i.jsx(Kp,{children:"A powerful, modern dashboard for managing your WhatsApp API instances with Evolution API"})]}),i.jsx(Eo,{className:"space-y-6",children:i.jsx("div",{className:"pt-6 border-t border-border",children:i.jsx("div",{className:"flex flex-col sm:flex-row gap-4 justify-center items-center",children:i.jsxs(se,{onClick:n,size:"lg",className:"px-8 py-3",children:["Access Manager Dashboard",i.jsx(Th,{className:"w-4 h-4 ml-2"})]})})})})]}),i.jsxs(So,{children:[i.jsxs(Co,{children:[i.jsx(gi,{children:"Resources & Support"}),i.jsx(Kp,{children:"Get help, contribute, or learn more about Evolution API"})]}),i.jsx(Eo,{children:i.jsxs("div",{className:"grid md:grid-cols-3 gap-4",children:[i.jsxs("a",{href:"https://github.com/EvolutionAPI/evolution-manager-v2",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-3 p-4 rounded-lg border border-border hover:bg-accent transition-colors",children:[i.jsx(aB,{className:"w-5 h-5 text-muted-foreground"}),i.jsxs("div",{children:[i.jsx("div",{className:"font-medium text-foreground",children:"GitHub"}),i.jsx("div",{className:"text-sm text-muted-foreground",children:"Source code"})]})]}),i.jsxs("a",{href:"https://evolution-api.com",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-3 p-4 rounded-lg border border-border hover:bg-accent transition-colors",children:[i.jsx(iB,{className:"w-5 h-5 text-muted-foreground"}),i.jsxs("div",{children:[i.jsx("div",{className:"font-medium text-foreground",children:"Website"}),i.jsx("div",{className:"text-sm text-muted-foreground",children:"Official site"})]})]}),i.jsxs("a",{href:"mailto:contato@evolution-api.com",className:"flex items-center gap-3 p-4 rounded-lg border border-border hover:bg-accent transition-colors",children:[i.jsx(vB,{className:"w-5 h-5 text-muted-foreground"}),i.jsxs("div",{children:[i.jsx("div",{className:"font-medium text-foreground",children:"Contact"}),i.jsx("div",{className:"text-sm text-muted-foreground",children:"Get support"})]})]})]})})]}),i.jsx("div",{className:"text-center mt-12 text-sm text-muted-foreground",children:i.jsx("p",{children:"© 2025 Evolution API. Licensed under Apache 2.0 with Evolution API custom conditions."})})]})})]})}const Lse=Z2([{path:"/",element:i.jsx(Fse,{})},{path:"/manager/login",element:i.jsx(jL,{children:i.jsx(Dse,{})})},{path:"/manager/",element:i.jsx(tn,{children:i.jsx(B5,{children:i.jsx(CZ,{})})})},{path:"/manager/instance/:instanceId/dashboard",element:i.jsx(tn,{children:i.jsx(un,{children:i.jsx(PX,{})})})},{path:"/manager/instance/:instanceId/chat",element:i.jsx(tn,{children:i.jsx(un,{children:i.jsx(tk,{})})})},{path:"/manager/instance/:instanceId/chat/:remoteJid",element:i.jsx(tn,{children:i.jsx(un,{children:i.jsx(tk,{})})})},{path:"/manager/instance/:instanceId/settings",element:i.jsx(tn,{children:i.jsx(un,{children:i.jsx(qre,{})})})},{path:"/manager/instance/:instanceId/openai",element:i.jsx(tn,{children:i.jsx(un,{children:i.jsx(Tk,{})})})},{path:"/manager/instance/:instanceId/openai/:botId",element:i.jsx(tn,{children:i.jsx(un,{children:i.jsx(Tk,{})})})},{path:"/manager/instance/:instanceId/webhook",element:i.jsx(tn,{children:i.jsx(un,{children:i.jsx(jse,{})})})},{path:"/manager/instance/:instanceId/websocket",element:i.jsx(tn,{children:i.jsx(un,{children:i.jsx(Ose,{})})})},{path:"/manager/instance/:instanceId/rabbitmq",element:i.jsx(tn,{children:i.jsx(un,{children:i.jsx(Bre,{})})})},{path:"/manager/instance/:instanceId/sqs",element:i.jsx(tn,{children:i.jsx(un,{children:i.jsx(Yre,{})})})},{path:"/manager/instance/:instanceId/chatwoot",element:i.jsx(tn,{children:i.jsx(un,{children:i.jsx(yX,{})})})},{path:"/manager/instance/:instanceId/typebot",element:i.jsx(tn,{children:i.jsx(un,{children:i.jsx(Nk,{})})})},{path:"/manager/instance/:instanceId/typebot/:typebotId",element:i.jsx(tn,{children:i.jsx(un,{children:i.jsx(Nk,{})})})},{path:"/manager/instance/:instanceId/dify",element:i.jsx(tn,{children:i.jsx(un,{children:i.jsx(xk,{})})})},{path:"/manager/instance/:instanceId/dify/:difyId",element:i.jsx(tn,{children:i.jsx(un,{children:i.jsx(xk,{})})})},{path:"/manager/instance/:instanceId/n8n",element:i.jsx(tn,{children:i.jsx(un,{children:i.jsx(jk,{})})})},{path:"/manager/instance/:instanceId/n8n/:n8nId",element:i.jsx(tn,{children:i.jsx(un,{children:i.jsx(jk,{})})})},{path:"/manager/instance/:instanceId/evoai",element:i.jsx(tn,{children:i.jsx(un,{children:i.jsx(Ck,{})})})},{path:"/manager/instance/:instanceId/evoai/:evoaiId",element:i.jsx(tn,{children:i.jsx(un,{children:i.jsx(Ck,{})})})},{path:"/manager/instance/:instanceId/evolutionBot",element:i.jsx(tn,{children:i.jsx(un,{children:i.jsx(Ek,{})})})},{path:"/manager/instance/:instanceId/evolutionBot/:evolutionBotId",element:i.jsx(tn,{children:i.jsx(un,{children:i.jsx(Ek,{})})})},{path:"/manager/instance/:instanceId/flowise",element:i.jsx(tn,{children:i.jsx(un,{children:i.jsx(kk,{})})})},{path:"/manager/instance/:instanceId/flowise/:flowiseId",element:i.jsx(tn,{children:i.jsx(un,{children:i.jsx(kk,{})})})},{path:"/manager/instance/:instanceId/proxy",element:i.jsx(tn,{children:i.jsx(un,{children:i.jsx(Ore,{})})})},{path:"/manager/embed-chat",element:i.jsx(Sk,{})},{path:"/manager/embed-chat/:remoteJid",element:i.jsx(Sk,{})}]),$se={type:"logger",log(e){this.output("log",e)},warn(e){this.output("warn",e)},error(e){this.output("error",e)},output(e,t){console&&console[e]&&console[e].apply(console,t)}};class uh{constructor(t){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};this.init(t,n)}init(t){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};this.prefix=n.prefix||"i18next:",this.logger=t||$se,this.options=n,this.debug=n.debug}log(){for(var t=arguments.length,n=new Array(t),r=0;r{this.observers[r]||(this.observers[r]=new Map);const s=this.observers[r].get(n)||0;this.observers[r].set(n,s+1)}),this}off(t,n){if(this.observers[t]){if(!n){delete this.observers[t];return}this.observers[t].delete(n)}}emit(t){for(var n=arguments.length,r=new Array(n>1?n-1:0),s=1;s{let[u,d]=l;for(let f=0;f{let[u,d]=l;for(let f=0;f{let e,t;const n=new Promise((r,s)=>{e=r,t=s});return n.resolve=e,n.reject=t,n},Mk=e=>e==null?"":""+e,Bse=(e,t,n)=>{e.forEach(r=>{t[r]&&(n[r]=t[r])})},zse=/###/g,_k=e=>e&&e.indexOf("###")>-1?e.replace(zse,"."):e,Rk=e=>!e||typeof e=="string",Pu=(e,t,n)=>{const r=typeof t!="string"?t:t.split(".");let s=0;for(;s{const{obj:r,k:s}=Pu(e,t,Object);if(r!==void 0||t.length===1){r[s]=n;return}let o=t[t.length-1],l=t.slice(0,t.length-1),u=Pu(e,l,Object);for(;u.obj===void 0&&l.length;)o=`${l[l.length-1]}.${o}`,l=l.slice(0,l.length-1),u=Pu(e,l,Object),u&&u.obj&&typeof u.obj[`${u.k}.${o}`]<"u"&&(u.obj=void 0);u.obj[`${u.k}.${o}`]=n},Use=(e,t,n,r)=>{const{obj:s,k:o}=Pu(e,t,Object);s[o]=s[o]||[],s[o].push(n)},dh=(e,t)=>{const{obj:n,k:r}=Pu(e,t);if(n)return n[r]},Vse=(e,t,n)=>{const r=dh(e,n);return r!==void 0?r:dh(t,n)},HI=(e,t,n)=>{for(const r in t)r!=="__proto__"&&r!=="constructor"&&(r in e?typeof e[r]=="string"||e[r]instanceof String||typeof t[r]=="string"||t[r]instanceof String?n&&(e[r]=t[r]):HI(e[r],t[r],n):e[r]=t[r]);return e},Sl=e=>e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&");var Hse={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"};const qse=e=>typeof e=="string"?e.replace(/[&<>"'\/]/g,t=>Hse[t]):e;class Kse{constructor(t){this.capacity=t,this.regExpMap=new Map,this.regExpQueue=[]}getRegExp(t){const n=this.regExpMap.get(t);if(n!==void 0)return n;const r=new RegExp(t);return this.regExpQueue.length===this.capacity&&this.regExpMap.delete(this.regExpQueue.shift()),this.regExpMap.set(t,r),this.regExpQueue.push(t),r}}const Wse=[" ",",","?","!",";"],Gse=new Kse(20),Jse=(e,t,n)=>{t=t||"",n=n||"";const r=Wse.filter(l=>t.indexOf(l)<0&&n.indexOf(l)<0);if(r.length===0)return!0;const s=Gse.getRegExp(`(${r.map(l=>l==="?"?"\\?":l).join("|")})`);let o=!s.test(e);if(!o){const l=e.indexOf(n);l>0&&!s.test(e.substring(0,l))&&(o=!0)}return o},Mb=function(e,t){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:".";if(!e)return;if(e[t])return e[t];const r=t.split(n);let s=e;for(let o=0;o-1&&de&&e.indexOf("_")>0?e.replace("_","-"):e;class Ok extends kg{constructor(t){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{ns:["translation"],defaultNS:"translation"};super(),this.data=t||{},this.options=n,this.options.keySeparator===void 0&&(this.options.keySeparator="."),this.options.ignoreJSONStructure===void 0&&(this.options.ignoreJSONStructure=!0)}addNamespaces(t){this.options.ns.indexOf(t)<0&&this.options.ns.push(t)}removeNamespaces(t){const n=this.options.ns.indexOf(t);n>-1&&this.options.ns.splice(n,1)}getResource(t,n,r){let s=arguments.length>3&&arguments[3]!==void 0?arguments[3]:{};const o=s.keySeparator!==void 0?s.keySeparator:this.options.keySeparator,l=s.ignoreJSONStructure!==void 0?s.ignoreJSONStructure:this.options.ignoreJSONStructure;let u;t.indexOf(".")>-1?u=t.split("."):(u=[t,n],r&&(Array.isArray(r)?u.push(...r):typeof r=="string"&&o?u.push(...r.split(o)):u.push(r)));const d=dh(this.data,u);return!d&&!n&&!r&&t.indexOf(".")>-1&&(t=u[0],n=u[1],r=u.slice(2).join(".")),d||!l||typeof r!="string"?d:Mb(this.data&&this.data[t]&&this.data[t][n],r,o)}addResource(t,n,r,s){let o=arguments.length>4&&arguments[4]!==void 0?arguments[4]:{silent:!1};const l=o.keySeparator!==void 0?o.keySeparator:this.options.keySeparator;let u=[t,n];r&&(u=u.concat(l?r.split(l):r)),t.indexOf(".")>-1&&(u=t.split("."),s=n,n=u[1]),this.addNamespaces(n),Pk(this.data,u,s),o.silent||this.emit("added",t,n,r,s)}addResources(t,n,r){let s=arguments.length>3&&arguments[3]!==void 0?arguments[3]:{silent:!1};for(const o in r)(typeof r[o]=="string"||Array.isArray(r[o]))&&this.addResource(t,n,o,r[o],{silent:!0});s.silent||this.emit("added",t,n,r)}addResourceBundle(t,n,r,s,o){let l=arguments.length>5&&arguments[5]!==void 0?arguments[5]:{silent:!1,skipCopy:!1},u=[t,n];t.indexOf(".")>-1&&(u=t.split("."),s=r,r=n,n=u[1]),this.addNamespaces(n);let d=dh(this.data,u)||{};l.skipCopy||(r=JSON.parse(JSON.stringify(r))),s?HI(d,r,o):d={...d,...r},Pk(this.data,u,d),l.silent||this.emit("added",t,n,r)}removeResourceBundle(t,n){this.hasResourceBundle(t,n)&&delete this.data[t][n],this.removeNamespaces(n),this.emit("removed",t,n)}hasResourceBundle(t,n){return this.getResource(t,n)!==void 0}getResourceBundle(t,n){return n||(n=this.options.defaultNS),this.options.compatibilityAPI==="v1"?{...this.getResource(t,n)}:this.getResource(t,n)}getDataByLanguage(t){return this.data[t]}hasLanguageSomeTranslations(t){const n=this.getDataByLanguage(t);return!!(n&&Object.keys(n)||[]).find(s=>n[s]&&Object.keys(n[s]).length>0)}toJSON(){return this.data}}var qI={processors:{},addPostProcessor(e){this.processors[e.name]=e},handle(e,t,n,r,s){return e.forEach(o=>{this.processors[o]&&(t=this.processors[o].process(t,n,r,s))}),t}};const Ik={};class ph extends kg{constructor(t){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),Bse(["resourceStore","languageUtils","pluralResolver","interpolator","backendConnector","i18nFormat","utils"],t,this),this.options=n,this.options.keySeparator===void 0&&(this.options.keySeparator="."),this.logger=Ks.create("translator")}changeLanguage(t){t&&(this.language=t)}exists(t){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{interpolation:{}};if(t==null)return!1;const r=this.resolve(t,n);return r&&r.res!==void 0}extractFromKey(t,n){let r=n.nsSeparator!==void 0?n.nsSeparator:this.options.nsSeparator;r===void 0&&(r=":");const s=n.keySeparator!==void 0?n.keySeparator:this.options.keySeparator;let o=n.ns||this.options.defaultNS||[];const l=r&&t.indexOf(r)>-1,u=!this.options.userDefinedKeySeparator&&!n.keySeparator&&!this.options.userDefinedNsSeparator&&!n.nsSeparator&&!Jse(t,r,s);if(l&&!u){const d=t.match(this.interpolator.nestingRegexp);if(d&&d.length>0)return{key:t,namespaces:o};const f=t.split(r);(r!==s||r===s&&this.options.ns.indexOf(f[0])>-1)&&(o=f.shift()),t=f.join(s)}return typeof o=="string"&&(o=[o]),{key:t,namespaces:o}}translate(t,n,r){if(typeof n!="object"&&this.options.overloadTranslationOptionHandler&&(n=this.options.overloadTranslationOptionHandler(arguments)),typeof n=="object"&&(n={...n}),n||(n={}),t==null)return"";Array.isArray(t)||(t=[String(t)]);const s=n.returnDetails!==void 0?n.returnDetails:this.options.returnDetails,o=n.keySeparator!==void 0?n.keySeparator:this.options.keySeparator,{key:l,namespaces:u}=this.extractFromKey(t[t.length-1],n),d=u[u.length-1],f=n.lng||this.language,h=n.appendNamespaceToCIMode||this.options.appendNamespaceToCIMode;if(f&&f.toLowerCase()==="cimode"){if(h){const _=n.nsSeparator||this.options.nsSeparator;return s?{res:`${d}${_}${l}`,usedKey:l,exactUsedKey:l,usedLng:f,usedNS:d,usedParams:this.getUsedParamsDetails(n)}:`${d}${_}${l}`}return s?{res:l,usedKey:l,exactUsedKey:l,usedLng:f,usedNS:d,usedParams:this.getUsedParamsDetails(n)}:l}const m=this.resolve(t,n);let g=m&&m.res;const x=m&&m.usedKey||l,b=m&&m.exactUsedKey||l,w=Object.prototype.toString.apply(g),C=["[object Number]","[object Function]","[object RegExp]"],k=n.joinArrays!==void 0?n.joinArrays:this.options.joinArrays,j=!this.i18nFormat||this.i18nFormat.handleAsObject;if(j&&g&&(typeof g!="string"&&typeof g!="boolean"&&typeof g!="number")&&C.indexOf(w)<0&&!(typeof k=="string"&&Array.isArray(g))){if(!n.returnObjects&&!this.options.returnObjects){this.options.returnedObjectHandler||this.logger.warn("accessing an object - but returnObjects options is not enabled!");const _=this.options.returnedObjectHandler?this.options.returnedObjectHandler(x,g,{...n,ns:u}):`key '${l} (${this.language})' returned an object instead of string.`;return s?(m.res=_,m.usedParams=this.getUsedParamsDetails(n),m):_}if(o){const _=Array.isArray(g),R=_?[]:{},N=_?b:x;for(const O in g)if(Object.prototype.hasOwnProperty.call(g,O)){const D=`${N}${o}${O}`;R[O]=this.translate(D,{...n,joinArrays:!1,ns:u}),R[O]===D&&(R[O]=g[O])}g=R}}else if(j&&typeof k=="string"&&Array.isArray(g))g=g.join(k),g&&(g=this.extendTranslation(g,t,n,r));else{let _=!1,R=!1;const N=n.count!==void 0&&typeof n.count!="string",O=ph.hasDefaultValue(n),D=N?this.pluralResolver.getSuffix(f,n.count,n):"",z=n.ordinal&&N?this.pluralResolver.getSuffix(f,n.count,{ordinal:!1}):"",Q=N&&!n.ordinal&&n.count===0&&this.pluralResolver.shouldUseIntlApi(),pe=Q&&n[`defaultValue${this.options.pluralSeparator}zero`]||n[`defaultValue${D}`]||n[`defaultValue${z}`]||n.defaultValue;!this.isValidLookup(g)&&O&&(_=!0,g=pe),this.isValidLookup(g)||(R=!0,g=l);const G=(n.missingKeyNoValueFallbackToKey||this.options.missingKeyNoValueFallbackToKey)&&R?void 0:g,W=O&&pe!==g&&this.options.updateMissing;if(R||_||W){if(this.logger.log(W?"updateKey":"missingKey",f,d,l,W?pe:g),o){const H=this.resolve(l,{...n,keySeparator:!1});H&&H.res&&this.logger.warn("Seems the loaded translations were in flat JSON format instead of nested. Either set keySeparator: false on init or make sure your translations are published in nested format.")}let ie=[];const re=this.languageUtils.getFallbackCodes(this.options.fallbackLng,n.lng||this.language);if(this.options.saveMissingTo==="fallback"&&re&&re[0])for(let H=0;H{const A=O&&he!==g?he:G;this.options.missingKeyHandler?this.options.missingKeyHandler(H,d,q,A,W,n):this.backendConnector&&this.backendConnector.saveMissing&&this.backendConnector.saveMissing(H,d,q,A,W,n),this.emit("missingKey",H,d,q,g)};this.options.saveMissing&&(this.options.saveMissingPlurals&&N?ie.forEach(H=>{const q=this.pluralResolver.getSuffixes(H,n);Q&&n[`defaultValue${this.options.pluralSeparator}zero`]&&q.indexOf(`${this.options.pluralSeparator}zero`)<0&&q.push(`${this.options.pluralSeparator}zero`),q.forEach(he=>{Y([H],l+he,n[`defaultValue${he}`]||pe)})}):Y(ie,l,pe))}g=this.extendTranslation(g,t,n,m,r),R&&g===l&&this.options.appendNamespaceToMissingKey&&(g=`${d}:${l}`),(R||_)&&this.options.parseMissingKeyHandler&&(this.options.compatibilityAPI!=="v1"?g=this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey?`${d}:${l}`:l,_?g:void 0):g=this.options.parseMissingKeyHandler(g))}return s?(m.res=g,m.usedParams=this.getUsedParamsDetails(n),m):g}extendTranslation(t,n,r,s,o){var l=this;if(this.i18nFormat&&this.i18nFormat.parse)t=this.i18nFormat.parse(t,{...this.options.interpolation.defaultVariables,...r},r.lng||this.language||s.usedLng,s.usedNS,s.usedKey,{resolved:s});else if(!r.skipInterpolation){r.interpolation&&this.interpolator.init({...r,interpolation:{...this.options.interpolation,...r.interpolation}});const f=typeof t=="string"&&(r&&r.interpolation&&r.interpolation.skipOnVariables!==void 0?r.interpolation.skipOnVariables:this.options.interpolation.skipOnVariables);let h;if(f){const g=t.match(this.interpolator.nestingRegexp);h=g&&g.length}let m=r.replace&&typeof r.replace!="string"?r.replace:r;if(this.options.interpolation.defaultVariables&&(m={...this.options.interpolation.defaultVariables,...m}),t=this.interpolator.interpolate(t,m,r.lng||this.language||s.usedLng,r),f){const g=t.match(this.interpolator.nestingRegexp),x=g&&g.length;h1&&arguments[1]!==void 0?arguments[1]:{},r,s,o,l,u;return typeof t=="string"&&(t=[t]),t.forEach(d=>{if(this.isValidLookup(r))return;const f=this.extractFromKey(d,n),h=f.key;s=h;let m=f.namespaces;this.options.fallbackNS&&(m=m.concat(this.options.fallbackNS));const g=n.count!==void 0&&typeof n.count!="string",x=g&&!n.ordinal&&n.count===0&&this.pluralResolver.shouldUseIntlApi(),b=n.context!==void 0&&(typeof n.context=="string"||typeof n.context=="number")&&n.context!=="",w=n.lngs?n.lngs:this.languageUtils.toResolveHierarchy(n.lng||this.language,n.fallbackLng);m.forEach(C=>{this.isValidLookup(r)||(u=C,!Ik[`${w[0]}-${C}`]&&this.utils&&this.utils.hasLoadedNamespace&&!this.utils.hasLoadedNamespace(u)&&(Ik[`${w[0]}-${C}`]=!0,this.logger.warn(`key "${s}" for languages "${w.join(", ")}" won't get resolved as namespace "${u}" was not yet loaded`,"This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!")),w.forEach(k=>{if(this.isValidLookup(r))return;l=k;const j=[h];if(this.i18nFormat&&this.i18nFormat.addLookupKeys)this.i18nFormat.addLookupKeys(j,h,k,C,n);else{let _;g&&(_=this.pluralResolver.getSuffix(k,n.count,n));const R=`${this.options.pluralSeparator}zero`,N=`${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;if(g&&(j.push(h+_),n.ordinal&&_.indexOf(N)===0&&j.push(h+_.replace(N,this.options.pluralSeparator)),x&&j.push(h+R)),b){const O=`${h}${this.options.contextSeparator}${n.context}`;j.push(O),g&&(j.push(O+_),n.ordinal&&_.indexOf(N)===0&&j.push(O+_.replace(N,this.options.pluralSeparator)),x&&j.push(O+R))}}let M;for(;M=j.pop();)this.isValidLookup(r)||(o=M,r=this.getResource(k,C,M,n))}))})}),{res:r,usedKey:s,exactUsedKey:o,usedLng:l,usedNS:u}}isValidLookup(t){return t!==void 0&&!(!this.options.returnNull&&t===null)&&!(!this.options.returnEmptyString&&t==="")}getResource(t,n,r){let s=arguments.length>3&&arguments[3]!==void 0?arguments[3]:{};return this.i18nFormat&&this.i18nFormat.getResource?this.i18nFormat.getResource(t,n,r,s):this.resourceStore.getResource(t,n,r,s)}getUsedParamsDetails(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const n=["defaultValue","ordinal","context","replace","lng","lngs","fallbackLng","ns","keySeparator","nsSeparator","returnObjects","returnDetails","joinArrays","postProcess","interpolation"],r=t.replace&&typeof t.replace!="string";let s=r?t.replace:t;if(r&&typeof t.count<"u"&&(s.count=t.count),this.options.interpolation.defaultVariables&&(s={...this.options.interpolation.defaultVariables,...s}),!r){s={...s};for(const o of n)delete s[o]}return s}static hasDefaultValue(t){const n="defaultValue";for(const r in t)if(Object.prototype.hasOwnProperty.call(t,r)&&n===r.substring(0,n.length)&&t[r]!==void 0)return!0;return!1}}const xy=e=>e.charAt(0).toUpperCase()+e.slice(1);class Ak{constructor(t){this.options=t,this.supportedLngs=this.options.supportedLngs||!1,this.logger=Ks.create("languageUtils")}getScriptPartFromCode(t){if(t=fh(t),!t||t.indexOf("-")<0)return null;const n=t.split("-");return n.length===2||(n.pop(),n[n.length-1].toLowerCase()==="x")?null:this.formatLanguageCode(n.join("-"))}getLanguagePartFromCode(t){if(t=fh(t),!t||t.indexOf("-")<0)return t;const n=t.split("-");return this.formatLanguageCode(n[0])}formatLanguageCode(t){if(typeof t=="string"&&t.indexOf("-")>-1){const n=["hans","hant","latn","cyrl","cans","mong","arab"];let r=t.split("-");return this.options.lowerCaseLng?r=r.map(s=>s.toLowerCase()):r.length===2?(r[0]=r[0].toLowerCase(),r[1]=r[1].toUpperCase(),n.indexOf(r[1].toLowerCase())>-1&&(r[1]=xy(r[1].toLowerCase()))):r.length===3&&(r[0]=r[0].toLowerCase(),r[1].length===2&&(r[1]=r[1].toUpperCase()),r[0]!=="sgn"&&r[2].length===2&&(r[2]=r[2].toUpperCase()),n.indexOf(r[1].toLowerCase())>-1&&(r[1]=xy(r[1].toLowerCase())),n.indexOf(r[2].toLowerCase())>-1&&(r[2]=xy(r[2].toLowerCase()))),r.join("-")}return this.options.cleanCode||this.options.lowerCaseLng?t.toLowerCase():t}isSupportedCode(t){return(this.options.load==="languageOnly"||this.options.nonExplicitSupportedLngs)&&(t=this.getLanguagePartFromCode(t)),!this.supportedLngs||!this.supportedLngs.length||this.supportedLngs.indexOf(t)>-1}getBestMatchFromCodes(t){if(!t)return null;let n;return t.forEach(r=>{if(n)return;const s=this.formatLanguageCode(r);(!this.options.supportedLngs||this.isSupportedCode(s))&&(n=s)}),!n&&this.options.supportedLngs&&t.forEach(r=>{if(n)return;const s=this.getLanguagePartFromCode(r);if(this.isSupportedCode(s))return n=s;n=this.options.supportedLngs.find(o=>{if(o===s)return o;if(!(o.indexOf("-")<0&&s.indexOf("-")<0)&&(o.indexOf("-")>0&&s.indexOf("-")<0&&o.substring(0,o.indexOf("-"))===s||o.indexOf(s)===0&&s.length>1))return o})}),n||(n=this.getFallbackCodes(this.options.fallbackLng)[0]),n}getFallbackCodes(t,n){if(!t)return[];if(typeof t=="function"&&(t=t(n)),typeof t=="string"&&(t=[t]),Array.isArray(t))return t;if(!n)return t.default||[];let r=t[n];return r||(r=t[this.getScriptPartFromCode(n)]),r||(r=t[this.formatLanguageCode(n)]),r||(r=t[this.getLanguagePartFromCode(n)]),r||(r=t.default),r||[]}toResolveHierarchy(t,n){const r=this.getFallbackCodes(n||this.options.fallbackLng||[],t),s=[],o=l=>{l&&(this.isSupportedCode(l)?s.push(l):this.logger.warn(`rejecting language code not found in supportedLngs: ${l}`))};return typeof t=="string"&&(t.indexOf("-")>-1||t.indexOf("_")>-1)?(this.options.load!=="languageOnly"&&o(this.formatLanguageCode(t)),this.options.load!=="languageOnly"&&this.options.load!=="currentOnly"&&o(this.getScriptPartFromCode(t)),this.options.load!=="currentOnly"&&o(this.getLanguagePartFromCode(t))):typeof t=="string"&&o(this.formatLanguageCode(t)),r.forEach(l=>{s.indexOf(l)<0&&o(this.formatLanguageCode(l))}),s}}let Qse=[{lngs:["ach","ak","am","arn","br","fil","gun","ln","mfe","mg","mi","oc","pt","pt-BR","tg","tl","ti","tr","uz","wa"],nr:[1,2],fc:1},{lngs:["af","an","ast","az","bg","bn","ca","da","de","dev","el","en","eo","es","et","eu","fi","fo","fur","fy","gl","gu","ha","hi","hu","hy","ia","it","kk","kn","ku","lb","mai","ml","mn","mr","nah","nap","nb","ne","nl","nn","no","nso","pa","pap","pms","ps","pt-PT","rm","sco","se","si","so","son","sq","sv","sw","ta","te","tk","ur","yo"],nr:[1,2],fc:2},{lngs:["ay","bo","cgg","fa","ht","id","ja","jbo","ka","km","ko","ky","lo","ms","sah","su","th","tt","ug","vi","wo","zh"],nr:[1],fc:3},{lngs:["be","bs","cnr","dz","hr","ru","sr","uk"],nr:[1,2,5],fc:4},{lngs:["ar"],nr:[0,1,2,3,11,100],fc:5},{lngs:["cs","sk"],nr:[1,2,5],fc:6},{lngs:["csb","pl"],nr:[1,2,5],fc:7},{lngs:["cy"],nr:[1,2,3,8],fc:8},{lngs:["fr"],nr:[1,2],fc:9},{lngs:["ga"],nr:[1,2,3,7,11],fc:10},{lngs:["gd"],nr:[1,2,3,20],fc:11},{lngs:["is"],nr:[1,2],fc:12},{lngs:["jv"],nr:[0,1],fc:13},{lngs:["kw"],nr:[1,2,3,4],fc:14},{lngs:["lt"],nr:[1,2,10],fc:15},{lngs:["lv"],nr:[1,2,0],fc:16},{lngs:["mk"],nr:[1,2],fc:17},{lngs:["mnk"],nr:[0,1,2],fc:18},{lngs:["mt"],nr:[1,2,11,20],fc:19},{lngs:["or"],nr:[2,1],fc:2},{lngs:["ro"],nr:[1,2,20],fc:20},{lngs:["sl"],nr:[5,1,2,3],fc:21},{lngs:["he","iw"],nr:[1,2,20,21],fc:22}],Zse={1:e=>+(e>1),2:e=>+(e!=1),3:e=>0,4:e=>e%10==1&&e%100!=11?0:e%10>=2&&e%10<=4&&(e%100<10||e%100>=20)?1:2,5:e=>e==0?0:e==1?1:e==2?2:e%100>=3&&e%100<=10?3:e%100>=11?4:5,6:e=>e==1?0:e>=2&&e<=4?1:2,7:e=>e==1?0:e%10>=2&&e%10<=4&&(e%100<10||e%100>=20)?1:2,8:e=>e==1?0:e==2?1:e!=8&&e!=11?2:3,9:e=>+(e>=2),10:e=>e==1?0:e==2?1:e<7?2:e<11?3:4,11:e=>e==1||e==11?0:e==2||e==12?1:e>2&&e<20?2:3,12:e=>+(e%10!=1||e%100==11),13:e=>+(e!==0),14:e=>e==1?0:e==2?1:e==3?2:3,15:e=>e%10==1&&e%100!=11?0:e%10>=2&&(e%100<10||e%100>=20)?1:2,16:e=>e%10==1&&e%100!=11?0:e!==0?1:2,17:e=>e==1||e%10==1&&e%100!=11?0:1,18:e=>e==0?0:e==1?1:2,19:e=>e==1?0:e==0||e%100>1&&e%100<11?1:e%100>10&&e%100<20?2:3,20:e=>e==1?0:e==0||e%100>0&&e%100<20?1:2,21:e=>e%100==1?1:e%100==2?2:e%100==3||e%100==4?3:0,22:e=>e==1?0:e==2?1:(e<0||e>10)&&e%10==0?2:3};const Yse=["v1","v2","v3"],Xse=["v4"],Dk={zero:0,one:1,two:2,few:3,many:4,other:5},eoe=()=>{const e={};return Qse.forEach(t=>{t.lngs.forEach(n=>{e[n]={numbers:t.nr,plurals:Zse[t.fc]}})}),e};class toe{constructor(t){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};this.languageUtils=t,this.options=n,this.logger=Ks.create("pluralResolver"),(!this.options.compatibilityJSON||Xse.includes(this.options.compatibilityJSON))&&(typeof Intl>"u"||!Intl.PluralRules)&&(this.options.compatibilityJSON="v3",this.logger.error("Your environment seems not to be Intl API compatible, use an Intl.PluralRules polyfill. Will fallback to the compatibilityJSON v3 format handling.")),this.rules=eoe(),this.pluralRulesCache={}}addRule(t,n){this.rules[t]=n}clearCache(){this.pluralRulesCache={}}getRule(t){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(this.shouldUseIntlApi())try{const r=fh(t==="dev"?"en":t),s=n.ordinal?"ordinal":"cardinal",o=JSON.stringify({cleanedCode:r,type:s});if(o in this.pluralRulesCache)return this.pluralRulesCache[o];const l=new Intl.PluralRules(r,{type:s});return this.pluralRulesCache[o]=l,l}catch{return}return this.rules[t]||this.rules[this.languageUtils.getLanguagePartFromCode(t)]}needsPlural(t){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const r=this.getRule(t,n);return this.shouldUseIntlApi()?r&&r.resolvedOptions().pluralCategories.length>1:r&&r.numbers.length>1}getPluralFormsOfKey(t,n){let r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};return this.getSuffixes(t,r).map(s=>`${n}${s}`)}getSuffixes(t){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const r=this.getRule(t,n);return r?this.shouldUseIntlApi()?r.resolvedOptions().pluralCategories.sort((s,o)=>Dk[s]-Dk[o]).map(s=>`${this.options.prepend}${n.ordinal?`ordinal${this.options.prepend}`:""}${s}`):r.numbers.map(s=>this.getSuffix(t,s,n)):[]}getSuffix(t,n){let r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};const s=this.getRule(t,r);return s?this.shouldUseIntlApi()?`${this.options.prepend}${r.ordinal?`ordinal${this.options.prepend}`:""}${s.select(n)}`:this.getSuffixRetroCompatible(s,n):(this.logger.warn(`no plural rule found for: ${t}`),"")}getSuffixRetroCompatible(t,n){const r=t.noAbs?t.plurals(n):t.plurals(Math.abs(n));let s=t.numbers[r];this.options.simplifyPluralSuffix&&t.numbers.length===2&&t.numbers[0]===1&&(s===2?s="plural":s===1&&(s=""));const o=()=>this.options.prepend&&s.toString()?this.options.prepend+s.toString():s.toString();return this.options.compatibilityJSON==="v1"?s===1?"":typeof s=="number"?`_plural_${s.toString()}`:o():this.options.compatibilityJSON==="v2"||this.options.simplifyPluralSuffix&&t.numbers.length===2&&t.numbers[0]===1?o():this.options.prepend&&r.toString()?this.options.prepend+r.toString():r.toString()}shouldUseIntlApi(){return!Yse.includes(this.options.compatibilityJSON)}}const Fk=function(e,t,n){let r=arguments.length>3&&arguments[3]!==void 0?arguments[3]:".",s=arguments.length>4&&arguments[4]!==void 0?arguments[4]:!0,o=Vse(e,t,n);return!o&&s&&typeof n=="string"&&(o=Mb(e,n,r),o===void 0&&(o=Mb(t,n,r))),o},wy=e=>e.replace(/\$/g,"$$$$");class noe{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this.logger=Ks.create("interpolator"),this.options=t,this.format=t.interpolation&&t.interpolation.format||(n=>n),this.init(t)}init(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};t.interpolation||(t.interpolation={escapeValue:!0});const{escape:n,escapeValue:r,useRawValueToEscape:s,prefix:o,prefixEscaped:l,suffix:u,suffixEscaped:d,formatSeparator:f,unescapeSuffix:h,unescapePrefix:m,nestingPrefix:g,nestingPrefixEscaped:x,nestingSuffix:b,nestingSuffixEscaped:w,nestingOptionsSeparator:C,maxReplaces:k,alwaysFormat:j}=t.interpolation;this.escape=n!==void 0?n:qse,this.escapeValue=r!==void 0?r:!0,this.useRawValueToEscape=s!==void 0?s:!1,this.prefix=o?Sl(o):l||"{{",this.suffix=u?Sl(u):d||"}}",this.formatSeparator=f||",",this.unescapePrefix=h?"":m||"-",this.unescapeSuffix=this.unescapePrefix?"":h||"",this.nestingPrefix=g?Sl(g):x||Sl("$t("),this.nestingSuffix=b?Sl(b):w||Sl(")"),this.nestingOptionsSeparator=C||",",this.maxReplaces=k||1e3,this.alwaysFormat=j!==void 0?j:!1,this.resetRegExp()}reset(){this.options&&this.init(this.options)}resetRegExp(){const t=(n,r)=>n&&n.source===r?(n.lastIndex=0,n):new RegExp(r,"g");this.regexp=t(this.regexp,`${this.prefix}(.+?)${this.suffix}`),this.regexpUnescape=t(this.regexpUnescape,`${this.prefix}${this.unescapePrefix}(.+?)${this.unescapeSuffix}${this.suffix}`),this.nestingRegexp=t(this.nestingRegexp,`${this.nestingPrefix}(.+?)${this.nestingSuffix}`)}interpolate(t,n,r,s){let o,l,u;const d=this.options&&this.options.interpolation&&this.options.interpolation.defaultVariables||{},f=x=>{if(x.indexOf(this.formatSeparator)<0){const k=Fk(n,d,x,this.options.keySeparator,this.options.ignoreJSONStructure);return this.alwaysFormat?this.format(k,void 0,r,{...s,...n,interpolationkey:x}):k}const b=x.split(this.formatSeparator),w=b.shift().trim(),C=b.join(this.formatSeparator).trim();return this.format(Fk(n,d,w,this.options.keySeparator,this.options.ignoreJSONStructure),C,r,{...s,...n,interpolationkey:w})};this.resetRegExp();const h=s&&s.missingInterpolationHandler||this.options.missingInterpolationHandler,m=s&&s.interpolation&&s.interpolation.skipOnVariables!==void 0?s.interpolation.skipOnVariables:this.options.interpolation.skipOnVariables;return[{regex:this.regexpUnescape,safeValue:x=>wy(x)},{regex:this.regexp,safeValue:x=>this.escapeValue?wy(this.escape(x)):wy(x)}].forEach(x=>{for(u=0;o=x.regex.exec(t);){const b=o[1].trim();if(l=f(b),l===void 0)if(typeof h=="function"){const C=h(t,o,s);l=typeof C=="string"?C:""}else if(s&&Object.prototype.hasOwnProperty.call(s,b))l="";else if(m){l=o[0];continue}else this.logger.warn(`missed to pass in variable ${b} for interpolating ${t}`),l="";else typeof l!="string"&&!this.useRawValueToEscape&&(l=Mk(l));const w=x.safeValue(l);if(t=t.replace(o[0],w),m?(x.regex.lastIndex+=l.length,x.regex.lastIndex-=o[0].length):x.regex.lastIndex=0,u++,u>=this.maxReplaces)break}}),t}nest(t,n){let r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},s,o,l;const u=(d,f)=>{const h=this.nestingOptionsSeparator;if(d.indexOf(h)<0)return d;const m=d.split(new RegExp(`${h}[ ]*{`));let g=`{${m[1]}`;d=m[0],g=this.interpolate(g,l);const x=g.match(/'/g),b=g.match(/"/g);(x&&x.length%2===0&&!b||b.length%2!==0)&&(g=g.replace(/'/g,'"'));try{l=JSON.parse(g),f&&(l={...f,...l})}catch(w){return this.logger.warn(`failed parsing options string in nesting for key ${d}`,w),`${d}${h}${g}`}return l.defaultValue&&l.defaultValue.indexOf(this.prefix)>-1&&delete l.defaultValue,d};for(;s=this.nestingRegexp.exec(t);){let d=[];l={...r},l=l.replace&&typeof l.replace!="string"?l.replace:l,l.applyPostProcessor=!1,delete l.defaultValue;let f=!1;if(s[0].indexOf(this.formatSeparator)!==-1&&!/{.*}/.test(s[1])){const h=s[1].split(this.formatSeparator).map(m=>m.trim());s[1]=h.shift(),d=h,f=!0}if(o=n(u.call(this,s[1].trim(),l),l),o&&s[0]===t&&typeof o!="string")return o;typeof o!="string"&&(o=Mk(o)),o||(this.logger.warn(`missed to resolve ${s[1]} for nesting ${t}`),o=""),f&&(o=d.reduce((h,m)=>this.format(h,m,r.lng,{...r,interpolationkey:s[1].trim()}),o.trim())),t=t.replace(s[0],o),this.regexp.lastIndex=0}return t}}const roe=e=>{let t=e.toLowerCase().trim();const n={};if(e.indexOf("(")>-1){const r=e.split("(");t=r[0].toLowerCase().trim();const s=r[1].substring(0,r[1].length-1);t==="currency"&&s.indexOf(":")<0?n.currency||(n.currency=s.trim()):t==="relativetime"&&s.indexOf(":")<0?n.range||(n.range=s.trim()):s.split(";").forEach(l=>{if(l){const[u,...d]=l.split(":"),f=d.join(":").trim().replace(/^'+|'+$/g,""),h=u.trim();n[h]||(n[h]=f),f==="false"&&(n[h]=!1),f==="true"&&(n[h]=!0),isNaN(f)||(n[h]=parseInt(f,10))}})}return{formatName:t,formatOptions:n}},Cl=e=>{const t={};return(n,r,s)=>{let o=s;s&&s.interpolationkey&&s.formatParams&&s.formatParams[s.interpolationkey]&&s[s.interpolationkey]&&(o={...o,[s.interpolationkey]:void 0});const l=r+JSON.stringify(o);let u=t[l];return u||(u=e(fh(r),s),t[l]=u),u(n)}};class soe{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this.logger=Ks.create("formatter"),this.options=t,this.formats={number:Cl((n,r)=>{const s=new Intl.NumberFormat(n,{...r});return o=>s.format(o)}),currency:Cl((n,r)=>{const s=new Intl.NumberFormat(n,{...r,style:"currency"});return o=>s.format(o)}),datetime:Cl((n,r)=>{const s=new Intl.DateTimeFormat(n,{...r});return o=>s.format(o)}),relativetime:Cl((n,r)=>{const s=new Intl.RelativeTimeFormat(n,{...r});return o=>s.format(o,r.range||"day")}),list:Cl((n,r)=>{const s=new Intl.ListFormat(n,{...r});return o=>s.format(o)})},this.init(t)}init(t){const r=(arguments.length>1&&arguments[1]!==void 0?arguments[1]:{interpolation:{}}).interpolation;this.formatSeparator=r.formatSeparator?r.formatSeparator:r.formatSeparator||","}add(t,n){this.formats[t.toLowerCase().trim()]=n}addCached(t,n){this.formats[t.toLowerCase().trim()]=Cl(n)}format(t,n,r){let s=arguments.length>3&&arguments[3]!==void 0?arguments[3]:{};const o=n.split(this.formatSeparator);if(o.length>1&&o[0].indexOf("(")>1&&o[0].indexOf(")")<0&&o.find(u=>u.indexOf(")")>-1)){const u=o.findIndex(d=>d.indexOf(")")>-1);o[0]=[o[0],...o.splice(1,u)].join(this.formatSeparator)}return o.reduce((u,d)=>{const{formatName:f,formatOptions:h}=roe(d);if(this.formats[f]){let m=u;try{const g=s&&s.formatParams&&s.formatParams[s.interpolationkey]||{},x=g.locale||g.lng||s.locale||s.lng||r;m=this.formats[f](u,x,{...h,...s,...g})}catch(g){this.logger.warn(g)}return m}else this.logger.warn(`there was no format function for ${f}`);return u},t)}}const ooe=(e,t)=>{e.pending[t]!==void 0&&(delete e.pending[t],e.pendingCount--)};class aoe extends kg{constructor(t,n,r){let s=arguments.length>3&&arguments[3]!==void 0?arguments[3]:{};super(),this.backend=t,this.store=n,this.services=r,this.languageUtils=r.languageUtils,this.options=s,this.logger=Ks.create("backendConnector"),this.waitingReads=[],this.maxParallelReads=s.maxParallelReads||10,this.readingCalls=0,this.maxRetries=s.maxRetries>=0?s.maxRetries:5,this.retryTimeout=s.retryTimeout>=1?s.retryTimeout:350,this.state={},this.queue=[],this.backend&&this.backend.init&&this.backend.init(r,s.backend,s)}queueLoad(t,n,r,s){const o={},l={},u={},d={};return t.forEach(f=>{let h=!0;n.forEach(m=>{const g=`${f}|${m}`;!r.reload&&this.store.hasResourceBundle(f,m)?this.state[g]=2:this.state[g]<0||(this.state[g]===1?l[g]===void 0&&(l[g]=!0):(this.state[g]=1,h=!1,l[g]===void 0&&(l[g]=!0),o[g]===void 0&&(o[g]=!0),d[m]===void 0&&(d[m]=!0)))}),h||(u[f]=!0)}),(Object.keys(o).length||Object.keys(l).length)&&this.queue.push({pending:l,pendingCount:Object.keys(l).length,loaded:{},errors:[],callback:s}),{toLoad:Object.keys(o),pending:Object.keys(l),toLoadLanguages:Object.keys(u),toLoadNamespaces:Object.keys(d)}}loaded(t,n,r){const s=t.split("|"),o=s[0],l=s[1];n&&this.emit("failedLoading",o,l,n),!n&&r&&this.store.addResourceBundle(o,l,r,void 0,void 0,{skipCopy:!0}),this.state[t]=n?-1:2,n&&r&&(this.state[t]=0);const u={};this.queue.forEach(d=>{Use(d.loaded,[o],l),ooe(d,t),n&&d.errors.push(n),d.pendingCount===0&&!d.done&&(Object.keys(d.loaded).forEach(f=>{u[f]||(u[f]={});const h=d.loaded[f];h.length&&h.forEach(m=>{u[f][m]===void 0&&(u[f][m]=!0)})}),d.done=!0,d.errors.length?d.callback(d.errors):d.callback())}),this.emit("loaded",u),this.queue=this.queue.filter(d=>!d.done)}read(t,n,r){let s=arguments.length>3&&arguments[3]!==void 0?arguments[3]:0,o=arguments.length>4&&arguments[4]!==void 0?arguments[4]:this.retryTimeout,l=arguments.length>5?arguments[5]:void 0;if(!t.length)return l(null,{});if(this.readingCalls>=this.maxParallelReads){this.waitingReads.push({lng:t,ns:n,fcName:r,tried:s,wait:o,callback:l});return}this.readingCalls++;const u=(f,h)=>{if(this.readingCalls--,this.waitingReads.length>0){const m=this.waitingReads.shift();this.read(m.lng,m.ns,m.fcName,m.tried,m.wait,m.callback)}if(f&&h&&s{this.read.call(this,t,n,r,s+1,o*2,l)},o);return}l(f,h)},d=this.backend[r].bind(this.backend);if(d.length===2){try{const f=d(t,n);f&&typeof f.then=="function"?f.then(h=>u(null,h)).catch(u):u(null,f)}catch(f){u(f)}return}return d(t,n,u)}prepareLoading(t,n){let r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},s=arguments.length>3?arguments[3]:void 0;if(!this.backend)return this.logger.warn("No backend was added via i18next.use. Will not load resources."),s&&s();typeof t=="string"&&(t=this.languageUtils.toResolveHierarchy(t)),typeof n=="string"&&(n=[n]);const o=this.queueLoad(t,n,r,s);if(!o.toLoad.length)return o.pending.length||s(),null;o.toLoad.forEach(l=>{this.loadOne(l)})}load(t,n,r){this.prepareLoading(t,n,{},r)}reload(t,n,r){this.prepareLoading(t,n,{reload:!0},r)}loadOne(t){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"";const r=t.split("|"),s=r[0],o=r[1];this.read(s,o,"read",void 0,void 0,(l,u)=>{l&&this.logger.warn(`${n}loading namespace ${o} for language ${s} failed`,l),!l&&u&&this.logger.log(`${n}loaded namespace ${o} for language ${s}`,u),this.loaded(t,l,u)})}saveMissing(t,n,r,s,o){let l=arguments.length>5&&arguments[5]!==void 0?arguments[5]:{},u=arguments.length>6&&arguments[6]!==void 0?arguments[6]:()=>{};if(this.services.utils&&this.services.utils.hasLoadedNamespace&&!this.services.utils.hasLoadedNamespace(n)){this.logger.warn(`did not save key "${r}" as the namespace "${n}" was not yet loaded`,"This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!");return}if(!(r==null||r==="")){if(this.backend&&this.backend.create){const d={...l,isUpdate:o},f=this.backend.create.bind(this.backend);if(f.length<6)try{let h;f.length===5?h=f(t,n,r,s,d):h=f(t,n,r,s),h&&typeof h.then=="function"?h.then(m=>u(null,m)).catch(u):u(null,h)}catch(h){u(h)}else f(t,n,r,s,u,d)}!t||!t[0]||this.store.addResource(t[0],n,r,s)}}}const Lk=()=>({debug:!1,initImmediate:!0,ns:["translation"],defaultNS:["translation"],fallbackLng:["dev"],fallbackNS:!1,supportedLngs:!1,nonExplicitSupportedLngs:!1,load:"all",preload:!1,simplifyPluralSuffix:!0,keySeparator:".",nsSeparator:":",pluralSeparator:"_",contextSeparator:"_",partialBundledLanguages:!1,saveMissing:!1,updateMissing:!1,saveMissingTo:"fallback",saveMissingPlurals:!0,missingKeyHandler:!1,missingInterpolationHandler:!1,postProcess:!1,postProcessPassResolved:!1,returnNull:!1,returnEmptyString:!0,returnObjects:!1,joinArrays:!1,returnedObjectHandler:!1,parseMissingKeyHandler:!1,appendNamespaceToMissingKey:!1,appendNamespaceToCIMode:!1,overloadTranslationOptionHandler:e=>{let t={};if(typeof e[1]=="object"&&(t=e[1]),typeof e[1]=="string"&&(t.defaultValue=e[1]),typeof e[2]=="string"&&(t.tDescription=e[2]),typeof e[2]=="object"||typeof e[3]=="object"){const n=e[3]||e[2];Object.keys(n).forEach(r=>{t[r]=n[r]})}return t},interpolation:{escapeValue:!0,format:e=>e,prefix:"{{",suffix:"}}",formatSeparator:",",unescapePrefix:"-",nestingPrefix:"$t(",nestingSuffix:")",nestingOptionsSeparator:",",maxReplaces:1e3,skipOnVariables:!0}}),$k=e=>(typeof e.ns=="string"&&(e.ns=[e.ns]),typeof e.fallbackLng=="string"&&(e.fallbackLng=[e.fallbackLng]),typeof e.fallbackNS=="string"&&(e.fallbackNS=[e.fallbackNS]),e.supportedLngs&&e.supportedLngs.indexOf("cimode")<0&&(e.supportedLngs=e.supportedLngs.concat(["cimode"])),e),lp=()=>{},ioe=e=>{Object.getOwnPropertyNames(Object.getPrototypeOf(e)).forEach(n=>{typeof e[n]=="function"&&(e[n]=e[n].bind(e))})};class dd extends kg{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(super(),this.options=$k(t),this.services={},this.logger=Ks,this.modules={external:[]},ioe(this),n&&!this.isInitialized&&!t.isClone){if(!this.options.initImmediate)return this.init(t,n),this;setTimeout(()=>{this.init(t,n)},0)}}init(){var t=this;let n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},r=arguments.length>1?arguments[1]:void 0;this.isInitializing=!0,typeof n=="function"&&(r=n,n={}),!n.defaultNS&&n.defaultNS!==!1&&n.ns&&(typeof n.ns=="string"?n.defaultNS=n.ns:n.ns.indexOf("translation")<0&&(n.defaultNS=n.ns[0]));const s=Lk();this.options={...s,...this.options,...$k(n)},this.options.compatibilityAPI!=="v1"&&(this.options.interpolation={...s.interpolation,...this.options.interpolation}),n.keySeparator!==void 0&&(this.options.userDefinedKeySeparator=n.keySeparator),n.nsSeparator!==void 0&&(this.options.userDefinedNsSeparator=n.nsSeparator);const o=h=>h?typeof h=="function"?new h:h:null;if(!this.options.isClone){this.modules.logger?Ks.init(o(this.modules.logger),this.options):Ks.init(null,this.options);let h;this.modules.formatter?h=this.modules.formatter:typeof Intl<"u"&&(h=soe);const m=new Ak(this.options);this.store=new Ok(this.options.resources,this.options);const g=this.services;g.logger=Ks,g.resourceStore=this.store,g.languageUtils=m,g.pluralResolver=new toe(m,{prepend:this.options.pluralSeparator,compatibilityJSON:this.options.compatibilityJSON,simplifyPluralSuffix:this.options.simplifyPluralSuffix}),h&&(!this.options.interpolation.format||this.options.interpolation.format===s.interpolation.format)&&(g.formatter=o(h),g.formatter.init(g,this.options),this.options.interpolation.format=g.formatter.format.bind(g.formatter)),g.interpolator=new noe(this.options),g.utils={hasLoadedNamespace:this.hasLoadedNamespace.bind(this)},g.backendConnector=new aoe(o(this.modules.backend),g.resourceStore,g,this.options),g.backendConnector.on("*",function(x){for(var b=arguments.length,w=new Array(b>1?b-1:0),C=1;C1?b-1:0),C=1;C{x.init&&x.init(this)})}if(this.format=this.options.interpolation.format,r||(r=lp),this.options.fallbackLng&&!this.services.languageDetector&&!this.options.lng){const h=this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);h.length>0&&h[0]!=="dev"&&(this.options.lng=h[0])}!this.services.languageDetector&&!this.options.lng&&this.logger.warn("init: no languageDetector is used and no lng is defined"),["getResource","hasResourceBundle","getResourceBundle","getDataByLanguage"].forEach(h=>{this[h]=function(){return t.store[h](...arguments)}}),["addResource","addResources","addResourceBundle","removeResourceBundle"].forEach(h=>{this[h]=function(){return t.store[h](...arguments),t}});const d=hu(),f=()=>{const h=(m,g)=>{this.isInitializing=!1,this.isInitialized&&!this.initializedStoreOnce&&this.logger.warn("init: i18next is already initialized. You should call init just once!"),this.isInitialized=!0,this.options.isClone||this.logger.log("initialized",this.options),this.emit("initialized",this.options),d.resolve(g),r(m,g)};if(this.languages&&this.options.compatibilityAPI!=="v1"&&!this.isInitialized)return h(null,this.t.bind(this));this.changeLanguage(this.options.lng,h)};return this.options.resources||!this.options.initImmediate?f():setTimeout(f,0),d}loadResources(t){let r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:lp;const s=typeof t=="string"?t:this.language;if(typeof t=="function"&&(r=t),!this.options.resources||this.options.partialBundledLanguages){if(s&&s.toLowerCase()==="cimode"&&(!this.options.preload||this.options.preload.length===0))return r();const o=[],l=u=>{if(!u||u==="cimode")return;this.services.languageUtils.toResolveHierarchy(u).forEach(f=>{f!=="cimode"&&o.indexOf(f)<0&&o.push(f)})};s?l(s):this.services.languageUtils.getFallbackCodes(this.options.fallbackLng).forEach(d=>l(d)),this.options.preload&&this.options.preload.forEach(u=>l(u)),this.services.backendConnector.load(o,this.options.ns,u=>{!u&&!this.resolvedLanguage&&this.language&&this.setResolvedLanguage(this.language),r(u)})}else r(null)}reloadResources(t,n,r){const s=hu();return typeof t=="function"&&(r=t,t=void 0),typeof n=="function"&&(r=n,n=void 0),t||(t=this.languages),n||(n=this.options.ns),r||(r=lp),this.services.backendConnector.reload(t,n,o=>{s.resolve(),r(o)}),s}use(t){if(!t)throw new Error("You are passing an undefined module! Please check the object you are passing to i18next.use()");if(!t.type)throw new Error("You are passing a wrong module! Please check the object you are passing to i18next.use()");return t.type==="backend"&&(this.modules.backend=t),(t.type==="logger"||t.log&&t.warn&&t.error)&&(this.modules.logger=t),t.type==="languageDetector"&&(this.modules.languageDetector=t),t.type==="i18nFormat"&&(this.modules.i18nFormat=t),t.type==="postProcessor"&&qI.addPostProcessor(t),t.type==="formatter"&&(this.modules.formatter=t),t.type==="3rdParty"&&this.modules.external.push(t),this}setResolvedLanguage(t){if(!(!t||!this.languages)&&!(["cimode","dev"].indexOf(t)>-1))for(let n=0;n-1)&&this.store.hasLanguageSomeTranslations(r)){this.resolvedLanguage=r;break}}}changeLanguage(t,n){var r=this;this.isLanguageChangingTo=t;const s=hu();this.emit("languageChanging",t);const o=d=>{this.language=d,this.languages=this.services.languageUtils.toResolveHierarchy(d),this.resolvedLanguage=void 0,this.setResolvedLanguage(d)},l=(d,f)=>{f?(o(f),this.translator.changeLanguage(f),this.isLanguageChangingTo=void 0,this.emit("languageChanged",f),this.logger.log("languageChanged",f)):this.isLanguageChangingTo=void 0,s.resolve(function(){return r.t(...arguments)}),n&&n(d,function(){return r.t(...arguments)})},u=d=>{!t&&!d&&this.services.languageDetector&&(d=[]);const f=typeof d=="string"?d:this.services.languageUtils.getBestMatchFromCodes(d);f&&(this.language||o(f),this.translator.language||this.translator.changeLanguage(f),this.services.languageDetector&&this.services.languageDetector.cacheUserLanguage&&this.services.languageDetector.cacheUserLanguage(f)),this.loadResources(f,h=>{l(h,f)})};return!t&&this.services.languageDetector&&!this.services.languageDetector.async?u(this.services.languageDetector.detect()):!t&&this.services.languageDetector&&this.services.languageDetector.async?this.services.languageDetector.detect.length===0?this.services.languageDetector.detect().then(u):this.services.languageDetector.detect(u):u(t),s}getFixedT(t,n,r){var s=this;const o=function(l,u){let d;if(typeof u!="object"){for(var f=arguments.length,h=new Array(f>2?f-2:0),m=2;m`${d.keyPrefix}${g}${b}`):x=d.keyPrefix?`${d.keyPrefix}${g}${l}`:l,s.t(x,d)};return typeof t=="string"?o.lng=t:o.lngs=t,o.ns=n,o.keyPrefix=r,o}t(){return this.translator&&this.translator.translate(...arguments)}exists(){return this.translator&&this.translator.exists(...arguments)}setDefaultNamespace(t){this.options.defaultNS=t}hasLoadedNamespace(t){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(!this.isInitialized)return this.logger.warn("hasLoadedNamespace: i18next was not initialized",this.languages),!1;if(!this.languages||!this.languages.length)return this.logger.warn("hasLoadedNamespace: i18n.languages were undefined or empty",this.languages),!1;const r=n.lng||this.resolvedLanguage||this.languages[0],s=this.options?this.options.fallbackLng:!1,o=this.languages[this.languages.length-1];if(r.toLowerCase()==="cimode")return!0;const l=(u,d)=>{const f=this.services.backendConnector.state[`${u}|${d}`];return f===-1||f===0||f===2};if(n.precheck){const u=n.precheck(this,l);if(u!==void 0)return u}return!!(this.hasResourceBundle(r,t)||!this.services.backendConnector.backend||this.options.resources&&!this.options.partialBundledLanguages||l(r,t)&&(!s||l(o,t)))}loadNamespaces(t,n){const r=hu();return this.options.ns?(typeof t=="string"&&(t=[t]),t.forEach(s=>{this.options.ns.indexOf(s)<0&&this.options.ns.push(s)}),this.loadResources(s=>{r.resolve(),n&&n(s)}),r):(n&&n(),Promise.resolve())}loadLanguages(t,n){const r=hu();typeof t=="string"&&(t=[t]);const s=this.options.preload||[],o=t.filter(l=>s.indexOf(l)<0&&this.services.languageUtils.isSupportedCode(l));return o.length?(this.options.preload=s.concat(o),this.loadResources(l=>{r.resolve(),n&&n(l)}),r):(n&&n(),Promise.resolve())}dir(t){if(t||(t=this.resolvedLanguage||(this.languages&&this.languages.length>0?this.languages[0]:this.language)),!t)return"rtl";const n=["ar","shu","sqr","ssh","xaa","yhd","yud","aao","abh","abv","acm","acq","acw","acx","acy","adf","ads","aeb","aec","afb","ajp","apc","apd","arb","arq","ars","ary","arz","auz","avl","ayh","ayl","ayn","ayp","bbz","pga","he","iw","ps","pbt","pbu","pst","prp","prd","ug","ur","ydd","yds","yih","ji","yi","hbo","men","xmn","fa","jpr","peo","pes","prs","dv","sam","ckb"],r=this.services&&this.services.languageUtils||new Ak(Lk());return n.indexOf(r.getLanguagePartFromCode(t))>-1||t.toLowerCase().indexOf("-arab")>1?"rtl":"ltr"}static createInstance(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;return new dd(t,n)}cloneInstance(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:lp;const r=t.forkResourceStore;r&&delete t.forkResourceStore;const s={...this.options,...t,isClone:!0},o=new dd(s);return(t.debug!==void 0||t.prefix!==void 0)&&(o.logger=o.logger.clone(t)),["store","services","language"].forEach(u=>{o[u]=this[u]}),o.services={...this.services},o.services.utils={hasLoadedNamespace:o.hasLoadedNamespace.bind(o)},r&&(o.store=new Ok(this.store.data,s),o.services.resourceStore=o.store),o.translator=new ph(o.services,s),o.translator.on("*",function(u){for(var d=arguments.length,f=new Array(d>1?d-1:0),h=1;h:not([hidden])~:not([hidden]){--tw-space-x-reverse: 0;margin-right:calc(.75rem * var(--tw-space-x-reverse));margin-left:calc(.75rem * calc(1 - var(--tw-space-x-reverse)))}.space-y-1>:not([hidden])~:not([hidden]){--tw-space-y-reverse: 0;margin-top:calc(.25rem * calc(1 - var(--tw-space-y-reverse)));margin-bottom:calc(.25rem * var(--tw-space-y-reverse))}.space-y-1\.5>:not([hidden])~:not([hidden]){--tw-space-y-reverse: 0;margin-top:calc(.375rem * calc(1 - var(--tw-space-y-reverse)));margin-bottom:calc(.375rem * var(--tw-space-y-reverse))}.space-y-2>:not([hidden])~:not([hidden]){--tw-space-y-reverse: 0;margin-top:calc(.5rem * calc(1 - var(--tw-space-y-reverse)));margin-bottom:calc(.5rem * var(--tw-space-y-reverse))}.space-y-4>:not([hidden])~:not([hidden]){--tw-space-y-reverse: 0;margin-top:calc(1rem * calc(1 - var(--tw-space-y-reverse)));margin-bottom:calc(1rem * var(--tw-space-y-reverse))}.space-y-6>:not([hidden])~:not([hidden]){--tw-space-y-reverse: 0;margin-top:calc(1.5rem * calc(1 - var(--tw-space-y-reverse)));margin-bottom:calc(1.5rem * var(--tw-space-y-reverse))}.divide-x>:not([hidden])~:not([hidden]){--tw-divide-x-reverse: 0;border-right-width:calc(1px * var(--tw-divide-x-reverse));border-left-width:calc(1px * calc(1 - var(--tw-divide-x-reverse)))}.divide-y>:not([hidden])~:not([hidden]){--tw-divide-y-reverse: 0;border-top-width:calc(1px * calc(1 - var(--tw-divide-y-reverse)));border-bottom-width:calc(1px * var(--tw-divide-y-reverse))}.self-end{align-self:flex-end}.overflow-auto{overflow:auto}.overflow-hidden{overflow:hidden}.overflow-visible{overflow:visible}.overflow-y-auto{overflow-y:auto}.overflow-x-hidden{overflow-x:hidden}.truncate{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.overflow-ellipsis,.text-ellipsis{text-overflow:ellipsis}.whitespace-nowrap{white-space:nowrap}.whitespace-pre-wrap{white-space:pre-wrap}.text-wrap{text-wrap:wrap}.break-words{overflow-wrap:break-word}.break-all{word-break:break-all}.rounded{border-radius:.25rem}.rounded-3xl{border-radius:1.5rem}.rounded-\[16px\]{border-radius:16px}.rounded-\[2px\]{border-radius:2px}.rounded-\[inherit\]{border-radius:inherit}.rounded-full{border-radius:9999px}.rounded-lg{border-radius:var(--radius)}.rounded-md{border-radius:calc(var(--radius) - 2px)}.rounded-none{border-radius:0}.rounded-sm{border-radius:calc(var(--radius) - 4px)}.rounded-xl{border-radius:.75rem}.rounded-l-lg{border-top-left-radius:var(--radius);border-bottom-left-radius:var(--radius)}.border{border-width:1px}.border-2{border-width:2px}.border-\[1\.5px\]{border-width:1.5px}.border-b{border-bottom-width:1px}.border-l{border-left-width:1px}.border-r{border-right-width:1px}.border-t{border-top-width:1px}.border-dashed{border-style:dashed}.border-none{border-style:none}.border-\[--color-border\]{border-color:var(--color-border)}.border-amber-500\/20{border-color:#f59e0b33}.border-black{--tw-border-opacity: 1;border-color:rgb(0 0 0 / var(--tw-border-opacity))}.border-black\/10{border-color:#0000001a}.border-border{border-color:hsl(var(--border))}.border-border\/50{border-color:hsl(var(--border) / .5)}.border-emerald-500\/20{border-color:#10b98133}.border-gray-300{--tw-border-opacity: 1;border-color:rgb(209 213 219 / var(--tw-border-opacity))}.border-gray-600\/50{border-color:#4b556380}.border-input{border-color:hsl(var(--input))}.border-muted{border-color:hsl(var(--muted))}.border-red-500\/20{border-color:#ef444433}.border-sky-500\/20{border-color:#0ea5e933}.border-slate-600{--tw-border-opacity: 1;border-color:rgb(71 85 105 / var(--tw-border-opacity))}.border-transparent{border-color:transparent}.border-zinc-500\/20{border-color:#71717a33}.border-l-transparent{border-left-color:transparent}.border-t-transparent{border-top-color:transparent}.bg-\[\#b2ece0\]{--tw-bg-opacity: 1;background-color:rgb(178 236 224 / var(--tw-bg-opacity))}.bg-\[\#c8fff2\]{--tw-bg-opacity: 1;background-color:rgb(200 255 242 / var(--tw-bg-opacity))}.bg-\[\#d2e2e2\]{--tw-bg-opacity: 1;background-color:rgb(210 226 226 / var(--tw-bg-opacity))}.bg-\[\#e0f0f0\]{--tw-bg-opacity: 1;background-color:rgb(224 240 240 / var(--tw-bg-opacity))}.bg-\[--color-bg\]{background-color:var(--color-bg)}.bg-amber-50\/50{background-color:#fffbeb80}.bg-amber-600{--tw-bg-opacity: 1;background-color:rgb(217 119 6 / var(--tw-bg-opacity))}.bg-background{background-color:hsl(var(--background))}.bg-background\/80{background-color:hsl(var(--background) / .8)}.bg-black\/10{background-color:#0000001a}.bg-black\/5{background-color:#0000000d}.bg-blue-100{--tw-bg-opacity: 1;background-color:rgb(219 234 254 / var(--tw-bg-opacity))}.bg-blue-700{--tw-bg-opacity: 1;background-color:rgb(29 78 216 / var(--tw-bg-opacity))}.bg-border{background-color:hsl(var(--border))}.bg-card{background-color:hsl(var(--card))}.bg-destructive{background-color:hsl(var(--destructive))}.bg-emerald-50\/50{background-color:#ecfdf580}.bg-gray-100{--tw-bg-opacity: 1;background-color:rgb(243 244 246 / var(--tw-bg-opacity))}.bg-muted{background-color:hsl(var(--muted))}.bg-muted\/50{background-color:hsl(var(--muted) / .5)}.bg-popover{background-color:hsl(var(--popover))}.bg-primary{background-color:hsl(var(--primary))}.bg-primary\/20{background-color:hsl(var(--primary) / .2)}.bg-primary\/30{background-color:hsl(var(--primary) / .3)}.bg-red-50{--tw-bg-opacity: 1;background-color:rgb(254 242 242 / var(--tw-bg-opacity))}.bg-red-50\/50{background-color:#fef2f280}.bg-secondary{background-color:hsl(var(--secondary))}.bg-sky-50\/50{background-color:#f0f9ff80}.bg-slate-700{--tw-bg-opacity: 1;background-color:rgb(51 65 85 / var(--tw-bg-opacity))}.bg-transparent{background-color:transparent}.bg-yellow-50{--tw-bg-opacity: 1;background-color:rgb(254 252 232 / var(--tw-bg-opacity))}.bg-zinc-50\/50{background-color:#fafafa80}.fill-current{fill:currentColor}.fill-gray-100{fill:#f3f4f6}.object-contain{-o-object-fit:contain;object-fit:contain}.object-cover{-o-object-fit:cover;object-fit:cover}.p-0{padding:0}.p-1{padding:.25rem}.p-1\.5{padding:.375rem}.p-2{padding:.5rem}.p-3{padding:.75rem}.p-4{padding:1rem}.p-5{padding:1.25rem}.p-6{padding:1.5rem}.p-8{padding:2rem}.p-\[0\.375rem_1rem_0_1rem\]{padding:.375rem 1rem 0}.p-\[1px\]{padding:1px}.px-1{padding-left:.25rem;padding-right:.25rem}.px-2{padding-left:.5rem;padding-right:.5rem}.px-2\.5{padding-left:.625rem;padding-right:.625rem}.px-3{padding-left:.75rem;padding-right:.75rem}.px-4{padding-left:1rem;padding-right:1rem}.px-8{padding-left:2rem;padding-right:2rem}.py-0\.5{padding-top:.125rem;padding-bottom:.125rem}.py-1{padding-top:.25rem;padding-bottom:.25rem}.py-1\.5{padding-top:.375rem;padding-bottom:.375rem}.py-16{padding-top:4rem;padding-bottom:4rem}.py-2{padding-top:.5rem;padding-bottom:.5rem}.py-3{padding-top:.75rem;padding-bottom:.75rem}.py-4{padding-top:1rem;padding-bottom:1rem}.py-6{padding-top:1.5rem;padding-bottom:1.5rem}.pb-3{padding-bottom:.75rem}.pl-2{padding-left:.5rem}.pl-3{padding-left:.75rem}.pl-4{padding-left:1rem}.pl-8{padding-left:2rem}.pr-2{padding-right:.5rem}.pr-4{padding-right:1rem}.pt-0{padding-top:0}.pt-2{padding-top:.5rem}.pt-3{padding-top:.75rem}.pt-5{padding-top:1.25rem}.pt-6{padding-top:1.5rem}.text-left{text-align:left}.text-center{text-align:center}.text-right{text-align:right}.align-middle{vertical-align:middle}.font-mono{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace}.text-2xl{font-size:1.5rem;line-height:2rem}.text-4xl{font-size:2.25rem;line-height:2.5rem}.text-base{font-size:1rem;line-height:1.5rem}.text-lg{font-size:1.125rem;line-height:1.75rem}.text-sm{font-size:.875rem;line-height:1.25rem}.text-xl{font-size:1.25rem;line-height:1.75rem}.text-xs{font-size:.75rem;line-height:1rem}.font-bold{font-weight:700}.font-medium{font-weight:500}.font-normal{font-weight:400}.font-semibold{font-weight:600}.tabular-nums{--tw-numeric-spacing: tabular-nums;font-variant-numeric:var(--tw-ordinal) var(--tw-slashed-zero) var(--tw-numeric-figure) var(--tw-numeric-spacing) var(--tw-numeric-fraction)}.leading-none{line-height:1}.tracking-tight{letter-spacing:-.025em}.tracking-wide{letter-spacing:.025em}.tracking-widest{letter-spacing:.1em}.text-\[\#008069\]{--tw-text-opacity: 1;color:rgb(0 128 105 / var(--tw-text-opacity))}.text-\[\#b03f3f\]{--tw-text-opacity: 1;color:rgb(176 63 63 / var(--tw-text-opacity))}.text-amber-100{--tw-text-opacity: 1;color:rgb(254 243 199 / var(--tw-text-opacity))}.text-amber-900{--tw-text-opacity: 1;color:rgb(120 53 15 / var(--tw-text-opacity))}.text-black{--tw-text-opacity: 1;color:rgb(0 0 0 / var(--tw-text-opacity))}.text-blue-600{--tw-text-opacity: 1;color:rgb(37 99 235 / var(--tw-text-opacity))}.text-blue-700{--tw-text-opacity: 1;color:rgb(29 78 216 / var(--tw-text-opacity))}.text-card-foreground{color:hsl(var(--card-foreground))}.text-destructive-foreground{color:hsl(var(--destructive-foreground))}.text-emerald-900{--tw-text-opacity: 1;color:rgb(6 78 59 / var(--tw-text-opacity))}.text-foreground{color:hsl(var(--foreground))}.text-gray-500{--tw-text-opacity: 1;color:rgb(107 114 128 / var(--tw-text-opacity))}.text-gray-600{--tw-text-opacity: 1;color:rgb(75 85 99 / var(--tw-text-opacity))}.text-gray-900{--tw-text-opacity: 1;color:rgb(17 24 39 / var(--tw-text-opacity))}.text-muted-foreground{color:hsl(var(--muted-foreground))}.text-muted-foreground\/80{color:hsl(var(--muted-foreground) / .8)}.text-popover-foreground{color:hsl(var(--popover-foreground))}.text-primary{color:hsl(var(--primary))}.text-primary-foreground{color:hsl(var(--primary-foreground))}.text-red-500{--tw-text-opacity: 1;color:rgb(239 68 68 / var(--tw-text-opacity))}.text-red-800{--tw-text-opacity: 1;color:rgb(153 27 27 / var(--tw-text-opacity))}.text-red-900{--tw-text-opacity: 1;color:rgb(127 29 29 / var(--tw-text-opacity))}.text-rose-600{--tw-text-opacity: 1;color:rgb(225 29 72 / var(--tw-text-opacity))}.text-secondary-foreground{color:hsl(var(--secondary-foreground))}.text-sky-900{--tw-text-opacity: 1;color:rgb(12 74 110 / var(--tw-text-opacity))}.text-slate-300{--tw-text-opacity: 1;color:rgb(203 213 225 / var(--tw-text-opacity))}.text-zinc-900{--tw-text-opacity: 1;color:rgb(24 24 27 / var(--tw-text-opacity))}.underline-offset-4{text-underline-offset:4px}.caret-transparent{caret-color:transparent}.opacity-0{opacity:0}.opacity-50{opacity:.5}.opacity-60{opacity:.6}.opacity-70{opacity:.7}.shadow-lg{--tw-shadow: 0 10px 15px -3px rgb(0 0 0 / .1), 0 4px 6px -4px rgb(0 0 0 / .1);--tw-shadow-colored: 0 10px 15px -3px var(--tw-shadow-color), 0 4px 6px -4px var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000),var(--tw-ring-shadow, 0 0 #0000),var(--tw-shadow)}.shadow-md{--tw-shadow: 0 4px 6px -1px rgb(0 0 0 / .1), 0 2px 4px -2px rgb(0 0 0 / .1);--tw-shadow-colored: 0 4px 6px -1px var(--tw-shadow-color), 0 2px 4px -2px var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000),var(--tw-ring-shadow, 0 0 #0000),var(--tw-shadow)}.shadow-none{--tw-shadow: 0 0 #0000;--tw-shadow-colored: 0 0 #0000;box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000),var(--tw-ring-shadow, 0 0 #0000),var(--tw-shadow)}.shadow-sm{--tw-shadow: 0 1px 2px 0 rgb(0 0 0 / .05);--tw-shadow-colored: 0 1px 2px 0 var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000),var(--tw-ring-shadow, 0 0 #0000),var(--tw-shadow)}.shadow-xl{--tw-shadow: 0 20px 25px -5px rgb(0 0 0 / .1), 0 8px 10px -6px rgb(0 0 0 / .1);--tw-shadow-colored: 0 20px 25px -5px var(--tw-shadow-color), 0 8px 10px -6px var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000),var(--tw-ring-shadow, 0 0 #0000),var(--tw-shadow)}.outline-none{outline:2px solid transparent;outline-offset:2px}.outline{outline-style:solid}.ring-0{--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(0px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow, 0 0 #0000)}.ring-2{--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow, 0 0 #0000)}.ring-muted-foreground{--tw-ring-color: hsl(var(--muted-foreground))}.ring-offset-background{--tw-ring-offset-color: hsl(var(--background))}.filter{filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)}.backdrop-blur-sm{--tw-backdrop-blur: blur(4px);-webkit-backdrop-filter:var(--tw-backdrop-blur) var(--tw-backdrop-brightness) var(--tw-backdrop-contrast) var(--tw-backdrop-grayscale) var(--tw-backdrop-hue-rotate) var(--tw-backdrop-invert) var(--tw-backdrop-opacity) var(--tw-backdrop-saturate) var(--tw-backdrop-sepia);backdrop-filter:var(--tw-backdrop-blur) var(--tw-backdrop-brightness) var(--tw-backdrop-contrast) var(--tw-backdrop-grayscale) var(--tw-backdrop-hue-rotate) var(--tw-backdrop-invert) var(--tw-backdrop-opacity) var(--tw-backdrop-saturate) var(--tw-backdrop-sepia)}.transition-all{transition-property:all;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.transition-colors{transition-property:color,background-color,border-color,text-decoration-color,fill,stroke;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.transition-opacity{transition-property:opacity;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.transition-transform{transition-property:transform;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.duration-200{transition-duration:.2s}.duration-300{transition-duration:.3s}@keyframes enter{0%{opacity:var(--tw-enter-opacity, 1);transform:translate3d(var(--tw-enter-translate-x, 0),var(--tw-enter-translate-y, 0),0) scale3d(var(--tw-enter-scale, 1),var(--tw-enter-scale, 1),var(--tw-enter-scale, 1)) rotate(var(--tw-enter-rotate, 0))}}@keyframes exit{to{opacity:var(--tw-exit-opacity, 1);transform:translate3d(var(--tw-exit-translate-x, 0),var(--tw-exit-translate-y, 0),0) scale3d(var(--tw-exit-scale, 1),var(--tw-exit-scale, 1),var(--tw-exit-scale, 1)) rotate(var(--tw-exit-rotate, 0))}}.duration-200{animation-duration:.2s}.duration-300{animation-duration:.3s}.paused{animation-play-state:paused}.file\:border-0::file-selector-button{border-width:0px}.file\:bg-transparent::file-selector-button{background-color:transparent}.file\:text-sm::file-selector-button{font-size:.875rem;line-height:1.25rem}.file\:font-medium::file-selector-button{font-weight:500}.placeholder\:text-muted-foreground::-moz-placeholder{color:hsl(var(--muted-foreground))}.placeholder\:text-muted-foreground::placeholder{color:hsl(var(--muted-foreground))}.after\:absolute:after{content:var(--tw-content);position:absolute}.after\:inset-y-0:after{content:var(--tw-content);top:0;bottom:0}.after\:bottom-\[12px\]:after{content:var(--tw-content);bottom:12px}.after\:left-1\/2:after{content:var(--tw-content);left:50%}.after\:w-1:after{content:var(--tw-content);width:.25rem}.after\:-translate-x-1\/2:after{content:var(--tw-content);--tw-translate-x: -50%;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.after\:border-\[8px\]:after{content:var(--tw-content);border-width:8px}.after\:border-solid:after{content:var(--tw-content);border-style:solid}.after\:bg-border:after{content:var(--tw-content);background-color:hsl(var(--border))}.hover\:bg-\[\#a4ecde\]:hover{--tw-bg-opacity: 1;background-color:rgb(164 236 222 / var(--tw-bg-opacity))}.hover\:bg-\[\#b2ece0\]:hover{--tw-bg-opacity: 1;background-color:rgb(178 236 224 / var(--tw-bg-opacity))}.hover\:bg-\[\#c2d2d2\]:hover{--tw-bg-opacity: 1;background-color:rgb(194 210 210 / var(--tw-bg-opacity))}.hover\:bg-accent:hover{background-color:hsl(var(--accent))}.hover\:bg-amber-600\/80:hover{background-color:#d97706cc}.hover\:bg-amber-600\/90:hover{background-color:#d97706e6}.hover\:bg-black\/10:hover{background-color:#0000001a}.hover\:bg-destructive\/80:hover{background-color:hsl(var(--destructive) / .8)}.hover\:bg-destructive\/90:hover{background-color:hsl(var(--destructive) / .9)}.hover\:bg-muted\/50:hover{background-color:hsl(var(--muted) / .5)}.hover\:bg-primary\/80:hover{background-color:hsl(var(--primary) / .8)}.hover\:bg-primary\/90:hover{background-color:hsl(var(--primary) / .9)}.hover\:bg-secondary\/80:hover{background-color:hsl(var(--secondary) / .8)}.hover\:stroke-destructive:hover{stroke:hsl(var(--destructive))}.hover\:text-accent-foreground:hover{color:hsl(var(--accent-foreground))}.hover\:underline:hover{text-decoration-line:underline}.hover\:opacity-100:hover{opacity:1}.focus\:bg-accent:focus{background-color:hsl(var(--accent))}.focus\:text-accent-foreground:focus{color:hsl(var(--accent-foreground))}.focus\:outline-none:focus{outline:2px solid transparent;outline-offset:2px}.focus\:ring-2:focus{--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow, 0 0 #0000)}.focus\:ring-ring:focus{--tw-ring-color: hsl(var(--ring))}.focus\:ring-offset-2:focus{--tw-ring-offset-width: 2px}.focus-visible\:outline-none:focus-visible{outline:2px solid transparent;outline-offset:2px}.focus-visible\:ring-0:focus-visible{--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(0px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow, 0 0 #0000)}.focus-visible\:ring-1:focus-visible{--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow, 0 0 #0000)}.focus-visible\:ring-2:focus-visible{--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow, 0 0 #0000)}.focus-visible\:ring-ring:focus-visible{--tw-ring-color: hsl(var(--ring))}.focus-visible\:ring-transparent:focus-visible{--tw-ring-color: transparent}.focus-visible\:ring-offset-0:focus-visible{--tw-ring-offset-width: 0px}.focus-visible\:ring-offset-1:focus-visible{--tw-ring-offset-width: 1px}.focus-visible\:ring-offset-2:focus-visible{--tw-ring-offset-width: 2px}.focus-visible\:ring-offset-background:focus-visible{--tw-ring-offset-color: hsl(var(--background))}.focus-visible\:ring-offset-transparent:focus-visible{--tw-ring-offset-color: transparent}.disabled\:pointer-events-none:disabled{pointer-events:none}.disabled\:cursor-default:disabled{cursor:default}.disabled\:cursor-not-allowed:disabled{cursor:not-allowed}.disabled\:opacity-50:disabled{opacity:.5}.group:hover .group-hover\:visible{visibility:visible}.group:hover .group-hover\:opacity-100{opacity:1}.peer:disabled~.peer-disabled\:cursor-not-allowed{cursor:not-allowed}.peer:disabled~.peer-disabled\:opacity-70{opacity:.7}.aria-selected\:bg-accent[aria-selected=true]{background-color:hsl(var(--accent))}.aria-selected\:text-accent-foreground[aria-selected=true]{color:hsl(var(--accent-foreground))}.data-\[disabled\]\:pointer-events-none[data-disabled]{pointer-events:none}.data-\[panel-group-direction\=vertical\]\:h-px[data-panel-group-direction=vertical]{height:1px}.data-\[panel-group-direction\=vertical\]\:w-full[data-panel-group-direction=vertical]{width:100%}.data-\[side\=bottom\]\:translate-y-1[data-side=bottom]{--tw-translate-y: .25rem;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.data-\[side\=left\]\:-translate-x-1[data-side=left]{--tw-translate-x: -.25rem;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.data-\[side\=right\]\:translate-x-1[data-side=right]{--tw-translate-x: .25rem;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.data-\[side\=top\]\:-translate-y-1[data-side=top]{--tw-translate-y: -.25rem;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.data-\[state\=checked\]\:translate-x-5[data-state=checked]{--tw-translate-x: 1.25rem;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.data-\[state\=unchecked\]\:translate-x-0[data-state=unchecked]{--tw-translate-x: 0px;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.data-\[panel-group-direction\=vertical\]\:flex-col[data-panel-group-direction=vertical]{flex-direction:column}.data-\[state\=active\]\:bg-background[data-state=active]{background-color:hsl(var(--background))}.data-\[state\=active\]\:bg-primary[data-state=active],.data-\[state\=checked\]\:bg-primary[data-state=checked]{background-color:hsl(var(--primary))}.data-\[state\=open\]\:bg-accent[data-state=open]{background-color:hsl(var(--accent))}.data-\[state\=selected\]\:bg-muted[data-state=selected]{background-color:hsl(var(--muted))}.data-\[state\=unchecked\]\:bg-slate-400[data-state=unchecked]{--tw-bg-opacity: 1;background-color:rgb(148 163 184 / var(--tw-bg-opacity))}.data-\[state\=active\]\:text-foreground[data-state=active]{color:hsl(var(--foreground))}.data-\[state\=active\]\:text-primary-foreground[data-state=active]{color:hsl(var(--primary-foreground))}.data-\[state\=open\]\:text-muted-foreground[data-state=open]{color:hsl(var(--muted-foreground))}.data-\[disabled\]\:opacity-50[data-disabled]{opacity:.5}.data-\[state\=active\]\:shadow-sm[data-state=active]{--tw-shadow: 0 1px 2px 0 rgb(0 0 0 / .05);--tw-shadow-colored: 0 1px 2px 0 var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000),var(--tw-ring-shadow, 0 0 #0000),var(--tw-shadow)}.data-\[state\=open\]\:animate-in[data-state=open]{animation-name:enter;animation-duration:.15s;--tw-enter-opacity: initial;--tw-enter-scale: initial;--tw-enter-rotate: initial;--tw-enter-translate-x: initial;--tw-enter-translate-y: initial}.data-\[state\=closed\]\:animate-out[data-state=closed]{animation-name:exit;animation-duration:.15s;--tw-exit-opacity: initial;--tw-exit-scale: initial;--tw-exit-rotate: initial;--tw-exit-translate-x: initial;--tw-exit-translate-y: initial}.data-\[state\=closed\]\:fade-out-0[data-state=closed]{--tw-exit-opacity: 0}.data-\[state\=open\]\:fade-in-0[data-state=open]{--tw-enter-opacity: 0}.data-\[state\=closed\]\:zoom-out-95[data-state=closed]{--tw-exit-scale: .95}.data-\[state\=open\]\:zoom-in-95[data-state=open]{--tw-enter-scale: .95}.data-\[side\=bottom\]\:slide-in-from-top-2[data-side=bottom]{--tw-enter-translate-y: -.5rem}.data-\[side\=left\]\:slide-in-from-right-2[data-side=left]{--tw-enter-translate-x: .5rem}.data-\[side\=right\]\:slide-in-from-left-2[data-side=right]{--tw-enter-translate-x: -.5rem}.data-\[side\=top\]\:slide-in-from-bottom-2[data-side=top]{--tw-enter-translate-y: .5rem}.data-\[state\=closed\]\:slide-out-to-left-1\/2[data-state=closed]{--tw-exit-translate-x: -50%}.data-\[state\=closed\]\:slide-out-to-top-\[48\%\][data-state=closed]{--tw-exit-translate-y: -48%}.data-\[state\=open\]\:slide-in-from-left-1\/2[data-state=open]{--tw-enter-translate-x: -50%}.data-\[state\=open\]\:slide-in-from-top-\[48\%\][data-state=open]{--tw-enter-translate-y: -48%}.data-\[panel-group-direction\=vertical\]\:after\:left-0[data-panel-group-direction=vertical]:after{content:var(--tw-content);left:0}.data-\[panel-group-direction\=vertical\]\:after\:h-1[data-panel-group-direction=vertical]:after{content:var(--tw-content);height:.25rem}.data-\[panel-group-direction\=vertical\]\:after\:w-full[data-panel-group-direction=vertical]:after{content:var(--tw-content);width:100%}.data-\[panel-group-direction\=vertical\]\:after\:-translate-y-1\/2[data-panel-group-direction=vertical]:after{content:var(--tw-content);--tw-translate-y: -50%;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.data-\[panel-group-direction\=vertical\]\:after\:translate-x-0[data-panel-group-direction=vertical]:after{content:var(--tw-content);--tw-translate-x: 0px;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.dark\:-rotate-90:is(.dark *){--tw-rotate: -90deg;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.dark\:rotate-0:is(.dark *){--tw-rotate: 0deg;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.dark\:scale-0:is(.dark *){--tw-scale-x: 0;--tw-scale-y: 0;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.dark\:scale-100:is(.dark *){--tw-scale-x: 1;--tw-scale-y: 1;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.dark\:border-amber-500\/30:is(.dark *){border-color:#f59e0b4d}.dark\:border-emerald-500\/30:is(.dark *){border-color:#10b9814d}.dark\:border-gray-700:is(.dark *){--tw-border-opacity: 1;border-color:rgb(55 65 81 / var(--tw-border-opacity))}.dark\:border-red-500\/30:is(.dark *){border-color:#ef44444d}.dark\:border-sky-500\/30:is(.dark *){border-color:#0ea5e94d}.dark\:border-white\/10:is(.dark *){border-color:#ffffff1a}.dark\:border-zinc-500\/30:is(.dark *){border-color:#71717a4d}.dark\:bg-\[\#082720\]:is(.dark *){--tw-bg-opacity: 1;background-color:rgb(8 39 32 / var(--tw-bg-opacity))}.dark\:bg-\[\#0b332a\]:is(.dark *){--tw-bg-opacity: 1;background-color:rgb(11 51 42 / var(--tw-bg-opacity))}.dark\:bg-\[\#0f1413\]:is(.dark *){--tw-bg-opacity: 1;background-color:rgb(15 20 19 / var(--tw-bg-opacity))}.dark\:bg-\[\#1d2724\]:is(.dark *){--tw-bg-opacity: 1;background-color:rgb(29 39 36 / var(--tw-bg-opacity))}.dark\:bg-amber-500\/10:is(.dark *){background-color:#f59e0b1a}.dark\:bg-blue-300:is(.dark *){--tw-bg-opacity: 1;background-color:rgb(147 197 253 / var(--tw-bg-opacity))}.dark\:bg-emerald-500\/10:is(.dark *){background-color:#10b9811a}.dark\:bg-gray-800:is(.dark *){--tw-bg-opacity: 1;background-color:rgb(31 41 55 / var(--tw-bg-opacity))}.dark\:bg-gray-900:is(.dark *){--tw-bg-opacity: 1;background-color:rgb(17 24 39 / var(--tw-bg-opacity))}.dark\:bg-red-500\/10:is(.dark *){background-color:#ef44441a}.dark\:bg-red-900:is(.dark *){--tw-bg-opacity: 1;background-color:rgb(127 29 29 / var(--tw-bg-opacity))}.dark\:bg-sky-500\/10:is(.dark *){background-color:#0ea5e91a}.dark\:bg-white\/10:is(.dark *){background-color:#ffffff1a}.dark\:bg-white\/5:is(.dark *){background-color:#ffffff0d}.dark\:bg-yellow-950:is(.dark *){--tw-bg-opacity: 1;background-color:rgb(66 32 6 / var(--tw-bg-opacity))}.dark\:bg-zinc-500\/10:is(.dark *){background-color:#71717a1a}.dark\:fill-gray-800:is(.dark *){fill:#1f2937}.dark\:text-\[\#00a884\]:is(.dark *){--tw-text-opacity: 1;color:rgb(0 168 132 / var(--tw-text-opacity))}.dark\:text-amber-200:is(.dark *){--tw-text-opacity: 1;color:rgb(253 230 138 / var(--tw-text-opacity))}.dark\:text-blue-300:is(.dark *){--tw-text-opacity: 1;color:rgb(147 197 253 / var(--tw-text-opacity))}.dark\:text-emerald-200:is(.dark *){--tw-text-opacity: 1;color:rgb(167 243 208 / var(--tw-text-opacity))}.dark\:text-gray-100:is(.dark *){--tw-text-opacity: 1;color:rgb(243 244 246 / var(--tw-text-opacity))}.dark\:text-gray-300:is(.dark *){--tw-text-opacity: 1;color:rgb(209 213 219 / var(--tw-text-opacity))}.dark\:text-gray-400:is(.dark *){--tw-text-opacity: 1;color:rgb(156 163 175 / var(--tw-text-opacity))}.dark\:text-red-200:is(.dark *){--tw-text-opacity: 1;color:rgb(254 202 202 / var(--tw-text-opacity))}.dark\:text-sky-200:is(.dark *){--tw-text-opacity: 1;color:rgb(186 230 253 / var(--tw-text-opacity))}.dark\:text-white:is(.dark *){--tw-text-opacity: 1;color:rgb(255 255 255 / var(--tw-text-opacity))}.dark\:text-zinc-300:is(.dark *){--tw-text-opacity: 1;color:rgb(212 212 216 / var(--tw-text-opacity))}.dark\:hover\:bg-\[\#071f19\]:hover:is(.dark *){--tw-bg-opacity: 1;background-color:rgb(7 31 25 / var(--tw-bg-opacity))}.dark\:hover\:bg-\[\#082720\]:hover:is(.dark *){--tw-bg-opacity: 1;background-color:rgb(8 39 32 / var(--tw-bg-opacity))}.dark\:hover\:bg-\[\#141a18\]:hover:is(.dark *){--tw-bg-opacity: 1;background-color:rgb(20 26 24 / var(--tw-bg-opacity))}.dark\:hover\:bg-white\/10:hover:is(.dark *){background-color:#ffffff1a}@media (min-width: 640px){.sm\:m-4{margin:1rem}.sm\:inline{display:inline}.sm\:max-h-\[600px\]{max-height:600px}.sm\:max-w-\[650px\]{max-width:650px}.sm\:max-w-\[740px\]{max-width:740px}.sm\:max-w-\[950px\]{max-width:950px}.sm\:grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.sm\:grid-cols-\[10rem_1fr_10rem\]{grid-template-columns:10rem 1fr 10rem}.sm\:flex-row{flex-direction:row}.sm\:justify-end{justify-content:flex-end}.sm\:space-x-2>:not([hidden])~:not([hidden]){--tw-space-x-reverse: 0;margin-right:calc(.5rem * var(--tw-space-x-reverse));margin-left:calc(.5rem * calc(1 - var(--tw-space-x-reverse)))}.sm\:rounded-lg{border-radius:var(--radius)}.sm\:text-left{text-align:left}}@media (min-width: 768px){.md\:inline{display:inline}.md\:flex{display:flex}.md\:w-64{width:16rem}.md\:w-full{width:100%}.md\:grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.md\:grid-cols-3{grid-template-columns:repeat(3,minmax(0,1fr))}.md\:flex-row{flex-direction:row}.md\:gap-8{gap:2rem}}@media (min-width: 1024px){.lg\:grid-cols-3{grid-template-columns:repeat(3,minmax(0,1fr))}}@media (min-width: 1280px){.xl\:grid-cols-4{grid-template-columns:repeat(4,minmax(0,1fr))}}.\[\&\:has\(\[role\=checkbox\]\)\]\:pr-0:has([role=checkbox]){padding-right:0}.\[\&\>\*\]\:p-4>*{padding:1rem}.\[\&\>\*\]\:px-4>*{padding-left:1rem;padding-right:1rem}.\[\&\>\*\]\:py-2>*{padding-top:.5rem;padding-bottom:.5rem}.\[\&\>div\[style\]\]\:\!block>div[style]{display:block!important}.\[\&\>div\[style\]\]\:h-full>div[style]{height:100%}.\[\&\>span\]\:line-clamp-1>span{overflow:hidden;display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:1}.\[\&\>svg\+div\]\:translate-y-\[-3px\]>svg+div{--tw-translate-y: -3px;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.\[\&\>svg\]\:absolute>svg{position:absolute}.\[\&\>svg\]\:left-4>svg{left:1rem}.\[\&\>svg\]\:top-4>svg{top:1rem}.\[\&\>svg\]\:h-2\.5>svg{height:.625rem}.\[\&\>svg\]\:h-3>svg{height:.75rem}.\[\&\>svg\]\:w-2\.5>svg{width:.625rem}.\[\&\>svg\]\:w-3>svg{width:.75rem}.\[\&\>svg\]\:fill-rose-600>svg{fill:#e11d48}.\[\&\>svg\]\:text-amber-500>svg{--tw-text-opacity: 1;color:rgb(245 158 11 / var(--tw-text-opacity))}.\[\&\>svg\]\:text-emerald-600>svg{--tw-text-opacity: 1;color:rgb(5 150 105 / var(--tw-text-opacity))}.\[\&\>svg\]\:text-foreground>svg{color:hsl(var(--foreground))}.\[\&\>svg\]\:text-muted-foreground>svg{color:hsl(var(--muted-foreground))}.\[\&\>svg\]\:text-red-600>svg{--tw-text-opacity: 1;color:rgb(220 38 38 / var(--tw-text-opacity))}.\[\&\>svg\]\:text-sky-500>svg{--tw-text-opacity: 1;color:rgb(14 165 233 / var(--tw-text-opacity))}.\[\&\>svg\]\:text-zinc-400>svg{--tw-text-opacity: 1;color:rgb(161 161 170 / var(--tw-text-opacity))}.hover\:\[\&\>svg\]\:fill-rose-700>svg:hover{fill:#be123c}.dark\:\[\&\>svg\]\:text-emerald-400\/80>svg:is(.dark *){color:#34d399cc}.dark\:\[\&\>svg\]\:text-red-400\/80>svg:is(.dark *){color:#f87171cc}.dark\:\[\&\>svg\]\:text-zinc-300>svg:is(.dark *){--tw-text-opacity: 1;color:rgb(212 212 216 / var(--tw-text-opacity))}.\[\&\>svg\~\*\]\:pl-7>svg~*{padding-left:1.75rem}.\[\&\>tr\]\:last\:border-b-0:last-child>tr{border-bottom-width:0px}.\[\&\[data-panel-group-direction\=vertical\]\>div\]\:rotate-90[data-panel-group-direction=vertical]>div{--tw-rotate: 90deg;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.\[\&_\.recharts-cartesian-axis-tick_text\]\:fill-muted-foreground .recharts-cartesian-axis-tick text{fill:hsl(var(--muted-foreground))}.\[\&_\.recharts-cartesian-grid_line\[stroke\=\'\#ccc\'\]\]\:stroke-border\/50 .recharts-cartesian-grid line[stroke="#ccc"]{stroke:hsl(var(--border) / .5)}.\[\&_\.recharts-curve\.recharts-tooltip-cursor\]\:stroke-border .recharts-curve.recharts-tooltip-cursor{stroke:hsl(var(--border))}.\[\&_\.recharts-dot\[stroke\=\'\#fff\'\]\]\:stroke-transparent .recharts-dot[stroke="#fff"]{stroke:transparent}.\[\&_\.recharts-layer\]\:outline-none .recharts-layer{outline:2px solid transparent;outline-offset:2px}.\[\&_\.recharts-polar-grid_\[stroke\=\'\#ccc\'\]\]\:stroke-border .recharts-polar-grid [stroke="#ccc"]{stroke:hsl(var(--border))}.\[\&_\.recharts-radial-bar-background-sector\]\:fill-muted .recharts-radial-bar-background-sector,.\[\&_\.recharts-rectangle\.recharts-tooltip-cursor\]\:fill-muted .recharts-rectangle.recharts-tooltip-cursor{fill:hsl(var(--muted))}.\[\&_\.recharts-reference-line_\[stroke\=\'\#ccc\'\]\]\:stroke-border .recharts-reference-line [stroke="#ccc"]{stroke:hsl(var(--border))}.\[\&_\.recharts-sector\[stroke\=\'\#fff\'\]\]\:stroke-transparent .recharts-sector[stroke="#fff"]{stroke:transparent}.\[\&_\.recharts-sector\]\:outline-none .recharts-sector,.\[\&_\.recharts-surface\]\:outline-none .recharts-surface{outline:2px solid transparent;outline-offset:2px}.\[\&_\[cmdk-group-heading\]\]\:px-2 [cmdk-group-heading]{padding-left:.5rem;padding-right:.5rem}.\[\&_\[cmdk-group-heading\]\]\:py-1\.5 [cmdk-group-heading]{padding-top:.375rem;padding-bottom:.375rem}.\[\&_\[cmdk-group-heading\]\]\:text-xs [cmdk-group-heading]{font-size:.75rem;line-height:1rem}.\[\&_\[cmdk-group-heading\]\]\:font-medium [cmdk-group-heading]{font-weight:500}.\[\&_\[cmdk-group-heading\]\]\:text-muted-foreground [cmdk-group-heading]{color:hsl(var(--muted-foreground))}.\[\&_\[cmdk-group\]\:not\(\[hidden\]\)_\~\[cmdk-group\]\]\:pt-0 [cmdk-group]:not([hidden])~[cmdk-group]{padding-top:0}.\[\&_\[cmdk-group\]\]\:px-2 [cmdk-group]{padding-left:.5rem;padding-right:.5rem}.\[\&_\[cmdk-input-wrapper\]_svg\]\:h-5 [cmdk-input-wrapper] svg{height:1.25rem}.\[\&_\[cmdk-input-wrapper\]_svg\]\:w-5 [cmdk-input-wrapper] svg{width:1.25rem}.\[\&_\[cmdk-input\]\]\:h-12 [cmdk-input]{height:3rem}.\[\&_\[cmdk-item\]\]\:px-2 [cmdk-item]{padding-left:.5rem;padding-right:.5rem}.\[\&_\[cmdk-item\]\]\:py-3 [cmdk-item]{padding-top:.75rem;padding-bottom:.75rem}.\[\&_\[cmdk-item\]_svg\]\:h-5 [cmdk-item] svg{height:1.25rem}.\[\&_\[cmdk-item\]_svg\]\:w-5 [cmdk-item] svg{width:1.25rem}.\[\&_p\]\:leading-relaxed p{line-height:1.625}.\[\&_strong\]\:text-foreground strong{color:hsl(var(--foreground))}.\[\&_tr\:last-child\]\:border-0 tr:last-child{border-width:0px}.\[\&_tr\]\:border-b tr{border-bottom-width:1px}:root{--toastify-color-light: #fff;--toastify-color-dark: #121212;--toastify-color-info: #3498db;--toastify-color-success: #07bc0c;--toastify-color-warning: #f1c40f;--toastify-color-error: #e74c3c;--toastify-color-transparent: rgba(255, 255, 255, .7);--toastify-icon-color-info: var(--toastify-color-info);--toastify-icon-color-success: var(--toastify-color-success);--toastify-icon-color-warning: var(--toastify-color-warning);--toastify-icon-color-error: var(--toastify-color-error);--toastify-toast-width: 320px;--toastify-toast-offset: 16px;--toastify-toast-top: max(var(--toastify-toast-offset), env(safe-area-inset-top));--toastify-toast-right: max(var(--toastify-toast-offset), env(safe-area-inset-right));--toastify-toast-left: max(var(--toastify-toast-offset), env(safe-area-inset-left));--toastify-toast-bottom: max(var(--toastify-toast-offset), env(safe-area-inset-bottom));--toastify-toast-background: #fff;--toastify-toast-min-height: 64px;--toastify-toast-max-height: 800px;--toastify-toast-bd-radius: 6px;--toastify-font-family: sans-serif;--toastify-z-index: 9999;--toastify-text-color-light: #757575;--toastify-text-color-dark: #fff;--toastify-text-color-info: #fff;--toastify-text-color-success: #fff;--toastify-text-color-warning: #fff;--toastify-text-color-error: #fff;--toastify-spinner-color: #616161;--toastify-spinner-color-empty-area: #e0e0e0;--toastify-color-progress-light: linear-gradient( to right, #4cd964, #5ac8fa, #007aff, #34aadc, #5856d6, #ff2d55 );--toastify-color-progress-dark: #bb86fc;--toastify-color-progress-info: var(--toastify-color-info);--toastify-color-progress-success: var(--toastify-color-success);--toastify-color-progress-warning: var(--toastify-color-warning);--toastify-color-progress-error: var(--toastify-color-error);--toastify-color-progress-bgo: .2}.Toastify__toast-container{z-index:var(--toastify-z-index);-webkit-transform:translate3d(0,0,var(--toastify-z-index));position:fixed;padding:4px;width:var(--toastify-toast-width);box-sizing:border-box;color:#fff}.Toastify__toast-container--top-left{top:var(--toastify-toast-top);left:var(--toastify-toast-left)}.Toastify__toast-container--top-center{top:var(--toastify-toast-top);left:50%;transform:translate(-50%)}.Toastify__toast-container--top-right{top:var(--toastify-toast-top);right:var(--toastify-toast-right)}.Toastify__toast-container--bottom-left{bottom:var(--toastify-toast-bottom);left:var(--toastify-toast-left)}.Toastify__toast-container--bottom-center{bottom:var(--toastify-toast-bottom);left:50%;transform:translate(-50%)}.Toastify__toast-container--bottom-right{bottom:var(--toastify-toast-bottom);right:var(--toastify-toast-right)}@media only screen and (max-width : 480px){.Toastify__toast-container{width:100vw;padding:0;left:env(safe-area-inset-left);margin:0}.Toastify__toast-container--top-left,.Toastify__toast-container--top-center,.Toastify__toast-container--top-right{top:env(safe-area-inset-top);transform:translate(0)}.Toastify__toast-container--bottom-left,.Toastify__toast-container--bottom-center,.Toastify__toast-container--bottom-right{bottom:env(safe-area-inset-bottom);transform:translate(0)}.Toastify__toast-container--rtl{right:env(safe-area-inset-right);left:initial}}.Toastify__toast{--y: 0;position:relative;touch-action:none;min-height:var(--toastify-toast-min-height);box-sizing:border-box;margin-bottom:1rem;padding:8px;border-radius:var(--toastify-toast-bd-radius);box-shadow:0 4px 12px #0000001a;display:flex;justify-content:space-between;max-height:var(--toastify-toast-max-height);font-family:var(--toastify-font-family);cursor:default;direction:ltr;z-index:0;overflow:hidden}.Toastify__toast--stacked{position:absolute;width:100%;transform:translate3d(0,var(--y),0) scale(var(--s));transition:transform .3s}.Toastify__toast--stacked[data-collapsed] .Toastify__toast-body,.Toastify__toast--stacked[data-collapsed] .Toastify__close-button{transition:opacity .1s}.Toastify__toast--stacked[data-collapsed=false]{overflow:visible}.Toastify__toast--stacked[data-collapsed=true]:not(:last-child)>*{opacity:0}.Toastify__toast--stacked:after{content:"";position:absolute;left:0;right:0;height:calc(var(--g) * 1px);bottom:100%}.Toastify__toast--stacked[data-pos=top]{top:0}.Toastify__toast--stacked[data-pos=bot]{bottom:0}.Toastify__toast--stacked[data-pos=bot].Toastify__toast--stacked:before{transform-origin:top}.Toastify__toast--stacked[data-pos=top].Toastify__toast--stacked:before{transform-origin:bottom}.Toastify__toast--stacked:before{content:"";position:absolute;left:0;right:0;bottom:0;height:100%;transform:scaleY(3);z-index:-1}.Toastify__toast--rtl{direction:rtl}.Toastify__toast--close-on-click{cursor:pointer}.Toastify__toast-body{margin:auto 0;flex:1 1 auto;padding:6px;display:flex;align-items:center}.Toastify__toast-body>div:last-child{word-break:break-word;flex:1}.Toastify__toast-icon{margin-inline-end:10px;width:20px;flex-shrink:0;display:flex}.Toastify--animate{animation-fill-mode:both;animation-duration:.5s}.Toastify--animate-icon{animation-fill-mode:both;animation-duration:.3s}@media only screen and (max-width : 480px){.Toastify__toast{margin-bottom:0;border-radius:0}}.Toastify__toast-theme--dark{background:var(--toastify-color-dark);color:var(--toastify-text-color-dark)}.Toastify__toast-theme--light,.Toastify__toast-theme--colored.Toastify__toast--default{background:var(--toastify-color-light);color:var(--toastify-text-color-light)}.Toastify__toast-theme--colored.Toastify__toast--info{color:var(--toastify-text-color-info);background:var(--toastify-color-info)}.Toastify__toast-theme--colored.Toastify__toast--success{color:var(--toastify-text-color-success);background:var(--toastify-color-success)}.Toastify__toast-theme--colored.Toastify__toast--warning{color:var(--toastify-text-color-warning);background:var(--toastify-color-warning)}.Toastify__toast-theme--colored.Toastify__toast--error{color:var(--toastify-text-color-error);background:var(--toastify-color-error)}.Toastify__progress-bar-theme--light{background:var(--toastify-color-progress-light)}.Toastify__progress-bar-theme--dark{background:var(--toastify-color-progress-dark)}.Toastify__progress-bar--info{background:var(--toastify-color-progress-info)}.Toastify__progress-bar--success{background:var(--toastify-color-progress-success)}.Toastify__progress-bar--warning{background:var(--toastify-color-progress-warning)}.Toastify__progress-bar--error{background:var(--toastify-color-progress-error)}.Toastify__progress-bar-theme--colored.Toastify__progress-bar--info,.Toastify__progress-bar-theme--colored.Toastify__progress-bar--success,.Toastify__progress-bar-theme--colored.Toastify__progress-bar--warning,.Toastify__progress-bar-theme--colored.Toastify__progress-bar--error{background:var(--toastify-color-transparent)}.Toastify__close-button{color:#fff;background:transparent;outline:none;border:none;padding:0;cursor:pointer;opacity:.7;transition:.3s ease;align-self:flex-start;z-index:1}.Toastify__close-button--light{color:#000;opacity:.3}.Toastify__close-button>svg{fill:currentColor;height:16px;width:14px}.Toastify__close-button:hover,.Toastify__close-button:focus{opacity:1}@keyframes Toastify__trackProgress{0%{transform:scaleX(1)}to{transform:scaleX(0)}}.Toastify__progress-bar{position:absolute;bottom:0;left:0;width:100%;height:100%;z-index:var(--toastify-z-index);opacity:.7;transform-origin:left;border-bottom-left-radius:var(--toastify-toast-bd-radius)}.Toastify__progress-bar--animated{animation:Toastify__trackProgress linear 1 forwards}.Toastify__progress-bar--controlled{transition:transform .2s}.Toastify__progress-bar--rtl{right:0;left:initial;transform-origin:right;border-bottom-left-radius:initial;border-bottom-right-radius:var(--toastify-toast-bd-radius)}.Toastify__progress-bar--wrp{position:absolute;bottom:0;left:0;width:100%;height:5px;border-bottom-left-radius:var(--toastify-toast-bd-radius)}.Toastify__progress-bar--wrp[data-hidden=true]{opacity:0}.Toastify__progress-bar--bg{opacity:var(--toastify-color-progress-bgo);width:100%;height:100%}.Toastify__spinner{width:20px;height:20px;box-sizing:border-box;border:2px solid;border-radius:100%;border-color:var(--toastify-spinner-color-empty-area);border-right-color:var(--toastify-spinner-color);animation:Toastify__spin .65s linear infinite}@keyframes Toastify__bounceInRight{0%,60%,75%,90%,to{animation-timing-function:cubic-bezier(.215,.61,.355,1)}0%{opacity:0;transform:translate3d(3000px,0,0)}60%{opacity:1;transform:translate3d(-25px,0,0)}75%{transform:translate3d(10px,0,0)}90%{transform:translate3d(-5px,0,0)}to{transform:none}}@keyframes Toastify__bounceOutRight{20%{opacity:1;transform:translate3d(-20px,var(--y),0)}to{opacity:0;transform:translate3d(2000px,var(--y),0)}}@keyframes Toastify__bounceInLeft{0%,60%,75%,90%,to{animation-timing-function:cubic-bezier(.215,.61,.355,1)}0%{opacity:0;transform:translate3d(-3000px,0,0)}60%{opacity:1;transform:translate3d(25px,0,0)}75%{transform:translate3d(-10px,0,0)}90%{transform:translate3d(5px,0,0)}to{transform:none}}@keyframes Toastify__bounceOutLeft{20%{opacity:1;transform:translate3d(20px,var(--y),0)}to{opacity:0;transform:translate3d(-2000px,var(--y),0)}}@keyframes Toastify__bounceInUp{0%,60%,75%,90%,to{animation-timing-function:cubic-bezier(.215,.61,.355,1)}0%{opacity:0;transform:translate3d(0,3000px,0)}60%{opacity:1;transform:translate3d(0,-20px,0)}75%{transform:translate3d(0,10px,0)}90%{transform:translate3d(0,-5px,0)}to{transform:translateZ(0)}}@keyframes Toastify__bounceOutUp{20%{transform:translate3d(0,calc(var(--y) - 10px),0)}40%,45%{opacity:1;transform:translate3d(0,calc(var(--y) + 20px),0)}to{opacity:0;transform:translate3d(0,-2000px,0)}}@keyframes Toastify__bounceInDown{0%,60%,75%,90%,to{animation-timing-function:cubic-bezier(.215,.61,.355,1)}0%{opacity:0;transform:translate3d(0,-3000px,0)}60%{opacity:1;transform:translate3d(0,25px,0)}75%{transform:translate3d(0,-10px,0)}90%{transform:translate3d(0,5px,0)}to{transform:none}}@keyframes Toastify__bounceOutDown{20%{transform:translate3d(0,calc(var(--y) - 10px),0)}40%,45%{opacity:1;transform:translate3d(0,calc(var(--y) + 20px),0)}to{opacity:0;transform:translate3d(0,2000px,0)}}.Toastify__bounce-enter--top-left,.Toastify__bounce-enter--bottom-left{animation-name:Toastify__bounceInLeft}.Toastify__bounce-enter--top-right,.Toastify__bounce-enter--bottom-right{animation-name:Toastify__bounceInRight}.Toastify__bounce-enter--top-center{animation-name:Toastify__bounceInDown}.Toastify__bounce-enter--bottom-center{animation-name:Toastify__bounceInUp}.Toastify__bounce-exit--top-left,.Toastify__bounce-exit--bottom-left{animation-name:Toastify__bounceOutLeft}.Toastify__bounce-exit--top-right,.Toastify__bounce-exit--bottom-right{animation-name:Toastify__bounceOutRight}.Toastify__bounce-exit--top-center{animation-name:Toastify__bounceOutUp}.Toastify__bounce-exit--bottom-center{animation-name:Toastify__bounceOutDown}@keyframes Toastify__zoomIn{0%{opacity:0;transform:scale3d(.3,.3,.3)}50%{opacity:1}}@keyframes Toastify__zoomOut{0%{opacity:1}50%{opacity:0;transform:translate3d(0,var(--y),0) scale3d(.3,.3,.3)}to{opacity:0}}.Toastify__zoom-enter{animation-name:Toastify__zoomIn}.Toastify__zoom-exit{animation-name:Toastify__zoomOut}@keyframes Toastify__flipIn{0%{transform:perspective(400px) rotateX(90deg);animation-timing-function:ease-in;opacity:0}40%{transform:perspective(400px) rotateX(-20deg);animation-timing-function:ease-in}60%{transform:perspective(400px) rotateX(10deg);opacity:1}80%{transform:perspective(400px) rotateX(-5deg)}to{transform:perspective(400px)}}@keyframes Toastify__flipOut{0%{transform:translate3d(0,var(--y),0) perspective(400px)}30%{transform:translate3d(0,var(--y),0) perspective(400px) rotateX(-20deg);opacity:1}to{transform:translate3d(0,var(--y),0) perspective(400px) rotateX(90deg);opacity:0}}.Toastify__flip-enter{animation-name:Toastify__flipIn}.Toastify__flip-exit{animation-name:Toastify__flipOut}@keyframes Toastify__slideInRight{0%{transform:translate3d(110%,0,0);visibility:visible}to{transform:translate3d(0,var(--y),0)}}@keyframes Toastify__slideInLeft{0%{transform:translate3d(-110%,0,0);visibility:visible}to{transform:translate3d(0,var(--y),0)}}@keyframes Toastify__slideInUp{0%{transform:translate3d(0,110%,0);visibility:visible}to{transform:translate3d(0,var(--y),0)}}@keyframes Toastify__slideInDown{0%{transform:translate3d(0,-110%,0);visibility:visible}to{transform:translate3d(0,var(--y),0)}}@keyframes Toastify__slideOutRight{0%{transform:translate3d(0,var(--y),0)}to{visibility:hidden;transform:translate3d(110%,var(--y),0)}}@keyframes Toastify__slideOutLeft{0%{transform:translate3d(0,var(--y),0)}to{visibility:hidden;transform:translate3d(-110%,var(--y),0)}}@keyframes Toastify__slideOutDown{0%{transform:translate3d(0,var(--y),0)}to{visibility:hidden;transform:translate3d(0,500px,0)}}@keyframes Toastify__slideOutUp{0%{transform:translate3d(0,var(--y),0)}to{visibility:hidden;transform:translate3d(0,-500px,0)}}.Toastify__slide-enter--top-left,.Toastify__slide-enter--bottom-left{animation-name:Toastify__slideInLeft}.Toastify__slide-enter--top-right,.Toastify__slide-enter--bottom-right{animation-name:Toastify__slideInRight}.Toastify__slide-enter--top-center{animation-name:Toastify__slideInDown}.Toastify__slide-enter--bottom-center{animation-name:Toastify__slideInUp}.Toastify__slide-exit--top-left,.Toastify__slide-exit--bottom-left{animation-name:Toastify__slideOutLeft;animation-timing-function:ease-in;animation-duration:.3s}.Toastify__slide-exit--top-right,.Toastify__slide-exit--bottom-right{animation-name:Toastify__slideOutRight;animation-timing-function:ease-in;animation-duration:.3s}.Toastify__slide-exit--top-center{animation-name:Toastify__slideOutUp;animation-timing-function:ease-in;animation-duration:.3s}.Toastify__slide-exit--bottom-center{animation-name:Toastify__slideOutDown;animation-timing-function:ease-in;animation-duration:.3s}@keyframes Toastify__spin{0%{transform:rotate(0)}to{transform:rotate(360deg)}}.chat-item{display:flex;padding:10px;cursor:pointer;background-color:hsl(var(--background))}.chat-item:hover,.chat-item.active{background-color:#2f2f2f}.bubble{border-radius:16px;padding:12px;word-wrap:break-word;max-width:100%;overflow:hidden}.bubble-right .bubble{background-color:#0a0a0a;max-width:100%}.bubble-right .bubble>span{text-align:right;display:block}.bubble-left .bubble{background-color:#1b1b1b;max-width:100%}.bubble-right{align-self:flex-end;display:flex;justify-content:flex-end;width:80%}.bubble-left{align-self:flex-start;display:flex;justify-content:flex-start;width:80%}.input-message textarea{background-color:#2f2f2f;padding-left:48px}.input-message textarea:focus{outline:none;border:none;box-shadow:none}.message-container{flex:1;overflow-y:auto;max-height:calc(100vh - 110px);padding-top:50px}.tabs-chat{background-color:transparent;width:100%;border-radius:0}.contacts-container{height:calc(100vh - 180px);overflow-y:auto;display:flex;flex-direction:column}.chat-item{display:flex;padding:10px;cursor:pointer}.custom-scrollbar{scrollbar-width:none}.custom-scrollbar::-webkit-scrollbar{display:none}.input-container{position:sticky;bottom:0;display:flex;flex-direction:column;gap:.375rem;background-color:transparent;padding:.375rem 1rem;width:100%;max-width:48rem;margin:0 auto;box-sizing:border-box}.formatted-message{white-space:pre-wrap}.formatted-message p{margin-bottom:1em}.formatted-message strong{font-weight:700}.formatted-message em{font-style:italic}.formatted-message del{text-decoration:line-through}.formatted-message a{color:#170c96!important;text-decoration:underline!important}.highlight-quoted{animation:highlight 2s ease-out}@keyframes highlight{0%{background-color:#3b82f633}to{background-color:transparent}} ================================================ FILE: manager/dist/index.html ================================================ Evolution Manager
================================================ FILE: manager_install.sh ================================================ #! /bin/bash cd evolution-manager-v2 npm install npm run build cd .. rm -rf manager/dist cp -r evolution-manager-v2/dist manager/dist ================================================ FILE: package.json ================================================ { "name": "evolution-api", "version": "2.3.7", "description": "Rest api for communication with WhatsApp", "main": "./dist/main.js", "type": "commonjs", "scripts": { "build": "tsc --noEmit && tsup", "start": "tsx ./src/main.ts", "start:prod": "node dist/main", "dev:server": "tsx watch ./src/main.ts", "test": "tsx watch ./test/all.test.ts", "lint": "eslint --fix --ext .ts src", "lint:check": "eslint --ext .ts src", "commit": "cz", "commitlint": "commitlint --edit", "db:generate": "node runWithProvider.js \"npx prisma generate --schema ./prisma/DATABASE_PROVIDER-schema.prisma\"", "db:deploy": "node runWithProvider.js \"rm -rf ./prisma/migrations && cp -r ./prisma/DATABASE_PROVIDER-migrations ./prisma/migrations && npx prisma migrate deploy --schema ./prisma/DATABASE_PROVIDER-schema.prisma\"", "db:deploy:win": "node runWithProvider.js \"xcopy /E /I prisma\\DATABASE_PROVIDER-migrations prisma\\migrations && npx prisma migrate deploy --schema prisma\\DATABASE_PROVIDER-schema.prisma\"", "db:studio": "node runWithProvider.js \"npx prisma studio --schema ./prisma/DATABASE_PROVIDER-schema.prisma\"", "db:migrate:dev": "node runWithProvider.js \"rm -rf ./prisma/migrations && cp -r ./prisma/DATABASE_PROVIDER-migrations ./prisma/migrations && npx prisma migrate dev --schema ./prisma/DATABASE_PROVIDER-schema.prisma && cp -r ./prisma/migrations/* ./prisma/DATABASE_PROVIDER-migrations\"", "db:migrate:dev:win": "node runWithProvider.js \"xcopy /E /I prisma\\DATABASE_PROVIDER-migrations prisma\\migrations && npx prisma migrate dev --schema prisma\\DATABASE_PROVIDER-schema.prisma\"", "prepare": "husky" }, "repository": { "type": "git", "url": "git+https://github.com/EvolutionAPI/evolution-api.git" }, "keywords": [ "chat", "communication", "message", "send message", "whatsapp", "js-whatsapp", "whatsapp-api", "whatsapp-web", "whatsapp", "whatsapp-chat", "whatsapp-group", "automation", "multi-device", "bot" ], "author": { "name": "Davidson Gomes", "email": "contato@evolution-api.com" }, "license": "Apache-2.0", "bugs": { "url": "https://github.com/EvolutionAPI/evolution-api/issues" }, "homepage": "https://github.com/EvolutionAPI/evolution-api#readme", "lint-staged": { "src/**/*.{ts,js}": [ "eslint --fix" ], "src/**/*.ts": [ "sh -c 'tsc --noEmit'" ] }, "config": { "commitizen": { "path": "cz-conventional-changelog" } }, "dependencies": { "@adiwajshing/keyed-db": "^0.2.4", "@aws-sdk/client-sqs": "^3.891.0", "@ffmpeg-installer/ffmpeg": "^1.1.0", "@figuro/chatwoot-sdk": "^1.1.16", "@hapi/boom": "^10.0.1", "@paralleldrive/cuid2": "^2.2.2", "@prisma/client": "^6.16.2", "@sentry/node": "^10.12.0", "@types/uuid": "^10.0.0", "amqplib": "^0.10.5", "audio-decode": "^2.2.3", "axios": "^1.7.9", "baileys": "7.0.0-rc.9", "class-validator": "^0.14.1", "compression": "^1.7.5", "cors": "^2.8.5", "dayjs": "^1.11.13", "dotenv": "^16.4.7", "emoji-regex": "^10.4.0", "eventemitter2": "^6.4.9", "express": "^4.21.2", "express-async-errors": "^3.1.1", "fluent-ffmpeg": "^2.1.3", "form-data": "^4.0.1", "https-proxy-agent": "^7.0.6", "fetch-socks": "^1.3.2", "i18next": "^23.7.19", "jimp": "^1.6.0", "json-schema": "^0.4.0", "jsonschema": "^1.4.1", "jsonwebtoken": "^9.0.2", "kafkajs": "^2.2.4", "libphonenumber-js": "^1.12.25", "link-preview-js": "^3.0.13", "long": "^5.2.3", "mediainfo.js": "^0.3.4", "mime": "^4.0.0", "mime-types": "^2.1.35", "minio": "^8.0.3", "multer": "^2.0.2", "nats": "^2.29.1", "node-cache": "^5.1.2", "node-cron": "^3.0.3", "openai": "^4.77.3", "pg": "^8.13.1", "pino": "^9.10.0", "prisma": "^6.1.0", "pusher": "^5.2.0", "qrcode": "^1.5.4", "qrcode-terminal": "^0.12.0", "redis": "^4.7.0", "rxjs": "^7.8.2", "sharp": "^0.34.2", "socket.io": "^4.8.1", "socket.io-client": "^4.8.1", "socks-proxy-agent": "^8.0.5", "swagger-ui-express": "^5.0.1", "tsup": "^8.3.5", "undici": "^7.16.0", "uuid": "^13.0.0" }, "devDependencies": { "@commitlint/cli": "^19.8.1", "@commitlint/config-conventional": "^19.8.1", "@types/compression": "^1.7.5", "@types/cors": "^2.8.17", "@types/express": "^4.17.18", "@types/json-schema": "^7.0.15", "@types/mime": "^4.0.0", "@types/mime-types": "^2.1.4", "@types/node": "^24.5.2", "@types/node-cron": "^3.0.11", "@types/qrcode": "^1.5.5", "@types/qrcode-terminal": "^0.12.2", "@typescript-eslint/eslint-plugin": "^8.44.0", "@typescript-eslint/parser": "^8.44.0", "commitizen": "^4.3.1", "cz-conventional-changelog": "^3.3.0", "eslint": "^8.45.0", "eslint-config-prettier": "^10.1.8", "eslint-plugin-import": "^2.31.0", "eslint-plugin-prettier": "^5.2.1", "eslint-plugin-simple-import-sort": "^12.1.1", "husky": "^9.1.7", "lint-staged": "^16.1.6", "prettier": "^3.4.2", "tsconfig-paths": "^4.2.0", "tsx": "^4.20.5", "typescript": "^5.7.2" } } ================================================ FILE: prisma/mysql-migrations/20240809105427_init/migration.sql ================================================ -- CreateTable CREATE TABLE `Instance` ( `id` VARCHAR(191) NOT NULL, `name` VARCHAR(255) NOT NULL, `connectionStatus` ENUM('open', 'close', 'connecting') NOT NULL DEFAULT 'open', `ownerJid` VARCHAR(100) NULL, `profileName` VARCHAR(100) NULL, `profilePicUrl` VARCHAR(500) NULL, `integration` VARCHAR(100) NULL, `number` VARCHAR(100) NULL, `businessId` VARCHAR(100) NULL, `token` VARCHAR(255) NULL, `clientName` VARCHAR(100) NULL, `disconnectionReasonCode` INTEGER NULL, `disconnectionObject` JSON NULL, `disconnectionAt` TIMESTAMP NULL, `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, `updatedAt` TIMESTAMP NULL, UNIQUE INDEX `Instance_name_key`(`name`), PRIMARY KEY (`id`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- CreateTable CREATE TABLE `Session` ( `id` VARCHAR(191) NOT NULL, `sessionId` VARCHAR(191) NOT NULL, `creds` TEXT NULL, `createdAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, UNIQUE INDEX `Session_sessionId_key`(`sessionId`), PRIMARY KEY (`id`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- CreateTable CREATE TABLE `Chat` ( `id` VARCHAR(191) NOT NULL, `remoteJid` VARCHAR(100) NOT NULL, `labels` JSON NULL, `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, `updatedAt` TIMESTAMP NULL, `instanceId` VARCHAR(191) NOT NULL, PRIMARY KEY (`id`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- CreateTable CREATE TABLE `Contact` ( `id` VARCHAR(191) NOT NULL, `remoteJid` VARCHAR(100) NOT NULL, `pushName` VARCHAR(100) NULL, `profilePicUrl` VARCHAR(500) NULL, `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, `updatedAt` TIMESTAMP NULL, `instanceId` VARCHAR(191) NOT NULL, PRIMARY KEY (`id`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- CreateTable CREATE TABLE `Message` ( `id` VARCHAR(191) NOT NULL, `key` JSON NOT NULL, `pushName` VARCHAR(100) NULL, `participant` VARCHAR(100) NULL, `messageType` VARCHAR(100) NOT NULL, `message` JSON NOT NULL, `contextInfo` JSON NULL, `source` ENUM('ios', 'android', 'web', 'unknown', 'desktop') NOT NULL, `messageTimestamp` INTEGER NOT NULL, `chatwootMessageId` INTEGER NULL, `chatwootInboxId` INTEGER NULL, `chatwootConversationId` INTEGER NULL, `chatwootContactInboxSourceId` VARCHAR(100) NULL, `chatwootIsRead` BOOLEAN NULL DEFAULT false, `instanceId` VARCHAR(191) NOT NULL, `typebotSessionId` VARCHAR(191) NULL, `openaiSessionId` VARCHAR(191) NULL, `webhookUrl` VARCHAR(500) NULL, `difySessionId` VARCHAR(191) NULL, PRIMARY KEY (`id`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- CreateTable CREATE TABLE `MessageUpdate` ( `id` VARCHAR(191) NOT NULL, `keyId` VARCHAR(100) NOT NULL, `remoteJid` VARCHAR(100) NOT NULL, `fromMe` BOOLEAN NOT NULL, `participant` VARCHAR(100) NULL, `pollUpdates` JSON NULL, `status` VARCHAR(30) NOT NULL, `messageId` VARCHAR(191) NOT NULL, `instanceId` VARCHAR(191) NOT NULL, PRIMARY KEY (`id`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- CreateTable CREATE TABLE `Webhook` ( `id` VARCHAR(191) NOT NULL, `url` VARCHAR(500) NOT NULL, `enabled` BOOLEAN NULL DEFAULT true, `events` JSON NULL, `webhookByEvents` BOOLEAN NULL DEFAULT false, `webhookBase64` BOOLEAN NULL DEFAULT false, `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, `updatedAt` TIMESTAMP NOT NULL, `instanceId` VARCHAR(191) NOT NULL, UNIQUE INDEX `Webhook_instanceId_key`(`instanceId`), PRIMARY KEY (`id`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- CreateTable CREATE TABLE `Chatwoot` ( `id` VARCHAR(191) NOT NULL, `enabled` BOOLEAN NULL DEFAULT true, `accountId` VARCHAR(100) NULL, `token` VARCHAR(100) NULL, `url` VARCHAR(500) NULL, `nameInbox` VARCHAR(100) NULL, `signMsg` BOOLEAN NULL DEFAULT false, `signDelimiter` VARCHAR(100) NULL, `number` VARCHAR(100) NULL, `reopenConversation` BOOLEAN NULL DEFAULT false, `conversationPending` BOOLEAN NULL DEFAULT false, `mergeBrazilContacts` BOOLEAN NULL DEFAULT false, `importContacts` BOOLEAN NULL DEFAULT false, `importMessages` BOOLEAN NULL DEFAULT false, `daysLimitImportMessages` INTEGER NULL, `organization` VARCHAR(100) NULL, `logo` VARCHAR(500) NULL, `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, `updatedAt` TIMESTAMP NOT NULL, `instanceId` VARCHAR(191) NOT NULL, UNIQUE INDEX `Chatwoot_instanceId_key`(`instanceId`), PRIMARY KEY (`id`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- CreateTable CREATE TABLE `Label` ( `id` VARCHAR(191) NOT NULL, `labelId` VARCHAR(100) NULL, `name` VARCHAR(100) NOT NULL, `color` VARCHAR(100) NOT NULL, `predefinedId` VARCHAR(100) NULL, `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, `updatedAt` TIMESTAMP NOT NULL, `instanceId` VARCHAR(191) NOT NULL, UNIQUE INDEX `Label_labelId_key`(`labelId`), PRIMARY KEY (`id`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- CreateTable CREATE TABLE `Proxy` ( `id` VARCHAR(191) NOT NULL, `enabled` BOOLEAN NOT NULL DEFAULT false, `host` VARCHAR(100) NOT NULL, `port` VARCHAR(100) NOT NULL, `protocol` VARCHAR(100) NOT NULL, `username` VARCHAR(100) NOT NULL, `password` VARCHAR(100) NOT NULL, `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, `updatedAt` TIMESTAMP NOT NULL, `instanceId` VARCHAR(191) NOT NULL, UNIQUE INDEX `Proxy_instanceId_key`(`instanceId`), PRIMARY KEY (`id`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- CreateTable CREATE TABLE `Setting` ( `id` VARCHAR(191) NOT NULL, `rejectCall` BOOLEAN NOT NULL DEFAULT false, `msgCall` VARCHAR(100) NULL, `groupsIgnore` BOOLEAN NOT NULL DEFAULT false, `alwaysOnline` BOOLEAN NOT NULL DEFAULT false, `readMessages` BOOLEAN NOT NULL DEFAULT false, `readStatus` BOOLEAN NOT NULL DEFAULT false, `syncFullHistory` BOOLEAN NOT NULL DEFAULT false, `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, `updatedAt` TIMESTAMP NOT NULL, `instanceId` VARCHAR(191) NOT NULL, UNIQUE INDEX `Setting_instanceId_key`(`instanceId`), PRIMARY KEY (`id`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- CreateTable CREATE TABLE `Rabbitmq` ( `id` VARCHAR(191) NOT NULL, `enabled` BOOLEAN NOT NULL DEFAULT false, `events` JSON NOT NULL, `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, `updatedAt` TIMESTAMP NOT NULL, `instanceId` VARCHAR(191) NOT NULL, UNIQUE INDEX `Rabbitmq_instanceId_key`(`instanceId`), PRIMARY KEY (`id`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- CreateTable CREATE TABLE `Sqs` ( `id` VARCHAR(191) NOT NULL, `enabled` BOOLEAN NOT NULL DEFAULT false, `events` JSON NOT NULL, `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, `updatedAt` TIMESTAMP NOT NULL, `instanceId` VARCHAR(191) NOT NULL, UNIQUE INDEX `Sqs_instanceId_key`(`instanceId`), PRIMARY KEY (`id`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- CreateTable CREATE TABLE `Websocket` ( `id` VARCHAR(191) NOT NULL, `enabled` BOOLEAN NOT NULL DEFAULT false, `events` JSON NOT NULL, `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, `updatedAt` TIMESTAMP NOT NULL, `instanceId` VARCHAR(191) NOT NULL, UNIQUE INDEX `Websocket_instanceId_key`(`instanceId`), PRIMARY KEY (`id`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- CreateTable CREATE TABLE `Typebot` ( `id` VARCHAR(191) NOT NULL, `enabled` BOOLEAN NOT NULL DEFAULT true, `description` VARCHAR(255) NULL, `url` VARCHAR(500) NOT NULL, `typebot` VARCHAR(100) NOT NULL, `expire` INTEGER NULL DEFAULT 0, `keywordFinish` VARCHAR(100) NULL, `delayMessage` INTEGER NULL, `unknownMessage` VARCHAR(100) NULL, `listeningFromMe` BOOLEAN NULL DEFAULT false, `stopBotFromMe` BOOLEAN NULL DEFAULT false, `keepOpen` BOOLEAN NULL DEFAULT false, `debounceTime` INTEGER NULL, `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, `updatedAt` TIMESTAMP NULL, `ignoreJids` JSON NULL, `triggerType` ENUM('all', 'keyword', 'none') NULL, `triggerOperator` ENUM('contains', 'equals', 'startsWith', 'endsWith', 'regex') NULL, `triggerValue` VARCHAR(191) NULL, `instanceId` VARCHAR(191) NOT NULL, PRIMARY KEY (`id`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- CreateTable CREATE TABLE `TypebotSession` ( `id` VARCHAR(191) NOT NULL, `remoteJid` VARCHAR(100) NOT NULL, `pushName` VARCHAR(100) NULL, `sessionId` VARCHAR(100) NOT NULL, `status` ENUM('opened', 'closed', 'paused') NOT NULL, `prefilledVariables` JSON NULL, `awaitUser` BOOLEAN NOT NULL DEFAULT false, `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, `updatedAt` TIMESTAMP NOT NULL, `typebotId` VARCHAR(191) NOT NULL, `instanceId` VARCHAR(191) NOT NULL, PRIMARY KEY (`id`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- CreateTable CREATE TABLE `TypebotSetting` ( `id` VARCHAR(191) NOT NULL, `expire` INTEGER NULL DEFAULT 0, `keywordFinish` VARCHAR(100) NULL, `delayMessage` INTEGER NULL, `unknownMessage` VARCHAR(100) NULL, `listeningFromMe` BOOLEAN NULL DEFAULT false, `stopBotFromMe` BOOLEAN NULL DEFAULT false, `keepOpen` BOOLEAN NULL DEFAULT false, `debounceTime` INTEGER NULL, `typebotIdFallback` VARCHAR(100) NULL, `ignoreJids` JSON NULL, `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, `updatedAt` TIMESTAMP NOT NULL, `instanceId` VARCHAR(191) NOT NULL, UNIQUE INDEX `TypebotSetting_instanceId_key`(`instanceId`), PRIMARY KEY (`id`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- CreateTable CREATE TABLE `Media` ( `id` VARCHAR(191) NOT NULL, `fileName` VARCHAR(500) NOT NULL, `type` VARCHAR(100) NOT NULL, `mimetype` VARCHAR(100) NOT NULL, `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, `messageId` VARCHAR(191) NOT NULL, `instanceId` VARCHAR(191) NOT NULL, UNIQUE INDEX `Media_fileName_key`(`fileName`), UNIQUE INDEX `Media_messageId_key`(`messageId`), PRIMARY KEY (`id`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- CreateTable CREATE TABLE `OpenaiCreds` ( `id` VARCHAR(191) NOT NULL, `name` VARCHAR(255) NULL, `apiKey` VARCHAR(255) NULL, `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, `updatedAt` TIMESTAMP NOT NULL, `instanceId` VARCHAR(191) NOT NULL, UNIQUE INDEX `OpenaiCreds_name_key`(`name`), UNIQUE INDEX `OpenaiCreds_apiKey_key`(`apiKey`), PRIMARY KEY (`id`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- CreateTable CREATE TABLE `OpenaiBot` ( `id` VARCHAR(191) NOT NULL, `enabled` BOOLEAN NOT NULL DEFAULT true, `description` VARCHAR(255) NULL, `botType` ENUM('assistant', 'chatCompletion') NOT NULL, `assistantId` VARCHAR(255) NULL, `functionUrl` VARCHAR(500) NULL, `model` VARCHAR(100) NULL, `systemMessages` JSON NULL, `assistantMessages` JSON NULL, `userMessages` JSON NULL, `maxTokens` INTEGER NULL, `expire` INTEGER NULL DEFAULT 0, `keywordFinish` VARCHAR(100) NULL, `delayMessage` INTEGER NULL, `unknownMessage` VARCHAR(100) NULL, `listeningFromMe` BOOLEAN NULL DEFAULT false, `stopBotFromMe` BOOLEAN NULL DEFAULT false, `keepOpen` BOOLEAN NULL DEFAULT false, `debounceTime` INTEGER NULL, `ignoreJids` JSON NULL, `triggerType` ENUM('all', 'keyword', 'none') NULL, `triggerOperator` ENUM('contains', 'equals', 'startsWith', 'endsWith', 'regex') NULL, `triggerValue` VARCHAR(191) NULL, `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, `updatedAt` TIMESTAMP NOT NULL, `openaiCredsId` VARCHAR(191) NOT NULL, `instanceId` VARCHAR(191) NOT NULL, PRIMARY KEY (`id`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- CreateTable CREATE TABLE `OpenaiSession` ( `id` VARCHAR(191) NOT NULL, `sessionId` VARCHAR(255) NOT NULL, `remoteJid` VARCHAR(100) NOT NULL, `status` ENUM('opened', 'closed', 'paused') NOT NULL, `awaitUser` BOOLEAN NOT NULL DEFAULT false, `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, `updatedAt` TIMESTAMP NOT NULL, `openaiBotId` VARCHAR(191) NOT NULL, `instanceId` VARCHAR(191) NOT NULL, PRIMARY KEY (`id`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- CreateTable CREATE TABLE `OpenaiSetting` ( `id` VARCHAR(191) NOT NULL, `expire` INTEGER NULL DEFAULT 0, `keywordFinish` VARCHAR(100) NULL, `delayMessage` INTEGER NULL, `unknownMessage` VARCHAR(100) NULL, `listeningFromMe` BOOLEAN NULL DEFAULT false, `stopBotFromMe` BOOLEAN NULL DEFAULT false, `keepOpen` BOOLEAN NULL DEFAULT false, `debounceTime` INTEGER NULL, `ignoreJids` JSON NULL, `speechToText` BOOLEAN NULL DEFAULT false, `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, `updatedAt` TIMESTAMP NOT NULL, `openaiCredsId` VARCHAR(191) NOT NULL, `openaiIdFallback` VARCHAR(100) NULL, `instanceId` VARCHAR(191) NOT NULL, UNIQUE INDEX `OpenaiSetting_openaiCredsId_key`(`openaiCredsId`), UNIQUE INDEX `OpenaiSetting_instanceId_key`(`instanceId`), PRIMARY KEY (`id`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- CreateTable CREATE TABLE `Template` ( `id` VARCHAR(191) NOT NULL, `templateId` VARCHAR(255) NOT NULL, `name` VARCHAR(255) NOT NULL, `template` JSON NOT NULL, `webhookUrl` VARCHAR(500) NULL, `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, `updatedAt` TIMESTAMP NOT NULL, `instanceId` VARCHAR(191) NOT NULL, UNIQUE INDEX `Template_templateId_key`(`templateId`), UNIQUE INDEX `Template_name_key`(`name`), PRIMARY KEY (`id`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- CreateTable CREATE TABLE `Dify` ( `id` VARCHAR(191) NOT NULL, `enabled` BOOLEAN NOT NULL DEFAULT true, `description` VARCHAR(255) NULL, `botType` ENUM('chatBot', 'textGenerator', 'agent', 'workflow') NOT NULL, `apiUrl` VARCHAR(255) NULL, `apiKey` VARCHAR(255) NULL, `expire` INTEGER NULL DEFAULT 0, `keywordFinish` VARCHAR(100) NULL, `delayMessage` INTEGER NULL, `unknownMessage` VARCHAR(100) NULL, `listeningFromMe` BOOLEAN NULL DEFAULT false, `stopBotFromMe` BOOLEAN NULL DEFAULT false, `keepOpen` BOOLEAN NULL DEFAULT false, `debounceTime` INTEGER NULL, `ignoreJids` JSON NULL, `triggerType` ENUM('all', 'keyword', 'none') NULL, `triggerOperator` ENUM('contains', 'equals', 'startsWith', 'endsWith', 'regex') NULL, `triggerValue` VARCHAR(191) NULL, `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, `updatedAt` TIMESTAMP NOT NULL, `instanceId` VARCHAR(191) NOT NULL, PRIMARY KEY (`id`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- CreateTable CREATE TABLE `DifySession` ( `id` VARCHAR(191) NOT NULL, `sessionId` VARCHAR(255) NOT NULL, `remoteJid` VARCHAR(100) NOT NULL, `status` ENUM('opened', 'closed', 'paused') NOT NULL, `awaitUser` BOOLEAN NOT NULL DEFAULT false, `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, `updatedAt` TIMESTAMP NOT NULL, `difyId` VARCHAR(191) NOT NULL, `instanceId` VARCHAR(191) NOT NULL, PRIMARY KEY (`id`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- CreateTable CREATE TABLE `DifySetting` ( `id` VARCHAR(191) NOT NULL, `expire` INTEGER NULL DEFAULT 0, `keywordFinish` VARCHAR(100) NULL, `delayMessage` INTEGER NULL, `unknownMessage` VARCHAR(100) NULL, `listeningFromMe` BOOLEAN NULL DEFAULT false, `stopBotFromMe` BOOLEAN NULL DEFAULT false, `keepOpen` BOOLEAN NULL DEFAULT false, `debounceTime` INTEGER NULL, `ignoreJids` JSON NULL, `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, `updatedAt` TIMESTAMP NOT NULL, `difyIdFallback` VARCHAR(100) NULL, `instanceId` VARCHAR(191) NOT NULL, UNIQUE INDEX `DifySetting_instanceId_key`(`instanceId`), PRIMARY KEY (`id`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- AddForeignKey ALTER TABLE `Session` ADD CONSTRAINT `Session_sessionId_fkey` FOREIGN KEY (`sessionId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `Chat` ADD CONSTRAINT `Chat_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `Contact` ADD CONSTRAINT `Contact_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `Message` ADD CONSTRAINT `Message_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `Message` ADD CONSTRAINT `Message_typebotSessionId_fkey` FOREIGN KEY (`typebotSessionId`) REFERENCES `TypebotSession`(`id`) ON DELETE SET NULL ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `Message` ADD CONSTRAINT `Message_openaiSessionId_fkey` FOREIGN KEY (`openaiSessionId`) REFERENCES `OpenaiSession`(`id`) ON DELETE SET NULL ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `Message` ADD CONSTRAINT `Message_difySessionId_fkey` FOREIGN KEY (`difySessionId`) REFERENCES `DifySession`(`id`) ON DELETE SET NULL ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `MessageUpdate` ADD CONSTRAINT `MessageUpdate_messageId_fkey` FOREIGN KEY (`messageId`) REFERENCES `Message`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `MessageUpdate` ADD CONSTRAINT `MessageUpdate_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `Webhook` ADD CONSTRAINT `Webhook_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `Chatwoot` ADD CONSTRAINT `Chatwoot_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `Label` ADD CONSTRAINT `Label_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `Proxy` ADD CONSTRAINT `Proxy_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `Setting` ADD CONSTRAINT `Setting_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `Rabbitmq` ADD CONSTRAINT `Rabbitmq_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `Sqs` ADD CONSTRAINT `Sqs_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `Websocket` ADD CONSTRAINT `Websocket_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `Typebot` ADD CONSTRAINT `Typebot_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `TypebotSession` ADD CONSTRAINT `TypebotSession_typebotId_fkey` FOREIGN KEY (`typebotId`) REFERENCES `Typebot`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `TypebotSession` ADD CONSTRAINT `TypebotSession_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `TypebotSetting` ADD CONSTRAINT `TypebotSetting_typebotIdFallback_fkey` FOREIGN KEY (`typebotIdFallback`) REFERENCES `Typebot`(`id`) ON DELETE SET NULL ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `TypebotSetting` ADD CONSTRAINT `TypebotSetting_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `Media` ADD CONSTRAINT `Media_messageId_fkey` FOREIGN KEY (`messageId`) REFERENCES `Message`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `Media` ADD CONSTRAINT `Media_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `OpenaiCreds` ADD CONSTRAINT `OpenaiCreds_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `OpenaiBot` ADD CONSTRAINT `OpenaiBot_openaiCredsId_fkey` FOREIGN KEY (`openaiCredsId`) REFERENCES `OpenaiCreds`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `OpenaiBot` ADD CONSTRAINT `OpenaiBot_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `OpenaiSession` ADD CONSTRAINT `OpenaiSession_openaiBotId_fkey` FOREIGN KEY (`openaiBotId`) REFERENCES `OpenaiBot`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `OpenaiSession` ADD CONSTRAINT `OpenaiSession_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `OpenaiSetting` ADD CONSTRAINT `OpenaiSetting_openaiCredsId_fkey` FOREIGN KEY (`openaiCredsId`) REFERENCES `OpenaiCreds`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `OpenaiSetting` ADD CONSTRAINT `OpenaiSetting_openaiIdFallback_fkey` FOREIGN KEY (`openaiIdFallback`) REFERENCES `OpenaiBot`(`id`) ON DELETE SET NULL ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `OpenaiSetting` ADD CONSTRAINT `OpenaiSetting_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `Template` ADD CONSTRAINT `Template_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `Dify` ADD CONSTRAINT `Dify_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `DifySession` ADD CONSTRAINT `DifySession_difyId_fkey` FOREIGN KEY (`difyId`) REFERENCES `Dify`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `DifySession` ADD CONSTRAINT `DifySession_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `DifySetting` ADD CONSTRAINT `DifySetting_difyIdFallback_fkey` FOREIGN KEY (`difyIdFallback`) REFERENCES `Dify`(`id`) ON DELETE SET NULL ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `DifySetting` ADD CONSTRAINT `DifySetting_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; ================================================ FILE: prisma/mysql-migrations/20240813153900_add_unique_index_for_remoted_jid_and_instance_in_contacts/migration.sql ================================================ /* Warnings: - You are about to alter the column `createdAt` on the `Chat` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Chat` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Chatwoot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Chatwoot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Contact` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Contact` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Dify` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Dify` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `DifySession` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `DifySession` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `DifySetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `DifySetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `disconnectionAt` on the `Instance` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Instance` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Instance` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Label` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Label` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Media` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `OpenaiBot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `OpenaiBot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `OpenaiCreds` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `OpenaiCreds` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `OpenaiSession` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `OpenaiSession` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `OpenaiSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `OpenaiSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Proxy` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Proxy` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Rabbitmq` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Rabbitmq` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Session` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Setting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Setting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Sqs` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Sqs` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Template` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Template` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Typebot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Typebot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `TypebotSession` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `TypebotSession` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `TypebotSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `TypebotSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Webhook` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Webhook` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Websocket` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Websocket` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - A unique constraint covering the columns `[remoteJid,instanceId]` on the table `Contact` will be added. If there are existing duplicate values, this will fail. */ -- AlterTable ALTER TABLE `Chat` ADD COLUMN `name` VARCHAR(100) NULL, MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NULL; -- AlterTable ALTER TABLE `Chatwoot` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Contact` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NULL; -- AlterTable ALTER TABLE `Dify` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `DifySession` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `DifySetting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Instance` MODIFY `disconnectionAt` TIMESTAMP NULL, MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NULL; -- AlterTable ALTER TABLE `Label` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Media` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP; -- AlterTable ALTER TABLE `OpenaiBot` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `OpenaiCreds` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `OpenaiSession` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `OpenaiSetting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Proxy` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Rabbitmq` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Session` MODIFY `createdAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP; -- AlterTable ALTER TABLE `Setting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Sqs` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Template` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Typebot` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NULL; -- AlterTable ALTER TABLE `TypebotSession` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `TypebotSetting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Webhook` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Websocket` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- CreateIndex CREATE UNIQUE INDEX `Contact_remoteJid_instanceId_key` ON `Contact` (`remoteJid`, `instanceId`); ================================================ FILE: prisma/mysql-migrations/20240814173138_add_ignore_jids_chatwoot/migration.sql ================================================ /* Warnings: - You are about to alter the column `createdAt` on the `Chat` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Chat` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Chatwoot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Chatwoot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Contact` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Contact` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Dify` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Dify` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `DifySession` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `DifySession` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `DifySetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `DifySetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `disconnectionAt` on the `Instance` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Instance` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Instance` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Label` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Label` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Media` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `OpenaiBot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `OpenaiBot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `OpenaiCreds` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `OpenaiCreds` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `OpenaiSession` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `OpenaiSession` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `OpenaiSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `OpenaiSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Proxy` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Proxy` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Rabbitmq` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Rabbitmq` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Session` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Setting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Setting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Sqs` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Sqs` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Template` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Template` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Typebot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Typebot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `TypebotSession` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `TypebotSession` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `TypebotSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `TypebotSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Webhook` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Webhook` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Websocket` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Websocket` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. */ -- DropIndex DROP INDEX `Label_labelId_key` ON `Label`; -- AlterTable ALTER TABLE `Chat` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NULL; -- AlterTable ALTER TABLE `Chatwoot` ADD COLUMN `ignoreJids` JSON NULL, MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Contact` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NULL; -- AlterTable ALTER TABLE `Dify` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `DifySession` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `DifySetting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Instance` MODIFY `disconnectionAt` TIMESTAMP NULL, MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NULL; -- AlterTable ALTER TABLE `Label` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Media` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP; -- AlterTable ALTER TABLE `OpenaiBot` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `OpenaiCreds` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `OpenaiSession` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `OpenaiSetting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Proxy` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Rabbitmq` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Session` MODIFY `createdAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP; -- AlterTable ALTER TABLE `Setting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Sqs` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Template` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Typebot` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NULL; -- AlterTable ALTER TABLE `TypebotSession` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `TypebotSetting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Webhook` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Websocket` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; ================================================ FILE: prisma/mysql-migrations/20240814214314_integrations_unification/migration.sql ================================================ /* Warnings: - You are about to alter the column `createdAt` on the `Chat` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Chat` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Chatwoot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Chatwoot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Contact` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Contact` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Dify` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Dify` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `DifySetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `DifySetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `disconnectionAt` on the `Instance` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Instance` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Instance` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Label` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Label` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Media` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to drop the column `difySessionId` on the `Message` table. All the data in the column will be lost. - You are about to drop the column `openaiSessionId` on the `Message` table. All the data in the column will be lost. - You are about to alter the column `createdAt` on the `OpenaiBot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `OpenaiBot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `OpenaiCreds` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `OpenaiCreds` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `OpenaiSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `OpenaiSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Proxy` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Proxy` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Rabbitmq` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Rabbitmq` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Session` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Setting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Setting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Sqs` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Sqs` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Template` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Template` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Typebot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Typebot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `TypebotSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `TypebotSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Webhook` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Webhook` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Websocket` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Websocket` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to drop the `DifySession` table. If the table is not empty, all the data it contains will be lost. - You are about to drop the `OpenaiSession` table. If the table is not empty, all the data it contains will be lost. - You are about to drop the `TypebotSession` table. If the table is not empty, all the data it contains will be lost. */ -- DropForeignKey ALTER TABLE `DifySession` DROP FOREIGN KEY `DifySession_difyId_fkey`; -- DropForeignKey ALTER TABLE `DifySession` DROP FOREIGN KEY `DifySession_instanceId_fkey`; -- DropForeignKey ALTER TABLE `Message` DROP FOREIGN KEY `Message_difySessionId_fkey`; -- DropForeignKey ALTER TABLE `Message` DROP FOREIGN KEY `Message_openaiSessionId_fkey`; -- DropForeignKey ALTER TABLE `Message` DROP FOREIGN KEY `Message_typebotSessionId_fkey`; -- DropForeignKey ALTER TABLE `OpenaiSession` DROP FOREIGN KEY `OpenaiSession_instanceId_fkey`; -- DropForeignKey ALTER TABLE `OpenaiSession` DROP FOREIGN KEY `OpenaiSession_openaiBotId_fkey`; -- DropForeignKey ALTER TABLE `TypebotSession` DROP FOREIGN KEY `TypebotSession_instanceId_fkey`; -- DropForeignKey ALTER TABLE `TypebotSession` DROP FOREIGN KEY `TypebotSession_typebotId_fkey`; -- AlterTable ALTER TABLE `Chat` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NULL; -- AlterTable ALTER TABLE `Chatwoot` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Contact` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NULL; -- AlterTable ALTER TABLE `Dify` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `DifySetting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Instance` MODIFY `disconnectionAt` TIMESTAMP NULL, MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NULL; -- AlterTable ALTER TABLE `Label` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Media` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP; -- AlterTable ALTER TABLE `Message` DROP COLUMN `difySessionId`, DROP COLUMN `openaiSessionId`, ADD COLUMN `sessionId` VARCHAR(191) NULL; -- AlterTable ALTER TABLE `OpenaiBot` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `OpenaiCreds` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `OpenaiSetting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Proxy` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Rabbitmq` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Session` MODIFY `createdAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP; -- AlterTable ALTER TABLE `Setting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Sqs` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Template` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Typebot` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NULL; -- AlterTable ALTER TABLE `TypebotSetting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Webhook` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Websocket` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- DropTable DROP TABLE `DifySession`; -- DropTable DROP TABLE `OpenaiSession`; -- DropTable DROP TABLE `TypebotSession`; -- CreateTable CREATE TABLE `IntegrationSession` ( `id` VARCHAR(191) NOT NULL, `sessionId` VARCHAR(255) NOT NULL, `remoteJid` VARCHAR(100) NOT NULL, `pushName` VARCHAR(191) NULL, `status` ENUM('opened', 'closed', 'paused') NOT NULL, `awaitUser` BOOLEAN NOT NULL DEFAULT false, `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, `updatedAt` TIMESTAMP NOT NULL, `instanceId` VARCHAR(191) NOT NULL, `parameters` JSON NULL, `openaiBotId` VARCHAR(191) NULL, `difyId` VARCHAR(191) NULL, `typebotId` VARCHAR(191) NULL, PRIMARY KEY (`id`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- AddForeignKey ALTER TABLE `Message` ADD CONSTRAINT `Message_sessionId_fkey` FOREIGN KEY (`sessionId`) REFERENCES `IntegrationSession`(`id`) ON DELETE SET NULL ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `IntegrationSession` ADD CONSTRAINT `IntegrationSession_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `IntegrationSession` ADD CONSTRAINT `IntegrationSession_openaiBotId_fkey` FOREIGN KEY (`openaiBotId`) REFERENCES `OpenaiBot`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `IntegrationSession` ADD CONSTRAINT `IntegrationSession_difyId_fkey` FOREIGN KEY (`difyId`) REFERENCES `Dify`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `IntegrationSession` ADD CONSTRAINT `IntegrationSession_typebotId_fkey` FOREIGN KEY (`typebotId`) REFERENCES `Typebot`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; ================================================ FILE: prisma/mysql-migrations/20240821203259_add_postgres_migrations/migration.sql ================================================ /* Warnings: - You are about to alter the column `createdAt` on the `Chat` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Chat` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Chatwoot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Chatwoot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Contact` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Contact` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Dify` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Dify` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `DifySetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `DifySetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `disconnectionAt` on the `Instance` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Instance` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Instance` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to drop the column `difyId` on the `IntegrationSession` table. All the data in the column will be lost. - You are about to drop the column `openaiBotId` on the `IntegrationSession` table. All the data in the column will be lost. - You are about to drop the column `typebotId` on the `IntegrationSession` table. All the data in the column will be lost. - You are about to alter the column `createdAt` on the `IntegrationSession` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `IntegrationSession` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Label` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Label` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Media` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `OpenaiBot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `OpenaiBot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `OpenaiCreds` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `OpenaiCreds` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `OpenaiSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `OpenaiSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Proxy` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Proxy` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Rabbitmq` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Rabbitmq` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Session` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Setting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Setting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Sqs` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Sqs` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Template` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Template` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Typebot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Typebot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `TypebotSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `TypebotSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Webhook` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Webhook` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Websocket` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Websocket` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. */ -- DropForeignKey ALTER TABLE `IntegrationSession` DROP FOREIGN KEY `IntegrationSession_difyId_fkey`; -- DropForeignKey ALTER TABLE `IntegrationSession` DROP FOREIGN KEY `IntegrationSession_openaiBotId_fkey`; -- DropForeignKey ALTER TABLE `IntegrationSession` DROP FOREIGN KEY `IntegrationSession_typebotId_fkey`; -- DropIndex DROP INDEX `Message_typebotSessionId_fkey` ON `Message`; -- AlterTable ALTER TABLE `Chat` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NULL; -- AlterTable ALTER TABLE `Chatwoot` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Contact` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NULL; -- AlterTable ALTER TABLE `Dify` MODIFY `triggerType` ENUM('all', 'keyword', 'none', 'advanced') NULL, MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `DifySetting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Instance` MODIFY `disconnectionAt` TIMESTAMP NULL, MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NULL; -- AlterTable ALTER TABLE `IntegrationSession` DROP COLUMN `difyId`, DROP COLUMN `openaiBotId`, DROP COLUMN `typebotId`, ADD COLUMN `botId` VARCHAR(191) NULL, ADD COLUMN `context` JSON NULL, MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Label` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Media` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP; -- AlterTable ALTER TABLE `OpenaiBot` MODIFY `triggerType` ENUM('all', 'keyword', 'none', 'advanced') NULL, MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `OpenaiCreds` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `OpenaiSetting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Proxy` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Rabbitmq` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Session` MODIFY `createdAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP; -- AlterTable ALTER TABLE `Setting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Sqs` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Template` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Typebot` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NULL, MODIFY `triggerType` ENUM('all', 'keyword', 'none', 'advanced') NULL; -- AlterTable ALTER TABLE `TypebotSetting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Webhook` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Websocket` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- CreateTable CREATE TABLE `GenericBot` ( `id` VARCHAR(191) NOT NULL, `enabled` BOOLEAN NOT NULL DEFAULT true, `description` VARCHAR(255) NULL, `apiUrl` VARCHAR(255) NULL, `apiKey` VARCHAR(255) NULL, `expire` INTEGER NULL DEFAULT 0, `keywordFinish` VARCHAR(100) NULL, `delayMessage` INTEGER NULL, `unknownMessage` VARCHAR(100) NULL, `listeningFromMe` BOOLEAN NULL DEFAULT false, `stopBotFromMe` BOOLEAN NULL DEFAULT false, `keepOpen` BOOLEAN NULL DEFAULT false, `debounceTime` INTEGER NULL, `ignoreJids` JSON NULL, `triggerType` ENUM('all', 'keyword', 'none', 'advanced') NULL, `triggerOperator` ENUM('contains', 'equals', 'startsWith', 'endsWith', 'regex') NULL, `triggerValue` VARCHAR(191) NULL, `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, `updatedAt` TIMESTAMP NOT NULL, `instanceId` VARCHAR(191) NOT NULL, PRIMARY KEY (`id`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- CreateTable CREATE TABLE `GenericSetting` ( `id` VARCHAR(191) NOT NULL, `expire` INTEGER NULL DEFAULT 0, `keywordFinish` VARCHAR(100) NULL, `delayMessage` INTEGER NULL, `unknownMessage` VARCHAR(100) NULL, `listeningFromMe` BOOLEAN NULL DEFAULT false, `stopBotFromMe` BOOLEAN NULL DEFAULT false, `keepOpen` BOOLEAN NULL DEFAULT false, `debounceTime` INTEGER NULL, `ignoreJids` JSON NULL, `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, `updatedAt` TIMESTAMP NOT NULL, `botIdFallback` VARCHAR(100) NULL, `instanceId` VARCHAR(191) NOT NULL, UNIQUE INDEX `GenericSetting_instanceId_key`(`instanceId`), PRIMARY KEY (`id`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- CreateTable CREATE TABLE `Flowise` ( `id` VARCHAR(191) NOT NULL, `enabled` BOOLEAN NOT NULL DEFAULT true, `description` VARCHAR(255) NULL, `apiUrl` VARCHAR(255) NULL, `apiKey` VARCHAR(255) NULL, `expire` INTEGER NULL DEFAULT 0, `keywordFinish` VARCHAR(100) NULL, `delayMessage` INTEGER NULL, `unknownMessage` VARCHAR(100) NULL, `listeningFromMe` BOOLEAN NULL DEFAULT false, `stopBotFromMe` BOOLEAN NULL DEFAULT false, `keepOpen` BOOLEAN NULL DEFAULT false, `debounceTime` INTEGER NULL, `ignoreJids` JSON NULL, `triggerType` ENUM('all', 'keyword', 'none', 'advanced') NULL, `triggerOperator` ENUM('contains', 'equals', 'startsWith', 'endsWith', 'regex') NULL, `triggerValue` VARCHAR(191) NULL, `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, `updatedAt` TIMESTAMP NOT NULL, `instanceId` VARCHAR(191) NOT NULL, PRIMARY KEY (`id`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- CreateTable CREATE TABLE `FlowiseSetting` ( `id` VARCHAR(191) NOT NULL, `expire` INTEGER NULL DEFAULT 0, `keywordFinish` VARCHAR(100) NULL, `delayMessage` INTEGER NULL, `unknownMessage` VARCHAR(100) NULL, `listeningFromMe` BOOLEAN NULL DEFAULT false, `stopBotFromMe` BOOLEAN NULL DEFAULT false, `keepOpen` BOOLEAN NULL DEFAULT false, `debounceTime` INTEGER NULL, `ignoreJids` JSON NULL, `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, `updatedAt` TIMESTAMP NOT NULL, `flowiseIdFallback` VARCHAR(100) NULL, `instanceId` VARCHAR(191) NOT NULL, UNIQUE INDEX `FlowiseSetting_instanceId_key`(`instanceId`), PRIMARY KEY (`id`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- AddForeignKey ALTER TABLE `GenericBot` ADD CONSTRAINT `GenericBot_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `GenericSetting` ADD CONSTRAINT `GenericSetting_botIdFallback_fkey` FOREIGN KEY (`botIdFallback`) REFERENCES `GenericBot`(`id`) ON DELETE SET NULL ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `GenericSetting` ADD CONSTRAINT `GenericSetting_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `Flowise` ADD CONSTRAINT `Flowise_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `FlowiseSetting` ADD CONSTRAINT `FlowiseSetting_flowiseIdFallback_fkey` FOREIGN KEY (`flowiseIdFallback`) REFERENCES `Flowise`(`id`) ON DELETE SET NULL ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `FlowiseSetting` ADD CONSTRAINT `FlowiseSetting_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; ================================================ FILE: prisma/mysql-migrations/20240824162012_add_type_on_integration_sessions/migration.sql ================================================ /* Warnings: - You are about to alter the column `createdAt` on the `Chat` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Chat` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Chatwoot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Chatwoot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Contact` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Contact` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Dify` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Dify` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `DifySetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `DifySetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Flowise` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Flowise` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `FlowiseSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `FlowiseSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `GenericBot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `GenericBot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `GenericSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `GenericSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `disconnectionAt` on the `Instance` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Instance` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Instance` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `IntegrationSession` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `IntegrationSession` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Label` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Label` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Media` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `OpenaiBot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `OpenaiBot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `OpenaiCreds` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `OpenaiCreds` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `OpenaiSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `OpenaiSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Proxy` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Proxy` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Rabbitmq` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Rabbitmq` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Session` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Setting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Setting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Sqs` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Sqs` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Template` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Template` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Typebot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Typebot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `TypebotSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `TypebotSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Webhook` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Webhook` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Websocket` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Websocket` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. */ -- AlterTable ALTER TABLE `Chat` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NULL; -- AlterTable ALTER TABLE `Chatwoot` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Contact` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NULL; -- AlterTable ALTER TABLE `Dify` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `DifySetting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Flowise` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `FlowiseSetting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `GenericBot` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `GenericSetting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Instance` MODIFY `disconnectionAt` TIMESTAMP NULL, MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NULL; -- AlterTable ALTER TABLE `IntegrationSession` ADD COLUMN `type` VARCHAR(100) NULL, MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Label` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Media` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP; -- AlterTable ALTER TABLE `OpenaiBot` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `OpenaiCreds` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `OpenaiSetting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Proxy` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Rabbitmq` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Session` MODIFY `createdAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP; -- AlterTable ALTER TABLE `Setting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Sqs` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Template` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Typebot` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NULL; -- AlterTable ALTER TABLE `TypebotSetting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Webhook` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Websocket` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; ================================================ FILE: prisma/mysql-migrations/20240825131301_change_to_evolution_bot/migration.sql ================================================ /* Warnings: - You are about to alter the column `createdAt` on the `Chat` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Chat` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Chatwoot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Chatwoot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Contact` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Contact` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Dify` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Dify` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `DifySetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `DifySetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Flowise` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Flowise` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `FlowiseSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `FlowiseSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `disconnectionAt` on the `Instance` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Instance` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Instance` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `IntegrationSession` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `IntegrationSession` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Label` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Label` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Media` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `OpenaiBot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `OpenaiBot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `OpenaiCreds` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `OpenaiCreds` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `OpenaiSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `OpenaiSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Proxy` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Proxy` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Rabbitmq` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Rabbitmq` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Session` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Setting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Setting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Sqs` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Sqs` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Template` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Template` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Typebot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Typebot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `TypebotSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `TypebotSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Webhook` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Webhook` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Websocket` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Websocket` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to drop the `GenericBot` table. If the table is not empty, all the data it contains will be lost. - You are about to drop the `GenericSetting` table. If the table is not empty, all the data it contains will be lost. */ -- DropForeignKey ALTER TABLE `GenericBot` DROP FOREIGN KEY `GenericBot_instanceId_fkey`; -- DropForeignKey ALTER TABLE `GenericSetting` DROP FOREIGN KEY `GenericSetting_botIdFallback_fkey`; -- DropForeignKey ALTER TABLE `GenericSetting` DROP FOREIGN KEY `GenericSetting_instanceId_fkey`; -- AlterTable ALTER TABLE `Chat` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NULL; -- AlterTable ALTER TABLE `Chatwoot` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Contact` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NULL; -- AlterTable ALTER TABLE `Dify` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `DifySetting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Flowise` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `FlowiseSetting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Instance` MODIFY `disconnectionAt` TIMESTAMP NULL, MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NULL; -- AlterTable ALTER TABLE `IntegrationSession` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Label` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Media` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP; -- AlterTable ALTER TABLE `OpenaiBot` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `OpenaiCreds` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `OpenaiSetting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Proxy` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Rabbitmq` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Session` MODIFY `createdAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP; -- AlterTable ALTER TABLE `Setting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Sqs` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Template` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Typebot` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NULL; -- AlterTable ALTER TABLE `TypebotSetting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Webhook` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Websocket` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- DropTable DROP TABLE `GenericBot`; -- DropTable DROP TABLE `GenericSetting`; -- CreateTable CREATE TABLE `EvolutionBot` ( `id` VARCHAR(191) NOT NULL, `enabled` BOOLEAN NOT NULL DEFAULT true, `description` VARCHAR(255) NULL, `apiUrl` VARCHAR(255) NULL, `apiKey` VARCHAR(255) NULL, `expire` INTEGER NULL DEFAULT 0, `keywordFinish` VARCHAR(100) NULL, `delayMessage` INTEGER NULL, `unknownMessage` VARCHAR(100) NULL, `listeningFromMe` BOOLEAN NULL DEFAULT false, `stopBotFromMe` BOOLEAN NULL DEFAULT false, `keepOpen` BOOLEAN NULL DEFAULT false, `debounceTime` INTEGER NULL, `ignoreJids` JSON NULL, `triggerType` ENUM('all', 'keyword', 'none', 'advanced') NULL, `triggerOperator` ENUM('contains', 'equals', 'startsWith', 'endsWith', 'regex') NULL, `triggerValue` VARCHAR(191) NULL, `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, `updatedAt` TIMESTAMP NOT NULL, `instanceId` VARCHAR(191) NOT NULL, PRIMARY KEY (`id`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- CreateTable CREATE TABLE `EvolutionBotSetting` ( `id` VARCHAR(191) NOT NULL, `expire` INTEGER NULL DEFAULT 0, `keywordFinish` VARCHAR(100) NULL, `delayMessage` INTEGER NULL, `unknownMessage` VARCHAR(100) NULL, `listeningFromMe` BOOLEAN NULL DEFAULT false, `stopBotFromMe` BOOLEAN NULL DEFAULT false, `keepOpen` BOOLEAN NULL DEFAULT false, `debounceTime` INTEGER NULL, `ignoreJids` JSON NULL, `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, `updatedAt` TIMESTAMP NOT NULL, `botIdFallback` VARCHAR(100) NULL, `instanceId` VARCHAR(191) NOT NULL, UNIQUE INDEX `EvolutionBotSetting_instanceId_key`(`instanceId`), PRIMARY KEY (`id`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- AddForeignKey ALTER TABLE `EvolutionBot` ADD CONSTRAINT `EvolutionBot_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `EvolutionBotSetting` ADD CONSTRAINT `EvolutionBotSetting_botIdFallback_fkey` FOREIGN KEY (`botIdFallback`) REFERENCES `EvolutionBot`(`id`) ON DELETE SET NULL ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `EvolutionBotSetting` ADD CONSTRAINT `EvolutionBotSetting_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; ================================================ FILE: prisma/mysql-migrations/20241001172800_add_message_status/migration.sql ================================================ /* Warnings: - You are about to alter the column `createdAt` on the `Chat` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Chat` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Chatwoot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Chatwoot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Contact` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Contact` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Dify` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Dify` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `DifySetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `DifySetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `EvolutionBot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `EvolutionBot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `EvolutionBotSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `EvolutionBotSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Flowise` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Flowise` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `FlowiseSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `FlowiseSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `disconnectionAt` on the `Instance` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Instance` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Instance` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `IntegrationSession` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `IntegrationSession` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Label` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Label` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Media` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `OpenaiBot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `OpenaiBot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `OpenaiCreds` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `OpenaiCreds` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `OpenaiSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `OpenaiSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Proxy` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Proxy` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Rabbitmq` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Rabbitmq` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Session` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Setting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Setting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Sqs` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Sqs` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Template` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Template` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Typebot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Typebot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `TypebotSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `TypebotSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Webhook` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Webhook` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Websocket` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Websocket` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. */ -- AlterTable ALTER TABLE `Chat` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NULL; -- AlterTable ALTER TABLE `Chatwoot` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Contact` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NULL; -- AlterTable ALTER TABLE `Dify` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `DifySetting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `EvolutionBot` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `EvolutionBotSetting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Flowise` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `FlowiseSetting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Instance` MODIFY `disconnectionAt` TIMESTAMP NULL, MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NULL; -- AlterTable ALTER TABLE `IntegrationSession` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Label` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Media` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP; -- AlterTable ALTER TABLE `Message` ADD COLUMN `status` INTEGER NULL; -- AlterTable ALTER TABLE `OpenaiBot` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `OpenaiCreds` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `OpenaiSetting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Proxy` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Rabbitmq` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Session` MODIFY `createdAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP; -- AlterTable ALTER TABLE `Setting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Sqs` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Template` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Typebot` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NULL; -- AlterTable ALTER TABLE `TypebotSetting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Webhook` ADD COLUMN `headers` JSON NULL, MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Websocket` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- CreateTable CREATE TABLE `IsOnWhatsapp` ( `id` VARCHAR(191) NOT NULL, `remoteJid` VARCHAR(100) NOT NULL, `jidOptions` VARCHAR(191) NOT NULL, `createdAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, `updatedAt` TIMESTAMP NOT NULL, UNIQUE INDEX `IsOnWhatsapp_remoteJid_key`(`remoteJid`), PRIMARY KEY (`id`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; ================================================ FILE: prisma/mysql-migrations/20241108101333_fix_message_status_as_string/migration.sql ================================================ /* Warnings: - You are about to alter the column `createdAt` on the `Chat` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Chat` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Chatwoot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Chatwoot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Contact` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Contact` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Dify` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Dify` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `DifySetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `DifySetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `EvolutionBot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `EvolutionBot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `EvolutionBotSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `EvolutionBotSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Flowise` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Flowise` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `FlowiseSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `FlowiseSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `disconnectionAt` on the `Instance` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Instance` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Instance` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `IntegrationSession` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `IntegrationSession` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `IsOnWhatsapp` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `IsOnWhatsapp` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Label` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Label` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Media` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `OpenaiBot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `OpenaiBot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `OpenaiCreds` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `OpenaiCreds` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `OpenaiSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `OpenaiSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Proxy` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Proxy` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Rabbitmq` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Rabbitmq` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Session` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Setting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Setting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Sqs` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Sqs` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Template` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Template` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Typebot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Typebot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `TypebotSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `TypebotSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Webhook` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Webhook` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Websocket` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Websocket` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. */ -- AlterTable ALTER TABLE `Chat` ADD COLUMN `unreadMessages` INTEGER NOT NULL DEFAULT 0, MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NULL; -- AlterTable ALTER TABLE `Chatwoot` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Contact` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NULL; -- AlterTable ALTER TABLE `Dify` ADD COLUMN `splitMessages` BOOLEAN NULL DEFAULT false, ADD COLUMN `timePerChar` INTEGER NULL DEFAULT 50, MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `DifySetting` ADD COLUMN `splitMessages` BOOLEAN NULL DEFAULT false, ADD COLUMN `timePerChar` INTEGER NULL DEFAULT 50, MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `EvolutionBot` ADD COLUMN `splitMessages` BOOLEAN NULL DEFAULT false, ADD COLUMN `timePerChar` INTEGER NULL DEFAULT 50, MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `EvolutionBotSetting` ADD COLUMN `splitMessages` BOOLEAN NULL DEFAULT false, ADD COLUMN `timePerChar` INTEGER NULL DEFAULT 50, MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Flowise` ADD COLUMN `splitMessages` BOOLEAN NULL DEFAULT false, ADD COLUMN `timePerChar` INTEGER NULL DEFAULT 50, MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `FlowiseSetting` ADD COLUMN `splitMessages` BOOLEAN NULL DEFAULT false, ADD COLUMN `timePerChar` INTEGER NULL DEFAULT 50, MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Instance` MODIFY `disconnectionAt` TIMESTAMP NULL, MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NULL; -- AlterTable ALTER TABLE `IntegrationSession` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `IsOnWhatsapp` MODIFY `createdAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Label` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Media` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP; -- AlterTable ALTER TABLE `Message` MODIFY `status` VARCHAR(30) NULL; -- AlterTable ALTER TABLE `OpenaiBot` ADD COLUMN `splitMessages` BOOLEAN NULL DEFAULT false, ADD COLUMN `timePerChar` INTEGER NULL DEFAULT 50, MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `OpenaiCreds` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `OpenaiSetting` ADD COLUMN `splitMessages` BOOLEAN NULL DEFAULT false, ADD COLUMN `timePerChar` INTEGER NULL DEFAULT 50, MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Proxy` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Rabbitmq` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Session` MODIFY `createdAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP; -- AlterTable ALTER TABLE `Setting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Sqs` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Template` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Typebot` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NULL; -- AlterTable ALTER TABLE `TypebotSetting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Webhook` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Websocket` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- CreateTable CREATE TABLE `Pusher` ( `id` VARCHAR(191) NOT NULL, `enabled` BOOLEAN NOT NULL DEFAULT false, `appId` VARCHAR(100) NOT NULL, `key` VARCHAR(100) NOT NULL, `secret` VARCHAR(100) NOT NULL, `cluster` VARCHAR(100) NOT NULL, `useTLS` BOOLEAN NOT NULL DEFAULT false, `events` JSON NOT NULL, `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, `updatedAt` TIMESTAMP NOT NULL, `instanceId` VARCHAR(191) NOT NULL, UNIQUE INDEX `Pusher_instanceId_key`(`instanceId`), PRIMARY KEY (`id`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- CreateIndex CREATE INDEX `Chat_remoteJid_idx` ON `Chat`(`remoteJid`); -- CreateIndex CREATE INDEX `Contact_remoteJid_idx` ON `Contact`(`remoteJid`); -- CreateIndex CREATE INDEX `Setting_instanceId_idx` ON `Setting`(`instanceId`); -- CreateIndex CREATE INDEX `Webhook_instanceId_idx` ON `Webhook`(`instanceId`); -- AddForeignKey ALTER TABLE `Pusher` ADD CONSTRAINT `Pusher_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; -- RenameIndex ALTER TABLE `Chat` RENAME INDEX `Chat_instanceId_fkey` TO `Chat_instanceId_idx`; -- RenameIndex ALTER TABLE `Contact` RENAME INDEX `Contact_instanceId_fkey` TO `Contact_instanceId_idx`; -- RenameIndex ALTER TABLE `Message` RENAME INDEX `Message_instanceId_fkey` TO `Message_instanceId_idx`; -- RenameIndex ALTER TABLE `MessageUpdate` RENAME INDEX `MessageUpdate_instanceId_fkey` TO `MessageUpdate_instanceId_idx`; -- RenameIndex ALTER TABLE `MessageUpdate` RENAME INDEX `MessageUpdate_messageId_fkey` TO `MessageUpdate_messageId_idx`; ================================================ FILE: prisma/mysql-migrations/20250214181954_add_wavoip_token_column/migration.sql ================================================ /* Warnings: - You are about to alter the column `createdAt` on the `Chat` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Chat` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Chatwoot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Chatwoot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Contact` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Contact` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Dify` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Dify` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `DifySetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `DifySetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `EvolutionBot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `EvolutionBot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `EvolutionBotSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `EvolutionBotSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Flowise` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Flowise` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `FlowiseSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `FlowiseSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `disconnectionAt` on the `Instance` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Instance` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Instance` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `IntegrationSession` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `IntegrationSession` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `IsOnWhatsapp` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `IsOnWhatsapp` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Label` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Label` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Media` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `OpenaiBot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `OpenaiBot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `OpenaiCreds` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `OpenaiCreds` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `OpenaiSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `OpenaiSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Proxy` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Proxy` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Pusher` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Pusher` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Rabbitmq` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Rabbitmq` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Session` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Setting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Setting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Sqs` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Sqs` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Template` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Template` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Typebot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Typebot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `TypebotSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `TypebotSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Webhook` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Webhook` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Websocket` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Websocket` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - A unique constraint covering the columns `[instanceId,remoteJid]` on the table `Chat` will be added. If there are existing duplicate values, this will fail. */ -- AlterTable ALTER TABLE `Chat` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NULL; -- AlterTable ALTER TABLE `Chatwoot` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Contact` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NULL; -- AlterTable ALTER TABLE `Dify` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `DifySetting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `EvolutionBot` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `EvolutionBotSetting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Flowise` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `FlowiseSetting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Instance` MODIFY `disconnectionAt` TIMESTAMP NULL, MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NULL; -- AlterTable ALTER TABLE `IntegrationSession` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `IsOnWhatsapp` MODIFY `createdAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Label` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Media` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP; -- AlterTable ALTER TABLE `OpenaiBot` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `OpenaiCreds` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `OpenaiSetting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Proxy` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Pusher` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Rabbitmq` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Session` MODIFY `createdAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP; -- AlterTable ALTER TABLE `Setting` ADD COLUMN `wavoipToken` VARCHAR(100) NULL, MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Sqs` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Template` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Typebot` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NULL; -- AlterTable ALTER TABLE `TypebotSetting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Webhook` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Websocket` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- CreateIndex CREATE UNIQUE INDEX `Chat_instanceId_remoteJid_key` ON `Chat`(`instanceId`, `remoteJid`); ================================================ FILE: prisma/mysql-migrations/20250225180031_add_nats_integration/migration.sql ================================================ -- CreateTable CREATE TABLE `Nats` ( `id` VARCHAR(191) NOT NULL, `enabled` BOOLEAN NOT NULL DEFAULT false, `events` JSON NOT NULL, `createdAt` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, `updatedAt` TIMESTAMP NOT NULL, `instanceId` VARCHAR(191) NOT NULL, PRIMARY KEY (`id`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- CreateIndex CREATE UNIQUE INDEX `Nats_instanceId_key` ON `Nats`(`instanceId`); -- AddForeignKey ALTER TABLE `Nats` ADD CONSTRAINT `Nats_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; ================================================ FILE: prisma/mysql-migrations/20250510035200_add_wavoip_token_to_settings_table/migration.sql ================================================ /* Warnings: - A unique constraint covering the columns `[remoteJid,instanceId]` on the table `Chat` will be added. If there are existing duplicate values, this will fail. */ -- AlterTable SET @column_exists := ( SELECT COUNT(*) FROM information_schema.columns WHERE table_schema = DATABASE() AND table_name = 'Setting' AND column_name = 'wavoipToken' ); SET @sql := IF(@column_exists = 0, 'ALTER TABLE Setting ADD COLUMN wavoipToken VARCHAR(100);', 'SELECT "Column already exists";' ); PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt; ALTER TABLE Chat ADD CONSTRAINT unique_remote_instance UNIQUE (remoteJid, instanceId); ================================================ FILE: prisma/mysql-migrations/20250514232744_add_n8n_table/migration.sql ================================================ -- CreateTable CREATE TABLE `N8n` ( `id` VARCHAR(191) NOT NULL, `enabled` BOOLEAN NOT NULL DEFAULT true, `description` VARCHAR(255), `webhookUrl` VARCHAR(255), `basicAuthUser` VARCHAR(255), `basicAuthPass` VARCHAR(255), `expire` INTEGER DEFAULT 0, `keywordFinish` VARCHAR(100), `delayMessage` INTEGER, `unknownMessage` VARCHAR(100), `listeningFromMe` BOOLEAN DEFAULT false, `stopBotFromMe` BOOLEAN DEFAULT false, `keepOpen` BOOLEAN DEFAULT false, `debounceTime` INTEGER, `ignoreJids` JSON, `splitMessages` BOOLEAN DEFAULT false, `timePerChar` INTEGER DEFAULT 50, `triggerType` ENUM('all', 'keyword', 'none') NULL, `triggerOperator` ENUM('contains', 'equals', 'startsWith', 'endsWith', 'regex') NULL, `triggerValue` VARCHAR(191) NULL, `createdAt` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, `updatedAt` TIMESTAMP NOT NULL, `instanceId` VARCHAR(191) NOT NULL, PRIMARY KEY (`id`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- CreateTable CREATE TABLE `N8nSetting` ( `id` VARCHAR(191) NOT NULL, `expire` INTEGER DEFAULT 0, `keywordFinish` VARCHAR(100), `delayMessage` INTEGER, `unknownMessage` VARCHAR(100), `listeningFromMe` BOOLEAN DEFAULT false, `stopBotFromMe` BOOLEAN DEFAULT false, `keepOpen` BOOLEAN DEFAULT false, `debounceTime` INTEGER, `ignoreJids` JSON, `splitMessages` BOOLEAN DEFAULT false, `timePerChar` INTEGER DEFAULT 50, `createdAt` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, `updatedAt` TIMESTAMP NOT NULL, `n8nIdFallback` VARCHAR(100), `instanceId` VARCHAR(191) NOT NULL, PRIMARY KEY (`id`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- CreateIndex CREATE UNIQUE INDEX `N8nSetting_instanceId_key` ON `N8nSetting`(`instanceId`); -- AddForeignKey ALTER TABLE `N8n` ADD CONSTRAINT `N8n_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `N8nSetting` ADD CONSTRAINT `N8nSetting_n8nIdFallback_fkey` FOREIGN KEY (`n8nIdFallback`) REFERENCES `N8n`(`id`) ON DELETE SET NULL ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `N8nSetting` ADD CONSTRAINT `N8nSetting_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; ================================================ FILE: prisma/mysql-migrations/20250515211815_add_evoai_table/migration.sql ================================================ -- CreateTable CREATE TABLE `Evoai` ( `id` VARCHAR(191) NOT NULL, `enabled` BOOLEAN NOT NULL DEFAULT true, `description` VARCHAR(255), `agentUrl` VARCHAR(255), `apiKey` VARCHAR(255), `expire` INTEGER DEFAULT 0, `keywordFinish` VARCHAR(100), `delayMessage` INTEGER, `unknownMessage` VARCHAR(100), `listeningFromMe` BOOLEAN DEFAULT false, `stopBotFromMe` BOOLEAN DEFAULT false, `keepOpen` BOOLEAN DEFAULT false, `debounceTime` INTEGER, `ignoreJids` JSON, `splitMessages` BOOLEAN DEFAULT false, `timePerChar` INTEGER DEFAULT 50, `triggerType` ENUM('all', 'keyword', 'none') NULL, `triggerOperator` ENUM('contains', 'equals', 'startsWith', 'endsWith', 'regex') NULL, `triggerValue` VARCHAR(191) NULL, `createdAt` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, `updatedAt` TIMESTAMP NOT NULL, `instanceId` VARCHAR(191) NOT NULL, PRIMARY KEY (`id`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- CreateTable CREATE TABLE `EvoaiSetting` ( `id` VARCHAR(191) NOT NULL, `expire` INTEGER DEFAULT 0, `keywordFinish` VARCHAR(100), `delayMessage` INTEGER, `unknownMessage` VARCHAR(100), `listeningFromMe` BOOLEAN DEFAULT false, `stopBotFromMe` BOOLEAN DEFAULT false, `keepOpen` BOOLEAN DEFAULT false, `debounceTime` INTEGER, `ignoreJids` JSON, `splitMessages` BOOLEAN DEFAULT false, `timePerChar` INTEGER DEFAULT 50, `createdAt` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, `updatedAt` TIMESTAMP NOT NULL, `evoaiIdFallback` VARCHAR(100), `instanceId` VARCHAR(191) NOT NULL, PRIMARY KEY (`id`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- CreateIndex CREATE UNIQUE INDEX `EvoaiSetting_instanceId_key` ON `EvoaiSetting`(`instanceId`); -- AddForeignKey ALTER TABLE `Evoai` ADD CONSTRAINT `Evoai_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `EvoaiSetting` ADD CONSTRAINT `EvoaiSetting_evoaiIdFallback_fkey` FOREIGN KEY (`evoaiIdFallback`) REFERENCES `Evoai`(`id`) ON DELETE SET NULL ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `EvoaiSetting` ADD CONSTRAINT `EvoaiSetting_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; ================================================ FILE: prisma/mysql-migrations/20250516012152_remove_unique_atribute_for_file_name_in_media/migration.sql ================================================ -- DropIndex ALTER TABLE `Media` DROP INDEX `Media_fileName_key`; ================================================ FILE: prisma/mysql-migrations/20250612155048_add_coluns_trypebot_tables/migration.sql ================================================ -- AlterTable ALTER TABLE `Typebot` ADD COLUMN `splitMessages` BOOLEAN DEFAULT false, ADD COLUMN `timePerChar` INTEGER DEFAULT 50; -- AlterTable ALTER TABLE `TypebotSetting` ADD COLUMN `splitMessages` BOOLEAN DEFAULT false, ADD COLUMN `timePerChar` INTEGER DEFAULT 50; ================================================ FILE: prisma/mysql-migrations/20250613143000_add_lid_column_to_is_onwhatsapp/migration.sql ================================================ -- AlterTable ALTER TABLE `IsOnWhatsapp` ADD COLUMN `lid` VARCHAR(100); ================================================ FILE: prisma/mysql-migrations/20250918183910_add_kafka_integration/migration.sql ================================================ /* Warnings: - You are about to alter the column `createdAt` on the `Chat` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Chat` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Chatwoot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Chatwoot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Contact` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Contact` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Dify` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Dify` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `DifySetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `DifySetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Evoai` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Evoai` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `EvoaiSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `EvoaiSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `EvolutionBot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `EvolutionBot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `EvolutionBotSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `EvolutionBotSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Flowise` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Flowise` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `FlowiseSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `FlowiseSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `disconnectionAt` on the `Instance` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Instance` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Instance` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `IntegrationSession` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `IntegrationSession` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to drop the column `lid` on the `IsOnWhatsapp` table. All the data in the column will be lost. - You are about to alter the column `createdAt` on the `IsOnWhatsapp` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `IsOnWhatsapp` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Label` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Label` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Media` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `N8n` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `N8n` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `N8nSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `N8nSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Nats` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Nats` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `OpenaiBot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `OpenaiBot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `OpenaiCreds` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `OpenaiCreds` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `OpenaiSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `OpenaiSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Proxy` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Proxy` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Pusher` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Pusher` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Rabbitmq` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Rabbitmq` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Session` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Setting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Setting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Sqs` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Sqs` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Template` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Template` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to drop the column `splitMessages` on the `Typebot` table. All the data in the column will be lost. - You are about to drop the column `timePerChar` on the `Typebot` table. All the data in the column will be lost. - You are about to alter the column `createdAt` on the `Typebot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Typebot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to drop the column `splitMessages` on the `TypebotSetting` table. All the data in the column will be lost. - You are about to drop the column `timePerChar` on the `TypebotSetting` table. All the data in the column will be lost. - You are about to alter the column `createdAt` on the `TypebotSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `TypebotSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Webhook` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Webhook` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `createdAt` on the `Websocket` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. - You are about to alter the column `updatedAt` on the `Websocket` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`. */ -- DropIndex DROP INDEX `unique_remote_instance` ON `Chat`; -- AlterTable ALTER TABLE `Chat` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NULL; -- AlterTable ALTER TABLE `Chatwoot` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Contact` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NULL; -- AlterTable ALTER TABLE `Dify` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `DifySetting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Evoai` MODIFY `triggerType` ENUM('all', 'keyword', 'none', 'advanced') NULL, MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `EvoaiSetting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `EvolutionBot` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `EvolutionBotSetting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Flowise` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `FlowiseSetting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Instance` MODIFY `disconnectionAt` TIMESTAMP NULL, MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NULL; -- AlterTable ALTER TABLE `IntegrationSession` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `IsOnWhatsapp` DROP COLUMN `lid`, MODIFY `createdAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Label` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Media` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP; -- AlterTable ALTER TABLE `N8n` MODIFY `triggerType` ENUM('all', 'keyword', 'none', 'advanced') NULL, MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `N8nSetting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Nats` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `OpenaiBot` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `OpenaiCreds` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `OpenaiSetting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Proxy` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Pusher` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Rabbitmq` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Session` MODIFY `createdAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP; -- AlterTable ALTER TABLE `Setting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Sqs` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Template` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Typebot` DROP COLUMN `splitMessages`, DROP COLUMN `timePerChar`, MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NULL; -- AlterTable ALTER TABLE `TypebotSetting` DROP COLUMN `splitMessages`, DROP COLUMN `timePerChar`, MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Webhook` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- AlterTable ALTER TABLE `Websocket` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, MODIFY `updatedAt` TIMESTAMP NOT NULL; -- CreateTable CREATE TABLE `Kafka` ( `id` VARCHAR(191) NOT NULL, `enabled` BOOLEAN NOT NULL DEFAULT false, `events` JSON NOT NULL, `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, `updatedAt` TIMESTAMP NOT NULL, `instanceId` VARCHAR(191) NOT NULL, UNIQUE INDEX `Kafka_instanceId_key`(`instanceId`), PRIMARY KEY (`id`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- AddForeignKey ALTER TABLE `Kafka` ADD CONSTRAINT `Kafka_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; ================================================ FILE: prisma/mysql-migrations/migration_lock.toml ================================================ # Please do not edit this file manually # It should be added in your version-control system (e.g., Git) provider = "mysql" ================================================ FILE: prisma/mysql-schema.prisma ================================================ // This is your Prisma schema file, // learn more about it in the docs: https://pris.ly/d/prisma-schema // Looking for ways to speed up your queries, or scale easily with your serverless or edge functions? // Try Prisma Accelerate: https://pris.ly/cli/accelerate-init generator client { provider = "prisma-client-js" } datasource db { provider = "mysql" url = env("DATABASE_CONNECTION_URI") } enum InstanceConnectionStatus { open close connecting } enum DeviceMessage { ios android web unknown desktop } enum SessionStatus { opened closed paused } enum TriggerType { all keyword none advanced } enum TriggerOperator { contains equals startsWith endsWith regex } enum OpenaiBotType { assistant chatCompletion } enum DifyBotType { chatBot textGenerator agent workflow } model Instance { id String @id @default(cuid()) name String @unique @db.VarChar(255) connectionStatus InstanceConnectionStatus @default(open) ownerJid String? @db.VarChar(100) profileName String? @db.VarChar(100) profilePicUrl String? @db.VarChar(500) integration String? @db.VarChar(100) number String? @db.VarChar(100) businessId String? @db.VarChar(100) token String? @db.VarChar(255) clientName String? @db.VarChar(100) disconnectionReasonCode Int? @db.Int disconnectionObject Json? @db.Json disconnectionAt DateTime? @db.Timestamp createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp updatedAt DateTime? @updatedAt @db.Timestamp Chat Chat[] Contact Contact[] Message Message[] Webhook Webhook? Chatwoot Chatwoot? Label Label[] Proxy Proxy? Setting Setting? Rabbitmq Rabbitmq? Nats Nats? Sqs Sqs? Kafka Kafka? Websocket Websocket? Typebot Typebot[] Session Session? MessageUpdate MessageUpdate[] TypebotSetting TypebotSetting? Media Media[] OpenaiCreds OpenaiCreds[] OpenaiBot OpenaiBot[] OpenaiSetting OpenaiSetting? Template Template[] Dify Dify[] DifySetting DifySetting? IntegrationSession IntegrationSession[] EvolutionBot EvolutionBot[] EvolutionBotSetting EvolutionBotSetting? Flowise Flowise[] FlowiseSetting FlowiseSetting? N8n N8n[] N8nSetting N8nSetting? Evoai Evoai[] EvoaiSetting EvoaiSetting? Pusher Pusher? } model Session { id String @id @default(cuid()) sessionId String @unique creds String? @db.Text createdAt DateTime @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp Instance Instance @relation(fields: [sessionId], references: [id], onDelete: Cascade) } model Chat { id String @id @default(cuid()) remoteJid String @db.VarChar(100) name String? @db.VarChar(100) labels Json? @db.Json createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp updatedAt DateTime? @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String unreadMessages Int @default(0) @@unique([instanceId, remoteJid]) @@index([instanceId]) @@index([remoteJid]) } model Contact { id String @id @default(cuid()) remoteJid String @db.VarChar(100) pushName String? @db.VarChar(100) profilePicUrl String? @db.VarChar(500) createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp updatedAt DateTime? @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @@unique([remoteJid, instanceId]) @@index([remoteJid]) @@index([instanceId]) } model Message { id String @id @default(cuid()) key Json @db.Json pushName String? @db.VarChar(100) participant String? @db.VarChar(100) messageType String @db.VarChar(100) message Json @db.Json contextInfo Json? @db.Json source DeviceMessage messageTimestamp Int @db.Int chatwootMessageId Int? @db.Int chatwootInboxId Int? @db.Int chatwootConversationId Int? @db.Int chatwootContactInboxSourceId String? @db.VarChar(100) chatwootIsRead Boolean? @default(false) Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String typebotSessionId String? MessageUpdate MessageUpdate[] Media Media? webhookUrl String? @db.VarChar(500) status String? @db.VarChar(30) sessionId String? session IntegrationSession? @relation(fields: [sessionId], references: [id]) @@index([instanceId]) } model MessageUpdate { id String @id @default(cuid()) keyId String @db.VarChar(100) remoteJid String @db.VarChar(100) fromMe Boolean participant String? @db.VarChar(100) pollUpdates Json? @db.Json status String @db.VarChar(30) Message Message @relation(fields: [messageId], references: [id], onDelete: Cascade) messageId String Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @@index([instanceId]) @@index([messageId]) } model Webhook { id String @id @default(cuid()) url String @db.VarChar(500) headers Json? @db.Json enabled Boolean? @default(true) events Json? @db.Json webhookByEvents Boolean? @default(false) webhookBase64 Boolean? @default(false) createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique @@index([instanceId]) } model Chatwoot { id String @id @default(cuid()) enabled Boolean? @default(true) accountId String? @db.VarChar(100) token String? @db.VarChar(100) url String? @db.VarChar(500) nameInbox String? @db.VarChar(100) signMsg Boolean? @default(false) signDelimiter String? @db.VarChar(100) number String? @db.VarChar(100) reopenConversation Boolean? @default(false) conversationPending Boolean? @default(false) mergeBrazilContacts Boolean? @default(false) importContacts Boolean? @default(false) importMessages Boolean? @default(false) daysLimitImportMessages Int? @db.Int organization String? @db.VarChar(100) logo String? @db.VarChar(500) ignoreJids Json? createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique } model Label { id String @id @default(cuid()) labelId String? @db.VarChar(100) name String @db.VarChar(100) color String @db.VarChar(100) predefinedId String? @db.VarChar(100) createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String } model Proxy { id String @id @default(cuid()) enabled Boolean @default(false) host String @db.VarChar(100) port String @db.VarChar(100) protocol String @db.VarChar(100) username String @db.VarChar(100) password String @db.VarChar(100) createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique } model Setting { id String @id @default(cuid()) rejectCall Boolean @default(false) msgCall String? @db.VarChar(100) groupsIgnore Boolean @default(false) alwaysOnline Boolean @default(false) readMessages Boolean @default(false) readStatus Boolean @default(false) syncFullHistory Boolean @default(false) wavoipToken String? @db.VarChar(100) createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique @@index([instanceId]) } model Rabbitmq { id String @id @default(cuid()) enabled Boolean @default(false) events Json @db.Json createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique } model Nats { id String @id @default(cuid()) enabled Boolean @default(false) events Json @db.Json createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique } model Sqs { id String @id @default(cuid()) enabled Boolean @default(false) events Json @db.Json createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique } model Kafka { id String @id @default(cuid()) enabled Boolean @default(false) events Json @db.Json createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique } model Websocket { id String @id @default(cuid()) enabled Boolean @default(false) events Json @db.Json createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique } model Pusher { id String @id @default(cuid()) enabled Boolean @default(false) appId String @db.VarChar(100) key String @db.VarChar(100) secret String @db.VarChar(100) cluster String @db.VarChar(100) useTLS Boolean @default(false) events Json @db.Json createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique } model Typebot { id String @id @default(cuid()) enabled Boolean @default(true) description String? @db.VarChar(255) url String @db.VarChar(500) typebot String @db.VarChar(100) expire Int? @default(0) @db.Int keywordFinish String? @db.VarChar(100) delayMessage Int? @db.Int unknownMessage String? @db.VarChar(100) listeningFromMe Boolean? @default(false) stopBotFromMe Boolean? @default(false) keepOpen Boolean? @default(false) debounceTime Int? @db.Int createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp updatedAt DateTime? @updatedAt @db.Timestamp ignoreJids Json? triggerType TriggerType? triggerOperator TriggerOperator? triggerValue String? Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String TypebotSetting TypebotSetting[] } model TypebotSetting { id String @id @default(cuid()) expire Int? @default(0) @db.Int keywordFinish String? @db.VarChar(100) delayMessage Int? @db.Int unknownMessage String? @db.VarChar(100) listeningFromMe Boolean? @default(false) stopBotFromMe Boolean? @default(false) keepOpen Boolean? @default(false) debounceTime Int? @db.Int typebotIdFallback String? @db.VarChar(100) ignoreJids Json? createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Fallback Typebot? @relation(fields: [typebotIdFallback], references: [id]) Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique } model IntegrationSession { id String @id @default(cuid()) sessionId String @db.VarChar(255) remoteJid String @db.VarChar(100) pushName String? status SessionStatus awaitUser Boolean @default(false) context Json? type String? @db.VarChar(100) createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Message Message[] Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String parameters Json? botId String? } model Media { id String @id @default(cuid()) fileName String @db.VarChar(500) type String @db.VarChar(100) mimetype String @db.VarChar(100) createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp Message Message @relation(fields: [messageId], references: [id], onDelete: Cascade) messageId String @unique Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String } model OpenaiCreds { id String @id @default(cuid()) name String? @unique @db.VarChar(255) apiKey String? @unique @db.VarChar(255) createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String OpenaiAssistant OpenaiBot[] OpenaiSetting OpenaiSetting? } model OpenaiBot { id String @id @default(cuid()) enabled Boolean @default(true) description String? @db.VarChar(255) botType OpenaiBotType assistantId String? @db.VarChar(255) functionUrl String? @db.VarChar(500) model String? @db.VarChar(100) systemMessages Json? @db.Json assistantMessages Json? @db.Json userMessages Json? @db.Json maxTokens Int? @db.Int expire Int? @default(0) @db.Int keywordFinish String? @db.VarChar(100) delayMessage Int? @db.Int unknownMessage String? @db.VarChar(100) listeningFromMe Boolean? @default(false) stopBotFromMe Boolean? @default(false) keepOpen Boolean? @default(false) debounceTime Int? @db.Int ignoreJids Json? splitMessages Boolean? @default(false) timePerChar Int? @default(50) @db.Int triggerType TriggerType? triggerOperator TriggerOperator? triggerValue String? createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp OpenaiCreds OpenaiCreds @relation(fields: [openaiCredsId], references: [id], onDelete: Cascade) openaiCredsId String Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String OpenaiSetting OpenaiSetting[] } model OpenaiSetting { id String @id @default(cuid()) expire Int? @default(0) @db.Int keywordFinish String? @db.VarChar(100) delayMessage Int? @db.Int unknownMessage String? @db.VarChar(100) listeningFromMe Boolean? @default(false) stopBotFromMe Boolean? @default(false) keepOpen Boolean? @default(false) debounceTime Int? @db.Int ignoreJids Json? splitMessages Boolean? @default(false) timePerChar Int? @default(50) @db.Int speechToText Boolean? @default(false) createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp OpenaiCreds OpenaiCreds? @relation(fields: [openaiCredsId], references: [id]) openaiCredsId String @unique Fallback OpenaiBot? @relation(fields: [openaiIdFallback], references: [id]) openaiIdFallback String? @db.VarChar(100) Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique } model Template { id String @id @default(cuid()) templateId String @unique @db.VarChar(255) name String @unique @db.VarChar(255) template Json @db.Json webhookUrl String? @db.VarChar(500) createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String } model Dify { id String @id @default(cuid()) enabled Boolean @default(true) description String? @db.VarChar(255) botType DifyBotType apiUrl String? @db.VarChar(255) apiKey String? @db.VarChar(255) expire Int? @default(0) @db.Int keywordFinish String? @db.VarChar(100) delayMessage Int? @db.Int unknownMessage String? @db.VarChar(100) listeningFromMe Boolean? @default(false) stopBotFromMe Boolean? @default(false) keepOpen Boolean? @default(false) debounceTime Int? @db.Int ignoreJids Json? splitMessages Boolean? @default(false) timePerChar Int? @default(50) @db.Int triggerType TriggerType? triggerOperator TriggerOperator? triggerValue String? createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String DifySetting DifySetting[] } model DifySetting { id String @id @default(cuid()) expire Int? @default(0) @db.Int keywordFinish String? @db.VarChar(100) delayMessage Int? @db.Int unknownMessage String? @db.VarChar(100) listeningFromMe Boolean? @default(false) stopBotFromMe Boolean? @default(false) keepOpen Boolean? @default(false) debounceTime Int? @db.Int ignoreJids Json? splitMessages Boolean? @default(false) timePerChar Int? @default(50) @db.Int createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Fallback Dify? @relation(fields: [difyIdFallback], references: [id]) difyIdFallback String? @db.VarChar(100) Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique } model EvolutionBot { id String @id @default(cuid()) enabled Boolean @default(true) description String? @db.VarChar(255) apiUrl String? @db.VarChar(255) apiKey String? @db.VarChar(255) expire Int? @default(0) @db.Int keywordFinish String? @db.VarChar(100) delayMessage Int? @db.Int unknownMessage String? @db.VarChar(100) listeningFromMe Boolean? @default(false) stopBotFromMe Boolean? @default(false) keepOpen Boolean? @default(false) debounceTime Int? @db.Int ignoreJids Json? splitMessages Boolean? @default(false) timePerChar Int? @default(50) @db.Int triggerType TriggerType? triggerOperator TriggerOperator? triggerValue String? createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String EvolutionBotSetting EvolutionBotSetting[] } model EvolutionBotSetting { id String @id @default(cuid()) expire Int? @default(0) @db.Int keywordFinish String? @db.VarChar(100) delayMessage Int? @db.Int unknownMessage String? @db.VarChar(100) listeningFromMe Boolean? @default(false) stopBotFromMe Boolean? @default(false) keepOpen Boolean? @default(false) debounceTime Int? @db.Int ignoreJids Json? splitMessages Boolean? @default(false) timePerChar Int? @default(50) @db.Int createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Fallback EvolutionBot? @relation(fields: [botIdFallback], references: [id]) botIdFallback String? @db.VarChar(100) Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique } model Flowise { id String @id @default(cuid()) enabled Boolean @default(true) description String? @db.VarChar(255) apiUrl String? @db.VarChar(255) apiKey String? @db.VarChar(255) expire Int? @default(0) @db.Int keywordFinish String? @db.VarChar(100) delayMessage Int? @db.Int unknownMessage String? @db.VarChar(100) listeningFromMe Boolean? @default(false) stopBotFromMe Boolean? @default(false) keepOpen Boolean? @default(false) debounceTime Int? @db.Int ignoreJids Json? splitMessages Boolean? @default(false) timePerChar Int? @default(50) @db.Int triggerType TriggerType? triggerOperator TriggerOperator? triggerValue String? createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String FlowiseSetting FlowiseSetting[] } model FlowiseSetting { id String @id @default(cuid()) expire Int? @default(0) @db.Int keywordFinish String? @db.VarChar(100) delayMessage Int? @db.Int unknownMessage String? @db.VarChar(100) listeningFromMe Boolean? @default(false) stopBotFromMe Boolean? @default(false) keepOpen Boolean? @default(false) debounceTime Int? @db.Int ignoreJids Json? splitMessages Boolean? @default(false) timePerChar Int? @default(50) @db.Int createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Fallback Flowise? @relation(fields: [flowiseIdFallback], references: [id]) flowiseIdFallback String? @db.VarChar(100) Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique } model IsOnWhatsapp { id String @id @default(cuid()) remoteJid String @unique @db.VarChar(100) jidOptions String createdAt DateTime @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp } model N8n { id String @id @default(cuid()) enabled Boolean @default(true) @db.TinyInt() description String? @db.VarChar(255) webhookUrl String? @db.VarChar(255) basicAuthUser String? @db.VarChar(255) basicAuthPass String? @db.VarChar(255) expire Int? @default(0) @db.Int keywordFinish String? @db.VarChar(100) delayMessage Int? @db.Int unknownMessage String? @db.VarChar(100) listeningFromMe Boolean? @default(false) stopBotFromMe Boolean? @default(false) keepOpen Boolean? @default(false) debounceTime Int? @db.Int ignoreJids Json? splitMessages Boolean? @default(false) timePerChar Int? @default(50) @db.Int triggerType TriggerType? triggerOperator TriggerOperator? triggerValue String? createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String N8nSetting N8nSetting[] } model N8nSetting { id String @id @default(cuid()) expire Int? @default(0) @db.Int keywordFinish String? @db.VarChar(100) delayMessage Int? @db.Int unknownMessage String? @db.VarChar(100) listeningFromMe Boolean? @default(false) stopBotFromMe Boolean? @default(false) keepOpen Boolean? @default(false) debounceTime Int? @db.Int ignoreJids Json? splitMessages Boolean? @default(false) timePerChar Int? @default(50) @db.Int createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Fallback N8n? @relation(fields: [n8nIdFallback], references: [id]) n8nIdFallback String? @db.VarChar(100) Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique } model Evoai { id String @id @default(cuid()) enabled Boolean @default(true) @db.TinyInt() description String? @db.VarChar(255) agentUrl String? @db.VarChar(255) apiKey String? @db.VarChar(255) expire Int? @default(0) @db.Int keywordFinish String? @db.VarChar(100) delayMessage Int? @db.Int unknownMessage String? @db.VarChar(100) listeningFromMe Boolean? @default(false) stopBotFromMe Boolean? @default(false) keepOpen Boolean? @default(false) debounceTime Int? @db.Int ignoreJids Json? splitMessages Boolean? @default(false) timePerChar Int? @default(50) @db.Int triggerType TriggerType? triggerOperator TriggerOperator? triggerValue String? createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String EvoaiSetting EvoaiSetting[] } model EvoaiSetting { id String @id @default(cuid()) expire Int? @default(0) @db.Int keywordFinish String? @db.VarChar(100) delayMessage Int? @db.Int unknownMessage String? @db.VarChar(100) listeningFromMe Boolean? @default(false) stopBotFromMe Boolean? @default(false) keepOpen Boolean? @default(false) debounceTime Int? @db.Int ignoreJids Json? splitMessages Boolean? @default(false) timePerChar Int? @default(50) @db.Int createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Fallback Evoai? @relation(fields: [evoaiIdFallback], references: [id]) evoaiIdFallback String? @db.VarChar(100) Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique } ================================================ FILE: prisma/postgresql-migrations/20240609181238_init/migration.sql ================================================ -- CreateEnum CREATE TYPE "InstanceConnectionStatus" AS ENUM ('open', 'close', 'connecting'); -- CreateEnum CREATE TYPE "DeviceMessage" AS ENUM ('ios', 'android', 'web', 'unknown', 'desktop'); -- CreateEnum CREATE TYPE "TypebotSessionStatus" AS ENUM ('open', 'closed', 'paused'); -- CreateEnum CREATE TYPE "TriggerType" AS ENUM ('all', 'keyword'); -- CreateEnum CREATE TYPE "TriggerOperator" AS ENUM ('contains', 'equals', 'startsWith', 'endsWith'); -- CreateTable CREATE TABLE "Instance" ( "id" TEXT NOT NULL, "name" VARCHAR(255) NOT NULL, "connectionStatus" "InstanceConnectionStatus" NOT NULL DEFAULT 'open', "ownerJid" VARCHAR(100), "profilePicUrl" VARCHAR(500), "integration" VARCHAR(100), "number" VARCHAR(100), "token" VARCHAR(255), "clientName" VARCHAR(100), "createdAt" TIMESTAMP DEFAULT CURRENT_TIMESTAMP, "updatedAt" TIMESTAMP, CONSTRAINT "Instance_pkey" PRIMARY KEY ("id") ); -- CreateTable CREATE TABLE "Session" ( "id" TEXT NOT NULL, "sessionId" TEXT NOT NULL, "creds" TEXT, "createdAt" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, CONSTRAINT "Session_pkey" PRIMARY KEY ("id") ); -- CreateTable CREATE TABLE "Chat" ( "id" TEXT NOT NULL, "remoteJid" VARCHAR(100) NOT NULL, "labels" JSONB, "createdAt" TIMESTAMP DEFAULT CURRENT_TIMESTAMP, "updatedAt" TIMESTAMP, "instanceId" TEXT NOT NULL, CONSTRAINT "Chat_pkey" PRIMARY KEY ("id") ); -- CreateTable CREATE TABLE "Contact" ( "id" TEXT NOT NULL, "remoteJid" VARCHAR(100) NOT NULL, "pushName" VARCHAR(100), "profilePicUrl" VARCHAR(500), "createdAt" TIMESTAMP DEFAULT CURRENT_TIMESTAMP, "updatedAt" TIMESTAMP, "instanceId" TEXT NOT NULL, CONSTRAINT "Contact_pkey" PRIMARY KEY ("id") ); -- CreateTable CREATE TABLE "Message" ( "id" TEXT NOT NULL, "key" JSONB NOT NULL, "pushName" VARCHAR(100), "participant" VARCHAR(100), "messageType" VARCHAR(100) NOT NULL, "message" JSONB NOT NULL, "contextInfo" JSONB, "source" "DeviceMessage" NOT NULL, "messageTimestamp" INTEGER NOT NULL, "chatwootMessageId" INTEGER, "chatwootInboxId" INTEGER, "chatwootConversationId" INTEGER, "chatwootContactInboxSourceId" VARCHAR(100), "chatwootIsRead" BOOLEAN, "instanceId" TEXT NOT NULL, "typebotSessionId" TEXT, CONSTRAINT "Message_pkey" PRIMARY KEY ("id") ); -- CreateTable CREATE TABLE "MessageUpdate" ( "id" TEXT NOT NULL, "keyId" VARCHAR(100) NOT NULL, "remoteJid" VARCHAR(100) NOT NULL, "fromMe" BOOLEAN NOT NULL, "participant" VARCHAR(100), "pollUpdates" JSONB, "status" VARCHAR(30) NOT NULL, "messageId" TEXT NOT NULL, "instanceId" TEXT NOT NULL, CONSTRAINT "MessageUpdate_pkey" PRIMARY KEY ("id") ); -- CreateTable CREATE TABLE "Webhook" ( "id" TEXT NOT NULL, "url" VARCHAR(500) NOT NULL, "enabled" BOOLEAN DEFAULT true, "events" JSONB, "webhookByEvents" BOOLEAN DEFAULT false, "webhookBase64" BOOLEAN DEFAULT false, "createdAt" TIMESTAMP DEFAULT CURRENT_TIMESTAMP, "updatedAt" TIMESTAMP NOT NULL, "instanceId" TEXT NOT NULL, CONSTRAINT "Webhook_pkey" PRIMARY KEY ("id") ); -- CreateTable CREATE TABLE "Chatwoot" ( "id" TEXT NOT NULL, "enabled" BOOLEAN DEFAULT true, "accountId" VARCHAR(100), "token" VARCHAR(100), "url" VARCHAR(500), "nameInbox" VARCHAR(100), "signMsg" BOOLEAN DEFAULT false, "signDelimiter" VARCHAR(100), "number" VARCHAR(100), "reopenConversation" BOOLEAN DEFAULT false, "conversationPending" BOOLEAN DEFAULT false, "mergeBrazilContacts" BOOLEAN DEFAULT false, "importContacts" BOOLEAN DEFAULT false, "importMessages" BOOLEAN DEFAULT false, "daysLimitImportMessages" INTEGER, "createdAt" TIMESTAMP DEFAULT CURRENT_TIMESTAMP, "updatedAt" TIMESTAMP NOT NULL, "instanceId" TEXT NOT NULL, CONSTRAINT "Chatwoot_pkey" PRIMARY KEY ("id") ); -- CreateTable CREATE TABLE "Label" ( "id" TEXT NOT NULL, "labelId" VARCHAR(100), "name" VARCHAR(100) NOT NULL, "color" VARCHAR(100) NOT NULL, "predefinedId" VARCHAR(100), "createdAt" TIMESTAMP DEFAULT CURRENT_TIMESTAMP, "updatedAt" TIMESTAMP NOT NULL, "instanceId" TEXT NOT NULL, CONSTRAINT "Label_pkey" PRIMARY KEY ("id") ); -- CreateTable CREATE TABLE "Proxy" ( "id" TEXT NOT NULL, "enabled" BOOLEAN NOT NULL DEFAULT false, "host" VARCHAR(100) NOT NULL, "port" VARCHAR(100) NOT NULL, "protocol" VARCHAR(100) NOT NULL, "username" VARCHAR(100) NOT NULL, "password" VARCHAR(100) NOT NULL, "createdAt" TIMESTAMP DEFAULT CURRENT_TIMESTAMP, "updatedAt" TIMESTAMP NOT NULL, "instanceId" TEXT NOT NULL, CONSTRAINT "Proxy_pkey" PRIMARY KEY ("id") ); -- CreateTable CREATE TABLE "Setting" ( "id" TEXT NOT NULL, "rejectCall" BOOLEAN NOT NULL DEFAULT false, "msgCall" VARCHAR(100), "groupsIgnore" BOOLEAN NOT NULL DEFAULT false, "alwaysOnline" BOOLEAN NOT NULL DEFAULT false, "readMessages" BOOLEAN NOT NULL DEFAULT false, "readStatus" BOOLEAN NOT NULL DEFAULT false, "syncFullHistory" BOOLEAN NOT NULL DEFAULT false, "createdAt" TIMESTAMP DEFAULT CURRENT_TIMESTAMP, "updatedAt" TIMESTAMP NOT NULL, "instanceId" TEXT NOT NULL, CONSTRAINT "Setting_pkey" PRIMARY KEY ("id") ); -- CreateTable CREATE TABLE "Rabbitmq" ( "id" TEXT NOT NULL, "enabled" BOOLEAN NOT NULL DEFAULT false, "events" JSONB NOT NULL, "createdAt" TIMESTAMP DEFAULT CURRENT_TIMESTAMP, "updatedAt" TIMESTAMP NOT NULL, "instanceId" TEXT NOT NULL, CONSTRAINT "Rabbitmq_pkey" PRIMARY KEY ("id") ); -- CreateTable CREATE TABLE "Sqs" ( "id" TEXT NOT NULL, "enabled" BOOLEAN NOT NULL DEFAULT false, "events" JSONB NOT NULL, "createdAt" TIMESTAMP DEFAULT CURRENT_TIMESTAMP, "updatedAt" TIMESTAMP NOT NULL, "instanceId" TEXT NOT NULL, CONSTRAINT "Sqs_pkey" PRIMARY KEY ("id") ); -- CreateTable CREATE TABLE "Websocket" ( "id" TEXT NOT NULL, "enabled" BOOLEAN NOT NULL DEFAULT false, "events" JSONB NOT NULL, "createdAt" TIMESTAMP DEFAULT CURRENT_TIMESTAMP, "updatedAt" TIMESTAMP NOT NULL, "instanceId" TEXT NOT NULL, CONSTRAINT "Websocket_pkey" PRIMARY KEY ("id") ); -- CreateTable CREATE TABLE "Typebot" ( "id" TEXT NOT NULL, "enabled" BOOLEAN NOT NULL DEFAULT true, "url" VARCHAR(500) NOT NULL, "typebot" VARCHAR(100) NOT NULL, "expire" INTEGER DEFAULT 0, "keywordFinish" VARCHAR(100), "delayMessage" INTEGER, "unknownMessage" VARCHAR(100), "listeningFromMe" BOOLEAN DEFAULT false, "stopBotFromMe" BOOLEAN DEFAULT false, "keepOpen" BOOLEAN DEFAULT false, "createdAt" TIMESTAMP DEFAULT CURRENT_TIMESTAMP, "updatedAt" TIMESTAMP, "triggerType" "TriggerType", "triggerOperator" "TriggerOperator", "triggerValue" TEXT, "instanceId" TEXT NOT NULL, CONSTRAINT "Typebot_pkey" PRIMARY KEY ("id") ); -- CreateTable CREATE TABLE "TypebotSession" ( "id" TEXT NOT NULL, "remoteJid" VARCHAR(100) NOT NULL, "pushName" VARCHAR(100), "sessionId" VARCHAR(100) NOT NULL, "status" VARCHAR(100) NOT NULL, "prefilledVariables" JSONB, "awaitUser" BOOLEAN NOT NULL DEFAULT false, "createdAt" TIMESTAMP DEFAULT CURRENT_TIMESTAMP, "updatedAt" TIMESTAMP NOT NULL, "typebotId" TEXT NOT NULL, "instanceId" TEXT NOT NULL, CONSTRAINT "TypebotSession_pkey" PRIMARY KEY ("id") ); -- CreateTable CREATE TABLE "TypebotSetting" ( "id" TEXT NOT NULL, "expire" INTEGER DEFAULT 0, "keywordFinish" VARCHAR(100), "delayMessage" INTEGER, "unknownMessage" VARCHAR(100), "listeningFromMe" BOOLEAN DEFAULT false, "stopBotFromMe" BOOLEAN DEFAULT false, "keepOpen" BOOLEAN DEFAULT false, "createdAt" TIMESTAMP DEFAULT CURRENT_TIMESTAMP, "updatedAt" TIMESTAMP NOT NULL, "instanceId" TEXT NOT NULL, CONSTRAINT "TypebotSetting_pkey" PRIMARY KEY ("id") ); -- CreateIndex CREATE UNIQUE INDEX "Instance_name_key" ON "Instance"("name"); -- CreateIndex CREATE UNIQUE INDEX "Instance_token_key" ON "Instance"("token"); -- CreateIndex CREATE UNIQUE INDEX "Session_sessionId_key" ON "Session"("sessionId"); -- CreateIndex CREATE UNIQUE INDEX "Webhook_instanceId_key" ON "Webhook"("instanceId"); -- CreateIndex CREATE UNIQUE INDEX "Chatwoot_instanceId_key" ON "Chatwoot"("instanceId"); -- CreateIndex CREATE UNIQUE INDEX "Label_labelId_key" ON "Label"("labelId"); -- CreateIndex CREATE UNIQUE INDEX "Proxy_instanceId_key" ON "Proxy"("instanceId"); -- CreateIndex CREATE UNIQUE INDEX "Setting_instanceId_key" ON "Setting"("instanceId"); -- CreateIndex CREATE UNIQUE INDEX "Rabbitmq_instanceId_key" ON "Rabbitmq"("instanceId"); -- CreateIndex CREATE UNIQUE INDEX "Sqs_instanceId_key" ON "Sqs"("instanceId"); -- CreateIndex CREATE UNIQUE INDEX "Websocket_instanceId_key" ON "Websocket"("instanceId"); -- CreateIndex CREATE UNIQUE INDEX "TypebotSetting_instanceId_key" ON "TypebotSetting"("instanceId"); -- AddForeignKey ALTER TABLE "Session" ADD CONSTRAINT "Session_sessionId_fkey" FOREIGN KEY ("sessionId") REFERENCES "Instance"("id") ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "Chat" ADD CONSTRAINT "Chat_instanceId_fkey" FOREIGN KEY ("instanceId") REFERENCES "Instance"("id") ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "Contact" ADD CONSTRAINT "Contact_instanceId_fkey" FOREIGN KEY ("instanceId") REFERENCES "Instance"("id") ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "Message" ADD CONSTRAINT "Message_instanceId_fkey" FOREIGN KEY ("instanceId") REFERENCES "Instance"("id") ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "Message" ADD CONSTRAINT "Message_typebotSessionId_fkey" FOREIGN KEY ("typebotSessionId") REFERENCES "TypebotSession"("id") ON DELETE SET NULL ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "MessageUpdate" ADD CONSTRAINT "MessageUpdate_messageId_fkey" FOREIGN KEY ("messageId") REFERENCES "Message"("id") ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "MessageUpdate" ADD CONSTRAINT "MessageUpdate_instanceId_fkey" FOREIGN KEY ("instanceId") REFERENCES "Instance"("id") ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "Webhook" ADD CONSTRAINT "Webhook_instanceId_fkey" FOREIGN KEY ("instanceId") REFERENCES "Instance"("id") ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "Chatwoot" ADD CONSTRAINT "Chatwoot_instanceId_fkey" FOREIGN KEY ("instanceId") REFERENCES "Instance"("id") ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "Label" ADD CONSTRAINT "Label_instanceId_fkey" FOREIGN KEY ("instanceId") REFERENCES "Instance"("id") ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "Proxy" ADD CONSTRAINT "Proxy_instanceId_fkey" FOREIGN KEY ("instanceId") REFERENCES "Instance"("id") ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "Setting" ADD CONSTRAINT "Setting_instanceId_fkey" FOREIGN KEY ("instanceId") REFERENCES "Instance"("id") ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "Rabbitmq" ADD CONSTRAINT "Rabbitmq_instanceId_fkey" FOREIGN KEY ("instanceId") REFERENCES "Instance"("id") ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "Sqs" ADD CONSTRAINT "Sqs_instanceId_fkey" FOREIGN KEY ("instanceId") REFERENCES "Instance"("id") ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "Websocket" ADD CONSTRAINT "Websocket_instanceId_fkey" FOREIGN KEY ("instanceId") REFERENCES "Instance"("id") ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "Typebot" ADD CONSTRAINT "Typebot_instanceId_fkey" FOREIGN KEY ("instanceId") REFERENCES "Instance"("id") ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "TypebotSession" ADD CONSTRAINT "TypebotSession_typebotId_fkey" FOREIGN KEY ("typebotId") REFERENCES "Typebot"("id") ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "TypebotSession" ADD CONSTRAINT "TypebotSession_instanceId_fkey" FOREIGN KEY ("instanceId") REFERENCES "Instance"("id") ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "TypebotSetting" ADD CONSTRAINT "TypebotSetting_instanceId_fkey" FOREIGN KEY ("instanceId") REFERENCES "Instance"("id") ON DELETE CASCADE ON UPDATE CASCADE; ================================================ FILE: prisma/postgresql-migrations/20240610144159_create_column_profile_name_instance/migration.sql ================================================ -- AlterTable ALTER TABLE "Instance" ADD COLUMN "profileName" VARCHAR(100); ================================================ FILE: prisma/postgresql-migrations/20240611125754_create_columns_whitelabel_chatwoot/migration.sql ================================================ -- AlterTable ALTER TABLE "Chatwoot" ADD COLUMN "logo" VARCHAR(500), ADD COLUMN "organization" VARCHAR(100); ================================================ FILE: prisma/postgresql-migrations/20240611202817_create_columns_debounce_time_typebot/migration.sql ================================================ -- AlterTable ALTER TABLE "Typebot" ADD COLUMN "debounceTime" INTEGER; -- AlterTable ALTER TABLE "TypebotSetting" ADD COLUMN "debounceTime" INTEGER; ================================================ FILE: prisma/postgresql-migrations/20240712144948_add_business_id_column_to_instances/migration.sql ================================================ -- AlterTable ALTER TABLE "Instance" ADD COLUMN "businessId" VARCHAR(100); ================================================ FILE: prisma/postgresql-migrations/20240712150256_create_templates_table/migration.sql ================================================ -- CreateTable CREATE TABLE "Template" ( "id" TEXT NOT NULL, "name" VARCHAR(255) NOT NULL, "language" VARCHAR(255) NOT NULL, "templateId" VARCHAR(255) NOT NULL, "createdAt" TIMESTAMP DEFAULT CURRENT_TIMESTAMP, "updatedAt" TIMESTAMP NOT NULL, "instanceId" TEXT NOT NULL, CONSTRAINT "Template_pkey" PRIMARY KEY ("id") ); -- CreateIndex CREATE UNIQUE INDEX "Template_templateId_key" ON "Template"("templateId"); -- CreateIndex CREATE UNIQUE INDEX "Template_instanceId_key" ON "Template"("instanceId"); -- AddForeignKey ALTER TABLE "Template" ADD CONSTRAINT "Template_instanceId_fkey" FOREIGN KEY ("instanceId") REFERENCES "Instance"("id") ON DELETE CASCADE ON UPDATE CASCADE; ================================================ FILE: prisma/postgresql-migrations/20240712155950_adjusts_in_templates_table/migration.sql ================================================ -- DropIndex DROP INDEX "Template_instanceId_key"; ================================================ FILE: prisma/postgresql-migrations/20240712162206_remove_templates_table/migration.sql ================================================ /* Warnings: - You are about to drop the `Template` table. If the table is not empty, all the data it contains will be lost. */ -- DropForeignKey ALTER TABLE "Template" DROP CONSTRAINT "Template_instanceId_fkey"; -- DropTable DROP TABLE "Template"; ================================================ FILE: prisma/postgresql-migrations/20240712223655_column_fallback_typebot/migration.sql ================================================ -- AlterEnum ALTER TYPE "TriggerOperator" ADD VALUE 'regex'; -- AlterTable ALTER TABLE "TypebotSetting" ADD COLUMN "typebotIdFallback" VARCHAR(100); -- AddForeignKey ALTER TABLE "TypebotSetting" ADD CONSTRAINT "TypebotSetting_typebotIdFallback_fkey" FOREIGN KEY ("typebotIdFallback") REFERENCES "Typebot"("id") ON DELETE SET NULL ON UPDATE CASCADE; ================================================ FILE: prisma/postgresql-migrations/20240712230631_column_ignore_jids_typebot/migration.sql ================================================ -- AlterTable ALTER TABLE "Typebot" ADD COLUMN "ignoreJids" JSONB; -- AlterTable ALTER TABLE "TypebotSetting" ADD COLUMN "ignoreJids" JSONB; ================================================ FILE: prisma/postgresql-migrations/20240713184337_add_media_table/migration.sql ================================================ -- CreateTable CREATE TABLE "Media" ( "id" TEXT NOT NULL, "fileName" VARCHAR(500) NOT NULL, "type" VARCHAR(100) NOT NULL, "mimetype" VARCHAR(100) NOT NULL, "createdAt" DATE DEFAULT CURRENT_TIMESTAMP, "messageId" TEXT NOT NULL, "instanceId" TEXT NOT NULL, CONSTRAINT "Media_pkey" PRIMARY KEY ("id") ); -- CreateIndex CREATE UNIQUE INDEX "Media_fileName_key" ON "Media"("fileName"); -- CreateIndex CREATE UNIQUE INDEX "Media_messageId_key" ON "Media"("messageId"); -- AddForeignKey ALTER TABLE "Media" ADD CONSTRAINT "Media_messageId_fkey" FOREIGN KEY ("messageId") REFERENCES "Message"("id") ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "Media" ADD CONSTRAINT "Media_instanceId_fkey" FOREIGN KEY ("instanceId") REFERENCES "Instance"("id") ON DELETE CASCADE ON UPDATE CASCADE; ================================================ FILE: prisma/postgresql-migrations/20240718121437_add_openai_tables/migration.sql ================================================ -- AlterTable ALTER TABLE "Message" ADD COLUMN "openaiSessionId" TEXT; -- CreateTable CREATE TABLE "OpenaiCreds" ( "id" TEXT NOT NULL, "apiKey" VARCHAR(255) NOT NULL, "createdAt" TIMESTAMP DEFAULT CURRENT_TIMESTAMP, "updatedAt" TIMESTAMP NOT NULL, "instanceId" TEXT NOT NULL, CONSTRAINT "OpenaiCreds_pkey" PRIMARY KEY ("id") ); -- CreateTable CREATE TABLE "OpenaiBot" ( "id" TEXT NOT NULL, "botType" VARCHAR(100) NOT NULL, "assistantId" VARCHAR(255), "model" VARCHAR(100), "systemMessages" JSONB, "assistantMessages" JSONB, "userMessages" JSONB, "maxTokens" INTEGER, "expire" INTEGER DEFAULT 0, "keywordFinish" VARCHAR(100), "delayMessage" INTEGER, "unknownMessage" VARCHAR(100), "listeningFromMe" BOOLEAN DEFAULT false, "stopBotFromMe" BOOLEAN DEFAULT false, "keepOpen" BOOLEAN DEFAULT false, "debounceTime" INTEGER, "ignoreJids" JSONB, "triggerType" "TriggerType", "triggerOperator" "TriggerOperator", "triggerValue" TEXT, "createdAt" TIMESTAMP DEFAULT CURRENT_TIMESTAMP, "updatedAt" TIMESTAMP NOT NULL, "openaiCredsId" TEXT NOT NULL, "instanceId" TEXT NOT NULL, CONSTRAINT "OpenaiBot_pkey" PRIMARY KEY ("id") ); -- CreateTable CREATE TABLE "OpenaiSession" ( "id" TEXT NOT NULL, "sessionId" VARCHAR(255) NOT NULL, "remoteJid" VARCHAR(100) NOT NULL, "status" "TypebotSessionStatus" NOT NULL, "awaitUser" BOOLEAN NOT NULL DEFAULT false, "createdAt" TIMESTAMP DEFAULT CURRENT_TIMESTAMP, "updatedAt" TIMESTAMP NOT NULL, "openaiBotId" TEXT NOT NULL, "instanceId" TEXT NOT NULL, CONSTRAINT "OpenaiSession_pkey" PRIMARY KEY ("id") ); -- CreateTable CREATE TABLE "OpenaiSetting" ( "id" TEXT NOT NULL, "expire" INTEGER DEFAULT 0, "keywordFinish" VARCHAR(100), "delayMessage" INTEGER, "unknownMessage" VARCHAR(100), "listeningFromMe" BOOLEAN DEFAULT false, "stopBotFromMe" BOOLEAN DEFAULT false, "keepOpen" BOOLEAN DEFAULT false, "debounceTime" INTEGER, "ignoreJids" JSONB, "createdAt" TIMESTAMP DEFAULT CURRENT_TIMESTAMP, "updatedAt" TIMESTAMP NOT NULL, "openaiCredsId" TEXT NOT NULL, "openaiIdFallback" VARCHAR(100), "instanceId" TEXT NOT NULL, CONSTRAINT "OpenaiSetting_pkey" PRIMARY KEY ("id") ); -- CreateIndex CREATE UNIQUE INDEX "OpenaiCreds_apiKey_key" ON "OpenaiCreds"("apiKey"); -- CreateIndex CREATE UNIQUE INDEX "OpenaiCreds_instanceId_key" ON "OpenaiCreds"("instanceId"); -- CreateIndex CREATE UNIQUE INDEX "OpenaiBot_assistantId_key" ON "OpenaiBot"("assistantId"); -- CreateIndex CREATE UNIQUE INDEX "OpenaiSetting_instanceId_key" ON "OpenaiSetting"("instanceId"); -- AddForeignKey ALTER TABLE "Message" ADD CONSTRAINT "Message_openaiSessionId_fkey" FOREIGN KEY ("openaiSessionId") REFERENCES "OpenaiSession"("id") ON DELETE SET NULL ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "OpenaiCreds" ADD CONSTRAINT "OpenaiCreds_instanceId_fkey" FOREIGN KEY ("instanceId") REFERENCES "Instance"("id") ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "OpenaiBot" ADD CONSTRAINT "OpenaiBot_openaiCredsId_fkey" FOREIGN KEY ("openaiCredsId") REFERENCES "OpenaiCreds"("id") ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "OpenaiBot" ADD CONSTRAINT "OpenaiBot_instanceId_fkey" FOREIGN KEY ("instanceId") REFERENCES "Instance"("id") ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "OpenaiSession" ADD CONSTRAINT "OpenaiSession_openaiBotId_fkey" FOREIGN KEY ("openaiBotId") REFERENCES "OpenaiBot"("id") ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "OpenaiSession" ADD CONSTRAINT "OpenaiSession_instanceId_fkey" FOREIGN KEY ("instanceId") REFERENCES "Instance"("id") ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "OpenaiSetting" ADD CONSTRAINT "OpenaiSetting_openaiCredsId_fkey" FOREIGN KEY ("openaiCredsId") REFERENCES "OpenaiCreds"("id") ON DELETE RESTRICT ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "OpenaiSetting" ADD CONSTRAINT "OpenaiSetting_openaiIdFallback_fkey" FOREIGN KEY ("openaiIdFallback") REFERENCES "OpenaiBot"("id") ON DELETE SET NULL ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "OpenaiSetting" ADD CONSTRAINT "OpenaiSetting_instanceId_fkey" FOREIGN KEY ("instanceId") REFERENCES "Instance"("id") ON DELETE CASCADE ON UPDATE CASCADE; ================================================ FILE: prisma/postgresql-migrations/20240718123923_adjusts_openai_tables/migration.sql ================================================ -- AlterTable ALTER TABLE "OpenaiBot" ADD COLUMN "enabled" BOOLEAN NOT NULL DEFAULT true; ================================================ FILE: prisma/postgresql-migrations/20240722173259_add_name_column_to_openai_creds/migration.sql ================================================ /* Warnings: - A unique constraint covering the columns `[name]` on the table `OpenaiCreds` will be added. If there are existing duplicate values, this will fail. */ -- AlterTable ALTER TABLE "OpenaiCreds" ADD COLUMN "name" VARCHAR(255), ALTER COLUMN "apiKey" DROP NOT NULL; -- CreateIndex CREATE UNIQUE INDEX "OpenaiCreds_name_key" ON "OpenaiCreds"("name"); ================================================ FILE: prisma/postgresql-migrations/20240722173518_add_name_column_to_openai_creds/migration.sql ================================================ -- DropIndex DROP INDEX "OpenaiCreds_instanceId_key"; ================================================ FILE: prisma/postgresql-migrations/20240723152648_adjusts_in_column_openai_creds/migration.sql ================================================ /* Warnings: - A unique constraint covering the columns `[openaiCredsId]` on the table `OpenaiSetting` will be added. If there are existing duplicate values, this will fail. */ -- CreateIndex CREATE UNIQUE INDEX "OpenaiSetting_openaiCredsId_key" ON "OpenaiSetting"("openaiCredsId"); ================================================ FILE: prisma/postgresql-migrations/20240723200254_add_webhookurl_on_message/migration.sql ================================================ -- AlterTable ALTER TABLE "Message" ADD COLUMN "webhookUrl" VARCHAR(500); ================================================ FILE: prisma/postgresql-migrations/20240725184147_create_template_table/migration.sql ================================================ -- CreateTable CREATE TABLE "Template" ( "id" TEXT NOT NULL, "templateId" VARCHAR(255) NOT NULL, "name" VARCHAR(255) NOT NULL, "template" JSONB NOT NULL, "createdAt" TIMESTAMP DEFAULT CURRENT_TIMESTAMP, "updatedAt" TIMESTAMP NOT NULL, "instanceId" TEXT NOT NULL, CONSTRAINT "Template_pkey" PRIMARY KEY ("id") ); -- CreateIndex CREATE UNIQUE INDEX "Template_templateId_key" ON "Template"("templateId"); -- CreateIndex CREATE UNIQUE INDEX "Template_name_key" ON "Template"("name"); -- AddForeignKey ALTER TABLE "Template" ADD CONSTRAINT "Template_instanceId_fkey" FOREIGN KEY ("instanceId") REFERENCES "Instance"("id") ON DELETE CASCADE ON UPDATE CASCADE; ================================================ FILE: prisma/postgresql-migrations/20240725202651_add_webhook_url_template_table/migration.sql ================================================ -- AlterTable ALTER TABLE "Template" ADD COLUMN "webhookUrl" VARCHAR(500); ================================================ FILE: prisma/postgresql-migrations/20240725221646_modify_token_instance_table/migration.sql ================================================ -- DropIndex DROP INDEX "Instance_token_key"; ================================================ FILE: prisma/postgresql-migrations/20240729115127_modify_trigger_type_openai_typebot_table/migration.sql ================================================ -- AlterEnum ALTER TYPE "TriggerType" ADD VALUE 'none'; ================================================ FILE: prisma/postgresql-migrations/20240729180347_modify_typebot_session_status_openai_typebot_table/migration.sql ================================================ /* Warnings: - The values [open] on the enum `TypebotSessionStatus` will be removed. If these variants are still used in the database, this will fail. - Changed the type of `status` on the `TypebotSession` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required. */ -- AlterEnum BEGIN; CREATE TYPE "TypebotSessionStatus_new" AS ENUM ('opened', 'closed', 'paused'); ALTER TABLE "TypebotSession" ALTER COLUMN "status" TYPE "TypebotSessionStatus_new" USING ("status"::text::"TypebotSessionStatus_new"); ALTER TABLE "OpenaiSession" ALTER COLUMN "status" TYPE "TypebotSessionStatus_new" USING ("status"::text::"TypebotSessionStatus_new"); ALTER TYPE "TypebotSessionStatus" RENAME TO "TypebotSessionStatus_old"; ALTER TYPE "TypebotSessionStatus_new" RENAME TO "TypebotSessionStatus"; DROP TYPE "TypebotSessionStatus_old"; COMMIT; -- AlterTable ALTER TABLE "TypebotSession" DROP COLUMN "status", ADD COLUMN "status" "TypebotSessionStatus" NOT NULL; ================================================ FILE: prisma/postgresql-migrations/20240730152156_create_dify_tables/migration.sql ================================================ /* Warnings: - Changed the type of `botType` on the `OpenaiBot` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required. */ -- CreateEnum CREATE TYPE "OpenaiBotType" AS ENUM ('assistant', 'chatCompletion'); -- CreateEnum CREATE TYPE "DifyBotType" AS ENUM ('chatBot', 'textGenerator', 'agent', 'workflow'); -- DropIndex DROP INDEX "OpenaiBot_assistantId_key"; -- AlterTable ALTER TABLE "Message" ADD COLUMN "difySessionId" TEXT; -- AlterTable ALTER TABLE "OpenaiBot" DROP COLUMN "botType", ADD COLUMN "botType" "OpenaiBotType" NOT NULL; -- CreateTable CREATE TABLE "Dify" ( "id" TEXT NOT NULL, "enabled" BOOLEAN NOT NULL DEFAULT true, "botType" "DifyBotType" NOT NULL, "apiUrl" VARCHAR(255), "apiKey" VARCHAR(255), "expire" INTEGER DEFAULT 0, "keywordFinish" VARCHAR(100), "delayMessage" INTEGER, "unknownMessage" VARCHAR(100), "listeningFromMe" BOOLEAN DEFAULT false, "stopBotFromMe" BOOLEAN DEFAULT false, "keepOpen" BOOLEAN DEFAULT false, "debounceTime" INTEGER, "ignoreJids" JSONB, "triggerType" "TriggerType", "triggerOperator" "TriggerOperator", "triggerValue" TEXT, "createdAt" TIMESTAMP DEFAULT CURRENT_TIMESTAMP, "updatedAt" TIMESTAMP NOT NULL, "instanceId" TEXT NOT NULL, CONSTRAINT "Dify_pkey" PRIMARY KEY ("id") ); -- CreateTable CREATE TABLE "DifySession" ( "id" TEXT NOT NULL, "sessionId" VARCHAR(255) NOT NULL, "remoteJid" VARCHAR(100) NOT NULL, "status" "TypebotSessionStatus" NOT NULL, "awaitUser" BOOLEAN NOT NULL DEFAULT false, "createdAt" TIMESTAMP DEFAULT CURRENT_TIMESTAMP, "updatedAt" TIMESTAMP NOT NULL, "difyId" TEXT NOT NULL, "instanceId" TEXT NOT NULL, CONSTRAINT "DifySession_pkey" PRIMARY KEY ("id") ); -- CreateTable CREATE TABLE "DifySetting" ( "id" TEXT NOT NULL, "expire" INTEGER DEFAULT 0, "keywordFinish" VARCHAR(100), "delayMessage" INTEGER, "unknownMessage" VARCHAR(100), "listeningFromMe" BOOLEAN DEFAULT false, "stopBotFromMe" BOOLEAN DEFAULT false, "keepOpen" BOOLEAN DEFAULT false, "debounceTime" INTEGER, "ignoreJids" JSONB, "createdAt" TIMESTAMP DEFAULT CURRENT_TIMESTAMP, "updatedAt" TIMESTAMP NOT NULL, "difyIdFallback" VARCHAR(100), "instanceId" TEXT NOT NULL, CONSTRAINT "DifySetting_pkey" PRIMARY KEY ("id") ); -- CreateIndex CREATE UNIQUE INDEX "DifySetting_instanceId_key" ON "DifySetting"("instanceId"); -- AddForeignKey ALTER TABLE "Message" ADD CONSTRAINT "Message_difySessionId_fkey" FOREIGN KEY ("difySessionId") REFERENCES "DifySession"("id") ON DELETE SET NULL ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "Dify" ADD CONSTRAINT "Dify_instanceId_fkey" FOREIGN KEY ("instanceId") REFERENCES "Instance"("id") ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "DifySession" ADD CONSTRAINT "DifySession_difyId_fkey" FOREIGN KEY ("difyId") REFERENCES "Dify"("id") ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "DifySession" ADD CONSTRAINT "DifySession_instanceId_fkey" FOREIGN KEY ("instanceId") REFERENCES "Instance"("id") ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "DifySetting" ADD CONSTRAINT "DifySetting_difyIdFallback_fkey" FOREIGN KEY ("difyIdFallback") REFERENCES "Dify"("id") ON DELETE SET NULL ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "DifySetting" ADD CONSTRAINT "DifySetting_instanceId_fkey" FOREIGN KEY ("instanceId") REFERENCES "Instance"("id") ON DELETE CASCADE ON UPDATE CASCADE; ================================================ FILE: prisma/postgresql-migrations/20240801193907_add_column_speech_to_text_openai_setting_table/migration.sql ================================================ -- AlterTable ALTER TABLE "OpenaiSetting" ADD COLUMN "speechToText" BOOLEAN DEFAULT false; ================================================ FILE: prisma/postgresql-migrations/20240803163908_add_column_description_on_integrations_table/migration.sql ================================================ -- AlterTable ALTER TABLE "Dify" ADD COLUMN "description" VARCHAR(255); -- AlterTable ALTER TABLE "OpenaiBot" ADD COLUMN "description" VARCHAR(255); -- AlterTable ALTER TABLE "Typebot" ADD COLUMN "description" VARCHAR(255); ================================================ FILE: prisma/postgresql-migrations/20240808210239_add_column_function_url_openaibot_table/migration.sql ================================================ -- AlterTable ALTER TABLE "Instance" ADD COLUMN "disconnectionAt" TIMESTAMP, ADD COLUMN "disconnectionObject" JSONB, ADD COLUMN "disconnectionReasonCode" INTEGER; -- AlterTable ALTER TABLE "OpenaiBot" ADD COLUMN "functionUrl" VARCHAR(500); ================================================ FILE: prisma/postgresql-migrations/20240811021156_add_chat_name_column/migration.sql ================================================ -- AlterTable ALTER TABLE "Chat" ADD COLUMN "name" VARCHAR(100); ================================================ FILE: prisma/postgresql-migrations/20240811183328_add_unique_index_for_remoted_jid_and_instance_in_contacts/migration.sql ================================================ /* Warnings: - A unique constraint covering the columns `[remoteJid,instanceId]` on the table `Contact` will be added. If there are existing duplicate values, this will fail. */ -- Remove the duplicates DELETE FROM "Contact" WHERE ctid NOT IN ( SELECT min(ctid) FROM "Contact" GROUP BY "remoteJid", "instanceId" ); -- CreateIndex CREATE UNIQUE INDEX "Contact_remoteJid_instanceId_key" ON "Contact"("remoteJid", "instanceId"); ================================================ FILE: prisma/postgresql-migrations/20240813003116_make_label_unique_for_instance/migration.sql ================================================ /* Warnings: - A unique constraint covering the columns `[labelId,instanceId]` on the table `Label` will be added. If there are existing duplicate values, this will fail. */ -- DropIndex DROP INDEX "Label_labelId_key"; -- CreateIndex CREATE UNIQUE INDEX "Label_labelId_instanceId_key" ON "Label"("labelId", "instanceId"); ================================================ FILE: prisma/postgresql-migrations/20240814173033_add_ignore_jids_chatwoot/migration.sql ================================================ -- AlterTable ALTER TABLE "Chatwoot" ADD COLUMN "ignoreJids" JSONB; ================================================ FILE: prisma/postgresql-migrations/20240814202359_integrations_unification/migration.sql ================================================ /* Warnings: - You are about to drop the column `difySessionId` on the `Message` table. All the data in the column will be lost. - You are about to drop the column `openaiSessionId` on the `Message` table. All the data in the column will be lost. - You are about to drop the column `typebotSessionId` on the `Message` table. All the data in the column will be lost. - You are about to drop the `DifySession` table. If the table is not empty, all the data it contains will be lost. - You are about to drop the `OpenaiSession` table. If the table is not empty, all the data it contains will be lost. - You are about to drop the `TypebotSession` table. If the table is not empty, all the data it contains will be lost. */ -- CreateEnum CREATE TYPE "SessionStatus" AS ENUM ('opened', 'closed', 'paused'); -- DropForeignKey ALTER TABLE "DifySession" DROP CONSTRAINT "DifySession_difyId_fkey"; -- DropForeignKey ALTER TABLE "DifySession" DROP CONSTRAINT "DifySession_instanceId_fkey"; -- DropForeignKey ALTER TABLE "Message" DROP CONSTRAINT "Message_difySessionId_fkey"; -- DropForeignKey ALTER TABLE "Message" DROP CONSTRAINT "Message_openaiSessionId_fkey"; -- DropForeignKey ALTER TABLE "Message" DROP CONSTRAINT "Message_typebotSessionId_fkey"; -- DropForeignKey ALTER TABLE "OpenaiSession" DROP CONSTRAINT "OpenaiSession_instanceId_fkey"; -- DropForeignKey ALTER TABLE "OpenaiSession" DROP CONSTRAINT "OpenaiSession_openaiBotId_fkey"; -- DropForeignKey ALTER TABLE "TypebotSession" DROP CONSTRAINT "TypebotSession_instanceId_fkey"; -- DropForeignKey ALTER TABLE "TypebotSession" DROP CONSTRAINT "TypebotSession_typebotId_fkey"; -- AlterTable ALTER TABLE "Message" DROP COLUMN "difySessionId", DROP COLUMN "openaiSessionId", DROP COLUMN "typebotSessionId", ADD COLUMN "sessionId" TEXT; -- DropTable DROP TABLE "DifySession"; -- DropTable DROP TABLE "OpenaiSession"; -- DropTable DROP TABLE "TypebotSession"; -- DropEnum DROP TYPE "TypebotSessionStatus"; -- CreateTable CREATE TABLE "IntegrationSession" ( "id" TEXT NOT NULL, "sessionId" VARCHAR(255) NOT NULL, "remoteJid" VARCHAR(100) NOT NULL, "pushName" TEXT, "status" "SessionStatus" NOT NULL, "awaitUser" BOOLEAN NOT NULL DEFAULT false, "createdAt" TIMESTAMP DEFAULT CURRENT_TIMESTAMP, "updatedAt" TIMESTAMP NOT NULL, "instanceId" TEXT NOT NULL, "parameters" JSONB, "openaiBotId" TEXT, "difyId" TEXT, "typebotId" TEXT, CONSTRAINT "IntegrationSession_pkey" PRIMARY KEY ("id") ); -- AddForeignKey ALTER TABLE "Message" ADD CONSTRAINT "Message_sessionId_fkey" FOREIGN KEY ("sessionId") REFERENCES "IntegrationSession"("id") ON DELETE SET NULL ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "IntegrationSession" ADD CONSTRAINT "IntegrationSession_instanceId_fkey" FOREIGN KEY ("instanceId") REFERENCES "Instance"("id") ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "IntegrationSession" ADD CONSTRAINT "IntegrationSession_openaiBotId_fkey" FOREIGN KEY ("openaiBotId") REFERENCES "OpenaiBot"("id") ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "IntegrationSession" ADD CONSTRAINT "IntegrationSession_difyId_fkey" FOREIGN KEY ("difyId") REFERENCES "Dify"("id") ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "IntegrationSession" ADD CONSTRAINT "IntegrationSession_typebotId_fkey" FOREIGN KEY ("typebotId") REFERENCES "Typebot"("id") ON DELETE CASCADE ON UPDATE CASCADE; ================================================ FILE: prisma/postgresql-migrations/20240817110155_add_trigger_type_advanced/migration.sql ================================================ -- AlterEnum ALTER TYPE "TriggerType" ADD VALUE 'advanced'; ================================================ FILE: prisma/postgresql-migrations/20240819154941_add_context_to_integration_session/migration.sql ================================================ -- AlterTable ALTER TABLE "IntegrationSession" ADD COLUMN "context" JSONB; ================================================ FILE: prisma/postgresql-migrations/20240821120816_bot_id_integration_session/migration.sql ================================================ /* Warnings: - You are about to drop the column `difyId` on the `IntegrationSession` table. All the data in the column will be lost. - You are about to drop the column `openaiBotId` on the `IntegrationSession` table. All the data in the column will be lost. - You are about to drop the column `typebotId` on the `IntegrationSession` table. All the data in the column will be lost. */ -- DropForeignKey ALTER TABLE "IntegrationSession" DROP CONSTRAINT "IntegrationSession_difyId_fkey"; -- DropForeignKey ALTER TABLE "IntegrationSession" DROP CONSTRAINT "IntegrationSession_openaiBotId_fkey"; -- DropForeignKey ALTER TABLE "IntegrationSession" DROP CONSTRAINT "IntegrationSession_typebotId_fkey"; -- AlterTable ALTER TABLE "IntegrationSession" DROP COLUMN "difyId", DROP COLUMN "openaiBotId", DROP COLUMN "typebotId", ADD COLUMN "botId" TEXT; ================================================ FILE: prisma/postgresql-migrations/20240821171327_add_generic_bot_table/migration.sql ================================================ -- CreateTable CREATE TABLE "GenericBot" ( "id" TEXT NOT NULL, "enabled" BOOLEAN NOT NULL DEFAULT true, "description" VARCHAR(255), "apiUrl" VARCHAR(255), "apiKey" VARCHAR(255), "expire" INTEGER DEFAULT 0, "keywordFinish" VARCHAR(100), "delayMessage" INTEGER, "unknownMessage" VARCHAR(100), "listeningFromMe" BOOLEAN DEFAULT false, "stopBotFromMe" BOOLEAN DEFAULT false, "keepOpen" BOOLEAN DEFAULT false, "debounceTime" INTEGER, "ignoreJids" JSONB, "triggerType" "TriggerType", "triggerOperator" "TriggerOperator", "triggerValue" TEXT, "createdAt" TIMESTAMP DEFAULT CURRENT_TIMESTAMP, "updatedAt" TIMESTAMP NOT NULL, "instanceId" TEXT NOT NULL, CONSTRAINT "GenericBot_pkey" PRIMARY KEY ("id") ); -- CreateTable CREATE TABLE "GenericSetting" ( "id" TEXT NOT NULL, "expire" INTEGER DEFAULT 0, "keywordFinish" VARCHAR(100), "delayMessage" INTEGER, "unknownMessage" VARCHAR(100), "listeningFromMe" BOOLEAN DEFAULT false, "stopBotFromMe" BOOLEAN DEFAULT false, "keepOpen" BOOLEAN DEFAULT false, "debounceTime" INTEGER, "ignoreJids" JSONB, "createdAt" TIMESTAMP DEFAULT CURRENT_TIMESTAMP, "updatedAt" TIMESTAMP NOT NULL, "botIdFallback" VARCHAR(100), "instanceId" TEXT NOT NULL, CONSTRAINT "GenericSetting_pkey" PRIMARY KEY ("id") ); -- CreateIndex CREATE UNIQUE INDEX "GenericSetting_instanceId_key" ON "GenericSetting"("instanceId"); -- AddForeignKey ALTER TABLE "GenericBot" ADD CONSTRAINT "GenericBot_instanceId_fkey" FOREIGN KEY ("instanceId") REFERENCES "Instance"("id") ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "GenericSetting" ADD CONSTRAINT "GenericSetting_botIdFallback_fkey" FOREIGN KEY ("botIdFallback") REFERENCES "GenericBot"("id") ON DELETE SET NULL ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "GenericSetting" ADD CONSTRAINT "GenericSetting_instanceId_fkey" FOREIGN KEY ("instanceId") REFERENCES "Instance"("id") ON DELETE CASCADE ON UPDATE CASCADE; ================================================ FILE: prisma/postgresql-migrations/20240821194524_add_flowise_table/migration.sql ================================================ -- CreateTable CREATE TABLE "Flowise" ( "id" TEXT NOT NULL, "enabled" BOOLEAN NOT NULL DEFAULT true, "description" VARCHAR(255), "apiUrl" VARCHAR(255), "apiKey" VARCHAR(255), "expire" INTEGER DEFAULT 0, "keywordFinish" VARCHAR(100), "delayMessage" INTEGER, "unknownMessage" VARCHAR(100), "listeningFromMe" BOOLEAN DEFAULT false, "stopBotFromMe" BOOLEAN DEFAULT false, "keepOpen" BOOLEAN DEFAULT false, "debounceTime" INTEGER, "ignoreJids" JSONB, "triggerType" "TriggerType", "triggerOperator" "TriggerOperator", "triggerValue" TEXT, "createdAt" TIMESTAMP DEFAULT CURRENT_TIMESTAMP, "updatedAt" TIMESTAMP NOT NULL, "instanceId" TEXT NOT NULL, CONSTRAINT "Flowise_pkey" PRIMARY KEY ("id") ); -- CreateTable CREATE TABLE "FlowiseSetting" ( "id" TEXT NOT NULL, "expire" INTEGER DEFAULT 0, "keywordFinish" VARCHAR(100), "delayMessage" INTEGER, "unknownMessage" VARCHAR(100), "listeningFromMe" BOOLEAN DEFAULT false, "stopBotFromMe" BOOLEAN DEFAULT false, "keepOpen" BOOLEAN DEFAULT false, "debounceTime" INTEGER, "ignoreJids" JSONB, "createdAt" TIMESTAMP DEFAULT CURRENT_TIMESTAMP, "updatedAt" TIMESTAMP NOT NULL, "flowiseIdFallback" VARCHAR(100), "instanceId" TEXT NOT NULL, CONSTRAINT "FlowiseSetting_pkey" PRIMARY KEY ("id") ); -- CreateIndex CREATE UNIQUE INDEX "FlowiseSetting_instanceId_key" ON "FlowiseSetting"("instanceId"); -- AddForeignKey ALTER TABLE "Flowise" ADD CONSTRAINT "Flowise_instanceId_fkey" FOREIGN KEY ("instanceId") REFERENCES "Instance"("id") ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "FlowiseSetting" ADD CONSTRAINT "FlowiseSetting_flowiseIdFallback_fkey" FOREIGN KEY ("flowiseIdFallback") REFERENCES "Flowise"("id") ON DELETE SET NULL ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "FlowiseSetting" ADD CONSTRAINT "FlowiseSetting_instanceId_fkey" FOREIGN KEY ("instanceId") REFERENCES "Instance"("id") ON DELETE CASCADE ON UPDATE CASCADE; ================================================ FILE: prisma/postgresql-migrations/20240824161333_add_type_on_integration_sessions/migration.sql ================================================ -- AlterTable ALTER TABLE "IntegrationSession" ADD COLUMN "type" VARCHAR(100); ================================================ FILE: prisma/postgresql-migrations/20240825130616_change_to_evolution_bot/migration.sql ================================================ /* Warnings: - You are about to drop the `GenericBot` table. If the table is not empty, all the data it contains will be lost. - You are about to drop the `GenericSetting` table. If the table is not empty, all the data it contains will be lost. */ -- DropForeignKey ALTER TABLE "GenericBot" DROP CONSTRAINT "GenericBot_instanceId_fkey"; -- DropForeignKey ALTER TABLE "GenericSetting" DROP CONSTRAINT "GenericSetting_botIdFallback_fkey"; -- DropForeignKey ALTER TABLE "GenericSetting" DROP CONSTRAINT "GenericSetting_instanceId_fkey"; -- DropTable DROP TABLE "GenericBot"; -- DropTable DROP TABLE "GenericSetting"; -- CreateTable CREATE TABLE "EvolutionBot" ( "id" TEXT NOT NULL, "enabled" BOOLEAN NOT NULL DEFAULT true, "description" VARCHAR(255), "apiUrl" VARCHAR(255), "apiKey" VARCHAR(255), "expire" INTEGER DEFAULT 0, "keywordFinish" VARCHAR(100), "delayMessage" INTEGER, "unknownMessage" VARCHAR(100), "listeningFromMe" BOOLEAN DEFAULT false, "stopBotFromMe" BOOLEAN DEFAULT false, "keepOpen" BOOLEAN DEFAULT false, "debounceTime" INTEGER, "ignoreJids" JSONB, "triggerType" "TriggerType", "triggerOperator" "TriggerOperator", "triggerValue" TEXT, "createdAt" TIMESTAMP DEFAULT CURRENT_TIMESTAMP, "updatedAt" TIMESTAMP NOT NULL, "instanceId" TEXT NOT NULL, CONSTRAINT "EvolutionBot_pkey" PRIMARY KEY ("id") ); -- CreateTable CREATE TABLE "EvolutionBotSetting" ( "id" TEXT NOT NULL, "expire" INTEGER DEFAULT 0, "keywordFinish" VARCHAR(100), "delayMessage" INTEGER, "unknownMessage" VARCHAR(100), "listeningFromMe" BOOLEAN DEFAULT false, "stopBotFromMe" BOOLEAN DEFAULT false, "keepOpen" BOOLEAN DEFAULT false, "debounceTime" INTEGER, "ignoreJids" JSONB, "createdAt" TIMESTAMP DEFAULT CURRENT_TIMESTAMP, "updatedAt" TIMESTAMP NOT NULL, "botIdFallback" VARCHAR(100), "instanceId" TEXT NOT NULL, CONSTRAINT "EvolutionBotSetting_pkey" PRIMARY KEY ("id") ); -- CreateIndex CREATE UNIQUE INDEX "EvolutionBotSetting_instanceId_key" ON "EvolutionBotSetting"("instanceId"); -- AddForeignKey ALTER TABLE "EvolutionBot" ADD CONSTRAINT "EvolutionBot_instanceId_fkey" FOREIGN KEY ("instanceId") REFERENCES "Instance"("id") ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "EvolutionBotSetting" ADD CONSTRAINT "EvolutionBotSetting_botIdFallback_fkey" FOREIGN KEY ("botIdFallback") REFERENCES "EvolutionBot"("id") ON DELETE SET NULL ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "EvolutionBotSetting" ADD CONSTRAINT "EvolutionBotSetting_instanceId_fkey" FOREIGN KEY ("instanceId") REFERENCES "Instance"("id") ON DELETE CASCADE ON UPDATE CASCADE; ================================================ FILE: prisma/postgresql-migrations/20240828140837_add_is_on_whatsapp_table/migration.sql ================================================ -- CreateTable CREATE TABLE "is_on_whatsapp" ( "id" TEXT NOT NULL, "remote_jid" VARCHAR(100) NOT NULL, "name" TEXT, "jid_options" TEXT NOT NULL, "created_at" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, "updated_at" TIMESTAMP NOT NULL, CONSTRAINT "is_on_whatsapp_pkey" PRIMARY KEY ("id") ); -- CreateIndex CREATE UNIQUE INDEX "is_on_whatsapp_remote_jid_key" ON "is_on_whatsapp"("remote_jid"); ================================================ FILE: prisma/postgresql-migrations/20240828141556_remove_name_column_from_on_whatsapp_table/migration.sql ================================================ /* Warnings: - You are about to drop the column `name` on the `is_on_whatsapp` table. All the data in the column will be lost. */ -- AlterTable ALTER TABLE "is_on_whatsapp" DROP COLUMN "name"; ================================================ FILE: prisma/postgresql-migrations/20240830193533_changed_table_case/migration.sql ================================================ /* Warnings: - You are about to drop the `is_on_whatsapp` table. If the table is not empty, all the data it contains will be lost. */ -- DropTable DROP TABLE "is_on_whatsapp"; -- CreateTable CREATE TABLE "IsOnWhatsapp" ( "id" TEXT NOT NULL, "remoteJid" VARCHAR(100) NOT NULL, "jidOptions" TEXT NOT NULL, "createdAt" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, "updatedAt" TIMESTAMP NOT NULL, CONSTRAINT "IsOnWhatsapp_pkey" PRIMARY KEY ("id") ); -- CreateIndex CREATE UNIQUE INDEX "IsOnWhatsapp_remoteJid_key" ON "IsOnWhatsapp"("remoteJid"); ================================================ FILE: prisma/postgresql-migrations/20240906202019_add_headers_on_webhook_config/migration.sql ================================================ -- AlterTable ALTER TABLE "Webhook" ADD COLUMN "headers" JSONB; ================================================ FILE: prisma/postgresql-migrations/20241001180457_add_message_status/migration.sql ================================================ -- AlterTable ALTER TABLE "Message" ADD COLUMN "status" INTEGER; ================================================ FILE: prisma/postgresql-migrations/20241006130306_alter_status_on_message_table/migration.sql ================================================ -- AlterTable ALTER TABLE "Message" ALTER COLUMN "status" SET DATA TYPE VARCHAR(30); UPDATE "Message" SET "status" = 'PENDING'; ================================================ FILE: prisma/postgresql-migrations/20241007164026_add_unread_messages_on_chat_table/migration.sql ================================================ -- AlterTable ALTER TABLE "Chat" ADD COLUMN "unreadMessages" INTEGER NOT NULL DEFAULT 0; ================================================ FILE: prisma/postgresql-migrations/20241011085129_create_pusher_table/migration.sql ================================================ -- CreateTable CREATE TABLE "Pusher" ( "id" TEXT NOT NULL, "enabled" BOOLEAN NOT NULL DEFAULT false, "appId" VARCHAR(100) NOT NULL, "key" VARCHAR(100) NOT NULL, "secret" VARCHAR(100) NOT NULL, "cluster" VARCHAR(100) NOT NULL, "useTLS" BOOLEAN NOT NULL DEFAULT false, "events" JSONB NOT NULL, "createdAt" TIMESTAMP DEFAULT CURRENT_TIMESTAMP, "updatedAt" TIMESTAMP NOT NULL, "instanceId" TEXT NOT NULL, CONSTRAINT "Pusher_pkey" PRIMARY KEY ("id") ); -- CreateIndex CREATE UNIQUE INDEX "Pusher_instanceId_key" ON "Pusher"("instanceId"); -- AddForeignKey ALTER TABLE "Pusher" ADD CONSTRAINT "Pusher_instanceId_fkey" FOREIGN KEY ("instanceId") REFERENCES "Instance"("id") ON DELETE CASCADE ON UPDATE CASCADE; ================================================ FILE: prisma/postgresql-migrations/20241011100803_split_messages_and_time_per_char_integrations/migration.sql ================================================ -- AlterTable ALTER TABLE "Dify" ADD COLUMN "splitMessages" BOOLEAN DEFAULT false, ADD COLUMN "timePerChar" INTEGER DEFAULT 50; -- AlterTable ALTER TABLE "DifySetting" ADD COLUMN "splitMessages" BOOLEAN DEFAULT false, ADD COLUMN "timePerChar" INTEGER DEFAULT 50; -- AlterTable ALTER TABLE "EvolutionBot" ADD COLUMN "splitMessages" BOOLEAN DEFAULT false, ADD COLUMN "timePerChar" INTEGER DEFAULT 50; -- AlterTable ALTER TABLE "EvolutionBotSetting" ADD COLUMN "splitMessages" BOOLEAN DEFAULT false, ADD COLUMN "timePerChar" INTEGER DEFAULT 50; -- AlterTable ALTER TABLE "Flowise" ADD COLUMN "splitMessages" BOOLEAN DEFAULT false, ADD COLUMN "timePerChar" INTEGER DEFAULT 50; -- AlterTable ALTER TABLE "FlowiseSetting" ADD COLUMN "splitMessages" BOOLEAN DEFAULT false, ADD COLUMN "timePerChar" INTEGER DEFAULT 50; -- AlterTable ALTER TABLE "OpenaiBot" ADD COLUMN "splitMessages" BOOLEAN DEFAULT false, ADD COLUMN "timePerChar" INTEGER DEFAULT 50; -- AlterTable ALTER TABLE "OpenaiSetting" ADD COLUMN "splitMessages" BOOLEAN DEFAULT false, ADD COLUMN "timePerChar" INTEGER DEFAULT 50; ================================================ FILE: prisma/postgresql-migrations/20241017144950_create_index/migration.sql ================================================ -- CreateIndex CREATE INDEX "Chat_instanceId_idx" ON "Chat"("instanceId"); -- CreateIndex CREATE INDEX "Chat_remoteJid_idx" ON "Chat"("remoteJid"); -- CreateIndex CREATE INDEX "Contact_remoteJid_idx" ON "Contact"("remoteJid"); -- CreateIndex CREATE INDEX "Contact_instanceId_idx" ON "Contact"("instanceId"); -- CreateIndex CREATE INDEX "Message_instanceId_idx" ON "Message"("instanceId"); -- CreateIndex CREATE INDEX "MessageUpdate_instanceId_idx" ON "MessageUpdate"("instanceId"); -- CreateIndex CREATE INDEX "MessageUpdate_messageId_idx" ON "MessageUpdate"("messageId"); -- CreateIndex CREATE INDEX "Setting_instanceId_idx" ON "Setting"("instanceId"); -- CreateIndex CREATE INDEX "Webhook_instanceId_idx" ON "Webhook"("instanceId"); ================================================ FILE: prisma/postgresql-migrations/20250116001415_add_wavoip_token_to_settings_table/migration.sql ================================================ /* Warnings: - A unique constraint covering the columns `[remoteJid,instanceId]` on the table `Chat` will be added. If there are existing duplicate values, this will fail. */ -- AlterTable ALTER TABLE "Setting" ADD COLUMN IF NOT EXISTS "wavoipToken" VARCHAR(100); ================================================ FILE: prisma/postgresql-migrations/20250225180031_add_nats_integration/migration.sql ================================================ -- CreateTable CREATE TABLE "Nats" ( "id" TEXT NOT NULL, "enabled" BOOLEAN NOT NULL DEFAULT false, "events" JSONB NOT NULL, "createdAt" TIMESTAMP DEFAULT CURRENT_TIMESTAMP, "updatedAt" TIMESTAMP NOT NULL, "instanceId" TEXT NOT NULL, CONSTRAINT "Nats_pkey" PRIMARY KEY ("id") ); -- CreateIndex CREATE UNIQUE INDEX "Nats_instanceId_key" ON "Nats"("instanceId"); -- AddForeignKey ALTER TABLE "Nats" ADD CONSTRAINT "Nats_instanceId_fkey" FOREIGN KEY ("instanceId") REFERENCES "Instance"("id") ON DELETE CASCADE ON UPDATE CASCADE; ================================================ FILE: prisma/postgresql-migrations/20250514232744_add_n8n_table/migration.sql ================================================ -- CreateTable CREATE TABLE "N8n" ( "id" TEXT NOT NULL, "enabled" BOOLEAN NOT NULL DEFAULT true, "description" VARCHAR(255), "webhookUrl" VARCHAR(255), "basicAuthUser" VARCHAR(255), "basicAuthPass" VARCHAR(255), "expire" INTEGER DEFAULT 0, "keywordFinish" VARCHAR(100), "delayMessage" INTEGER, "unknownMessage" VARCHAR(100), "listeningFromMe" BOOLEAN DEFAULT false, "stopBotFromMe" BOOLEAN DEFAULT false, "keepOpen" BOOLEAN DEFAULT false, "debounceTime" INTEGER, "ignoreJids" JSONB, "splitMessages" BOOLEAN DEFAULT false, "timePerChar" INTEGER DEFAULT 50, "triggerType" "TriggerType", "triggerOperator" "TriggerOperator", "triggerValue" TEXT, "createdAt" TIMESTAMP DEFAULT CURRENT_TIMESTAMP, "updatedAt" TIMESTAMP NOT NULL, "instanceId" TEXT NOT NULL, CONSTRAINT "N8n_pkey" PRIMARY KEY ("id") ); -- CreateTable CREATE TABLE "N8nSetting" ( "id" TEXT NOT NULL, "expire" INTEGER DEFAULT 0, "keywordFinish" VARCHAR(100), "delayMessage" INTEGER, "unknownMessage" VARCHAR(100), "listeningFromMe" BOOLEAN DEFAULT false, "stopBotFromMe" BOOLEAN DEFAULT false, "keepOpen" BOOLEAN DEFAULT false, "debounceTime" INTEGER, "ignoreJids" JSONB, "splitMessages" BOOLEAN DEFAULT false, "timePerChar" INTEGER DEFAULT 50, "createdAt" TIMESTAMP DEFAULT CURRENT_TIMESTAMP, "updatedAt" TIMESTAMP NOT NULL, "n8nIdFallback" VARCHAR(100), "instanceId" TEXT NOT NULL, CONSTRAINT "N8nSetting_pkey" PRIMARY KEY ("id") ); -- CreateIndex CREATE UNIQUE INDEX "N8nSetting_instanceId_key" ON "N8nSetting"("instanceId"); -- AddForeignKey ALTER TABLE "N8n" ADD CONSTRAINT "N8n_instanceId_fkey" FOREIGN KEY ("instanceId") REFERENCES "Instance"("id") ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "N8nSetting" ADD CONSTRAINT "N8nSetting_n8nIdFallback_fkey" FOREIGN KEY ("n8nIdFallback") REFERENCES "N8n"("id") ON DELETE SET NULL ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "N8nSetting" ADD CONSTRAINT "N8nSetting_instanceId_fkey" FOREIGN KEY ("instanceId") REFERENCES "Instance"("id") ON DELETE CASCADE ON UPDATE CASCADE; ================================================ FILE: prisma/postgresql-migrations/20250515211815_add_evoai_table/migration.sql ================================================ -- CreateTable CREATE TABLE "Evoai" ( "id" TEXT NOT NULL, "enabled" BOOLEAN NOT NULL DEFAULT true, "description" VARCHAR(255), "agentUrl" VARCHAR(255), "apiKey" VARCHAR(255), "expire" INTEGER DEFAULT 0, "keywordFinish" VARCHAR(100), "delayMessage" INTEGER, "unknownMessage" VARCHAR(100), "listeningFromMe" BOOLEAN DEFAULT false, "stopBotFromMe" BOOLEAN DEFAULT false, "keepOpen" BOOLEAN DEFAULT false, "debounceTime" INTEGER, "ignoreJids" JSONB, "splitMessages" BOOLEAN DEFAULT false, "timePerChar" INTEGER DEFAULT 50, "triggerType" "TriggerType", "triggerOperator" "TriggerOperator", "triggerValue" TEXT, "createdAt" TIMESTAMP DEFAULT CURRENT_TIMESTAMP, "updatedAt" TIMESTAMP NOT NULL, "instanceId" TEXT NOT NULL, CONSTRAINT "Evoai_pkey" PRIMARY KEY ("id") ); -- CreateTable CREATE TABLE "EvoaiSetting" ( "id" TEXT NOT NULL, "expire" INTEGER DEFAULT 0, "keywordFinish" VARCHAR(100), "delayMessage" INTEGER, "unknownMessage" VARCHAR(100), "listeningFromMe" BOOLEAN DEFAULT false, "stopBotFromMe" BOOLEAN DEFAULT false, "keepOpen" BOOLEAN DEFAULT false, "debounceTime" INTEGER, "ignoreJids" JSONB, "splitMessages" BOOLEAN DEFAULT false, "timePerChar" INTEGER DEFAULT 50, "createdAt" TIMESTAMP DEFAULT CURRENT_TIMESTAMP, "updatedAt" TIMESTAMP NOT NULL, "evoaiIdFallback" VARCHAR(100), "instanceId" TEXT NOT NULL, CONSTRAINT "EvoaiSetting_pkey" PRIMARY KEY ("id") ); -- CreateIndex CREATE UNIQUE INDEX "EvoaiSetting_instanceId_key" ON "EvoaiSetting"("instanceId"); -- AddForeignKey ALTER TABLE "Evoai" ADD CONSTRAINT "Evoai_instanceId_fkey" FOREIGN KEY ("instanceId") REFERENCES "Instance"("id") ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "EvoaiSetting" ADD CONSTRAINT "EvoaiSetting_evoaiIdFallback_fkey" FOREIGN KEY ("evoaiIdFallback") REFERENCES "Evoai"("id") ON DELETE SET NULL ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "EvoaiSetting" ADD CONSTRAINT "EvoaiSetting_instanceId_fkey" FOREIGN KEY ("instanceId") REFERENCES "Instance"("id") ON DELETE CASCADE ON UPDATE CASCADE; ================================================ FILE: prisma/postgresql-migrations/20250516012152_remove_unique_atribute_for_file_name_in_media/migration.sql ================================================ -- DropIndex DROP INDEX "Media_fileName_key"; ================================================ FILE: prisma/postgresql-migrations/20250612155048_add_coluns_trypebot_tables/migration.sql ================================================ -- AlterTable ALTER TABLE "Typebot" ADD COLUMN "splitMessages" BOOLEAN DEFAULT false, ADD COLUMN "timePerChar" INTEGER DEFAULT 50; -- AlterTable ALTER TABLE "TypebotSetting" ADD COLUMN "splitMessages" BOOLEAN DEFAULT false, ADD COLUMN "timePerChar" INTEGER DEFAULT 50; ================================================ FILE: prisma/postgresql-migrations/20250613143000_add_lid_column_to_is_onwhatsapp/migration.sql ================================================ -- AlterTable ALTER TABLE "IsOnWhatsapp" ADD COLUMN "lid" VARCHAR(100); ================================================ FILE: prisma/postgresql-migrations/20250918182355_add_kafka_integration/migration.sql ================================================ -- CreateTable CREATE TABLE "Kafka" ( "id" TEXT NOT NULL, "enabled" BOOLEAN NOT NULL DEFAULT false, "events" JSONB NOT NULL, "createdAt" TIMESTAMP DEFAULT CURRENT_TIMESTAMP, "updatedAt" TIMESTAMP NOT NULL, "instanceId" TEXT NOT NULL, CONSTRAINT "Kafka_pkey" PRIMARY KEY ("id") ); -- CreateIndex CREATE UNIQUE INDEX "Kafka_instanceId_key" ON "Kafka"("instanceId"); -- AddForeignKey ALTER TABLE "Kafka" ADD CONSTRAINT "Kafka_instanceId_fkey" FOREIGN KEY ("instanceId") REFERENCES "Instance"("id") ON DELETE CASCADE ON UPDATE CASCADE; ================================================ FILE: prisma/postgresql-migrations/20251122003044_add_chat_instance_remotejid_unique/migration.sql ================================================ -- 1. Cleanup: Remove duplicate chats, keeping the most recently updated one DELETE FROM "Chat" WHERE id IN ( SELECT id FROM ( SELECT id, ROW_NUMBER() OVER ( PARTITION BY "instanceId", "remoteJid" ORDER BY "updatedAt" DESC ) as row_num FROM "Chat" ) t WHERE t.row_num > 1 ); -- 2. Create the unique index (Constraint) CREATE UNIQUE INDEX "Chat_instanceId_remoteJid_key" ON "Chat"("instanceId", "remoteJid"); ================================================ FILE: prisma/postgresql-migrations/migration_lock.toml ================================================ # Please do not edit this file manually # It should be added in your version-control system (e.g., Git) provider = "postgresql" ================================================ FILE: prisma/postgresql-schema.prisma ================================================ // This is your Prisma schema file, // learn more about it in the docs: https://pris.ly/d/prisma-schema // Looking for ways to speed up your queries, or scale easily with your serverless or edge functions? // Try Prisma Accelerate: https://pris.ly/cli/accelerate-init generator client { provider = "prisma-client-js" } datasource db { provider = "postgresql" url = env("DATABASE_CONNECTION_URI") } enum InstanceConnectionStatus { open close connecting } enum DeviceMessage { ios android web unknown desktop } enum SessionStatus { opened closed paused } enum TriggerType { all keyword none advanced } enum TriggerOperator { contains equals startsWith endsWith regex } enum OpenaiBotType { assistant chatCompletion } enum DifyBotType { chatBot textGenerator agent workflow } model Instance { id String @id @default(cuid()) name String @unique @db.VarChar(255) connectionStatus InstanceConnectionStatus @default(open) ownerJid String? @db.VarChar(100) profileName String? @db.VarChar(100) profilePicUrl String? @db.VarChar(500) integration String? @db.VarChar(100) number String? @db.VarChar(100) businessId String? @db.VarChar(100) token String? @db.VarChar(255) clientName String? @db.VarChar(100) disconnectionReasonCode Int? @db.Integer disconnectionObject Json? @db.JsonB disconnectionAt DateTime? @db.Timestamp createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime? @updatedAt @db.Timestamp Chat Chat[] Contact Contact[] Message Message[] Webhook Webhook? Chatwoot Chatwoot? Label Label[] Proxy Proxy? Setting Setting? Rabbitmq Rabbitmq? Nats Nats? Sqs Sqs? Kafka Kafka? Websocket Websocket? Typebot Typebot[] Session Session? MessageUpdate MessageUpdate[] TypebotSetting TypebotSetting? Media Media[] OpenaiCreds OpenaiCreds[] OpenaiBot OpenaiBot[] OpenaiSetting OpenaiSetting? Template Template[] Dify Dify[] DifySetting DifySetting? IntegrationSession IntegrationSession[] EvolutionBot EvolutionBot[] EvolutionBotSetting EvolutionBotSetting? Flowise Flowise[] FlowiseSetting FlowiseSetting? Pusher Pusher? N8n N8n[] N8nSetting N8nSetting[] Evoai Evoai[] EvoaiSetting EvoaiSetting? } model Session { id String @id @default(cuid()) sessionId String @unique creds String? @db.Text createdAt DateTime @default(now()) @db.Timestamp Instance Instance @relation(fields: [sessionId], references: [id], onDelete: Cascade) } model Chat { id String @id @default(cuid()) remoteJid String @db.VarChar(100) name String? @db.VarChar(100) labels Json? @db.JsonB createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime? @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String unreadMessages Int @default(0) @@unique([instanceId, remoteJid]) @@index([instanceId]) @@index([remoteJid]) } model Contact { id String @id @default(cuid()) remoteJid String @db.VarChar(100) pushName String? @db.VarChar(100) profilePicUrl String? @db.VarChar(500) createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime? @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @@unique([remoteJid, instanceId]) @@index([remoteJid]) @@index([instanceId]) } model Message { id String @id @default(cuid()) key Json @db.JsonB pushName String? @db.VarChar(100) participant String? @db.VarChar(100) messageType String @db.VarChar(100) message Json @db.JsonB contextInfo Json? @db.JsonB source DeviceMessage messageTimestamp Int @db.Integer chatwootMessageId Int? @db.Integer chatwootInboxId Int? @db.Integer chatwootConversationId Int? @db.Integer chatwootContactInboxSourceId String? @db.VarChar(100) chatwootIsRead Boolean? @db.Boolean Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String MessageUpdate MessageUpdate[] Media Media? webhookUrl String? @db.VarChar(500) status String? @db.VarChar(30) sessionId String? session IntegrationSession? @relation(fields: [sessionId], references: [id]) @@index([instanceId]) } model MessageUpdate { id String @id @default(cuid()) keyId String @db.VarChar(100) remoteJid String @db.VarChar(100) fromMe Boolean @db.Boolean participant String? @db.VarChar(100) pollUpdates Json? @db.JsonB status String @db.VarChar(30) Message Message @relation(fields: [messageId], references: [id], onDelete: Cascade) messageId String Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @@index([instanceId]) @@index([messageId]) } model Webhook { id String @id @default(cuid()) url String @db.VarChar(500) headers Json? @db.JsonB enabled Boolean? @default(true) @db.Boolean events Json? @db.JsonB webhookByEvents Boolean? @default(false) @db.Boolean webhookBase64 Boolean? @default(false) @db.Boolean createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique @@index([instanceId]) } model Chatwoot { id String @id @default(cuid()) enabled Boolean? @default(true) @db.Boolean accountId String? @db.VarChar(100) token String? @db.VarChar(100) url String? @db.VarChar(500) nameInbox String? @db.VarChar(100) signMsg Boolean? @default(false) @db.Boolean signDelimiter String? @db.VarChar(100) number String? @db.VarChar(100) reopenConversation Boolean? @default(false) @db.Boolean conversationPending Boolean? @default(false) @db.Boolean mergeBrazilContacts Boolean? @default(false) @db.Boolean importContacts Boolean? @default(false) @db.Boolean importMessages Boolean? @default(false) @db.Boolean daysLimitImportMessages Int? @db.Integer organization String? @db.VarChar(100) logo String? @db.VarChar(500) ignoreJids Json? createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique } model Label { id String @id @default(cuid()) labelId String? @db.VarChar(100) name String @db.VarChar(100) color String @db.VarChar(100) predefinedId String? @db.VarChar(100) createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @@unique([labelId, instanceId]) } model Proxy { id String @id @default(cuid()) enabled Boolean @default(false) @db.Boolean host String @db.VarChar(100) port String @db.VarChar(100) protocol String @db.VarChar(100) username String @db.VarChar(100) password String @db.VarChar(100) createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique } model Setting { id String @id @default(cuid()) rejectCall Boolean @default(false) @db.Boolean msgCall String? @db.VarChar(100) groupsIgnore Boolean @default(false) @db.Boolean alwaysOnline Boolean @default(false) @db.Boolean readMessages Boolean @default(false) @db.Boolean readStatus Boolean @default(false) @db.Boolean syncFullHistory Boolean @default(false) @db.Boolean wavoipToken String? @db.VarChar(100) createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique @@index([instanceId]) } model Rabbitmq { id String @id @default(cuid()) enabled Boolean @default(false) @db.Boolean events Json @db.JsonB createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique } model Nats { id String @id @default(cuid()) enabled Boolean @default(false) @db.Boolean events Json @db.JsonB createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique } model Sqs { id String @id @default(cuid()) enabled Boolean @default(false) @db.Boolean events Json @db.JsonB createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique } model Kafka { id String @id @default(cuid()) enabled Boolean @default(false) @db.Boolean events Json @db.JsonB createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique } model Websocket { id String @id @default(cuid()) enabled Boolean @default(false) @db.Boolean events Json @db.JsonB createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique } model Pusher { id String @id @default(cuid()) enabled Boolean @default(false) @db.Boolean appId String @db.VarChar(100) key String @db.VarChar(100) secret String @db.VarChar(100) cluster String @db.VarChar(100) useTLS Boolean @default(false) @db.Boolean events Json @db.JsonB createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique } model Typebot { id String @id @default(cuid()) enabled Boolean @default(true) @db.Boolean description String? @db.VarChar(255) url String @db.VarChar(500) typebot String @db.VarChar(100) expire Int? @default(0) @db.Integer keywordFinish String? @db.VarChar(100) delayMessage Int? @db.Integer unknownMessage String? @db.VarChar(100) listeningFromMe Boolean? @default(false) @db.Boolean stopBotFromMe Boolean? @default(false) @db.Boolean keepOpen Boolean? @default(false) @db.Boolean debounceTime Int? @db.Integer createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime? @updatedAt @db.Timestamp ignoreJids Json? triggerType TriggerType? triggerOperator TriggerOperator? triggerValue String? splitMessages Boolean? @default(false) @db.Boolean timePerChar Int? @default(50) @db.Integer Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String TypebotSetting TypebotSetting[] } model TypebotSetting { id String @id @default(cuid()) expire Int? @default(0) @db.Integer keywordFinish String? @db.VarChar(100) delayMessage Int? @db.Integer unknownMessage String? @db.VarChar(100) listeningFromMe Boolean? @default(false) @db.Boolean stopBotFromMe Boolean? @default(false) @db.Boolean keepOpen Boolean? @default(false) @db.Boolean debounceTime Int? @db.Integer typebotIdFallback String? @db.VarChar(100) ignoreJids Json? splitMessages Boolean? @default(false) @db.Boolean timePerChar Int? @default(50) @db.Integer createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Fallback Typebot? @relation(fields: [typebotIdFallback], references: [id]) Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique } model Media { id String @id @default(cuid()) fileName String @db.VarChar(500) type String @db.VarChar(100) mimetype String @db.VarChar(100) createdAt DateTime? @default(now()) @db.Date Message Message @relation(fields: [messageId], references: [id], onDelete: Cascade) messageId String @unique Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String } model OpenaiCreds { id String @id @default(cuid()) name String? @unique @db.VarChar(255) apiKey String? @unique @db.VarChar(255) createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String OpenaiAssistant OpenaiBot[] OpenaiSetting OpenaiSetting? } model OpenaiBot { id String @id @default(cuid()) enabled Boolean @default(true) @db.Boolean description String? @db.VarChar(255) botType OpenaiBotType assistantId String? @db.VarChar(255) functionUrl String? @db.VarChar(500) model String? @db.VarChar(100) systemMessages Json? @db.JsonB assistantMessages Json? @db.JsonB userMessages Json? @db.JsonB maxTokens Int? @db.Integer expire Int? @default(0) @db.Integer keywordFinish String? @db.VarChar(100) delayMessage Int? @db.Integer unknownMessage String? @db.VarChar(100) listeningFromMe Boolean? @default(false) @db.Boolean stopBotFromMe Boolean? @default(false) @db.Boolean keepOpen Boolean? @default(false) @db.Boolean debounceTime Int? @db.Integer splitMessages Boolean? @default(false) @db.Boolean timePerChar Int? @default(50) @db.Integer ignoreJids Json? triggerType TriggerType? triggerOperator TriggerOperator? triggerValue String? createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp OpenaiCreds OpenaiCreds @relation(fields: [openaiCredsId], references: [id], onDelete: Cascade) openaiCredsId String Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String OpenaiSetting OpenaiSetting[] } model IntegrationSession { id String @id @default(cuid()) sessionId String @db.VarChar(255) remoteJid String @db.VarChar(100) pushName String? status SessionStatus awaitUser Boolean @default(false) @db.Boolean context Json? type String? @db.VarChar(100) createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Message Message[] Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String parameters Json? @db.JsonB botId String? } model OpenaiSetting { id String @id @default(cuid()) expire Int? @default(0) @db.Integer keywordFinish String? @db.VarChar(100) delayMessage Int? @db.Integer unknownMessage String? @db.VarChar(100) listeningFromMe Boolean? @default(false) @db.Boolean stopBotFromMe Boolean? @default(false) @db.Boolean keepOpen Boolean? @default(false) @db.Boolean debounceTime Int? @db.Integer ignoreJids Json? splitMessages Boolean? @default(false) @db.Boolean timePerChar Int? @default(50) @db.Integer speechToText Boolean? @default(false) @db.Boolean createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp OpenaiCreds OpenaiCreds? @relation(fields: [openaiCredsId], references: [id]) openaiCredsId String @unique Fallback OpenaiBot? @relation(fields: [openaiIdFallback], references: [id]) openaiIdFallback String? @db.VarChar(100) Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique } model Template { id String @id @default(cuid()) templateId String @unique @db.VarChar(255) name String @unique @db.VarChar(255) template Json @db.JsonB webhookUrl String? @db.VarChar(500) createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String } model Dify { id String @id @default(cuid()) enabled Boolean @default(true) @db.Boolean description String? @db.VarChar(255) botType DifyBotType apiUrl String? @db.VarChar(255) apiKey String? @db.VarChar(255) expire Int? @default(0) @db.Integer keywordFinish String? @db.VarChar(100) delayMessage Int? @db.Integer unknownMessage String? @db.VarChar(100) listeningFromMe Boolean? @default(false) @db.Boolean stopBotFromMe Boolean? @default(false) @db.Boolean keepOpen Boolean? @default(false) @db.Boolean debounceTime Int? @db.Integer ignoreJids Json? splitMessages Boolean? @default(false) @db.Boolean timePerChar Int? @default(50) @db.Integer triggerType TriggerType? triggerOperator TriggerOperator? triggerValue String? createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String DifySetting DifySetting[] } model DifySetting { id String @id @default(cuid()) expire Int? @default(0) @db.Integer keywordFinish String? @db.VarChar(100) delayMessage Int? @db.Integer unknownMessage String? @db.VarChar(100) listeningFromMe Boolean? @default(false) @db.Boolean stopBotFromMe Boolean? @default(false) @db.Boolean keepOpen Boolean? @default(false) @db.Boolean debounceTime Int? @db.Integer ignoreJids Json? splitMessages Boolean? @default(false) @db.Boolean timePerChar Int? @default(50) @db.Integer createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Fallback Dify? @relation(fields: [difyIdFallback], references: [id]) difyIdFallback String? @db.VarChar(100) Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique } model EvolutionBot { id String @id @default(cuid()) enabled Boolean @default(true) @db.Boolean description String? @db.VarChar(255) apiUrl String? @db.VarChar(255) apiKey String? @db.VarChar(255) expire Int? @default(0) @db.Integer keywordFinish String? @db.VarChar(100) delayMessage Int? @db.Integer unknownMessage String? @db.VarChar(100) listeningFromMe Boolean? @default(false) @db.Boolean stopBotFromMe Boolean? @default(false) @db.Boolean keepOpen Boolean? @default(false) @db.Boolean debounceTime Int? @db.Integer ignoreJids Json? splitMessages Boolean? @default(false) @db.Boolean timePerChar Int? @default(50) @db.Integer triggerType TriggerType? triggerOperator TriggerOperator? triggerValue String? createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String EvolutionBotSetting EvolutionBotSetting[] } model EvolutionBotSetting { id String @id @default(cuid()) expire Int? @default(0) @db.Integer keywordFinish String? @db.VarChar(100) delayMessage Int? @db.Integer unknownMessage String? @db.VarChar(100) listeningFromMe Boolean? @default(false) @db.Boolean stopBotFromMe Boolean? @default(false) @db.Boolean keepOpen Boolean? @default(false) @db.Boolean debounceTime Int? @db.Integer ignoreJids Json? splitMessages Boolean? @default(false) @db.Boolean timePerChar Int? @default(50) @db.Integer createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Fallback EvolutionBot? @relation(fields: [botIdFallback], references: [id]) botIdFallback String? @db.VarChar(100) Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique } model Flowise { id String @id @default(cuid()) enabled Boolean @default(true) @db.Boolean description String? @db.VarChar(255) apiUrl String? @db.VarChar(255) apiKey String? @db.VarChar(255) expire Int? @default(0) @db.Integer keywordFinish String? @db.VarChar(100) delayMessage Int? @db.Integer unknownMessage String? @db.VarChar(100) listeningFromMe Boolean? @default(false) @db.Boolean stopBotFromMe Boolean? @default(false) @db.Boolean keepOpen Boolean? @default(false) @db.Boolean debounceTime Int? @db.Integer ignoreJids Json? splitMessages Boolean? @default(false) @db.Boolean timePerChar Int? @default(50) @db.Integer triggerType TriggerType? triggerOperator TriggerOperator? triggerValue String? createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String FlowiseSetting FlowiseSetting[] } model FlowiseSetting { id String @id @default(cuid()) expire Int? @default(0) @db.Integer keywordFinish String? @db.VarChar(100) delayMessage Int? @db.Integer unknownMessage String? @db.VarChar(100) listeningFromMe Boolean? @default(false) @db.Boolean stopBotFromMe Boolean? @default(false) @db.Boolean keepOpen Boolean? @default(false) @db.Boolean debounceTime Int? @db.Integer ignoreJids Json? splitMessages Boolean? @default(false) @db.Boolean timePerChar Int? @default(50) @db.Integer createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Fallback Flowise? @relation(fields: [flowiseIdFallback], references: [id]) flowiseIdFallback String? @db.VarChar(100) Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique } model IsOnWhatsapp { id String @id @default(cuid()) remoteJid String @unique @db.VarChar(100) jidOptions String lid String? @db.VarChar(100) createdAt DateTime @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp } model N8n { id String @id @default(cuid()) enabled Boolean @default(true) @db.Boolean description String? @db.VarChar(255) webhookUrl String? @db.VarChar(255) basicAuthUser String? @db.VarChar(255) basicAuthPass String? @db.VarChar(255) expire Int? @default(0) @db.Integer keywordFinish String? @db.VarChar(100) delayMessage Int? @db.Integer unknownMessage String? @db.VarChar(100) listeningFromMe Boolean? @default(false) @db.Boolean stopBotFromMe Boolean? @default(false) @db.Boolean keepOpen Boolean? @default(false) @db.Boolean debounceTime Int? @db.Integer ignoreJids Json? splitMessages Boolean? @default(false) @db.Boolean timePerChar Int? @default(50) @db.Integer triggerType TriggerType? triggerOperator TriggerOperator? triggerValue String? createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String N8nSetting N8nSetting[] } model N8nSetting { id String @id @default(cuid()) expire Int? @default(0) @db.Integer keywordFinish String? @db.VarChar(100) delayMessage Int? @db.Integer unknownMessage String? @db.VarChar(100) listeningFromMe Boolean? @default(false) @db.Boolean stopBotFromMe Boolean? @default(false) @db.Boolean keepOpen Boolean? @default(false) @db.Boolean debounceTime Int? @db.Integer ignoreJids Json? splitMessages Boolean? @default(false) @db.Boolean timePerChar Int? @default(50) @db.Integer createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Fallback N8n? @relation(fields: [n8nIdFallback], references: [id]) n8nIdFallback String? @db.VarChar(100) Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique } model Evoai { id String @id @default(cuid()) enabled Boolean @default(true) @db.Boolean description String? @db.VarChar(255) agentUrl String? @db.VarChar(255) apiKey String? @db.VarChar(255) expire Int? @default(0) @db.Integer keywordFinish String? @db.VarChar(100) delayMessage Int? @db.Integer unknownMessage String? @db.VarChar(100) listeningFromMe Boolean? @default(false) @db.Boolean stopBotFromMe Boolean? @default(false) @db.Boolean keepOpen Boolean? @default(false) @db.Boolean debounceTime Int? @db.Integer ignoreJids Json? splitMessages Boolean? @default(false) @db.Boolean timePerChar Int? @default(50) @db.Integer triggerType TriggerType? triggerOperator TriggerOperator? triggerValue String? createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String EvoaiSetting EvoaiSetting[] } model EvoaiSetting { id String @id @default(cuid()) expire Int? @default(0) @db.Integer keywordFinish String? @db.VarChar(100) delayMessage Int? @db.Integer unknownMessage String? @db.VarChar(100) listeningFromMe Boolean? @default(false) @db.Boolean stopBotFromMe Boolean? @default(false) @db.Boolean keepOpen Boolean? @default(false) @db.Boolean debounceTime Int? @db.Integer ignoreJids Json? splitMessages Boolean? @default(false) @db.Boolean timePerChar Int? @default(50) @db.Integer createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Fallback Evoai? @relation(fields: [evoaiIdFallback], references: [id]) evoaiIdFallback String? @db.VarChar(100) Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique } ================================================ FILE: prisma/psql_bouncer-schema.prisma ================================================ // This is your Prisma schema file, // learn more about it in the docs: https://pris.ly/d/prisma-schema // Looking for ways to speed up your queries, or scale easily with your serverless or edge functions? // Try Prisma Accelerate: https://pris.ly/cli/accelerate-init generator client { provider = "prisma-client-js" } datasource db { provider = "postgresql" url = env("DATABASE_BOUNCER_CONNECTION_URI") directUrl = env("DATABASE_CONNECTION_URI") } enum InstanceConnectionStatus { open close connecting } enum DeviceMessage { ios android web unknown desktop } enum SessionStatus { opened closed paused } enum TriggerType { all keyword none advanced } enum TriggerOperator { contains equals startsWith endsWith regex } enum OpenaiBotType { assistant chatCompletion } enum DifyBotType { chatBot textGenerator agent workflow } model Instance { id String @id @default(cuid()) name String @unique @db.VarChar(255) connectionStatus InstanceConnectionStatus @default(open) ownerJid String? @db.VarChar(100) profileName String? @db.VarChar(100) profilePicUrl String? @db.VarChar(500) integration String? @db.VarChar(100) number String? @db.VarChar(100) businessId String? @db.VarChar(100) token String? @db.VarChar(255) clientName String? @db.VarChar(100) disconnectionReasonCode Int? @db.Integer disconnectionObject Json? @db.JsonB disconnectionAt DateTime? @db.Timestamp createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime? @updatedAt @db.Timestamp Chat Chat[] Contact Contact[] Message Message[] Webhook Webhook? Chatwoot Chatwoot? Label Label[] Proxy Proxy? Setting Setting? Rabbitmq Rabbitmq? Nats Nats? Sqs Sqs? Kafka Kafka? Websocket Websocket? Typebot Typebot[] Session Session? MessageUpdate MessageUpdate[] TypebotSetting TypebotSetting? Media Media[] OpenaiCreds OpenaiCreds[] OpenaiBot OpenaiBot[] OpenaiSetting OpenaiSetting? Template Template[] Dify Dify[] DifySetting DifySetting? IntegrationSession IntegrationSession[] EvolutionBot EvolutionBot[] EvolutionBotSetting EvolutionBotSetting? Flowise Flowise[] FlowiseSetting FlowiseSetting? Pusher Pusher? N8n N8n[] N8nSetting N8nSetting[] Evoai Evoai[] EvoaiSetting EvoaiSetting? } model Session { id String @id @default(cuid()) sessionId String @unique creds String? @db.Text createdAt DateTime @default(now()) @db.Timestamp Instance Instance @relation(fields: [sessionId], references: [id], onDelete: Cascade) } model Chat { id String @id @default(cuid()) remoteJid String @db.VarChar(100) name String? @db.VarChar(100) labels Json? @db.JsonB createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime? @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String unreadMessages Int @default(0) @@index([instanceId]) @@index([remoteJid]) } model Contact { id String @id @default(cuid()) remoteJid String @db.VarChar(100) pushName String? @db.VarChar(100) profilePicUrl String? @db.VarChar(500) createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime? @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @@unique([remoteJid, instanceId]) @@index([remoteJid]) @@index([instanceId]) } model Message { id String @id @default(cuid()) key Json @db.JsonB pushName String? @db.VarChar(100) participant String? @db.VarChar(100) messageType String @db.VarChar(100) message Json @db.JsonB contextInfo Json? @db.JsonB source DeviceMessage messageTimestamp Int @db.Integer chatwootMessageId Int? @db.Integer chatwootInboxId Int? @db.Integer chatwootConversationId Int? @db.Integer chatwootContactInboxSourceId String? @db.VarChar(100) chatwootIsRead Boolean? @db.Boolean Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String MessageUpdate MessageUpdate[] Media Media? webhookUrl String? @db.VarChar(500) status String? @db.VarChar(30) sessionId String? session IntegrationSession? @relation(fields: [sessionId], references: [id]) @@index([instanceId]) } model MessageUpdate { id String @id @default(cuid()) keyId String @db.VarChar(100) remoteJid String @db.VarChar(100) fromMe Boolean @db.Boolean participant String? @db.VarChar(100) pollUpdates Json? @db.JsonB status String @db.VarChar(30) Message Message @relation(fields: [messageId], references: [id], onDelete: Cascade) messageId String Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @@index([instanceId]) @@index([messageId]) } model Webhook { id String @id @default(cuid()) url String @db.VarChar(500) headers Json? @db.JsonB enabled Boolean? @default(true) @db.Boolean events Json? @db.JsonB webhookByEvents Boolean? @default(false) @db.Boolean webhookBase64 Boolean? @default(false) @db.Boolean createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique @@index([instanceId]) } model Chatwoot { id String @id @default(cuid()) enabled Boolean? @default(true) @db.Boolean accountId String? @db.VarChar(100) token String? @db.VarChar(100) url String? @db.VarChar(500) nameInbox String? @db.VarChar(100) signMsg Boolean? @default(false) @db.Boolean signDelimiter String? @db.VarChar(100) number String? @db.VarChar(100) reopenConversation Boolean? @default(false) @db.Boolean conversationPending Boolean? @default(false) @db.Boolean mergeBrazilContacts Boolean? @default(false) @db.Boolean importContacts Boolean? @default(false) @db.Boolean importMessages Boolean? @default(false) @db.Boolean daysLimitImportMessages Int? @db.Integer organization String? @db.VarChar(100) logo String? @db.VarChar(500) ignoreJids Json? createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique } model Label { id String @id @default(cuid()) labelId String? @db.VarChar(100) name String @db.VarChar(100) color String @db.VarChar(100) predefinedId String? @db.VarChar(100) createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @@unique([labelId, instanceId]) } model Proxy { id String @id @default(cuid()) enabled Boolean @default(false) @db.Boolean host String @db.VarChar(100) port String @db.VarChar(100) protocol String @db.VarChar(100) username String @db.VarChar(100) password String @db.VarChar(100) createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique } model Setting { id String @id @default(cuid()) rejectCall Boolean @default(false) @db.Boolean msgCall String? @db.VarChar(100) groupsIgnore Boolean @default(false) @db.Boolean alwaysOnline Boolean @default(false) @db.Boolean readMessages Boolean @default(false) @db.Boolean readStatus Boolean @default(false) @db.Boolean syncFullHistory Boolean @default(false) @db.Boolean wavoipToken String? @db.VarChar(100) createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique @@index([instanceId]) } model Rabbitmq { id String @id @default(cuid()) enabled Boolean @default(false) @db.Boolean events Json @db.JsonB createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique } model Nats { id String @id @default(cuid()) enabled Boolean @default(false) @db.Boolean events Json @db.JsonB createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique } model Sqs { id String @id @default(cuid()) enabled Boolean @default(false) @db.Boolean events Json @db.JsonB createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique } model Kafka { id String @id @default(cuid()) enabled Boolean @default(false) @db.Boolean events Json @db.JsonB createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique } model Websocket { id String @id @default(cuid()) enabled Boolean @default(false) @db.Boolean events Json @db.JsonB createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique } model Pusher { id String @id @default(cuid()) enabled Boolean @default(false) @db.Boolean appId String @db.VarChar(100) key String @db.VarChar(100) secret String @db.VarChar(100) cluster String @db.VarChar(100) useTLS Boolean @default(false) @db.Boolean events Json @db.JsonB createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique } model Typebot { id String @id @default(cuid()) enabled Boolean @default(true) @db.Boolean description String? @db.VarChar(255) url String @db.VarChar(500) typebot String @db.VarChar(100) expire Int? @default(0) @db.Integer keywordFinish String? @db.VarChar(100) delayMessage Int? @db.Integer unknownMessage String? @db.VarChar(100) listeningFromMe Boolean? @default(false) @db.Boolean stopBotFromMe Boolean? @default(false) @db.Boolean keepOpen Boolean? @default(false) @db.Boolean debounceTime Int? @db.Integer createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime? @updatedAt @db.Timestamp ignoreJids Json? triggerType TriggerType? triggerOperator TriggerOperator? triggerValue String? splitMessages Boolean? @default(false) @db.Boolean timePerChar Int? @default(50) @db.Integer Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String TypebotSetting TypebotSetting[] } model TypebotSetting { id String @id @default(cuid()) expire Int? @default(0) @db.Integer keywordFinish String? @db.VarChar(100) delayMessage Int? @db.Integer unknownMessage String? @db.VarChar(100) listeningFromMe Boolean? @default(false) @db.Boolean stopBotFromMe Boolean? @default(false) @db.Boolean keepOpen Boolean? @default(false) @db.Boolean debounceTime Int? @db.Integer typebotIdFallback String? @db.VarChar(100) ignoreJids Json? splitMessages Boolean? @default(false) @db.Boolean timePerChar Int? @default(50) @db.Integer createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Fallback Typebot? @relation(fields: [typebotIdFallback], references: [id]) Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique } model Media { id String @id @default(cuid()) fileName String @db.VarChar(500) type String @db.VarChar(100) mimetype String @db.VarChar(100) createdAt DateTime? @default(now()) @db.Date Message Message @relation(fields: [messageId], references: [id], onDelete: Cascade) messageId String @unique Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String } model OpenaiCreds { id String @id @default(cuid()) name String? @unique @db.VarChar(255) apiKey String? @unique @db.VarChar(255) createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String OpenaiAssistant OpenaiBot[] OpenaiSetting OpenaiSetting? } model OpenaiBot { id String @id @default(cuid()) enabled Boolean @default(true) @db.Boolean description String? @db.VarChar(255) botType OpenaiBotType assistantId String? @db.VarChar(255) functionUrl String? @db.VarChar(500) model String? @db.VarChar(100) systemMessages Json? @db.JsonB assistantMessages Json? @db.JsonB userMessages Json? @db.JsonB maxTokens Int? @db.Integer expire Int? @default(0) @db.Integer keywordFinish String? @db.VarChar(100) delayMessage Int? @db.Integer unknownMessage String? @db.VarChar(100) listeningFromMe Boolean? @default(false) @db.Boolean stopBotFromMe Boolean? @default(false) @db.Boolean keepOpen Boolean? @default(false) @db.Boolean debounceTime Int? @db.Integer splitMessages Boolean? @default(false) @db.Boolean timePerChar Int? @default(50) @db.Integer ignoreJids Json? triggerType TriggerType? triggerOperator TriggerOperator? triggerValue String? createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp OpenaiCreds OpenaiCreds @relation(fields: [openaiCredsId], references: [id], onDelete: Cascade) openaiCredsId String Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String OpenaiSetting OpenaiSetting[] } model IntegrationSession { id String @id @default(cuid()) sessionId String @db.VarChar(255) remoteJid String @db.VarChar(100) pushName String? status SessionStatus awaitUser Boolean @default(false) @db.Boolean context Json? type String? @db.VarChar(100) createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Message Message[] Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String parameters Json? @db.JsonB botId String? } model OpenaiSetting { id String @id @default(cuid()) expire Int? @default(0) @db.Integer keywordFinish String? @db.VarChar(100) delayMessage Int? @db.Integer unknownMessage String? @db.VarChar(100) listeningFromMe Boolean? @default(false) @db.Boolean stopBotFromMe Boolean? @default(false) @db.Boolean keepOpen Boolean? @default(false) @db.Boolean debounceTime Int? @db.Integer ignoreJids Json? splitMessages Boolean? @default(false) @db.Boolean timePerChar Int? @default(50) @db.Integer speechToText Boolean? @default(false) @db.Boolean createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp OpenaiCreds OpenaiCreds? @relation(fields: [openaiCredsId], references: [id]) openaiCredsId String @unique Fallback OpenaiBot? @relation(fields: [openaiIdFallback], references: [id]) openaiIdFallback String? @db.VarChar(100) Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique } model Template { id String @id @default(cuid()) templateId String @unique @db.VarChar(255) name String @unique @db.VarChar(255) template Json @db.JsonB webhookUrl String? @db.VarChar(500) createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String } model Dify { id String @id @default(cuid()) enabled Boolean @default(true) @db.Boolean description String? @db.VarChar(255) botType DifyBotType apiUrl String? @db.VarChar(255) apiKey String? @db.VarChar(255) expire Int? @default(0) @db.Integer keywordFinish String? @db.VarChar(100) delayMessage Int? @db.Integer unknownMessage String? @db.VarChar(100) listeningFromMe Boolean? @default(false) @db.Boolean stopBotFromMe Boolean? @default(false) @db.Boolean keepOpen Boolean? @default(false) @db.Boolean debounceTime Int? @db.Integer ignoreJids Json? splitMessages Boolean? @default(false) @db.Boolean timePerChar Int? @default(50) @db.Integer triggerType TriggerType? triggerOperator TriggerOperator? triggerValue String? createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String DifySetting DifySetting[] } model DifySetting { id String @id @default(cuid()) expire Int? @default(0) @db.Integer keywordFinish String? @db.VarChar(100) delayMessage Int? @db.Integer unknownMessage String? @db.VarChar(100) listeningFromMe Boolean? @default(false) @db.Boolean stopBotFromMe Boolean? @default(false) @db.Boolean keepOpen Boolean? @default(false) @db.Boolean debounceTime Int? @db.Integer ignoreJids Json? splitMessages Boolean? @default(false) @db.Boolean timePerChar Int? @default(50) @db.Integer createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Fallback Dify? @relation(fields: [difyIdFallback], references: [id]) difyIdFallback String? @db.VarChar(100) Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique } model EvolutionBot { id String @id @default(cuid()) enabled Boolean @default(true) @db.Boolean description String? @db.VarChar(255) apiUrl String? @db.VarChar(255) apiKey String? @db.VarChar(255) expire Int? @default(0) @db.Integer keywordFinish String? @db.VarChar(100) delayMessage Int? @db.Integer unknownMessage String? @db.VarChar(100) listeningFromMe Boolean? @default(false) @db.Boolean stopBotFromMe Boolean? @default(false) @db.Boolean keepOpen Boolean? @default(false) @db.Boolean debounceTime Int? @db.Integer ignoreJids Json? splitMessages Boolean? @default(false) @db.Boolean timePerChar Int? @default(50) @db.Integer triggerType TriggerType? triggerOperator TriggerOperator? triggerValue String? createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String EvolutionBotSetting EvolutionBotSetting[] } model EvolutionBotSetting { id String @id @default(cuid()) expire Int? @default(0) @db.Integer keywordFinish String? @db.VarChar(100) delayMessage Int? @db.Integer unknownMessage String? @db.VarChar(100) listeningFromMe Boolean? @default(false) @db.Boolean stopBotFromMe Boolean? @default(false) @db.Boolean keepOpen Boolean? @default(false) @db.Boolean debounceTime Int? @db.Integer ignoreJids Json? splitMessages Boolean? @default(false) @db.Boolean timePerChar Int? @default(50) @db.Integer createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Fallback EvolutionBot? @relation(fields: [botIdFallback], references: [id]) botIdFallback String? @db.VarChar(100) Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique } model Flowise { id String @id @default(cuid()) enabled Boolean @default(true) @db.Boolean description String? @db.VarChar(255) apiUrl String? @db.VarChar(255) apiKey String? @db.VarChar(255) expire Int? @default(0) @db.Integer keywordFinish String? @db.VarChar(100) delayMessage Int? @db.Integer unknownMessage String? @db.VarChar(100) listeningFromMe Boolean? @default(false) @db.Boolean stopBotFromMe Boolean? @default(false) @db.Boolean keepOpen Boolean? @default(false) @db.Boolean debounceTime Int? @db.Integer ignoreJids Json? splitMessages Boolean? @default(false) @db.Boolean timePerChar Int? @default(50) @db.Integer triggerType TriggerType? triggerOperator TriggerOperator? triggerValue String? createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String FlowiseSetting FlowiseSetting[] } model FlowiseSetting { id String @id @default(cuid()) expire Int? @default(0) @db.Integer keywordFinish String? @db.VarChar(100) delayMessage Int? @db.Integer unknownMessage String? @db.VarChar(100) listeningFromMe Boolean? @default(false) @db.Boolean stopBotFromMe Boolean? @default(false) @db.Boolean keepOpen Boolean? @default(false) @db.Boolean debounceTime Int? @db.Integer ignoreJids Json? splitMessages Boolean? @default(false) @db.Boolean timePerChar Int? @default(50) @db.Integer createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Fallback Flowise? @relation(fields: [flowiseIdFallback], references: [id]) flowiseIdFallback String? @db.VarChar(100) Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique } model IsOnWhatsapp { id String @id @default(cuid()) remoteJid String @unique @db.VarChar(100) jidOptions String lid String? @db.VarChar(100) createdAt DateTime @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp } model N8n { id String @id @default(cuid()) enabled Boolean @default(true) @db.Boolean description String? @db.VarChar(255) webhookUrl String? @db.VarChar(255) basicAuthUser String? @db.VarChar(255) basicAuthPass String? @db.VarChar(255) expire Int? @default(0) @db.Integer keywordFinish String? @db.VarChar(100) delayMessage Int? @db.Integer unknownMessage String? @db.VarChar(100) listeningFromMe Boolean? @default(false) @db.Boolean stopBotFromMe Boolean? @default(false) @db.Boolean keepOpen Boolean? @default(false) @db.Boolean debounceTime Int? @db.Integer ignoreJids Json? splitMessages Boolean? @default(false) @db.Boolean timePerChar Int? @default(50) @db.Integer triggerType TriggerType? triggerOperator TriggerOperator? triggerValue String? createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String N8nSetting N8nSetting[] } model N8nSetting { id String @id @default(cuid()) expire Int? @default(0) @db.Integer keywordFinish String? @db.VarChar(100) delayMessage Int? @db.Integer unknownMessage String? @db.VarChar(100) listeningFromMe Boolean? @default(false) @db.Boolean stopBotFromMe Boolean? @default(false) @db.Boolean keepOpen Boolean? @default(false) @db.Boolean debounceTime Int? @db.Integer ignoreJids Json? splitMessages Boolean? @default(false) @db.Boolean timePerChar Int? @default(50) @db.Integer createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Fallback N8n? @relation(fields: [n8nIdFallback], references: [id]) n8nIdFallback String? @db.VarChar(100) Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique } model Evoai { id String @id @default(cuid()) enabled Boolean @default(true) @db.Boolean description String? @db.VarChar(255) agentUrl String? @db.VarChar(255) apiKey String? @db.VarChar(255) expire Int? @default(0) @db.Integer keywordFinish String? @db.VarChar(100) delayMessage Int? @db.Integer unknownMessage String? @db.VarChar(100) listeningFromMe Boolean? @default(false) @db.Boolean stopBotFromMe Boolean? @default(false) @db.Boolean keepOpen Boolean? @default(false) @db.Boolean debounceTime Int? @db.Integer ignoreJids Json? splitMessages Boolean? @default(false) @db.Boolean timePerChar Int? @default(50) @db.Integer triggerType TriggerType? triggerOperator TriggerOperator? triggerValue String? createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String EvoaiSetting EvoaiSetting[] } model EvoaiSetting { id String @id @default(cuid()) expire Int? @default(0) @db.Integer keywordFinish String? @db.VarChar(100) delayMessage Int? @db.Integer unknownMessage String? @db.VarChar(100) listeningFromMe Boolean? @default(false) @db.Boolean stopBotFromMe Boolean? @default(false) @db.Boolean keepOpen Boolean? @default(false) @db.Boolean debounceTime Int? @db.Integer ignoreJids Json? splitMessages Boolean? @default(false) @db.Boolean timePerChar Int? @default(50) @db.Integer createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Fallback Evoai? @relation(fields: [evoaiIdFallback], references: [id]) evoaiIdFallback String? @db.VarChar(100) Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique } ================================================ FILE: prometheus.yml.example ================================================ # Prometheus configuration example for Evolution API # Copy this file to prometheus.yml and adjust the settings global: scrape_interval: 15s evaluation_interval: 15s rule_files: # - "first_rules.yml" # - "second_rules.yml" scrape_configs: # Evolution API metrics - job_name: 'evolution-api' static_configs: - targets: ['localhost:8080'] # Adjust to your Evolution API URL # Metrics endpoint path metrics_path: '/metrics' # Scrape interval for this job scrape_interval: 30s # Basic authentication (if METRICS_AUTH_REQUIRED=true) basic_auth: username: 'prometheus' # Should match METRICS_USER password: 'secure_random_password_here' # Should match METRICS_PASSWORD # Optional: Add custom labels relabel_configs: - source_labels: [__address__] target_label: __param_target - source_labels: [__param_target] target_label: instance - target_label: __address__ replacement: localhost:8080 # Evolution API address # Alerting configuration (optional) alerting: alertmanagers: - static_configs: - targets: # - alertmanager:9093 # Example alert rules for Evolution API # Create a file called evolution_alerts.yml with these rules: # # groups: # - name: evolution-api # rules: # - alert: EvolutionAPIDown # expr: up{job="evolution-api"} == 0 # for: 1m # labels: # severity: critical # annotations: # summary: "Evolution API is down" # description: "Evolution API has been down for more than 1 minute." # # - alert: EvolutionInstanceDown # expr: evolution_instance_up == 0 # for: 2m # labels: # severity: warning # annotations: # summary: "Evolution instance {{ $labels.instance }} is down" # description: "Instance {{ $labels.instance }} has been down for more than 2 minutes." # # - alert: HighInstanceCount # expr: evolution_instances_total > 100 # for: 5m # labels: # severity: warning # annotations: # summary: "High number of Evolution instances" # description: "Evolution API is managing {{ $value }} instances." ================================================ FILE: runWithProvider.js ================================================ const dotenv = require('dotenv'); const { execSync } = require('child_process'); const { existsSync } = require('fs'); dotenv.config(); const { DATABASE_PROVIDER } = process.env; const databaseProviderDefault = DATABASE_PROVIDER ?? 'postgresql'; if (!DATABASE_PROVIDER) { console.warn(`DATABASE_PROVIDER is not set in the .env file, using default: ${databaseProviderDefault}`); } // Função para determinar qual pasta de migrations usar // Função para determinar qual pasta de migrations usar function getMigrationsFolder(provider) { switch (provider) { case 'psql_bouncer': return 'postgresql-migrations'; // psql_bouncer usa as migrations do postgresql default: return `${provider}-migrations`; } } const migrationsFolder = getMigrationsFolder(databaseProviderDefault); let command = process.argv .slice(2) .join(' ') .replace(/DATABASE_PROVIDER/g, databaseProviderDefault); // Substituir referências à pasta de migrations pela pasta correta const migrationsPattern = new RegExp(`${databaseProviderDefault}-migrations`, 'g'); command = command.replace(migrationsPattern, migrationsFolder); if (command.includes('rmdir') && existsSync('prisma\\migrations')) { try { execSync('rmdir /S /Q prisma\\migrations', { stdio: 'inherit' }); } catch (error) { console.error(`Error removing directory: prisma\\migrations`); process.exit(1); } } else if (command.includes('rmdir')) { console.warn(`Directory 'prisma\\migrations' does not exist, skipping removal.`); } try { execSync(command, { stdio: 'inherit' }); } catch (error) { console.error(`Error executing command: ${command}`); process.exit(1); } ================================================ FILE: src/@types/express.d.ts ================================================ import { Multer } from 'multer'; declare global { namespace Express { interface Request { file?: Multer.File; } } } ================================================ FILE: src/api/abstract/abstract.cache.ts ================================================ export interface ICache { get(key: string): Promise; hGet(key: string, field: string): Promise; set(key: string, value: any, ttl?: number): void; hSet(key: string, field: string, value: any): Promise; has(key: string): Promise; keys(appendCriteria?: string): Promise; delete(key: string | string[]): Promise; hDelete(key: string, field: string): Promise; deleteAll(appendCriteria?: string): Promise; } ================================================ FILE: src/api/abstract/abstract.repository.ts ================================================ import { ConfigService, Database } from '@config/env.config'; import { ROOT_DIR } from '@config/path.config'; import { existsSync, mkdirSync, writeFileSync } from 'fs'; import { join } from 'path'; export type IInsert = { insertCount: number }; export interface IRepository { insert(data: any, instanceName: string, saveDb?: boolean): Promise; update(data: any, instanceName: string, saveDb?: boolean): Promise; find(query: any): Promise; delete(query: any, force?: boolean): Promise; dbSettings: Database; readonly storePath: string; } type WriteStore = { path: string; fileName: string; data: U; }; export abstract class Repository implements IRepository { constructor(configService: ConfigService) { this.dbSettings = configService.get('DATABASE'); } dbSettings: Database; readonly storePath = join(ROOT_DIR, 'store'); public writeStore = (create: WriteStore) => { if (!existsSync(create.path)) { mkdirSync(create.path, { recursive: true }); } try { writeFileSync(join(create.path, create.fileName + '.json'), JSON.stringify({ ...create.data }), { encoding: 'utf-8', }); return { message: 'create - success' }; } finally { create.data = undefined; } }; // eslint-disable-next-line public insert(data: any, instanceName: string, saveDb = false): Promise { throw new Error('Method not implemented.'); } // eslint-disable-next-line public update(data: any, instanceName: string, saveDb = false): Promise { throw new Error('Method not implemented.'); } // eslint-disable-next-line public find(query: any): Promise { throw new Error('Method not implemented.'); } // eslint-disable-next-line delete(query: any, force?: boolean): Promise { throw new Error('Method not implemented.'); } } ================================================ FILE: src/api/abstract/abstract.router.ts ================================================ import 'express-async-errors'; import { GetParticipant, GroupInvite } from '@api/dto/group.dto'; import { InstanceDto } from '@api/dto/instance.dto'; import { Logger } from '@config/logger.config'; import { BadRequestException } from '@exceptions'; import { Request } from 'express'; import { JSONSchema7 } from 'json-schema'; import { validate } from 'jsonschema'; type DataValidate = { request: Request; schema: JSONSchema7; ClassRef: any; execute: (instance: InstanceDto, data: T) => Promise; }; const logger = new Logger('Validate'); export abstract class RouterBroker { constructor() {} public routerPath(path: string, param = true) { let route = '/' + path; param ? (route += '/:instanceName') : null; return route; } public async dataValidate(args: DataValidate) { const { request, schema, ClassRef, execute } = args; const ref = new ClassRef(); const body = request.body; const instance = request.params as unknown as InstanceDto; if (request?.query && Object.keys(request.query).length > 0) { Object.assign(instance, request.query); } if (request.originalUrl.includes('/instance/create')) { Object.assign(instance, body); } Object.assign(ref, body); const v = schema ? validate(ref, schema) : { valid: true, errors: [] }; if (!v.valid) { const message: any[] = v.errors.map(({ stack, schema }) => { let message: string; if (schema['description']) { message = schema['description']; } else { message = stack.replace('instance.', ''); } return message; }); logger.error(message); throw new BadRequestException(message); } return await execute(instance, ref); } public async groupNoValidate(args: DataValidate) { const { request, ClassRef, schema, execute } = args; const instance = request.params as unknown as InstanceDto; const ref = new ClassRef(); Object.assign(ref, request.body); const v = validate(ref, schema); if (!v.valid) { const message: any[] = v.errors.map(({ property, stack, schema }) => { let message: string; if (schema['description']) { message = schema['description']; } else { message = stack.replace('instance.', ''); } return { property: property.replace('instance.', ''), message, }; }); logger.error([...message]); throw new BadRequestException(...message); } return await execute(instance, ref); } public async groupValidate(args: DataValidate) { const { request, ClassRef, schema, execute } = args; const instance = request.params as unknown as InstanceDto; const body = request.body; let groupJid = body?.groupJid; if (!groupJid) { if (request.query?.groupJid) { groupJid = request.query.groupJid; } else { throw new BadRequestException('The group id needs to be informed in the query', 'ex: "groupJid=120362@g.us"'); } } if (!groupJid.endsWith('@g.us')) { groupJid = groupJid + '@g.us'; } Object.assign(body, { groupJid: groupJid, }); const ref = new ClassRef(); Object.assign(ref, body); const v = validate(ref, schema); if (!v.valid) { const message: any[] = v.errors.map(({ property, stack, schema }) => { let message: string; if (schema['description']) { message = schema['description']; } else { message = stack.replace('instance.', ''); } return { property: property.replace('instance.', ''), message, }; }); logger.error([...message]); throw new BadRequestException(...message); } return await execute(instance, ref); } public async inviteCodeValidate(args: DataValidate) { const { request, ClassRef, schema, execute } = args; const inviteCode = request.query as unknown as GroupInvite; if (!inviteCode?.inviteCode) { throw new BadRequestException( 'The group invite code id needs to be informed in the query', 'ex: "inviteCode=F1EX5QZxO181L3TMVP31gY" (Obtained from group join link)', ); } const instance = request.params as unknown as InstanceDto; const body = request.body; const ref = new ClassRef(); Object.assign(body, inviteCode); Object.assign(ref, body); const v = validate(ref, schema); if (!v.valid) { const message: any[] = v.errors.map(({ property, stack, schema }) => { let message: string; if (schema['description']) { message = schema['description']; } else { message = stack.replace('instance.', ''); } return { property: property.replace('instance.', ''), message, }; }); logger.error([...message]); throw new BadRequestException(...message); } return await execute(instance, ref); } public async getParticipantsValidate(args: DataValidate) { const { request, ClassRef, schema, execute } = args; const getParticipants = request.query as unknown as GetParticipant; if (!getParticipants?.getParticipants) { throw new BadRequestException('The getParticipants needs to be informed in the query'); } const instance = request.params as unknown as InstanceDto; const body = request.body; const ref = new ClassRef(); Object.assign(body, getParticipants); Object.assign(ref, body); const v = validate(ref, schema); if (!v.valid) { const message: any[] = v.errors.map(({ property, stack, schema }) => { let message: string; if (schema['description']) { message = schema['description']; } else { message = stack.replace('instance.', ''); } return { property: property.replace('instance.', ''), message, }; }); logger.error([...message]); throw new BadRequestException(...message); } return await execute(instance, ref); } } ================================================ FILE: src/api/controllers/business.controller.ts ================================================ import { getCatalogDto, getCollectionsDto } from '@api/dto/business.dto'; import { InstanceDto } from '@api/dto/instance.dto'; import { WAMonitoringService } from '@api/services/monitor.service'; export class BusinessController { constructor(private readonly waMonitor: WAMonitoringService) {} public async fetchCatalog({ instanceName }: InstanceDto, data: getCatalogDto) { return await this.waMonitor.waInstances[instanceName].fetchCatalog(instanceName, data); } public async fetchCollections({ instanceName }: InstanceDto, data: getCollectionsDto) { return await this.waMonitor.waInstances[instanceName].fetchCollections(instanceName, data); } } ================================================ FILE: src/api/controllers/call.controller.ts ================================================ import { OfferCallDto } from '@api/dto/call.dto'; import { InstanceDto } from '@api/dto/instance.dto'; import { WAMonitoringService } from '@api/services/monitor.service'; export class CallController { constructor(private readonly waMonitor: WAMonitoringService) {} public async offerCall({ instanceName }: InstanceDto, data: OfferCallDto) { return await this.waMonitor.waInstances[instanceName].offerCall(data); } } ================================================ FILE: src/api/controllers/chat.controller.ts ================================================ import { ArchiveChatDto, BlockUserDto, DeleteMessage, getBase64FromMediaMessageDto, MarkChatUnreadDto, NumberDto, PrivacySettingDto, ProfileNameDto, ProfilePictureDto, ProfileStatusDto, ReadMessageDto, SendPresenceDto, UpdateMessageDto, WhatsAppNumberDto, } from '@api/dto/chat.dto'; import { InstanceDto } from '@api/dto/instance.dto'; import { Query } from '@api/repository/repository.service'; import { WAMonitoringService } from '@api/services/monitor.service'; import { Contact, Message, MessageUpdate } from '@prisma/client'; export class ChatController { constructor(private readonly waMonitor: WAMonitoringService) {} public async whatsappNumber({ instanceName }: InstanceDto, data: WhatsAppNumberDto) { return await this.waMonitor.waInstances[instanceName].whatsappNumber(data); } public async readMessage({ instanceName }: InstanceDto, data: ReadMessageDto) { return await this.waMonitor.waInstances[instanceName].markMessageAsRead(data); } public async archiveChat({ instanceName }: InstanceDto, data: ArchiveChatDto) { return await this.waMonitor.waInstances[instanceName].archiveChat(data); } public async markChatUnread({ instanceName }: InstanceDto, data: MarkChatUnreadDto) { return await this.waMonitor.waInstances[instanceName].markChatUnread(data); } public async deleteMessage({ instanceName }: InstanceDto, data: DeleteMessage) { return await this.waMonitor.waInstances[instanceName].deleteMessage(data); } public async fetchProfilePicture({ instanceName }: InstanceDto, data: NumberDto) { return await this.waMonitor.waInstances[instanceName].profilePicture(data.number); } public async fetchProfile({ instanceName }: InstanceDto, data: NumberDto) { return await this.waMonitor.waInstances[instanceName].fetchProfile(instanceName, data.number); } public async fetchContacts({ instanceName }: InstanceDto, query: Query) { return await this.waMonitor.waInstances[instanceName].fetchContacts(query); } public async getBase64FromMediaMessage({ instanceName }: InstanceDto, data: getBase64FromMediaMessageDto) { return await this.waMonitor.waInstances[instanceName].getBase64FromMediaMessage(data); } public async fetchMessages({ instanceName }: InstanceDto, query: Query) { return await this.waMonitor.waInstances[instanceName].fetchMessages(query); } public async fetchStatusMessage({ instanceName }: InstanceDto, query: Query) { return await this.waMonitor.waInstances[instanceName].fetchStatusMessage(query); } public async fetchChats({ instanceName }: InstanceDto, query: Query) { return await this.waMonitor.waInstances[instanceName].fetchChats(query); } public async findChatByRemoteJid({ instanceName }: InstanceDto, remoteJid: string) { return await this.waMonitor.waInstances[instanceName].findChatByRemoteJid(remoteJid); } public async sendPresence({ instanceName }: InstanceDto, data: SendPresenceDto) { return await this.waMonitor.waInstances[instanceName].sendPresence(data); } public async fetchPrivacySettings({ instanceName }: InstanceDto) { return await this.waMonitor.waInstances[instanceName].fetchPrivacySettings(); } public async updatePrivacySettings({ instanceName }: InstanceDto, data: PrivacySettingDto) { return await this.waMonitor.waInstances[instanceName].updatePrivacySettings(data); } public async fetchBusinessProfile({ instanceName }: InstanceDto, data: ProfilePictureDto) { return await this.waMonitor.waInstances[instanceName].fetchBusinessProfile(data.number); } public async updateProfileName({ instanceName }: InstanceDto, data: ProfileNameDto) { return await this.waMonitor.waInstances[instanceName].updateProfileName(data.name); } public async updateProfileStatus({ instanceName }: InstanceDto, data: ProfileStatusDto) { return await this.waMonitor.waInstances[instanceName].updateProfileStatus(data.status); } public async updateProfilePicture({ instanceName }: InstanceDto, data: ProfilePictureDto) { return await this.waMonitor.waInstances[instanceName].updateProfilePicture(data.picture); } public async removeProfilePicture({ instanceName }: InstanceDto) { return await this.waMonitor.waInstances[instanceName].removeProfilePicture(); } public async updateMessage({ instanceName }: InstanceDto, data: UpdateMessageDto) { return await this.waMonitor.waInstances[instanceName].updateMessage(data); } public async blockUser({ instanceName }: InstanceDto, data: BlockUserDto) { return await this.waMonitor.waInstances[instanceName].blockUser(data); } } ================================================ FILE: src/api/controllers/group.controller.ts ================================================ import { AcceptGroupInvite, CreateGroupDto, GetParticipant, GroupDescriptionDto, GroupInvite, GroupJid, GroupPictureDto, GroupSendInvite, GroupSubjectDto, GroupToggleEphemeralDto, GroupUpdateParticipantDto, GroupUpdateSettingDto, } from '@api/dto/group.dto'; import { InstanceDto } from '@api/dto/instance.dto'; import { WAMonitoringService } from '@api/services/monitor.service'; export class GroupController { constructor(private readonly waMonitor: WAMonitoringService) {} public async createGroup(instance: InstanceDto, create: CreateGroupDto) { return await this.waMonitor.waInstances[instance.instanceName].createGroup(create); } public async updateGroupPicture(instance: InstanceDto, update: GroupPictureDto) { return await this.waMonitor.waInstances[instance.instanceName].updateGroupPicture(update); } public async updateGroupSubject(instance: InstanceDto, update: GroupSubjectDto) { return await this.waMonitor.waInstances[instance.instanceName].updateGroupSubject(update); } public async updateGroupDescription(instance: InstanceDto, update: GroupDescriptionDto) { return await this.waMonitor.waInstances[instance.instanceName].updateGroupDescription(update); } public async findGroupInfo(instance: InstanceDto, groupJid: GroupJid) { return await this.waMonitor.waInstances[instance.instanceName].findGroup(groupJid); } public async fetchAllGroups(instance: InstanceDto, getPaticipants: GetParticipant) { return await this.waMonitor.waInstances[instance.instanceName].fetchAllGroups(getPaticipants); } public async inviteCode(instance: InstanceDto, groupJid: GroupJid) { return await this.waMonitor.waInstances[instance.instanceName].inviteCode(groupJid); } public async inviteInfo(instance: InstanceDto, inviteCode: GroupInvite) { return await this.waMonitor.waInstances[instance.instanceName].inviteInfo(inviteCode); } public async sendInvite(instance: InstanceDto, data: GroupSendInvite) { return await this.waMonitor.waInstances[instance.instanceName].sendInvite(data); } public async acceptInviteCode(instance: InstanceDto, inviteCode: AcceptGroupInvite) { return await this.waMonitor.waInstances[instance.instanceName].acceptInviteCode(inviteCode); } public async revokeInviteCode(instance: InstanceDto, groupJid: GroupJid) { return await this.waMonitor.waInstances[instance.instanceName].revokeInviteCode(groupJid); } public async findParticipants(instance: InstanceDto, groupJid: GroupJid) { return await this.waMonitor.waInstances[instance.instanceName].findParticipants(groupJid); } public async updateGParticipate(instance: InstanceDto, update: GroupUpdateParticipantDto) { return await this.waMonitor.waInstances[instance.instanceName].updateGParticipant(update); } public async updateGSetting(instance: InstanceDto, update: GroupUpdateSettingDto) { return await this.waMonitor.waInstances[instance.instanceName].updateGSetting(update); } public async toggleEphemeral(instance: InstanceDto, update: GroupToggleEphemeralDto) { return await this.waMonitor.waInstances[instance.instanceName].toggleEphemeral(update); } public async leaveGroup(instance: InstanceDto, groupJid: GroupJid) { return await this.waMonitor.waInstances[instance.instanceName].leaveGroup(groupJid); } } ================================================ FILE: src/api/controllers/instance.controller.ts ================================================ import { InstanceDto, SetPresenceDto } from '@api/dto/instance.dto'; import { ChatwootService } from '@api/integrations/chatbot/chatwoot/services/chatwoot.service'; import { ProviderFiles } from '@api/provider/sessions'; import { PrismaRepository } from '@api/repository/repository.service'; import { channelController, eventManager } from '@api/server.module'; import { CacheService } from '@api/services/cache.service'; import { WAMonitoringService } from '@api/services/monitor.service'; import { SettingsService } from '@api/services/settings.service'; import { Events, Integration, wa } from '@api/types/wa.types'; import { Auth, Chatwoot, ConfigService, HttpServer, WaBusiness } from '@config/env.config'; import { Logger } from '@config/logger.config'; import { BadRequestException, InternalServerErrorException, UnauthorizedException } from '@exceptions'; import { delay } from 'baileys'; import { isArray, isURL } from 'class-validator'; import EventEmitter2 from 'eventemitter2'; import { v4 } from 'uuid'; import { ProxyController } from './proxy.controller'; export class InstanceController { constructor( private readonly waMonitor: WAMonitoringService, private readonly configService: ConfigService, private readonly prismaRepository: PrismaRepository, private readonly eventEmitter: EventEmitter2, private readonly chatwootService: ChatwootService, private readonly settingsService: SettingsService, private readonly proxyService: ProxyController, private readonly cache: CacheService, private readonly chatwootCache: CacheService, private readonly baileysCache: CacheService, private readonly providerFiles: ProviderFiles, ) {} private readonly logger = new Logger('InstanceController'); public async createInstance(instanceData: InstanceDto) { try { const instance = channelController.init(instanceData, { configService: this.configService, eventEmitter: this.eventEmitter, prismaRepository: this.prismaRepository, cache: this.cache, chatwootCache: this.chatwootCache, baileysCache: this.baileysCache, providerFiles: this.providerFiles, }); if (!instance) { throw new BadRequestException('Invalid integration'); } const instanceId = v4(); instanceData.instanceId = instanceId; let hash: string; if (!instanceData.token) hash = v4().toUpperCase(); else hash = instanceData.token; await this.waMonitor.saveInstance({ instanceId, integration: instanceData.integration, instanceName: instanceData.instanceName, ownerJid: instanceData.ownerJid, profileName: instanceData.profileName, profilePicUrl: instanceData.profilePicUrl, hash, number: instanceData.number, businessId: instanceData.businessId, status: instanceData.status, }); instance.setInstance({ instanceName: instanceData.instanceName, instanceId, integration: instanceData.integration, token: hash, number: instanceData.number, businessId: instanceData.businessId, }); this.waMonitor.waInstances[instance.instanceName] = instance; this.waMonitor.delInstanceTime(instance.instanceName); // set events await eventManager.setInstance(instance.instanceName, instanceData); instance.sendDataWebhook(Events.INSTANCE_CREATE, { instanceName: instanceData.instanceName, instanceId: instanceId, }); const instanceDto: InstanceDto = { instanceName: instance.instanceName, instanceId: instance.instanceId, connectionStatus: typeof instance.connectionStatus === 'string' ? instance.connectionStatus : instance.connectionStatus?.state || 'unknown', }; if (instanceData.proxyHost && instanceData.proxyPort && instanceData.proxyProtocol) { const testProxy = await this.proxyService.testProxy({ host: instanceData.proxyHost, port: instanceData.proxyPort, protocol: instanceData.proxyProtocol, username: instanceData.proxyUsername, password: instanceData.proxyPassword, }); if (!testProxy) { throw new BadRequestException('Invalid proxy'); } await this.proxyService.createProxy(instanceDto, { enabled: true, host: instanceData.proxyHost, port: instanceData.proxyPort, protocol: instanceData.proxyProtocol, username: instanceData.proxyUsername, password: instanceData.proxyPassword, }); } const settings: wa.LocalSettings = { rejectCall: instanceData.rejectCall === true, msgCall: instanceData.msgCall || '', groupsIgnore: instanceData.groupsIgnore === true, alwaysOnline: instanceData.alwaysOnline === true, readMessages: instanceData.readMessages === true, readStatus: instanceData.readStatus === true, syncFullHistory: instanceData.syncFullHistory === true, wavoipToken: instanceData.wavoipToken || '', }; await this.settingsService.create(instanceDto, settings); let webhookWaBusiness = null, accessTokenWaBusiness = ''; if (instanceData.integration === Integration.WHATSAPP_BUSINESS) { if (!instanceData.number) { throw new BadRequestException('number is required'); } const urlServer = this.configService.get('SERVER').URL; webhookWaBusiness = `${urlServer}/webhook/meta`; accessTokenWaBusiness = this.configService.get('WA_BUSINESS').TOKEN_WEBHOOK; } if (!instanceData.chatwootAccountId || !instanceData.chatwootToken || !instanceData.chatwootUrl) { let getQrcode: wa.QrCode; if (instanceData.qrcode && instanceData.integration === Integration.WHATSAPP_BAILEYS) { await instance.connectToWhatsapp(instanceData.number); await delay(5000); getQrcode = instance.qrCode; } const result = { instance: { instanceName: instance.instanceName, instanceId: instanceId, integration: instanceData.integration, webhookWaBusiness, accessTokenWaBusiness, status: typeof instance.connectionStatus === 'string' ? instance.connectionStatus : instance.connectionStatus?.state || 'unknown', }, hash, webhook: { webhookUrl: instanceData?.webhook?.url, webhookHeaders: instanceData?.webhook?.headers, webhookByEvents: instanceData?.webhook?.byEvents, webhookBase64: instanceData?.webhook?.base64, }, websocket: { enabled: instanceData?.websocket?.enabled, }, rabbitmq: { enabled: instanceData?.rabbitmq?.enabled, }, nats: { enabled: instanceData?.nats?.enabled, }, sqs: { enabled: instanceData?.sqs?.enabled, }, settings, qrcode: getQrcode, }; return result; } if (!this.configService.get('CHATWOOT').ENABLED) throw new BadRequestException('Chatwoot is not enabled'); if (!instanceData.chatwootAccountId) { throw new BadRequestException('accountId is required'); } if (!instanceData.chatwootToken) { throw new BadRequestException('token is required'); } if (!instanceData.chatwootUrl) { throw new BadRequestException('url is required'); } if (!isURL(instanceData.chatwootUrl, { require_tld: false })) { throw new BadRequestException('Invalid "url" property in chatwoot'); } if (instanceData.chatwootSignMsg !== true && instanceData.chatwootSignMsg !== false) { throw new BadRequestException('signMsg is required'); } if (instanceData.chatwootReopenConversation !== true && instanceData.chatwootReopenConversation !== false) { throw new BadRequestException('reopenConversation is required'); } if (instanceData.chatwootConversationPending !== true && instanceData.chatwootConversationPending !== false) { throw new BadRequestException('conversationPending is required'); } const urlServer = this.configService.get('SERVER').URL; try { this.chatwootService.create(instanceDto, { enabled: true, accountId: instanceData.chatwootAccountId, token: instanceData.chatwootToken, url: instanceData.chatwootUrl, signMsg: instanceData.chatwootSignMsg || false, nameInbox: instanceData.chatwootNameInbox ?? instance.instanceName.split('-cwId-')[0], number: instanceData.number, reopenConversation: instanceData.chatwootReopenConversation || false, conversationPending: instanceData.chatwootConversationPending || false, importContacts: instanceData.chatwootImportContacts ?? true, mergeBrazilContacts: instanceData.chatwootMergeBrazilContacts ?? false, importMessages: instanceData.chatwootImportMessages ?? true, daysLimitImportMessages: instanceData.chatwootDaysLimitImportMessages ?? 60, organization: instanceData.chatwootOrganization, logo: instanceData.chatwootLogo, autoCreate: instanceData.chatwootAutoCreate !== false, }); } catch (error) { this.logger.log(error); } return { instance: { instanceName: instance.instanceName, instanceId: instanceId, integration: instanceData.integration, webhookWaBusiness, accessTokenWaBusiness, status: typeof instance.connectionStatus === 'string' ? instance.connectionStatus : instance.connectionStatus?.state || 'unknown', }, hash, webhook: { webhookUrl: instanceData?.webhook?.url, webhookHeaders: instanceData?.webhook?.headers, webhookByEvents: instanceData?.webhook?.byEvents, webhookBase64: instanceData?.webhook?.base64, }, websocket: { enabled: instanceData?.websocket?.enabled, }, rabbitmq: { enabled: instanceData?.rabbitmq?.enabled, }, nats: { enabled: instanceData?.nats?.enabled, }, sqs: { enabled: instanceData?.sqs?.enabled, }, settings, chatwoot: { enabled: true, accountId: instanceData.chatwootAccountId, token: instanceData.chatwootToken, url: instanceData.chatwootUrl, signMsg: instanceData.chatwootSignMsg || false, reopenConversation: instanceData.chatwootReopenConversation || false, conversationPending: instanceData.chatwootConversationPending || false, mergeBrazilContacts: instanceData.chatwootMergeBrazilContacts ?? false, importContacts: instanceData.chatwootImportContacts ?? true, importMessages: instanceData.chatwootImportMessages ?? true, daysLimitImportMessages: instanceData.chatwootDaysLimitImportMessages || 60, number: instanceData.number, nameInbox: instanceData.chatwootNameInbox ?? instance.instanceName, webhookUrl: `${urlServer}/chatwoot/webhook/${encodeURIComponent(instance.instanceName)}`, }, }; } catch (error) { this.waMonitor.deleteInstance(instanceData.instanceName); this.logger.error(isArray(error.message) ? error.message[0] : error.message); throw new BadRequestException(isArray(error.message) ? error.message[0] : error.message); } } public async connectToWhatsapp({ instanceName, number = null }: InstanceDto) { try { const instance = this.waMonitor.waInstances[instanceName]; const state = instance?.connectionStatus?.state; if (!state) { throw new BadRequestException('The "' + instanceName + '" instance does not exist'); } if (state == 'open') { return await this.connectionState({ instanceName }); } if (state == 'connecting') { return instance.qrCode; } if (state == 'close') { await instance.connectToWhatsapp(number); await delay(2000); return instance.qrCode; } return { instance: { instanceName: instanceName, status: state, }, qrcode: instance?.qrCode, }; } catch (error) { this.logger.error(error); return { error: true, message: error.toString() }; } } public async restartInstance({ instanceName }: InstanceDto) { try { const instance = this.waMonitor.waInstances[instanceName]; const state = instance?.connectionStatus?.state; if (!state) { throw new BadRequestException('The "' + instanceName + '" instance does not exist'); } if (state === 'close') { throw new BadRequestException('The "' + instanceName + '" instance is not connected'); } this.logger.info(`Restarting instance: ${instanceName}`); if (typeof instance.restart === 'function') { await instance.restart(); // Wait a bit for the reconnection to be established await new Promise((r) => setTimeout(r, 2000)); return { instance: { instanceName: instanceName, status: instance.connectionStatus?.state || 'connecting', }, }; } // Fallback for Baileys (uses different mechanism) if (state === 'open' || state === 'connecting') { if (this.configService.get('CHATWOOT').ENABLED) instance.clearCacheChatwoot(); instance.client?.ws?.close(); instance.client?.end(new Error('restart')); return await this.connectToWhatsapp({ instanceName }); } return { instance: { instanceName: instanceName, status: state, }, }; } catch (error) { this.logger.error(error); return { error: true, message: error.toString() }; } } public async connectionState({ instanceName }: InstanceDto) { return { instance: { instanceName: instanceName, state: this.waMonitor.waInstances[instanceName]?.connectionStatus?.state, }, }; } public async fetchInstances({ instanceName, instanceId, number }: InstanceDto, key: string) { const env = this.configService.get('AUTHENTICATION').API_KEY; if (env.KEY !== key) { const instancesByKey = await this.prismaRepository.instance.findMany({ where: { token: key, name: instanceName || undefined, id: instanceId || undefined, }, }); if (instancesByKey.length > 0) { const names = instancesByKey.map((instance) => instance.name); return this.waMonitor.instanceInfo(names); } else { throw new UnauthorizedException(); } } if (instanceId || number) { return this.waMonitor.instanceInfoById(instanceId, number); } const instanceNames = instanceName ? [instanceName] : null; return this.waMonitor.instanceInfo(instanceNames); } public async setPresence({ instanceName }: InstanceDto, data: SetPresenceDto) { return await this.waMonitor.waInstances[instanceName].setPresence(data); } public async logout({ instanceName }: InstanceDto) { const { instance } = await this.connectionState({ instanceName }); if (instance.state === 'close') { throw new BadRequestException('The "' + instanceName + '" instance is not connected'); } try { await this.waMonitor.waInstances[instanceName]?.logoutInstance(); return { status: 'SUCCESS', error: false, response: { message: 'Instance logged out' } }; } catch (error) { throw new InternalServerErrorException(error.toString()); } } public async deleteInstance({ instanceName }: InstanceDto) { const { instance } = await this.connectionState({ instanceName }); try { const waInstances = this.waMonitor.waInstances[instanceName]; if (this.configService.get('CHATWOOT').ENABLED) waInstances?.clearCacheChatwoot(); if (instance.state === 'connecting' || instance.state === 'open') { await this.logout({ instanceName }); } try { waInstances?.sendDataWebhook(Events.INSTANCE_DELETE, { instanceName, instanceId: waInstances.instanceId, }); } catch (error) { this.logger.error(error); } this.eventEmitter.emit('remove.instance', instanceName, 'inner'); return { status: 'SUCCESS', error: false, response: { message: 'Instance deleted' } }; } catch (error) { throw new BadRequestException(error.toString()); } } } ================================================ FILE: src/api/controllers/label.controller.ts ================================================ import { InstanceDto } from '@api/dto/instance.dto'; import { HandleLabelDto } from '@api/dto/label.dto'; import { WAMonitoringService } from '@api/services/monitor.service'; export class LabelController { constructor(private readonly waMonitor: WAMonitoringService) {} public async fetchLabels({ instanceName }: InstanceDto) { return await this.waMonitor.waInstances[instanceName].fetchLabels(); } public async handleLabel({ instanceName }: InstanceDto, data: HandleLabelDto) { return await this.waMonitor.waInstances[instanceName].handleLabel(data); } } ================================================ FILE: src/api/controllers/proxy.controller.ts ================================================ import { InstanceDto } from '@api/dto/instance.dto'; import { ProxyDto } from '@api/dto/proxy.dto'; import { WAMonitoringService } from '@api/services/monitor.service'; import { ProxyService } from '@api/services/proxy.service'; import { Logger } from '@config/logger.config'; import { BadRequestException, NotFoundException } from '@exceptions'; import { makeProxyAgent } from '@utils/makeProxyAgent'; import axios from 'axios'; const logger = new Logger('ProxyController'); export class ProxyController { constructor( private readonly proxyService: ProxyService, private readonly waMonitor: WAMonitoringService, ) {} public async createProxy(instance: InstanceDto, data: ProxyDto) { if (!this.waMonitor.waInstances[instance.instanceName]) { throw new NotFoundException(`The "${instance.instanceName}" instance does not exist`); } if (!data?.enabled) { data.host = ''; data.port = ''; data.protocol = ''; data.username = ''; data.password = ''; } if (data.host) { const testProxy = await this.testProxy(data); if (!testProxy) { throw new BadRequestException('Invalid proxy'); } } return this.proxyService.create(instance, data); } public async findProxy(instance: InstanceDto) { if (!this.waMonitor.waInstances[instance.instanceName]) { throw new NotFoundException(`The "${instance.instanceName}" instance does not exist`); } return this.proxyService.find(instance); } public async testProxy(proxy: ProxyDto) { try { const serverIp = await axios.get('https://icanhazip.com/'); const response = await axios.get('https://icanhazip.com/', { httpsAgent: makeProxyAgent(proxy), }); const result = response?.data !== serverIp?.data; if (result) { logger.info('testProxy: proxy connection successful'); } else { logger.warn("testProxy: proxy connection doesn't change the origin IP"); } return result; } catch (error) { if (axios.isAxiosError(error)) { logger.error('testProxy error: axios error: ' + error.message); } else { logger.error('testProxy error: unexpected error: ' + error); } return false; } } } ================================================ FILE: src/api/controllers/sendMessage.controller.ts ================================================ import { InstanceDto } from '@api/dto/instance.dto'; import { SendAudioDto, SendButtonsDto, SendContactDto, SendListDto, SendLocationDto, SendMediaDto, SendPollDto, SendPtvDto, SendReactionDto, SendStatusDto, SendStickerDto, SendTemplateDto, SendTextDto, } from '@api/dto/sendMessage.dto'; import { WAMonitoringService } from '@api/services/monitor.service'; import { BadRequestException } from '@exceptions'; import { isBase64, isURL } from 'class-validator'; import emojiRegex from 'emoji-regex'; const regex = emojiRegex(); function isEmoji(str: string) { if (str === '') return true; const match = str.match(regex); return match?.length === 1 && match[0] === str; } export class SendMessageController { constructor(private readonly waMonitor: WAMonitoringService) {} public async sendTemplate({ instanceName }: InstanceDto, data: SendTemplateDto) { return await this.waMonitor.waInstances[instanceName].templateMessage(data); } public async sendText({ instanceName }: InstanceDto, data: SendTextDto) { return await this.waMonitor.waInstances[instanceName].textMessage(data); } public async sendMedia({ instanceName }: InstanceDto, data: SendMediaDto, file?: any) { if (isBase64(data?.media) && !data?.fileName && data?.mediatype === 'document') { throw new BadRequestException('For base64 the file name must be informed.'); } if (file || isURL(data?.media) || isBase64(data?.media)) { return await this.waMonitor.waInstances[instanceName].mediaMessage(data, file); } throw new BadRequestException('Owned media must be a url or base64'); } public async sendPtv({ instanceName }: InstanceDto, data: SendPtvDto, file?: any) { if (file || isURL(data?.video) || isBase64(data?.video)) { return await this.waMonitor.waInstances[instanceName].ptvMessage(data, file); } throw new BadRequestException('Owned media must be a url or base64'); } public async sendSticker({ instanceName }: InstanceDto, data: SendStickerDto, file?: any) { if (file || isURL(data.sticker) || isBase64(data.sticker)) { return await this.waMonitor.waInstances[instanceName].mediaSticker(data, file); } throw new BadRequestException('Owned media must be a url or base64'); } public async sendWhatsAppAudio({ instanceName }: InstanceDto, data: SendAudioDto, file?: any) { if (file?.buffer || isURL(data.audio) || isBase64(data.audio)) { // Si file existe y tiene buffer, o si es una URL o Base64, continúa return await this.waMonitor.waInstances[instanceName].audioWhatsapp(data, file); } else { console.error('El archivo no tiene buffer o el audio no es una URL o Base64 válida'); throw new BadRequestException('Owned media must be a url, base64, or valid file with buffer'); } } public async sendButtons({ instanceName }: InstanceDto, data: SendButtonsDto) { return await this.waMonitor.waInstances[instanceName].buttonMessage(data); } public async sendLocation({ instanceName }: InstanceDto, data: SendLocationDto) { return await this.waMonitor.waInstances[instanceName].locationMessage(data); } public async sendList({ instanceName }: InstanceDto, data: SendListDto) { return await this.waMonitor.waInstances[instanceName].listMessage(data); } public async sendContact({ instanceName }: InstanceDto, data: SendContactDto) { return await this.waMonitor.waInstances[instanceName].contactMessage(data); } public async sendReaction({ instanceName }: InstanceDto, data: SendReactionDto) { if (!isEmoji(data.reaction)) { throw new BadRequestException('Reaction must be a single emoji or empty string'); } return await this.waMonitor.waInstances[instanceName].reactionMessage(data); } public async sendPoll({ instanceName }: InstanceDto, data: SendPollDto) { return await this.waMonitor.waInstances[instanceName].pollMessage(data); } public async sendStatus({ instanceName }: InstanceDto, data: SendStatusDto, file?: any) { return await this.waMonitor.waInstances[instanceName].statusMessage(data, file); } } ================================================ FILE: src/api/controllers/settings.controller.ts ================================================ import { InstanceDto } from '@api/dto/instance.dto'; import { SettingsDto } from '@api/dto/settings.dto'; import { SettingsService } from '@api/services/settings.service'; export class SettingsController { constructor(private readonly settingsService: SettingsService) {} public async createSettings(instance: InstanceDto, data: SettingsDto) { return this.settingsService.create(instance, data); } public async findSettings(instance: InstanceDto) { const settings = this.settingsService.find(instance); return settings; } } ================================================ FILE: src/api/controllers/template.controller.ts ================================================ import { InstanceDto } from '@api/dto/instance.dto'; import { TemplateDto } from '@api/dto/template.dto'; import { TemplateService } from '@api/services/template.service'; export class TemplateController { constructor(private readonly templateService: TemplateService) {} public async createTemplate(instance: InstanceDto, data: TemplateDto) { return this.templateService.create(instance, data); } public async findTemplate(instance: InstanceDto) { return this.templateService.find(instance); } public async editTemplate( instance: InstanceDto, data: { templateId: string; category?: string; components?: any; allowCategoryChange?: boolean; ttl?: number }, ) { return this.templateService.edit(instance, data); } public async deleteTemplate(instance: InstanceDto, data: { name: string; hsmId?: string }) { return this.templateService.delete(instance, data); } } ================================================ FILE: src/api/dto/business.dto.ts ================================================ export class NumberDto { number: string; } export class getCatalogDto { number?: string; limit?: number; cursor?: string; } export class getCollectionsDto { number?: string; limit?: number; } ================================================ FILE: src/api/dto/call.dto.ts ================================================ export class Metadata { number: string; } export class OfferCallDto extends Metadata { isVideo?: boolean; callDuration?: number; } ================================================ FILE: src/api/dto/chat.dto.ts ================================================ import { proto, WAPresence, WAPrivacyGroupAddValue, WAPrivacyOnlineValue, WAPrivacyValue, WAReadReceiptsValue, } from 'baileys'; export class OnWhatsAppDto { constructor( public readonly jid: string, public readonly exists: boolean, public readonly number: string, public readonly name?: string, public readonly lid?: string, ) {} } export class getBase64FromMediaMessageDto { message: proto.WebMessageInfo; convertToMp4?: boolean; } export class WhatsAppNumberDto { numbers: string[]; } export class NumberDto { number: string; } export class NumberBusiness { wid?: string; jid?: string; exists?: boolean; isBusiness: boolean; name?: string; message?: string; description?: string; email?: string; websites?: string[]; website?: string[]; address?: string; about?: string; vertical?: string; profilehandle?: string; } export class ProfileNameDto { name: string; } export class ProfileStatusDto { status: string; } export class ProfilePictureDto { number?: string; // url or base64 picture?: string; } class Key { id: string; fromMe: boolean; remoteJid: string; } export class ReadMessageDto { readMessages: Key[]; } export class LastMessage { key: Key; messageTimestamp?: number; } export class ArchiveChatDto { lastMessage?: LastMessage; chat?: string; archive: boolean; } export class MarkChatUnreadDto { lastMessage?: LastMessage; chat?: string; } export class PrivacySettingDto { readreceipts: WAReadReceiptsValue; profile: WAPrivacyValue; status: WAPrivacyValue; online: WAPrivacyOnlineValue; last: WAPrivacyValue; groupadd: WAPrivacyGroupAddValue; } export class DeleteMessage { id: string; fromMe: boolean; remoteJid: string; participant?: string; } export class Options { delay?: number; presence?: WAPresence; } class OptionsMessage { options: Options; } export class Metadata extends OptionsMessage { number: string; } export class SendPresenceDto extends Metadata { presence: WAPresence; delay: number; } export class UpdateMessageDto extends Metadata { number: string; key: proto.IMessageKey; text: string; } export class BlockUserDto { number: string; status: 'block' | 'unblock'; } ================================================ FILE: src/api/dto/chatbot.dto.ts ================================================ export class Session { remoteJid?: string; sessionId?: string; status?: string; createdAt?: number; updateAt?: number; } export class IgnoreJidDto { remoteJid?: string; action?: string; } ================================================ FILE: src/api/dto/group.dto.ts ================================================ export class CreateGroupDto { subject: string; participants: string[]; description?: string; promoteParticipants?: boolean; } export class GroupPictureDto { groupJid: string; image: string; } export class GroupSubjectDto { groupJid: string; subject: string; } export class GroupDescriptionDto { groupJid: string; description: string; } export class GroupJid { groupJid: string; } export class GetParticipant { getParticipants: string; } export class GroupInvite { inviteCode: string; } export class AcceptGroupInvite { inviteCode: string; } export class GroupSendInvite { groupJid: string; description: string; numbers: string[]; } export class GroupUpdateParticipantDto extends GroupJid { action: 'add' | 'remove' | 'promote' | 'demote'; participants: string[]; } export class GroupUpdateSettingDto extends GroupJid { action: 'announcement' | 'not_announcement' | 'unlocked' | 'locked'; } export class GroupToggleEphemeralDto extends GroupJid { expiration: 0 | 86400 | 604800 | 7776000; } ================================================ FILE: src/api/dto/instance.dto.ts ================================================ import { IntegrationDto } from '@api/integrations/integration.dto'; import { JsonValue } from '@prisma/client/runtime/library'; import { WAPresence } from 'baileys'; export class InstanceDto extends IntegrationDto { instanceName: string; instanceId?: string; qrcode?: boolean; businessId?: string; number?: string; integration?: string; token?: string; status?: string; ownerJid?: string; connectionStatus?: string; profileName?: string; profilePicUrl?: string; // settings rejectCall?: boolean; msgCall?: string; groupsIgnore?: boolean; alwaysOnline?: boolean; readMessages?: boolean; readStatus?: boolean; syncFullHistory?: boolean; wavoipToken?: string; // proxy proxyHost?: string; proxyPort?: string; proxyProtocol?: string; proxyUsername?: string; proxyPassword?: string; webhook?: { enabled?: boolean; events?: string[]; headers?: JsonValue; url?: string; byEvents?: boolean; base64?: boolean; }; chatwootAccountId?: string; chatwootConversationPending?: boolean; chatwootAutoCreate?: boolean; chatwootDaysLimitImportMessages?: number; chatwootImportContacts?: boolean; chatwootImportMessages?: boolean; chatwootLogo?: string; chatwootMergeBrazilContacts?: boolean; chatwootNameInbox?: string; chatwootOrganization?: string; chatwootReopenConversation?: boolean; chatwootSignMsg?: boolean; chatwootToken?: string; chatwootUrl?: string; } export class SetPresenceDto { presence: WAPresence; } ================================================ FILE: src/api/dto/label.dto.ts ================================================ export class LabelDto { id?: string; name: string; color: string; predefinedId?: string; } export class HandleLabelDto { number: string; labelId: string; action: 'add' | 'remove'; } ================================================ FILE: src/api/dto/proxy.dto.ts ================================================ export class ProxyDto { enabled?: boolean; host: string; port: string; protocol: string; username?: string; password?: string; } ================================================ FILE: src/api/dto/sendMessage.dto.ts ================================================ import { proto, WAPresence } from 'baileys'; export class Quoted { key: proto.IMessageKey; message: proto.IMessage; } export class Options { delay?: number; presence?: WAPresence; quoted?: Quoted; linkPreview?: boolean; encoding?: boolean; mentionsEveryOne?: boolean; mentioned?: string[]; webhookUrl?: string; } export class MediaMessage { mediatype: MediaType; mimetype?: string; caption?: string; // for document fileName?: string; // url or base64 media: string; } export class StatusMessage { type: string; content: string; statusJidList?: string[]; allContacts?: boolean; caption?: string; backgroundColor?: string; font?: number; } export class Metadata { number: string; delay?: number; quoted?: Quoted; linkPreview?: boolean; mentionsEveryOne?: boolean; mentioned?: string[]; encoding?: boolean; notConvertSticker?: boolean; } export class SendTextDto extends Metadata { text: string; } export class SendPresence extends Metadata { text: string; } export class SendStatusDto extends Metadata { type: string; content: string; statusJidList?: string[]; allContacts?: boolean; caption?: string; backgroundColor?: string; font?: number; } export class SendPollDto extends Metadata { name: string; selectableCount: number; values: string[]; messageSecret?: Uint8Array; } export type MediaType = 'image' | 'document' | 'video' | 'audio' | 'ptv'; export class SendMediaDto extends Metadata { mediatype: MediaType; mimetype?: string; caption?: string; // for document fileName?: string; // url or base64 media: string; } export class SendPtvDto extends Metadata { video: string; } export class SendStickerDto extends Metadata { sticker: string; } export class SendAudioDto extends Metadata { audio: string; } export type TypeButton = 'reply' | 'copy' | 'url' | 'call' | 'pix'; export type KeyType = 'phone' | 'email' | 'cpf' | 'cnpj' | 'random'; export class Button { type: TypeButton; displayText?: string; id?: string; url?: string; copyCode?: string; phoneNumber?: string; currency?: string; name?: string; keyType?: KeyType; key?: string; } export class SendButtonsDto extends Metadata { thumbnailUrl?: string; title: string; description?: string; footer?: string; buttons: Button[]; } export class SendLocationDto extends Metadata { latitude: number; longitude: number; name?: string; address?: string; } class Row { title: string; description: string; rowId: string; } class Section { title: string; rows: Row[]; } export class SendListDto extends Metadata { title: string; description?: string; footerText?: string; buttonText: string; sections: Section[]; } export class ContactMessage { fullName: string; wuid: string; phoneNumber: string; organization?: string; email?: string; url?: string; } export class SendTemplateDto extends Metadata { name: string; language: string; components: any; webhookUrl?: string; } export class SendContactDto extends Metadata { contact: ContactMessage[]; } export class SendReactionDto { key: proto.IMessageKey; reaction: string; } ================================================ FILE: src/api/dto/settings.dto.ts ================================================ export class SettingsDto { rejectCall?: boolean; msgCall?: string; groupsIgnore?: boolean; alwaysOnline?: boolean; readMessages?: boolean; readStatus?: boolean; syncFullHistory?: boolean; wavoipToken?: string; } ================================================ FILE: src/api/dto/template.dto.ts ================================================ export class TemplateDto { name: string; category: string; allowCategoryChange: boolean; language: string; components: any; webhookUrl?: string; } export class TemplateEditDto { templateId: string; category?: 'AUTHENTICATION' | 'MARKETING' | 'UTILITY'; allowCategoryChange?: boolean; ttl?: number; components?: any; } export class TemplateDeleteDto { name: string; hsmId?: string; } ================================================ FILE: src/api/guards/auth.guard.ts ================================================ import { InstanceDto } from '@api/dto/instance.dto'; import { prismaRepository } from '@api/server.module'; import { Auth, configService, Database } from '@config/env.config'; import { Logger } from '@config/logger.config'; import { ForbiddenException, UnauthorizedException } from '@exceptions'; import { NextFunction, Request, Response } from 'express'; const logger = new Logger('GUARD'); async function apikey(req: Request, _: Response, next: NextFunction) { const env = configService.get('AUTHENTICATION').API_KEY; const key = req.get('apikey'); const db = configService.get('DATABASE'); if (!key) { throw new UnauthorizedException(); } if (env.KEY === key) { return next(); } if ((req.originalUrl.includes('/instance/create') || req.originalUrl.includes('/instance/fetchInstances')) && !key) { throw new ForbiddenException('Missing global api key', 'The global api key must be set'); } const param = req.params as unknown as InstanceDto; try { if (param?.instanceName) { const instance = await prismaRepository.instance.findUnique({ where: { name: param.instanceName }, }); if (instance.token === key) { return next(); } } else { if (req.originalUrl.includes('/instance/fetchInstances') && db.SAVE_DATA.INSTANCE) { const instanceByKey = await prismaRepository.instance.findFirst({ where: { token: key }, }); if (instanceByKey) { return next(); } } } } catch (error) { logger.error(error); } throw new UnauthorizedException(); } export const authGuard = { apikey }; ================================================ FILE: src/api/guards/instance.guard.ts ================================================ import { InstanceDto } from '@api/dto/instance.dto'; import { cache, prismaRepository, waMonitor } from '@api/server.module'; import { CacheConf, configService } from '@config/env.config'; import { BadRequestException, ForbiddenException, InternalServerErrorException, NotFoundException } from '@exceptions'; import { NextFunction, Request, Response } from 'express'; async function getInstance(instanceName: string) { try { const cacheConf = configService.get('CACHE'); const exists = !!waMonitor.waInstances[instanceName]; if (cacheConf.REDIS.ENABLED && cacheConf.REDIS.SAVE_INSTANCES) { const keyExists = await cache.has(instanceName); return exists || keyExists; } return exists || (await prismaRepository.instance.findMany({ where: { name: instanceName } })).length > 0; } catch (error) { throw new InternalServerErrorException(error?.toString()); } } export async function instanceExistsGuard(req: Request, _: Response, next: NextFunction) { if (req.originalUrl.includes('/instance/create') || req.originalUrl.includes('/instance/fetchInstances')) { return next(); } const param = req.params as unknown as InstanceDto; if (!param?.instanceName) { throw new BadRequestException('"instanceName" not provided.'); } if (!(await getInstance(param.instanceName))) { throw new NotFoundException(`The "${param.instanceName}" instance does not exist`); } next(); } export async function instanceLoggedGuard(req: Request, _: Response, next: NextFunction) { if (req.originalUrl.includes('/instance/create')) { const instance = req.body as InstanceDto; if (await getInstance(instance.instanceName)) { throw new ForbiddenException(`This name "${instance.instanceName}" is already in use.`); } if (waMonitor.waInstances[instance.instanceName]) { delete waMonitor.waInstances[instance.instanceName]; } } next(); } ================================================ FILE: src/api/guards/telemetry.guard.ts ================================================ import { sendTelemetry } from '@utils/sendTelemetry'; import { NextFunction, Request, Response } from 'express'; class Telemetry { public collectTelemetry(req: Request, res: Response, next: NextFunction): void { sendTelemetry(req.path); next(); } } export default Telemetry; ================================================ FILE: src/api/integrations/channel/channel.controller.ts ================================================ import { InstanceDto } from '@api/dto/instance.dto'; import { ProviderFiles } from '@api/provider/sessions'; import { PrismaRepository } from '@api/repository/repository.service'; import { CacheService } from '@api/services/cache.service'; import { WAMonitoringService } from '@api/services/monitor.service'; import { Integration } from '@api/types/wa.types'; import { ConfigService } from '@config/env.config'; import { BadRequestException } from '@exceptions'; import EventEmitter2 from 'eventemitter2'; import { EvolutionStartupService } from './evolution/evolution.channel.service'; import { BusinessStartupService } from './meta/whatsapp.business.service'; import { BaileysStartupService } from './whatsapp/whatsapp.baileys.service'; type ChannelDataType = { configService: ConfigService; eventEmitter: EventEmitter2; prismaRepository: PrismaRepository; cache: CacheService; chatwootCache: CacheService; baileysCache: CacheService; providerFiles: ProviderFiles; }; export interface ChannelControllerInterface { receiveWebhook(data: any): Promise; } export class ChannelController { public prismaRepository: PrismaRepository; public waMonitor: WAMonitoringService; constructor(prismaRepository: PrismaRepository, waMonitor: WAMonitoringService) { this.prisma = prismaRepository; this.monitor = waMonitor; } public set prisma(prisma: PrismaRepository) { this.prismaRepository = prisma; } public get prisma() { return this.prismaRepository; } public set monitor(waMonitor: WAMonitoringService) { this.waMonitor = waMonitor; } public get monitor() { return this.waMonitor; } public init(instanceData: InstanceDto, data: ChannelDataType) { if (!instanceData.token && instanceData.integration === Integration.WHATSAPP_BUSINESS) { throw new BadRequestException('token is required'); } if (instanceData.integration === Integration.WHATSAPP_BUSINESS) { return new BusinessStartupService( data.configService, data.eventEmitter, data.prismaRepository, data.cache, data.chatwootCache, data.baileysCache, data.providerFiles, ); } if (instanceData.integration === Integration.EVOLUTION) { return new EvolutionStartupService( data.configService, data.eventEmitter, data.prismaRepository, data.cache, data.chatwootCache, ); } if (instanceData.integration === Integration.WHATSAPP_BAILEYS) { return new BaileysStartupService( data.configService, data.eventEmitter, data.prismaRepository, data.cache, data.chatwootCache, data.baileysCache, data.providerFiles, ); } return null; } } ================================================ FILE: src/api/integrations/channel/channel.router.ts ================================================ import { Router } from 'express'; import { EvolutionRouter } from './evolution/evolution.router'; import { MetaRouter } from './meta/meta.router'; import { BaileysRouter } from './whatsapp/baileys.router'; export class ChannelRouter { public readonly router: Router; constructor(configService: any, ...guards: any[]) { this.router = Router(); this.router.use('/', new EvolutionRouter(configService).router); this.router.use('/', new MetaRouter(configService).router); this.router.use('/baileys', new BaileysRouter(...guards).router); } } ================================================ FILE: src/api/integrations/channel/evolution/evolution.channel.service.ts ================================================ import { InstanceDto } from '@api/dto/instance.dto'; import { MediaMessage, Options, SendAudioDto, SendButtonsDto, SendMediaDto, SendTextDto, } from '@api/dto/sendMessage.dto'; import * as s3Service from '@api/integrations/storage/s3/libs/minio.server'; import { PrismaRepository } from '@api/repository/repository.service'; import { chatbotController } from '@api/server.module'; import { CacheService } from '@api/services/cache.service'; import { ChannelStartupService } from '@api/services/channel.service'; import { Events, wa } from '@api/types/wa.types'; import { AudioConverter, Chatwoot, ConfigService, Openai, S3 } from '@config/env.config'; import { BadRequestException, InternalServerErrorException } from '@exceptions'; import { createJid } from '@utils/createJid'; import { sendTelemetry } from '@utils/sendTelemetry'; import axios from 'axios'; import { isBase64, isURL } from 'class-validator'; import EventEmitter2 from 'eventemitter2'; import FormData from 'form-data'; import mimeTypes from 'mime-types'; import { join } from 'path'; import { v4 } from 'uuid'; export class EvolutionStartupService extends ChannelStartupService { constructor( public readonly configService: ConfigService, public readonly eventEmitter: EventEmitter2, public readonly prismaRepository: PrismaRepository, public readonly cache: CacheService, public readonly chatwootCache: CacheService, ) { super(configService, eventEmitter, prismaRepository, chatwootCache); this.client = null; } public client: any; public stateConnection: wa.StateConnection = { state: 'open' }; public phoneNumber: string; public mobile: boolean; public get connectionStatus() { return this.stateConnection; } public async closeClient() { this.stateConnection = { state: 'close' }; } public get qrCode(): wa.QrCode { return { pairingCode: this.instance.qrcode?.pairingCode, code: this.instance.qrcode?.code, base64: this.instance.qrcode?.base64, count: this.instance.qrcode?.count, }; } public async logoutInstance() { await this.closeClient(); } public setInstance(instance: InstanceDto) { this.logger.setInstance(instance.instanceId); this.instance.name = instance.instanceName; this.instance.id = instance.instanceId; this.instance.integration = instance.integration; this.instance.number = instance.number; this.instance.token = instance.token; this.instance.businessId = instance.businessId; if (this.configService.get('CHATWOOT').ENABLED && this.localChatwoot?.enabled) { this.chatwootService.eventWhatsapp( Events.STATUS_INSTANCE, { instanceName: this.instance.name, instanceId: this.instance.id, integration: instance.integration, }, { instance: this.instance.name, status: 'created', }, ); } } public async profilePicture(number: string) { const jid = createJid(number); return { wuid: jid, profilePictureUrl: null, }; } public async getProfileName() { return null; } public async profilePictureUrl() { return null; } public async getProfileStatus() { return null; } public async connectToWhatsapp(data?: any): Promise { if (!data) { this.loadChatwoot(); return; } try { this.eventHandler(data); } catch (error) { this.logger.error(error); throw new InternalServerErrorException(error?.toString()); } } protected async eventHandler(received: any) { try { let messageRaw: any; if (received.message) { const key = { id: received.key.id || v4(), remoteJid: received.key.remoteJid, fromMe: received.key.fromMe, profilePicUrl: received.profilePicUrl, }; messageRaw = { key, pushName: received.pushName, message: received.message, messageType: received.messageType, messageTimestamp: Math.round(new Date().getTime() / 1000), source: 'unknown', instanceId: this.instanceId, }; const isAudio = received?.message?.audioMessage; if (this.configService.get('OPENAI').ENABLED && isAudio) { const openAiDefaultSettings = await this.prismaRepository.openaiSetting.findFirst({ where: { instanceId: this.instanceId, }, include: { OpenaiCreds: true, }, }); if ( openAiDefaultSettings && openAiDefaultSettings.openaiCredsId && openAiDefaultSettings.speechToText && received?.message?.audioMessage ) { messageRaw.message.speechToText = `[audio] ${await this.openaiService.speechToText(received, this)}`; } } this.logger.log(messageRaw); sendTelemetry(`received.message.${messageRaw.messageType ?? 'unknown'}`); this.sendDataWebhook(Events.MESSAGES_UPSERT, messageRaw); await chatbotController.emit({ instance: { instanceName: this.instance.name, instanceId: this.instanceId }, remoteJid: messageRaw.key.remoteJid, msg: messageRaw, pushName: messageRaw.pushName, }); if (this.configService.get('CHATWOOT').ENABLED && this.localChatwoot?.enabled) { const chatwootSentMessage = await this.chatwootService.eventWhatsapp( Events.MESSAGES_UPSERT, { instanceName: this.instance.name, instanceId: this.instanceId }, messageRaw, ); if (chatwootSentMessage?.id) { messageRaw.chatwootMessageId = chatwootSentMessage.id; messageRaw.chatwootInboxId = chatwootSentMessage.id; messageRaw.chatwootConversationId = chatwootSentMessage.id; } } await this.prismaRepository.message.create({ data: messageRaw, }); await this.updateContact({ remoteJid: messageRaw.key.remoteJid, pushName: messageRaw.pushName, profilePicUrl: received.profilePicUrl, }); } } catch (error) { this.logger.error(error); } } private async updateContact(data: { remoteJid: string; pushName?: string; profilePicUrl?: string }) { const contactRaw: any = { remoteJid: data.remoteJid, pushName: data?.pushName, instanceId: this.instanceId, profilePicUrl: data?.profilePicUrl, }; const existingContact = await this.prismaRepository.contact.findFirst({ where: { remoteJid: data.remoteJid, instanceId: this.instanceId, }, }); if (existingContact) { await this.prismaRepository.contact.updateMany({ where: { remoteJid: data.remoteJid, instanceId: this.instanceId, }, data: contactRaw, }); } else { await this.prismaRepository.contact.create({ data: contactRaw, }); } this.sendDataWebhook(Events.CONTACTS_UPSERT, contactRaw); if (this.configService.get('CHATWOOT').ENABLED && this.localChatwoot?.enabled) { await this.chatwootService.eventWhatsapp( Events.CONTACTS_UPDATE, { instanceName: this.instance.name, instanceId: this.instanceId, integration: this.instance.integration, }, contactRaw, ); } const chat = await this.prismaRepository.chat.findFirst({ where: { instanceId: this.instanceId, remoteJid: data.remoteJid }, }); if (chat) { const chatRaw: any = { remoteJid: data.remoteJid, instanceId: this.instanceId, }; this.sendDataWebhook(Events.CHATS_UPDATE, chatRaw); await this.prismaRepository.chat.updateMany({ where: { remoteJid: chat.remoteJid }, data: chatRaw, }); } const chatRaw: any = { remoteJid: data.remoteJid, instanceId: this.instanceId, }; this.sendDataWebhook(Events.CHATS_UPSERT, chatRaw); await this.prismaRepository.chat.create({ data: chatRaw, }); } protected async sendMessageWithTyping( number: string, message: any, options?: Options, file?: any, isIntegration = false, ) { try { let quoted: any; let webhookUrl: any; if (options?.quoted) { const m = options?.quoted; const msg = m?.key; if (!msg) { throw 'Message not found'; } quoted = msg; } if (options.delay) { await new Promise((resolve) => setTimeout(resolve, options.delay)); } if (options?.webhookUrl) { webhookUrl = options.webhookUrl; } let audioFile; const messageId = v4(); let messageRaw: any; if (message?.mediaType === 'image') { messageRaw = { key: { fromMe: true, id: messageId, remoteJid: number }, message: { base64: isBase64(message.media) ? message.media : null, mediaUrl: isURL(message.media) ? message.media : null, quoted, }, messageType: 'imageMessage', messageTimestamp: Math.round(new Date().getTime() / 1000), webhookUrl, source: 'unknown', instanceId: this.instanceId, }; } else if (message?.mediaType === 'video') { messageRaw = { key: { fromMe: true, id: messageId, remoteJid: number }, message: { base64: isBase64(message.media) ? message.media : null, mediaUrl: isURL(message.media) ? message.media : null, quoted, }, messageType: 'videoMessage', messageTimestamp: Math.round(new Date().getTime() / 1000), webhookUrl, source: 'unknown', instanceId: this.instanceId, }; } else if (message?.mediaType === 'audio') { messageRaw = { key: { fromMe: true, id: messageId, remoteJid: number }, message: { base64: isBase64(message.media) ? message.media : null, mediaUrl: isURL(message.media) ? message.media : null, quoted, }, messageType: 'audioMessage', messageTimestamp: Math.round(new Date().getTime() / 1000), webhookUrl, source: 'unknown', instanceId: this.instanceId, }; const buffer = Buffer.from(message.media, 'base64'); audioFile = { buffer, mimetype: 'audio/mp4', originalname: `${messageId}.mp4`, }; } else if (message?.mediaType === 'document') { messageRaw = { key: { fromMe: true, id: messageId, remoteJid: number }, message: { base64: isBase64(message.media) ? message.media : null, mediaUrl: isURL(message.media) ? message.media : null, quoted, }, messageType: 'documentMessage', messageTimestamp: Math.round(new Date().getTime() / 1000), webhookUrl, source: 'unknown', instanceId: this.instanceId, }; } else if (message.buttonMessage) { messageRaw = { key: { fromMe: true, id: messageId, remoteJid: number }, message: { ...message.buttonMessage, buttons: message.buttonMessage.buttons, footer: message.buttonMessage.footer, body: message.buttonMessage.body, quoted, }, messageType: 'buttonMessage', messageTimestamp: Math.round(new Date().getTime() / 1000), webhookUrl, source: 'unknown', instanceId: this.instanceId, }; } else if (message.listMessage) { messageRaw = { key: { fromMe: true, id: messageId, remoteJid: number }, message: { ...message.listMessage, quoted, }, messageType: 'listMessage', messageTimestamp: Math.round(new Date().getTime() / 1000), webhookUrl, source: 'unknown', instanceId: this.instanceId, }; } else { messageRaw = { key: { fromMe: true, id: messageId, remoteJid: number }, message: { ...message, quoted, }, messageType: 'conversation', messageTimestamp: Math.round(new Date().getTime() / 1000), webhookUrl, source: 'unknown', instanceId: this.instanceId, }; } if (messageRaw.message.contextInfo) { messageRaw.contextInfo = { ...messageRaw.message.contextInfo, }; } if (messageRaw.contextInfo?.stanzaId) { const key: any = { id: messageRaw.contextInfo.stanzaId, }; const findMessage = await this.prismaRepository.message.findFirst({ where: { instanceId: this.instanceId, key, }, }); if (findMessage) { messageRaw.contextInfo.quotedMessage = findMessage.message; } } const { base64 } = messageRaw.message; delete messageRaw.message.base64; if (base64 || file || audioFile) { if (this.configService.get('S3').ENABLE) { try { // Verificação adicional para garantir que há conteúdo de mídia real const hasRealMedia = this.hasValidMediaContent(messageRaw); if (!hasRealMedia) { this.logger.warn('Message detected as media but contains no valid media content'); } else { const fileBuffer = audioFile?.buffer || file?.buffer; const buffer = base64 ? Buffer.from(base64, 'base64') : fileBuffer; let mediaType: string; let mimetype = audioFile?.mimetype || file.mimetype; if (messageRaw.messageType === 'documentMessage') { mediaType = 'document'; mimetype = !mimetype ? 'application/pdf' : mimetype; } else if (messageRaw.messageType === 'imageMessage') { mediaType = 'image'; mimetype = !mimetype ? 'image/png' : mimetype; } else if (messageRaw.messageType === 'audioMessage') { mediaType = 'audio'; mimetype = !mimetype ? 'audio/mp4' : mimetype; } else if (messageRaw.messageType === 'videoMessage') { mediaType = 'video'; mimetype = !mimetype ? 'video/mp4' : mimetype; } const fileName = `${messageRaw.key.id}.${mimetype.split('/')[1]}`; const size = buffer.byteLength; const fullName = join(`${this.instance.id}`, messageRaw.key.remoteJid, mediaType, fileName); await s3Service.uploadFile(fullName, buffer, size, { 'Content-Type': mimetype, }); const mediaUrl = await s3Service.getObjectUrl(fullName); messageRaw.message.mediaUrl = mediaUrl; } } catch (error) { this.logger.error(['Error on upload file to minio', error?.message, error?.stack]); } } } this.logger.log(messageRaw); this.sendDataWebhook(Events.SEND_MESSAGE, messageRaw); if (this.configService.get('CHATWOOT').ENABLED && this.localChatwoot?.enabled && !isIntegration) { this.chatwootService.eventWhatsapp( Events.SEND_MESSAGE, { instanceName: this.instance.name, instanceId: this.instanceId }, messageRaw, ); } if (this.configService.get('CHATWOOT').ENABLED && this.localChatwoot?.enabled && isIntegration) await chatbotController.emit({ instance: { instanceName: this.instance.name, instanceId: this.instanceId }, remoteJid: messageRaw.key.remoteJid, msg: messageRaw, pushName: messageRaw.pushName, }); await this.prismaRepository.message.create({ data: messageRaw, }); return messageRaw; } catch (error) { this.logger.error(error); throw new BadRequestException(error.toString()); } } public async textMessage(data: SendTextDto, isIntegration = false) { const res = await this.sendMessageWithTyping( data.number, { conversation: data.text, }, { delay: data?.delay, presence: 'composing', quoted: data?.quoted, linkPreview: data?.linkPreview, mentionsEveryOne: data?.mentionsEveryOne, mentioned: data?.mentioned, }, null, isIntegration, ); return res; } protected async prepareMediaMessage(mediaMessage: MediaMessage) { try { if (mediaMessage.mediatype === 'document' && !mediaMessage.fileName) { const regex = new RegExp(/.*\/(.+?)\./); const arrayMatch = regex.exec(mediaMessage.media); mediaMessage.fileName = arrayMatch[1]; } if (mediaMessage.mediatype === 'image' && !mediaMessage.fileName) { mediaMessage.fileName = 'image.png'; } if (mediaMessage.mediatype === 'video' && !mediaMessage.fileName) { mediaMessage.fileName = 'video.mp4'; } let mimetype: string | false; const prepareMedia: any = { caption: mediaMessage?.caption, fileName: mediaMessage.fileName, mediaType: mediaMessage.mediatype, media: mediaMessage.media, gifPlayback: false, }; if (isURL(mediaMessage.media)) { mimetype = mimeTypes.lookup(mediaMessage.media); } else { mimetype = mimeTypes.lookup(mediaMessage.fileName); } prepareMedia.mimetype = mimetype; return prepareMedia; } catch (error) { this.logger.error(error); throw new InternalServerErrorException(error?.toString() || error); } } public async mediaMessage(data: SendMediaDto, file?: any, isIntegration = false) { const mediaData: SendMediaDto = { ...data }; if (file) mediaData.media = file.buffer.toString('base64'); const message = await this.prepareMediaMessage(mediaData); const mediaSent = await this.sendMessageWithTyping( data.number, { ...message }, { delay: data?.delay, presence: 'composing', quoted: data?.quoted, linkPreview: data?.linkPreview, mentionsEveryOne: data?.mentionsEveryOne, mentioned: data?.mentioned, }, file, isIntegration, ); return mediaSent; } public async processAudio(audio: string, number: string, file: any) { number = number.replace(/\D/g, ''); const hash = `${number}-${new Date().getTime()}`; const audioConverterConfig = this.configService.get('AUDIO_CONVERTER'); if (audioConverterConfig.API_URL) { try { this.logger.verbose('Using audio converter API'); const formData = new FormData(); if (file) { formData.append('file', file.buffer, { filename: file.originalname, contentType: file.mimetype, }); } else if (isURL(audio)) { formData.append('url', audio); } else { formData.append('base64', audio); } formData.append('format', 'mp4'); const response = await axios.post(audioConverterConfig.API_URL, formData, { headers: { ...formData.getHeaders(), apikey: audioConverterConfig.API_KEY, }, }); if (!response?.data?.audio) { throw new InternalServerErrorException('Failed to convert audio'); } const prepareMedia: any = { fileName: `${hash}.mp4`, mediaType: 'audio', media: response?.data?.audio, mimetype: 'audio/mpeg', }; return prepareMedia; } catch (error) { this.logger.error(error?.response?.data || error); throw new InternalServerErrorException(error?.response?.data?.message || error?.toString() || error); } } else { let mimetype: string; const prepareMedia: any = { fileName: `${hash}.mp3`, mediaType: 'audio', media: audio, mimetype: 'audio/mpeg', }; if (isURL(audio)) { mimetype = mimeTypes.lookup(audio).toString(); } else { mimetype = mimeTypes.lookup(prepareMedia.fileName).toString(); } prepareMedia.mimetype = mimetype; return prepareMedia; } } public async audioWhatsapp(data: SendAudioDto, file?: any, isIntegration = false) { const mediaData: SendAudioDto = { ...data }; if (file?.buffer) { mediaData.audio = file.buffer.toString('base64'); } else { console.error('El archivo o buffer no est� definido correctamente.'); throw new Error('File or buffer is undefined.'); } const message = await this.processAudio(mediaData.audio, data.number, file); const audioSent = await this.sendMessageWithTyping( data.number, { ...message }, { delay: data?.delay, presence: 'composing', quoted: data?.quoted, linkPreview: data?.linkPreview, mentionsEveryOne: data?.mentionsEveryOne, mentioned: data?.mentioned, }, file, isIntegration, ); return audioSent; } public async buttonMessage(data: SendButtonsDto, isIntegration = false) { return await this.sendMessageWithTyping( data.number, { buttonMessage: { title: data.title, description: data.description, footer: data.footer, buttons: data.buttons, }, }, { delay: data?.delay, presence: 'composing', quoted: data?.quoted, mentionsEveryOne: data?.mentionsEveryOne, mentioned: data?.mentioned, }, null, isIntegration, ); } public async locationMessage() { throw new BadRequestException('Method not available on Evolution Channel'); } public async listMessage() { throw new BadRequestException('Method not available on Evolution Channel'); } public async templateMessage() { throw new BadRequestException('Method not available on Evolution Channel'); } public async contactMessage() { throw new BadRequestException('Method not available on Evolution Channel'); } public async reactionMessage() { throw new BadRequestException('Method not available on Evolution Channel'); } public async getBase64FromMediaMessage() { throw new BadRequestException('Method not available on Evolution Channel'); } public async deleteMessage() { throw new BadRequestException('Method not available on Evolution Channel'); } public async mediaSticker() { throw new BadRequestException('Method not available on Evolution Channel'); } public async pollMessage() { throw new BadRequestException('Method not available on Evolution Channel'); } public async statusMessage() { throw new BadRequestException('Method not available on Evolution Channel'); } public async reloadConnection() { throw new BadRequestException('Method not available on Evolution Channel'); } public async whatsappNumber() { throw new BadRequestException('Method not available on Evolution Channel'); } public async markMessageAsRead() { throw new BadRequestException('Method not available on Evolution Channel'); } public async archiveChat() { throw new BadRequestException('Method not available on Evolution Channel'); } public async markChatUnread() { throw new BadRequestException('Method not available on Evolution Channel'); } public async fetchProfile() { throw new BadRequestException('Method not available on Evolution Channel'); } public async offerCall() { throw new BadRequestException('Method not available on WhatsApp Business API'); } public async sendPresence() { throw new BadRequestException('Method not available on Evolution Channel'); } public async setPresence() { throw new BadRequestException('Method not available on Evolution Channel'); } public async fetchPrivacySettings() { throw new BadRequestException('Method not available on Evolution Channel'); } public async updatePrivacySettings() { throw new BadRequestException('Method not available on Evolution Channel'); } public async fetchBusinessProfile() { throw new BadRequestException('Method not available on Evolution Channel'); } public async updateProfileName() { throw new BadRequestException('Method not available on Evolution Channel'); } public async updateProfileStatus() { throw new BadRequestException('Method not available on Evolution Channel'); } public async updateProfilePicture() { throw new BadRequestException('Method not available on Evolution Channel'); } public async removeProfilePicture() { throw new BadRequestException('Method not available on Evolution Channel'); } public async blockUser() { throw new BadRequestException('Method not available on Evolution Channel'); } public async updateMessage() { throw new BadRequestException('Method not available on Evolution Channel'); } public async createGroup() { throw new BadRequestException('Method not available on Evolution Channel'); } public async updateGroupPicture() { throw new BadRequestException('Method not available on Evolution Channel'); } public async updateGroupSubject() { throw new BadRequestException('Method not available on Evolution Channel'); } public async updateGroupDescription() { throw new BadRequestException('Method not available on Evolution Channel'); } public async findGroup() { throw new BadRequestException('Method not available on Evolution Channel'); } public async fetchAllGroups() { throw new BadRequestException('Method not available on Evolution Channel'); } public async inviteCode() { throw new BadRequestException('Method not available on Evolution Channel'); } public async inviteInfo() { throw new BadRequestException('Method not available on Evolution Channel'); } public async sendInvite() { throw new BadRequestException('Method not available on Evolution Channel'); } public async acceptInviteCode() { throw new BadRequestException('Method not available on Evolution Channel'); } public async revokeInviteCode() { throw new BadRequestException('Method not available on Evolution Channel'); } public async findParticipants() { throw new BadRequestException('Method not available on Evolution Channel'); } public async updateGParticipant() { throw new BadRequestException('Method not available on Evolution Channel'); } public async updateGSetting() { throw new BadRequestException('Method not available on Evolution Channel'); } public async toggleEphemeral() { throw new BadRequestException('Method not available on Evolution Channel'); } public async leaveGroup() { throw new BadRequestException('Method not available on Evolution Channel'); } public async fetchLabels() { throw new BadRequestException('Method not available on Evolution Channel'); } public async handleLabel() { throw new BadRequestException('Method not available on Evolution Channel'); } public async receiveMobileCode() { throw new BadRequestException('Method not available on Evolution Channel'); } public async fakeCall() { throw new BadRequestException('Method not available on Evolution Channel'); } } ================================================ FILE: src/api/integrations/channel/evolution/evolution.controller.ts ================================================ import { PrismaRepository } from '@api/repository/repository.service'; import { WAMonitoringService } from '@api/services/monitor.service'; import { Logger } from '@config/logger.config'; import { ChannelController, ChannelControllerInterface } from '../channel.controller'; export class EvolutionController extends ChannelController implements ChannelControllerInterface { private readonly logger = new Logger('EvolutionController'); constructor(prismaRepository: PrismaRepository, waMonitor: WAMonitoringService) { super(prismaRepository, waMonitor); } integrationEnabled: boolean; public async receiveWebhook(data: any) { const numberId = data.numberId; if (!numberId) { this.logger.error('WebhookService -> receiveWebhookEvolution -> numberId not found'); return; } const instance = await this.prismaRepository.instance.findFirst({ where: { number: numberId }, }); if (!instance) { this.logger.error('WebhookService -> receiveWebhook -> instance not found'); return; } await this.waMonitor.waInstances[instance.name].connectToWhatsapp(data); return { status: 'success', }; } } ================================================ FILE: src/api/integrations/channel/evolution/evolution.router.ts ================================================ import { RouterBroker } from '@api/abstract/abstract.router'; import { evolutionController } from '@api/server.module'; import { ConfigService } from '@config/env.config'; import { Router } from 'express'; export class EvolutionRouter extends RouterBroker { constructor(readonly configService: ConfigService) { super(); this.router.post(this.routerPath('webhook/evolution', false), async (req, res) => { const { body } = req; const response = await evolutionController.receiveWebhook(body); return res.status(200).json(response); }); } public readonly router: Router = Router(); } ================================================ FILE: src/api/integrations/channel/meta/meta.controller.ts ================================================ import { PrismaRepository } from '@api/repository/repository.service'; import { WAMonitoringService } from '@api/services/monitor.service'; import { Logger } from '@config/logger.config'; import axios from 'axios'; import { ChannelController, ChannelControllerInterface } from '../channel.controller'; export class MetaController extends ChannelController implements ChannelControllerInterface { private readonly logger = new Logger('MetaController'); constructor(prismaRepository: PrismaRepository, waMonitor: WAMonitoringService) { super(prismaRepository, waMonitor); } integrationEnabled: boolean; public async receiveWebhook(data: any) { if (data.object === 'whatsapp_business_account') { if (data.entry[0]?.changes[0]?.field === 'message_template_status_update') { const template = await this.prismaRepository.template.findFirst({ where: { templateId: `${data.entry[0].changes[0].value.message_template_id}` }, }); if (!template) { console.log('template not found'); return; } const { webhookUrl } = template; await axios.post(webhookUrl, data.entry[0].changes[0].value, { headers: { 'Content-Type': 'application/json', }, }); return; } data.entry?.forEach(async (entry: any) => { const numberId = entry.changes[0].value.metadata.phone_number_id; if (!numberId) { this.logger.error('WebhookService -> receiveWebhookMeta -> numberId not found'); return { status: 'success', }; } const instance = await this.prismaRepository.instance.findFirst({ where: { number: numberId }, }); if (!instance) { this.logger.error('WebhookService -> receiveWebhookMeta -> instance not found'); return { status: 'success', }; } await this.waMonitor.waInstances[instance.name].connectToWhatsapp(data); return { status: 'success', }; }); } return { status: 'success', }; } } ================================================ FILE: src/api/integrations/channel/meta/meta.router.ts ================================================ import { RouterBroker } from '@api/abstract/abstract.router'; import { metaController } from '@api/server.module'; import { ConfigService, WaBusiness } from '@config/env.config'; import { Router } from 'express'; export class MetaRouter extends RouterBroker { constructor(readonly configService: ConfigService) { super(); this.router .get(this.routerPath('webhook/meta', false), async (req, res) => { if (req.query['hub.verify_token'] === configService.get('WA_BUSINESS').TOKEN_WEBHOOK) res.send(req.query['hub.challenge']); else res.send('Error, wrong validation token'); }) .post(this.routerPath('webhook/meta', false), async (req, res) => { const { body } = req; const response = await metaController.receiveWebhook(body); return res.status(200).json(response); }); } public readonly router: Router = Router(); } ================================================ FILE: src/api/integrations/channel/meta/whatsapp.business.service.ts ================================================ import { NumberBusiness } from '@api/dto/chat.dto'; import { ContactMessage, MediaMessage, Options, SendAudioDto, SendButtonsDto, SendContactDto, SendListDto, SendLocationDto, SendMediaDto, SendReactionDto, SendTemplateDto, SendTextDto, } from '@api/dto/sendMessage.dto'; import * as s3Service from '@api/integrations/storage/s3/libs/minio.server'; import { ProviderFiles } from '@api/provider/sessions'; import { PrismaRepository } from '@api/repository/repository.service'; import { chatbotController } from '@api/server.module'; import { CacheService } from '@api/services/cache.service'; import { ChannelStartupService } from '@api/services/channel.service'; import { Events, wa } from '@api/types/wa.types'; import { AudioConverter, Chatwoot, ConfigService, Database, Openai, S3, WaBusiness } from '@config/env.config'; import { BadRequestException, InternalServerErrorException } from '@exceptions'; import { createJid } from '@utils/createJid'; import { status } from '@utils/renderStatus'; import { sendTelemetry } from '@utils/sendTelemetry'; import axios from 'axios'; import { arrayUnique, isURL } from 'class-validator'; import EventEmitter2 from 'eventemitter2'; import FormData from 'form-data'; import mimeTypes from 'mime-types'; import { join } from 'path'; export class BusinessStartupService extends ChannelStartupService { constructor( public readonly configService: ConfigService, public readonly eventEmitter: EventEmitter2, public readonly prismaRepository: PrismaRepository, public readonly cache: CacheService, public readonly chatwootCache: CacheService, public readonly baileysCache: CacheService, private readonly providerFiles: ProviderFiles, ) { super(configService, eventEmitter, prismaRepository, chatwootCache); } public stateConnection: wa.StateConnection = { state: 'open' }; public phoneNumber: string; public mobile: boolean; public get connectionStatus() { return this.stateConnection; } public async closeClient() { this.stateConnection = { state: 'close' }; } public get qrCode(): wa.QrCode { return { pairingCode: this.instance.qrcode?.pairingCode, code: this.instance.qrcode?.code, base64: this.instance.qrcode?.base64, count: this.instance.qrcode?.count, }; } public async logoutInstance() { await this.closeClient(); } private isMediaMessage(message: any) { return message.document || message.image || message.audio || message.video; } private async post(message: any, params: string) { try { let urlServer = this.configService.get('WA_BUSINESS').URL; const version = this.configService.get('WA_BUSINESS').VERSION; urlServer = `${urlServer}/${version}/${this.number}/${params}`; const headers = { 'Content-Type': 'application/json', Authorization: `Bearer ${this.token}` }; const result = await axios.post(urlServer, message, { headers }); return result.data; } catch (e) { return e.response?.data?.error; } } public async profilePicture(number: string) { const jid = createJid(number); return { wuid: jid, profilePictureUrl: null, }; } public async getProfileName() { return null; } public async profilePictureUrl() { return null; } public async getProfileStatus() { return null; } public async setWhatsappBusinessProfile(data: NumberBusiness): Promise { const content = { messaging_product: 'whatsapp', about: data.about, address: data.address, description: data.description, vertical: data.vertical, email: data.email, websites: data.websites, profile_picture_handle: data.profilehandle, }; return await this.post(content, 'whatsapp_business_profile'); } public async connectToWhatsapp(data?: any): Promise { if (!data) return; const content = data.entry[0].changes[0].value; try { this.loadChatwoot(); this.eventHandler(content); this.phoneNumber = createJid(content.messages ? content.messages[0].from : content.statuses[0]?.recipient_id); } catch (error) { this.logger.error(error); throw new InternalServerErrorException(error?.toString()); } } private async downloadMediaMessage(message: any) { try { const id = message[message.type].id; let urlServer = this.configService.get('WA_BUSINESS').URL; const version = this.configService.get('WA_BUSINESS').VERSION; urlServer = `${urlServer}/${version}/${id}`; const headers = { 'Content-Type': 'application/json', Authorization: `Bearer ${this.token}` }; // Primeiro, obtenha a URL do arquivo let result = await axios.get(urlServer, { headers }); // Depois, baixe o arquivo usando a URL retornada result = await axios.get(result.data.url, { headers: { Authorization: `Bearer ${this.token}` }, // Use apenas o token de autorização para download responseType: 'arraybuffer', }); return result.data; } catch (e) { this.logger.error(`Error downloading media: ${e}`); throw e; } } private messageMediaJson(received: any) { const message = received.messages[0]; let content: any = message.type + 'Message'; content = { [content]: message[message.type] }; if (message.context) { content = { ...content, contextInfo: { stanzaId: message.context.id } }; } return content; } private messageAudioJson(received: any) { const message = received.messages[0]; let content: any = { audioMessage: { ...message.audio, ptt: message.audio.voice || false, // Define se é mensagem de voz }, }; if (message.context) { content = { ...content, contextInfo: { stanzaId: message.context.id } }; } return content; } private messageInteractiveJson(received: any) { const message = received.messages[0]; let content: any = { conversation: message.interactive[message.interactive.type].title }; message.context ? (content = { ...content, contextInfo: { stanzaId: message.context.id } }) : content; return content; } private messageButtonJson(received: any) { const message = received.messages[0]; let content: any = { conversation: received.messages[0].button?.text }; message.context ? (content = { ...content, contextInfo: { stanzaId: message.context.id } }) : content; return content; } private messageReactionJson(received: any) { const message = received.messages[0]; let content: any = { reactionMessage: { key: { id: message.reaction.message_id, }, text: message.reaction.emoji, }, }; message.context ? (content = { ...content, contextInfo: { stanzaId: message.context.id } }) : content; return content; } private messageTextJson(received: any) { // Verificar que received y received.messages existen if (!received || !received.messages || received.messages.length === 0) { this.logger.error('Error: received object or messages array is undefined or empty'); return null; } const message = received.messages[0]; let content: any; // Verificar si es un mensaje de tipo sticker, location u otro tipo que no tiene text if (!message.text) { // Si no hay texto, manejamos diferente según el tipo de mensaje if (message.type === 'sticker') { content = { stickerMessage: {} }; } else if (message.type === 'location') { content = { locationMessage: { degreesLatitude: message.location?.latitude, degreesLongitude: message.location?.longitude, name: message.location?.name, address: message.location?.address, }, }; } else { // Para otros tipos de mensajes sin texto, creamos un contenido genérico this.logger.log(`Mensaje de tipo ${message.type} sin campo text`); content = { [message.type + 'Message']: message[message.type] || {} }; } // Añadir contexto si existe if (message.context) { content = { ...content, contextInfo: { stanzaId: message.context.id } }; } return content; } // Si el mensaje tiene texto, procesamos normalmente if (!received.metadata || !received.metadata.phone_number_id) { this.logger.error('Error: metadata or phone_number_id is undefined'); return null; } if (message.from === received.metadata.phone_number_id) { content = { extendedTextMessage: { text: message.text.body }, }; if (message.context) { content = { ...content, contextInfo: { stanzaId: message.context.id } }; } } else { content = { conversation: message.text.body }; if (message.context) { content = { ...content, contextInfo: { stanzaId: message.context.id } }; } } return content; } private messageLocationJson(received: any) { const message = received.messages[0]; let content: any = { locationMessage: { degreesLatitude: message.location.latitude, degreesLongitude: message.location.longitude, name: message.location?.name, address: message.location?.address, }, }; message.context ? (content = { ...content, contextInfo: { stanzaId: message.context.id } }) : content; return content; } private messageContactsJson(received: any) { const message = received.messages[0]; let content: any = {}; const vcard = (contact: any) => { let result = 'BEGIN:VCARD\n' + 'VERSION:3.0\n' + `N:${contact.name.formatted_name}\n` + `FN:${contact.name.formatted_name}\n`; if (contact.org) { result += `ORG:${contact.org.company};\n`; } if (contact.emails) { result += `EMAIL:${contact.emails[0].email}\n`; } if (contact.urls) { result += `URL:${contact.urls[0].url}\n`; } if (!contact.phones[0]?.wa_id) { contact.phones[0].wa_id = createJid(contact.phones[0].phone); } result += `item1.TEL;waid=${contact.phones[0]?.wa_id}:${contact.phones[0].phone}\n` + 'item1.X-ABLabel:Celular\n' + 'END:VCARD'; return result; }; if (message.contacts.length === 1) { content.contactMessage = { displayName: message.contacts[0].name.formatted_name, vcard: vcard(message.contacts[0]), }; } else { content.contactsArrayMessage = { displayName: `${message.length} contacts`, contacts: message.map((contact) => { return { displayName: contact.name.formatted_name, vcard: vcard(contact), }; }), }; } message.context ? (content = { ...content, contextInfo: { stanzaId: message.context.id } }) : content; return content; } private renderMessageType(type: string) { let messageType: string; switch (type) { case 'text': messageType = 'conversation'; break; case 'image': messageType = 'imageMessage'; break; case 'video': messageType = 'videoMessage'; break; case 'audio': messageType = 'audioMessage'; break; case 'document': messageType = 'documentMessage'; break; case 'template': messageType = 'conversation'; break; case 'location': messageType = 'locationMessage'; break; case 'sticker': messageType = 'stickerMessage'; break; default: messageType = 'conversation'; break; } return messageType; } protected async messageHandle(received: any, database: Database, settings: any) { try { let messageRaw: any; let pushName: any; if (received.contacts) pushName = received.contacts[0].profile.name; if (received.messages) { const message = received.messages[0]; // Añadir esta línea para definir message const key = { id: message.id, remoteJid: this.phoneNumber, fromMe: message.from === received.metadata.phone_number_id, }; if (message.type === 'sticker') { this.logger.log('Procesando mensaje de tipo sticker'); messageRaw = { key, pushName, message: { stickerMessage: message.sticker || {}, }, messageType: 'stickerMessage', messageTimestamp: parseInt(message.timestamp) as number, source: 'unknown', instanceId: this.instanceId, }; } else if (this.isMediaMessage(message)) { const messageContent = message.type === 'audio' ? this.messageAudioJson(received) : this.messageMediaJson(received); messageRaw = { key, pushName, message: messageContent, contextInfo: messageContent?.contextInfo, messageType: this.renderMessageType(received.messages[0].type), messageTimestamp: parseInt(received.messages[0].timestamp) as number, source: 'unknown', instanceId: this.instanceId, }; if (this.configService.get('S3').ENABLE) { try { const message: any = received; // Verificação adicional para garantir que há conteúdo de mídia real const hasRealMedia = this.hasValidMediaContent(messageRaw); if (!hasRealMedia) { this.logger.warn('Message detected as media but contains no valid media content'); } else { const id = message.messages[0][message.messages[0].type].id; let urlServer = this.configService.get('WA_BUSINESS').URL; const version = this.configService.get('WA_BUSINESS').VERSION; urlServer = `${urlServer}/${version}/${id}`; const headers = { 'Content-Type': 'application/json', Authorization: `Bearer ${this.token}` }; const result = await axios.get(urlServer, { headers }); const buffer = await axios.get(result.data.url, { headers: { Authorization: `Bearer ${this.token}` }, // Use apenas o token de autorização para download responseType: 'arraybuffer', }); let mediaType; if (message.messages[0].document) { mediaType = 'document'; } else if (message.messages[0].image) { mediaType = 'image'; } else if (message.messages[0].audio) { mediaType = 'audio'; } else { mediaType = 'video'; } if (mediaType == 'video' && !this.configService.get('S3').SAVE_VIDEO) { this.logger?.info?.('Video upload attempted but is disabled by configuration.'); return { success: false, message: 'Video upload is currently disabled. Please contact support if you need this feature enabled.', }; } const mimetype = result.data?.mime_type || result.headers['content-type']; const contentDisposition = result.headers['content-disposition']; let fileName = `${message.messages[0].id}.${mimetype.split('/')[1]}`; if (contentDisposition) { const match = contentDisposition.match(/filename="(.+?)"/); if (match) { fileName = match[1]; } } // Para áudio, garantir extensão correta baseada no mimetype if (mediaType === 'audio') { if (mimetype.includes('ogg')) { fileName = `${message.messages[0].id}.ogg`; } else if (mimetype.includes('mp3')) { fileName = `${message.messages[0].id}.mp3`; } else if (mimetype.includes('m4a')) { fileName = `${message.messages[0].id}.m4a`; } } const size = result.headers['content-length'] || buffer.data.byteLength; const fullName = join(`${this.instance.id}`, key.remoteJid, mediaType, fileName); await s3Service.uploadFile(fullName, buffer.data, size, { 'Content-Type': mimetype, }); const createdMessage = await this.prismaRepository.message.create({ data: messageRaw, }); await this.prismaRepository.media.create({ data: { messageId: createdMessage.id, instanceId: this.instanceId, type: mediaType, fileName: fullName, mimetype, }, }); const mediaUrl = await s3Service.getObjectUrl(fullName); messageRaw.message.mediaUrl = mediaUrl; if (this.localWebhook.enabled && this.localWebhook.webhookBase64) { messageRaw.message.base64 = buffer.data.toString('base64'); } // Processar OpenAI speech-to-text para áudio após o mediaUrl estar disponível if (this.configService.get('OPENAI').ENABLED && mediaType === 'audio') { const openAiDefaultSettings = await this.prismaRepository.openaiSetting.findFirst({ where: { instanceId: this.instanceId, }, include: { OpenaiCreds: true, }, }); if ( openAiDefaultSettings && openAiDefaultSettings.openaiCredsId && openAiDefaultSettings.speechToText ) { try { messageRaw.message.speechToText = `[audio] ${await this.openaiService.speechToText( openAiDefaultSettings.OpenaiCreds, { message: { mediaUrl: messageRaw.message.mediaUrl, ...messageRaw, }, }, )}`; } catch (speechError) { this.logger.error(`Error processing speech-to-text: ${speechError}`); } } } } } catch (error) { this.logger.error(['Error on upload file to minio', error?.message, error?.stack]); } } else { if (this.localWebhook.enabled && this.localWebhook.webhookBase64) { const buffer = await this.downloadMediaMessage(received?.messages[0]); messageRaw.message.base64 = buffer.toString('base64'); } // Processar OpenAI speech-to-text para áudio mesmo sem S3 if (this.configService.get('OPENAI').ENABLED && message.type === 'audio') { let openAiBase64 = messageRaw.message.base64; if (!openAiBase64) { const buffer = await this.downloadMediaMessage(received?.messages[0]); openAiBase64 = buffer.toString('base64'); } const openAiDefaultSettings = await this.prismaRepository.openaiSetting.findFirst({ where: { instanceId: this.instanceId, }, include: { OpenaiCreds: true, }, }); if (openAiDefaultSettings && openAiDefaultSettings.openaiCredsId && openAiDefaultSettings.speechToText) { try { messageRaw.message.speechToText = `[audio] ${await this.openaiService.speechToText( openAiDefaultSettings.OpenaiCreds, { message: { base64: openAiBase64, ...messageRaw, }, }, )}`; } catch (speechError) { this.logger.error(`Error processing speech-to-text: ${speechError}`); } } } } } else if (received?.messages[0].interactive) { messageRaw = { key, pushName, message: { ...this.messageInteractiveJson(received), }, contextInfo: this.messageInteractiveJson(received)?.contextInfo, messageType: 'interactiveMessage', messageTimestamp: parseInt(received.messages[0].timestamp) as number, source: 'unknown', instanceId: this.instanceId, }; } else if (received?.messages[0].button) { messageRaw = { key, pushName, message: { ...this.messageButtonJson(received), }, contextInfo: this.messageButtonJson(received)?.contextInfo, messageType: 'buttonMessage', messageTimestamp: parseInt(received.messages[0].timestamp) as number, source: 'unknown', instanceId: this.instanceId, }; } else if (received?.messages[0].reaction) { messageRaw = { key, pushName, message: { ...this.messageReactionJson(received), }, contextInfo: this.messageReactionJson(received)?.contextInfo, messageType: 'reactionMessage', messageTimestamp: parseInt(received.messages[0].timestamp) as number, source: 'unknown', instanceId: this.instanceId, }; } else if (received?.messages[0].contacts) { messageRaw = { key, pushName, message: { ...this.messageContactsJson(received), }, contextInfo: this.messageContactsJson(received)?.contextInfo, messageType: 'contactMessage', messageTimestamp: parseInt(received.messages[0].timestamp) as number, source: 'unknown', instanceId: this.instanceId, }; } else { messageRaw = { key, pushName, message: this.messageTextJson(received), contextInfo: this.messageTextJson(received)?.contextInfo, messageType: this.renderMessageType(received.messages[0].type), messageTimestamp: parseInt(received.messages[0].timestamp) as number, source: 'unknown', instanceId: this.instanceId, }; } if (this.localSettings.readMessages) { // await this.client.readMessages([received.key]); } this.logger.log(messageRaw); sendTelemetry(`received.message.${messageRaw.messageType ?? 'unknown'}`); this.sendDataWebhook(Events.MESSAGES_UPSERT, messageRaw); await chatbotController.emit({ instance: { instanceName: this.instance.name, instanceId: this.instanceId }, remoteJid: messageRaw.key.remoteJid, msg: messageRaw, pushName: messageRaw.pushName, }); if (this.configService.get('CHATWOOT').ENABLED && this.localChatwoot?.enabled) { const chatwootSentMessage = await this.chatwootService.eventWhatsapp( Events.MESSAGES_UPSERT, { instanceName: this.instance.name, instanceId: this.instanceId }, messageRaw, ); if (chatwootSentMessage?.id) { messageRaw.chatwootMessageId = chatwootSentMessage.id; messageRaw.chatwootInboxId = chatwootSentMessage.id; messageRaw.chatwootConversationId = chatwootSentMessage.id; } } if (!this.isMediaMessage(message) && message.type !== 'sticker') { await this.prismaRepository.message.create({ data: messageRaw, }); } const contact = await this.prismaRepository.contact.findFirst({ where: { instanceId: this.instanceId, remoteJid: key.remoteJid }, }); const contactRaw: any = { remoteJid: received.contacts[0].profile.phone, pushName, // profilePicUrl: '', instanceId: this.instanceId, }; if (contactRaw.remoteJid === 'status@broadcast') { return; } if (contact) { const contactRaw: any = { remoteJid: received.contacts[0].profile.phone, pushName, // profilePicUrl: '', instanceId: this.instanceId, }; this.sendDataWebhook(Events.CONTACTS_UPDATE, contactRaw); if (this.configService.get('CHATWOOT').ENABLED && this.localChatwoot?.enabled) { await this.chatwootService.eventWhatsapp( Events.CONTACTS_UPDATE, { instanceName: this.instance.name, instanceId: this.instanceId }, contactRaw, ); } await this.prismaRepository.contact.updateMany({ where: { remoteJid: contact.remoteJid }, data: contactRaw, }); return; } this.sendDataWebhook(Events.CONTACTS_UPSERT, contactRaw); this.prismaRepository.contact.create({ data: contactRaw, }); } if (received.statuses) { for await (const item of received.statuses) { const key = { id: item.id, remoteJid: this.phoneNumber, fromMe: this.phoneNumber === received.metadata.phone_number_id, }; if (settings?.groups_ignore && key.remoteJid.includes('@g.us')) { return; } if (key.remoteJid !== 'status@broadcast' && !key?.remoteJid?.match(/(:\d+)/)) { const findMessage = await this.prismaRepository.message.findFirst({ where: { instanceId: this.instanceId, key: { path: ['id'], equals: key.id, }, }, }); if (!findMessage) { return; } if (item.message === null && item.status === undefined) { this.sendDataWebhook(Events.MESSAGES_DELETE, key); const message: any = { messageId: findMessage.id, keyId: key.id, remoteJid: key.remoteJid, fromMe: key.fromMe, participant: key?.remoteJid, status: 'DELETED', instanceId: this.instanceId, }; await this.prismaRepository.messageUpdate.create({ data: message, }); if (this.configService.get('CHATWOOT').ENABLED && this.localChatwoot?.enabled) { this.chatwootService.eventWhatsapp( Events.MESSAGES_DELETE, { instanceName: this.instance.name, instanceId: this.instanceId }, { key: key }, ); } return; } const message: any = { messageId: findMessage.id, keyId: key.id, remoteJid: key.remoteJid, fromMe: key.fromMe, participant: key?.remoteJid, status: item.status.toUpperCase(), instanceId: this.instanceId, }; this.sendDataWebhook(Events.MESSAGES_UPDATE, message); await this.prismaRepository.messageUpdate.create({ data: message, }); if (findMessage.webhookUrl) { await axios.post(findMessage.webhookUrl, message); } } } } } catch (error) { this.logger.error(error); } } private convertMessageToRaw(message: any, content: any) { let convertMessage: any; if (message?.conversation) { if (content?.context?.message_id) { convertMessage = { ...message, contextInfo: { stanzaId: content.context.message_id }, }; return convertMessage; } convertMessage = message; return convertMessage; } if (message?.mediaType === 'image') { if (content?.context?.message_id) { convertMessage = { imageMessage: message, contextInfo: { stanzaId: content.context.message_id }, }; return convertMessage; } return { imageMessage: message, }; } if (message?.mediaType === 'video') { if (content?.context?.message_id) { convertMessage = { videoMessage: message, contextInfo: { stanzaId: content.context.message_id }, }; return convertMessage; } return { videoMessage: message, }; } if (message?.mediaType === 'audio') { if (content?.context?.message_id) { convertMessage = { audioMessage: message, contextInfo: { stanzaId: content.context.message_id }, }; return convertMessage; } return { audioMessage: message, }; } if (message?.mediaType === 'document') { if (content?.context?.message_id) { convertMessage = { documentMessage: message, contextInfo: { stanzaId: content.context.message_id }, }; return convertMessage; } return { documentMessage: message, }; } return message; } protected async eventHandler(content: any) { try { // Registro para depuración this.logger.log('Contenido recibido en eventHandler:'); this.logger.log(JSON.stringify(content, null, 2)); const database = this.configService.get('DATABASE'); const settings = await this.findSettings(); // Si hay mensajes, verificar primero el tipo if (content.messages && content.messages.length > 0) { const message = content.messages[0]; this.logger.log(`Tipo de mensaje recibido: ${message.type}`); // Verificamos el tipo de mensaje antes de procesarlo if ( message.type === 'text' || message.type === 'image' || message.type === 'video' || message.type === 'audio' || message.type === 'document' || message.type === 'sticker' || message.type === 'location' || message.type === 'contacts' || message.type === 'interactive' || message.type === 'button' || message.type === 'reaction' ) { // Procesar el mensaje normalmente this.messageHandle(content, database, settings); } else { this.logger.warn(`Tipo de mensaje no reconocido: ${message.type}`); } } else if (content.statuses) { // Procesar actualizaciones de estado this.messageHandle(content, database, settings); } else { this.logger.warn('No se encontraron mensajes ni estados en el contenido recibido'); } } catch (error) { this.logger.error('Error en eventHandler:'); this.logger.error(error); } } protected async sendMessageWithTyping(number: string, message: any, options?: Options, isIntegration = false) { try { let quoted: any; let webhookUrl: any; if (options?.quoted) { const m = options?.quoted; const msg = m?.key; if (!msg) { throw 'Message not found'; } quoted = msg; } if (options?.webhookUrl) { webhookUrl = options.webhookUrl; } let content: any; const messageSent = await (async () => { if (message['reactionMessage']) { content = { messaging_product: 'whatsapp', recipient_type: 'individual', type: 'reaction', to: number.replace(/\D/g, ''), reaction: { message_id: message['reactionMessage']['key']['id'], emoji: message['reactionMessage']['text'], }, }; quoted ? (content.context = { message_id: quoted.id }) : content; return await this.post(content, 'messages'); } if (message['locationMessage']) { content = { messaging_product: 'whatsapp', recipient_type: 'individual', type: 'location', to: number.replace(/\D/g, ''), location: { longitude: message['locationMessage']['degreesLongitude'], latitude: message['locationMessage']['degreesLatitude'], name: message['locationMessage']['name'], address: message['locationMessage']['address'], }, }; quoted ? (content.context = { message_id: quoted.id }) : content; return await this.post(content, 'messages'); } if (message['contacts']) { content = { messaging_product: 'whatsapp', recipient_type: 'individual', type: 'contacts', to: number.replace(/\D/g, ''), contacts: message['contacts'], }; quoted ? (content.context = { message_id: quoted.id }) : content; message = message['message']; return await this.post(content, 'messages'); } if (message['conversation']) { content = { messaging_product: 'whatsapp', recipient_type: 'individual', type: 'text', to: number.replace(/\D/g, ''), text: { body: message['conversation'], preview_url: Boolean(options?.linkPreview), }, }; quoted ? (content.context = { message_id: quoted.id }) : content; return await this.post(content, 'messages'); } if (message['media']) { const isImage = message['mimetype']?.startsWith('image/'); content = { messaging_product: 'whatsapp', recipient_type: 'individual', type: message['mediaType'], to: number.replace(/\D/g, ''), [message['mediaType']]: { [message['type']]: message['id'], ...(message['mediaType'] !== 'audio' && message['mediaType'] !== 'video' && message['fileName'] && !isImage && { filename: message['fileName'] }), ...(message['mediaType'] !== 'audio' && message['caption'] && { caption: message['caption'] }), }, }; quoted ? (content.context = { message_id: quoted.id }) : content; return await this.post(content, 'messages'); } if (message['audio']) { content = { messaging_product: 'whatsapp', recipient_type: 'individual', type: 'audio', to: number.replace(/\D/g, ''), audio: { [message['type']]: message['id'], }, }; quoted ? (content.context = { message_id: quoted.id }) : content; return await this.post(content, 'messages'); } if (message['buttons']) { content = { messaging_product: 'whatsapp', recipient_type: 'individual', to: number.replace(/\D/g, ''), type: 'interactive', interactive: { type: 'button', body: { text: message['text'] || 'Select', }, action: { buttons: message['buttons'], }, }, }; quoted ? (content.context = { message_id: quoted.id }) : content; let formattedText = ''; for (const item of message['buttons']) { formattedText += `▶️ ${item.reply?.title}\n`; } message = { conversation: `${message['text'] || 'Select'}\n` + formattedText }; return await this.post(content, 'messages'); } if (message['listMessage']) { content = { messaging_product: 'whatsapp', recipient_type: 'individual', to: number.replace(/\D/g, ''), type: 'interactive', interactive: { type: 'list', header: { type: 'text', text: message['listMessage']['title'], }, body: { text: message['listMessage']['description'], }, footer: { text: message['listMessage']['footerText'], }, action: { button: message['listMessage']['buttonText'], sections: message['listMessage']['sections'], }, }, }; quoted ? (content.context = { message_id: quoted.id }) : content; let formattedText = ''; for (const section of message['listMessage']['sections']) { formattedText += `${section?.title}\n`; for (const row of section.rows) { formattedText += `${row?.title}\n`; } } message = { conversation: `${message['listMessage']['title']}\n` + formattedText }; return await this.post(content, 'messages'); } if (message['template']) { content = { messaging_product: 'whatsapp', recipient_type: 'individual', to: number.replace(/\D/g, ''), type: 'template', template: { name: message['template']['name'], language: { code: message['template']['language'] || 'en_US', }, components: message['template']['components'], }, }; quoted ? (content.context = { message_id: quoted.id }) : content; message = { conversation: `▶️${message['template']['name']}◀️` }; return await this.post(content, 'messages'); } })(); if (messageSent?.error_data || messageSent.message) { this.logger.error(messageSent); return messageSent; } const messageRaw: any = { key: { fromMe: true, id: messageSent?.messages[0]?.id, remoteJid: createJid(number) }, message: this.convertMessageToRaw(message, content), messageType: this.renderMessageType(content.type), messageTimestamp: (messageSent?.messages[0]?.timestamp as number) || Math.round(new Date().getTime() / 1000), instanceId: this.instanceId, webhookUrl, status: status[1], source: 'unknown', }; this.logger.log(messageRaw); this.sendDataWebhook(Events.SEND_MESSAGE, messageRaw); if (this.configService.get('CHATWOOT').ENABLED && this.localChatwoot?.enabled && !isIntegration) { this.chatwootService.eventWhatsapp( Events.SEND_MESSAGE, { instanceName: this.instance.name, instanceId: this.instanceId }, messageRaw, ); } if (this.configService.get('CHATWOOT').ENABLED && this.localChatwoot?.enabled && isIntegration) await chatbotController.emit({ instance: { instanceName: this.instance.name, instanceId: this.instanceId }, remoteJid: messageRaw.key.remoteJid, msg: messageRaw, pushName: messageRaw.pushName, }); await this.prismaRepository.message.create({ data: messageRaw, }); return messageRaw; } catch (error) { this.logger.error(error); throw new BadRequestException(error.toString()); } } // Send Message Controller public async textMessage(data: SendTextDto, isIntegration = false) { const res = await this.sendMessageWithTyping( data.number, { conversation: data.text, }, { delay: data?.delay, presence: 'composing', quoted: data?.quoted, linkPreview: data?.linkPreview, mentionsEveryOne: data?.mentionsEveryOne, mentioned: data?.mentioned, }, isIntegration, ); return res; } private async getIdMedia(mediaMessage: any, isFile = false) { try { const formData = new FormData(); if (isFile === false) { if (isURL(mediaMessage.media)) { const response = await axios.get(mediaMessage.media, { responseType: 'arraybuffer' }); const buffer = Buffer.from(response.data, 'base64'); formData.append('file', buffer, { filename: mediaMessage.fileName || 'media', contentType: mediaMessage.mimetype, }); } else { const buffer = Buffer.from(mediaMessage.media, 'base64'); formData.append('file', buffer, { filename: mediaMessage.fileName || 'media', contentType: mediaMessage.mimetype, }); } } else { formData.append('file', mediaMessage.media.buffer, { filename: mediaMessage.media.originalname, contentType: mediaMessage.media.mimetype, }); } const mimetype = mediaMessage.mimetype || mediaMessage.media.mimetype; formData.append('typeFile', mimetype); formData.append('messaging_product', 'whatsapp'); const token = this.token; const headers = { Authorization: `Bearer ${token}` }; const url = `${this.configService.get('WA_BUSINESS').URL}/${ this.configService.get('WA_BUSINESS').VERSION }/${this.number}/media`; const res = await axios.post(url, formData, { headers }); return res.data.id; } catch (error) { this.logger.error(error.response.data); throw new InternalServerErrorException(error?.toString() || error); } } protected async prepareMediaMessage(mediaMessage: MediaMessage) { try { if (mediaMessage.mediatype === 'document' && !mediaMessage.fileName) { const regex = new RegExp(/.*\/(.+?)\./); const arrayMatch = regex.exec(mediaMessage.media); mediaMessage.fileName = arrayMatch[1]; } if (mediaMessage.mediatype === 'image' && !mediaMessage.fileName) { mediaMessage.fileName = 'image.png'; } if (mediaMessage.mediatype === 'video' && !mediaMessage.fileName) { mediaMessage.fileName = 'video.mp4'; } let mimetype: string | false; const prepareMedia: any = { caption: mediaMessage?.caption, fileName: mediaMessage.fileName, mediaType: mediaMessage.mediatype, media: mediaMessage.media, gifPlayback: false, }; if (isURL(mediaMessage.media)) { mimetype = mimeTypes.lookup(mediaMessage.media); prepareMedia.id = mediaMessage.media; prepareMedia.type = 'link'; } else { mimetype = mimeTypes.lookup(mediaMessage.fileName); const id = await this.getIdMedia(prepareMedia); prepareMedia.id = id; prepareMedia.type = 'id'; } prepareMedia.mimetype = mimetype; return prepareMedia; } catch (error) { this.logger.error(error); throw new InternalServerErrorException(error?.toString() || error); } } public async mediaMessage(data: SendMediaDto, file?: any, isIntegration = false) { const mediaData: SendMediaDto = { ...data }; if (file) mediaData.media = file.buffer.toString('base64'); const message = await this.prepareMediaMessage(mediaData); const mediaSent = await this.sendMessageWithTyping( data.number, { ...message }, { delay: data?.delay, presence: 'composing', quoted: data?.quoted, linkPreview: data?.linkPreview, mentionsEveryOne: data?.mentionsEveryOne, mentioned: data?.mentioned, }, isIntegration, ); return mediaSent; } public async processAudio(audio: string, number: string, file: any) { number = number.replace(/\D/g, ''); const hash = `${number}-${new Date().getTime()}`; const audioConverterConfig = this.configService.get('AUDIO_CONVERTER'); if (audioConverterConfig.API_URL) { this.logger.verbose('Using audio converter API'); const formData = new FormData(); if (file) { formData.append('file', file.buffer, { filename: file.originalname, contentType: file.mimetype, }); } else if (isURL(audio)) { formData.append('url', audio); } else { formData.append('base64', audio); } formData.append('format', 'mp3'); const response = await axios.post(audioConverterConfig.API_URL, formData, { headers: { ...formData.getHeaders(), apikey: audioConverterConfig.API_KEY, }, }); const audioConverter = response?.data?.audio || response?.data?.url; if (!audioConverter) { throw new InternalServerErrorException('Failed to convert audio'); } const prepareMedia: any = { fileName: `${hash}.mp3`, mediaType: 'audio', media: audioConverter, mimetype: 'audio/mpeg', }; const id = await this.getIdMedia(prepareMedia); prepareMedia.id = id; prepareMedia.type = 'id'; this.logger.verbose('Audio converted'); return prepareMedia; } else { let mimetype: string | false; const prepareMedia: any = { fileName: `${hash}.mp3`, mediaType: 'audio', media: audio, }; if (isURL(audio)) { mimetype = mimeTypes.lookup(audio); prepareMedia.id = audio; prepareMedia.type = 'link'; } else if (audio && !file) { mimetype = mimeTypes.lookup(prepareMedia.fileName); const id = await this.getIdMedia(prepareMedia); prepareMedia.id = id; prepareMedia.type = 'id'; } else if (file) { prepareMedia.media = file; const id = await this.getIdMedia(prepareMedia, true); prepareMedia.id = id; prepareMedia.type = 'id'; mimetype = file.mimetype; } prepareMedia.mimetype = mimetype; return prepareMedia; } } public async audioWhatsapp(data: SendAudioDto, file?: any, isIntegration = false) { const message = await this.processAudio(data.audio, data.number, file); const audioSent = await this.sendMessageWithTyping( data.number, { ...message }, { delay: data?.delay, presence: 'composing', quoted: data?.quoted, linkPreview: data?.linkPreview, mentionsEveryOne: data?.mentionsEveryOne, mentioned: data?.mentioned, }, isIntegration, ); return audioSent; } public async buttonMessage(data: SendButtonsDto) { const embeddedMedia: any = {}; const btnItems = { text: data.buttons.map((btn) => btn.displayText), ids: data.buttons.map((btn) => btn.id), }; if (!arrayUnique(btnItems.text) || !arrayUnique(btnItems.ids)) { throw new BadRequestException('Button texts cannot be repeated', 'Button IDs cannot be repeated.'); } return await this.sendMessageWithTyping( data.number, { text: !embeddedMedia?.mediaKey ? data.title : undefined, buttons: data.buttons.map((button) => { return { type: 'reply', reply: { title: button.displayText, id: button.id, }, }; }), [embeddedMedia?.mediaKey]: embeddedMedia?.message, }, { delay: data?.delay, presence: 'composing', quoted: data?.quoted, linkPreview: data?.linkPreview, mentionsEveryOne: data?.mentionsEveryOne, mentioned: data?.mentioned, }, ); } public async locationMessage(data: SendLocationDto) { return await this.sendMessageWithTyping( data.number, { locationMessage: { degreesLatitude: data.latitude, degreesLongitude: data.longitude, name: data?.name, address: data?.address, }, }, { delay: data?.delay, presence: 'composing', quoted: data?.quoted, linkPreview: data?.linkPreview, mentionsEveryOne: data?.mentionsEveryOne, mentioned: data?.mentioned, }, ); } public async listMessage(data: SendListDto) { const sectionsItems = { title: data.sections.map((list) => list.title), }; if (!arrayUnique(sectionsItems.title)) { throw new BadRequestException('Section tiles cannot be repeated'); } const sendData: any = { listMessage: { title: data.title, description: data.description, footerText: data?.footerText, buttonText: data?.buttonText, sections: data.sections.map((section) => { return { title: section.title, rows: section.rows.map((row) => { return { title: row.title, description: row.description.substring(0, 72), id: row.rowId, }; }), }; }), }, }; return await this.sendMessageWithTyping(data.number, sendData, { delay: data?.delay, presence: 'composing', quoted: data?.quoted, linkPreview: data?.linkPreview, mentionsEveryOne: data?.mentionsEveryOne, mentioned: data?.mentioned, }); } public async templateMessage(data: SendTemplateDto, isIntegration = false) { const res = await this.sendMessageWithTyping( data.number, { template: { name: data.name, language: data.language, components: data.components, }, }, { delay: data?.delay, presence: 'composing', quoted: data?.quoted, linkPreview: data?.linkPreview, mentionsEveryOne: data?.mentionsEveryOne, mentioned: data?.mentioned, webhookUrl: data?.webhookUrl, }, isIntegration, ); return res; } public async contactMessage(data: SendContactDto) { const message: any = {}; const vcard = (contact: ContactMessage) => { let result = 'BEGIN:VCARD\n' + 'VERSION:3.0\n' + `N:${contact.fullName}\n` + `FN:${contact.fullName}\n`; if (contact.organization) { result += `ORG:${contact.organization};\n`; } if (contact.email) { result += `EMAIL:${contact.email}\n`; } if (contact.url) { result += `URL:${contact.url}\n`; } if (!contact.wuid) { contact.wuid = createJid(contact.phoneNumber); } result += `item1.TEL;waid=${contact.wuid}:${contact.phoneNumber}\n` + 'item1.X-ABLabel:Celular\n' + 'END:VCARD'; return result; }; if (data.contact.length === 1) { message.contact = { displayName: data.contact[0].fullName, vcard: vcard(data.contact[0]), }; } else { message.contactsArrayMessage = { displayName: `${data.contact.length} contacts`, contacts: data.contact.map((contact) => { return { displayName: contact.fullName, vcard: vcard(contact), }; }), }; } return await this.sendMessageWithTyping( data.number, { contacts: data.contact.map((contact) => { return { name: { formatted_name: contact.fullName, first_name: contact.fullName }, phones: [{ phone: contact.phoneNumber }], urls: [{ url: contact.url }], emails: [{ email: contact.email }], org: { company: contact.organization }, }; }), message, }, { delay: data?.delay, presence: 'composing', quoted: data?.quoted, linkPreview: data?.linkPreview, mentionsEveryOne: data?.mentionsEveryOne, mentioned: data?.mentioned, }, ); } public async reactionMessage(data: SendReactionDto) { return await this.sendMessageWithTyping(data.key.remoteJid, { reactionMessage: { key: data.key, text: data.reaction, }, }); } public async getBase64FromMediaMessage(data: any) { try { const msg = data.message; const messageType = msg.messageType.includes('Message') ? msg.messageType : msg.messageType + 'Message'; const mediaMessage = msg.message[messageType]; if (!msg.message?.base64) { const buffer = await this.downloadMediaMessage({ type: messageType, ...msg.message }); msg.message.base64 = buffer.toString('base64'); } return { mediaType: msg.messageType, fileName: mediaMessage?.fileName || mediaMessage?.filename, caption: mediaMessage?.caption, size: { fileLength: mediaMessage?.fileLength, height: mediaMessage?.fileLength, width: mediaMessage?.width, }, mimetype: mediaMessage?.mime_type, base64: msg.message.base64, }; } catch (error) { this.logger.error(error); throw new BadRequestException(error.toString()); } } public async deleteMessage() { throw new BadRequestException('Method not available on WhatsApp Business API'); } // methods not available on WhatsApp Business API public async mediaSticker() { throw new BadRequestException('Method not available on WhatsApp Business API'); } public async pollMessage() { throw new BadRequestException('Method not available on WhatsApp Business API'); } public async statusMessage() { throw new BadRequestException('Method not available on WhatsApp Business API'); } public async reloadConnection() { throw new BadRequestException('Method not available on WhatsApp Business API'); } public async whatsappNumber() { throw new BadRequestException('Method not available on WhatsApp Business API'); } public async markMessageAsRead() { throw new BadRequestException('Method not available on WhatsApp Business API'); } public async archiveChat() { throw new BadRequestException('Method not available on WhatsApp Business API'); } public async markChatUnread() { throw new BadRequestException('Method not available on WhatsApp Business API'); } public async fetchProfile() { throw new BadRequestException('Method not available on WhatsApp Business API'); } public async offerCall() { throw new BadRequestException('Method not available on WhatsApp Business API'); } public async sendPresence() { throw new BadRequestException('Method not available on WhatsApp Business API'); } public async setPresence() { throw new BadRequestException('Method not available on WhatsApp Business API'); } public async fetchPrivacySettings() { throw new BadRequestException('Method not available on WhatsApp Business API'); } public async updatePrivacySettings() { throw new BadRequestException('Method not available on WhatsApp Business API'); } public async fetchBusinessProfile() { throw new BadRequestException('Method not available on WhatsApp Business API'); } public async updateProfileName() { throw new BadRequestException('Method not available on WhatsApp Business API'); } public async updateProfileStatus() { throw new BadRequestException('Method not available on WhatsApp Business API'); } public async updateProfilePicture() { throw new BadRequestException('Method not available on WhatsApp Business API'); } public async removeProfilePicture() { throw new BadRequestException('Method not available on WhatsApp Business API'); } public async blockUser() { throw new BadRequestException('Method not available on WhatsApp Business API'); } public async updateMessage() { throw new BadRequestException('Method not available on WhatsApp Business API'); } public async createGroup() { throw new BadRequestException('Method not available on WhatsApp Business API'); } public async updateGroupPicture() { throw new BadRequestException('Method not available on WhatsApp Business API'); } public async updateGroupSubject() { throw new BadRequestException('Method not available on WhatsApp Business API'); } public async updateGroupDescription() { throw new BadRequestException('Method not available on WhatsApp Business API'); } public async findGroup() { throw new BadRequestException('Method not available on WhatsApp Business API'); } public async fetchAllGroups() { throw new BadRequestException('Method not available on WhatsApp Business API'); } public async inviteCode() { throw new BadRequestException('Method not available on WhatsApp Business API'); } public async inviteInfo() { throw new BadRequestException('Method not available on WhatsApp Business API'); } public async sendInvite() { throw new BadRequestException('Method not available on WhatsApp Business API'); } public async acceptInviteCode() { throw new BadRequestException('Method not available on WhatsApp Business API'); } public async revokeInviteCode() { throw new BadRequestException('Method not available on WhatsApp Business API'); } public async findParticipants() { throw new BadRequestException('Method not available on WhatsApp Business API'); } public async updateGParticipant() { throw new BadRequestException('Method not available on WhatsApp Business API'); } public async updateGSetting() { throw new BadRequestException('Method not available on WhatsApp Business API'); } public async toggleEphemeral() { throw new BadRequestException('Method not available on WhatsApp Business API'); } public async leaveGroup() { throw new BadRequestException('Method not available on WhatsApp Business API'); } public async fetchLabels() { throw new BadRequestException('Method not available on WhatsApp Business API'); } public async handleLabel() { throw new BadRequestException('Method not available on WhatsApp Business API'); } public async receiveMobileCode() { throw new BadRequestException('Method not available on WhatsApp Business API'); } public async fakeCall() { throw new BadRequestException('Method not available on WhatsApp Business API'); } } ================================================ FILE: src/api/integrations/channel/whatsapp/baileys.controller.ts ================================================ import { InstanceDto } from '@api/dto/instance.dto'; import { WAMonitoringService } from '@api/services/monitor.service'; export class BaileysController { constructor(private readonly waMonitor: WAMonitoringService) {} public async onWhatsapp({ instanceName }: InstanceDto, body: any) { const instance = this.waMonitor.waInstances[instanceName]; return instance.baileysOnWhatsapp(body?.jid); } public async profilePictureUrl({ instanceName }: InstanceDto, body: any) { const instance = this.waMonitor.waInstances[instanceName]; return instance.baileysProfilePictureUrl(body?.jid, body?.type, body?.timeoutMs); } public async assertSessions({ instanceName }: InstanceDto, body: any) { const instance = this.waMonitor.waInstances[instanceName]; return instance.baileysAssertSessions(body?.jids, body?.force); } public async createParticipantNodes({ instanceName }: InstanceDto, body: any) { const instance = this.waMonitor.waInstances[instanceName]; return instance.baileysCreateParticipantNodes(body?.jids, body?.message, body?.extraAttrs); } public async getUSyncDevices({ instanceName }: InstanceDto, body: any) { const instance = this.waMonitor.waInstances[instanceName]; return instance.baileysGetUSyncDevices(body?.jids, body?.useCache, body?.ignoreZeroDevices); } public async generateMessageTag({ instanceName }: InstanceDto) { const instance = this.waMonitor.waInstances[instanceName]; return instance.baileysGenerateMessageTag(); } public async sendNode({ instanceName }: InstanceDto, body: any) { const instance = this.waMonitor.waInstances[instanceName]; return instance.baileysSendNode(body?.stanza); } public async signalRepositoryDecryptMessage({ instanceName }: InstanceDto, body: any) { const instance = this.waMonitor.waInstances[instanceName]; return instance.baileysSignalRepositoryDecryptMessage(body?.jid, body?.type, body?.ciphertext); } public async getAuthState({ instanceName }: InstanceDto) { const instance = this.waMonitor.waInstances[instanceName]; return instance.baileysGetAuthState(); } } ================================================ FILE: src/api/integrations/channel/whatsapp/baileys.router.ts ================================================ import { RouterBroker } from '@api/abstract/abstract.router'; import { InstanceDto } from '@api/dto/instance.dto'; import { HttpStatus } from '@api/routes/index.router'; import { baileysController } from '@api/server.module'; import { instanceSchema } from '@validate/instance.schema'; import { RequestHandler, Router } from 'express'; export class BaileysRouter extends RouterBroker { constructor(...guards: RequestHandler[]) { super(); this.router .post(this.routerPath('onWhatsapp'), ...guards, async (req, res) => { const response = await this.dataValidate({ request: req, schema: instanceSchema, ClassRef: InstanceDto, execute: (instance) => baileysController.onWhatsapp(instance, req.body), }); res.status(HttpStatus.OK).json(response); }) .post(this.routerPath('profilePictureUrl'), ...guards, async (req, res) => { const response = await this.dataValidate({ request: req, schema: instanceSchema, ClassRef: InstanceDto, execute: (instance) => baileysController.profilePictureUrl(instance, req.body), }); res.status(HttpStatus.OK).json(response); }) .post(this.routerPath('assertSessions'), ...guards, async (req, res) => { const response = await this.dataValidate({ request: req, schema: instanceSchema, ClassRef: InstanceDto, execute: (instance) => baileysController.assertSessions(instance, req.body), }); res.status(HttpStatus.OK).json(response); }) .post(this.routerPath('createParticipantNodes'), ...guards, async (req, res) => { const response = await this.dataValidate({ request: req, schema: instanceSchema, ClassRef: InstanceDto, execute: (instance) => baileysController.createParticipantNodes(instance, req.body), }); res.status(HttpStatus.OK).json(response); }) .post(this.routerPath('getUSyncDevices'), ...guards, async (req, res) => { const response = await this.dataValidate({ request: req, schema: instanceSchema, ClassRef: InstanceDto, execute: (instance) => baileysController.getUSyncDevices(instance, req.body), }); res.status(HttpStatus.OK).json(response); }) .post(this.routerPath('generateMessageTag'), ...guards, async (req, res) => { const response = await this.dataValidate({ request: req, schema: instanceSchema, ClassRef: InstanceDto, execute: (instance) => baileysController.generateMessageTag(instance), }); res.status(HttpStatus.OK).json(response); }) .post(this.routerPath('sendNode'), ...guards, async (req, res) => { const response = await this.dataValidate({ request: req, schema: instanceSchema, ClassRef: InstanceDto, execute: (instance) => baileysController.sendNode(instance, req.body), }); res.status(HttpStatus.OK).json(response); }) .post(this.routerPath('signalRepositoryDecryptMessage'), ...guards, async (req, res) => { const response = await this.dataValidate({ request: req, schema: instanceSchema, ClassRef: InstanceDto, execute: (instance) => baileysController.signalRepositoryDecryptMessage(instance, req.body), }); res.status(HttpStatus.OK).json(response); }) .post(this.routerPath('getAuthState'), ...guards, async (req, res) => { const response = await this.dataValidate({ request: req, schema: instanceSchema, ClassRef: InstanceDto, execute: (instance) => baileysController.getAuthState(instance), }); res.status(HttpStatus.OK).json(response); }); } public readonly router: Router = Router(); } ================================================ FILE: src/api/integrations/channel/whatsapp/baileysMessage.processor.ts ================================================ import { Logger } from '@config/logger.config'; import { BaileysEventMap, MessageUpsertType, WAMessage } from 'baileys'; import { catchError, concatMap, delay, EMPTY, from, retryWhen, Subject, Subscription, take, tap } from 'rxjs'; type MessageUpsertPayload = BaileysEventMap['messages.upsert']; type MountProps = { onMessageReceive: (payload: MessageUpsertPayload, settings: any) => Promise; }; export class BaileysMessageProcessor { private processorLogs = new Logger('BaileysMessageProcessor'); private subscription?: Subscription; protected messageSubject = new Subject<{ messages: WAMessage[]; type: MessageUpsertType; requestId?: string; settings: any; }>(); mount({ onMessageReceive }: MountProps) { // Se já existe subscription, fazer cleanup primeiro if (this.subscription && !this.subscription.closed) { this.subscription.unsubscribe(); } // Se o Subject foi completado, recriar if (this.messageSubject.closed) { this.processorLogs.warn('MessageSubject was closed, recreating...'); this.messageSubject = new Subject<{ messages: WAMessage[]; type: MessageUpsertType; requestId?: string; settings: any; }>(); } this.subscription = this.messageSubject .pipe( tap(({ messages }) => { this.processorLogs.log(`Processing batch of ${messages.length} messages`); }), concatMap(({ messages, type, requestId, settings }) => from(onMessageReceive({ messages, type, requestId }, settings)).pipe( retryWhen((errors) => errors.pipe( tap((error) => this.processorLogs.warn(`Retrying message batch due to error: ${error.message}`)), delay(1000), // 1 segundo de delay take(3), // Máximo 3 tentativas ), ), ), ), catchError((error) => { this.processorLogs.error(`Error processing message batch: ${error}`); return EMPTY; }), ) .subscribe({ error: (error) => { this.processorLogs.error(`Message stream error: ${error}`); }, }); } processMessage(payload: MessageUpsertPayload, settings: any) { const { messages, type, requestId } = payload; this.messageSubject.next({ messages, type, requestId, settings }); } onDestroy() { this.subscription?.unsubscribe(); this.messageSubject.complete(); } } ================================================ FILE: src/api/integrations/channel/whatsapp/voiceCalls/transport.type.ts ================================================ import { BinaryNode, Contact, JidWithDevice, proto, WAConnectionState } from 'baileys'; export interface ServerToClientEvents { withAck: (d: string, callback: (e: number) => void) => void; onWhatsApp: onWhatsAppType; profilePictureUrl: ProfilePictureUrlType; assertSessions: AssertSessionsType; createParticipantNodes: CreateParticipantNodesType; getUSyncDevices: GetUSyncDevicesType; generateMessageTag: GenerateMessageTagType; sendNode: SendNodeType; 'signalRepository:decryptMessage': SignalRepositoryDecryptMessageType; } export interface ClientToServerEvents { init: ( me: Contact | undefined, account: proto.IADVSignedDeviceIdentity | undefined, status: WAConnectionState, ) => void; 'CB:call': (packet: any) => void; 'CB:ack,class:call': (packet: any) => void; 'connection.update:status': ( me: Contact | undefined, account: proto.IADVSignedDeviceIdentity | undefined, status: WAConnectionState, ) => void; 'connection.update:qr': (qr: string) => void; } export type onWhatsAppType = (jid: string, callback: onWhatsAppCallback) => void; export type onWhatsAppCallback = ( response: { exists: boolean; jid: string; }[], ) => void; export type ProfilePictureUrlType = ( jid: string, type: 'image' | 'preview', timeoutMs: number | undefined, callback: ProfilePictureUrlCallback, ) => void; export type ProfilePictureUrlCallback = (response: string | undefined) => void; export type AssertSessionsType = (jids: string[], force: boolean, callback: AssertSessionsCallback) => void; export type AssertSessionsCallback = (response: boolean) => void; export type CreateParticipantNodesType = ( jids: string[], message: any, extraAttrs: any, callback: CreateParticipantNodesCallback, ) => void; export type CreateParticipantNodesCallback = (nodes: any, shouldIncludeDeviceIdentity: boolean) => void; export type GetUSyncDevicesType = ( jids: string[], useCache: boolean, ignoreZeroDevices: boolean, callback: GetUSyncDevicesTypeCallback, ) => void; export type GetUSyncDevicesTypeCallback = (jids: JidWithDevice[]) => void; export type GenerateMessageTagType = (callback: GenerateMessageTagTypeCallback) => void; export type GenerateMessageTagTypeCallback = (response: string) => void; export type SendNodeType = (stanza: BinaryNode, callback: SendNodeTypeCallback) => void; export type SendNodeTypeCallback = (response: boolean) => void; export type SignalRepositoryDecryptMessageType = ( jid: string, type: 'pkmsg' | 'msg', ciphertext: Buffer, callback: SignalRepositoryDecryptMessageCallback, ) => void; export type SignalRepositoryDecryptMessageCallback = (response: any) => void; ================================================ FILE: src/api/integrations/channel/whatsapp/voiceCalls/useVoiceCallsBaileys.ts ================================================ import { ConnectionState, WAConnectionState, WASocket } from 'baileys'; import { io, Socket } from 'socket.io-client'; import { ClientToServerEvents, ServerToClientEvents } from './transport.type'; let baileys_connection_state: WAConnectionState = 'close'; export const useVoiceCallsBaileys = async ( wavoip_token: string, baileys_sock: WASocket, status?: WAConnectionState, logger?: boolean, ) => { baileys_connection_state = status ?? 'close'; const socket: Socket = io('https://devices.wavoip.com/baileys', { transports: ['websocket'], path: `/${wavoip_token}/websocket`, }); socket.on('connect', () => { if (logger) console.log('[*] - Wavoip connected', socket.id); socket.emit( 'init', baileys_sock.authState.creds.me, baileys_sock.authState.creds.account, baileys_connection_state, ); }); socket.on('disconnect', () => { if (logger) console.log('[*] - Wavoip disconnect'); }); socket.on('connect_error', (error) => { if (socket.active) { if (logger) console.log( '[*] - Wavoip connection error temporary failure, the socket will automatically try to reconnect', error, ); } else { if (logger) console.log('[*] - Wavoip connection error', error.message); } }); socket.on('onWhatsApp', async (jid, callback) => { try { const response: any = await baileys_sock.onWhatsApp(jid); callback(response); if (logger) console.log('[*] Success on call onWhatsApp function', response, jid); } catch (error) { if (logger) console.error('[*] Error on call onWhatsApp function', error); } }); socket.on('profilePictureUrl', async (jid, type, timeoutMs, callback) => { try { const response = await baileys_sock.profilePictureUrl(jid, type, timeoutMs); callback(response); if (logger) console.log('[*] Success on call profilePictureUrl function', response); } catch (error) { if (logger) console.error('[*] Error on call profilePictureUrl function', error); } }); socket.on('assertSessions', async (jids, force, callback) => { try { const response = await baileys_sock.assertSessions(jids); callback(response); if (logger) console.log('[*] Success on call assertSessions function', response); } catch (error) { if (logger) console.error('[*] Error on call assertSessions function', error); } }); socket.on('createParticipantNodes', async (jids, message, extraAttrs, callback) => { try { const response = await baileys_sock.createParticipantNodes(jids, message, extraAttrs); callback(response, true); if (logger) console.log('[*] Success on call createParticipantNodes function', response); } catch (error) { if (logger) console.error('[*] Error on call createParticipantNodes function', error); } }); socket.on('getUSyncDevices', async (jids, useCache, ignoreZeroDevices, callback) => { try { const response = await baileys_sock.getUSyncDevices(jids, useCache, ignoreZeroDevices); callback(response); if (logger) console.log('[*] Success on call getUSyncDevices function', response); } catch (error) { if (logger) console.error('[*] Error on call getUSyncDevices function', error); } }); socket.on('generateMessageTag', async (callback) => { try { const response = await baileys_sock.generateMessageTag(); callback(response); if (logger) console.log('[*] Success on call generateMessageTag function', response); } catch (error) { if (logger) console.error('[*] Error on call generateMessageTag function', error); } }); socket.on('sendNode', async (stanza, callback) => { try { console.log('sendNode', JSON.stringify(stanza)); const response = await baileys_sock.sendNode(stanza); callback(true); if (logger) console.log('[*] Success on call sendNode function', response); } catch (error) { if (logger) console.error('[*] Error on call sendNode function', error); } }); socket.on('signalRepository:decryptMessage', async (jid, type, ciphertext, callback) => { try { const response = await baileys_sock.signalRepository.decryptMessage({ jid: jid, type: type, ciphertext: ciphertext, }); callback(response); if (logger) console.log('[*] Success on call signalRepository:decryptMessage function', response); } catch (error) { if (logger) console.error('[*] Error on call signalRepository:decryptMessage function', error); } }); // we only use this connection data to inform the webphone that the device is connected and creeds account to generate e2e whatsapp key for make call packets baileys_sock.ev.on('connection.update', (update: Partial) => { const { connection } = update; if (connection) { baileys_connection_state = connection; socket .timeout(1000) .emit( 'connection.update:status', baileys_sock.authState.creds.me, baileys_sock.authState.creds.account, connection, ); } if (update.qr) { socket.timeout(1000).emit('connection.update:qr', update.qr); } }); baileys_sock.ws.on('CB:call', (packet) => { if (logger) console.log('[*] Signling received'); socket.volatile.timeout(1000).emit('CB:call', packet); }); baileys_sock.ws.on('CB:ack,class:call', (packet) => { if (logger) console.log('[*] Signling ack received'); socket.volatile.timeout(1000).emit('CB:ack,class:call', packet); }); return socket; }; ================================================ FILE: src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts ================================================ import { getCollectionsDto } from '@api/dto/business.dto'; import { OfferCallDto } from '@api/dto/call.dto'; import { ArchiveChatDto, BlockUserDto, DeleteMessage, getBase64FromMediaMessageDto, LastMessage, MarkChatUnreadDto, NumberBusiness, OnWhatsAppDto, PrivacySettingDto, ReadMessageDto, SendPresenceDto, UpdateMessageDto, WhatsAppNumberDto, } from '@api/dto/chat.dto'; import { AcceptGroupInvite, CreateGroupDto, GetParticipant, GroupDescriptionDto, GroupInvite, GroupJid, GroupPictureDto, GroupSendInvite, GroupSubjectDto, GroupToggleEphemeralDto, GroupUpdateParticipantDto, GroupUpdateSettingDto, } from '@api/dto/group.dto'; import { InstanceDto, SetPresenceDto } from '@api/dto/instance.dto'; import { HandleLabelDto, LabelDto } from '@api/dto/label.dto'; import { Button, ContactMessage, KeyType, MediaMessage, Options, SendAudioDto, SendButtonsDto, SendContactDto, SendListDto, SendLocationDto, SendMediaDto, SendPollDto, SendPtvDto, SendReactionDto, SendStatusDto, SendStickerDto, SendTextDto, StatusMessage, TypeButton, } from '@api/dto/sendMessage.dto'; import { chatwootImport } from '@api/integrations/chatbot/chatwoot/utils/chatwoot-import-helper'; import * as s3Service from '@api/integrations/storage/s3/libs/minio.server'; import { ProviderFiles } from '@api/provider/sessions'; import { PrismaRepository, Query } from '@api/repository/repository.service'; import { chatbotController, waMonitor } from '@api/server.module'; import { CacheService } from '@api/services/cache.service'; import { ChannelStartupService } from '@api/services/channel.service'; import { Events, MessageSubtype, TypeMediaMessage, wa } from '@api/types/wa.types'; import { CacheEngine } from '@cache/cacheengine'; import { AudioConverter, CacheConf, Chatwoot, ConfigService, configService, ConfigSessionPhone, Database, Log, Openai, ProviderSession, QrCode, S3, } from '@config/env.config'; import { BadRequestException, InternalServerErrorException, NotFoundException } from '@exceptions'; import ffmpegPath from '@ffmpeg-installer/ffmpeg'; import { Boom } from '@hapi/boom'; import { createId as cuid } from '@paralleldrive/cuid2'; import { Instance, Message } from '@prisma/client'; import { createJid } from '@utils/createJid'; import { fetchLatestWaWebVersion } from '@utils/fetchLatestWaWebVersion'; import { makeProxyAgent, makeProxyAgentUndici } from '@utils/makeProxyAgent'; import { getOnWhatsappCache, saveOnWhatsappCache } from '@utils/onWhatsappCache'; import { status } from '@utils/renderStatus'; import { sendTelemetry } from '@utils/sendTelemetry'; import useMultiFileAuthStatePrisma from '@utils/use-multi-file-auth-state-prisma'; import { AuthStateProvider } from '@utils/use-multi-file-auth-state-provider-files'; import { useMultiFileAuthStateRedisDb } from '@utils/use-multi-file-auth-state-redis-db'; import axios from 'axios'; import makeWASocket, { AnyMessageContent, BufferedEventData, BufferJSON, CacheStore, CatalogCollection, Chat, ConnectionState, Contact, decryptPollVote, delay, DisconnectReason, downloadContentFromMessage, downloadMediaMessage, generateWAMessageFromContent, getAggregateVotesInPollMessage, GetCatalogOptions, getContentType, getDevice, GroupMetadata, isJidBroadcast, isJidGroup, isJidNewsletter, isPnUser, jidNormalizedUser, makeCacheableSignalKeyStore, MessageUpsertType, MessageUserReceiptUpdate, MiscMessageGenerationOptions, ParticipantAction, prepareWAMessageMedia, Product, proto, UserFacingSocketConfig, WABrowserDescription, WAMediaUpload, WAMessage, WAMessageKey, WAPresence, WASocket, } from 'baileys'; import { Label } from 'baileys/lib/Types/Label'; import { LabelAssociation } from 'baileys/lib/Types/LabelAssociation'; import { spawn } from 'child_process'; import { isArray, isBase64, isURL } from 'class-validator'; import { createHash } from 'crypto'; import EventEmitter2 from 'eventemitter2'; import ffmpeg from 'fluent-ffmpeg'; import FormData from 'form-data'; import Long from 'long'; import mimeTypes from 'mime-types'; import NodeCache from 'node-cache'; import cron from 'node-cron'; import { release } from 'os'; import { join } from 'path'; import P from 'pino'; import qrcode, { QRCodeToDataURLOptions } from 'qrcode'; import qrcodeTerminal from 'qrcode-terminal'; import sharp from 'sharp'; import { PassThrough, Readable } from 'stream'; import { v4 } from 'uuid'; import { BaileysMessageProcessor } from './baileysMessage.processor'; import { useVoiceCallsBaileys } from './voiceCalls/useVoiceCallsBaileys'; export interface ExtendedIMessageKey extends proto.IMessageKey { remoteJidAlt?: string; participantAlt?: string; server_id?: string; isViewOnce?: boolean; } const groupMetadataCache = new CacheService(new CacheEngine(configService, 'groups').getEngine()); // Adicione a função getVideoDuration no início do arquivo async function getVideoDuration(input: Buffer | string | Readable): Promise { const MediaInfoFactory = (await import('mediainfo.js')).default; const mediainfo = await MediaInfoFactory({ format: 'JSON' }); let fileSize: number; let readChunk: (size: number, offset: number) => Promise; if (Buffer.isBuffer(input)) { fileSize = input.length; readChunk = async (size: number, offset: number): Promise => { return input.slice(offset, offset + size); }; } else if (typeof input === 'string') { const fs = await import('fs'); const stat = await fs.promises.stat(input); fileSize = stat.size; const fd = await fs.promises.open(input, 'r'); readChunk = async (size: number, offset: number): Promise => { const buffer = Buffer.alloc(size); await fd.read(buffer, 0, size, offset); return buffer; }; try { const result = await mediainfo.analyzeData(() => fileSize, readChunk); const jsonResult = JSON.parse(result); const generalTrack = jsonResult.media.track.find((t: any) => t['@type'] === 'General'); const duration = generalTrack.Duration; return Math.round(parseFloat(duration)); } finally { await fd.close(); } } else if (input instanceof Readable) { const chunks: Buffer[] = []; for await (const chunk of input) { chunks.push(chunk); } const data = Buffer.concat(chunks); fileSize = data.length; readChunk = async (size: number, offset: number): Promise => { return data.slice(offset, offset + size); }; } else { throw new Error('Tipo de entrada não suportado'); } const result = await mediainfo.analyzeData(() => fileSize, readChunk); const jsonResult = JSON.parse(result); const generalTrack = jsonResult.media.track.find((t: any) => t['@type'] === 'General'); const duration = generalTrack.Duration; return Math.round(parseFloat(duration)); } export class BaileysStartupService extends ChannelStartupService { private messageProcessor = new BaileysMessageProcessor(); constructor( public readonly configService: ConfigService, public readonly eventEmitter: EventEmitter2, public readonly prismaRepository: PrismaRepository, public readonly cache: CacheService, public readonly chatwootCache: CacheService, public readonly baileysCache: CacheService, private readonly providerFiles: ProviderFiles, ) { super(configService, eventEmitter, prismaRepository, chatwootCache); this.instance.qrcode = { count: 0 }; this.messageProcessor.mount({ onMessageReceive: this.messageHandle['messages.upsert'].bind(this), // Bind the method to the current context }); this.authStateProvider = new AuthStateProvider(this.providerFiles); } private authStateProvider: AuthStateProvider; private readonly msgRetryCounterCache: CacheStore = new NodeCache(); private readonly userDevicesCache: CacheStore = new NodeCache({ stdTTL: 300000, useClones: false }); private endSession = false; private logBaileys = this.configService.get('LOG').BAILEYS; private eventProcessingQueue: Promise = Promise.resolve(); // Cache TTL constants (in seconds) private readonly MESSAGE_CACHE_TTL_SECONDS = 5 * 60; // 5 minutes - avoid duplicate message processing private readonly UPDATE_CACHE_TTL_SECONDS = 30 * 60; // 30 minutes - avoid duplicate status updates public stateConnection: wa.StateConnection = { state: 'close' }; public phoneNumber: string; public get connectionStatus() { return this.stateConnection; } public async logoutInstance() { this.messageProcessor.onDestroy(); await this.client?.logout('Log out instance: ' + this.instanceName); this.client?.ws?.close(); const db = this.configService.get('DATABASE'); const cache = this.configService.get('CACHE'); const provider = this.configService.get('PROVIDER'); if (provider?.ENABLED) { const authState = await this.authStateProvider.authStateProvider(this.instance.id); await authState.removeCreds(); } if (cache?.REDIS.ENABLED && cache?.REDIS.SAVE_INSTANCES) { const authState = await useMultiFileAuthStateRedisDb(this.instance.id, this.cache); await authState.removeCreds(); } if (db.SAVE_DATA.INSTANCE) { const authState = await useMultiFileAuthStatePrisma(this.instance.id, this.cache); await authState.removeCreds(); } const sessionExists = await this.prismaRepository.session.findFirst({ where: { sessionId: this.instanceId } }); if (sessionExists) { await this.prismaRepository.session.delete({ where: { sessionId: this.instanceId } }); } } public async getProfileName() { let profileName = this.client.user?.name ?? this.client.user?.verifiedName; if (!profileName) { const data = await this.prismaRepository.session.findUnique({ where: { sessionId: this.instanceId } }); if (data) { const creds = JSON.parse(JSON.stringify(data.creds), BufferJSON.reviver); profileName = creds.me?.name || creds.me?.verifiedName; } } return profileName; } public async getProfileStatus() { const status = await this.client.fetchStatus(this.instance.wuid); return status[0]?.status; } public get profilePictureUrl() { return this.instance.profilePictureUrl; } public get qrCode(): wa.QrCode { return { pairingCode: this.instance.qrcode?.pairingCode, code: this.instance.qrcode?.code, base64: this.instance.qrcode?.base64, count: this.instance.qrcode?.count, }; } private async connectionUpdate({ qr, connection, lastDisconnect }: Partial) { if (qr) { if (this.instance.qrcode.count === this.configService.get('QRCODE').LIMIT) { this.sendDataWebhook(Events.QRCODE_UPDATED, { message: 'QR code limit reached, please login again', statusCode: DisconnectReason.badSession, }); if (this.configService.get('CHATWOOT').ENABLED && this.localChatwoot?.enabled) { this.chatwootService.eventWhatsapp( Events.QRCODE_UPDATED, { instanceName: this.instance.name, instanceId: this.instanceId }, { message: 'QR code limit reached, please login again', statusCode: DisconnectReason.badSession }, ); } this.sendDataWebhook(Events.CONNECTION_UPDATE, { instance: this.instance.name, state: 'refused', statusReason: DisconnectReason.connectionClosed, wuid: this.instance.wuid, profileName: await this.getProfileName(), profilePictureUrl: this.instance.profilePictureUrl, }); this.endSession = true; return this.eventEmitter.emit('no.connection', this.instance.name); } this.instance.qrcode.count++; const color = this.configService.get('QRCODE').COLOR; const optsQrcode: QRCodeToDataURLOptions = { margin: 3, scale: 4, errorCorrectionLevel: 'H', color: { light: '#ffffff', dark: color }, }; if (this.phoneNumber) { await delay(1000); this.instance.qrcode.pairingCode = await this.client.requestPairingCode(this.phoneNumber); } else { this.instance.qrcode.pairingCode = null; } qrcode.toDataURL(qr, optsQrcode, (error, base64) => { if (error) { this.logger.error('Qrcode generate failed:' + error.toString()); return; } this.instance.qrcode.base64 = base64; this.instance.qrcode.code = qr; this.sendDataWebhook(Events.QRCODE_UPDATED, { qrcode: { instance: this.instance.name, pairingCode: this.instance.qrcode.pairingCode, code: qr, base64 }, }); if (this.configService.get('CHATWOOT').ENABLED && this.localChatwoot?.enabled) { this.chatwootService.eventWhatsapp( Events.QRCODE_UPDATED, { instanceName: this.instance.name, instanceId: this.instanceId }, { qrcode: { instance: this.instance.name, pairingCode: this.instance.qrcode.pairingCode, code: qr, base64 }, }, ); } }); qrcodeTerminal.generate(qr, { small: true }, (qrcode) => this.logger.log( `\n{ instance: ${this.instance.name} pairingCode: ${this.instance.qrcode.pairingCode}, qrcodeCount: ${this.instance.qrcode.count} }\n` + qrcode, ), ); await this.prismaRepository.instance.update({ where: { id: this.instanceId }, data: { connectionStatus: 'connecting' }, }); } if (connection) { this.stateConnection = { state: connection, statusReason: (lastDisconnect?.error as Boom)?.output?.statusCode ?? 200, }; } if (connection === 'close') { const statusCode = (lastDisconnect?.error as Boom)?.output?.statusCode; const codesToNotReconnect = [DisconnectReason.loggedOut, DisconnectReason.forbidden, 402, 406]; const shouldReconnect = !codesToNotReconnect.includes(statusCode); if (shouldReconnect) { await this.connectToWhatsapp(this.phoneNumber); } else { this.sendDataWebhook(Events.STATUS_INSTANCE, { instance: this.instance.name, status: 'closed', disconnectionAt: new Date(), disconnectionReasonCode: statusCode, disconnectionObject: JSON.stringify(lastDisconnect), }); await this.prismaRepository.instance.update({ where: { id: this.instanceId }, data: { connectionStatus: 'close', disconnectionAt: new Date(), disconnectionReasonCode: statusCode, disconnectionObject: JSON.stringify(lastDisconnect), }, }); if (this.configService.get('CHATWOOT').ENABLED && this.localChatwoot?.enabled) { this.chatwootService.eventWhatsapp( Events.STATUS_INSTANCE, { instanceName: this.instance.name, instanceId: this.instanceId }, { instance: this.instance.name, status: 'closed' }, ); } this.eventEmitter.emit('logout.instance', this.instance.name, 'inner'); this.client?.ws?.close(); this.client.end(new Error('Close connection')); this.sendDataWebhook(Events.CONNECTION_UPDATE, { instance: this.instance.name, ...this.stateConnection }); } } if (connection === 'open') { this.instance.wuid = this.client.user.id.replace(/:\d+/, ''); try { const profilePic = await this.profilePicture(this.instance.wuid); this.instance.profilePictureUrl = profilePic.profilePictureUrl; } catch { this.instance.profilePictureUrl = null; } const formattedWuid = this.instance.wuid.split('@')[0].padEnd(30, ' '); const formattedName = this.instance.name; this.logger.info( ` ┌──────────────────────────────┐ │ CONNECTED TO WHATSAPP │ └──────────────────────────────┘`.replace(/^ +/gm, ' '), ); this.logger.info( ` wuid: ${formattedWuid} name: ${formattedName} `, ); await this.prismaRepository.instance.update({ where: { id: this.instanceId }, data: { ownerJid: this.instance.wuid, profileName: (await this.getProfileName()) as string, profilePicUrl: this.instance.profilePictureUrl, connectionStatus: 'open', }, }); if (this.configService.get('CHATWOOT').ENABLED && this.localChatwoot?.enabled) { this.chatwootService.eventWhatsapp( Events.CONNECTION_UPDATE, { instanceName: this.instance.name, instanceId: this.instanceId }, { instance: this.instance.name, status: 'open' }, ); this.syncChatwootLostMessages(); } this.sendDataWebhook(Events.CONNECTION_UPDATE, { instance: this.instance.name, wuid: this.instance.wuid, profileName: await this.getProfileName(), profilePictureUrl: this.instance.profilePictureUrl, ...this.stateConnection, }); } if (connection === 'connecting') { this.sendDataWebhook(Events.CONNECTION_UPDATE, { instance: this.instance.name, ...this.stateConnection }); } } private async getMessage(key: proto.IMessageKey, full = false) { try { // Use raw SQL to avoid JSON path issues const webMessageInfo = (await this.prismaRepository.$queryRaw` SELECT * FROM "Message" WHERE "instanceId" = ${this.instanceId} AND "key"->>'id' = ${key.id} `) as proto.IWebMessageInfo[]; if (full) { return webMessageInfo[0]; } if (webMessageInfo[0].message?.pollCreationMessage) { const messageSecretBase64 = webMessageInfo[0].message?.messageContextInfo?.messageSecret; if (typeof messageSecretBase64 === 'string') { const messageSecret = Buffer.from(messageSecretBase64, 'base64'); const msg = { messageContextInfo: { messageSecret }, pollCreationMessage: webMessageInfo[0].message?.pollCreationMessage, }; return msg; } } return webMessageInfo[0].message; } catch { return { conversation: '' }; } } private async defineAuthState() { const db = this.configService.get('DATABASE'); const cache = this.configService.get('CACHE'); const provider = this.configService.get('PROVIDER'); if (provider?.ENABLED) { return await this.authStateProvider.authStateProvider(this.instance.id); } if (cache?.REDIS.ENABLED && cache?.REDIS.SAVE_INSTANCES) { this.logger.info('Redis enabled'); return await useMultiFileAuthStateRedisDb(this.instance.id, this.cache); } if (db.SAVE_DATA.INSTANCE) { return await useMultiFileAuthStatePrisma(this.instance.id, this.cache); } } private async createClient(number?: string): Promise { this.instance.authState = await this.defineAuthState(); const session = this.configService.get('CONFIG_SESSION_PHONE'); let browserOptions = {}; if (number || this.phoneNumber) { this.phoneNumber = number; this.logger.info(`Phone number: ${number}`); } else { const browser: WABrowserDescription = [session.CLIENT, session.NAME, release()]; browserOptions = { browser }; this.logger.info(`Browser: ${browser}`); } const baileysVersion = await fetchLatestWaWebVersion({}); const version = baileysVersion.version; const log = `Baileys version: ${version.join('.')}`; this.logger.info(log); this.logger.info(`Group Ignore: ${this.localSettings.groupsIgnore}`); let options; if (this.localProxy?.enabled) { this.logger.info('Proxy enabled: ' + this.localProxy?.host); if (this.localProxy?.host?.includes('proxyscrape')) { try { const response = await axios.get(this.localProxy?.host); const text = response.data; const proxyUrls = text.split('\r\n'); const rand = Math.floor(Math.random() * Math.floor(proxyUrls.length)); const proxyUrl = 'http://' + proxyUrls[rand]; options = { agent: makeProxyAgent(proxyUrl), fetchAgent: makeProxyAgentUndici(proxyUrl) }; } catch { this.localProxy.enabled = false; } } else { options = { agent: makeProxyAgent({ host: this.localProxy.host, port: this.localProxy.port, protocol: this.localProxy.protocol, username: this.localProxy.username, password: this.localProxy.password, }), fetchAgent: makeProxyAgentUndici({ host: this.localProxy.host, port: this.localProxy.port, protocol: this.localProxy.protocol, username: this.localProxy.username, password: this.localProxy.password, }), }; } } const socketConfig: UserFacingSocketConfig = { ...options, version, logger: P({ level: this.logBaileys }), printQRInTerminal: false, auth: { creds: this.instance.authState.state.creds, keys: makeCacheableSignalKeyStore(this.instance.authState.state.keys, P({ level: 'error' }) as any), }, msgRetryCounterCache: this.msgRetryCounterCache, generateHighQualityLinkPreview: true, getMessage: async (key) => (await this.getMessage(key)) as Promise, ...browserOptions, markOnlineOnConnect: this.localSettings.alwaysOnline, retryRequestDelayMs: 350, maxMsgRetryCount: 4, fireInitQueries: true, connectTimeoutMs: 30_000, keepAliveIntervalMs: 30_000, qrTimeout: 45_000, emitOwnEvents: false, shouldIgnoreJid: (jid) => { if (this.localSettings.syncFullHistory && isJidGroup(jid)) { return false; } const isGroupJid = this.localSettings.groupsIgnore && isJidGroup(jid); const isBroadcast = !this.localSettings.readStatus && isJidBroadcast(jid); const isNewsletter = isJidNewsletter(jid); return isGroupJid || isBroadcast || isNewsletter; }, syncFullHistory: this.localSettings.syncFullHistory, shouldSyncHistoryMessage: (msg: proto.Message.IHistorySyncNotification) => { return this.historySyncNotification(msg); }, cachedGroupMetadata: this.getGroupMetadataCache, userDevicesCache: this.userDevicesCache, transactionOpts: { maxCommitRetries: 10, delayBetweenTriesMs: 3000 }, patchMessageBeforeSending(message) { if ( message.deviceSentMessage?.message?.listMessage?.listType === proto.Message.ListMessage.ListType.PRODUCT_LIST ) { message = JSON.parse(JSON.stringify(message)); message.deviceSentMessage.message.listMessage.listType = proto.Message.ListMessage.ListType.SINGLE_SELECT; } if (message.listMessage?.listType == proto.Message.ListMessage.ListType.PRODUCT_LIST) { message = JSON.parse(JSON.stringify(message)); message.listMessage.listType = proto.Message.ListMessage.ListType.SINGLE_SELECT; } return message; }, }; this.endSession = false; this.client = makeWASocket(socketConfig); if (this.localSettings.wavoipToken && this.localSettings.wavoipToken.length > 0) { useVoiceCallsBaileys(this.localSettings.wavoipToken, this.client, this.connectionStatus.state as any, true); } this.eventHandler(); this.client.ws.on('CB:call', (packet) => { console.log('CB:call', packet); const payload = { event: 'CB:call', packet: packet }; this.sendDataWebhook(Events.CALL, payload, true, ['websocket']); }); this.client.ws.on('CB:ack,class:call', (packet) => { console.log('CB:ack,class:call', packet); const payload = { event: 'CB:ack,class:call', packet: packet }; this.sendDataWebhook(Events.CALL, payload, true, ['websocket']); }); this.phoneNumber = number; return this.client; } public async connectToWhatsapp(number?: string): Promise { try { this.loadChatwoot(); this.loadSettings(); this.loadWebhook(); this.loadProxy(); // Remontar o messageProcessor para garantir que está funcionando após reconexão this.messageProcessor.mount({ onMessageReceive: this.messageHandle['messages.upsert'].bind(this), }); return await this.createClient(number); } catch (error) { this.logger.error(error); throw new InternalServerErrorException(error?.toString()); } } public async reloadConnection(): Promise { try { return await this.createClient(this.phoneNumber); } catch (error) { this.logger.error(error); throw new InternalServerErrorException(error?.toString()); } } private readonly chatHandle = { 'chats.upsert': async (chats: Chat[]) => { const existingChatIds = await this.prismaRepository.chat.findMany({ where: { instanceId: this.instanceId }, select: { remoteJid: true }, }); const existingChatIdSet = new Set(existingChatIds.map((chat) => chat.remoteJid)); const chatsToInsert = chats .filter((chat) => !existingChatIdSet?.has(chat.id)) .map((chat) => ({ remoteJid: chat.id, instanceId: this.instanceId, name: chat.name, unreadMessages: chat.unreadCount !== undefined ? chat.unreadCount : 0, })); this.sendDataWebhook(Events.CHATS_UPSERT, chatsToInsert); if (chatsToInsert.length > 0) { if (this.configService.get('DATABASE').SAVE_DATA.CHATS) await this.prismaRepository.chat.createMany({ data: chatsToInsert, skipDuplicates: true }); } }, 'chats.update': async ( chats: Partial< proto.IConversation & { lastMessageRecvTimestamp?: number } & { conditional: (bufferedData: BufferedEventData) => boolean; } >[], ) => { const chatsRaw = chats.map((chat) => { return { remoteJid: chat.id, instanceId: this.instanceId }; }); this.sendDataWebhook(Events.CHATS_UPDATE, chatsRaw); for (const chat of chats) { await this.prismaRepository.chat.updateMany({ where: { instanceId: this.instanceId, remoteJid: chat.id, name: chat.name }, data: { remoteJid: chat.id }, }); } }, 'chats.delete': async (chats: string[]) => { chats.forEach( async (chat) => await this.prismaRepository.chat.deleteMany({ where: { instanceId: this.instanceId, remoteJid: chat } }), ); this.sendDataWebhook(Events.CHATS_DELETE, [...chats]); }, }; private readonly contactHandle = { 'contacts.upsert': async (contacts: Contact[]) => { try { const contactsRaw: any = contacts.map((contact) => ({ remoteJid: contact.id, pushName: contact?.name || contact?.verifiedName || contact.id.split('@')[0], profilePicUrl: null, instanceId: this.instanceId, })); if (contactsRaw.length > 0) { this.sendDataWebhook(Events.CONTACTS_UPSERT, contactsRaw); if (this.configService.get('DATABASE').SAVE_DATA.CONTACTS) await this.prismaRepository.contact.createMany({ data: contactsRaw, skipDuplicates: true }); const usersContacts = contactsRaw.filter((c) => c.remoteJid.includes('@s.whatsapp')); if (usersContacts) { await saveOnWhatsappCache(usersContacts.map((c) => ({ remoteJid: c.remoteJid }))); } } if ( this.configService.get('CHATWOOT').ENABLED && this.localChatwoot?.enabled && this.localChatwoot.importContacts && contactsRaw.length ) { this.chatwootService.addHistoryContacts( { instanceName: this.instance.name, instanceId: this.instance.id }, contactsRaw, ); chatwootImport.importHistoryContacts( { instanceName: this.instance.name, instanceId: this.instance.id }, this.localChatwoot, ); } const updatedContacts = await Promise.all( contacts.map(async (contact) => ({ remoteJid: contact.id, pushName: contact?.name || contact?.verifiedName || contact.id.split('@')[0], profilePicUrl: (await this.profilePicture(contact.id)).profilePictureUrl, instanceId: this.instanceId, })), ); if (updatedContacts.length > 0) { const usersContacts = updatedContacts.filter((c) => c.remoteJid.includes('@s.whatsapp')); if (usersContacts) { await saveOnWhatsappCache(usersContacts.map((c) => ({ remoteJid: c.remoteJid }))); } this.sendDataWebhook(Events.CONTACTS_UPDATE, updatedContacts); await Promise.all( updatedContacts.map(async (contact) => { if (this.configService.get('DATABASE').SAVE_DATA.CONTACTS) { await this.prismaRepository.contact.updateMany({ where: { remoteJid: contact.remoteJid, instanceId: this.instanceId }, data: { profilePicUrl: contact.profilePicUrl }, }); } if (this.configService.get('CHATWOOT').ENABLED && this.localChatwoot?.enabled) { const instance = { instanceName: this.instance.name, instanceId: this.instance.id }; const findParticipant = await this.chatwootService.findContact( instance, contact.remoteJid.split('@')[0], ); if (!findParticipant) { return; } this.chatwootService.updateContact(instance, findParticipant.id, { name: contact.pushName, avatar_url: contact.profilePicUrl, }); } }), ); } } catch (error) { console.error(error); this.logger.error(`Error: ${error.message}`); } }, 'contacts.update': async (contacts: Partial[]) => { const contactsRaw: { remoteJid: string; pushName?: string; profilePicUrl?: string; instanceId: string }[] = []; for await (const contact of contacts) { this.logger.debug(`Updating contact: ${JSON.stringify(contact, null, 2)}`); contactsRaw.push({ remoteJid: contact.id, pushName: contact?.name ?? contact?.verifiedName, profilePicUrl: (await this.profilePicture(contact.id)).profilePictureUrl, instanceId: this.instanceId, }); } this.sendDataWebhook(Events.CONTACTS_UPDATE, contactsRaw); if (this.configService.get('DATABASE').SAVE_DATA.CONTACTS) { const updateTransactions = contactsRaw.map((contact) => this.prismaRepository.contact.upsert({ where: { remoteJid_instanceId: { remoteJid: contact.remoteJid, instanceId: contact.instanceId } }, create: contact, update: contact, }), ); await this.prismaRepository.$transaction(updateTransactions); } //const usersContacts = contactsRaw.filter((c) => c.remoteJid.includes('@s.whatsapp')); }, }; private readonly messageHandle = { 'messaging-history.set': async ({ messages, chats, contacts, isLatest, progress, syncType, }: { chats: Chat[]; contacts: Contact[]; messages: WAMessage[]; isLatest?: boolean; progress?: number; syncType?: proto.HistorySync.HistorySyncType; }) => { try { if (syncType === proto.HistorySync.HistorySyncType.ON_DEMAND) { console.log('received on-demand history sync, messages=', messages); } console.log( `recv ${chats.length} chats, ${contacts.length} contacts, ${messages.length} msgs (is latest: ${isLatest}, progress: ${progress}%), type: ${syncType}`, ); const instance: InstanceDto = { instanceName: this.instance.name }; let timestampLimitToImport = null; if (this.configService.get('CHATWOOT').ENABLED) { const daysLimitToImport = this.localChatwoot?.enabled ? this.localChatwoot.daysLimitImportMessages : 1000; const date = new Date(); timestampLimitToImport = new Date(date.setDate(date.getDate() - daysLimitToImport)).getTime() / 1000; const maxBatchTimestamp = Math.max(...messages.map((message) => message.messageTimestamp as number)); const processBatch = maxBatchTimestamp >= timestampLimitToImport; if (!processBatch) { return; } } const contactsMap = new Map(); for (const contact of contacts) { if (contact.id && (contact.notify || contact.name)) { contactsMap.set(contact.id, { name: contact.name ?? contact.notify, jid: contact.id }); } } const chatsRaw: { remoteJid: string; instanceId: string; name?: string }[] = []; const chatsRepository = new Set( (await this.prismaRepository.chat.findMany({ where: { instanceId: this.instanceId } })).map( (chat) => chat.remoteJid, ), ); for (const chat of chats) { if (chatsRepository?.has(chat.id)) { continue; } chatsRaw.push({ remoteJid: chat.id, instanceId: this.instanceId, name: chat.name }); } this.sendDataWebhook(Events.CHATS_SET, chatsRaw); if (this.configService.get('DATABASE').SAVE_DATA.HISTORIC) { await this.prismaRepository.chat.createMany({ data: chatsRaw, skipDuplicates: true }); } const messagesRaw: any[] = []; const messagesRepository: Set = new Set( chatwootImport.getRepositoryMessagesCache(instance) ?? ( await this.prismaRepository.message.findMany({ select: { key: true }, where: { instanceId: this.instanceId }, }) ).map((message) => { const key = message.key as { id: string }; return key.id; }), ); if (chatwootImport.getRepositoryMessagesCache(instance) === null) { chatwootImport.setRepositoryMessagesCache(instance, messagesRepository); } for (const m of messages) { if (!m.message || !m.key || !m.messageTimestamp) { continue; } if (Long.isLong(m?.messageTimestamp)) { m.messageTimestamp = m.messageTimestamp?.toNumber(); } if (this.configService.get('CHATWOOT').ENABLED) { if (m.messageTimestamp <= timestampLimitToImport) { continue; } } if (messagesRepository?.has(m.key.id)) { continue; } if (!m.pushName && !m.key.fromMe) { const participantJid = m.participant || m.key.participant || m.key.remoteJid; if (participantJid && contactsMap.has(participantJid)) { m.pushName = contactsMap.get(participantJid).name; } else if (participantJid) { m.pushName = participantJid.split('@')[0]; } } messagesRaw.push(this.prepareMessage(m)); } this.sendDataWebhook(Events.MESSAGES_SET, [...messagesRaw], true, undefined, { isLatest, progress, }); if (this.configService.get('DATABASE').SAVE_DATA.HISTORIC) { await this.prismaRepository.message.createMany({ data: messagesRaw, skipDuplicates: true }); } if ( this.configService.get('CHATWOOT').ENABLED && this.localChatwoot?.enabled && this.localChatwoot.importMessages && messagesRaw.length > 0 ) { this.chatwootService.addHistoryMessages( instance, messagesRaw.filter((msg) => !chatwootImport.isIgnorePhoneNumber(msg.key?.remoteJid)), ); } await this.contactHandle['contacts.upsert']( contacts.filter((c) => !!c.notify || !!c.name).map((c) => ({ id: c.id, name: c.name ?? c.notify })), ); contacts = undefined; messages = undefined; chats = undefined; } catch (error) { this.logger.error(error); } }, 'messages.upsert': async ( { messages, type, requestId }: { messages: WAMessage[]; type: MessageUpsertType; requestId?: string }, settings: any, ) => { try { for (const received of messages) { if ( received?.messageStubParameters?.some?.((param) => [ 'No matching sessions found for message', 'Bad MAC', 'failed to decrypt message', 'SessionError', 'Invalid PreKey ID', 'No session record', 'No session found to decrypt message', 'Message absent from node', ].some((err) => param?.includes?.(err)), ) ) { this.logger.warn(`Message ignored with messageStubParameters: ${JSON.stringify(received, null, 2)}`); continue; } if (received.message?.conversation || received.message?.extendedTextMessage?.text) { const text = received.message?.conversation || received.message?.extendedTextMessage?.text; if (text == 'requestPlaceholder' && !requestId) { const messageId = await this.client.requestPlaceholderResend(received.key); console.log('requested placeholder resync, id=', messageId); } else if (requestId) { console.log('Message received from phone, id=', requestId, received); } if (text == 'onDemandHistSync') { const messageId = await this.client.fetchMessageHistory(50, received.key, received.messageTimestamp!); console.log('requested on-demand sync, id=', messageId); } } const editedMessage = received?.message?.protocolMessage || received?.message?.editedMessage?.message?.protocolMessage; if (editedMessage) { if (this.configService.get('CHATWOOT').ENABLED && this.localChatwoot?.enabled) this.chatwootService.eventWhatsapp( 'messages.edit', { instanceName: this.instance.name, instanceId: this.instance.id }, editedMessage, ); await this.sendDataWebhook(Events.MESSAGES_EDITED, editedMessage); if (received.key?.id && editedMessage.key?.id) { await this.baileysCache.set(`protocol_${received.key.id}`, editedMessage.key.id, 60 * 60 * 24); } const oldMessage = await this.getMessage(editedMessage.key, true); if ((oldMessage as any)?.id) { const editedMessageTimestamp = Long.isLong(received?.messageTimestamp) ? Math.floor(received?.messageTimestamp.toNumber()) : Math.floor(received?.messageTimestamp as number); await this.prismaRepository.message.update({ where: { id: (oldMessage as any).id }, data: { message: editedMessage.editedMessage as any, messageTimestamp: editedMessageTimestamp, status: 'EDITED', }, }); await this.prismaRepository.messageUpdate.create({ data: { fromMe: editedMessage.key.fromMe, keyId: editedMessage.key.id, remoteJid: editedMessage.key.remoteJid, status: 'EDITED', instanceId: this.instanceId, messageId: (oldMessage as any).id, }, }); } } if ((type !== 'notify' && type !== 'append') || editedMessage || !received?.message) { continue; } if (Long.isLong(received.messageTimestamp)) { received.messageTimestamp = received.messageTimestamp?.toNumber(); } if (settings?.groupsIgnore && received.key.remoteJid.includes('@g.us')) { continue; } const existingChat = await this.prismaRepository.chat.findFirst({ where: { instanceId: this.instanceId, remoteJid: received.key.remoteJid }, select: { id: true, name: true }, }); if ( existingChat && received.pushName && existingChat.name !== received.pushName && received.pushName.trim().length > 0 && !received.key.fromMe && !received.key.remoteJid.includes('@g.us') ) { this.sendDataWebhook(Events.CHATS_UPSERT, [{ ...existingChat, name: received.pushName }]); if (this.configService.get('DATABASE').SAVE_DATA.CHATS) { try { await this.prismaRepository.chat.update({ where: { id: existingChat.id }, data: { name: received.pushName }, }); } catch { console.log(`Chat insert record ignored: ${received.key.remoteJid} - ${this.instanceId}`); } } } const messageRaw = this.prepareMessage(received); if (messageRaw.messageType === 'pollUpdateMessage') { const pollCreationKey = messageRaw.message.pollUpdateMessage.pollCreationMessageKey; const pollMessage = (await this.getMessage(pollCreationKey, true)) as proto.IWebMessageInfo; const pollMessageSecret = (await this.getMessage(pollCreationKey)) as any; if (pollMessage) { const pollOptions = (pollMessage.message as any).pollCreationMessage?.options || (pollMessage.message as any).pollCreationMessageV3?.options || []; const pollVote = messageRaw.message.pollUpdateMessage.vote; const voterJid = received.key.fromMe ? this.instance.wuid : received.key.participant || received.key.remoteJid; let pollEncKey = pollMessageSecret?.messageContextInfo?.messageSecret; let successfulVoterJid = voterJid; if (typeof pollEncKey === 'string') { pollEncKey = Buffer.from(pollEncKey, 'base64'); } else if (pollEncKey?.type === 'Buffer' && Array.isArray(pollEncKey.data)) { pollEncKey = Buffer.from(pollEncKey.data); } if (Buffer.isBuffer(pollEncKey) && pollEncKey.length === 44) { pollEncKey = Buffer.from(pollEncKey.toString('utf8'), 'base64'); } if (pollVote.encPayload && pollEncKey) { const creatorCandidates = [ this.instance.wuid, this.client.user?.lid, pollMessage.key.participant, (pollMessage.key as any).participantAlt, pollMessage.key.remoteJid, ]; const key = received.key as any; const voterCandidates = [ this.instance.wuid, this.client.user?.lid, key.participant, key.participantAlt, key.remoteJidAlt, key.remoteJid, ]; const uniqueCreators = [ ...new Set(creatorCandidates.filter(Boolean).map((id) => jidNormalizedUser(id))), ]; const uniqueVoters = [...new Set(voterCandidates.filter(Boolean).map((id) => jidNormalizedUser(id)))]; let decryptedVote; for (const creator of uniqueCreators) { for (const voter of uniqueVoters) { try { decryptedVote = decryptPollVote(pollVote, { pollCreatorJid: creator, pollMsgId: pollMessage.key.id, pollEncKey, voterJid: voter, } as any); if (decryptedVote) { successfulVoterJid = voter; break; } } catch { // Continue trying } } if (decryptedVote) break; } if (decryptedVote) { Object.assign(pollVote, decryptedVote); } } const selectedOptions = pollVote?.selectedOptions || []; const selectedOptionNames = pollOptions .filter((option) => { const hash = createHash('sha256').update(option.optionName).digest(); return selectedOptions.some((selected) => Buffer.compare(selected, hash) === 0); }) .map((option) => option.optionName); messageRaw.message.pollUpdateMessage.vote.selectedOptions = selectedOptionNames; const pollUpdates = pollOptions.map((option) => ({ name: option.optionName, voters: selectedOptionNames.includes(option.optionName) ? [successfulVoterJid] : [], })); messageRaw.pollUpdates = pollUpdates; } } const isMedia = received?.message?.imageMessage || received?.message?.videoMessage || received?.message?.stickerMessage || received?.message?.documentMessage || received?.message?.documentWithCaptionMessage || received?.message?.ptvMessage || received?.message?.audioMessage; const isVideo = received?.message?.videoMessage; if (this.localSettings.readMessages && received.key.id !== 'status@broadcast') { await this.client.readMessages([received.key]); } if (this.localSettings.readStatus && received.key.id === 'status@broadcast') { await this.client.readMessages([received.key]); } if ( this.configService.get('CHATWOOT').ENABLED && this.localChatwoot?.enabled && !received.key.id.includes('@broadcast') ) { const chatwootSentMessage = await this.chatwootService.eventWhatsapp( Events.MESSAGES_UPSERT, { instanceName: this.instance.name, instanceId: this.instanceId }, messageRaw, ); if (chatwootSentMessage?.id) { messageRaw.chatwootMessageId = chatwootSentMessage.id; messageRaw.chatwootInboxId = chatwootSentMessage.inbox_id; messageRaw.chatwootConversationId = chatwootSentMessage.conversation_id; } } if (this.configService.get('OPENAI').ENABLED && received?.message?.audioMessage) { const openAiDefaultSettings = await this.prismaRepository.openaiSetting.findFirst({ where: { instanceId: this.instanceId }, include: { OpenaiCreds: true }, }); if (openAiDefaultSettings && openAiDefaultSettings.openaiCredsId && openAiDefaultSettings.speechToText) { messageRaw.message.speechToText = `[audio] ${await this.openaiService.speechToText(received, this)}`; } } if (this.configService.get('DATABASE').SAVE_DATA.NEW_MESSAGE) { // eslint-disable-next-line @typescript-eslint/no-unused-vars const { pollUpdates, ...messageData } = messageRaw; const msg = await this.prismaRepository.message.create({ data: messageData }); const { remoteJid } = received.key; const timestamp = msg.messageTimestamp; const fromMe = received.key.fromMe.toString(); const messageKey = `${remoteJid}_${timestamp}_${fromMe}`; const cachedTimestamp = await this.baileysCache.get(messageKey); if (!cachedTimestamp) { if (!received.key.fromMe) { if (msg.status === status[3]) { this.logger.log(`Update not read messages ${remoteJid}`); await this.updateChatUnreadMessages(remoteJid); } else if (msg.status === status[4]) { this.logger.log(`Update readed messages ${remoteJid} - ${timestamp}`); await this.updateMessagesReadedByTimestamp(remoteJid, timestamp); } } else { // is send message by me this.logger.log(`Update readed messages ${remoteJid} - ${timestamp}`); await this.updateMessagesReadedByTimestamp(remoteJid, timestamp); } await this.baileysCache.set(messageKey, true, this.MESSAGE_CACHE_TTL_SECONDS); } else { this.logger.info(`Update readed messages duplicated ignored [avoid deadlock]: ${messageKey}`); } if (isMedia) { if (this.configService.get('S3').ENABLE) { try { if (isVideo && !this.configService.get('S3').SAVE_VIDEO) { this.logger.warn('Video upload is disabled. Skipping video upload.'); // Skip video upload by returning early from this block return; } const message: any = received; // Verificação adicional para garantir que há conteúdo de mídia real const hasRealMedia = this.hasValidMediaContent(message); if (!hasRealMedia) { this.logger.warn('Message detected as media but contains no valid media content'); } else { const media = await this.getBase64FromMediaMessage({ message }, true); if (!media) { this.logger.verbose('No valid media to upload (messageContextInfo only), skipping MinIO'); return; } const { buffer, mediaType, fileName, size } = media; const mimetype = mimeTypes.lookup(fileName).toString(); const fullName = join( `${this.instance.id}`, received.key.remoteJid, mediaType, `${Date.now()}_${fileName}`, ); await s3Service.uploadFile(fullName, buffer, size.fileLength?.low, { 'Content-Type': mimetype }); await this.prismaRepository.media.create({ data: { messageId: msg.id, instanceId: this.instanceId, type: mediaType, fileName: fullName, mimetype, }, }); const mediaUrl = await s3Service.getObjectUrl(fullName); messageRaw.message.mediaUrl = mediaUrl; await this.prismaRepository.message.update({ where: { id: msg.id }, data: messageRaw }); } } catch (error) { this.logger.error(['Error on upload file to minio', error?.message, error?.stack]); } } } } if (this.localWebhook.enabled) { if (isMedia && this.localWebhook.webhookBase64) { try { const buffer = await downloadMediaMessage( { key: received.key, message: received?.message }, 'buffer', {}, { logger: P({ level: 'error' }) as any, reuploadRequest: this.client.updateMediaMessage }, ); if (buffer) { messageRaw.message.base64 = buffer.toString('base64'); } else { // retry to download media const buffer = await downloadMediaMessage( { key: received.key, message: received?.message }, 'buffer', {}, { logger: P({ level: 'error' }) as any, reuploadRequest: this.client.updateMediaMessage }, ); if (buffer) { messageRaw.message.base64 = buffer.toString('base64'); } } } catch (error) { this.logger.error(['Error converting media to base64', error?.message]); } } } this.logger.verbose(messageRaw); sendTelemetry(`received.message.${messageRaw.messageType ?? 'unknown'}`); if (messageRaw.key.remoteJid?.includes('@lid') && messageRaw.key.remoteJidAlt) { messageRaw.key.remoteJid = messageRaw.key.remoteJidAlt; } console.log(messageRaw); this.sendDataWebhook(Events.MESSAGES_UPSERT, messageRaw); await chatbotController.emit({ instance: { instanceName: this.instance.name, instanceId: this.instanceId }, remoteJid: messageRaw.key.remoteJid, msg: messageRaw, pushName: messageRaw.pushName, }); const contact = await this.prismaRepository.contact.findFirst({ where: { remoteJid: received.key.remoteJid, instanceId: this.instanceId }, }); const contactRaw: { remoteJid: string; pushName: string; profilePicUrl?: string; instanceId: string; } = { remoteJid: received.key.remoteJid, pushName: received.key.fromMe ? '' : received.key.fromMe == null ? '' : received.pushName, profilePicUrl: (await this.profilePicture(received.key.remoteJid)).profilePictureUrl, instanceId: this.instanceId, }; if (contactRaw.remoteJid === 'status@broadcast') { continue; } if (contactRaw.remoteJid.includes('@s.whatsapp') || contactRaw.remoteJid.includes('@lid')) { await saveOnWhatsappCache([ { remoteJid: messageRaw.key.addressingMode === 'lid' ? messageRaw.key.remoteJidAlt : messageRaw.key.remoteJid, remoteJidAlt: messageRaw.key.remoteJidAlt, lid: messageRaw.key.addressingMode === 'lid' ? 'lid' : null, }, ]); } if (contact) { this.sendDataWebhook(Events.CONTACTS_UPDATE, contactRaw); if (this.configService.get('CHATWOOT').ENABLED && this.localChatwoot?.enabled) { await this.chatwootService.eventWhatsapp( Events.CONTACTS_UPDATE, { instanceName: this.instance.name, instanceId: this.instanceId }, contactRaw, ); } if (this.configService.get('DATABASE').SAVE_DATA.CONTACTS) await this.prismaRepository.contact.upsert({ where: { remoteJid_instanceId: { remoteJid: contactRaw.remoteJid, instanceId: contactRaw.instanceId } }, create: contactRaw, update: contactRaw, }); continue; } this.sendDataWebhook(Events.CONTACTS_UPSERT, contactRaw); if (this.configService.get('DATABASE').SAVE_DATA.CONTACTS) await this.prismaRepository.contact.upsert({ where: { remoteJid_instanceId: { remoteJid: contactRaw.remoteJid, instanceId: contactRaw.instanceId } }, update: contactRaw, create: contactRaw, }); } } catch (error) { this.logger.error(error); } }, 'messages.update': async (args: { update: Partial; key: WAMessageKey }[], settings: any) => { this.logger.verbose(`Update messages ${JSON.stringify(args, undefined, 2)}`); const readChatToUpdate: Record = {}; // {remoteJid: true} for await (const { key, update } of args) { if (settings?.groupsIgnore && key.remoteJid?.includes('@g.us')) { continue; } const updateKey = `${this.instance.id}_${key.id}_${update.status}`; const cached = await this.baileysCache.get(updateKey); const secondsSinceEpoch = Math.floor(Date.now() / 1000); console.log('CACHE:', { cached, updateKey, messageTimestamp: update.messageTimestamp, secondsSinceEpoch }); if ( (update.messageTimestamp && update.messageTimestamp === cached) || (!update.messageTimestamp && secondsSinceEpoch === cached) ) { this.logger.info(`Update Message duplicated ignored [avoid deadlock]: ${updateKey}`); continue; } if (update.messageTimestamp) { await this.baileysCache.set(updateKey, update.messageTimestamp, 30 * 60); } else { await this.baileysCache.set(updateKey, secondsSinceEpoch, 30 * 60); } if (status[update.status] === 'READ' && key.fromMe) { if (this.configService.get('CHATWOOT').ENABLED && this.localChatwoot?.enabled) { this.chatwootService.eventWhatsapp( 'messages.read', { instanceName: this.instance.name, instanceId: this.instanceId }, { key: key }, ); } } if (key.remoteJid !== 'status@broadcast' && key.id !== undefined) { let pollUpdates: any; if (update.pollUpdates) { const pollCreation = await this.getMessage(key); if (pollCreation) { pollUpdates = getAggregateVotesInPollMessage({ message: pollCreation as proto.IMessage, pollUpdates: update.pollUpdates, }); } } const message: any = { keyId: key.id, remoteJid: key?.remoteJid, fromMe: key.fromMe, participant: key?.participant, status: status[update.status] ?? 'SERVER_ACK', pollUpdates, instanceId: this.instanceId, }; if (update.message) { message.message = update.message; } let findMessage: any; const configDatabaseData = this.configService.get('DATABASE').SAVE_DATA; if (configDatabaseData.HISTORIC || configDatabaseData.NEW_MESSAGE) { // Use raw SQL to avoid JSON path issues const protocolMapKey = `protocol_${key.id}`; const originalMessageId = (await this.baileysCache.get(protocolMapKey)) as string; if (originalMessageId) { message.keyId = originalMessageId; } const searchId = originalMessageId || key.id; const messages = (await this.prismaRepository.$queryRaw` SELECT * FROM "Message" WHERE "instanceId" = ${this.instanceId} AND "key"->>'id' = ${searchId} LIMIT 1 `) as any[]; findMessage = messages[0] || null; if (!findMessage?.id) { this.logger.warn(`Original message not found for update. Skipping. Key: ${JSON.stringify(key)}`); continue; } message.messageId = findMessage.id; } if (update.message === null && update.status === undefined) { this.sendDataWebhook(Events.MESSAGES_DELETE, { ...key, status: 'DELETED' }); if (this.configService.get('DATABASE').SAVE_DATA.MESSAGE_UPDATE) await this.prismaRepository.messageUpdate.create({ data: message }); if (this.configService.get('CHATWOOT').ENABLED && this.localChatwoot?.enabled) { this.chatwootService.eventWhatsapp( Events.MESSAGES_DELETE, { instanceName: this.instance.name, instanceId: this.instanceId }, { key: key }, ); } continue; } if (findMessage && update.status !== undefined && status[update.status] !== findMessage.status) { if (!key.fromMe && key.remoteJid) { readChatToUpdate[key.remoteJid] = true; const { remoteJid } = key; const timestamp = findMessage.messageTimestamp; const fromMe = key.fromMe.toString(); const messageKey = `${remoteJid}_${timestamp}_${fromMe}`; const cachedTimestamp = await this.baileysCache.get(messageKey); if (!cachedTimestamp) { if (status[update.status] === status[4]) { this.logger.log(`Update as read in message.update ${remoteJid} - ${timestamp}`); await this.updateMessagesReadedByTimestamp(remoteJid, timestamp); await this.baileysCache.set(messageKey, true, this.MESSAGE_CACHE_TTL_SECONDS); } await this.prismaRepository.message.update({ where: { id: findMessage.id }, data: { status: status[update.status] }, }); } else { this.logger.info( `Update readed messages duplicated ignored in message.update [avoid deadlock]: ${messageKey}`, ); } } } this.sendDataWebhook(Events.MESSAGES_UPDATE, message); if (this.configService.get('DATABASE').SAVE_DATA.MESSAGE_UPDATE) { // eslint-disable-next-line @typescript-eslint/no-unused-vars const { message: _msg, ...messageData } = message; await this.prismaRepository.messageUpdate.create({ data: messageData }); } const existingChat = await this.prismaRepository.chat.findFirst({ where: { instanceId: this.instanceId, remoteJid: message.remoteJid }, }); if (existingChat) { const chatToInsert = { remoteJid: message.remoteJid, instanceId: this.instanceId, unreadMessages: 0 }; this.sendDataWebhook(Events.CHATS_UPSERT, [chatToInsert]); if (this.configService.get('DATABASE').SAVE_DATA.CHATS) { try { await this.prismaRepository.chat.update({ where: { id: existingChat.id }, data: chatToInsert }); } catch { console.log(`Chat insert record ignored: ${chatToInsert.remoteJid} - ${chatToInsert.instanceId}`); } } } } } await Promise.all(Object.keys(readChatToUpdate).map((remoteJid) => this.updateChatUnreadMessages(remoteJid))); }, }; private readonly groupHandler = { 'groups.upsert': (groupMetadata: GroupMetadata[]) => { this.sendDataWebhook(Events.GROUPS_UPSERT, groupMetadata); }, 'groups.update': (groupMetadataUpdate: Partial[]) => { this.sendDataWebhook(Events.GROUPS_UPDATE, groupMetadataUpdate); groupMetadataUpdate.forEach((group) => { if (isJidGroup(group.id)) { this.updateGroupMetadataCache(group.id); } }); }, 'group-participants.update': async (participantsUpdate: { id: string; participants: string[]; action: ParticipantAction; }) => { // ENHANCEMENT: Adds participantsData field while maintaining backward compatibility // MAINTAINS: participants: string[] (original JID strings) // ADDS: participantsData: { jid: string, phoneNumber: string, name?: string, imgUrl?: string }[] // This enables LID to phoneNumber conversion without breaking existing webhook consumers // Helper to normalize participantId as phone number const normalizePhoneNumber = (id: string | null | undefined): string => { // Remove @lid, @s.whatsapp.net suffixes and extract just the number part return String(id || '').split('@')[0]; }; try { // Usa o mesmo método que o endpoint /group/participants const groupParticipants = await this.findParticipants({ groupJid: participantsUpdate.id }); // Validação para garantir que temos dados válidos if (!groupParticipants?.participants || !Array.isArray(groupParticipants.participants)) { throw new Error('Invalid participant data received from findParticipants'); } // Filtra apenas os participantes que estão no evento const resolvedParticipants = participantsUpdate.participants.map((participantId) => { const participantData = groupParticipants.participants.find((p) => p.id === participantId); let phoneNumber: string; if (participantData?.phoneNumber) { phoneNumber = participantData.phoneNumber; } else { phoneNumber = normalizePhoneNumber(participantId); } return { jid: participantId, phoneNumber, name: participantData?.name, imgUrl: participantData?.imgUrl, }; }); // Mantém formato original + adiciona dados resolvidos const enhancedParticipantsUpdate = { ...participantsUpdate, participants: participantsUpdate.participants, // Mantém array original de strings // Adiciona dados resolvidos em campo separado participantsData: resolvedParticipants, }; this.sendDataWebhook(Events.GROUP_PARTICIPANTS_UPDATE, enhancedParticipantsUpdate); } catch (error) { this.logger.error( `Failed to resolve participant data for GROUP_PARTICIPANTS_UPDATE webhook: ${error.message} | Group: ${participantsUpdate.id} | Participants: ${participantsUpdate.participants.length}`, ); // Fallback - envia sem conversão this.sendDataWebhook(Events.GROUP_PARTICIPANTS_UPDATE, participantsUpdate); } this.updateGroupMetadataCache(participantsUpdate.id); }, }; private readonly labelHandle = { [Events.LABELS_EDIT]: async (label: Label) => { this.sendDataWebhook(Events.LABELS_EDIT, { ...label, instance: this.instance.name }); const labelsRepository = await this.prismaRepository.label.findMany({ where: { instanceId: this.instanceId } }); const savedLabel = labelsRepository.find((l) => l.labelId === label.id); if (label.deleted && savedLabel) { await this.prismaRepository.label.delete({ where: { labelId_instanceId: { instanceId: this.instanceId, labelId: label.id } }, }); this.sendDataWebhook(Events.LABELS_EDIT, { ...label, instance: this.instance.name }); return; } const labelName = label.name.replace(/[^\x20-\x7E]/g, ''); if (!savedLabel || savedLabel.color !== `${label.color}` || savedLabel.name !== labelName) { if (this.configService.get('DATABASE').SAVE_DATA.LABELS) { const labelData = { color: `${label.color}`, name: labelName, labelId: label.id, predefinedId: label.predefinedId, instanceId: this.instanceId, }; await this.prismaRepository.label.upsert({ where: { labelId_instanceId: { instanceId: labelData.instanceId, labelId: labelData.labelId } }, update: labelData, create: labelData, }); } } }, [Events.LABELS_ASSOCIATION]: async ( data: { association: LabelAssociation; type: 'remove' | 'add' }, database: Database, ) => { this.logger.info( `labels association - ${data?.association?.chatId} (${data.type}-${data?.association?.type}): ${data?.association?.labelId}`, ); if (database.SAVE_DATA.CHATS) { const instanceId = this.instanceId; const chatId = data.association.chatId; const labelId = data.association.labelId; if (data.type === 'add') { await this.addLabel(labelId, instanceId, chatId); } else if (data.type === 'remove') { await this.removeLabel(labelId, instanceId, chatId); } } this.sendDataWebhook(Events.LABELS_ASSOCIATION, { instance: this.instance.name, type: data.type, chatId: data.association.chatId, labelId: data.association.labelId, }); }, }; private eventHandler() { this.client.ev.process(async (events) => { this.eventProcessingQueue = this.eventProcessingQueue.then(async () => { try { if (!this.endSession) { const database = this.configService.get('DATABASE'); const settings = await this.findSettings(); if (events.call) { const call = events.call[0]; if (settings?.rejectCall && call.status == 'offer') { this.client.rejectCall(call.id, call.from); } if (settings?.msgCall?.trim().length > 0 && call.status == 'offer') { if (call.from.endsWith('@lid')) { call.from = await this.client.signalRepository.lidMapping.getPNForLID(call.from as string); } const msg = await this.client.sendMessage(call.from, { text: settings.msgCall }); this.client.ev.emit('messages.upsert', { messages: [msg], type: 'notify' }); } this.sendDataWebhook(Events.CALL, call); } if (events['connection.update']) { this.connectionUpdate(events['connection.update']); } if (events['creds.update']) { this.instance.authState.saveCreds(); } if (events['messaging-history.set']) { const payload = events['messaging-history.set']; await this.messageHandle['messaging-history.set'](payload); } if (events['messages.upsert']) { const payload = events['messages.upsert']; // this.messageProcessor.processMessage(payload, settings); await this.messageHandle['messages.upsert'](payload, settings); } if (events['messages.update']) { const payload = events['messages.update']; await this.messageHandle['messages.update'](payload, settings); } if (events['message-receipt.update']) { const payload = events['message-receipt.update'] as MessageUserReceiptUpdate[]; const remotesJidMap: Record = {}; for (const event of payload) { if (typeof event.key.remoteJid === 'string' && typeof event.receipt.readTimestamp === 'number') { remotesJidMap[event.key.remoteJid] = event.receipt.readTimestamp; } } await Promise.all( Object.keys(remotesJidMap).map(async (remoteJid) => this.updateMessagesReadedByTimestamp(remoteJid, remotesJidMap[remoteJid]), ), ); } if (events['presence.update']) { const payload = events['presence.update']; if (settings?.groupsIgnore && payload.id.includes('@g.us')) { return; } this.sendDataWebhook(Events.PRESENCE_UPDATE, payload); } if (!settings?.groupsIgnore) { if (events['groups.upsert']) { const payload = events['groups.upsert']; this.groupHandler['groups.upsert'](payload); } if (events['groups.update']) { const payload = events['groups.update']; this.groupHandler['groups.update'](payload); } if (events['group-participants.update']) { const payload = events['group-participants.update'] as any; this.groupHandler['group-participants.update'](payload); } } if (events['chats.upsert']) { const payload = events['chats.upsert']; this.chatHandle['chats.upsert'](payload); } if (events['chats.update']) { const payload = events['chats.update']; this.chatHandle['chats.update'](payload); } if (events['chats.delete']) { const payload = events['chats.delete']; this.chatHandle['chats.delete'](payload); } if (events['contacts.upsert']) { const payload = events['contacts.upsert']; this.contactHandle['contacts.upsert'](payload); } if (events['contacts.update']) { const payload = events['contacts.update']; this.contactHandle['contacts.update'](payload); } if (events[Events.LABELS_ASSOCIATION]) { const payload = events[Events.LABELS_ASSOCIATION]; this.labelHandle[Events.LABELS_ASSOCIATION](payload, database); return; } if (events[Events.LABELS_EDIT]) { const payload = events[Events.LABELS_EDIT]; this.labelHandle[Events.LABELS_EDIT](payload); return; } } } catch (error) { this.logger.error(error); } }); }); } private historySyncNotification(msg: proto.Message.IHistorySyncNotification) { const instance: InstanceDto = { instanceName: this.instance.name }; if ( this.configService.get('CHATWOOT').ENABLED && this.localChatwoot?.enabled && this.localChatwoot.importMessages && this.isSyncNotificationFromUsedSyncType(msg) ) { if (msg.chunkOrder === 1) { this.chatwootService.startImportHistoryMessages(instance); } if (msg.progress === 100) { setTimeout(() => { this.chatwootService.importHistoryMessages(instance); }, 10000); } } return true; } private isSyncNotificationFromUsedSyncType(msg: proto.Message.IHistorySyncNotification) { return ( (this.localSettings.syncFullHistory && msg?.syncType === 2) || (!this.localSettings.syncFullHistory && msg?.syncType === 3) ); } public async profilePicture(number: string) { const jid = createJid(number); try { const profilePictureUrl = await this.client.profilePictureUrl(jid, 'image'); return { wuid: jid, profilePictureUrl }; } catch { return { wuid: jid, profilePictureUrl: null }; } } public async getStatus(number: string) { const jid = createJid(number); try { return { wuid: jid, status: (await this.client.fetchStatus(jid))[0]?.status }; } catch { return { wuid: jid, status: null }; } } public async fetchProfile(instanceName: string, number?: string) { const jid = number ? createJid(number) : this.client?.user?.id; const onWhatsapp = (await this.whatsappNumber({ numbers: [jid] }))?.shift(); if (!onWhatsapp.exists) { throw new BadRequestException(onWhatsapp); } try { if (number) { const info = (await this.whatsappNumber({ numbers: [jid] }))?.shift(); const picture = await this.profilePicture(info?.jid); const status = await this.getStatus(info?.jid); const business = await this.fetchBusinessProfile(info?.jid); return { wuid: info?.jid || jid, name: info?.name, numberExists: info?.exists, picture: picture?.profilePictureUrl, status: status?.status, isBusiness: business.isBusiness, email: business?.email, description: business?.description, website: business?.website?.shift(), }; } else { const instanceNames = instanceName ? [instanceName] : null; const info: Instance = await waMonitor.instanceInfo(instanceNames); const business = await this.fetchBusinessProfile(jid); return { wuid: jid, name: info?.profileName, numberExists: true, picture: info?.profilePicUrl, status: info?.connectionStatus, isBusiness: business.isBusiness, email: business?.email, description: business?.description, website: business?.website?.shift(), }; } } catch { return { wuid: jid, name: null, picture: null, status: null, os: null, isBusiness: false }; } } public async offerCall({ number, isVideo, callDuration }: OfferCallDto) { const jid = createJid(number); try { // const call = await this.client.offerCall(jid, isVideo); // setTimeout(() => this.client.terminateCall(call.id, call.to), callDuration * 1000); // return call; return { id: '123', jid, isVideo, callDuration }; } catch (error) { return error; } } private async sendMessage( sender: string, message: any, mentions: any, linkPreview: any, quoted: any, messageId?: string, ephemeralExpiration?: number, contextInfo?: any, // participants?: GroupParticipant[], ) { sender = sender.toLowerCase(); const option: any = { quoted }; if (isJidGroup(sender)) { option.useCachedGroupMetadata = true; // if (participants) // option.cachedGroupMetadata = async () => { // return { participants: participants as GroupParticipant[] }; // }; } if (ephemeralExpiration) option.ephemeralExpiration = ephemeralExpiration; // NOTE: NÃO DEVEMOS GERAR O messageId AQUI, SOMENTE SE VIER INFORMADO POR PARAMETRO. A GERAÇÃO ANTERIOR IMPEDE O WZAP DE IDENTIFICAR A SOURCE. if (messageId) option.messageId = messageId; if (message['viewOnceMessage']) { const m = generateWAMessageFromContent(sender, message, { timestamp: new Date(), userJid: this.instance.wuid, messageId, quoted, }); const id = await this.client.relayMessage(sender, message, { messageId }); m.key = { id: id, remoteJid: sender, participant: isPnUser(sender) ? sender : undefined, fromMe: true }; for (const [key, value] of Object.entries(m)) { if (!value || (isArray(value) && value.length) === 0) { delete m[key]; } } return m; } if ( !message['audio'] && !message['poll'] && !message['sticker'] && !message['conversation'] && sender !== 'status@broadcast' ) { if (message['reactionMessage']) { return await this.client.sendMessage( sender, { react: { text: message['reactionMessage']['text'], key: message['reactionMessage']['key'] }, } as unknown as AnyMessageContent, option as unknown as MiscMessageGenerationOptions, ); } } if (contextInfo) { message['contextInfo'] = contextInfo; } if (message['conversation']) { return await this.client.sendMessage( sender, { text: message['conversation'], mentions, linkPreview: linkPreview, contextInfo: message['contextInfo'], } as unknown as AnyMessageContent, option as unknown as MiscMessageGenerationOptions, ); } if (!message['audio'] && !message['poll'] && !message['sticker'] && sender != 'status@broadcast') { return await this.client.sendMessage( sender, { forward: { key: { remoteJid: this.instance.wuid, fromMe: true }, message }, mentions, contextInfo: message['contextInfo'], }, option as unknown as MiscMessageGenerationOptions, ); } if (sender === 'status@broadcast') { let jidList; if (message['status'].option.allContacts) { const contacts = await this.prismaRepository.contact.findMany({ where: { instanceId: this.instanceId, remoteJid: { not: { endsWith: '@g.us' } } }, }); jidList = contacts.map((contact) => contact.remoteJid); } else { jidList = message['status'].option.statusJidList; } const batchSize = 10; const batches = Array.from({ length: Math.ceil(jidList.length / batchSize) }, (_, i) => jidList.slice(i * batchSize, i * batchSize + batchSize), ); let msgId: string | null = null; let firstMessage: WAMessage; const firstBatch = batches.shift(); if (firstBatch) { firstMessage = await this.client.sendMessage( sender, message['status'].content as unknown as AnyMessageContent, { backgroundColor: message['status'].option.backgroundColor, font: message['status'].option.font, statusJidList: firstBatch, } as unknown as MiscMessageGenerationOptions, ); msgId = firstMessage.key.id; } if (batches.length === 0) return firstMessage; await Promise.allSettled( batches.map(async (batch) => { const messageSent = await this.client.sendMessage( sender, message['status'].content as unknown as AnyMessageContent, { backgroundColor: message['status'].option.backgroundColor, font: message['status'].option.font, statusJidList: batch, messageId: msgId, } as unknown as MiscMessageGenerationOptions, ); return messageSent; }), ); return firstMessage; } return await this.client.sendMessage( sender, message as unknown as AnyMessageContent, option as unknown as MiscMessageGenerationOptions, ); } private async sendMessageWithTyping( number: string, message: T, options?: Options, isIntegration = false, ) { const isWA = (await this.whatsappNumber({ numbers: [number] }))?.shift(); if (!isWA.exists && !isJidGroup(isWA.jid) && !isWA.jid.includes('@broadcast')) { throw new BadRequestException(isWA); } const sender = isWA.jid.toLowerCase(); this.logger.verbose(`Sending message to ${sender}`); try { if (options?.delay) { this.logger.verbose(`Typing for ${options.delay}ms to ${sender}`); if (options.delay > 20000) { let remainingDelay = options.delay; while (remainingDelay > 20000) { await this.client.presenceSubscribe(sender); await this.client.sendPresenceUpdate((options.presence as WAPresence) ?? 'composing', sender); await delay(20000); await this.client.sendPresenceUpdate('paused', sender); remainingDelay -= 20000; } if (remainingDelay > 0) { await this.client.presenceSubscribe(sender); await this.client.sendPresenceUpdate((options.presence as WAPresence) ?? 'composing', sender); await delay(remainingDelay); await this.client.sendPresenceUpdate('paused', sender); } } else { await this.client.presenceSubscribe(sender); await this.client.sendPresenceUpdate((options.presence as WAPresence) ?? 'composing', sender); await delay(options.delay); await this.client.sendPresenceUpdate('paused', sender); } } const linkPreview = options?.linkPreview != false ? undefined : false; let quoted: WAMessage; if (options?.quoted) { const m = options?.quoted; const msg = m?.message ? m : ((await this.getMessage(m.key, true)) as WAMessage); if (msg) { quoted = msg; } } let messageSent: WAMessage; let mentions: string[]; let contextInfo: any; if (isJidGroup(sender)) { let group; try { const cache = this.configService.get('CACHE'); if (!cache.REDIS.ENABLED && !cache.LOCAL.ENABLED) group = await this.findGroup({ groupJid: sender }, 'inner'); else group = await this.getGroupMetadataCache(sender); // group = await this.findGroup({ groupJid: sender }, 'inner'); } catch { throw new NotFoundException('Group not found'); } if (!group) { throw new NotFoundException('Group not found'); } if (options?.mentionsEveryOne) { mentions = group.participants.map((participant) => participant.id); } else if (options?.mentioned?.length) { mentions = options.mentioned.map((mention) => { const jid = createJid(mention); if (isJidGroup(jid)) { return null; } return jid; }); } messageSent = await this.sendMessage( sender, message, mentions, linkPreview, quoted, null, group?.ephemeralDuration, // group?.participants, ); } else { contextInfo = { mentionedJid: [], groupMentions: [], //expiration: 7776000, ephemeralSettingTimestamp: { low: Math.floor(Date.now() / 1000) - 172800, high: 0, unsigned: false, }, disappearingMode: { initiator: 0 }, }; messageSent = await this.sendMessage( sender, message, mentions, linkPreview, quoted, null, undefined, contextInfo, ); } if (Long.isLong(messageSent?.messageTimestamp)) { messageSent.messageTimestamp = messageSent.messageTimestamp?.toNumber(); } const messageRaw = this.prepareMessage(messageSent); const isMedia = messageSent?.message?.imageMessage || messageSent?.message?.videoMessage || messageSent?.message?.stickerMessage || messageSent?.message?.ptvMessage || messageSent?.message?.documentMessage || messageSent?.message?.documentWithCaptionMessage || messageSent?.message?.ptvMessage || messageSent?.message?.audioMessage; const isVideo = messageSent?.message?.videoMessage; if (this.configService.get('CHATWOOT').ENABLED && this.localChatwoot?.enabled && !isIntegration) { this.chatwootService.eventWhatsapp( Events.SEND_MESSAGE, { instanceName: this.instance.name, instanceId: this.instanceId }, messageRaw, ); } if (this.configService.get('OPENAI').ENABLED && messageRaw?.message?.audioMessage) { const openAiDefaultSettings = await this.prismaRepository.openaiSetting.findFirst({ where: { instanceId: this.instanceId }, include: { OpenaiCreds: true }, }); if (openAiDefaultSettings && openAiDefaultSettings.openaiCredsId && openAiDefaultSettings.speechToText) { messageRaw.message.speechToText = `[audio] ${await this.openaiService.speechToText(messageRaw, this)}`; } } if (this.configService.get('DATABASE').SAVE_DATA.NEW_MESSAGE) { const msg = await this.prismaRepository.message.create({ data: messageRaw }); if (isMedia && this.configService.get('S3').ENABLE) { try { if (isVideo && !this.configService.get('S3').SAVE_VIDEO) { throw new Error('Video upload is disabled.'); } const message: any = messageRaw; // Verificação adicional para garantir que há conteúdo de mídia real const hasRealMedia = this.hasValidMediaContent(message); if (!hasRealMedia) { this.logger.warn('Message detected as media but contains no valid media content'); } else { const media = await this.getBase64FromMediaMessage({ message }, true); if (!media) { this.logger.verbose('No valid media to upload (messageContextInfo only), skipping MinIO'); return; } const { buffer, mediaType, fileName, size } = media; const mimetype = mimeTypes.lookup(fileName).toString(); const fullName = join( `${this.instance.id}`, messageRaw.key.remoteJid, `${messageRaw.key.id}`, mediaType, fileName, ); await s3Service.uploadFile(fullName, buffer, size.fileLength?.low, { 'Content-Type': mimetype }); await this.prismaRepository.media.create({ data: { messageId: msg.id, instanceId: this.instanceId, type: mediaType, fileName: fullName, mimetype }, }); const mediaUrl = await s3Service.getObjectUrl(fullName); messageRaw.message.mediaUrl = mediaUrl; await this.prismaRepository.message.update({ where: { id: msg.id }, data: messageRaw }); } } catch (error) { this.logger.error(['Error on upload file to minio', error?.message, error?.stack]); } } } if (this.localWebhook.enabled) { if (isMedia && this.localWebhook.webhookBase64) { try { const buffer = await downloadMediaMessage( { key: messageRaw.key, message: messageRaw?.message }, 'buffer', {}, { logger: P({ level: 'error' }) as any, reuploadRequest: this.client.updateMediaMessage }, ); if (buffer) { messageRaw.message.base64 = buffer.toString('base64'); } else { // retry to download media const buffer = await downloadMediaMessage( { key: messageRaw.key, message: messageRaw?.message }, 'buffer', {}, { logger: P({ level: 'error' }) as any, reuploadRequest: this.client.updateMediaMessage }, ); if (buffer) { messageRaw.message.base64 = buffer.toString('base64'); } } } catch (error) { this.logger.error(['Error converting media to base64', error?.message]); } } } this.logger.verbose(messageSent); this.sendDataWebhook(Events.SEND_MESSAGE, messageRaw); if (this.configService.get('CHATWOOT').ENABLED && this.localChatwoot?.enabled && isIntegration) { await chatbotController.emit({ instance: { instanceName: this.instance.name, instanceId: this.instanceId }, remoteJid: messageRaw.key.remoteJid, msg: messageRaw, pushName: messageRaw.pushName, isIntegration, }); } return messageRaw; } catch (error) { this.logger.error(error); throw new BadRequestException(error.toString()); } } // Instance Controller public async sendPresence(data: SendPresenceDto) { try { const { number } = data; const isWA = (await this.whatsappNumber({ numbers: [number] }))?.shift(); if (!isWA.exists && !isJidGroup(isWA.jid) && !isWA.jid.includes('@broadcast')) { throw new BadRequestException(isWA); } const sender = isWA.jid; if (data?.delay && data?.delay > 20000) { let remainingDelay = data?.delay; while (remainingDelay > 20000) { await this.client.presenceSubscribe(sender); await this.client.sendPresenceUpdate((data?.presence as WAPresence) ?? 'composing', sender); await delay(20000); await this.client.sendPresenceUpdate('paused', sender); remainingDelay -= 20000; } if (remainingDelay > 0) { await this.client.presenceSubscribe(sender); await this.client.sendPresenceUpdate((data?.presence as WAPresence) ?? 'composing', sender); await delay(remainingDelay); await this.client.sendPresenceUpdate('paused', sender); } } else { await this.client.presenceSubscribe(sender); await this.client.sendPresenceUpdate((data?.presence as WAPresence) ?? 'composing', sender); await delay(data?.delay); await this.client.sendPresenceUpdate('paused', sender); } return { presence: data.presence }; } catch (error) { this.logger.error(error); throw new BadRequestException(error.toString()); } } // Presence Controller public async setPresence(data: SetPresenceDto) { try { await this.client.sendPresenceUpdate(data.presence); return { presence: data.presence }; } catch (error) { this.logger.error(error); throw new BadRequestException(error.toString()); } } // Send Message Controller public async textMessage(data: SendTextDto, isIntegration = false) { const text = data.text; if (!text || text.trim().length === 0) { throw new BadRequestException('Text is required'); } return await this.sendMessageWithTyping( data.number, { conversation: data.text }, { delay: data?.delay, presence: 'composing', quoted: data?.quoted, linkPreview: data?.linkPreview, mentionsEveryOne: data?.mentionsEveryOne, mentioned: data?.mentioned, }, isIntegration, ); } public async pollMessage(data: SendPollDto) { return await this.sendMessageWithTyping( data.number, { poll: { name: data.name, selectableCount: data.selectableCount, values: data.values } }, { delay: data?.delay, presence: 'composing', quoted: data?.quoted, linkPreview: data?.linkPreview, mentionsEveryOne: data?.mentionsEveryOne, mentioned: data?.mentioned, }, ); } private async formatStatusMessage(status: StatusMessage) { if (!status.type) { throw new BadRequestException('Type is required'); } if (!status.content) { throw new BadRequestException('Content is required'); } if (status.allContacts) { const contacts = await this.prismaRepository.contact.findMany({ where: { instanceId: this.instanceId } }); if (!contacts.length) { throw new BadRequestException('Contacts not found'); } status.statusJidList = contacts.filter((contact) => contact.pushName).map((contact) => contact.remoteJid); } if (!status.statusJidList?.length && !status.allContacts) { throw new BadRequestException('StatusJidList is required'); } if (status.type === 'text') { if (!status.backgroundColor) { throw new BadRequestException('Background color is required'); } if (!status.font) { throw new BadRequestException('Font is required'); } return { content: { text: status.content }, option: { backgroundColor: status.backgroundColor, font: status.font, statusJidList: status.statusJidList }, }; } if (status.type === 'image') { return { content: { image: { url: status.content }, caption: status.caption }, option: { statusJidList: status.statusJidList }, }; } if (status.type === 'video') { return { content: { video: { url: status.content }, caption: status.caption }, option: { statusJidList: status.statusJidList }, }; } if (status.type === 'audio') { const convert = await this.processAudioMp4(status.content); if (Buffer.isBuffer(convert)) { const result = { content: { audio: convert, ptt: true, mimetype: 'audio/ogg; codecs=opus' }, option: { statusJidList: status.statusJidList }, }; return result; } else { throw new InternalServerErrorException(convert); } } throw new BadRequestException('Type not found'); } public async statusMessage(data: SendStatusDto, file?: any) { const mediaData: SendStatusDto = { ...data }; if (file) mediaData.content = file.buffer.toString('base64'); const status = await this.formatStatusMessage(mediaData); const statusSent = await this.sendMessageWithTyping('status@broadcast', { status }); return statusSent; } private async prepareMediaMessage(mediaMessage: MediaMessage) { try { const type = mediaMessage.mediatype === 'ptv' ? 'video' : mediaMessage.mediatype; let mediaInput: any; if (mediaMessage.mediatype === 'image') { let imageBuffer: Buffer; if (isURL(mediaMessage.media)) { let config: any = { responseType: 'arraybuffer' }; if (this.localProxy?.enabled) { config = { ...config, httpsAgent: makeProxyAgent({ host: this.localProxy.host, port: this.localProxy.port, protocol: this.localProxy.protocol, username: this.localProxy.username, password: this.localProxy.password, }), }; } const response = await axios.get(mediaMessage.media, config); imageBuffer = Buffer.from(response.data, 'binary'); } else { imageBuffer = Buffer.from(mediaMessage.media, 'base64'); } mediaInput = await sharp(imageBuffer).jpeg().toBuffer(); mediaMessage.fileName ??= 'image.jpg'; mediaMessage.mimetype = 'image/jpeg'; } else { mediaInput = isURL(mediaMessage.media) ? { url: mediaMessage.media } : Buffer.from(mediaMessage.media, 'base64'); } const prepareMedia = await prepareWAMessageMedia( { [type]: mediaInput, } as any, { upload: this.client.waUploadToServer }, ); const mediaType = mediaMessage.mediatype + 'Message'; if (mediaMessage.mediatype === 'document' && !mediaMessage.fileName) { const regex = new RegExp(/.*\/(.+?)\./); const arrayMatch = regex.exec(mediaMessage.media); mediaMessage.fileName = arrayMatch[1]; } if (mediaMessage.mediatype === 'image' && !mediaMessage.fileName) { mediaMessage.fileName = 'image.jpg'; } if (mediaMessage.mediatype === 'video' && !mediaMessage.fileName) { mediaMessage.fileName = 'video.mp4'; } let mimetype: string | false; if (mediaMessage.mimetype) { mimetype = mediaMessage.mimetype; } else { mimetype = mimeTypes.lookup(mediaMessage.fileName); if (!mimetype && isURL(mediaMessage.media)) { let config: any = { responseType: 'arraybuffer' }; if (this.localProxy?.enabled) { config = { ...config, httpsAgent: makeProxyAgent({ host: this.localProxy.host, port: this.localProxy.port, protocol: this.localProxy.protocol, username: this.localProxy.username, password: this.localProxy.password, }), }; } const response = await axios.get(mediaMessage.media, config); mimetype = response.headers['content-type']; } } if (mediaMessage.mediatype === 'ptv') { prepareMedia[mediaType] = prepareMedia[type + 'Message']; mimetype = 'video/mp4'; if (!prepareMedia[mediaType]) { throw new Error('Failed to prepare video message'); } try { let mediaInput; if (isURL(mediaMessage.media)) { mediaInput = mediaMessage.media; } else { const mediaBuffer = Buffer.from(mediaMessage.media, 'base64'); if (!mediaBuffer || mediaBuffer.length === 0) { throw new Error('Invalid media buffer'); } mediaInput = mediaBuffer; } const duration = await getVideoDuration(mediaInput); if (!duration || duration <= 0) { throw new Error('Invalid media duration'); } this.logger.verbose(`Video duration: ${duration} seconds`); prepareMedia[mediaType].seconds = duration; } catch (error) { this.logger.error('Error getting video duration:'); this.logger.error(error); throw new Error(`Failed to get video duration: ${error.message}`); } } if (mediaMessage?.fileName) { mimetype = mimeTypes.lookup(mediaMessage.fileName).toString(); if (mimetype === 'application/mp4') { mimetype = 'video/mp4'; } } prepareMedia[mediaType].caption = mediaMessage?.caption; prepareMedia[mediaType].mimetype = mimetype; prepareMedia[mediaType].fileName = mediaMessage.fileName; if (mediaMessage.mediatype === 'video') { prepareMedia[mediaType].gifPlayback = false; } return generateWAMessageFromContent( '', { [mediaType]: { ...prepareMedia[mediaType] } }, { userJid: this.instance.wuid }, ); } catch (error) { this.logger.error(error); throw new InternalServerErrorException(error?.toString() || error); } } private async convertToWebP(image: string): Promise { try { let imageBuffer: Buffer; if (isBase64(image)) { const base64Data = image.replace(/^data:image\/(jpeg|png|gif);base64,/, ''); imageBuffer = Buffer.from(base64Data, 'base64'); } else { const timestamp = new Date().getTime(); const parsedURL = new URL(image); parsedURL.searchParams.set('timestamp', timestamp.toString()); const url = parsedURL.toString(); let config: any = { responseType: 'arraybuffer' }; if (this.localProxy?.enabled) { config = { ...config, httpsAgent: makeProxyAgent({ host: this.localProxy.host, port: this.localProxy.port, protocol: this.localProxy.protocol, username: this.localProxy.username, password: this.localProxy.password, }), }; } const response = await axios.get(url, config); imageBuffer = Buffer.from(response.data, 'binary'); } const isAnimated = this.isAnimated(image, imageBuffer); if (isAnimated) { return await sharp(imageBuffer, { animated: true }).webp({ quality: 80 }).toBuffer(); } else { return await sharp(imageBuffer).webp().toBuffer(); } } catch (error) { console.error('Erro ao converter a imagem para WebP:', error); throw error; } } private isAnimatedWebp(buffer: Buffer): boolean { if (buffer.length < 12) return false; return buffer.indexOf(Buffer.from('ANIM')) !== -1; } private isAnimated(image: string, buffer: Buffer): boolean { const lowerCaseImage = image.toLowerCase(); if (lowerCaseImage.includes('.gif')) return true; if (lowerCaseImage.includes('.webp')) return this.isAnimatedWebp(buffer); return false; } public async mediaSticker(data: SendStickerDto, file?: any) { const mediaData: SendStickerDto = { ...data }; if (file) mediaData.sticker = file.buffer.toString('base64'); const convert = data?.notConvertSticker ? Buffer.from(data.sticker, 'base64') : await this.convertToWebP(data.sticker); const gifPlayback = data.sticker.includes('.gif'); const result = await this.sendMessageWithTyping( data.number, { sticker: convert, gifPlayback }, { delay: data?.delay, presence: 'composing', quoted: data?.quoted, mentionsEveryOne: data?.mentionsEveryOne, mentioned: data?.mentioned, }, ); return result; } public async mediaMessage(data: SendMediaDto, file?: any, isIntegration = false) { const mediaData: SendMediaDto = { ...data }; if (file) mediaData.media = file.buffer.toString('base64'); const generate = await this.prepareMediaMessage(mediaData); const mediaSent = await this.sendMessageWithTyping( data.number, { ...generate.message }, { delay: data?.delay, presence: 'composing', quoted: data?.quoted, mentionsEveryOne: data?.mentionsEveryOne, mentioned: data?.mentioned, }, isIntegration, ); return mediaSent; } public async ptvMessage(data: SendPtvDto, file?: any, isIntegration = false) { const mediaData: SendMediaDto = { number: data.number, media: data.video, mediatype: 'ptv', delay: data?.delay, quoted: data?.quoted, mentionsEveryOne: data?.mentionsEveryOne, mentioned: data?.mentioned, }; if (file) mediaData.media = file.buffer.toString('base64'); const generate = await this.prepareMediaMessage(mediaData); const mediaSent = await this.sendMessageWithTyping( data.number, { ...generate.message }, { delay: data?.delay, presence: 'composing', quoted: data?.quoted, mentionsEveryOne: data?.mentionsEveryOne, mentioned: data?.mentioned, }, isIntegration, ); return mediaSent; } public async processAudioMp4(audio: string) { let inputStream: PassThrough; if (isURL(audio)) { const response = await axios.get(audio, { responseType: 'stream' }); inputStream = response.data; } else { const audioBuffer = Buffer.from(audio, 'base64'); inputStream = new PassThrough(); inputStream.end(audioBuffer); } return new Promise((resolve, reject) => { const ffmpegProcess = spawn(ffmpegPath.path, [ '-i', 'pipe:0', '-vn', '-ab', '128k', '-ar', '44100', '-f', 'mp4', '-movflags', 'frag_keyframe+empty_moov', 'pipe:1', ]); const outputChunks: Buffer[] = []; let stderrData = ''; ffmpegProcess.stdout.on('data', (chunk) => { outputChunks.push(chunk); }); ffmpegProcess.stderr.on('data', (data) => { stderrData += data.toString(); this.logger.verbose(`ffmpeg stderr: ${data}`); }); ffmpegProcess.on('error', (error) => { console.error('Error in ffmpeg process', error); reject(error); }); ffmpegProcess.on('close', (code) => { if (code === 0) { this.logger.verbose('Audio converted to mp4'); const outputBuffer = Buffer.concat(outputChunks); resolve(outputBuffer); } else { this.logger.error(`ffmpeg exited with code ${code}`); this.logger.error(`ffmpeg stderr: ${stderrData}`); reject(new Error(`ffmpeg exited with code ${code}: ${stderrData}`)); } }); inputStream.pipe(ffmpegProcess.stdin); inputStream.on('error', (err) => { console.error('Error in inputStream', err); ffmpegProcess.stdin.end(); reject(err); }); }); } public async processAudio(audio: string): Promise { const audioConverterConfig = this.configService.get('AUDIO_CONVERTER'); if (audioConverterConfig.API_URL) { this.logger.verbose('Using audio converter API'); const formData = new FormData(); if (isURL(audio)) { formData.append('url', audio); } else { formData.append('base64', audio); } const { data } = await axios.post(audioConverterConfig.API_URL, formData, { headers: { ...formData.getHeaders(), apikey: audioConverterConfig.API_KEY }, }); if (!data.audio) { throw new InternalServerErrorException('Failed to convert audio'); } this.logger.verbose('Audio converted'); return Buffer.from(data.audio, 'base64'); } else { let inputAudioStream: PassThrough; if (isURL(audio)) { const timestamp = new Date().getTime(); const parsedURL = new URL(audio); parsedURL.searchParams.set('timestamp', timestamp.toString()); const url = parsedURL.toString(); const config: any = { responseType: 'stream' }; const response = await axios.get(url, config); inputAudioStream = response.data.pipe(new PassThrough()); } else { const audioBuffer = Buffer.from(audio, 'base64'); inputAudioStream = new PassThrough(); inputAudioStream.end(audioBuffer); } const isLpcm = isURL(audio) && /\.lpcm($|\?)/i.test(audio); return new Promise((resolve, reject) => { const outputAudioStream = new PassThrough(); const chunks: Buffer[] = []; outputAudioStream.on('data', (chunk) => chunks.push(chunk)); outputAudioStream.on('end', () => { const outputBuffer = Buffer.concat(chunks); resolve(outputBuffer); }); outputAudioStream.on('error', (error) => { console.log('error', error); reject(error); }); ffmpeg.setFfmpegPath(ffmpegPath.path); let command = ffmpeg(inputAudioStream); if (isLpcm) { this.logger.verbose('Detected LPCM input – applying raw PCM settings'); command = command.inputFormat('s16le').inputOptions(['-ar', '24000', '-ac', '1']); } command .outputFormat('ogg') .noVideo() .audioCodec('libopus') .addOutputOptions('-avoid_negative_ts make_zero') .audioBitrate('128k') .audioFrequency(48000) .audioChannels(1) .outputOptions([ '-write_xing', '0', '-compression_level', '10', '-application', 'voip', '-fflags', '+bitexact', '-flags', '+bitexact', '-id3v2_version', '0', '-map_metadata', '-1', '-map_chapters', '-1', '-write_bext', '0', ]) .pipe(outputAudioStream, { end: true }) .on('error', function (error) { console.log('error', error); reject(error); }); }); } } public async audioWhatsapp(data: SendAudioDto, file?: any, isIntegration = false) { const mediaData: SendAudioDto = { ...data }; if (file?.buffer) { mediaData.audio = file.buffer.toString('base64'); } else if (!isURL(data.audio) && !isBase64(data.audio)) { console.error('Invalid file or audio source'); throw new BadRequestException('File buffer, URL, or base64 audio is required'); } if (!data?.encoding && data?.encoding !== false) { data.encoding = true; } if (data?.encoding) { const convert = await this.processAudio(mediaData.audio); if (Buffer.isBuffer(convert)) { const result = this.sendMessageWithTyping( data.number, { audio: convert, ptt: true, mimetype: 'audio/ogg; codecs=opus' }, { presence: 'recording', delay: data?.delay }, isIntegration, ); return result; } else { throw new InternalServerErrorException('Failed to convert audio'); } } return await this.sendMessageWithTyping( data.number, { audio: isURL(data.audio) ? { url: data.audio } : Buffer.from(data.audio, 'base64'), ptt: true, mimetype: 'audio/ogg; codecs=opus', }, { presence: 'recording', delay: data?.delay }, isIntegration, ); } private generateRandomId(length = 11) { const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; let result = ''; for (let i = 0; i < length; i++) { result += characters.charAt(Math.floor(Math.random() * characters.length)); } return result; } private toJSONString(button: Button): string { const toString = (obj: any) => JSON.stringify(obj); const json = { call: () => toString({ display_text: button.displayText, phone_number: button.phoneNumber }), reply: () => toString({ display_text: button.displayText, id: button.id }), copy: () => toString({ display_text: button.displayText, copy_code: button.copyCode }), url: () => toString({ display_text: button.displayText, url: button.url, merchant_url: button.url }), pix: () => toString({ currency: button.currency, total_amount: { value: 0, offset: 100 }, reference_id: this.generateRandomId(), type: 'physical-goods', order: { status: 'pending', subtotal: { value: 0, offset: 100 }, order_type: 'ORDER', items: [ { name: '', amount: { value: 0, offset: 100 }, quantity: 0, sale_amount: { value: 0, offset: 100 } }, ], }, payment_settings: [ { type: 'pix_static_code', pix_static_code: { merchant_name: button.name, key: button.key, key_type: this.mapKeyType.get(button.keyType), }, }, ], share_payment_status: false, }), }; return json[button.type]?.() || ''; } private readonly mapType = new Map([ ['reply', 'quick_reply'], ['copy', 'cta_copy'], ['url', 'cta_url'], ['call', 'cta_call'], ['pix', 'payment_info'], ]); private readonly mapKeyType = new Map([ ['phone', 'PHONE'], ['email', 'EMAIL'], ['cpf', 'CPF'], ['cnpj', 'CNPJ'], ['random', 'EVP'], ]); public async buttonMessage(data: SendButtonsDto) { if (data.buttons.length === 0) { throw new BadRequestException('At least one button is required'); } const hasReplyButtons = data.buttons.some((btn) => btn.type === 'reply'); const hasPixButton = data.buttons.some((btn) => btn.type === 'pix'); const hasOtherButtons = data.buttons.some((btn) => btn.type !== 'reply' && btn.type !== 'pix'); if (hasReplyButtons) { if (data.buttons.length > 3) { throw new BadRequestException('Maximum of 3 reply buttons allowed'); } if (hasOtherButtons) { throw new BadRequestException('Reply buttons cannot be mixed with other button types'); } } if (hasPixButton) { if (data.buttons.length > 1) { throw new BadRequestException('Only one PIX button is allowed'); } if (hasOtherButtons) { throw new BadRequestException('PIX button cannot be mixed with other button types'); } const message: proto.IMessage = { viewOnceMessage: { message: { interactiveMessage: { nativeFlowMessage: { buttons: [{ name: this.mapType.get('pix'), buttonParamsJson: this.toJSONString(data.buttons[0]) }], messageParamsJson: JSON.stringify({ from: 'api', templateId: v4() }), }, }, }, }, }; return await this.sendMessageWithTyping(data.number, message, { delay: data?.delay, presence: 'composing', quoted: data?.quoted, mentionsEveryOne: data?.mentionsEveryOne, mentioned: data?.mentioned, }); } const generate = await (async () => { if (data?.thumbnailUrl) { return await this.prepareMediaMessage({ mediatype: 'image', media: data.thumbnailUrl }); } })(); const buttons = data.buttons.map((value) => { return { name: this.mapType.get(value.type), buttonParamsJson: this.toJSONString(value) }; }); const message: proto.IMessage = { viewOnceMessage: { message: { interactiveMessage: { body: { text: (() => { let t = '*' + data.title + '*'; if (data?.description) { t += '\n\n'; t += data.description; t += '\n'; } return t; })(), }, footer: { text: data?.footer }, header: (() => { if (generate?.message?.imageMessage) { return { hasMediaAttachment: !!generate.message.imageMessage, imageMessage: generate.message.imageMessage, }; } })(), nativeFlowMessage: { buttons: buttons, messageParamsJson: JSON.stringify({ from: 'api', templateId: v4() }), }, }, }, }, }; return await this.sendMessageWithTyping(data.number, message, { delay: data?.delay, presence: 'composing', quoted: data?.quoted, mentionsEveryOne: data?.mentionsEveryOne, mentioned: data?.mentioned, }); } public async locationMessage(data: SendLocationDto) { return await this.sendMessageWithTyping( data.number, { locationMessage: { degreesLatitude: data.latitude, degreesLongitude: data.longitude, name: data?.name, address: data?.address, }, }, { delay: data?.delay, presence: 'composing', quoted: data?.quoted, mentionsEveryOne: data?.mentionsEveryOne, mentioned: data?.mentioned, }, ); } public async listMessage(data: SendListDto) { return await this.sendMessageWithTyping( data.number, { listMessage: { title: data.title, description: data.description, buttonText: data?.buttonText, footerText: data?.footerText, sections: data.sections, listType: 2, }, }, { delay: data?.delay, presence: 'composing', quoted: data?.quoted, mentionsEveryOne: data?.mentionsEveryOne, mentioned: data?.mentioned, }, ); } public async contactMessage(data: SendContactDto) { const message: proto.IMessage = {}; const vcard = (contact: ContactMessage) => { let result = 'BEGIN:VCARD\n' + 'VERSION:3.0\n' + `N:${contact.fullName}\n` + `FN:${contact.fullName}\n`; if (contact.organization) { result += `ORG:${contact.organization};\n`; } if (contact.email) { result += `EMAIL:${contact.email}\n`; } if (contact.url) { result += `URL:${contact.url}\n`; } if (!contact.wuid) { contact.wuid = createJid(contact.phoneNumber); } result += `item1.TEL;waid=${contact.wuid}:${contact.phoneNumber}\n` + 'item1.X-ABLabel:Celular\n' + 'END:VCARD'; return result; }; if (data.contact.length === 1) { message.contactMessage = { displayName: data.contact[0].fullName, vcard: vcard(data.contact[0]) }; } else { message.contactsArrayMessage = { displayName: `${data.contact.length} contacts`, contacts: data.contact.map((contact) => { return { displayName: contact.fullName, vcard: vcard(contact) }; }), }; } return await this.sendMessageWithTyping(data.number, { ...message }, {}); } public async reactionMessage(data: SendReactionDto) { return await this.sendMessageWithTyping(data.key.remoteJid, { reactionMessage: { key: data.key, text: data.reaction }, }); } // Chat Controller public async whatsappNumber(data: WhatsAppNumberDto) { const jids: { groups: { number: string; jid: string }[]; broadcast: { number: string; jid: string }[]; users: { number: string; jid: string; name?: string }[]; } = { groups: [], broadcast: [], users: [] }; data.numbers.forEach((number) => { const jid = createJid(number); if (isJidGroup(jid)) { jids.groups.push({ number, jid }); } else if (jid === 'status@broadcast') { jids.broadcast.push({ number, jid }); } else { jids.users.push({ number, jid }); } }); const onWhatsapp: OnWhatsAppDto[] = []; // BROADCAST onWhatsapp.push(...jids.broadcast.map(({ jid, number }) => new OnWhatsAppDto(jid, false, number))); // GROUPS const groups = await Promise.all( jids.groups.map(async ({ jid, number }) => { const group = await this.findGroup({ groupJid: jid }, 'inner'); if (!group) { return new OnWhatsAppDto(jid, false, number); } return new OnWhatsAppDto(group.id, true, number, group?.subject); }), ); onWhatsapp.push(...groups); // USERS const contacts: any[] = await this.prismaRepository.contact.findMany({ where: { instanceId: this.instanceId, remoteJid: { in: jids.users.map(({ jid }) => jid) } }, }); // Unified cache verification for all numbers (normal and LID) const numbersToVerify = jids.users.map(({ jid }) => jid.replace('+', '')); // Get all numbers from cache const cachedNumbers = await getOnWhatsappCache(numbersToVerify); // Separate numbers that are and are not in cache const cachedJids = new Set(cachedNumbers.flatMap((cached) => cached.jidOptions)); const numbersNotInCache = numbersToVerify.filter((jid) => !cachedJids.has(jid)); // Only call Baileys for normal numbers (@s.whatsapp.net) that are not in cache let verify: { jid: string; exists: boolean }[] = []; const normalNumbersNotInCache = numbersNotInCache.filter((jid) => !jid.includes('@lid')); if (normalNumbersNotInCache.length > 0) { this.logger.verbose(`Checking ${normalNumbersNotInCache.length} numbers via Baileys (not found in cache)`); verify = await this.client.onWhatsApp(...normalNumbersNotInCache); } const verifiedUsers = await Promise.all( jids.users.map(async (user) => { // Try to get from cache first (works for all: normal and LID) const cached = cachedNumbers.find((cached) => cached.jidOptions.includes(user.jid.replace('+', ''))); if (cached) { this.logger.verbose(`Number ${user.number} found in cache`); return new OnWhatsAppDto( cached.remoteJid, true, user.number, contacts.find((c) => c.remoteJid === cached.remoteJid)?.pushName, cached.lid || (cached.remoteJid.includes('@lid') ? 'lid' : undefined), ); } // If it's a LID number and not in cache, consider it valid if (user.jid.includes('@lid')) { return new OnWhatsAppDto( user.jid, true, user.number, contacts.find((c) => c.remoteJid === user.jid)?.pushName, 'lid', ); } // If not in cache and is a normal number, use Baileys verification let numberVerified: (typeof verify)[0] | null = null; // Brazilian numbers if (user.number.startsWith('55')) { const numberWithDigit = user.number.slice(4, 5) === '9' && user.number.length === 13 ? user.number : `${user.number.slice(0, 4)}9${user.number.slice(4)}`; const numberWithoutDigit = user.number.length === 12 ? user.number : user.number.slice(0, 4) + user.number.slice(5); numberVerified = verify.find( (v) => v.jid === `${numberWithDigit}@s.whatsapp.net` || v.jid === `${numberWithoutDigit}@s.whatsapp.net`, ); } // Mexican/Argentina numbers // Ref: https://faq.whatsapp.com/1294841057948784 if (!numberVerified && (user.number.startsWith('52') || user.number.startsWith('54'))) { let prefix = ''; if (user.number.startsWith('52')) { prefix = '1'; } if (user.number.startsWith('54')) { prefix = '9'; } const numberWithDigit = user.number.slice(2, 3) === prefix && user.number.length === 13 ? user.number : `${user.number.slice(0, 2)}${prefix}${user.number.slice(2)}`; const numberWithoutDigit = user.number.length === 12 ? user.number : user.number.slice(0, 2) + user.number.slice(3); numberVerified = verify.find( (v) => v.jid === `${numberWithDigit}@s.whatsapp.net` || v.jid === `${numberWithoutDigit}@s.whatsapp.net`, ); } if (!numberVerified) { numberVerified = verify.find((v) => v.jid === user.jid); } const numberJid = numberVerified?.jid || user.jid; return new OnWhatsAppDto( numberJid, !!numberVerified?.exists, user.number, contacts.find((c) => c.remoteJid === numberJid)?.pushName, undefined, ); }), ); // Combine results onWhatsapp.push(...verifiedUsers); // TODO: Salvar no cache apenas números que NÃO estavam no cache const numbersToCache = onWhatsapp.filter((user) => { if (!user.exists) return false; // Verifica se estava no cache usando jidOptions const cached = cachedNumbers?.find((cached) => cached.jidOptions.includes(user.jid.replace('+', ''))); return !cached; }); if (numbersToCache.length > 0) { this.logger.verbose(`Salvando ${numbersToCache.length} números no cache`); await saveOnWhatsappCache( numbersToCache.map((user) => ({ remoteJid: user.jid, lid: user.lid === 'lid' ? 'lid' : undefined, })), ); } return onWhatsapp; } public async markMessageAsRead(data: ReadMessageDto) { try { const keys: proto.IMessageKey[] = []; data.readMessages.forEach((read) => { if (isJidGroup(read.remoteJid) || isPnUser(read.remoteJid)) { keys.push({ remoteJid: read.remoteJid, fromMe: read.fromMe, id: read.id }); } }); await this.client.readMessages(keys); return { message: 'Read messages', read: 'success' }; } catch (error) { throw new InternalServerErrorException('Read messages fail', error.toString()); } } public async getLastMessage(number: string) { const where: any = { key: { remoteJid: number }, instanceId: this.instance.id }; const messages = await this.prismaRepository.message.findMany({ where, orderBy: { messageTimestamp: 'desc' }, take: 1, }); if (messages.length === 0) { throw new NotFoundException('Messages not found'); } let lastMessage = messages.pop(); for (const message of messages) { if (message.messageTimestamp >= lastMessage.messageTimestamp) { lastMessage = message; } } return lastMessage as unknown as LastMessage; } public async archiveChat(data: ArchiveChatDto) { try { let last_message = data.lastMessage; let number = data.chat; if (!last_message && number) { last_message = await this.getLastMessage(number); } else { last_message = data.lastMessage; last_message.messageTimestamp = last_message?.messageTimestamp ?? Date.now(); number = last_message?.key?.remoteJid; } if (!last_message || Object.keys(last_message).length === 0) { throw new NotFoundException('Last message not found'); } await this.client.chatModify({ archive: data.archive, lastMessages: [last_message] }, createJid(number)); return { chatId: number, archived: true }; } catch (error) { throw new InternalServerErrorException({ archived: false, message: ['An error occurred while archiving the chat. Open a calling.', error.toString()], }); } } public async markChatUnread(data: MarkChatUnreadDto) { try { let last_message = data.lastMessage; let number = data.chat; if (!last_message && number) { last_message = await this.getLastMessage(number); } else { last_message = data.lastMessage; last_message.messageTimestamp = last_message?.messageTimestamp ?? Date.now(); number = last_message?.key?.remoteJid; } if (!last_message || Object.keys(last_message).length === 0) { throw new NotFoundException('Last message not found'); } await this.client.chatModify({ markRead: false, lastMessages: [last_message] }, createJid(number)); return { chatId: number, markedChatUnread: true }; } catch (error) { throw new InternalServerErrorException({ markedChatUnread: false, message: ['An error occurred while marked unread the chat. Open a calling.', error.toString()], }); } } public async deleteMessage(del: DeleteMessage) { try { const response = await this.client.sendMessage(del.remoteJid, { delete: del }); if (response) { const messageId = response.message?.protocolMessage?.key?.id; if (messageId) { const isLogicalDeleted = configService.get('DATABASE').DELETE_DATA.LOGICAL_MESSAGE_DELETE; let message = await this.prismaRepository.message.findFirst({ where: { key: { path: ['id'], equals: messageId } }, }); if (isLogicalDeleted) { if (!message) return response; const existingKey = typeof message?.key === 'object' && message.key !== null ? message.key : {}; message = await this.prismaRepository.message.update({ where: { id: message.id }, data: { key: { ...existingKey, deleted: true }, status: 'DELETED' }, }); if (this.configService.get('DATABASE').SAVE_DATA.MESSAGE_UPDATE) { const messageUpdate: any = { messageId: message.id, keyId: messageId, remoteJid: response.key.remoteJid, fromMe: response.key.fromMe, participant: response.key?.participant, status: 'DELETED', instanceId: this.instanceId, }; await this.prismaRepository.messageUpdate.create({ data: messageUpdate }); } } else { if (!message) return response; await this.prismaRepository.message.deleteMany({ where: { id: message.id } }); } this.sendDataWebhook(Events.MESSAGES_DELETE, { id: message.id, instanceId: message.instanceId, key: message.key, messageType: message.messageType, status: 'DELETED', source: message.source, messageTimestamp: message.messageTimestamp, pushName: message.pushName, participant: message.participant, message: message.message, }); } } return response; } catch (error) { throw new InternalServerErrorException('Error while deleting message for everyone', error?.toString()); } } public async mapMediaType(mediaType) { const map = { imageMessage: 'image', videoMessage: 'video', documentMessage: 'document', stickerMessage: 'sticker', audioMessage: 'audio', ptvMessage: 'video', }; return map[mediaType] || null; } public async getBase64FromMediaMessage(data: getBase64FromMediaMessageDto, getBuffer = false) { try { const m = data?.message; const convertToMp4 = data?.convertToMp4 ?? false; const msg = m?.message ? m : ((await this.getMessage(m.key, true)) as proto.IWebMessageInfo); if (!msg) { throw 'Message not found'; } for (const subtype of MessageSubtype) { if (msg.message[subtype]) { msg.message = msg.message[subtype].message; } } if ('messageContextInfo' in msg.message && Object.keys(msg.message).length === 1) { this.logger.verbose('Message contains only messageContextInfo, skipping media processing'); return null; } let mediaMessage: any; let mediaType: string; if (msg.message?.templateMessage) { const template = msg.message.templateMessage.hydratedTemplate || msg.message.templateMessage.hydratedFourRowTemplate; for (const type of TypeMediaMessage) { if (template[type]) { mediaMessage = template[type]; mediaType = type; msg.message = { [type]: { ...template[type], url: template[type].staticUrl } }; break; } } if (!mediaMessage) { throw 'Template message does not contain a supported media type'; } } else { for (const type of TypeMediaMessage) { mediaMessage = msg.message[type]; if (mediaMessage) { mediaType = type; break; } } if (!mediaMessage) { throw 'The message is not of the media type'; } } if (typeof mediaMessage['mediaKey'] === 'object') { msg.message[mediaType].mediaKey = Uint8Array.from(Object.values(mediaMessage['mediaKey'])); } let buffer: Buffer; try { buffer = await downloadMediaMessage( { key: msg?.key, message: msg?.message }, 'buffer', {}, { logger: P({ level: 'error' }) as any, reuploadRequest: this.client.updateMediaMessage }, ); } catch { this.logger.error('Download Media failed, trying to retry in 5 seconds...'); await new Promise((resolve) => setTimeout(resolve, 5000)); const mediaType = Object.keys(msg.message).find((key) => key.endsWith('Message')); if (!mediaType) throw new Error('Could not determine mediaType for fallback'); try { const media = await downloadContentFromMessage( { mediaKey: msg.message?.[mediaType]?.mediaKey, directPath: msg.message?.[mediaType]?.directPath, url: `https://mmg.whatsapp.net${msg?.message?.[mediaType]?.directPath}`, }, await this.mapMediaType(mediaType), {}, ); const chunks = []; for await (const chunk of media) { chunks.push(chunk); } buffer = Buffer.concat(chunks); this.logger.info('Download Media with downloadContentFromMessage was successful!'); } catch (fallbackErr) { this.logger.error('Download Media with downloadContentFromMessage also failed!'); throw fallbackErr; } } const typeMessage = getContentType(msg.message); const ext = mimeTypes.extension(mediaMessage?.['mimetype']); const fileName = mediaMessage?.['fileName'] || `${msg.key.id}.${ext}` || `${v4()}.${ext}`; if (convertToMp4 && typeMessage === 'audioMessage') { try { const convert = await this.processAudioMp4(buffer.toString('base64')); if (Buffer.isBuffer(convert)) { const result = { mediaType, fileName, caption: mediaMessage['caption'], size: { fileLength: mediaMessage['fileLength'], height: mediaMessage['height'], width: mediaMessage['width'], }, mimetype: 'audio/mp4', base64: convert.toString('base64'), buffer: getBuffer ? convert : null, }; return result; } } catch (error) { this.logger.error('Error converting audio to mp4:'); this.logger.error(error); throw new BadRequestException('Failed to convert audio to MP4'); } } return { mediaType, fileName, caption: mediaMessage['caption'], size: { fileLength: mediaMessage['fileLength'], height: mediaMessage['height'], width: mediaMessage['width'] }, mimetype: mediaMessage['mimetype'], base64: buffer.toString('base64'), buffer: getBuffer ? buffer : null, }; } catch (error) { this.logger.error('Error processing media message:'); this.logger.error(error); throw new BadRequestException(error.toString()); } } public async fetchPrivacySettings() { const privacy = await this.client.fetchPrivacySettings(); return { readreceipts: privacy.readreceipts, profile: privacy.profile, status: privacy.status, online: privacy.online, last: privacy.last, groupadd: privacy.groupadd, }; } public async updatePrivacySettings(settings: PrivacySettingDto) { try { await this.client.updateReadReceiptsPrivacy(settings.readreceipts); await this.client.updateProfilePicturePrivacy(settings.profile); await this.client.updateStatusPrivacy(settings.status); await this.client.updateOnlinePrivacy(settings.online); await this.client.updateLastSeenPrivacy(settings.last); await this.client.updateGroupsAddPrivacy(settings.groupadd); this.reloadConnection(); return { update: 'success', data: { readreceipts: settings.readreceipts, profile: settings.profile, status: settings.status, online: settings.online, last: settings.last, groupadd: settings.groupadd, }, }; } catch (error) { throw new InternalServerErrorException('Error updating privacy settings', error.toString()); } } public async fetchBusinessProfile(number: string): Promise { try { const jid = number ? createJid(number) : this.instance.wuid; const profile = await this.client.getBusinessProfile(jid); if (!profile) { const info = await this.whatsappNumber({ numbers: [jid] }); return { isBusiness: false, message: 'Not is business profile', ...info?.shift() }; } return { isBusiness: true, ...profile }; } catch (error) { throw new InternalServerErrorException('Error updating profile name', error.toString()); } } public async updateProfileName(name: string) { try { await this.client.updateProfileName(name); return { update: 'success' }; } catch (error) { throw new InternalServerErrorException('Error updating profile name', error.toString()); } } public async updateProfileStatus(status: string) { try { await this.client.updateProfileStatus(status); return { update: 'success' }; } catch (error) { throw new InternalServerErrorException('Error updating profile status', error.toString()); } } public async updateProfilePicture(picture: string) { try { let pic: WAMediaUpload; if (isURL(picture)) { const timestamp = new Date().getTime(); const parsedURL = new URL(picture); parsedURL.searchParams.set('timestamp', timestamp.toString()); const url = parsedURL.toString(); let config: any = { responseType: 'arraybuffer' }; if (this.localProxy?.enabled) { config = { ...config, httpsAgent: makeProxyAgent({ host: this.localProxy.host, port: this.localProxy.port, protocol: this.localProxy.protocol, username: this.localProxy.username, password: this.localProxy.password, }), }; } pic = (await axios.get(url, config)).data; } else if (isBase64(picture)) { pic = Buffer.from(picture, 'base64'); } else { throw new BadRequestException('"profilePicture" must be a url or a base64'); } await this.client.updateProfilePicture(this.instance.wuid, pic); this.reloadConnection(); return { update: 'success' }; } catch (error) { throw new InternalServerErrorException('Error updating profile picture', error.toString()); } } public async removeProfilePicture() { try { await this.client.removeProfilePicture(this.instance.wuid); this.reloadConnection(); return { update: 'success' }; } catch (error) { throw new InternalServerErrorException('Error removing profile picture', error.toString()); } } public async blockUser(data: BlockUserDto) { try { const { number } = data; const isWA = (await this.whatsappNumber({ numbers: [number] }))?.shift(); if (!isWA.exists && !isJidGroup(isWA.jid) && !isWA.jid.includes('@broadcast')) { throw new BadRequestException(isWA); } const sender = isWA.jid; await this.client.updateBlockStatus(sender, data.status); return { block: 'success' }; } catch (error) { throw new InternalServerErrorException('Error blocking user', error.toString()); } } private async formatUpdateMessage(data: UpdateMessageDto) { try { if (!this.configService.get('DATABASE').SAVE_DATA.NEW_MESSAGE) { return data; } const msg: any = await this.getMessage(data.key, true); if (msg?.messageType === 'conversation' || msg?.messageType === 'extendedTextMessage') { return { text: data.text }; } if (msg?.messageType === 'imageMessage') { return { image: msg?.message?.imageMessage, caption: data.text }; } if (msg?.messageType === 'videoMessage') { return { video: msg?.message?.videoMessage, caption: data.text }; } return null; } catch (error) { this.logger.error(error); throw new BadRequestException(error.toString()); } } public async updateMessage(data: UpdateMessageDto) { const jid = createJid(data.number); const options = await this.formatUpdateMessage(data); if (!options) { this.logger.error('Message not compatible'); throw new BadRequestException('Message not compatible'); } try { const oldMessage: any = await this.getMessage(data.key, true); if (this.configService.get('DATABASE').SAVE_DATA.NEW_MESSAGE) { if (!oldMessage) throw new NotFoundException('Message not found'); if (oldMessage?.key?.remoteJid !== jid) { throw new BadRequestException('RemoteJid does not match'); } if (oldMessage?.messageTimestamp > Date.now() + 900000) { // 15 minutes in milliseconds throw new BadRequestException('Message is older than 15 minutes'); } } const messageSent = await this.client.sendMessage(jid, { ...(options as any), edit: data.key }); if (messageSent) { const editedMessage = messageSent?.message?.protocolMessage || messageSent?.message?.editedMessage?.message?.protocolMessage; if (editedMessage) { this.sendDataWebhook(Events.SEND_MESSAGE_UPDATE, editedMessage); if (this.configService.get('CHATWOOT').ENABLED && this.localChatwoot?.enabled) this.chatwootService.eventWhatsapp( 'send.message.update', { instanceName: this.instance.name, instanceId: this.instance.id }, editedMessage, ); const messageId = messageSent.message?.protocolMessage?.key?.id; if (messageId && this.configService.get('DATABASE').SAVE_DATA.NEW_MESSAGE) { let message = await this.prismaRepository.message.findFirst({ where: { key: { path: ['id'], equals: messageId } }, }); if (!message) throw new NotFoundException('Message not found'); if (!(message.key.valueOf() as any).fromMe) { new BadRequestException('You cannot edit others messages'); } if ((message.key.valueOf() as any)?.deleted) { new BadRequestException('You cannot edit deleted messages'); } if (oldMessage.messageType === 'conversation' || oldMessage.messageType === 'extendedTextMessage') { oldMessage.message.conversation = data.text; } else { oldMessage.message[oldMessage.messageType].caption = data.text; } message = await this.prismaRepository.message.update({ where: { id: message.id }, data: { message: oldMessage.message, status: 'EDITED', messageTimestamp: Math.floor(Date.now() / 1000), // Convert to int32 by dividing by 1000 to get seconds }, }); if (this.configService.get('DATABASE').SAVE_DATA.MESSAGE_UPDATE) { const messageUpdate: any = { messageId: message.id, keyId: messageId, remoteJid: messageSent.key.remoteJid, fromMe: messageSent.key.fromMe, participant: messageSent.key?.participant, status: 'EDITED', instanceId: this.instanceId, }; await this.prismaRepository.messageUpdate.create({ data: messageUpdate }); } } } } return messageSent; } catch (error) { this.logger.error(error); throw error; } } public async fetchLabels(): Promise { const labels = await this.prismaRepository.label.findMany({ where: { instanceId: this.instanceId } }); return labels.map((label) => ({ color: label.color, name: label.name, id: label.labelId, predefinedId: label.predefinedId, })); } public async handleLabel(data: HandleLabelDto) { const whatsappContact = await this.whatsappNumber({ numbers: [data.number] }); if (whatsappContact.length === 0) { throw new NotFoundException('Number not found'); } const contact = whatsappContact[0]; if (!contact.exists) { throw new NotFoundException('Number is not on WhatsApp'); } try { if (data.action === 'add') { await this.client.addChatLabel(contact.jid, data.labelId); await this.addLabel(data.labelId, this.instanceId, contact.jid); return { numberJid: contact.jid, labelId: data.labelId, add: true }; } if (data.action === 'remove') { await this.client.removeChatLabel(contact.jid, data.labelId); await this.removeLabel(data.labelId, this.instanceId, contact.jid); return { numberJid: contact.jid, labelId: data.labelId, remove: true }; } } catch (error) { throw new BadRequestException(`Unable to ${data.action} label to chat`, error.toString()); } } // Group private async updateGroupMetadataCache(groupJid: string) { try { const meta = await this.client.groupMetadata(groupJid); const cacheConf = this.configService.get('CACHE'); if ((cacheConf?.REDIS?.ENABLED && cacheConf?.REDIS?.URI !== '') || cacheConf?.LOCAL?.ENABLED) { this.logger.verbose(`Updating cache for group: ${groupJid}`); await groupMetadataCache.set(groupJid, { timestamp: Date.now(), data: meta }); } return meta; } catch (error) { this.logger.error(error); return null; } } private getGroupMetadataCache = async (groupJid: string) => { if (!isJidGroup(groupJid)) return null; const cacheConf = this.configService.get('CACHE'); if ((cacheConf?.REDIS?.ENABLED && cacheConf?.REDIS?.URI !== '') || cacheConf?.LOCAL?.ENABLED) { if (await groupMetadataCache?.has(groupJid)) { console.log(`Cache request for group: ${groupJid}`); const meta = await groupMetadataCache.get(groupJid); if (Date.now() - meta.timestamp > 3600000) { await this.updateGroupMetadataCache(groupJid); } return meta.data; } console.log(`Cache request for group: ${groupJid} - not found`); return await this.updateGroupMetadataCache(groupJid); } return await this.findGroup({ groupJid }, 'inner'); }; public async createGroup(create: CreateGroupDto) { try { const participants = (await this.whatsappNumber({ numbers: create.participants })) .filter((participant) => participant.exists) .map((participant) => participant.jid); const { id } = await this.client.groupCreate(create.subject, participants); if (create?.description) { await this.client.groupUpdateDescription(id, create.description); } if (create?.promoteParticipants) { await this.updateGParticipant({ groupJid: id, action: 'promote', participants: participants }); } const group = await this.client.groupMetadata(id); return group; } catch (error) { this.logger.error(error); throw new InternalServerErrorException('Error creating group', error.toString()); } } public async updateGroupPicture(picture: GroupPictureDto) { try { let pic: WAMediaUpload; if (isURL(picture.image)) { const timestamp = new Date().getTime(); const parsedURL = new URL(picture.image); parsedURL.searchParams.set('timestamp', timestamp.toString()); const url = parsedURL.toString(); let config: any = { responseType: 'arraybuffer' }; if (this.localProxy?.enabled) { config = { ...config, httpsAgent: makeProxyAgent({ host: this.localProxy.host, port: this.localProxy.port, protocol: this.localProxy.protocol, username: this.localProxy.username, password: this.localProxy.password, }), }; } pic = (await axios.get(url, config)).data; } else if (isBase64(picture.image)) { pic = Buffer.from(picture.image, 'base64'); } else { throw new BadRequestException('"profilePicture" must be a url or a base64'); } await this.client.updateProfilePicture(picture.groupJid, pic); return { update: 'success' }; } catch (error) { throw new InternalServerErrorException('Error update group picture', error.toString()); } } public async updateGroupSubject(data: GroupSubjectDto) { try { await this.client.groupUpdateSubject(data.groupJid, data.subject); return { update: 'success' }; } catch (error) { throw new InternalServerErrorException('Error updating group subject', error.toString()); } } public async updateGroupDescription(data: GroupDescriptionDto) { try { await this.client.groupUpdateDescription(data.groupJid, data.description); return { update: 'success' }; } catch (error) { throw new InternalServerErrorException('Error updating group description', error.toString()); } } public async findGroup(id: GroupJid, reply: 'inner' | 'out' = 'out') { try { const group = await this.client.groupMetadata(id.groupJid); if (!group) { this.logger.error('Group not found'); return null; } const picture = await this.profilePicture(group.id); return { id: group.id, subject: group.subject, subjectOwner: group.subjectOwner, subjectTime: group.subjectTime, pictureUrl: picture.profilePictureUrl, size: group.participants.length, creation: group.creation, owner: group.owner, desc: group.desc, descId: group.descId, restrict: group.restrict, announce: group.announce, participants: group.participants, isCommunity: group.isCommunity, isCommunityAnnounce: group.isCommunityAnnounce, linkedParent: group.linkedParent, }; } catch (error) { if (reply === 'inner') { return; } throw new NotFoundException('Error fetching group', error.toString()); } } public async fetchAllGroups(getParticipants: GetParticipant) { const fetch = Object.values(await this?.client?.groupFetchAllParticipating()); let groups = []; for (const group of fetch) { const picture = await this.profilePicture(group.id); const result = { id: group.id, subject: group.subject, subjectOwner: group.subjectOwner, subjectTime: group.subjectTime, pictureUrl: picture?.profilePictureUrl, size: group.participants.length, creation: group.creation, owner: group.owner, desc: group.desc, descId: group.descId, restrict: group.restrict, announce: group.announce, isCommunity: group.isCommunity, isCommunityAnnounce: group.isCommunityAnnounce, linkedParent: group.linkedParent, }; if (getParticipants.getParticipants == 'true') { result['participants'] = group.participants; } groups = [...groups, result]; } return groups; } public async inviteCode(id: GroupJid) { try { const code = await this.client.groupInviteCode(id.groupJid); return { inviteUrl: `https://chat.whatsapp.com/${code}`, inviteCode: code }; } catch (error) { throw new NotFoundException('No invite code', error.toString()); } } public async inviteInfo(id: GroupInvite) { try { return await this.client.groupGetInviteInfo(id.inviteCode); } catch { throw new NotFoundException('No invite info', id.inviteCode); } } public async sendInvite(id: GroupSendInvite) { try { const inviteCode = await this.inviteCode({ groupJid: id.groupJid }); const inviteUrl = inviteCode.inviteUrl; const numbers = id.numbers.map((number) => createJid(number)); const description = id.description ?? ''; const msg = `${description}\n\n${inviteUrl}`; const message = { conversation: msg }; for await (const number of numbers) { await this.sendMessageWithTyping(number, message); } return { send: true, inviteUrl }; } catch { throw new NotFoundException('No send invite'); } } public async acceptInviteCode(id: AcceptGroupInvite) { try { const groupJid = await this.client.groupAcceptInvite(id.inviteCode); return { accepted: true, groupJid: groupJid }; } catch (error) { throw new NotFoundException('Accept invite error', error.toString()); } } public async revokeInviteCode(id: GroupJid) { try { const inviteCode = await this.client.groupRevokeInvite(id.groupJid); return { revoked: true, inviteCode }; } catch (error) { throw new NotFoundException('Revoke error', error.toString()); } } public async findParticipants(id: GroupJid) { try { const participants = (await this.client.groupMetadata(id.groupJid)).participants; const contacts = await this.prismaRepository.contact.findMany({ where: { instanceId: this.instanceId, remoteJid: { in: participants.map((p) => p.id) } }, }); const parsedParticipants = participants.map((participant) => { const contact = contacts.find((c) => c.remoteJid === participant.id); return { ...participant, name: participant.name ?? contact?.pushName, imgUrl: participant.imgUrl ?? contact?.profilePicUrl, }; }); const usersContacts = parsedParticipants.filter((c) => c.id.includes('@s.whatsapp')); if (usersContacts) { await saveOnWhatsappCache(usersContacts.map((c) => ({ remoteJid: c.id }))); } return { participants: parsedParticipants }; } catch (error) { console.error(error); throw new NotFoundException('No participants', error.toString()); } } public async updateGParticipant(update: GroupUpdateParticipantDto) { try { const participants = update.participants.map((p) => createJid(p)); const updateParticipants = await this.client.groupParticipantsUpdate( update.groupJid, participants, update.action, ); return { updateParticipants: updateParticipants }; } catch (error) { throw new BadRequestException('Error updating participants', error.toString()); } } public async updateGSetting(update: GroupUpdateSettingDto) { try { const updateSetting = await this.client.groupSettingUpdate(update.groupJid, update.action); return { updateSetting: updateSetting }; } catch (error) { throw new BadRequestException('Error updating setting', error.toString()); } } public async toggleEphemeral(update: GroupToggleEphemeralDto) { try { await this.client.groupToggleEphemeral(update.groupJid, update.expiration); return { success: true }; } catch (error) { throw new BadRequestException('Error updating setting', error.toString()); } } public async leaveGroup(id: GroupJid) { try { await this.client.groupLeave(id.groupJid); return { groupJid: id.groupJid, leave: true }; } catch (error) { throw new BadRequestException('Unable to leave the group', error.toString()); } } public async templateMessage() { throw new Error('Method not available in the Baileys service'); } private deserializeMessageBuffers(obj: any): any { if (obj === null || obj === undefined) { return obj; } if (typeof obj === 'object' && !Array.isArray(obj) && !Buffer.isBuffer(obj)) { const keys = Object.keys(obj); const isIndexedObject = keys.every((key) => !isNaN(Number(key))); if (isIndexedObject && keys.length > 0) { const values = keys.sort((a, b) => Number(a) - Number(b)).map((key) => obj[key]); return new Uint8Array(values); } } // Is Buffer?, converter to Uint8Array if (Buffer.isBuffer(obj)) { return new Uint8Array(obj); } // Process arrays recursively if (Array.isArray(obj)) { return obj.map((item) => this.deserializeMessageBuffers(item)); } // Process objects recursively if (typeof obj === 'object') { const converted: any = {}; for (const key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { converted[key] = this.deserializeMessageBuffers(obj[key]); } } return converted; } return obj; } private prepareMessage(message: proto.IWebMessageInfo): any { const contentType = getContentType(message.message); const contentMsg = message?.message[contentType] as any; const messageRaw = { key: message.key, // Save key exactly as it comes from Baileys pushName: message.pushName || (message.key.fromMe ? 'Você' : message?.participant || (message.key?.participant ? message.key.participant.split('@')[0] : null)), status: status[message.status], message: this.deserializeMessageBuffers({ ...message.message }), contextInfo: this.deserializeMessageBuffers(contentMsg?.contextInfo), messageType: contentType || 'unknown', messageTimestamp: Long.isLong(message.messageTimestamp) ? message.messageTimestamp.toNumber() : (message.messageTimestamp as number), instanceId: this.instanceId, source: getDevice(message.key.id), }; if (!messageRaw.status && message.key.fromMe === false) { messageRaw.status = status[3]; // DELIVERED MESSAGE } if (messageRaw.message.extendedTextMessage) { messageRaw.messageType = 'conversation'; messageRaw.message.conversation = messageRaw.message.extendedTextMessage.text; delete messageRaw.message.extendedTextMessage; } if (messageRaw.message.documentWithCaptionMessage) { messageRaw.messageType = 'documentMessage'; messageRaw.message.documentMessage = messageRaw.message.documentWithCaptionMessage.message.documentMessage; delete messageRaw.message.documentWithCaptionMessage; } const quotedMessage = messageRaw?.contextInfo?.quotedMessage; if (quotedMessage) { if (quotedMessage.extendedTextMessage) { quotedMessage.conversation = quotedMessage.extendedTextMessage.text; delete quotedMessage.extendedTextMessage; } if (quotedMessage.documentWithCaptionMessage) { quotedMessage.documentMessage = quotedMessage.documentWithCaptionMessage.message.documentMessage; delete quotedMessage.documentWithCaptionMessage; } } return messageRaw; } private async syncChatwootLostMessages() { if (this.configService.get('CHATWOOT').ENABLED && this.localChatwoot?.enabled) { const chatwootConfig = await this.findChatwoot(); const prepare = (message: any) => this.prepareMessage(message); this.chatwootService.syncLostMessages({ instanceName: this.instance.name }, chatwootConfig, prepare); // Generate ID for this cron task and store in cache const cronId = cuid(); const cronKey = `chatwoot:syncLostMessages`; await this.chatwootService.getCache()?.hSet(cronKey, this.instance.name, cronId); const task = cron.schedule('0,30 * * * *', async () => { // Check ID before executing (only if cache is available) const cache = this.chatwootService.getCache(); if (cache) { const storedId = await cache.hGet(cronKey, this.instance.name); if (storedId && storedId !== cronId) { this.logger.info(`Stopping syncChatwootLostMessages cron - ID mismatch: ${cronId} vs ${storedId}`); task.stop(); return; } } this.chatwootService.syncLostMessages({ instanceName: this.instance.name }, chatwootConfig, prepare); }); task.start(); } } private async updateMessagesReadedByTimestamp(remoteJid: string, timestamp?: number): Promise { if (timestamp === undefined || timestamp === null) return 0; // Use raw SQL to avoid JSON path issues const result = await this.prismaRepository.$executeRaw` UPDATE "Message" SET "status" = ${status[4]} WHERE "instanceId" = ${this.instanceId} AND "key"->>'remoteJid' = ${remoteJid} AND ("key"->>'fromMe')::boolean = false AND "messageTimestamp" <= ${timestamp} AND ("status" IS NULL OR "status" = ${status[3]}) `; if (result) { if (result > 0) { this.updateChatUnreadMessages(remoteJid); } return result; } return 0; } private async updateChatUnreadMessages(remoteJid: string): Promise { const [chat, unreadMessages] = await Promise.all([ this.prismaRepository.chat.findFirst({ where: { remoteJid } }), // Use raw SQL to avoid JSON path issues this.prismaRepository.$queryRaw` SELECT COUNT(*)::int as count FROM "Message" WHERE "instanceId" = ${this.instanceId} AND "key"->>'remoteJid' = ${remoteJid} AND ("key"->>'fromMe')::boolean = false AND "status" = ${status[3]} `.then((result: any[]) => result[0]?.count || 0), ]); if (chat && chat.unreadMessages !== unreadMessages) { await this.prismaRepository.chat.update({ where: { id: chat.id }, data: { unreadMessages } }); } return unreadMessages; } private async addLabel(labelId: string, instanceId: string, chatId: string) { const id = cuid(); await this.prismaRepository.$executeRawUnsafe( `INSERT INTO "Chat" ("id", "instanceId", "remoteJid", "labels", "createdAt", "updatedAt") VALUES ($4, $2, $3, to_jsonb(ARRAY[$1]::text[]), NOW(), NOW()) ON CONFLICT ("instanceId", "remoteJid") DO UPDATE SET "labels" = ( SELECT to_jsonb(array_agg(DISTINCT elem)) FROM ( SELECT jsonb_array_elements_text("Chat"."labels") AS elem UNION SELECT $1::text AS elem ) sub ), "updatedAt" = NOW();`, labelId, instanceId, chatId, id, ); } private async removeLabel(labelId: string, instanceId: string, chatId: string) { const id = cuid(); await this.prismaRepository.$executeRawUnsafe( `INSERT INTO "Chat" ("id", "instanceId", "remoteJid", "labels", "createdAt", "updatedAt") VALUES ($4, $2, $3, '[]'::jsonb, NOW(), NOW()) ON CONFLICT ("instanceId", "remoteJid") DO UPDATE SET "labels" = COALESCE ( ( SELECT jsonb_agg(elem) FROM jsonb_array_elements_text("Chat"."labels") AS elem WHERE elem <> $1 ), '[]'::jsonb ), "updatedAt" = NOW();`, labelId, instanceId, chatId, id, ); } public async baileysOnWhatsapp(jid: string) { const response = await this.client.onWhatsApp(jid); return response; } public async baileysProfilePictureUrl(jid: string, type: 'image' | 'preview', timeoutMs: number) { const response = await this.client.profilePictureUrl(jid, type, timeoutMs); return response; } public async baileysAssertSessions(jids: string[]) { const response = await this.client.assertSessions(jids); return response; } public async baileysCreateParticipantNodes(jids: string[], message: proto.IMessage, extraAttrs: any) { const response = await this.client.createParticipantNodes(jids, message, extraAttrs); const convertedResponse = { ...response, nodes: response.nodes.map((node: any) => ({ ...node, content: node.content?.map((c: any) => ({ ...c, content: c.content instanceof Uint8Array ? Buffer.from(c.content).toString('base64') : c.content, })), })), }; return convertedResponse; } public async baileysSendNode(stanza: any) { console.log('stanza', JSON.stringify(stanza)); const response = await this.client.sendNode(stanza); return response; } public async baileysGetUSyncDevices(jids: string[], useCache: boolean, ignoreZeroDevices: boolean) { const response = await this.client.getUSyncDevices(jids, useCache, ignoreZeroDevices); return response; } public async baileysGenerateMessageTag() { const response = await this.client.generateMessageTag(); return response; } public async baileysSignalRepositoryDecryptMessage(jid: string, type: 'pkmsg' | 'msg', ciphertext: string) { try { const ciphertextBuffer = Buffer.from(ciphertext, 'base64'); const response = await this.client.signalRepository.decryptMessage({ jid, type, ciphertext: ciphertextBuffer }); return response instanceof Uint8Array ? Buffer.from(response).toString('base64') : response; } catch (error) { this.logger.error('Error decrypting message:'); this.logger.error(error); throw error; } } public async baileysGetAuthState() { const response = { me: this.client.authState.creds.me, account: this.client.authState.creds.account }; return response; } //Business Controller public async fetchCatalog(instanceName: string, data: getCollectionsDto) { const jid = data.number ? createJid(data.number) : this.client?.user?.id; const limit = data.limit || 10; const cursor = null; const onWhatsapp = (await this.whatsappNumber({ numbers: [jid] }))?.shift(); if (!onWhatsapp.exists) { throw new BadRequestException(onWhatsapp); } try { const info = (await this.whatsappNumber({ numbers: [jid] }))?.shift(); const business = await this.fetchBusinessProfile(info?.jid); let catalog = await this.getCatalog({ jid: info?.jid, limit, cursor }); let nextPageCursor = catalog.nextPageCursor; let nextPageCursorJson = nextPageCursor ? JSON.parse(atob(nextPageCursor)) : null; let pagination = nextPageCursorJson?.pagination_cursor ? JSON.parse(atob(nextPageCursorJson.pagination_cursor)) : null; let fetcherHasMore = pagination?.fetcher_has_more === true ? true : false; let productsCatalog = catalog.products || []; let countLoops = 0; while (fetcherHasMore && countLoops < 4) { catalog = await this.getCatalog({ jid: info?.jid, limit, cursor: nextPageCursor }); nextPageCursor = catalog.nextPageCursor; nextPageCursorJson = nextPageCursor ? JSON.parse(atob(nextPageCursor)) : null; pagination = nextPageCursorJson?.pagination_cursor ? JSON.parse(atob(nextPageCursorJson.pagination_cursor)) : null; fetcherHasMore = pagination?.fetcher_has_more === true ? true : false; productsCatalog = [...productsCatalog, ...catalog.products]; countLoops++; } return { wuid: info?.jid || jid, numberExists: info?.exists, isBusiness: business.isBusiness, catalogLength: productsCatalog.length, catalog: productsCatalog, }; } catch (error) { console.log(error); return { wuid: jid, name: null, isBusiness: false }; } } public async getCatalog({ jid, limit, cursor, }: GetCatalogOptions): Promise<{ products: Product[]; nextPageCursor: string | undefined }> { try { jid = jid ? createJid(jid) : this.instance.wuid; const catalog = await this.client.getCatalog({ jid, limit: limit, cursor: cursor }); if (!catalog) { return { products: undefined, nextPageCursor: undefined }; } return catalog; } catch (error) { throw new InternalServerErrorException('Error getCatalog', error.toString()); } } public async fetchCollections(instanceName: string, data: getCollectionsDto) { const jid = data.number ? createJid(data.number) : this.client?.user?.id; const limit = data.limit <= 20 ? data.limit : 20; //(tem esse limite, não sei porque) const onWhatsapp = (await this.whatsappNumber({ numbers: [jid] }))?.shift(); if (!onWhatsapp.exists) { throw new BadRequestException(onWhatsapp); } try { const info = (await this.whatsappNumber({ numbers: [jid] }))?.shift(); const business = await this.fetchBusinessProfile(info?.jid); const collections = await this.getCollections(info?.jid, limit); return { wuid: info?.jid || jid, name: info?.name, numberExists: info?.exists, isBusiness: business.isBusiness, collectionsLength: collections?.length, collections: collections, }; } catch { return { wuid: jid, name: null, isBusiness: false }; } } public async getCollections(jid?: string | undefined, limit?: number): Promise { try { jid = jid ? createJid(jid) : this.instance.wuid; const result = await this.client.getCollections(jid, limit); if (!result) { return [{ id: undefined, name: undefined, products: [], status: undefined }]; } return result.collections; } catch (error) { throw new InternalServerErrorException('Error getCatalog', error.toString()); } } public async fetchMessages(query: Query) { const keyFilters = query?.where?.key as ExtendedIMessageKey; const timestampFilter = {}; if (query?.where?.messageTimestamp) { if (query.where.messageTimestamp['gte'] && query.where.messageTimestamp['lte']) { timestampFilter['messageTimestamp'] = { gte: Math.floor(new Date(query.where.messageTimestamp['gte']).getTime() / 1000), lte: Math.floor(new Date(query.where.messageTimestamp['lte']).getTime() / 1000), }; } } const count = await this.prismaRepository.message.count({ where: { instanceId: this.instanceId, id: query?.where?.id, source: query?.where?.source, messageType: query?.where?.messageType, ...timestampFilter, AND: [ keyFilters?.id ? { key: { path: ['id'], equals: keyFilters?.id } } : {}, keyFilters?.fromMe ? { key: { path: ['fromMe'], equals: keyFilters?.fromMe } } : {}, keyFilters?.participant ? { key: { path: ['participant'], equals: keyFilters?.participant } } : {}, { OR: [ keyFilters?.remoteJid ? { key: { path: ['remoteJid'], equals: keyFilters?.remoteJid } } : {}, keyFilters?.remoteJidAlt ? { key: { path: ['remoteJidAlt'], equals: keyFilters?.remoteJidAlt } } : {}, ], }, ], }, }); if (!query?.offset) { query.offset = 50; } if (!query?.page) { query.page = 1; } const messages = await this.prismaRepository.message.findMany({ where: { instanceId: this.instanceId, id: query?.where?.id, source: query?.where?.source, messageType: query?.where?.messageType, ...timestampFilter, AND: [ keyFilters?.id ? { key: { path: ['id'], equals: keyFilters?.id } } : {}, keyFilters?.fromMe ? { key: { path: ['fromMe'], equals: keyFilters?.fromMe } } : {}, keyFilters?.participant ? { key: { path: ['participant'], equals: keyFilters?.participant } } : {}, { OR: [ keyFilters?.remoteJid ? { key: { path: ['remoteJid'], equals: keyFilters?.remoteJid } } : {}, keyFilters?.remoteJidAlt ? { key: { path: ['remoteJidAlt'], equals: keyFilters?.remoteJidAlt } } : {}, ], }, ], }, orderBy: { messageTimestamp: 'desc' }, skip: query.offset * (query?.page === 1 ? 0 : (query?.page as number) - 1), take: query.offset, select: { id: true, key: true, pushName: true, messageType: true, message: true, messageTimestamp: true, instanceId: true, source: true, contextInfo: true, MessageUpdate: { select: { status: true } }, }, }); const formattedMessages = messages.map((message) => { const messageKey = message.key as { fromMe: boolean; remoteJid: string; id: string; participant?: string }; if (!message.pushName) { if (messageKey.fromMe) { message.pushName = 'Você'; } else if (message.contextInfo) { const contextInfo = message.contextInfo as { participant?: string }; if (contextInfo.participant) { message.pushName = contextInfo.participant.split('@')[0]; } else if (messageKey.participant) { message.pushName = messageKey.participant.split('@')[0]; } } } return message; }); return { messages: { total: count, pages: Math.ceil(count / query.offset), currentPage: query.page, records: formattedMessages, }, }; } } ================================================ FILE: src/api/integrations/chatbot/base-chatbot.controller.ts ================================================ import { IgnoreJidDto } from '@api/dto/chatbot.dto'; import { InstanceDto } from '@api/dto/instance.dto'; import { PrismaRepository } from '@api/repository/repository.service'; import { WAMonitoringService } from '@api/services/monitor.service'; import { Events } from '@api/types/wa.types'; import { Logger } from '@config/logger.config'; import { BadRequestException } from '@exceptions'; import { TriggerOperator, TriggerType } from '@prisma/client'; import { getConversationMessage } from '@utils/getConversationMessage'; import { BaseChatbotDto } from './base-chatbot.dto'; import { ChatbotController, ChatbotControllerInterface, EmitData } from './chatbot.controller'; // Common settings interface for all chatbot integrations export interface ChatbotSettings { expire: number; keywordFinish: string; delayMessage: number; unknownMessage: string; listeningFromMe: boolean; stopBotFromMe: boolean; keepOpen: boolean; debounceTime: number; ignoreJids: string[]; splitMessages: boolean; timePerChar: number; [key: string]: any; } // Common bot properties for all chatbot integrations export interface BaseBotData { enabled?: boolean; description: string; expire?: number; keywordFinish?: string; delayMessage?: number; unknownMessage?: string; listeningFromMe?: boolean; stopBotFromMe?: boolean; keepOpen?: boolean; debounceTime?: number; triggerType: string | TriggerType; triggerOperator?: string | TriggerOperator; triggerValue?: string; ignoreJids?: string[]; splitMessages?: boolean; timePerChar?: number; [key: string]: any; } export abstract class BaseChatbotController extends ChatbotController implements ChatbotControllerInterface { public readonly logger: Logger; integrationEnabled: boolean; botRepository: any; settingsRepository: any; sessionRepository: any; userMessageDebounce: { [key: string]: { message: string; timeoutId: NodeJS.Timeout } } = {}; // Name of the integration, to be set by the derived class protected abstract readonly integrationName: string; // Method to process bot-specific logic protected abstract processBot( waInstance: any, remoteJid: string, bot: BotType, session: any, settings: ChatbotSettings, content: string, pushName?: string, msg?: any, ): Promise; // Method to get the fallback bot ID from settings protected abstract getFallbackBotId(settings: any): string | undefined; constructor(prismaRepository: PrismaRepository, waMonitor: WAMonitoringService) { super(prismaRepository, waMonitor); this.sessionRepository = this.prismaRepository.integrationSession; } // Base create bot implementation public async createBot(instance: InstanceDto, data: BotData) { if (!this.integrationEnabled) throw new BadRequestException(`${this.integrationName} is disabled`); const instanceId = await this.prismaRepository.instance .findFirst({ where: { name: instance.instanceName, }, }) .then((instance) => instance.id); // Set default settings if not provided if ( !data.expire || !data.keywordFinish || !data.delayMessage || !data.unknownMessage || !data.listeningFromMe || !data.stopBotFromMe || !data.keepOpen || !data.debounceTime || !data.ignoreJids || !data.splitMessages || !data.timePerChar ) { const defaultSettingCheck = await this.settingsRepository.findFirst({ where: { instanceId: instanceId, }, }); if (data.expire === undefined || data.expire === null) data.expire = defaultSettingCheck?.expire; if (data.keywordFinish === undefined || data.keywordFinish === null) data.keywordFinish = defaultSettingCheck?.keywordFinish; if (data.delayMessage === undefined || data.delayMessage === null) data.delayMessage = defaultSettingCheck?.delayMessage; if (data.unknownMessage === undefined || data.unknownMessage === null) data.unknownMessage = defaultSettingCheck?.unknownMessage; if (data.listeningFromMe === undefined || data.listeningFromMe === null) data.listeningFromMe = defaultSettingCheck?.listeningFromMe; if (data.stopBotFromMe === undefined || data.stopBotFromMe === null) data.stopBotFromMe = defaultSettingCheck?.stopBotFromMe; if (data.keepOpen === undefined || data.keepOpen === null) data.keepOpen = defaultSettingCheck?.keepOpen; if (data.debounceTime === undefined || data.debounceTime === null) data.debounceTime = defaultSettingCheck?.debounceTime; if (data.ignoreJids === undefined || data.ignoreJids === null) data.ignoreJids = defaultSettingCheck?.ignoreJids; if (data.splitMessages === undefined || data.splitMessages === null) data.splitMessages = defaultSettingCheck?.splitMessages ?? false; if (data.timePerChar === undefined || data.timePerChar === null) data.timePerChar = defaultSettingCheck?.timePerChar ?? 0; if (!defaultSettingCheck) { await this.settings(instance, { expire: data.expire, keywordFinish: data.keywordFinish, delayMessage: data.delayMessage, unknownMessage: data.unknownMessage, listeningFromMe: data.listeningFromMe, stopBotFromMe: data.stopBotFromMe, keepOpen: data.keepOpen, debounceTime: data.debounceTime, ignoreJids: data.ignoreJids, splitMessages: data.splitMessages, timePerChar: data.timePerChar, }); } } const checkTriggerAll = await this.botRepository.findFirst({ where: { enabled: true, triggerType: 'all', instanceId: instanceId, }, }); if (checkTriggerAll && data.triggerType === 'all') { throw new Error( `You already have a ${this.integrationName} with an "All" trigger, you cannot have more bots while it is active`, ); } // Check for trigger keyword duplicates if (data.triggerType === 'keyword') { if (!data.triggerOperator || !data.triggerValue) { throw new Error('Trigger operator and value are required'); } const checkDuplicate = await this.botRepository.findFirst({ where: { triggerOperator: data.triggerOperator, triggerValue: data.triggerValue, instanceId: instanceId, }, }); if (checkDuplicate) { throw new Error('Trigger already exists'); } } // Check for trigger advanced duplicates if (data.triggerType === 'advanced') { if (!data.triggerValue) { throw new Error('Trigger value is required'); } const checkDuplicate = await this.botRepository.findFirst({ where: { triggerValue: data.triggerValue, instanceId: instanceId, }, }); if (checkDuplicate) { throw new Error('Trigger already exists'); } } // Derived classes should implement the specific duplicate checking before calling this method // and add bot-specific fields to the data object try { const botData = { enabled: data?.enabled, description: data.description, expire: data.expire, keywordFinish: data.keywordFinish, delayMessage: data.delayMessage, unknownMessage: data.unknownMessage, listeningFromMe: data.listeningFromMe, stopBotFromMe: data.stopBotFromMe, keepOpen: data.keepOpen, debounceTime: data.debounceTime, instanceId: instanceId, triggerType: data.triggerType, triggerOperator: data.triggerOperator, triggerValue: data.triggerValue, ignoreJids: data.ignoreJids, splitMessages: data.splitMessages, timePerChar: data.timePerChar, ...this.getAdditionalBotData(data), }; const bot = await this.botRepository.create({ data: botData, }); return bot; } catch (error) { this.logger.error(error); throw new Error(`Error creating ${this.integrationName}`); } } // Additional fields needed for specific bot types protected abstract getAdditionalBotData(data: BotData): Record; // Common implementation for findBot public async findBot(instance: InstanceDto) { if (!this.integrationEnabled) throw new BadRequestException(`${this.integrationName} is disabled`); const instanceId = await this.prismaRepository.instance .findFirst({ where: { name: instance.instanceName, }, }) .then((instance) => instance.id); try { const bots = await this.botRepository.findMany({ where: { instanceId: instanceId, }, }); return bots; } catch (error) { this.logger.error(error); throw new Error(`Error finding ${this.integrationName}`); } } // Common implementation for fetchBot public async fetchBot(instance: InstanceDto, botId: string) { if (!this.integrationEnabled) throw new BadRequestException(`${this.integrationName} is disabled`); try { const bot = await this.botRepository.findUnique({ where: { id: botId, }, }); if (!bot) { return null; } return bot; } catch (error) { this.logger.error(error); throw new Error(`Error fetching ${this.integrationName}`); } } // Common implementation for settings public async settings(instance: InstanceDto, data: any) { if (!this.integrationEnabled) throw new BadRequestException(`${this.integrationName} is disabled`); try { const instanceId = await this.prismaRepository.instance .findFirst({ where: { name: instance.instanceName, }, }) .then((instance) => instance.id); const existingSettings = await this.settingsRepository.findFirst({ where: { instanceId: instanceId, }, }); // Get the name of the fallback field for this integration type const fallbackFieldName = this.getFallbackFieldName(); const settingsData = { expire: data.expire, keywordFinish: data.keywordFinish, delayMessage: data.delayMessage, unknownMessage: data.unknownMessage, listeningFromMe: data.listeningFromMe, stopBotFromMe: data.stopBotFromMe, keepOpen: data.keepOpen, debounceTime: data.debounceTime, ignoreJids: data.ignoreJids, splitMessages: data.splitMessages, timePerChar: data.timePerChar, [fallbackFieldName]: data.fallbackId, // Use the correct field name dynamically }; if (existingSettings) { const settings = await this.settingsRepository.update({ where: { id: existingSettings.id, }, data: settingsData, }); // Map the specific fallback field to a generic 'fallbackId' in the response return { ...settings, fallbackId: settings[fallbackFieldName], }; } else { const settings = await this.settingsRepository.create({ data: { ...settingsData, Instance: { connect: { id: instanceId, }, }, }, }); // Map the specific fallback field to a generic 'fallbackId' in the response return { ...settings, fallbackId: settings[fallbackFieldName], }; } } catch (error) { this.logger.error(error); throw new Error('Error setting default settings'); } } // Abstract method to get the field name for the fallback ID protected abstract getFallbackFieldName(): string; // Abstract method to get the integration type (dify, n8n, evoai, etc.) protected abstract getIntegrationType(): string; // Common implementation for fetchSettings public async fetchSettings(instance: InstanceDto) { if (!this.integrationEnabled) throw new BadRequestException(`${this.integrationName} is disabled`); try { const instanceId = await this.prismaRepository.instance .findFirst({ where: { name: instance.instanceName, }, }) .then((instance) => instance.id); const settings = await this.settingsRepository.findFirst({ where: { instanceId: instanceId, }, include: { Fallback: true, }, }); // Get the name of the fallback field for this integration type const fallbackFieldName = this.getFallbackFieldName(); if (!settings) { return { expire: 300, keywordFinish: 'bye', delayMessage: 1000, unknownMessage: 'Sorry, I dont understand', listeningFromMe: true, stopBotFromMe: true, keepOpen: false, debounceTime: 1, ignoreJids: [], splitMessages: false, timePerChar: 0, fallbackId: '', fallback: null, }; } // Return with standardized fallbackId field return { ...settings, fallbackId: settings[fallbackFieldName], fallback: settings.Fallback, }; } catch (error) { this.logger.error(error); throw new Error('Error fetching settings'); } } // Common implementation for changeStatus public async changeStatus(instance: InstanceDto, data: any) { if (!this.integrationEnabled) throw new BadRequestException(`${this.integrationName} is disabled`); try { const instanceId = await this.prismaRepository.instance .findFirst({ where: { name: instance.instanceName, }, }) .then((instance) => instance.id); const defaultSettingCheck = await this.settingsRepository.findFirst({ where: { instanceId, }, }); const remoteJid = data.remoteJid; const status = data.status; const session = await this.getSession(remoteJid, instance); if (this.integrationName === 'Typebot') { const typebotData = { remoteJid: remoteJid, status: status, session, }; this.waMonitor.waInstances[instance.instanceName].sendDataWebhook(Events.TYPEBOT_CHANGE_STATUS, typebotData); } if (status === 'delete') { await this.sessionRepository.deleteMany({ where: { remoteJid: remoteJid, botId: { not: null }, }, }); return { bot: { remoteJid: remoteJid, status: status } }; } if (status === 'closed') { if (defaultSettingCheck?.keepOpen) { await this.sessionRepository.updateMany({ where: { remoteJid: remoteJid, botId: { not: null }, }, data: { status: 'closed', }, }); } else { await this.sessionRepository.deleteMany({ where: { remoteJid: remoteJid, botId: { not: null }, }, }); } return { bot: { ...instance, bot: { remoteJid: remoteJid, status: status } } }; } else { const session = await this.sessionRepository.updateMany({ where: { instanceId: instanceId, remoteJid: remoteJid, botId: { not: null }, }, data: { status: status, }, }); const botData = { remoteJid: remoteJid, status: status, session, }; return { bot: { ...instance, bot: botData } }; } } catch (error) { this.logger.error(error); throw new Error(`Error changing ${this.integrationName} status`); } } // Common implementation for fetchSessions public async fetchSessions(instance: InstanceDto, botId: string, remoteJid?: string) { if (!this.integrationEnabled) throw new BadRequestException(`${this.integrationName} is disabled`); try { const instanceId = await this.prismaRepository.instance .findFirst({ where: { name: instance.instanceName, }, }) .then((instance) => instance.id); const bot = await this.botRepository.findFirst({ where: { id: botId, }, }); if (bot && bot.instanceId !== instanceId) { throw new Error(`${this.integrationName} not found`); } // Get the integration type (dify, n8n, evoai, etc.) const integrationType = this.getIntegrationType(); return await this.sessionRepository.findMany({ where: { instanceId: instanceId, remoteJid, botId: bot ? botId : { not: null }, type: integrationType, }, }); } catch (error) { this.logger.error(error); throw new Error('Error fetching sessions'); } } // Common implementation for ignoreJid public async ignoreJid(instance: InstanceDto, data: IgnoreJidDto) { if (!this.integrationEnabled) throw new BadRequestException(`${this.integrationName} is disabled`); try { const instanceId = await this.prismaRepository.instance .findFirst({ where: { name: instance.instanceName, }, }) .then((instance) => instance.id); const settings = await this.settingsRepository.findFirst({ where: { instanceId: instanceId, }, }); if (!settings) { throw new Error('Settings not found'); } let ignoreJids: any = settings?.ignoreJids || []; if (data.action === 'add') { if (ignoreJids.includes(data.remoteJid)) return { ignoreJids: ignoreJids }; ignoreJids.push(data.remoteJid); } else { ignoreJids = ignoreJids.filter((jid) => jid !== data.remoteJid); } const updateSettings = await this.settingsRepository.update({ where: { id: settings.id, }, data: { ignoreJids: ignoreJids, }, }); return { ignoreJids: updateSettings.ignoreJids, }; } catch (error) { this.logger.error(error); throw new Error('Error setting default settings'); } } // Base implementation for updateBot public async updateBot(instance: InstanceDto, botId: string, data: BotData) { if (!this.integrationEnabled) throw new BadRequestException(`${this.integrationName} is disabled`); try { const instanceId = await this.prismaRepository.instance .findFirst({ where: { name: instance.instanceName, }, }) .then((instance) => instance.id); const bot = await this.botRepository.findFirst({ where: { id: botId, }, }); if (!bot) { throw new Error(`${this.integrationName} not found`); } if (bot.instanceId !== instanceId) { throw new Error(`${this.integrationName} not found`); } // Check for "all" trigger type conflicts if (data.triggerType === 'all') { const checkTriggerAll = await this.botRepository.findFirst({ where: { enabled: true, triggerType: 'all', id: { not: botId, }, instanceId: instanceId, }, }); if (checkTriggerAll) { throw new Error( `You already have a ${this.integrationName} with an "All" trigger, you cannot have more bots while it is active`, ); } } // Let subclasses check for integration-specific duplicates await this.validateNoDuplicatesOnUpdate(botId, instanceId, data); // Check for keyword trigger duplicates if (data.triggerType === 'keyword') { if (!data.triggerOperator || !data.triggerValue) { throw new Error('Trigger operator and value are required'); } const checkDuplicate = await this.botRepository.findFirst({ where: { triggerOperator: data.triggerOperator, triggerValue: data.triggerValue, id: { not: botId }, instanceId: instanceId, }, }); if (checkDuplicate) { throw new Error('Trigger already exists'); } } // Check for advanced trigger duplicates if (data.triggerType === 'advanced') { if (!data.triggerValue) { throw new Error('Trigger value is required'); } const checkDuplicate = await this.botRepository.findFirst({ where: { triggerValue: data.triggerValue, id: { not: botId }, instanceId: instanceId, }, }); if (checkDuplicate) { throw new Error('Trigger already exists'); } } // Combine common fields with bot-specific fields const updateData = { enabled: data?.enabled, description: data.description, expire: data.expire, keywordFinish: data.keywordFinish, delayMessage: data.delayMessage, unknownMessage: data.unknownMessage, listeningFromMe: data.listeningFromMe, stopBotFromMe: data.stopBotFromMe, keepOpen: data.keepOpen, debounceTime: data.debounceTime, instanceId: instanceId, triggerType: data.triggerType, triggerOperator: data.triggerOperator, triggerValue: data.triggerValue, ignoreJids: data.ignoreJids, splitMessages: data.splitMessages, timePerChar: data.timePerChar, ...this.getAdditionalUpdateFields(data), }; const updatedBot = await this.botRepository.update({ where: { id: botId, }, data: updateData, }); return updatedBot; } catch (error) { this.logger.error(error); throw new Error(`Error updating ${this.integrationName}`); } } // Abstract method for validating bot-specific duplicates on update protected abstract validateNoDuplicatesOnUpdate(botId: string, instanceId: string, data: BotData): Promise; // Abstract method for getting additional fields for update protected abstract getAdditionalUpdateFields(data: BotData): Record; // Base implementation for deleteBot public async deleteBot(instance: InstanceDto, botId: string) { if (!this.integrationEnabled) throw new BadRequestException(`${this.integrationName} is disabled`); try { const instanceId = await this.prismaRepository.instance .findFirst({ where: { name: instance.instanceName, }, }) .then((instance) => instance.id); const bot = await this.botRepository.findFirst({ where: { id: botId, }, }); if (!bot) { throw new Error(`${this.integrationName} not found`); } if (bot.instanceId !== instanceId) { throw new Error(`${this.integrationName} not found`); } await this.prismaRepository.integrationSession.deleteMany({ where: { botId: botId, }, }); await this.botRepository.delete({ where: { id: botId, }, }); return { bot: { id: botId } }; } catch (error) { this.logger.error(error); throw new Error(`Error deleting ${this.integrationName} bot`); } } // Base implementation for emit public async emit({ instance, remoteJid, msg }: EmitData) { if (!this.integrationEnabled) return; try { const settings = await this.settingsRepository.findFirst({ where: { instanceId: instance.instanceId, }, }); if (this.checkIgnoreJids(settings?.ignoreJids, remoteJid)) return; const session = await this.getSession(remoteJid, instance); const content = getConversationMessage(msg); // Get integration type // const integrationType = this.getIntegrationType(); // Find a bot for this message let findBot: any = await this.findBotTrigger(this.botRepository, content, instance, session); // If no bot is found, try to use fallback if (!findBot) { const fallback = await this.settingsRepository.findFirst({ where: { instanceId: instance.instanceId, }, }); // Get the fallback ID for this integration type const fallbackId = this.getFallbackBotId(fallback); if (fallbackId) { const findFallback = await this.botRepository.findFirst({ where: { id: fallbackId, }, }); findBot = findFallback; } else { return; } } // If we still don't have a bot, return if (!findBot) { return; } // Collect settings with fallbacks to default settings let expire = findBot.expire; let keywordFinish = findBot.keywordFinish; let delayMessage = findBot.delayMessage; let unknownMessage = findBot.unknownMessage; let listeningFromMe = findBot.listeningFromMe; let stopBotFromMe = findBot.stopBotFromMe; let keepOpen = findBot.keepOpen; let debounceTime = findBot.debounceTime; let ignoreJids = findBot.ignoreJids; let splitMessages = findBot.splitMessages; let timePerChar = findBot.timePerChar; if (expire === undefined || expire === null) expire = settings.expire; if (keywordFinish === undefined || keywordFinish === null) keywordFinish = settings.keywordFinish; if (delayMessage === undefined || delayMessage === null) delayMessage = settings.delayMessage; if (unknownMessage === undefined || unknownMessage === null) unknownMessage = settings.unknownMessage; if (listeningFromMe === undefined || listeningFromMe === null) listeningFromMe = settings.listeningFromMe; if (stopBotFromMe === undefined || stopBotFromMe === null) stopBotFromMe = settings.stopBotFromMe; if (keepOpen === undefined || keepOpen === null) keepOpen = settings.keepOpen; if (debounceTime === undefined || debounceTime === null) debounceTime = settings.debounceTime; if (ignoreJids === undefined || ignoreJids === null) ignoreJids = settings.ignoreJids; if (splitMessages === undefined || splitMessages === null) splitMessages = settings?.splitMessages ?? false; if (timePerChar === undefined || timePerChar === null) timePerChar = settings?.timePerChar ?? 0; const key = msg.key as { id: string; remoteJid: string; fromMe: boolean; participant: string; }; // Handle stopping the bot if message is from me if (stopBotFromMe && key.fromMe && session) { await this.prismaRepository.integrationSession.update({ where: { id: session.id, }, data: { status: 'paused', }, }); if (this.integrationName === 'Typebot') { const typebotData = { remoteJid: remoteJid, status: 'paused', session, }; this.waMonitor.waInstances[instance.instanceName].sendDataWebhook(Events.TYPEBOT_CHANGE_STATUS, typebotData); } return; } // Skip if not listening to messages from me if (!listeningFromMe && key.fromMe) { return; } // Skip if session exists but not awaiting user input if (session && session.status === 'closed') { return; } // Merged settings const mergedSettings = { ...settings, expire, keywordFinish, delayMessage, unknownMessage, listeningFromMe, stopBotFromMe, keepOpen, debounceTime, ignoreJids, splitMessages, timePerChar, }; // Process with debounce if needed if (debounceTime && debounceTime > 0) { this.processDebounce(this.userMessageDebounce, content, remoteJid, debounceTime, async (debouncedContent) => { await this.processBot( this.waMonitor.waInstances[instance.instanceName], remoteJid, findBot, session, mergedSettings, debouncedContent, msg?.pushName, msg, ); }); } else { await this.processBot( this.waMonitor.waInstances[instance.instanceName], remoteJid, findBot, session, mergedSettings, content, msg?.pushName, msg, ); } } catch (error) { this.logger.error(error); } } } ================================================ FILE: src/api/integrations/chatbot/base-chatbot.dto.ts ================================================ import { TriggerOperator, TriggerType } from '@prisma/client'; /** * Base DTO for all chatbot integrations * Contains common properties shared by all chatbot types */ export class BaseChatbotDto { enabled?: boolean; description: string; expire?: number; keywordFinish?: string; delayMessage?: number; unknownMessage?: string; listeningFromMe?: boolean; stopBotFromMe?: boolean; keepOpen?: boolean; debounceTime?: number; triggerType: TriggerType; triggerOperator?: TriggerOperator; triggerValue?: string; ignoreJids?: string[]; splitMessages?: boolean; timePerChar?: number; } /** * Base settings DTO for all chatbot integrations */ export class BaseChatbotSettingDto { expire?: number; keywordFinish?: string; delayMessage?: number; unknownMessage?: string; listeningFromMe?: boolean; stopBotFromMe?: boolean; keepOpen?: boolean; debounceTime?: number; ignoreJids?: any; splitMessages?: boolean; timePerChar?: number; fallbackId?: string; // Unified fallback ID field for all integrations } ================================================ FILE: src/api/integrations/chatbot/base-chatbot.service.ts ================================================ import { InstanceDto } from '@api/dto/instance.dto'; import { PrismaRepository } from '@api/repository/repository.service'; import { WAMonitoringService } from '@api/services/monitor.service'; import { Integration } from '@api/types/wa.types'; import { ConfigService } from '@config/env.config'; import { Logger } from '@config/logger.config'; import { IntegrationSession } from '@prisma/client'; /** * Base class for all chatbot service implementations * Contains common methods shared across different chatbot integrations */ export abstract class BaseChatbotService { protected readonly logger: Logger; protected readonly waMonitor: WAMonitoringService; protected readonly prismaRepository: PrismaRepository; protected readonly configService?: ConfigService; constructor( waMonitor: WAMonitoringService, prismaRepository: PrismaRepository, loggerName: string, configService?: ConfigService, ) { this.waMonitor = waMonitor; this.prismaRepository = prismaRepository; this.logger = new Logger(loggerName); this.configService = configService; } /** * Check if a message contains an image */ protected isImageMessage(content: string): boolean { return content.includes('imageMessage'); } /** * Check if a message contains audio */ protected isAudioMessage(content: string): boolean { return content.includes('audioMessage'); } /** * Check if a string is valid JSON */ protected isJSON(str: string): boolean { try { JSON.parse(str); return true; } catch { return false; } } /** * Determine the media type from a URL based on its extension */ protected getMediaType(url: string): string | null { const extension = url.split('.').pop()?.toLowerCase(); const imageExtensions = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp']; const audioExtensions = ['mp3', 'wav', 'aac', 'ogg']; const videoExtensions = ['mp4', 'avi', 'mkv', 'mov']; const documentExtensions = ['pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'txt']; if (imageExtensions.includes(extension || '')) return 'image'; if (audioExtensions.includes(extension || '')) return 'audio'; if (videoExtensions.includes(extension || '')) return 'video'; if (documentExtensions.includes(extension || '')) return 'document'; return null; } /** * Create a new chatbot session */ public async createNewSession(instance: InstanceDto | any, data: any, type: string) { try { // Extract pushName safely - if data.pushName is an object with a pushName property, use that const pushNameValue = typeof data.pushName === 'object' && data.pushName?.pushName ? data.pushName.pushName : typeof data.pushName === 'string' ? data.pushName : null; // Extract remoteJid safely const remoteJidValue = typeof data.remoteJid === 'object' && data.remoteJid?.remoteJid ? data.remoteJid.remoteJid : data.remoteJid; const session = await this.prismaRepository.integrationSession.create({ data: { remoteJid: remoteJidValue, pushName: pushNameValue, sessionId: remoteJidValue, status: 'opened', awaitUser: false, botId: data.botId, instanceId: instance.instanceId, type: type, }, }); return { session }; } catch (error) { this.logger.error(error); return; } } /** * Standard implementation for processing incoming messages * This handles the common workflow across all chatbot types: * 1. Check for existing session or create new one * 2. Handle message based on session state */ public async process( instance: any, remoteJid: string, bot: BotType, session: IntegrationSession, settings: SettingsType, content: string, pushName?: string, msg?: any, ): Promise { try { // For new sessions or sessions awaiting initialization if (!session) { await this.initNewSession(instance, remoteJid, bot, settings, session, content, pushName, msg); return; } // If session is paused, ignore the message if (session.status === 'paused') { return; } // For existing sessions, keywords might indicate the conversation should end const keywordFinish = (settings as any)?.keywordFinish || ''; const normalizedContent = content.toLowerCase().trim(); if (keywordFinish.length > 0 && normalizedContent === keywordFinish.toLowerCase()) { // Update session to closed and return await this.prismaRepository.integrationSession.update({ where: { id: session.id, }, data: { status: 'closed', }, }); return; } // Forward the message to the chatbot API await this.sendMessageToBot(instance, session, settings, bot, remoteJid, pushName || '', content, msg); // Update session to indicate we're waiting for user response await this.prismaRepository.integrationSession.update({ where: { id: session.id, }, data: { status: 'opened', awaitUser: true, }, }); } catch (error) { this.logger.error(`Error in process: ${error}`); return; } } /** * Standard implementation for sending messages to WhatsApp * This handles common patterns like markdown links and formatting */ protected async sendMessageWhatsApp( instance: any, remoteJid: string, message: string, settings: SettingsType, linkPreview: boolean = true, ): Promise { if (!message) return; const linkRegex = /!?\[(.*?)\]\((.*?)\)/g; let textBuffer = ''; let lastIndex = 0; let match: RegExpExecArray | null; const splitMessages = (settings as any)?.splitMessages ?? false; while ((match = linkRegex.exec(message)) !== null) { const [fullMatch, altText, url] = match; const mediaType = this.getMediaType(url); const beforeText = message.slice(lastIndex, match.index); if (beforeText) { textBuffer += beforeText; } if (mediaType) { // Send accumulated text before sending media if (textBuffer.trim()) { await this.sendFormattedText(instance, remoteJid, textBuffer.trim(), settings, splitMessages, linkPreview); textBuffer = ''; } // Handle sending the media try { if (mediaType === 'audio') { await instance.audioWhatsapp({ number: remoteJid.includes('@lid') ? remoteJid : remoteJid.split('@')[0], delay: (settings as any)?.delayMessage || 1000, audio: url, caption: altText, }); } else { await instance.mediaMessage( { number: remoteJid.includes('@lid') ? remoteJid : remoteJid.split('@')[0], delay: (settings as any)?.delayMessage || 1000, mediatype: mediaType, media: url, caption: altText, fileName: mediaType === 'document' ? altText || 'document' : undefined, }, null, false, ); } } catch (error) { this.logger.error(`Error sending media: ${error}`); // If media fails, at least send the alt text and URL textBuffer += `${altText}: ${url}`; } } else { // It's a regular link, keep it in the text textBuffer += fullMatch; } lastIndex = linkRegex.lastIndex; } // Add any remaining text after the last match if (lastIndex < message.length) { const remainingText = message.slice(lastIndex); if (remainingText.trim()) { textBuffer += remainingText; } } // Send any remaining text if (textBuffer.trim()) { await this.sendFormattedText(instance, remoteJid, textBuffer.trim(), settings, splitMessages, linkPreview); } } /** * Split message by double line breaks and return array of message parts */ private splitMessageByDoubleLineBreaks(message: string): string[] { return message.split('\n\n').filter((part) => part.trim().length > 0); } /** * Send a single message with proper typing indicators and delays */ private async sendSingleMessage( instance: any, remoteJid: string, message: string, settings: any, linkPreview: boolean = true, ): Promise { const timePerChar = settings?.timePerChar ?? 0; const minDelay = 1000; const maxDelay = 20000; const delay = Math.min(Math.max(message.length * timePerChar, minDelay), maxDelay); this.logger.debug(`[BaseChatbot] Sending single message with linkPreview: ${linkPreview}`); if (instance.integration === Integration.WHATSAPP_BAILEYS) { await instance.client.presenceSubscribe(remoteJid); await instance.client.sendPresenceUpdate('composing', remoteJid); } await new Promise((resolve) => { setTimeout(async () => { await instance.textMessage( { number: remoteJid.includes('@lid') ? remoteJid : remoteJid.split('@')[0], delay: settings?.delayMessage || 1000, text: message, linkPreview, }, false, ); resolve(); }, delay); }); if (instance.integration === Integration.WHATSAPP_BAILEYS) { await instance.client.sendPresenceUpdate('paused', remoteJid); } } /** * Helper method to send formatted text with proper typing indicators and delays */ private async sendFormattedText( instance: any, remoteJid: string, text: string, settings: any, splitMessages: boolean, linkPreview: boolean = true, ): Promise { if (splitMessages) { const messageParts = this.splitMessageByDoubleLineBreaks(text); this.logger.debug(`[BaseChatbot] Splitting message into ${messageParts.length} parts`); for (let index = 0; index < messageParts.length; index++) { const message = messageParts[index]; this.logger.debug(`[BaseChatbot] Sending message part ${index + 1}/${messageParts.length}`); await this.sendSingleMessage(instance, remoteJid, message, settings, linkPreview); } this.logger.debug(`[BaseChatbot] All message parts sent successfully`); } else { this.logger.debug(`[BaseChatbot] Sending single message`); await this.sendSingleMessage(instance, remoteJid, text, settings, linkPreview); } } /** * Standard implementation for initializing a new session * This method should be overridden if a subclass needs specific initialization */ protected async initNewSession( instance: any, remoteJid: string, bot: BotType, settings: SettingsType, session: IntegrationSession, content: string, pushName?: string | any, msg?: any, ): Promise { // Create a session if none exists if (!session) { // Extract pushName properly - if it's an object with pushName property, use that const pushNameValue = typeof pushName === 'object' && pushName?.pushName ? pushName.pushName : typeof pushName === 'string' ? pushName : null; const sessionResult = await this.createNewSession( { instanceName: instance.instanceName, instanceId: instance.instanceId, }, { remoteJid, pushName: pushNameValue, botId: (bot as any).id, }, this.getBotType(), ); if (!sessionResult || !sessionResult.session) { this.logger.error('Failed to create new session'); return; } session = sessionResult.session; } // Update session status to opened await this.prismaRepository.integrationSession.update({ where: { id: session.id, }, data: { status: 'opened', awaitUser: false, }, }); // Forward the message to the chatbot await this.sendMessageToBot(instance, session, settings, bot, remoteJid, pushName || '', content, msg); } /** * Get the bot type identifier (e.g., 'dify', 'n8n', 'evoai') * This should match the type field used in the IntegrationSession */ protected abstract getBotType(): string; /** * Send a message to the chatbot API * This is specific to each chatbot integration */ protected abstract sendMessageToBot( instance: any, session: IntegrationSession, settings: SettingsType, bot: BotType, remoteJid: string, pushName: string, content: string, msg?: any, ): Promise; } ================================================ FILE: src/api/integrations/chatbot/chatbot.controller.ts ================================================ import { InstanceDto } from '@api/dto/instance.dto'; import { PrismaRepository } from '@api/repository/repository.service'; import { difyController, evoaiController, evolutionBotController, flowiseController, n8nController, openaiController, typebotController, } from '@api/server.module'; import { WAMonitoringService } from '@api/services/monitor.service'; import { Logger } from '@config/logger.config'; import { IntegrationSession } from '@prisma/client'; import { findBotByTrigger } from '@utils/findBotByTrigger'; export type EmitData = { instance: InstanceDto; remoteJid: string; msg: any; pushName?: string; }; export interface ChatbotControllerInterface { integrationEnabled: boolean; botRepository: any; settingsRepository: any; sessionRepository: any; userMessageDebounce: { [key: string]: { message: string; timeoutId: NodeJS.Timeout } }; createBot(instance: InstanceDto, data: any): Promise; findBot(instance: InstanceDto): Promise; fetchBot(instance: InstanceDto, botId: string): Promise; updateBot(instance: InstanceDto, botId: string, data: any): Promise; deleteBot(instance: InstanceDto, botId: string): Promise; settings(instance: InstanceDto, data: any): Promise; fetchSettings(instance: InstanceDto): Promise; changeStatus(instance: InstanceDto, botId: string, status: string): Promise; fetchSessions(instance: InstanceDto, botId: string, remoteJid?: string): Promise; ignoreJid(instance: InstanceDto, data: any): Promise; emit(data: EmitData): Promise; } export class ChatbotController { public prismaRepository: PrismaRepository; public waMonitor: WAMonitoringService; public readonly logger = new Logger('ChatbotController'); constructor(prismaRepository: PrismaRepository, waMonitor: WAMonitoringService) { this.prisma = prismaRepository; this.monitor = waMonitor; } public set prisma(prisma: PrismaRepository) { this.prismaRepository = prisma; } public get prisma() { return this.prismaRepository; } public set monitor(waMonitor: WAMonitoringService) { this.waMonitor = waMonitor; } public get monitor() { return this.waMonitor; } public async emit({ instance, remoteJid, msg, pushName, isIntegration = false, }: { instance: InstanceDto; remoteJid: string; msg: any; pushName?: string; isIntegration?: boolean; }): Promise { const emitData = { instance, remoteJid, msg, pushName, isIntegration, }; evolutionBotController.emit(emitData); typebotController.emit(emitData); openaiController.emit(emitData); difyController.emit(emitData); n8nController.emit(emitData); evoaiController.emit(emitData); flowiseController.emit(emitData); } public processDebounce( userMessageDebounce: any, content: string, remoteJid: string, debounceTime: number, callback: any, ) { if (userMessageDebounce[remoteJid]) { userMessageDebounce[remoteJid].message += `\n${content}`; this.logger.log('message debounced: ' + userMessageDebounce[remoteJid].message); clearTimeout(userMessageDebounce[remoteJid].timeoutId); } else { userMessageDebounce[remoteJid] = { message: content, timeoutId: null, }; } userMessageDebounce[remoteJid].timeoutId = setTimeout(() => { const myQuestion = userMessageDebounce[remoteJid].message; this.logger.log('Debounce complete. Processing message: ' + myQuestion); delete userMessageDebounce[remoteJid]; callback(myQuestion); }, debounceTime * 1000); } public checkIgnoreJids(ignoreJids: any, remoteJid: string) { if (ignoreJids && ignoreJids.length > 0) { let ignoreGroups = false; let ignoreContacts = false; if (ignoreJids.includes('@g.us')) { ignoreGroups = true; } if (ignoreJids.includes('@s.whatsapp.net')) { ignoreContacts = true; } if (ignoreGroups && remoteJid.endsWith('@g.us')) { this.logger.warn('Ignoring message from group: ' + remoteJid); return true; } if (ignoreContacts && remoteJid.endsWith('@s.whatsapp.net')) { this.logger.warn('Ignoring message from contact: ' + remoteJid); return true; } if (ignoreJids.includes(remoteJid)) { this.logger.warn('Ignoring message from jid: ' + remoteJid); return true; } return false; } return false; } public async getSession(remoteJid: string, instance: InstanceDto) { let session = await this.prismaRepository.integrationSession.findFirst({ where: { remoteJid: remoteJid, instanceId: instance.instanceId, }, orderBy: { createdAt: 'desc' }, }); if (session) { if (session.status !== 'closed' && !session.botId) { this.logger.warn('Session is already opened in another integration'); return null; } else if (!session.botId) { session = null; } } return session; } public async findBotTrigger( botRepository: any, content: string, instance: InstanceDto, session?: IntegrationSession, ) { let findBot: any = null; if (!session) { findBot = await findBotByTrigger(botRepository, content, instance.instanceId); if (!findBot) { return null; } } else { findBot = await botRepository.findFirst({ where: { id: session.botId, }, }); } return findBot; } } ================================================ FILE: src/api/integrations/chatbot/chatbot.router.ts ================================================ import { ChatwootRouter } from '@api/integrations/chatbot/chatwoot/routes/chatwoot.router'; import { DifyRouter } from '@api/integrations/chatbot/dify/routes/dify.router'; import { OpenaiRouter } from '@api/integrations/chatbot/openai/routes/openai.router'; import { TypebotRouter } from '@api/integrations/chatbot/typebot/routes/typebot.router'; import { Router } from 'express'; import { EvoaiRouter } from './evoai/routes/evoai.router'; import { EvolutionBotRouter } from './evolutionBot/routes/evolutionBot.router'; import { FlowiseRouter } from './flowise/routes/flowise.router'; import { N8nRouter } from './n8n/routes/n8n.router'; export class ChatbotRouter { public readonly router: Router; constructor(...guards: any[]) { this.router = Router(); this.router.use('/evolutionBot', new EvolutionBotRouter(...guards).router); this.router.use('/chatwoot', new ChatwootRouter(...guards).router); this.router.use('/typebot', new TypebotRouter(...guards).router); this.router.use('/openai', new OpenaiRouter(...guards).router); this.router.use('/dify', new DifyRouter(...guards).router); this.router.use('/flowise', new FlowiseRouter(...guards).router); this.router.use('/n8n', new N8nRouter(...guards).router); this.router.use('/evoai', new EvoaiRouter(...guards).router); } } ================================================ FILE: src/api/integrations/chatbot/chatbot.schema.ts ================================================ export * from '@api/integrations/chatbot/chatwoot/validate/chatwoot.schema'; export * from '@api/integrations/chatbot/dify/validate/dify.schema'; export * from '@api/integrations/chatbot/evoai/validate/evoai.schema'; export * from '@api/integrations/chatbot/evolutionBot/validate/evolutionBot.schema'; export * from '@api/integrations/chatbot/flowise/validate/flowise.schema'; export * from '@api/integrations/chatbot/n8n/validate/n8n.schema'; export * from '@api/integrations/chatbot/openai/validate/openai.schema'; export * from '@api/integrations/chatbot/typebot/validate/typebot.schema'; ================================================ FILE: src/api/integrations/chatbot/chatwoot/controllers/chatwoot.controller.ts ================================================ import { InstanceDto } from '@api/dto/instance.dto'; import { ChatwootDto } from '@api/integrations/chatbot/chatwoot/dto/chatwoot.dto'; import { ChatwootService } from '@api/integrations/chatbot/chatwoot/services/chatwoot.service'; import { Chatwoot, ConfigService, HttpServer } from '@config/env.config'; import { BadRequestException } from '@exceptions'; import { isURL } from 'class-validator'; export class ChatwootController { constructor( private readonly chatwootService: ChatwootService, private readonly configService: ConfigService, ) {} public async createChatwoot(instance: InstanceDto, data: ChatwootDto) { if (!this.configService.get('CHATWOOT').ENABLED) throw new BadRequestException('Chatwoot is disabled'); if (data?.enabled) { if (!isURL(data.url, { require_tld: false })) { throw new BadRequestException('url is not valid'); } if (!data.accountId) { throw new BadRequestException('accountId is required'); } if (!data.token) { throw new BadRequestException('token is required'); } if (data.signMsg !== true && data.signMsg !== false) { throw new BadRequestException('signMsg is required'); } if (data.signMsg === false) data.signDelimiter = null; } if (!data.nameInbox || data.nameInbox === '') { data.nameInbox = instance.instanceName; } const result = await this.chatwootService.create(instance, data); const urlServer = this.configService.get('SERVER').URL; const response = { ...result, webhook_url: `${urlServer}/chatwoot/webhook/${encodeURIComponent(instance.instanceName)}`, }; return response; } public async findChatwoot(instance: InstanceDto): Promise { if (!this.configService.get('CHATWOOT').ENABLED) throw new BadRequestException('Chatwoot is disabled'); const result = await this.chatwootService.find(instance); const urlServer = this.configService.get('SERVER').URL; if (Object.keys(result || {}).length === 0) { return { enabled: false, url: '', accountId: '', token: '', signMsg: false, nameInbox: '', webhook_url: '', }; } const response = { ...result, webhook_url: `${urlServer}/chatwoot/webhook/${encodeURIComponent(instance.instanceName)}`, }; return response; } public async receiveWebhook(instance: InstanceDto, data: any) { if (!this.configService.get('CHATWOOT').ENABLED) throw new BadRequestException('Chatwoot is disabled'); return this.chatwootService.receiveWebhook(instance, data); } } ================================================ FILE: src/api/integrations/chatbot/chatwoot/dto/chatwoot.dto.ts ================================================ import { Constructor } from '@api/integrations/integration.dto'; export class ChatwootDto { enabled?: boolean; accountId?: string; token?: string; url?: string; nameInbox?: string; signMsg?: boolean; signDelimiter?: string; number?: string; reopenConversation?: boolean; conversationPending?: boolean; mergeBrazilContacts?: boolean; importContacts?: boolean; importMessages?: boolean; daysLimitImportMessages?: number; autoCreate?: boolean; organization?: string; logo?: string; ignoreJids?: string[]; } export function ChatwootInstanceMixin(Base: TBase) { return class extends Base { chatwootAccountId?: string; chatwootToken?: string; chatwootUrl?: string; chatwootSignMsg?: boolean; chatwootReopenConversation?: boolean; chatwootConversationPending?: boolean; chatwootMergeBrazilContacts?: boolean; chatwootImportContacts?: boolean; chatwootImportMessages?: boolean; chatwootDaysLimitImportMessages?: number; chatwootNameInbox?: string; chatwootOrganization?: string; chatwootLogo?: string; chatwootAutoCreate?: boolean; }; } ================================================ FILE: src/api/integrations/chatbot/chatwoot/libs/postgres.client.ts ================================================ import { Chatwoot, configService } from '@config/env.config'; import { Logger } from '@config/logger.config'; import postgresql from 'pg'; const { Pool } = postgresql; class Postgres { private logger = new Logger('Postgres'); private pool; private connected = false; getConnection(connectionString: string) { if (this.connected) { return this.pool; } else { this.pool = new Pool({ connectionString, ssl: { rejectUnauthorized: false, }, }); this.pool.on('error', () => { this.logger.error('postgres disconnected'); this.connected = false; }); try { this.connected = true; } catch (e) { this.connected = false; this.logger.error('postgres connect exception caught: ' + e); return null; } return this.pool; } } getChatwootConnection() { const uri = configService.get('CHATWOOT').IMPORT.DATABASE.CONNECTION.URI; return this.getConnection(uri); } } export const postgresClient = new Postgres(); ================================================ FILE: src/api/integrations/chatbot/chatwoot/routes/chatwoot.router.ts ================================================ import { RouterBroker } from '@api/abstract/abstract.router'; import { InstanceDto } from '@api/dto/instance.dto'; import { ChatwootDto } from '@api/integrations/chatbot/chatwoot/dto/chatwoot.dto'; import { HttpStatus } from '@api/routes/index.router'; import { chatwootController } from '@api/server.module'; import { chatwootSchema, instanceSchema } from '@validate/validate.schema'; import { RequestHandler, Router } from 'express'; export class ChatwootRouter extends RouterBroker { constructor(...guards: RequestHandler[]) { super(); this.router .post(this.routerPath('set'), ...guards, async (req, res) => { const response = await this.dataValidate({ request: req, schema: chatwootSchema, ClassRef: ChatwootDto, execute: (instance, data) => chatwootController.createChatwoot(instance, data), }); res.status(HttpStatus.CREATED).json(response); }) .get(this.routerPath('find'), ...guards, async (req, res) => { const response = await this.dataValidate({ request: req, schema: instanceSchema, ClassRef: InstanceDto, execute: (instance) => chatwootController.findChatwoot(instance), }); res.status(HttpStatus.OK).json(response); }) .post(this.routerPath('webhook'), async (req, res) => { const response = await this.dataValidate({ request: req, schema: instanceSchema, ClassRef: InstanceDto, execute: (instance, data) => chatwootController.receiveWebhook(instance, data), }); res.status(HttpStatus.OK).json(response); }); } public readonly router: Router = Router(); } ================================================ FILE: src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts ================================================ import { InstanceDto } from '@api/dto/instance.dto'; import { Options, Quoted, SendAudioDto, SendMediaDto, SendTextDto } from '@api/dto/sendMessage.dto'; import { ChatwootDto } from '@api/integrations/chatbot/chatwoot/dto/chatwoot.dto'; import { postgresClient } from '@api/integrations/chatbot/chatwoot/libs/postgres.client'; import { chatwootImport } from '@api/integrations/chatbot/chatwoot/utils/chatwoot-import-helper'; import { PrismaRepository } from '@api/repository/repository.service'; import { CacheService } from '@api/services/cache.service'; import { WAMonitoringService } from '@api/services/monitor.service'; import { Events } from '@api/types/wa.types'; import { Chatwoot, ConfigService, Database, HttpServer } from '@config/env.config'; import { Logger } from '@config/logger.config'; import ChatwootClient, { ChatwootAPIConfig, contact, contact_inboxes, conversation, conversation_show, generic_id, inbox, } from '@figuro/chatwoot-sdk'; import { request as chatwootRequest } from '@figuro/chatwoot-sdk/dist/core/request'; import { Chatwoot as ChatwootModel, Contact as ContactModel, Message as MessageModel } from '@prisma/client'; import i18next from '@utils/i18n'; import { sendTelemetry } from '@utils/sendTelemetry'; import axios from 'axios'; import { WAMessageContent, WAMessageKey } from 'baileys'; import dayjs from 'dayjs'; import FormData from 'form-data'; import { Jimp, JimpMime } from 'jimp'; import { parsePhoneNumberFromString } from 'libphonenumber-js'; import Long from 'long'; import mimeTypes from 'mime-types'; import path from 'path'; import { Readable } from 'stream'; interface ChatwootMessage { messageId?: number; inboxId?: number; conversationId?: number; contactInboxSourceId?: string; isRead?: boolean; } export class ChatwootService { private readonly logger = new Logger('ChatwootService'); // Lock polling delay private readonly LOCK_POLLING_DELAY_MS = 300; // Delay between lock status checks private provider: any; constructor( private readonly waMonitor: WAMonitoringService, private readonly configService: ConfigService, private readonly prismaRepository: PrismaRepository, private readonly cache: CacheService, ) {} private pgClient = postgresClient.getChatwootConnection(); private async getProvider(instance: InstanceDto): Promise { const cacheKey = `${instance.instanceName}:getProvider`; if (await this.cache.has(cacheKey)) { const provider = (await this.cache.get(cacheKey)) as ChatwootModel; return provider; } const provider = await this.waMonitor.waInstances[instance.instanceName]?.findChatwoot(); if (!provider) { this.logger.warn('provider not found'); return null; } this.cache.set(cacheKey, provider); return provider; } private async clientCw(instance: InstanceDto) { const provider = await this.getProvider(instance); if (!provider) { this.logger.error('provider not found'); return null; } this.provider = provider; const client = new ChatwootClient({ config: this.getClientCwConfig(), }); return client; } public getClientCwConfig(): ChatwootAPIConfig & { nameInbox: string; mergeBrazilContacts: boolean } { return { basePath: this.provider.url, with_credentials: true, credentials: 'include', token: this.provider.token, nameInbox: this.provider.nameInbox, mergeBrazilContacts: this.provider.mergeBrazilContacts, }; } public getCache() { return this.cache; } public async create(instance: InstanceDto, data: ChatwootDto) { await this.waMonitor.waInstances[instance.instanceName].setChatwoot(data); if (data.autoCreate) { this.logger.log('Auto create chatwoot instance'); const urlServer = this.configService.get('SERVER').URL; await this.initInstanceChatwoot( instance, data.nameInbox ?? instance.instanceName.split('-cwId-')[0], `${urlServer}/chatwoot/webhook/${encodeURIComponent(instance.instanceName)}`, true, data.number, data.organization, data.logo, ); } return data; } public async find(instance: InstanceDto): Promise { try { return await this.waMonitor.waInstances[instance.instanceName].findChatwoot(); } catch { this.logger.error('chatwoot not found'); return { enabled: null, url: '' }; } } public async getContact(instance: InstanceDto, id: number) { const client = await this.clientCw(instance); if (!client) { this.logger.warn('client not found'); return null; } if (!id) { this.logger.warn('id is required'); return null; } const contact = await client.contact.getContactable({ accountId: this.provider.accountId, id, }); if (!contact) { this.logger.warn('contact not found'); return null; } return contact; } public async initInstanceChatwoot( instance: InstanceDto, inboxName: string, webhookUrl: string, qrcode: boolean, number: string, organization?: string, logo?: string, ) { const client = await this.clientCw(instance); if (!client) { this.logger.warn('client not found'); return null; } const findInbox: any = await client.inboxes.list({ accountId: this.provider.accountId, }); const checkDuplicate = findInbox.payload.map((inbox) => inbox.name).includes(inboxName); let inboxId: number; this.logger.log('Creating chatwoot inbox'); if (!checkDuplicate) { const data = { type: 'api', webhook_url: webhookUrl, }; const inbox = await client.inboxes.create({ accountId: this.provider.accountId, data: { name: inboxName, channel: data as any, }, }); if (!inbox) { this.logger.warn('inbox not found'); return null; } inboxId = inbox.id; } else { const inbox = findInbox.payload.find((inbox) => inbox.name === inboxName); if (!inbox) { this.logger.warn('inbox not found'); return null; } inboxId = inbox.id; } this.logger.log(`Inbox created - inboxId: ${inboxId}`); if (!this.configService.get('CHATWOOT').BOT_CONTACT) { this.logger.log('Chatwoot bot contact is disabled'); return true; } this.logger.log('Creating chatwoot bot contact'); const contact = (await this.findContact(instance, '123456')) || ((await this.createContact( instance, '123456', inboxId, false, organization ? organization : 'EvolutionAPI', logo ? logo : 'https://evolution-api.com/files/evolution-api-favicon.png', )) as any); if (!contact) { this.logger.warn('contact not found'); return null; } const contactId = contact.id || contact.payload.contact.id; this.logger.log(`Contact created - contactId: ${contactId}`); if (qrcode) { this.logger.log('QR code enabled'); const data = { contact_id: contactId.toString(), inbox_id: inboxId.toString(), }; const conversation = await client.conversations.create({ accountId: this.provider.accountId, data, }); if (!conversation) { this.logger.warn('conversation not found'); return null; } let contentMsg = 'init'; if (number) { contentMsg = `init:${number}`; } const message = await client.messages.create({ accountId: this.provider.accountId, conversationId: conversation.id, data: { content: contentMsg, message_type: 'outgoing', }, }); if (!message) { this.logger.warn('conversation not found'); return null; } this.logger.log('Init message sent'); } return true; } public async createContact( instance: InstanceDto, phoneNumber: string, inboxId: number, isGroup: boolean, name?: string, avatar_url?: string, jid?: string, ) { try { const client = await this.clientCw(instance); if (!client) { this.logger.warn('client not found'); return null; } let data: any = {}; if (!isGroup) { data = { inbox_id: inboxId, name: name || phoneNumber, identifier: jid, avatar_url: avatar_url, }; if ((jid && jid.includes('@')) || !jid) { data['phone_number'] = `+${phoneNumber}`; } } else { data = { inbox_id: inboxId, name: name || phoneNumber, identifier: phoneNumber, avatar_url: avatar_url, }; } const contact = await client.contacts.create({ accountId: this.provider.accountId, data, }); if (!contact) { this.logger.warn('contact not found'); return null; } const findContact = await this.findContact(instance, phoneNumber); const contactId = findContact?.id; await this.addLabelToContact(this.provider.nameInbox, contactId); return contact; } catch (error) { if ((error.status === 422 || error.response?.status === 422) && jid) { this.logger.warn(`Contact with identifier ${jid} creation failed (422). Checking if it already exists...`); const existingContact = await this.findContactByIdentifier(instance, jid); if (existingContact) { const contactId = existingContact.id; await this.addLabelToContact(this.provider.nameInbox, contactId); return existingContact; } } this.logger.error('Error creating contact'); console.log(error); return null; } } public async updateContact(instance: InstanceDto, id: number, data: any) { const client = await this.clientCw(instance); if (!client) { this.logger.warn('client not found'); return null; } if (!id) { this.logger.warn('id is required'); return null; } try { const contact = await client.contacts.update({ accountId: this.provider.accountId, id, data, }); return contact; } catch { return null; } } public async addLabelToContact(nameInbox: string, contactId: number) { try { const uri = this.configService.get('CHATWOOT').IMPORT.DATABASE.CONNECTION.URI; if (!uri) return false; const sqlTags = `SELECT id, taggings_count FROM tags WHERE name = $1 LIMIT 1`; const tagData = (await this.pgClient.query(sqlTags, [nameInbox]))?.rows[0]; let tagId = tagData?.id; const taggingsCount = tagData?.taggings_count || 0; const sqlTag = `INSERT INTO tags (name, taggings_count) VALUES ($1, $2) ON CONFLICT (name) DO UPDATE SET taggings_count = tags.taggings_count + 1 RETURNING id`; tagId = (await this.pgClient.query(sqlTag, [nameInbox, taggingsCount + 1]))?.rows[0]?.id; const sqlCheckTagging = `SELECT 1 FROM taggings WHERE tag_id = $1 AND taggable_type = 'Contact' AND taggable_id = $2 AND context = 'labels' LIMIT 1`; const taggingExists = (await this.pgClient.query(sqlCheckTagging, [tagId, contactId]))?.rowCount > 0; if (!taggingExists) { const sqlInsertLabel = `INSERT INTO taggings (tag_id, taggable_type, taggable_id, context, created_at) VALUES ($1, 'Contact', $2, 'labels', NOW())`; await this.pgClient.query(sqlInsertLabel, [tagId, contactId]); } return true; } catch { return false; } } public async findContactByIdentifier(instance: InstanceDto, identifier: string) { const client = await this.clientCw(instance); if (!client) { this.logger.warn('client not found'); return null; } // Direct search by query (q) - most common way to search by identifier/email/phone const contact = (await (client as any).get('contacts/search', { params: { q: identifier, sort: 'name', }, })) as any; if (contact && contact.data && contact.data.payload && contact.data.payload.length > 0) { return contact.data.payload[0]; } // Fallback for older API versions or different response structures if (contact && contact.payload && contact.payload.length > 0) { return contact.payload[0]; } // Try search by attribute const contactByAttr = (await (client as any).post('contacts/filter', { payload: [ { attribute_key: 'identifier', filter_operator: 'equal_to', values: [identifier], query_operator: null, }, ], })) as any; if (contactByAttr && contactByAttr.payload && contactByAttr.payload.length > 0) { return contactByAttr.payload[0]; } // Check inside data property if using axios interceptors wrapper if (contactByAttr && contactByAttr.data && contactByAttr.data.payload && contactByAttr.data.payload.length > 0) { return contactByAttr.data.payload[0]; } return null; } public async findContact(instance: InstanceDto, phoneNumber: string) { const client = await this.clientCw(instance); if (!client) { this.logger.warn('client not found'); return null; } let query: any; const isGroup = phoneNumber.includes('@g.us'); if (!isGroup) { query = `+${phoneNumber}`; } else { query = phoneNumber; } let contact: any; if (isGroup) { contact = await client.contacts.search({ accountId: this.provider.accountId, q: query, }); } else { contact = await chatwootRequest(this.getClientCwConfig(), { method: 'POST', url: `/api/v1/accounts/${this.provider.accountId}/contacts/filter`, body: { payload: this.getFilterPayload(query), }, }); } if (!contact && contact?.payload?.length === 0) { this.logger.warn('contact not found'); return null; } if (!isGroup) { return contact.payload.length > 1 ? this.findContactInContactList(contact.payload, query) : contact.payload[0]; } else { return contact.payload.find((contact) => contact.identifier === query); } } private async mergeContacts(baseId: number, mergeId: number) { try { const contact = await chatwootRequest(this.getClientCwConfig(), { method: 'POST', url: `/api/v1/accounts/${this.provider.accountId}/actions/contact_merge`, body: { base_contact_id: baseId, mergee_contact_id: mergeId, }, }); return contact; } catch { this.logger.error('Error merging contacts'); return null; } } private async mergeBrazilianContacts(contacts: any[]) { try { const contact = await chatwootRequest(this.getClientCwConfig(), { method: 'POST', url: `/api/v1/accounts/${this.provider.accountId}/actions/contact_merge`, body: { base_contact_id: contacts.find((contact) => contact.phone_number.length === 14)?.id, mergee_contact_id: contacts.find((contact) => contact.phone_number.length === 13)?.id, }, }); return contact; } catch { this.logger.error('Error merging contacts'); return null; } } private findContactInContactList(contacts: any[], query: string) { const phoneNumbers = this.getNumbers(query); const searchableFields = this.getSearchableFields(); // eslint-disable-next-line prettier/prettier if (contacts.length === 2 && this.getClientCwConfig().mergeBrazilContacts && query.startsWith('+55')) { const contact = this.mergeBrazilianContacts(contacts); if (contact) { return contact; } } const phone = phoneNumbers.reduce( (savedNumber, number) => (number.length > savedNumber.length ? number : savedNumber), '', ); const contact_with9 = contacts.find((contact) => contact.phone_number === phone); if (contact_with9) { return contact_with9; } for (const contact of contacts) { for (const field of searchableFields) { if (contact[field] && phoneNumbers.includes(contact[field])) { return contact; } } } return null; } private getNumbers(query: string) { const numbers = []; numbers.push(query); if (query.startsWith('+55') && query.length === 14) { const withoutNine = query.slice(0, 5) + query.slice(6); numbers.push(withoutNine); } else if (query.startsWith('+55') && query.length === 13) { const withNine = query.slice(0, 5) + '9' + query.slice(5); numbers.push(withNine); } return numbers; } private getSearchableFields() { return ['phone_number']; } private getFilterPayload(query: string) { const filterPayload = []; const numbers = this.getNumbers(query); const fieldsToSearch = this.getSearchableFields(); fieldsToSearch.forEach((field, index1) => { numbers.forEach((number, index2) => { const queryOperator = fieldsToSearch.length - 1 === index1 && numbers.length - 1 === index2 ? null : 'OR'; filterPayload.push({ attribute_key: field, filter_operator: 'equal_to', values: [number.replace('+', '')], query_operator: queryOperator, }); }); }); return filterPayload; } public async createConversation(instance: InstanceDto, body: any) { const isLid = body.key.addressingMode === 'lid'; const isGroup = body.key.remoteJid.endsWith('@g.us'); const phoneNumber = isLid && !isGroup ? body.key.remoteJidAlt : body.key.remoteJid; const { remoteJid } = body.key; const cacheKey = `${instance.instanceName}:createConversation-${remoteJid}`; const lockKey = `${instance.instanceName}:lock:createConversation-${remoteJid}`; const maxWaitTime = 5000; // 5 seconds const client = await this.clientCw(instance); if (!client) return null; try { // Processa atualização de contatos já criados @lid if (phoneNumber && remoteJid && !isGroup) { const contact = await this.findContact(instance, phoneNumber.split('@')[0]); if (contact && contact.identifier !== remoteJid) { this.logger.verbose( `Identifier needs update: (contact.identifier: ${contact.identifier}, phoneNumber: ${phoneNumber}, body.key.remoteJidAlt: ${remoteJid}`, ); const updateContact = await this.updateContact(instance, contact.id, { identifier: phoneNumber, phone_number: `+${phoneNumber.split('@')[0]}`, }); if (updateContact === null) { const baseContact = await this.findContact(instance, phoneNumber.split('@')[0]); if (baseContact) { await this.mergeContacts(baseContact.id, contact.id); this.logger.verbose( `Merge contacts: (${baseContact.id}) ${baseContact.phone_number} and (${contact.id}) ${contact.phone_number}`, ); } } } } this.logger.verbose(`--- Start createConversation ---`); this.logger.verbose(`Instance: ${JSON.stringify(instance)}`); // If it already exists in the cache, return conversationId if (await this.cache.has(cacheKey)) { const conversationId = (await this.cache.get(cacheKey)) as number; this.logger.verbose(`Found conversation to: ${phoneNumber}, conversation ID: ${conversationId}`); let conversationExists: any; try { conversationExists = await client.conversations.get({ accountId: this.provider.accountId, conversationId: conversationId, }); this.logger.verbose( `Conversation exists: ID: ${conversationExists.id} - Name: ${conversationExists.meta.sender.name} - Identifier: ${conversationExists.meta.sender.identifier}`, ); } catch (error) { this.logger.error(`Error getting conversation: ${error}`); conversationExists = false; } if (!conversationExists) { this.logger.verbose('Conversation does not exist, re-calling createConversation'); this.cache.delete(cacheKey); return await this.createConversation(instance, body); } return conversationId; } // If lock already exists, wait until release or timeout if (await this.cache.has(lockKey)) { this.logger.verbose(`Operação de criação já em andamento para ${remoteJid}, aguardando resultado...`); const start = Date.now(); while (await this.cache.has(lockKey)) { if (Date.now() - start > maxWaitTime) { this.logger.warn(`Timeout aguardando lock para ${remoteJid}`); break; } await new Promise((res) => setTimeout(res, this.LOCK_POLLING_DELAY_MS)); if (await this.cache.has(cacheKey)) { const conversationId = (await this.cache.get(cacheKey)) as number; this.logger.verbose(`Resolves creation of: ${remoteJid}, conversation ID: ${conversationId}`); return conversationId; } } } // Adquire lock await this.cache.set(lockKey, true, 30); this.logger.verbose(`Bloqueio adquirido para: ${lockKey}`); try { /* Double check after lock Utilizei uma nova verificação para evitar que outra thread execute entre o terminio do while e o set lock */ if (await this.cache.has(cacheKey)) { return (await this.cache.get(cacheKey)) as number; } const chatId = isGroup ? remoteJid : phoneNumber.split('@')[0].split(':')[0]; let nameContact = !body.key.fromMe ? body.pushName : chatId; const filterInbox = await this.getInbox(instance); if (!filterInbox) return null; if (isGroup) { this.logger.verbose(`Processing group conversation`); const group = await this.waMonitor.waInstances[instance.instanceName].client.groupMetadata(chatId); this.logger.verbose(`Group metadata: JID:${group.JID} - Subject:${group?.subject || group?.Name}`); const participantJid = isLid && !body.key.fromMe ? body.key.participantAlt : body.key.participant; nameContact = `${group.subject} (GROUP)`; const picture_url = await this.waMonitor.waInstances[instance.instanceName].profilePicture( participantJid.split('@')[0], ); this.logger.verbose(`Participant profile picture URL: ${JSON.stringify(picture_url)}`); const findParticipant = await this.findContact(instance, participantJid.split('@')[0]); if (findParticipant) { this.logger.verbose( `Found participant: ID:${findParticipant.id} - Name: ${findParticipant.name} - identifier: ${findParticipant.identifier}`, ); if (!findParticipant.name || findParticipant.name === chatId) { await this.updateContact(instance, findParticipant.id, { name: body.pushName, avatar_url: picture_url.profilePictureUrl || null, }); } } else { await this.createContact( instance, participantJid.split('@')[0].split(':')[0], filterInbox.id, false, body.pushName, picture_url.profilePictureUrl || null, participantJid, ); } } const picture_url = await this.waMonitor.waInstances[instance.instanceName].profilePicture(chatId); this.logger.verbose(`Contact profile picture URL: ${JSON.stringify(picture_url)}`); this.logger.verbose(`Searching contact for: ${chatId}`); let contact = await this.findContact(instance, chatId); if (contact) { this.logger.verbose(`Found contact: ID:${contact.id} - Name:${contact.name}`); if (!body.key.fromMe) { const waProfilePictureFile = picture_url?.profilePictureUrl?.split('#')[0].split('?')[0].split('/').pop() || ''; const chatwootProfilePictureFile = contact?.thumbnail?.split('#')[0].split('?')[0].split('/').pop() || ''; const pictureNeedsUpdate = waProfilePictureFile !== chatwootProfilePictureFile; const nameNeedsUpdate = !contact.name || contact.name === chatId; this.logger.verbose(`Picture needs update: ${pictureNeedsUpdate}`); this.logger.verbose(`Name needs update: ${nameNeedsUpdate}`); if (pictureNeedsUpdate || nameNeedsUpdate) { contact = await this.updateContact(instance, contact.id, { ...(nameNeedsUpdate && { name: nameContact }), ...(waProfilePictureFile === '' && { avatar: null }), ...(pictureNeedsUpdate && { avatar_url: picture_url?.profilePictureUrl }), }); } } } else { contact = await this.createContact( instance, chatId, filterInbox.id, isGroup, nameContact, picture_url.profilePictureUrl || null, phoneNumber, ); } if (!contact) { this.logger.warn(`Contact not created or found`); return null; } const contactId = contact?.payload?.id || contact?.payload?.contact?.id || contact?.id; this.logger.verbose(`Contact ID: ${contactId}`); const contactConversations = (await client.contacts.listConversations({ accountId: this.provider.accountId, id: contactId, })) as any; if (!contactConversations || !contactConversations.payload) { this.logger.error(`No conversations found or payload is undefined`); return null; } let inboxConversation = contactConversations.payload.find( (conversation) => conversation.inbox_id == filterInbox.id, ); if (inboxConversation) { if (this.provider.reopenConversation) { this.logger.verbose( `Found conversation in reopenConversation mode: ID: ${inboxConversation.id} - Name: ${inboxConversation.meta.sender.name} - Identifier: ${inboxConversation.meta.sender.identifier}`, ); if (inboxConversation && this.provider.conversationPending && inboxConversation.status !== 'open') { await client.conversations.toggleStatus({ accountId: this.provider.accountId, conversationId: inboxConversation.id, data: { status: 'pending', }, }); } } else { inboxConversation = contactConversations.payload.find( (conversation) => conversation && conversation.status !== 'resolved' && conversation.inbox_id == filterInbox.id, ); this.logger.verbose(`Found conversation: ${JSON.stringify(inboxConversation)}`); } if (inboxConversation) { this.logger.verbose(`Returning existing conversation ID: ${inboxConversation.id}`); this.cache.set(cacheKey, inboxConversation.id, 1800); return inboxConversation.id; } } const data = { contact_id: contactId.toString(), inbox_id: filterInbox.id.toString(), }; if (this.provider.conversationPending) { data['status'] = 'pending'; } const conversation = await client.conversations.create({ accountId: this.provider.accountId, data, }); if (!conversation) { this.logger.warn(`Conversation not created or found`); return null; } this.logger.verbose(`New conversation created of ${remoteJid} with ID: ${conversation.id}`); this.cache.set(cacheKey, conversation.id, 1800); return conversation.id; } finally { await this.cache.delete(lockKey); this.logger.verbose(`Block released for: ${lockKey}`); } } catch (error) { this.logger.error(`Error in createConversation: ${error}`); return null; } } public async getInbox(instance: InstanceDto): Promise { const cacheKey = `${instance.instanceName}:getInbox`; if (await this.cache.has(cacheKey)) { return (await this.cache.get(cacheKey)) as inbox; } const client = await this.clientCw(instance); if (!client) { this.logger.warn('client not found'); return null; } const inbox = (await client.inboxes.list({ accountId: this.provider.accountId, })) as any; if (!inbox) { this.logger.warn('inbox not found'); return null; } const findByName = inbox.payload.find((inbox) => inbox.name === this.getClientCwConfig().nameInbox); if (!findByName) { this.logger.warn('inbox not found'); return null; } this.cache.set(cacheKey, findByName); return findByName; } public async createMessage( instance: InstanceDto, conversationId: number, content: string, messageType: 'incoming' | 'outgoing' | undefined, privateMessage?: boolean, attachments?: { content: unknown; encoding: string; filename: string; }[], messageBody?: any, sourceId?: string, quotedMsg?: MessageModel, ) { const client = await this.clientCw(instance); if (!client) { this.logger.warn('client not found'); return null; } const replyToIds = await this.getReplyToIds(messageBody, instance); const sourceReplyId = quotedMsg?.chatwootMessageId || null; const message = await client.messages.create({ accountId: this.provider.accountId, conversationId: conversationId, data: { content: content, message_type: messageType, attachments: attachments, private: privateMessage || false, source_id: sourceId, content_attributes: { ...replyToIds, }, source_reply_id: sourceReplyId ? sourceReplyId.toString() : null, }, }); if (!message) { this.logger.warn('message not found'); return null; } return message; } public async getOpenConversationByContact( instance: InstanceDto, inbox: inbox, contact: generic_id & contact, ): Promise { const client = await this.clientCw(instance); if (!client) { this.logger.warn('client not found'); return null; } const conversations = (await client.contacts.listConversations({ accountId: this.provider.accountId, id: contact.id, })) as any; return ( conversations.payload.find( (conversation) => conversation.inbox_id === inbox.id && conversation.status === 'open', ) || undefined ); } public async createBotMessage( instance: InstanceDto, content: string, messageType: 'incoming' | 'outgoing' | undefined, attachments?: { content: unknown; encoding: string; filename: string; }[], ) { const client = await this.clientCw(instance); if (!client) { this.logger.warn('client not found'); return null; } const contact = await this.findContact(instance, '123456'); if (!contact) { this.logger.warn('contact not found'); return null; } const filterInbox = await this.getInbox(instance); if (!filterInbox) { this.logger.warn('inbox not found'); return null; } const conversation = await this.getOpenConversationByContact(instance, filterInbox, contact); if (!conversation) { this.logger.warn('conversation not found'); return; } const message = await client.messages.create({ accountId: this.provider.accountId, conversationId: conversation.id, data: { content: content, message_type: messageType, attachments: attachments, }, }); if (!message) { this.logger.warn('message not found'); return null; } return message; } private async sendData( conversationId: number, fileStream: Readable, fileName: string, messageType: 'incoming' | 'outgoing' | undefined, content?: string, instance?: InstanceDto, messageBody?: any, sourceId?: string, quotedMsg?: MessageModel, ) { if (sourceId && this.isImportHistoryAvailable()) { const messageAlreadySaved = await chatwootImport.getExistingSourceIds([sourceId], conversationId); if (messageAlreadySaved) { if (messageAlreadySaved.size > 0) { this.logger.warn('Message already saved on chatwoot'); return null; } } } const data = new FormData(); if (content) { data.append('content', content); } data.append('message_type', messageType); data.append('attachments[]', fileStream, { filename: fileName }); const sourceReplyId = quotedMsg?.chatwootMessageId || null; if (messageBody && instance) { const replyToIds = await this.getReplyToIds(messageBody, instance); if (replyToIds.in_reply_to || replyToIds.in_reply_to_external_id) { const content = JSON.stringify({ ...replyToIds, }); data.append('content_attributes', content); } } if (sourceReplyId) { data.append('source_reply_id', sourceReplyId.toString()); } if (sourceId) { data.append('source_id', sourceId); } const config = { method: 'post', maxBodyLength: Infinity, url: `${this.provider.url}/api/v1/accounts/${this.provider.accountId}/conversations/${conversationId}/messages`, headers: { api_access_token: this.provider.token, ...data.getHeaders(), }, data: data, }; try { const { data } = await axios.request(config); return data; } catch (error) { this.logger.error(error); } } public async createBotQr( instance: InstanceDto, content: string, messageType: 'incoming' | 'outgoing' | undefined, fileStream?: Readable, fileName?: string, ) { const client = await this.clientCw(instance); if (!client) { this.logger.warn('client not found'); return null; } if (!this.configService.get('CHATWOOT').BOT_CONTACT) { this.logger.log('Chatwoot bot contact is disabled'); return true; } const contact = await this.findContact(instance, '123456'); if (!contact) { this.logger.warn('contact not found'); return null; } const filterInbox = await this.getInbox(instance); if (!filterInbox) { this.logger.warn('inbox not found'); return null; } const conversation = await this.getOpenConversationByContact(instance, filterInbox, contact); if (!conversation) { this.logger.warn('conversation not found'); return; } const data = new FormData(); if (content) { data.append('content', content); } data.append('message_type', messageType); if (fileStream && fileName) { data.append('attachments[]', fileStream, { filename: fileName }); } const config = { method: 'post', maxBodyLength: Infinity, url: `${this.provider.url}/api/v1/accounts/${this.provider.accountId}/conversations/${conversation.id}/messages`, headers: { api_access_token: this.provider.token, ...data.getHeaders(), }, data: data, }; try { const { data } = await axios.request(config); return data; } catch (error) { this.logger.error(error); } } public async sendAttachment(waInstance: any, number: string, media: any, caption?: string, options?: Options) { try { const parsedMedia = path.parse(decodeURIComponent(media)); let mimeType = mimeTypes.lookup(parsedMedia?.ext) || ''; let fileName = parsedMedia?.name + parsedMedia?.ext; if (!mimeType) { const parts = media.split('/'); fileName = decodeURIComponent(parts[parts.length - 1]); const response = await axios.get(media, { responseType: 'arraybuffer', }); mimeType = response.headers['content-type']; } let type = 'document'; switch (mimeType.split('/')[0]) { case 'image': type = 'image'; break; case 'video': type = 'video'; break; case 'audio': type = 'audio'; break; default: type = 'document'; break; } if (type === 'audio') { const data: SendAudioDto = { number: number, audio: media, delay: Math.floor(Math.random() * (2000 - 500 + 1)) + 500, quoted: options?.quoted, }; sendTelemetry('/message/sendWhatsAppAudio'); const messageSent = await waInstance?.audioWhatsapp(data, null, true); return messageSent; } const documentExtensions = ['.gif', '.svg', '.tiff', '.tif', '.dxf', '.dwg']; if (type === 'image' && parsedMedia && documentExtensions.includes(parsedMedia?.ext)) { type = 'document'; } const data: SendMediaDto = { number: number, mediatype: type as any, fileName: fileName, media: media, delay: 1200, quoted: options?.quoted, }; sendTelemetry('/message/sendMedia'); if (caption) { data.caption = caption; } const messageSent = await waInstance?.mediaMessage(data, null, true); return messageSent; } catch (error) { this.logger.error(error); throw error; // Re-throw para que o erro seja tratado pelo caller } } public async onSendMessageError(instance: InstanceDto, conversation: number, error?: any) { this.logger.verbose(`onSendMessageError ${JSON.stringify(error)}`); const client = await this.clientCw(instance); if (!client) { return; } if (error && error?.status === 400 && error?.message[0]?.exists === false) { client.messages.create({ accountId: this.provider.accountId, conversationId: conversation, data: { content: `${i18next.t('cw.message.numbernotinwhatsapp')}`, message_type: 'outgoing', private: true, }, }); return; } client.messages.create({ accountId: this.provider.accountId, conversationId: conversation, data: { content: i18next.t('cw.message.notsent', { error: error ? `_${error.toString()}_` : '', }), message_type: 'outgoing', private: true, }, }); } public async receiveWebhook(instance: InstanceDto, body: any) { try { await new Promise((resolve) => setTimeout(resolve, 500)); const client = await this.clientCw(instance); if (!client) { this.logger.warn('client not found'); return null; } if ( this.provider.reopenConversation === false && body.event === 'conversation_status_changed' && body.status === 'resolved' && body.meta?.sender?.identifier ) { const keyToDelete = `${instance.instanceName}:createConversation-${body.meta.sender.identifier}`; this.cache.delete(keyToDelete); } if ( !body?.conversation || body.private || (body.event === 'message_updated' && !body.content_attributes?.deleted) ) { return { message: 'bot' }; } const chatId = body.conversation.meta.sender?.identifier || body.conversation.meta.sender?.phone_number.replace('+', ''); // Chatwoot to Whatsapp const messageReceived = body.content ? body.content .replaceAll(/(?('CHATWOOT').BOT_CONTACT; if (chatId === '123456' && body.message_type === 'outgoing') { const command = messageReceived.replace('/', ''); if (cwBotContact && (command.includes('init') || command.includes('iniciar'))) { const state = waInstance?.connectionStatus?.state; if (state !== 'open') { const number = command.split(':')[1]; await waInstance.connectToWhatsapp(number); } else { await this.createBotMessage( instance, i18next.t('cw.inbox.alreadyConnected', { inboxName: body.inbox.name, }), 'incoming', ); } } if (command === 'clearcache') { waInstance.clearCacheChatwoot(); await this.createBotMessage( instance, i18next.t('cw.inbox.clearCache', { inboxName: body.inbox.name, }), 'incoming', ); } if (command === 'status') { const state = waInstance?.connectionStatus?.state; if (!state) { await this.createBotMessage( instance, i18next.t('cw.inbox.notFound', { inboxName: body.inbox.name, }), 'incoming', ); } if (state) { await this.createBotMessage( instance, i18next.t('cw.inbox.status', { inboxName: body.inbox.name, state: state, }), 'incoming', ); } } if (cwBotContact && (command === 'disconnect' || command === 'desconectar')) { const msgLogout = i18next.t('cw.inbox.disconnect', { inboxName: body.inbox.name, }); await this.createBotMessage(instance, msgLogout, 'incoming'); await waInstance?.client?.logout('Log out instance: ' + instance.instanceName); await waInstance?.client?.ws?.close(); } } if (body.message_type === 'outgoing' && body?.conversation?.messages?.length && chatId !== '123456') { if (body?.conversation?.messages[0]?.source_id?.substring(0, 5) === 'WAID:') { return { message: 'bot' }; } if (!waInstance && body.conversation?.id) { this.onSendMessageError(instance, body.conversation?.id, 'Instance not found'); return { message: 'bot' }; } let formatText: string; if (senderName === null || senderName === undefined) { formatText = messageReceived; } else { const formattedDelimiter = this.provider.signDelimiter ? this.provider.signDelimiter.replaceAll('\\n', '\n') : '\n'; const textToConcat = this.provider.signMsg ? [`*${senderName}:*`] : []; textToConcat.push(messageReceived); formatText = textToConcat.join(formattedDelimiter); } for (const message of body.conversation.messages) { if (message.attachments && message.attachments.length > 0) { for (const attachment of message.attachments) { if (!messageReceived) { formatText = null; } const options: Options = { quoted: await this.getQuotedMessage(body, instance), }; const messageSent = await this.sendAttachment( waInstance, chatId, attachment.data_url, formatText, options, ); if (!messageSent && body.conversation?.id) { this.onSendMessageError(instance, body.conversation?.id); } await this.updateChatwootMessageId( { ...messageSent, }, { messageId: body.id, inboxId: body.inbox?.id, conversationId: body.conversation?.id, contactInboxSourceId: body.conversation?.contact_inbox?.source_id, }, instance, ); } } else { const data: SendTextDto = { number: chatId, text: formatText, delay: Math.floor(Math.random() * (2000 - 500 + 1)) + 500, quoted: await this.getQuotedMessage(body, instance), }; sendTelemetry('/message/sendText'); let messageSent: any; try { messageSent = await waInstance?.textMessage(data, true); if (!messageSent) { throw new Error('Message not sent'); } if (Long.isLong(messageSent?.messageTimestamp)) { messageSent.messageTimestamp = messageSent.messageTimestamp?.toNumber(); } await this.updateChatwootMessageId( { ...messageSent, }, { messageId: body.id, inboxId: body.inbox?.id, conversationId: body.conversation?.id, contactInboxSourceId: body.conversation?.contact_inbox?.source_id, }, instance, ); } catch (error) { if (!messageSent && body.conversation?.id) { this.onSendMessageError(instance, body.conversation?.id, error); } throw error; } } } const chatwootRead = this.configService.get('CHATWOOT').MESSAGE_READ; if (chatwootRead) { const lastMessage = await this.prismaRepository.message.findFirst({ where: { key: { path: ['fromMe'], equals: false, }, instanceId: instance.instanceId, }, }); if (lastMessage && !lastMessage.chatwootIsRead) { const key = lastMessage.key as WAMessageKey; waInstance?.markMessageAsRead({ readMessages: [ { id: key.id, fromMe: key.fromMe, remoteJid: key.remoteJid, }, ], }); const updateMessage = { chatwootMessageId: lastMessage.chatwootMessageId, chatwootConversationId: lastMessage.chatwootConversationId, chatwootInboxId: lastMessage.chatwootInboxId, chatwootContactInboxSourceId: lastMessage.chatwootContactInboxSourceId, chatwootIsRead: true, }; await this.prismaRepository.message.updateMany({ where: { instanceId: instance.instanceId, key: { path: ['id'], equals: key.id, }, }, data: updateMessage, }); } } } if (body.message_type === 'template' && body.event === 'message_created') { const data: SendTextDto = { number: chatId, text: body.content.replace(/\\\r\n|\\\n|\n/g, '\n'), delay: Math.floor(Math.random() * (2000 - 500 + 1)) + 500, }; sendTelemetry('/message/sendText'); await waInstance?.textMessage(data); } return { message: 'bot' }; } catch (error) { this.logger.error(error); return { message: 'bot' }; } } private async updateChatwootMessageId( message: MessageModel, chatwootMessageIds: ChatwootMessage, instance: InstanceDto, ) { const key = message.key as WAMessageKey; if (!chatwootMessageIds.messageId || !key?.id) { return; } // Use raw SQL to avoid JSON path issues const result = await this.prismaRepository.$executeRaw` UPDATE "Message" SET "chatwootMessageId" = ${chatwootMessageIds.messageId}, "chatwootConversationId" = ${chatwootMessageIds.conversationId}, "chatwootInboxId" = ${chatwootMessageIds.inboxId}, "chatwootContactInboxSourceId" = ${chatwootMessageIds.contactInboxSourceId}, "chatwootIsRead" = ${chatwootMessageIds.isRead || false} WHERE "instanceId" = ${instance.instanceId} AND "key"->>'id' = ${key.id} `; this.logger.verbose(`Update result: ${result} rows affected`); if (this.isImportHistoryAvailable()) { try { await chatwootImport.updateMessageSourceID(chatwootMessageIds.messageId, key.id); } catch (error) { this.logger.error(`Error updating Chatwoot message source ID: ${error}`); } } } private async getMessageByKeyId(instance: InstanceDto, keyId: string): Promise { // Use raw SQL query to avoid JSON path issues with Prisma const messages = await this.prismaRepository.$queryRaw` SELECT * FROM "Message" WHERE "instanceId" = ${instance.instanceId} AND "key"->>'id' = ${keyId} LIMIT 1 `; return (messages as MessageModel[])[0] || null; } private async getReplyToIds( msg: any, instance: InstanceDto, ): Promise<{ in_reply_to: string; in_reply_to_external_id: string }> { let inReplyTo = null; let inReplyToExternalId = null; if (msg) { inReplyToExternalId = msg.message?.extendedTextMessage?.contextInfo?.stanzaId ?? msg.contextInfo?.stanzaId; if (inReplyToExternalId) { const message = await this.getMessageByKeyId(instance, inReplyToExternalId); if (message?.chatwootMessageId) { inReplyTo = message.chatwootMessageId; } } } return { in_reply_to: inReplyTo, in_reply_to_external_id: inReplyToExternalId, }; } private async getQuotedMessage(msg: any, instance: InstanceDto): Promise { if (msg?.content_attributes?.in_reply_to) { const message = await this.prismaRepository.message.findFirst({ where: { chatwootMessageId: msg?.content_attributes?.in_reply_to, instanceId: instance.instanceId, }, }); const key = message?.key as WAMessageKey; const messageContent = message?.message as WAMessageContent; if (messageContent && key?.id) { return { key: key, message: messageContent, }; } } return null; } private isMediaMessage(message: any) { const media = [ 'imageMessage', 'documentMessage', 'documentWithCaptionMessage', 'audioMessage', 'videoMessage', 'stickerMessage', 'viewOnceMessageV2', ]; const messageKeys = Object.keys(message); const result = messageKeys.some((key) => media.includes(key)); return result; } private isInteractiveButtonMessage(messageType: string, message: any) { return messageType === 'interactiveMessage' && message.interactiveMessage?.nativeFlowMessage?.buttons?.length > 0; } private getAdsMessage(msg: any) { interface AdsMessage { title: string; body: string; thumbnailUrl: string; sourceUrl: string; } const adsMessage: AdsMessage | undefined = { title: msg.extendedTextMessage?.contextInfo?.externalAdReply?.title || msg.contextInfo?.externalAdReply?.title, body: msg.extendedTextMessage?.contextInfo?.externalAdReply?.body || msg.contextInfo?.externalAdReply?.body, thumbnailUrl: msg.extendedTextMessage?.contextInfo?.externalAdReply?.thumbnailUrl || msg.contextInfo?.externalAdReply?.thumbnailUrl, sourceUrl: msg.extendedTextMessage?.contextInfo?.externalAdReply?.sourceUrl || msg.contextInfo?.externalAdReply?.sourceUrl, }; return adsMessage; } private getReactionMessage(msg: any) { interface ReactionMessage { key: { id: string; fromMe: boolean; remoteJid: string; participant?: string; }; text: string; } const reactionMessage: ReactionMessage | undefined = msg?.reactionMessage; return reactionMessage; } private getTypeMessage(msg: any) { const types = { conversation: msg.conversation, imageMessage: msg.imageMessage?.caption, videoMessage: msg.videoMessage?.caption, extendedTextMessage: msg.extendedTextMessage?.text, messageContextInfo: msg.messageContextInfo?.stanzaId, stickerMessage: undefined, documentMessage: msg.documentMessage?.caption, documentWithCaptionMessage: msg.documentWithCaptionMessage?.message?.documentMessage?.caption, audioMessage: msg.audioMessage ? (msg.audioMessage.caption ?? '') : undefined, contactMessage: msg.contactMessage?.vcard, contactsArrayMessage: msg.contactsArrayMessage, locationMessage: msg.locationMessage, liveLocationMessage: msg.liveLocationMessage, listMessage: msg.listMessage, listResponseMessage: msg.listResponseMessage, viewOnceMessageV2: msg?.message?.viewOnceMessageV2?.message?.imageMessage?.url || msg?.message?.viewOnceMessageV2?.message?.videoMessage?.url || msg?.message?.viewOnceMessageV2?.message?.audioMessage?.url, }; return types; } private getMessageContent(types: any) { const typeKey = Object.keys(types).find((key) => types[key] !== undefined); let result = typeKey ? types[typeKey] : undefined; // Remove externalAdReplyBody| in Chatwoot (Already Have) if (result && typeof result === 'string' && result.includes('externalAdReplyBody|')) { result = result.split('externalAdReplyBody|').filter(Boolean).join(''); } if (typeKey === 'locationMessage' || typeKey === 'liveLocationMessage') { const latitude = result.degreesLatitude; const longitude = result.degreesLongitude; const locationName = result?.name; const locationAddress = result?.address; const formattedLocation = `*${i18next.t('cw.locationMessage.location')}:*\n\n` + `_${i18next.t('cw.locationMessage.latitude')}:_ ${latitude} \n` + `_${i18next.t('cw.locationMessage.longitude')}:_ ${longitude} \n` + (locationName ? `_${i18next.t('cw.locationMessage.locationName')}:_ ${locationName}\n` : '') + (locationAddress ? `_${i18next.t('cw.locationMessage.locationAddress')}:_ ${locationAddress} \n` : '') + `_${i18next.t('cw.locationMessage.locationUrl')}:_ ` + `https://www.google.com/maps/search/?api=1&query=${latitude},${longitude}`; return formattedLocation; } if (typeKey === 'contactMessage') { const vCardData = result.split('\n'); const contactInfo = {}; vCardData.forEach((line) => { const [key, value] = line.split(':'); if (key && value) { contactInfo[key] = value; } }); let formattedContact = `*${i18next.t('cw.contactMessage.contact')}:*\n\n` + `_${i18next.t('cw.contactMessage.name')}:_ ${contactInfo['FN']}`; let numberCount = 1; Object.keys(contactInfo).forEach((key) => { if (key.startsWith('item') && key.includes('TEL')) { const phoneNumber = contactInfo[key]; formattedContact += `\n_${i18next.t('cw.contactMessage.number')} (${numberCount}):_ ${phoneNumber}`; numberCount++; } else if (key.includes('TEL')) { const phoneNumber = contactInfo[key]; formattedContact += `\n_${i18next.t('cw.contactMessage.number')} (${numberCount}):_ ${phoneNumber}`; numberCount++; } }); return formattedContact; } if (typeKey === 'contactsArrayMessage') { const formattedContacts = result.contacts.map((contact) => { const vCardData = contact.vcard.split('\n'); const contactInfo = {}; vCardData.forEach((line) => { const [key, value] = line.split(':'); if (key && value) { contactInfo[key] = value; } }); let formattedContact = `*${i18next.t('cw.contactMessage.contact')}:*\n\n_${i18next.t( 'cw.contactMessage.name', )}:_ ${contact.displayName}`; let numberCount = 1; Object.keys(contactInfo).forEach((key) => { if (key.startsWith('item') && key.includes('TEL')) { const phoneNumber = contactInfo[key]; formattedContact += `\n_${i18next.t('cw.contactMessage.number')} (${numberCount}):_ ${phoneNumber}`; numberCount++; } else if (key.includes('TEL')) { const phoneNumber = contactInfo[key]; formattedContact += `\n_${i18next.t('cw.contactMessage.number')} (${numberCount}):_ ${phoneNumber}`; numberCount++; } }); return formattedContact; }); const formattedContactsArray = formattedContacts.join('\n\n'); return formattedContactsArray; } if (typeKey === 'listMessage') { const listTitle = result?.title || 'Unknown'; const listDescription = result?.description || 'Unknown'; const listFooter = result?.footerText || 'Unknown'; let formattedList = '*List Menu:*\n\n' + '_Title_: ' + listTitle + '\n' + '_Description_: ' + listDescription + '\n' + '_Footer_: ' + listFooter; if (result.sections && result.sections.length > 0) { result.sections.forEach((section, sectionIndex) => { formattedList += '\n\n*Section ' + (sectionIndex + 1) + ':* ' + section.title || 'Unknown\n'; if (section.rows && section.rows.length > 0) { section.rows.forEach((row, rowIndex) => { formattedList += '\n*Line ' + (rowIndex + 1) + ':*\n'; formattedList += '_▪️ Title:_ ' + (row.title || 'Unknown') + '\n'; formattedList += '_▪️ Description:_ ' + (row.description || 'Unknown') + '\n'; formattedList += '_▪️ ID:_ ' + (row.rowId || 'Unknown') + '\n'; }); } else { formattedList += '\nNo lines found in this section.\n'; } }); } else { formattedList += '\nNo sections found.\n'; } return formattedList; } if (typeKey === 'listResponseMessage') { const responseTitle = result?.title || 'Unknown'; const responseDescription = result?.description || 'Unknown'; const responseRowId = result?.singleSelectReply?.selectedRowId || 'Unknown'; const formattedResponseList = '*List Response:*\n\n' + '_Title_: ' + responseTitle + '\n' + '_Description_: ' + responseDescription + '\n' + '_ID_: ' + responseRowId; return formattedResponseList; } return result; } public getConversationMessage(msg: any) { const types = this.getTypeMessage(msg); const messageContent = this.getMessageContent(types); return messageContent; } public async eventWhatsapp(event: string, instance: InstanceDto, body: any) { try { const waInstance = this.waMonitor.waInstances[instance.instanceName]; if (!waInstance) { this.logger.warn('wa instance not found'); return null; } const client = await this.clientCw(instance); if (!client) { this.logger.warn('client not found'); return null; } if (this.provider?.ignoreJids && this.provider?.ignoreJids.length > 0) { const ignoreJids: any = this.provider?.ignoreJids; let ignoreGroups = false; let ignoreContacts = false; if (ignoreJids.includes('@g.us')) { ignoreGroups = true; } if (ignoreJids.includes('@s.whatsapp.net')) { ignoreContacts = true; } if (ignoreGroups && body?.key?.remoteJid.endsWith('@g.us')) { this.logger.warn('Ignoring message from group: ' + body?.key?.remoteJid); return; } if (ignoreContacts && body?.key?.remoteJid.endsWith('@s.whatsapp.net')) { this.logger.warn('Ignoring message from contact: ' + body?.key?.remoteJid); return; } if (ignoreJids.includes(body?.key?.remoteJid)) { this.logger.warn('Ignoring message from jid: ' + body?.key?.remoteJid); return; } } if (event === 'messages.upsert' || event === 'send.message') { this.logger.info(`[${event}] New message received - Instance: ${JSON.stringify(body, null, 2)}`); if (body.key.remoteJid === 'status@broadcast') { return; } if (body.message?.ephemeralMessage?.message) { body.message = { ...body.message?.ephemeralMessage?.message, }; } const originalMessage = await this.getConversationMessage(body.message); const bodyMessage = originalMessage ? originalMessage .replaceAll(/\*((?!\s)([^\n*]+?)(? {}; fileStream.push(fileData); fileStream.push(null); if (body.key.remoteJid.includes('@g.us')) { const participantName = body.pushName; const rawPhoneNumber = body.key.addressingMode === 'lid' && !body.key.fromMe && body.key.participantAlt ? body.key.participantAlt.split('@')[0].split(':')[0] : body.key.participant.split('@')[0].split(':')[0]; const formattedPhoneNumber = parsePhoneNumberFromString(`+${rawPhoneNumber}`).formatInternational(); let content: string; if (!body.key.fromMe) { content = bodyMessage ? `**${formattedPhoneNumber} - ${participantName}:**\n\n${bodyMessage}` : `**${formattedPhoneNumber} - ${participantName}:**`; } else { content = bodyMessage || ''; } const send = await this.sendData( getConversation, fileStream, nameFile, messageType, content, instance, body, 'WAID:' + body.key.id, quotedMsg, ); if (!send) { this.logger.warn('message not sent'); return; } return send; } else { const send = await this.sendData( getConversation, fileStream, nameFile, messageType, bodyMessage, instance, body, 'WAID:' + body.key.id, quotedMsg, ); if (!send) { this.logger.warn('message not sent'); return; } return send; } } if (reactionMessage) { if (reactionMessage.text) { const send = await this.createMessage( instance, getConversation, reactionMessage.text, messageType, false, [], { message: { extendedTextMessage: { contextInfo: { stanzaId: reactionMessage.key.id } } }, }, 'WAID:' + body.key.id, quotedMsg, ); if (!send) { this.logger.warn('message not sent'); return; } } return; } if (isInteractiveButtonMessage) { const buttons = body.message.interactiveMessage.nativeFlowMessage.buttons; this.logger.info('is Interactive Button Message: ' + JSON.stringify(buttons)); for (const button of buttons) { const buttonParams = JSON.parse(button.buttonParamsJson); const paymentSettings = buttonParams.payment_settings; if (button.name === 'payment_info' && paymentSettings[0].type === 'pix_static_code') { const pixSettings = paymentSettings[0].pix_static_code; const pixKeyType = (() => { switch (pixSettings.key_type) { case 'EVP': return 'Chave Aleatória'; case 'EMAIL': return 'E-mail'; case 'PHONE': return 'Telefone'; default: return pixSettings.key_type; } })(); const pixKey = pixSettings.key_type === 'PHONE' ? pixSettings.key.replace('+55', '') : pixSettings.key; const content = `*${pixSettings.merchant_name}*\nChave PIX: ${pixKey} (${pixKeyType})`; const send = await this.createMessage( instance, getConversation, content, messageType, false, [], body, 'WAID:' + body.key.id, quotedMsg, ); if (!send) this.logger.warn('message not sent'); } else { this.logger.warn('Interactive Button Message not mapped'); } } return; } const isAdsMessage = (adsMessage && adsMessage.title) || adsMessage.body || adsMessage.thumbnailUrl; if (isAdsMessage) { const imgBuffer = await axios.get(adsMessage.thumbnailUrl, { responseType: 'arraybuffer' }); const extension = mimeTypes.extension(imgBuffer.headers['content-type']); const mimeType = extension && mimeTypes.lookup(extension); if (!mimeType) { this.logger.warn('mimetype of Ads message not found'); return; } const random = Math.random().toString(36).substring(7); const nameFile = `${random}.${mimeTypes.extension(mimeType)}`; const fileData = Buffer.from(imgBuffer.data, 'binary'); const img = await Jimp.read(fileData); await img.cover({ w: 320, h: 180, }); const processedBuffer = await img.getBuffer(JimpMime.png); const fileStream = new Readable(); fileStream._read = () => {}; // _read is required but you can noop it fileStream.push(processedBuffer); fileStream.push(null); const truncStr = (str: string, len: number) => { if (!str) return ''; return str.length > len ? str.substring(0, len) + '...' : str; }; const title = truncStr(adsMessage.title, 40); const description = truncStr(adsMessage?.body, 75); const send = await this.sendData( getConversation, fileStream, nameFile, messageType, `${bodyMessage}\n\n\n**${title}**\n${description}\n${adsMessage.sourceUrl}`, instance, body, 'WAID:' + body.key.id, ); if (!send) { this.logger.warn('message not sent'); return; } return send; } if (body.key.remoteJid.includes('@g.us')) { const participantName = body.pushName; const rawPhoneNumber = body.key.addressingMode === 'lid' && !body.key.fromMe && body.key.participantAlt ? body.key.participantAlt.split('@')[0].split(':')[0] : body.key.participant.split('@')[0].split(':')[0]; const formattedPhoneNumber = parsePhoneNumberFromString(`+${rawPhoneNumber}`).formatInternational(); let content: string; if (!body.key.fromMe) { content = `**${formattedPhoneNumber} - ${participantName}:**\n\n${bodyMessage}`; } else { content = `${bodyMessage}`; } const send = await this.createMessage( instance, getConversation, content, messageType, false, [], body, 'WAID:' + body.key.id, quotedMsg, ); if (!send) { this.logger.warn('message not sent'); return; } return send; } else { const send = await this.createMessage( instance, getConversation, bodyMessage, messageType, false, [], body, 'WAID:' + body.key.id, quotedMsg, ); if (!send) { this.logger.warn('message not sent'); return; } return send; } } if (event === Events.MESSAGES_DELETE) { const chatwootDelete = this.configService.get('CHATWOOT').MESSAGE_DELETE; if (chatwootDelete === true) { if (!body?.key?.id) { this.logger.warn('message id not found'); return; } const message = await this.getMessageByKeyId(instance, body.key.id); if (message?.chatwootMessageId && message?.chatwootConversationId) { await this.prismaRepository.message.deleteMany({ where: { key: { path: ['id'], equals: body.key.id, }, instanceId: instance.instanceId, }, }); return await client.messages.delete({ accountId: this.provider.accountId, conversationId: message.chatwootConversationId, messageId: message.chatwootMessageId, }); } } } if (event === 'messages.edit' || event === 'send.message.update') { const editedMessageContentRaw = body?.editedMessage?.conversation ?? body?.editedMessage?.extendedTextMessage?.text ?? body?.editedMessage?.imageMessage?.caption ?? body?.editedMessage?.videoMessage?.caption ?? body?.editedMessage?.documentMessage?.caption ?? (typeof body?.text === 'string' ? body.text : undefined); const editedMessageContent = (editedMessageContentRaw ?? '').trim(); if (!editedMessageContent) { this.logger.info('[CW.EDIT] Conteúdo vazio — ignorando (DELETE tratará se for revoke).'); return; } const message = await this.getMessageByKeyId(instance, body?.key?.id); if (!message) { this.logger.warn('Message not found for edit event'); return; } const key = message.key as WAMessageKey; const messageType = key?.fromMe ? 'outgoing' : 'incoming'; if (message && message.chatwootConversationId && message.chatwootMessageId) { // Criar nova mensagem com formato: "Mensagem editada:\n\nteste1" const editedText = `\n\n\`${i18next.t('cw.message.edited')}:\`\n\n${editedMessageContent}`; const send = await this.createMessage( instance, message.chatwootConversationId, editedText, messageType, false, [], { message: { extendedTextMessage: { contextInfo: { stanzaId: key.id } } }, }, 'WAID:' + body.key.id, null, ); if (!send) { this.logger.warn('edited message not sent'); return; } } return; } if (event === 'messages.read') { if (!body?.key?.id || !body?.key?.remoteJid) { this.logger.warn('message id not found'); return; } const message = await this.getMessageByKeyId(instance, body.key.id); const conversationId = message?.chatwootConversationId; const contactInboxSourceId = message?.chatwootContactInboxSourceId; if (conversationId) { let sourceId = contactInboxSourceId; const inbox = (await this.getInbox(instance)) as inbox & { inbox_identifier?: string; }; if (!sourceId && inbox) { const conversation = (await client.conversations.get({ accountId: this.provider.accountId, conversationId: conversationId, })) as conversation_show & { last_non_activity_message: { conversation: { contact_inbox: contact_inboxes } }; }; sourceId = conversation.last_non_activity_message?.conversation?.contact_inbox?.source_id; } if (sourceId && inbox?.inbox_identifier) { const url = `/public/api/v1/inboxes/${inbox.inbox_identifier}/contacts/${sourceId}` + `/conversations/${conversationId}/update_last_seen`; await chatwootRequest(this.getClientCwConfig(), { method: 'POST', url: url, }); } } return; } if (event === 'status.instance') { const data = body; const inbox = await this.getInbox(instance); if (!inbox) { this.logger.warn('inbox not found'); return; } const msgStatus = i18next.t('cw.inbox.status', { inboxName: inbox.name, state: data.status, }); await this.createBotMessage(instance, msgStatus, 'incoming'); } if (event === 'connection.update' && body.status === 'open') { const waInstance = this.waMonitor.waInstances[instance.instanceName]; if (!waInstance) return; const now = Date.now(); const timeSinceLastNotification = now - (waInstance.lastConnectionNotification || 0); // Se a conexão foi estabelecida via QR code, notifica imediatamente. if (waInstance.qrCode && waInstance.qrCode.count > 0) { const msgConnection = i18next.t('cw.inbox.connected'); await this.createBotMessage(instance, msgConnection, 'incoming'); waInstance.qrCode.count = 0; waInstance.lastConnectionNotification = now; chatwootImport.clearAll(instance); } // Se não foi via QR code, verifica o throttling. else if (timeSinceLastNotification >= 30000) { const msgConnection = i18next.t('cw.inbox.connected'); await this.createBotMessage(instance, msgConnection, 'incoming'); waInstance.lastConnectionNotification = now; } else { this.logger.warn( `Connection notification skipped for ${instance.instanceName} - too frequent (${timeSinceLastNotification}ms since last)`, ); } } if (event === 'qrcode.updated') { if (body.statusCode === 500) { const erroQRcode = `🚨 ${i18next.t('qrlimitreached')}`; return await this.createBotMessage(instance, erroQRcode, 'incoming'); } else { const fileData = Buffer.from(body?.qrcode.base64.replace('data:image/png;base64,', ''), 'base64'); const fileStream = new Readable(); fileStream._read = () => {}; fileStream.push(fileData); fileStream.push(null); await this.createBotQr( instance, i18next.t('qrgeneratedsuccesfully'), 'incoming', fileStream, `${instance.instanceName}.png`, ); let msgQrCode = `⚡️${i18next.t('qrgeneratedsuccesfully')}\n\n${i18next.t('scanqr')}`; if (body?.qrcode?.pairingCode) { msgQrCode = msgQrCode + `\n\n*Pairing Code:* ${body.qrcode.pairingCode.substring(0, 4)}-${body.qrcode.pairingCode.substring( 4, 8, )}`; } await this.createBotMessage(instance, msgQrCode, 'incoming'); } } } catch (error) { this.logger.error(error); } } public normalizeJidIdentifier(remoteJid: string) { if (!remoteJid) { return ''; } if (remoteJid.includes('@lid')) { return remoteJid; } return remoteJid.replace(/:\d+/, '').split('@')[0]; } public startImportHistoryMessages(instance: InstanceDto) { if (!this.isImportHistoryAvailable()) { return; } this.createBotMessage(instance, i18next.t('cw.import.startImport'), 'incoming'); } public isImportHistoryAvailable() { const uri = this.configService.get('CHATWOOT').IMPORT.DATABASE.CONNECTION.URI; return uri && uri !== 'postgres://user:password@hostname:port/dbname'; } public addHistoryMessages(instance: InstanceDto, messagesRaw: MessageModel[]) { if (!this.isImportHistoryAvailable()) { return; } chatwootImport.addHistoryMessages(instance, messagesRaw); } public addHistoryContacts(instance: InstanceDto, contactsRaw: ContactModel[]) { if (!this.isImportHistoryAvailable()) { return; } return chatwootImport.addHistoryContacts(instance, contactsRaw); } public async importHistoryMessages(instance: InstanceDto) { if (!this.isImportHistoryAvailable()) { return; } this.createBotMessage(instance, i18next.t('cw.import.importingMessages'), 'incoming'); const totalMessagesImported = await chatwootImport.importHistoryMessages( instance, this, await this.getInbox(instance), this.provider, ); this.updateContactAvatarInRecentConversations(instance); const msg = Number.isInteger(totalMessagesImported) ? i18next.t('cw.import.messagesImported', { totalMessagesImported }) : i18next.t('cw.import.messagesException'); this.createBotMessage(instance, msg, 'incoming'); return totalMessagesImported; } public async updateContactAvatarInRecentConversations(instance: InstanceDto, limitContacts = 100) { try { if (!this.isImportHistoryAvailable()) { return; } const client = await this.clientCw(instance); if (!client) { this.logger.warn('client not found'); return null; } const inbox = await this.getInbox(instance); if (!inbox) { this.logger.warn('inbox not found'); return null; } const recentContacts = await chatwootImport.getContactsOrderByRecentConversations( inbox, this.provider, limitContacts, ); const contactIdentifiers = recentContacts .map((contact) => contact.identifier) .filter((identifier) => identifier !== null); const contactsWithProfilePicture = ( await this.prismaRepository.contact.findMany({ where: { instanceId: instance.instanceId, id: { in: contactIdentifiers, }, profilePicUrl: { not: null, }, }, }) ).reduce((acc: Map, contact: ContactModel) => acc.set(contact.id, contact), new Map()); recentContacts.forEach(async (contact) => { if (contactsWithProfilePicture.has(contact.identifier)) { client.contacts.update({ accountId: this.provider.accountId, id: contact.id, data: { avatar_url: contactsWithProfilePicture.get(contact.identifier).profilePictureUrl || null, }, }); } }); } catch (error) { this.logger.error(`Error on update avatar in recent conversations: ${error.toString()}`); } } public async syncLostMessages( instance: InstanceDto, chatwootConfig: ChatwootDto, prepareMessage: (message: any) => any, ) { try { if (!this.isImportHistoryAvailable()) { return; } if (!this.configService.get('DATABASE').SAVE_DATA.MESSAGE_UPDATE) { return; } const inbox = await this.getInbox(instance); const sqlMessages = `select * from messages m where account_id = ${chatwootConfig.accountId} and inbox_id = ${inbox.id} and created_at >= now() - interval '6h' order by created_at desc`; const messagesData = (await this.pgClient.query(sqlMessages))?.rows; const ids: string[] = messagesData .filter((message) => !!message.source_id) .map((message) => message.source_id.replace('WAID:', '')); const savedMessages = await this.prismaRepository.message.findMany({ where: { Instance: { name: instance.instanceName }, messageTimestamp: { gte: Number(dayjs().subtract(6, 'hours').unix()) }, AND: ids.map((id) => ({ key: { path: ['id'], not: id } })), }, }); const filteredMessages = savedMessages.filter( (msg: any) => !chatwootImport.isIgnorePhoneNumber(msg.key?.remoteJid), ); const messagesRaw: any[] = []; for (const m of filteredMessages) { if (!m.message || !m.key || !m.messageTimestamp) { continue; } if (Long.isLong(m?.messageTimestamp)) { m.messageTimestamp = m.messageTimestamp?.toNumber(); } messagesRaw.push(prepareMessage(m as any)); } this.addHistoryMessages( instance, messagesRaw.filter((msg) => !chatwootImport.isIgnorePhoneNumber(msg.key?.remoteJid)), ); await chatwootImport.importHistoryMessages(instance, this, inbox, this.provider); const waInstance = this.waMonitor.waInstances[instance.instanceName]; waInstance.clearCacheChatwoot(); } catch { return; } } } ================================================ FILE: src/api/integrations/chatbot/chatwoot/utils/chatwoot-import-helper.ts ================================================ import { InstanceDto } from '@api/dto/instance.dto'; import { ChatwootDto } from '@api/integrations/chatbot/chatwoot/dto/chatwoot.dto'; import { postgresClient } from '@api/integrations/chatbot/chatwoot/libs/postgres.client'; import { ChatwootService } from '@api/integrations/chatbot/chatwoot/services/chatwoot.service'; import { Chatwoot, configService } from '@config/env.config'; import { Logger } from '@config/logger.config'; import { inbox } from '@figuro/chatwoot-sdk'; import { Chatwoot as ChatwootModel, Contact, Message } from '@prisma/client'; import { proto } from 'baileys'; type ChatwootUser = { user_type: string; user_id: number; }; type FksChatwoot = { phone_number: string; contact_id: string; conversation_id: string; }; type firstLastTimestamp = { first: number; last: number; }; type IWebMessageInfo = Omit & Partial>; class ChatwootImport { private logger = new Logger('ChatwootImport'); private repositoryMessagesCache = new Map>(); private historyMessages = new Map(); private historyContacts = new Map(); public getRepositoryMessagesCache(instance: InstanceDto) { return this.repositoryMessagesCache.has(instance.instanceName) ? this.repositoryMessagesCache.get(instance.instanceName) : null; } public setRepositoryMessagesCache(instance: InstanceDto, repositoryMessagesCache: Set) { this.repositoryMessagesCache.set(instance.instanceName, repositoryMessagesCache); } public deleteRepositoryMessagesCache(instance: InstanceDto) { this.repositoryMessagesCache.delete(instance.instanceName); } public addHistoryMessages(instance: InstanceDto, messagesRaw: Message[]) { const actualValue = this.historyMessages.has(instance.instanceName) ? this.historyMessages.get(instance.instanceName) : []; this.historyMessages.set(instance.instanceName, [...actualValue, ...messagesRaw]); } public addHistoryContacts(instance: InstanceDto, contactsRaw: Contact[]) { const actualValue = this.historyContacts.has(instance.instanceName) ? this.historyContacts.get(instance.instanceName) : []; this.historyContacts.set(instance.instanceName, actualValue.concat(contactsRaw)); } public deleteHistoryMessages(instance: InstanceDto) { this.historyMessages.delete(instance.instanceName); } public deleteHistoryContacts(instance: InstanceDto) { this.historyContacts.delete(instance.instanceName); } public clearAll(instance: InstanceDto) { this.deleteRepositoryMessagesCache(instance); this.deleteHistoryMessages(instance); this.deleteHistoryContacts(instance); } public getHistoryMessagesLenght(instance: InstanceDto) { return this.historyMessages.get(instance.instanceName)?.length ?? 0; } public async importHistoryContacts(instance: InstanceDto, provider: ChatwootDto) { try { if (this.getHistoryMessagesLenght(instance) > 0) { return; } const pgClient = postgresClient.getChatwootConnection(); let totalContactsImported = 0; const contacts = this.historyContacts.get(instance.instanceName) || []; if (contacts.length === 0) { return 0; } let contactsChunk: Contact[] = this.sliceIntoChunks(contacts, 3000); while (contactsChunk.length > 0) { const labelSql = `SELECT id FROM labels WHERE title = '${provider.nameInbox}' AND account_id = ${provider.accountId} LIMIT 1`; let labelId = (await pgClient.query(labelSql))?.rows[0]?.id; if (!labelId) { // creating label in chatwoot db and getting the id const sqlLabel = `INSERT INTO labels (title, color, show_on_sidebar, account_id, created_at, updated_at) VALUES ('${provider.nameInbox}', '#34039B', true, ${provider.accountId}, NOW(), NOW()) RETURNING id`; labelId = (await pgClient.query(sqlLabel))?.rows[0]?.id; } // inserting contacts in chatwoot db let sqlInsert = `INSERT INTO contacts (name, phone_number, account_id, identifier, created_at, updated_at) VALUES `; const bindInsert = [provider.accountId]; for (const contact of contactsChunk) { const isGroup = this.isIgnorePhoneNumber(contact.remoteJid); const contactName = isGroup ? `${contact.pushName} (GROUP)` : contact.pushName; bindInsert.push(contactName); const bindName = `$${bindInsert.length}`; let bindPhoneNumber: string; if (!isGroup) { bindInsert.push(`+${contact.remoteJid.split('@')[0]}`); bindPhoneNumber = `$${bindInsert.length}`; } else { bindPhoneNumber = 'NULL'; } bindInsert.push(contact.remoteJid); const bindIdentifier = `$${bindInsert.length}`; sqlInsert += `(${bindName}, ${bindPhoneNumber}, $1, ${bindIdentifier}, NOW(), NOW()),`; } if (sqlInsert.slice(-1) === ',') { sqlInsert = sqlInsert.slice(0, -1); } sqlInsert += ` ON CONFLICT (identifier, account_id) DO UPDATE SET name = EXCLUDED.name, phone_number = EXCLUDED.phone_number, updated_at = NOW()`; totalContactsImported += (await pgClient.query(sqlInsert, bindInsert))?.rowCount ?? 0; const sqlTags = `SELECT id FROM tags WHERE name = '${provider.nameInbox}' LIMIT 1`; const tagData = (await pgClient.query(sqlTags))?.rows[0]; let tagId = tagData?.id; const sqlTag = `INSERT INTO tags (name, taggings_count) VALUES ('${provider.nameInbox}', ${totalContactsImported}) ON CONFLICT (name) DO UPDATE SET taggings_count = tags.taggings_count + ${totalContactsImported} RETURNING id`; tagId = (await pgClient.query(sqlTag))?.rows[0]?.id; await pgClient.query(sqlTag); let sqlInsertLabel = `INSERT INTO taggings (tag_id, taggable_type, taggable_id, context, created_at) VALUES `; contactsChunk.forEach((contact) => { const bindTaggableId = `(SELECT id FROM contacts WHERE identifier = '${contact.remoteJid}' AND account_id = ${provider.accountId})`; sqlInsertLabel += `($1, $2, ${bindTaggableId}, $3, NOW()),`; }); if (sqlInsertLabel.slice(-1) === ',') { sqlInsertLabel = sqlInsertLabel.slice(0, -1); } await pgClient.query(sqlInsertLabel, [tagId, 'Contact', 'labels']); contactsChunk = this.sliceIntoChunks(contacts, 3000); } this.deleteHistoryContacts(instance); return totalContactsImported; } catch (error) { this.logger.error(`Error on import history contacts: ${error.toString()}`); } } public async getExistingSourceIds(sourceIds: string[], conversationId?: number): Promise> { try { const existingSourceIdsSet = new Set(); if (sourceIds.length === 0) { return existingSourceIdsSet; } // Ensure all sourceIds are consistently prefixed with 'WAID:' as required by downstream systems and database queries. const formattedSourceIds = sourceIds.map((sourceId) => `WAID:${sourceId.replace('WAID:', '')}`); const pgClient = postgresClient.getChatwootConnection(); const params = conversationId ? [formattedSourceIds, conversationId] : [formattedSourceIds]; const query = conversationId ? 'SELECT source_id FROM messages WHERE source_id = ANY($1) AND conversation_id = $2' : 'SELECT source_id FROM messages WHERE source_id = ANY($1)'; const result = await pgClient.query(query, params); for (const row of result.rows) { existingSourceIdsSet.add(row.source_id); } return existingSourceIdsSet; } catch (error) { this.logger.error(`Error on getExistingSourceIds: ${error.toString()}`); return new Set(); } } public async importHistoryMessages( instance: InstanceDto, chatwootService: ChatwootService, inbox: inbox, provider: ChatwootModel, ) { try { const pgClient = postgresClient.getChatwootConnection(); const chatwootUser = await this.getChatwootUser(provider); if (!chatwootUser) { throw new Error('User not found to import messages.'); } let totalMessagesImported = 0; let messagesOrdered = this.historyMessages.get(instance.instanceName) || []; if (messagesOrdered.length === 0) { return 0; } // ordering messages by number and timestamp asc messagesOrdered.sort((a, b) => { const aKey = a.key as { remoteJid: string; }; const bKey = b.key as { remoteJid: string; }; const aMessageTimestamp = a.messageTimestamp as any as number; const bMessageTimestamp = b.messageTimestamp as any as number; return parseInt(aKey.remoteJid) - parseInt(bKey.remoteJid) || aMessageTimestamp - bMessageTimestamp; }); const allMessagesMappedByPhoneNumber = this.createMessagesMapByPhoneNumber(messagesOrdered); // Map structure: +552199999999 => { first message timestamp from number, last message timestamp from number} const phoneNumbersWithTimestamp = new Map(); allMessagesMappedByPhoneNumber.forEach((messages: Message[], phoneNumber: string) => { phoneNumbersWithTimestamp.set(phoneNumber, { first: messages[0]?.messageTimestamp as any as number, last: messages[messages.length - 1]?.messageTimestamp as any as number, }); }); const existingSourceIds = await this.getExistingSourceIds(messagesOrdered.map((message: any) => message.key.id)); messagesOrdered = messagesOrdered.filter((message: any) => !existingSourceIds.has(message.key.id)); // processing messages in batch const batchSize = 4000; let messagesChunk: Message[] = this.sliceIntoChunks(messagesOrdered, batchSize); while (messagesChunk.length > 0) { // Map structure: +552199999999 => Message[] const messagesByPhoneNumber = this.createMessagesMapByPhoneNumber(messagesChunk); if (messagesByPhoneNumber.size > 0) { const fksByNumber = await this.selectOrCreateFksFromChatwoot( provider, inbox, phoneNumbersWithTimestamp, messagesByPhoneNumber, ); // inserting messages in chatwoot db let sqlInsertMsg = `INSERT INTO messages (content, processed_message_content, account_id, inbox_id, conversation_id, message_type, private, content_type, sender_type, sender_id, source_id, created_at, updated_at) VALUES `; const bindInsertMsg = [provider.accountId, inbox.id]; messagesByPhoneNumber.forEach((messages: any[], phoneNumber: string) => { const fksChatwoot = fksByNumber.get(phoneNumber); messages.forEach((message) => { if (!message.message) { return; } if (!fksChatwoot?.conversation_id || !fksChatwoot?.contact_id) { return; } const contentMessage = this.getContentMessage(chatwootService, message); if (!contentMessage) { return; } bindInsertMsg.push(contentMessage); const bindContent = `$${bindInsertMsg.length}`; bindInsertMsg.push(fksChatwoot.conversation_id); const bindConversationId = `$${bindInsertMsg.length}`; bindInsertMsg.push(message.key.fromMe ? '1' : '0'); const bindMessageType = `$${bindInsertMsg.length}`; bindInsertMsg.push(message.key.fromMe ? chatwootUser.user_type : 'Contact'); const bindSenderType = `$${bindInsertMsg.length}`; bindInsertMsg.push(message.key.fromMe ? chatwootUser.user_id : fksChatwoot.contact_id); const bindSenderId = `$${bindInsertMsg.length}`; bindInsertMsg.push('WAID:' + message.key.id); const bindSourceId = `$${bindInsertMsg.length}`; bindInsertMsg.push(message.messageTimestamp as number); const bindmessageTimestamp = `$${bindInsertMsg.length}`; sqlInsertMsg += `(${bindContent}, ${bindContent}, $1, $2, ${bindConversationId}, ${bindMessageType}, FALSE, 0, ${bindSenderType},${bindSenderId},${bindSourceId}, to_timestamp(${bindmessageTimestamp}), to_timestamp(${bindmessageTimestamp})),`; }); }); if (bindInsertMsg.length > 2) { if (sqlInsertMsg.slice(-1) === ',') { sqlInsertMsg = sqlInsertMsg.slice(0, -1); } totalMessagesImported += (await pgClient.query(sqlInsertMsg, bindInsertMsg))?.rowCount ?? 0; } } messagesChunk = this.sliceIntoChunks(messagesOrdered, batchSize); } this.deleteHistoryMessages(instance); this.deleteRepositoryMessagesCache(instance); const providerData: ChatwootDto = { ...provider, ignoreJids: Array.isArray(provider.ignoreJids) ? provider.ignoreJids.map((event) => String(event)) : [], }; this.importHistoryContacts(instance, providerData); return totalMessagesImported; } catch (error) { this.logger.error(`Error on import history messages: ${error.toString()}`); this.deleteHistoryMessages(instance); this.deleteRepositoryMessagesCache(instance); } } public async selectOrCreateFksFromChatwoot( provider: ChatwootModel, inbox: inbox, phoneNumbersWithTimestamp: Map, messagesByPhoneNumber: Map, ): Promise> { const pgClient = postgresClient.getChatwootConnection(); const bindValues = [provider.accountId, inbox.id]; const phoneNumberBind = Array.from(messagesByPhoneNumber.keys()) .map((phoneNumber) => { const phoneNumberTimestamp = phoneNumbersWithTimestamp.get(phoneNumber); if (phoneNumberTimestamp) { bindValues.push(phoneNumber); let bindStr = `($${bindValues.length},`; bindValues.push(phoneNumberTimestamp.first); bindStr += `$${bindValues.length},`; bindValues.push(phoneNumberTimestamp.last); return `${bindStr}$${bindValues.length})`; } }) .join(','); // select (or insert when necessary) data from tables contacts, contact_inboxes, conversations from chatwoot db const sqlFromChatwoot = `WITH phone_number AS ( SELECT phone_number, created_at::INTEGER, last_activity_at::INTEGER FROM ( VALUES ${phoneNumberBind} ) as t (phone_number, created_at, last_activity_at) ), only_new_phone_number AS ( SELECT * FROM phone_number WHERE phone_number NOT IN ( SELECT phone_number FROM contacts JOIN contact_inboxes ci ON ci.contact_id = contacts.id AND ci.inbox_id = $2 JOIN conversations con ON con.contact_inbox_id = ci.id AND con.account_id = $1 AND con.inbox_id = $2 AND con.contact_id = contacts.id WHERE contacts.account_id = $1 ) ), new_contact AS ( INSERT INTO contacts (name, phone_number, account_id, identifier, created_at, updated_at) SELECT REPLACE(p.phone_number, '+', ''), p.phone_number, $1, CONCAT(REPLACE(p.phone_number, '+', ''), '@s.whatsapp.net'), to_timestamp(p.created_at), to_timestamp(p.last_activity_at) FROM only_new_phone_number AS p ON CONFLICT(identifier, account_id) DO UPDATE SET updated_at = EXCLUDED.updated_at RETURNING id, phone_number, created_at, updated_at ), new_contact_inbox AS ( INSERT INTO contact_inboxes (contact_id, inbox_id, source_id, created_at, updated_at) SELECT new_contact.id, $2, gen_random_uuid(), new_contact.created_at, new_contact.updated_at FROM new_contact RETURNING id, contact_id, created_at, updated_at ), new_conversation AS ( INSERT INTO conversations (account_id, inbox_id, status, contact_id, contact_inbox_id, uuid, last_activity_at, created_at, updated_at) SELECT $1, $2, 0, new_contact_inbox.contact_id, new_contact_inbox.id, gen_random_uuid(), new_contact_inbox.updated_at, new_contact_inbox.created_at, new_contact_inbox.updated_at FROM new_contact_inbox RETURNING id, contact_id ) SELECT new_contact.phone_number, new_conversation.contact_id, new_conversation.id AS conversation_id FROM new_conversation JOIN new_contact ON new_conversation.contact_id = new_contact.id UNION SELECT p.phone_number, c.id contact_id, con.id conversation_id FROM phone_number p JOIN contacts c ON c.phone_number = p.phone_number JOIN contact_inboxes ci ON ci.contact_id = c.id AND ci.inbox_id = $2 JOIN conversations con ON con.contact_inbox_id = ci.id AND con.account_id = $1 AND con.inbox_id = $2 AND con.contact_id = c.id`; const fksFromChatwoot = await pgClient.query(sqlFromChatwoot, bindValues); return new Map(fksFromChatwoot.rows.map((item: FksChatwoot) => [item.phone_number, item])); } public async getChatwootUser(provider: ChatwootModel): Promise { try { const pgClient = postgresClient.getChatwootConnection(); const sqlUser = `SELECT owner_type AS user_type, owner_id AS user_id FROM access_tokens WHERE token = $1`; return (await pgClient.query(sqlUser, [provider.token]))?.rows[0] || false; } catch (error) { this.logger.error(`Error on getChatwootUser: ${error.toString()}`); } } public createMessagesMapByPhoneNumber(messages: Message[]): Map { return messages.reduce((acc: Map, message: Message) => { const key = message?.key as { remoteJid: string; }; if (!this.isIgnorePhoneNumber(key?.remoteJid)) { const phoneNumber = key?.remoteJid?.split('@')[0]; if (phoneNumber) { const phoneNumberPlus = `+${phoneNumber}`; const messages = acc.has(phoneNumberPlus) ? acc.get(phoneNumberPlus) : []; messages.push(message); acc.set(phoneNumberPlus, messages); } } return acc; }, new Map()); } public async getContactsOrderByRecentConversations( inbox: inbox, provider: ChatwootModel, limit = 50, ): Promise<{ id: number; phone_number: string; identifier: string }[]> { try { const pgClient = postgresClient.getChatwootConnection(); const sql = `SELECT contacts.id, contacts.identifier, contacts.phone_number FROM conversations JOIN contacts ON contacts.id = conversations.contact_id WHERE conversations.account_id = $1 AND inbox_id = $2 ORDER BY conversations.last_activity_at DESC LIMIT $3`; return (await pgClient.query(sql, [provider.accountId, inbox.id, limit]))?.rows; } catch (error) { this.logger.error(`Error on get recent conversations: ${error.toString()}`); } } public getContentMessage(chatwootService: ChatwootService, msg: IWebMessageInfo) { const contentMessage = chatwootService.getConversationMessage(msg.message); if (contentMessage) { return contentMessage; } if (!configService.get('CHATWOOT').IMPORT.PLACEHOLDER_MEDIA_MESSAGE) { return ''; } const types = { documentMessage: msg.message.documentMessage, documentWithCaptionMessage: msg.message.documentWithCaptionMessage?.message?.documentMessage, imageMessage: msg.message.imageMessage, videoMessage: msg.message.videoMessage, audioMessage: msg.message.audioMessage, stickerMessage: msg.message.stickerMessage, templateMessage: msg.message.templateMessage?.hydratedTemplate?.hydratedContentText, }; const typeKey = Object.keys(types).find((key) => types[key] !== undefined && types[key] !== null); switch (typeKey) { case 'documentMessage': { const doc = msg.message.documentMessage; const fileName = doc?.fileName || 'document'; const caption = doc?.caption ? ` ${doc.caption}` : ''; return `__`; } case 'documentWithCaptionMessage': { const doc = msg.message.documentWithCaptionMessage?.message?.documentMessage; const fileName = doc?.fileName || 'document'; const caption = doc?.caption ? ` ${doc.caption}` : ''; return `__`; } case 'templateMessage': { const template = msg.message.templateMessage?.hydratedTemplate; return ( (template?.hydratedTitleText ? `*${template.hydratedTitleText}*\n` : '') + (template?.hydratedContentText || '') ); } case 'imageMessage': return '__'; case 'videoMessage': return '_