@kaikybrofc/omnizap-system 2.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. package/.env.example +534 -0
  2. package/LICENSE +21 -0
  3. package/README.md +431 -0
  4. package/RELEASE-v2.1.2.md +83 -0
  5. package/app/config/adminIdentity.js +87 -0
  6. package/app/config/baileysConfig.js +693 -0
  7. package/app/config/groupUtils.js +388 -0
  8. package/app/connection/socketController.js +992 -0
  9. package/app/controllers/messageController.js +354 -0
  10. package/app/modules/adminModule/groupCommandHandlers.js +1294 -0
  11. package/app/modules/adminModule/groupEventHandlers.js +355 -0
  12. package/app/modules/aiModule/catCommand.js +1006 -0
  13. package/app/modules/broadcastModule/noticeCommand.js +416 -0
  14. package/app/modules/gameModule/diceCommand.js +67 -0
  15. package/app/modules/menuModule/common.js +311 -0
  16. package/app/modules/menuModule/menus.js +59 -0
  17. package/app/modules/playModule/playCommand.js +1615 -0
  18. package/app/modules/quoteModule/quoteCommand.js +851 -0
  19. package/app/modules/rpgPokemonModule/rpgBattleCanvasRenderer.js +786 -0
  20. package/app/modules/rpgPokemonModule/rpgBattleService.js +2082 -0
  21. package/app/modules/rpgPokemonModule/rpgBattleService.test.js +760 -0
  22. package/app/modules/rpgPokemonModule/rpgEvolutionUtils.js +22 -0
  23. package/app/modules/rpgPokemonModule/rpgPokemonCommand.js +172 -0
  24. package/app/modules/rpgPokemonModule/rpgPokemonDomain.js +192 -0
  25. package/app/modules/rpgPokemonModule/rpgPokemonDomain.test.js +93 -0
  26. package/app/modules/rpgPokemonModule/rpgPokemonEvolution.test.js +46 -0
  27. package/app/modules/rpgPokemonModule/rpgPokemonMessages.js +746 -0
  28. package/app/modules/rpgPokemonModule/rpgPokemonRepository.js +1859 -0
  29. package/app/modules/rpgPokemonModule/rpgPokemonService.js +6738 -0
  30. package/app/modules/rpgPokemonModule/rpgProfileCanvasRenderer.js +354 -0
  31. package/app/modules/statsModule/globalRankingCommand.js +65 -0
  32. package/app/modules/statsModule/noMessageCommand.js +288 -0
  33. package/app/modules/statsModule/rankingCommand.js +60 -0
  34. package/app/modules/statsModule/rankingCommon.js +889 -0
  35. package/app/modules/stickerModule/addStickerMetadata.js +239 -0
  36. package/app/modules/stickerModule/convertToWebp.js +390 -0
  37. package/app/modules/stickerModule/stickerCommand.js +454 -0
  38. package/app/modules/stickerModule/stickerConvertCommand.js +156 -0
  39. package/app/modules/stickerModule/stickerTextCommand.js +657 -0
  40. package/app/modules/stickerPackModule/autoPackCollectorRuntime.js +20 -0
  41. package/app/modules/stickerPackModule/autoPackCollectorService.js +284 -0
  42. package/app/modules/stickerPackModule/semanticReclassificationEngine.js +466 -0
  43. package/app/modules/stickerPackModule/semanticReclassificationEngine.test.js +88 -0
  44. package/app/modules/stickerPackModule/semanticThemeClusterService.js +571 -0
  45. package/app/modules/stickerPackModule/stickerAssetClassificationRepository.js +449 -0
  46. package/app/modules/stickerPackModule/stickerAssetRepository.js +400 -0
  47. package/app/modules/stickerPackModule/stickerAssetReprocessQueueRepository.js +180 -0
  48. package/app/modules/stickerPackModule/stickerAutoPackByTagsRuntime.js +4078 -0
  49. package/app/modules/stickerPackModule/stickerClassificationBackgroundRuntime.js +598 -0
  50. package/app/modules/stickerPackModule/stickerClassificationService.js +588 -0
  51. package/app/modules/stickerPackModule/stickerMarketplaceDriftService.js +102 -0
  52. package/app/modules/stickerPackModule/stickerPackCatalogHttp.js +7506 -0
  53. package/app/modules/stickerPackModule/stickerPackCommandHandlers.js +1095 -0
  54. package/app/modules/stickerPackModule/stickerPackEngagementRepository.js +108 -0
  55. package/app/modules/stickerPackModule/stickerPackErrors.js +30 -0
  56. package/app/modules/stickerPackModule/stickerPackInteractionEventRepository.js +110 -0
  57. package/app/modules/stickerPackModule/stickerPackItemRepository.js +440 -0
  58. package/app/modules/stickerPackModule/stickerPackMarketplaceService.js +337 -0
  59. package/app/modules/stickerPackModule/stickerPackMessageService.js +296 -0
  60. package/app/modules/stickerPackModule/stickerPackRepository.js +442 -0
  61. package/app/modules/stickerPackModule/stickerPackService.js +788 -0
  62. package/app/modules/stickerPackModule/stickerPackServiceRuntime.js +51 -0
  63. package/app/modules/stickerPackModule/stickerPackUtils.js +97 -0
  64. package/app/modules/stickerPackModule/stickerStorageService.js +507 -0
  65. package/app/modules/stickerPackModule/stickerWorkerPipelineRuntime.js +233 -0
  66. package/app/modules/stickerPackModule/stickerWorkerTaskQueueRepository.js +205 -0
  67. package/app/modules/systemMetricsModule/pingCommand.js +421 -0
  68. package/app/modules/tiktokModule/tiktokCommand.js +798 -0
  69. package/app/modules/userModule/userCommand.js +1217 -0
  70. package/app/modules/waifuPicsModule/waifuPicsCommand.js +177 -0
  71. package/app/observability/metrics.js +734 -0
  72. package/app/services/captchaService.js +492 -0
  73. package/app/services/dbWriteQueue.js +572 -0
  74. package/app/services/groupMetadataService.js +279 -0
  75. package/app/services/lidMapService.js +663 -0
  76. package/app/services/messagePersistenceService.js +56 -0
  77. package/app/services/newsBroadcastService.js +351 -0
  78. package/app/services/pokeApiService.js +398 -0
  79. package/app/services/queueUtils.js +57 -0
  80. package/app/services/socketState.js +7 -0
  81. package/app/store/aiPromptStore.js +38 -0
  82. package/app/store/groupConfigStore.js +58 -0
  83. package/app/store/premiumUserStore.js +36 -0
  84. package/app/utils/antiLink/antiLinkModule.js +804 -0
  85. package/app/utils/http/getImageBufferModule.js +18 -0
  86. package/app/utils/json/jsonSanitizer.js +113 -0
  87. package/app/utils/json/jsonSanitizer.test.js +40 -0
  88. package/app/utils/logger/loggerModule.js +262 -0
  89. package/app/utils/systemMetrics/systemMetricsModule.js +91 -0
  90. package/database/index.js +2052 -0
  91. package/database/init.js +516 -0
  92. package/database/migrations/20260203_0001_sticker_packs.sql +54 -0
  93. package/database/migrations/20260210_0003_rpg_pokemon.sql +58 -0
  94. package/database/migrations/20260210_0004_rpg_shiny_biome.sql +9 -0
  95. package/database/migrations/20260210_0005_rpg_missions.sql +14 -0
  96. package/database/migrations/20260210_0006_rpg_world_pokedex_traits.sql +27 -0
  97. package/database/migrations/20260210_0007_rpg_raid_pvp.sql +56 -0
  98. package/database/migrations/20260210_0008_rpg_social_system.sql +195 -0
  99. package/database/migrations/20260211_0009_rpg_social_xp.sql +36 -0
  100. package/database/migrations/20260222_0010_remove_message_xp.sql +2 -0
  101. package/database/migrations/20260226_0011_sticker_asset_classification.sql +17 -0
  102. package/database/migrations/20260226_0012_sticker_pack_engagement.sql +16 -0
  103. package/database/migrations/20260226_0013_sticker_marketplace_intelligence.sql +19 -0
  104. package/database/migrations/20260226_0014_sticker_pack_publish_flow.sql +30 -0
  105. package/database/migrations/20260226_0014_sticker_worker_queues.sql +42 -0
  106. package/database/migrations/20260226_0015_sticker_auto_pack_curation_integrity.sql +18 -0
  107. package/database/migrations/20260226_0016_sticker_web_google_auth_persistence.sql +34 -0
  108. package/database/migrations/20260226_0017_sticker_web_admin_ban.sql +22 -0
  109. package/database/migrations/20260226_0018_sticker_web_admin_moderator.sql +18 -0
  110. package/database/migrations/20260227_0019_sticker_classification_v2_signals.sql +12 -0
  111. package/database/migrations/20260227_0020_semantic_theme_clusters.sql +35 -0
  112. package/docker-compose.yml +103 -0
  113. package/ecosystem.prod.config.cjs +35 -0
  114. package/eslint.config.js +61 -0
  115. package/index.js +437 -0
  116. package/ml/clip_classifier/Dockerfile +16 -0
  117. package/ml/clip_classifier/README.md +120 -0
  118. package/ml/clip_classifier/adaptive_scoring.py +40 -0
  119. package/ml/clip_classifier/classifier.py +654 -0
  120. package/ml/clip_classifier/embedding_store.py +481 -0
  121. package/ml/clip_classifier/env_loader.py +15 -0
  122. package/ml/clip_classifier/llm_label_expander.py +144 -0
  123. package/ml/clip_classifier/main.py +213 -0
  124. package/ml/clip_classifier/requirements.txt +10 -0
  125. package/ml/clip_classifier/similarity_engine.py +74 -0
  126. package/observability/alert-rules.yml +60 -0
  127. package/observability/grafana/dashboards/omnizap-mysql.json +136 -0
  128. package/observability/grafana/dashboards/omnizap-overview.json +170 -0
  129. package/observability/grafana/provisioning/dashboards/dashboards.yml +11 -0
  130. package/observability/grafana/provisioning/datasources/datasources.yml +15 -0
  131. package/observability/loki-config.yml +38 -0
  132. package/observability/mysql-exporter.cnf +5 -0
  133. package/observability/mysql-setup.sql +46 -0
  134. package/observability/prometheus.yml +32 -0
  135. package/observability/promtail-config.yml +84 -0
  136. package/package.json +109 -0
  137. package/public/api-docs/index.html +144 -0
  138. package/public/css/github-project-panel.css +297 -0
  139. package/public/css/stickers-admin.css +1272 -0
  140. package/public/css/styles.css +671 -0
  141. package/public/index.html +1311 -0
  142. package/public/js/apps/apiDocsApp.js +310 -0
  143. package/public/js/apps/createPackApp.js +2069 -0
  144. package/public/js/apps/homeApp.js +396 -0
  145. package/public/js/apps/stickersAdminApp.js +1744 -0
  146. package/public/js/apps/stickersApp.js +4830 -0
  147. package/public/js/catalog.js +1019 -0
  148. package/public/js/github-panel/components/CommitList.js +34 -0
  149. package/public/js/github-panel/components/ErrorState.js +16 -0
  150. package/public/js/github-panel/components/GithubProjectPanel.js +106 -0
  151. package/public/js/github-panel/components/ReleaseList.js +38 -0
  152. package/public/js/github-panel/components/SkeletonPanel.js +22 -0
  153. package/public/js/github-panel/components/StatCard.js +15 -0
  154. package/public/js/github-panel/index.js +15 -0
  155. package/public/js/github-panel/useGithubRepoData.js +154 -0
  156. package/public/js/github-panel/vendor/react.js +11 -0
  157. package/public/js/runtime/react-runtime.js +19 -0
  158. package/public/licenca/index.html +106 -0
  159. package/public/stickers/admin/index.html +23 -0
  160. package/public/stickers/create/index.html +47 -0
  161. package/public/stickers/index.html +48 -0
  162. package/public/termos-de-uso/index.html +125 -0
  163. package/scripts/cache-bust.mjs +107 -0
  164. package/scripts/deploy.sh +458 -0
  165. package/scripts/github-deploy-notify.mjs +174 -0
  166. package/scripts/release.sh +129 -0
@@ -0,0 +1,120 @@
1
+ # OmniZap CLIP Classifier 2.0 (MobileCLIP)
2
+
3
+ Serviço de classificação de imagens com MobileCLIP (OpenCLIP), com arquitetura híbrida:
4
+
5
+ - embeddings persistidos (imagem e labels)
6
+ - multi-label top-k com entropia e margin
7
+ - clustering por similaridade imagem-imagem
8
+ - ajuste adaptativo por feedback de packs
9
+ - expansão semântica via API da OpenAI (cacheada)
10
+
11
+ ## Estrutura
12
+
13
+ - `classifier.py`: pipeline principal de inferência/classificação.
14
+ - `embedding_store.py`: persistência MySQL de embeddings, feedback e cache LLM.
15
+ - `similarity_engine.py`: cosine similarity e busca de imagens similares.
16
+ - `adaptive_scoring.py`: ajuste adaptativo de score por afinidade histórica.
17
+ - `llm_label_expander.py`: expansão semântica de labels usando OpenAI.
18
+ - `main.py`: API FastAPI.
19
+
20
+ ## Rodando localmente
21
+
22
+ ```bash
23
+ cd ml/clip_classifier
24
+ python -m venv .venv
25
+ source .venv/bin/activate
26
+ pip install -r requirements.txt
27
+ uvicorn main:app --host 0.0.0.0 --port 8008 --reload
28
+ ```
29
+
30
+ ## Endpoints
31
+
32
+ ### `POST /classify`
33
+
34
+ Multipart form:
35
+
36
+ - `file`: imagem
37
+ - `labels` (opcional): JSON array ou CSV
38
+ - `nsfw_threshold` (opcional)
39
+ - `asset_id` (opcional)
40
+ - `asset_sha256` (opcional)
41
+ - `theme` (opcional, para adaptive scoring)
42
+ - `similar_threshold` (opcional)
43
+ - `similar_limit` (opcional)
44
+
45
+ ### `POST /feedback`
46
+
47
+ JSON:
48
+
49
+ ```json
50
+ {
51
+ "image_hash": "...",
52
+ "theme": "reaction-meme",
53
+ "accepted": true,
54
+ "asset_id": "uuid-opcional"
55
+ }
56
+ ```
57
+
58
+ ### `GET /labels`
59
+
60
+ Retorna labels padrão, thresholds e flags de recursos.
61
+
62
+ ## Variáveis de ambiente
63
+
64
+ Principais:
65
+
66
+ - `CLIP_TOP_K=5`
67
+ - `ENABLE_EMBEDDING_CACHE=true`
68
+ - `ENABLE_CLUSTERING=true`
69
+ - `ENABLE_ADAPTIVE_SCORING=true`
70
+ - `ENABLE_LLM_LABEL_EXPANSION=true`
71
+ - `ADAPTIVE_ALPHA=0.4`
72
+ - `ENTROPY_THRESHOLD=2.5`
73
+
74
+ Complementares:
75
+
76
+ - `SIMILARITY_THRESHOLD=0.85`
77
+ - `SIMILARITY_LIMIT=25`
78
+ - `SIMILARITY_SCAN_LIMIT=3000`
79
+ - `LLM_LABEL_EXPANSION_MODEL=gpt-4.1-mini`
80
+ - `LLM_LABEL_EXPANSION_TIMEOUT_MS=6000`
81
+
82
+ Persistência MySQL (obrigatório para cache/feedback):
83
+
84
+ - `DB_HOST`
85
+ - `DB_PORT` (opcional, padrão `3306`)
86
+ - `DB_USER`
87
+ - `DB_PASSWORD`
88
+ - `DB_NAME`
89
+
90
+ OpenAI:
91
+
92
+ - `OPENAI_API_KEY`
93
+
94
+ ## Resposta (exemplo resumido)
95
+
96
+ ```json
97
+ {
98
+ "category": "anime illustration",
99
+ "confidence": 0.82,
100
+ "top_labels": [
101
+ {"label": "anime illustration", "score": 0.82, "logit": 18.10, "clip_score": 0.80},
102
+ {"label": "cartoon", "score": 0.09, "logit": 13.40, "clip_score": 0.10}
103
+ ],
104
+ "entropy": 1.42,
105
+ "confidence_margin": 0.73,
106
+ "ambiguous": false,
107
+ "nsfw_score": 0.01,
108
+ "is_nsfw": false,
109
+ "raw_logits": {"anime illustration": 18.1, "cartoon": 13.4},
110
+ "llm_expansion": {
111
+ "subtags": ["cel shading", "shonen vibe"],
112
+ "style_traits": ["high contrast"],
113
+ "emotions": ["energetic"],
114
+ "pack_suggestions": ["anime-reaction"]
115
+ },
116
+ "similar_images": [
117
+ {"image_hash": "...", "asset_id": "...", "similarity": 0.91}
118
+ ]
119
+ }
120
+ ```
@@ -0,0 +1,40 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Iterable
4
+
5
+
6
+ def adjusted_score(clip_score: float, affinity_weight: float, alpha: float) -> float:
7
+ return float(clip_score) * (1.0 + float(affinity_weight) * float(alpha))
8
+
9
+
10
+ def apply_adaptive_scores(
11
+ base_scores: dict[str, float],
12
+ affinity_weight: float,
13
+ alpha: float,
14
+ ) -> dict[str, float]:
15
+ if not base_scores:
16
+ return {}
17
+
18
+ boosted = {
19
+ label: adjusted_score(score, affinity_weight=affinity_weight, alpha=alpha)
20
+ for label, score in base_scores.items()
21
+ }
22
+
23
+ # Re-normalize to keep a probabilistic interpretation for entropy.
24
+ total = sum(max(0.0, float(value)) for value in boosted.values())
25
+ if total <= 1e-12:
26
+ return {label: 0.0 for label in boosted}
27
+
28
+ return {label: float(max(0.0, value) / total) for label, value in boosted.items()}
29
+
30
+
31
+ def top_k_items(score_map: dict[str, float], k: int) -> list[tuple[str, float]]:
32
+ safe_k = max(1, int(k or 1))
33
+ return sorted(score_map.items(), key=lambda item: item[1], reverse=True)[:safe_k]
34
+
35
+
36
+ def confidence_margin(items: Iterable[tuple[str, float]]) -> float:
37
+ ordered = list(items)
38
+ if len(ordered) < 2:
39
+ return float(ordered[0][1]) if ordered else 0.0
40
+ return float(ordered[0][1]) - float(ordered[1][1])