@vanzxysenpai/baileys 0.0.0-stage → 0.0.2

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 (431) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/LICENSE +25 -0
  3. package/NOTICE.md +158 -0
  4. package/README.md +5294 -2
  5. package/VanzxyBanner.js +134 -0
  6. package/WAProto/index.d.ts +13317 -0
  7. package/WAProto/index.js +147553 -0
  8. package/lib/Builders/A2UI.d.ts +131 -0
  9. package/lib/Builders/A2UI.js +343 -0
  10. package/lib/Builders/AIRich.d.ts +1021 -0
  11. package/lib/Builders/AIRich.js +2889 -0
  12. package/lib/Builders/Album.d.ts +51 -0
  13. package/lib/Builders/Album.js +99 -0
  14. package/lib/Builders/Button.d.ts +137449 -0
  15. package/lib/Builders/Button.js +1054 -0
  16. package/lib/Builders/ButtonV2.d.ts +43 -0
  17. package/lib/Builders/ButtonV2.js +175 -0
  18. package/lib/Builders/ButtonV3.d.ts +35 -0
  19. package/lib/Builders/ButtonV3.js +189 -0
  20. package/lib/Builders/Carousel.d.ts +68 -0
  21. package/lib/Builders/Carousel.js +161 -0
  22. package/lib/Builders/Event.d.ts +61 -0
  23. package/lib/Builders/Event.js +118 -0
  24. package/lib/Builders/Expiring.d.ts +17 -0
  25. package/lib/Builders/Expiring.js +27 -0
  26. package/lib/Builders/Poll.d.ts +63 -0
  27. package/lib/Builders/Poll.js +139 -0
  28. package/lib/Builders/VanzxyBaileys.d.ts +42 -0
  29. package/lib/Builders/VanzxyBaileys.js +110 -0
  30. package/lib/Builders/errors.d.ts +25 -0
  31. package/lib/Builders/errors.js +29 -0
  32. package/lib/Builders/index.d.ts +14 -0
  33. package/lib/Builders/index.js +23 -0
  34. package/lib/Builders/shared.d.ts +395 -0
  35. package/lib/Builders/shared.js +738 -0
  36. package/lib/Defaults/bot-jid.d.ts +1 -0
  37. package/lib/Defaults/bot-jid.js +1 -0
  38. package/lib/Defaults/index.d.ts +161 -0
  39. package/lib/Defaults/index.js +165 -0
  40. package/lib/Defaults/version.d.ts +1 -0
  41. package/lib/Defaults/version.js +1 -0
  42. package/lib/Framework/Bot.d.ts +865 -0
  43. package/lib/Framework/Bot.js +230 -0
  44. package/lib/Framework/Context.d.ts +17 -0
  45. package/lib/Framework/Context.js +90 -0
  46. package/lib/Framework/MediaManager.d.ts +15 -0
  47. package/lib/Framework/MediaManager.js +154 -0
  48. package/lib/Framework/SessionManager.d.ts +10 -0
  49. package/lib/Framework/SessionManager.js +34 -0
  50. package/lib/Framework/StatsManager.d.ts +20 -0
  51. package/lib/Framework/StatsManager.js +117 -0
  52. package/lib/Framework/Store/SQLiteStore.d.ts +13 -0
  53. package/lib/Framework/Store/SQLiteStore.js +68 -0
  54. package/lib/Framework/index.d.ts +6 -0
  55. package/lib/Framework/index.js +11 -0
  56. package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
  57. package/lib/Signal/Group/ciphertext-message.js +11 -0
  58. package/lib/Signal/Group/group-session-builder.d.ts +7 -0
  59. package/lib/Signal/Group/group-session-builder.js +29 -0
  60. package/lib/Signal/Group/group_cipher.d.ts +10 -0
  61. package/lib/Signal/Group/group_cipher.js +81 -0
  62. package/lib/Signal/Group/index.d.ts +11 -0
  63. package/lib/Signal/Group/index.js +11 -0
  64. package/lib/Signal/Group/keyhelper.d.ts +6 -0
  65. package/lib/Signal/Group/keyhelper.js +17 -0
  66. package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
  67. package/lib/Signal/Group/sender-chain-key.js +25 -0
  68. package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
  69. package/lib/Signal/Group/sender-key-distribution-message.js +62 -0
  70. package/lib/Signal/Group/sender-key-message.d.ts +18 -0
  71. package/lib/Signal/Group/sender-key-message.js +65 -0
  72. package/lib/Signal/Group/sender-key-name.d.ts +11 -0
  73. package/lib/Signal/Group/sender-key-name.js +47 -0
  74. package/lib/Signal/Group/sender-key-record.d.ts +12 -0
  75. package/lib/Signal/Group/sender-key-record.js +40 -0
  76. package/lib/Signal/Group/sender-key-state.d.ts +16 -0
  77. package/lib/Signal/Group/sender-key-state.js +83 -0
  78. package/lib/Signal/Group/sender-message-key.d.ts +11 -0
  79. package/lib/Signal/Group/sender-message-key.js +25 -0
  80. package/lib/Signal/libsignal.d.ts +58 -0
  81. package/lib/Signal/libsignal.js +436 -0
  82. package/lib/Signal/lid-mapping.d.ts +20 -0
  83. package/lib/Signal/lid-mapping.js +276 -0
  84. package/lib/Socket/Client/index.d.ts +2 -0
  85. package/lib/Socket/Client/index.js +2 -0
  86. package/lib/Socket/Client/types.d.ts +5 -0
  87. package/lib/Socket/Client/types.js +10 -0
  88. package/lib/Socket/Client/websocket.d.ts +12 -0
  89. package/lib/Socket/Client/websocket.js +53 -0
  90. package/lib/Socket/business.d.ts +674 -0
  91. package/lib/Socket/business.js +379 -0
  92. package/lib/Socket/chats.d.ts +137 -0
  93. package/lib/Socket/chats.js +1299 -0
  94. package/lib/Socket/communities.d.ts +805 -0
  95. package/lib/Socket/communities.js +454 -0
  96. package/lib/Socket/dugong.d.ts +118 -0
  97. package/lib/Socket/dugong.js +810 -0
  98. package/lib/Socket/groups.d.ts +287 -0
  99. package/lib/Socket/groups.js +386 -0
  100. package/lib/Socket/index.d.ts +826 -0
  101. package/lib/Socket/index.js +35 -0
  102. package/lib/Socket/messages-recv.d.ts +613 -0
  103. package/lib/Socket/messages-recv.js +1851 -0
  104. package/lib/Socket/messages-send.d.ts +608 -0
  105. package/lib/Socket/messages-send.js +1574 -0
  106. package/lib/Socket/mex-fallback.d.ts +51 -0
  107. package/lib/Socket/mex-fallback.js +97 -0
  108. package/lib/Socket/mex.d.ts +1 -0
  109. package/lib/Socket/mex.js +41 -0
  110. package/lib/Socket/newsletter-ext.d.ts +47 -0
  111. package/lib/Socket/newsletter-ext.js +262 -0
  112. package/lib/Socket/newsletter.d.ts +285 -0
  113. package/lib/Socket/newsletter.js +223 -0
  114. package/lib/Socket/socket.d.ts +60 -0
  115. package/lib/Socket/socket.js +1001 -0
  116. package/lib/Socket/username.d.ts +842 -0
  117. package/lib/Socket/username.js +156 -0
  118. package/lib/Store/index.d.ts +3 -0
  119. package/lib/Store/index.js +3 -0
  120. package/lib/Store/make-in-memory-store.d.ts +62 -0
  121. package/lib/Store/make-in-memory-store.js +425 -0
  122. package/lib/Store/make-ordered-dictionary.d.ts +12 -0
  123. package/lib/Store/make-ordered-dictionary.js +78 -0
  124. package/lib/Store/object-repository.d.ts +10 -0
  125. package/lib/Store/object-repository.js +23 -0
  126. package/lib/Types/Auth.d.ts +1 -0
  127. package/lib/Types/Auth.js +1 -0
  128. package/lib/Types/Bussines.d.ts +1 -0
  129. package/lib/Types/Bussines.js +1 -0
  130. package/lib/Types/Call.d.ts +1 -0
  131. package/lib/Types/Call.js +1 -0
  132. package/lib/Types/Chat.d.ts +1 -0
  133. package/lib/Types/Chat.js +7 -0
  134. package/lib/Types/Contact.d.ts +1 -0
  135. package/lib/Types/Contact.js +1 -0
  136. package/lib/Types/Events.d.ts +1 -0
  137. package/lib/Types/Events.js +1 -0
  138. package/lib/Types/GroupMetadata.d.ts +1 -0
  139. package/lib/Types/GroupMetadata.js +1 -0
  140. package/lib/Types/Label.d.ts +2 -0
  141. package/lib/Types/Label.js +24 -0
  142. package/lib/Types/LabelAssociation.d.ts +2 -0
  143. package/lib/Types/LabelAssociation.js +6 -0
  144. package/lib/Types/Message.d.ts +11 -0
  145. package/lib/Types/Message.js +17 -0
  146. package/lib/Types/Mex.d.ts +2 -0
  147. package/lib/Types/Mex.js +38 -0
  148. package/lib/Types/Product.d.ts +1 -0
  149. package/lib/Types/Product.js +1 -0
  150. package/lib/Types/RichType.d.ts +2 -0
  151. package/lib/Types/RichType.js +22 -0
  152. package/lib/Types/Signal.d.ts +1 -0
  153. package/lib/Types/Signal.js +1 -0
  154. package/lib/Types/Socket.d.ts +1 -0
  155. package/lib/Types/Socket.js +1 -0
  156. package/lib/Types/State.d.ts +5 -0
  157. package/lib/Types/State.js +55 -0
  158. package/lib/Types/USync.d.ts +1 -0
  159. package/lib/Types/USync.js +1 -0
  160. package/lib/Types/index.d.ts +15 -0
  161. package/lib/Types/index.js +27 -0
  162. package/lib/Utils/PersistentStore.d.ts +83 -0
  163. package/lib/Utils/PersistentStore.js +592 -0
  164. package/lib/Utils/anchor-guard.d.ts +31 -0
  165. package/lib/Utils/anchor-guard.js +329 -0
  166. package/lib/Utils/android-stanza-id.d.ts +4 -0
  167. package/lib/Utils/android-stanza-id.js +21 -0
  168. package/lib/Utils/anti-delete.d.ts +62 -0
  169. package/lib/Utils/anti-delete.js +212 -0
  170. package/lib/Utils/auth-secure.d.ts +180 -0
  171. package/lib/Utils/auth-secure.js +791 -0
  172. package/lib/Utils/auth-utils.d.ts +59 -0
  173. package/lib/Utils/auth-utils.js +326 -0
  174. package/lib/Utils/auto-reconnect.d.ts +8 -0
  175. package/lib/Utils/auto-reconnect.js +204 -0
  176. package/lib/Utils/auto-reply.d.ts +35 -0
  177. package/lib/Utils/auto-reply.js +152 -0
  178. package/lib/Utils/bad-mac-handler.d.ts +59 -0
  179. package/lib/Utils/bad-mac-handler.js +119 -0
  180. package/lib/Utils/baileys-event-stream.d.ts +5 -0
  181. package/lib/Utils/baileys-event-stream.js +62 -0
  182. package/lib/Utils/browser-utils.d.ts +9 -0
  183. package/lib/Utils/browser-utils.js +29 -0
  184. package/lib/Utils/business.d.ts +49 -0
  185. package/lib/Utils/business.js +236 -0
  186. package/lib/Utils/button-helper-utils.d.ts +59 -0
  187. package/lib/Utils/button-helper-utils.js +266 -0
  188. package/lib/Utils/button-sender.d.ts +164 -0
  189. package/lib/Utils/button-sender.js +845 -0
  190. package/lib/Utils/chat-control.d.ts +98 -0
  191. package/lib/Utils/chat-control.js +231 -0
  192. package/lib/Utils/chat-history-helpers.d.ts +4 -0
  193. package/lib/Utils/chat-history-helpers.js +70 -0
  194. package/lib/Utils/chat-utils.d.ts +408 -0
  195. package/lib/Utils/chat-utils.js +879 -0
  196. package/lib/Utils/companion-reg-client-utils.d.ts +4 -0
  197. package/lib/Utils/companion-reg-client-utils.js +39 -0
  198. package/lib/Utils/connection-watchdog.d.ts +10 -0
  199. package/lib/Utils/connection-watchdog.js +74 -0
  200. package/lib/Utils/crypto.d.ts +41 -0
  201. package/lib/Utils/crypto.js +145 -0
  202. package/lib/Utils/decode-wa-message.d.ts +83 -0
  203. package/lib/Utils/decode-wa-message.js +315 -0
  204. package/lib/Utils/disconnect-reason.d.ts +13 -0
  205. package/lib/Utils/disconnect-reason.js +36 -0
  206. package/lib/Utils/event-buffer.d.ts +12 -0
  207. package/lib/Utils/event-buffer.js +640 -0
  208. package/lib/Utils/fetch-timeout.d.ts +4 -0
  209. package/lib/Utils/fetch-timeout.js +14 -0
  210. package/lib/Utils/ffmpeg-path.d.ts +5 -0
  211. package/lib/Utils/ffmpeg-path.js +130 -0
  212. package/lib/Utils/generics.d.ts +79 -0
  213. package/lib/Utils/generics.js +426 -0
  214. package/lib/Utils/group-metadata-cache.d.ts +3 -0
  215. package/lib/Utils/group-metadata-cache.js +25 -0
  216. package/lib/Utils/group-status-detection.d.ts +5 -0
  217. package/lib/Utils/group-status-detection.js +114 -0
  218. package/lib/Utils/history.d.ts +91 -0
  219. package/lib/Utils/history.js +144 -0
  220. package/lib/Utils/html-app.d.ts +14 -0
  221. package/lib/Utils/html-app.js +97 -0
  222. package/lib/Utils/html-multiplayer.d.ts +8 -0
  223. package/lib/Utils/html-multiplayer.js +90 -0
  224. package/lib/Utils/humanizer.d.ts +8 -0
  225. package/lib/Utils/humanizer.js +74 -0
  226. package/lib/Utils/identity-change-handler.d.ts +13 -0
  227. package/lib/Utils/identity-change-handler.js +49 -0
  228. package/lib/Utils/index.d.ts +88 -0
  229. package/lib/Utils/index.js +93 -0
  230. package/lib/Utils/jid-tools.d.ts +3 -0
  231. package/lib/Utils/jid-tools.js +78 -0
  232. package/lib/Utils/link-preview-metadata.d.ts +47 -0
  233. package/lib/Utils/link-preview-metadata.js +90 -0
  234. package/lib/Utils/link-preview.d.ts +12 -0
  235. package/lib/Utils/link-preview.js +84 -0
  236. package/lib/Utils/lock-manager.d.ts +5 -0
  237. package/lib/Utils/lock-manager.js +50 -0
  238. package/lib/Utils/logger.d.ts +2 -0
  239. package/lib/Utils/logger.js +2 -0
  240. package/lib/Utils/lt-hash.d.ts +12 -0
  241. package/lib/Utils/lt-hash.js +26 -0
  242. package/lib/Utils/make-mutex.d.ts +6 -0
  243. package/lib/Utils/make-mutex.js +32 -0
  244. package/lib/Utils/media-messages.d.ts +35 -0
  245. package/lib/Utils/media-messages.js +70 -0
  246. package/lib/Utils/media-processor.d.ts +6 -0
  247. package/lib/Utils/media-processor.js +174 -0
  248. package/lib/Utils/media-set.d.ts +6 -0
  249. package/lib/Utils/media-set.js +169 -0
  250. package/lib/Utils/message-kind.d.ts +26 -0
  251. package/lib/Utils/message-kind.js +138 -0
  252. package/lib/Utils/message-retry-manager.d.ts +79 -0
  253. package/lib/Utils/message-retry-manager.js +264 -0
  254. package/lib/Utils/message-search.d.ts +40 -0
  255. package/lib/Utils/message-search.js +181 -0
  256. package/lib/Utils/messages-media.d.ts +136 -0
  257. package/lib/Utils/messages-media.js +867 -0
  258. package/lib/Utils/messages.d.ts +66 -0
  259. package/lib/Utils/messages.js +2271 -0
  260. package/lib/Utils/meta-ai-msmsg.d.ts +3 -0
  261. package/lib/Utils/meta-ai-msmsg.js +132 -0
  262. package/lib/Utils/meta-ai.d.ts +4 -0
  263. package/lib/Utils/meta-ai.js +75 -0
  264. package/lib/Utils/migrate-auth-state.d.ts +23 -0
  265. package/lib/Utils/migrate-auth-state.js +126 -0
  266. package/lib/Utils/mini-app.d.ts +20 -0
  267. package/lib/Utils/mini-app.js +215 -0
  268. package/lib/Utils/mock-socket.d.ts +67 -0
  269. package/lib/Utils/mock-socket.js +254 -0
  270. package/lib/Utils/modern-messages.d.ts +64 -0
  271. package/lib/Utils/modern-messages.js +497 -0
  272. package/lib/Utils/native-flow.d.ts +19 -0
  273. package/lib/Utils/native-flow.js +112 -0
  274. package/lib/Utils/newsletter-status.d.ts +157 -0
  275. package/lib/Utils/newsletter-status.js +652 -0
  276. package/lib/Utils/noise-handler.d.ts +20 -0
  277. package/lib/Utils/noise-handler.js +200 -0
  278. package/lib/Utils/offline-node-processor.d.ts +9 -0
  279. package/lib/Utils/offline-node-processor.js +39 -0
  280. package/lib/Utils/pairing-utils.d.ts +5 -0
  281. package/lib/Utils/pairing-utils.js +29 -0
  282. package/lib/Utils/passkey.d.ts +4 -0
  283. package/lib/Utils/passkey.js +11 -0
  284. package/lib/Utils/past-participants.d.ts +2 -0
  285. package/lib/Utils/past-participants.js +40 -0
  286. package/lib/Utils/payment-detection.d.ts +40 -0
  287. package/lib/Utils/payment-detection.js +213 -0
  288. package/lib/Utils/payment-guard.d.ts +28 -0
  289. package/lib/Utils/payment-guard.js +143 -0
  290. package/lib/Utils/payment-messages.d.ts +42 -0
  291. package/lib/Utils/payment-messages.js +161 -0
  292. package/lib/Utils/payment-utils.d.ts +75 -0
  293. package/lib/Utils/payment-utils.js +145 -0
  294. package/lib/Utils/phone-utils.d.ts +3 -0
  295. package/lib/Utils/phone-utils.js +29 -0
  296. package/lib/Utils/pre-key-manager.d.ts +25 -0
  297. package/lib/Utils/pre-key-manager.js +105 -0
  298. package/lib/Utils/process-message.d.ts +103 -0
  299. package/lib/Utils/process-message.js +868 -0
  300. package/lib/Utils/qr-terminal.d.ts +1 -0
  301. package/lib/Utils/qr-terminal.js +16 -0
  302. package/lib/Utils/reconnect-backoff.d.ts +25 -0
  303. package/lib/Utils/reconnect-backoff.js +47 -0
  304. package/lib/Utils/reporting-utils.d.ts +12 -0
  305. package/lib/Utils/reporting-utils.js +257 -0
  306. package/lib/Utils/rich-message-utils.d.ts +54 -0
  307. package/lib/Utils/rich-message-utils.js +435 -0
  308. package/lib/Utils/rich-messages.d.ts +298 -0
  309. package/lib/Utils/rich-messages.js +1145 -0
  310. package/lib/Utils/scheduled-message.d.ts +81 -0
  311. package/lib/Utils/scheduled-message.js +101 -0
  312. package/lib/Utils/scheduling.d.ts +59 -0
  313. package/lib/Utils/scheduling.js +139 -0
  314. package/lib/Utils/signal.d.ts +82 -0
  315. package/lib/Utils/signal.js +200 -0
  316. package/lib/Utils/stanza-ack.d.ts +16 -0
  317. package/lib/Utils/stanza-ack.js +37 -0
  318. package/lib/Utils/status-stickers.d.ts +79 -0
  319. package/lib/Utils/status-stickers.js +261 -0
  320. package/lib/Utils/status.d.ts +107 -0
  321. package/lib/Utils/status.js +131 -0
  322. package/lib/Utils/sticker-pack-maker.d.ts +20 -0
  323. package/lib/Utils/sticker-pack-maker.js +112 -0
  324. package/lib/Utils/stickerpack.d.ts +18 -0
  325. package/lib/Utils/stickerpack.js +316 -0
  326. package/lib/Utils/sync-action-utils.d.ts +2 -0
  327. package/lib/Utils/sync-action-utils.js +48 -0
  328. package/lib/Utils/tag.d.ts +8 -0
  329. package/lib/Utils/tag.js +45 -0
  330. package/lib/Utils/tc-token-utils.d.ts +29 -0
  331. package/lib/Utils/tc-token-utils.js +162 -0
  332. package/lib/Utils/templates.d.ts +86 -0
  333. package/lib/Utils/templates.js +148 -0
  334. package/lib/Utils/text-format.d.ts +13 -0
  335. package/lib/Utils/text-format.js +81 -0
  336. package/lib/Utils/text-tools.d.ts +3 -0
  337. package/lib/Utils/text-tools.js +38 -0
  338. package/lib/Utils/ttl-cache.d.ts +29 -0
  339. package/lib/Utils/ttl-cache.js +123 -0
  340. package/lib/Utils/use-cache-manager-auth-state.d.ts +22 -0
  341. package/lib/Utils/use-cache-manager-auth-state.js +86 -0
  342. package/lib/Utils/use-multi-file-auth-state.d.ts +20 -0
  343. package/lib/Utils/use-multi-file-auth-state.js +201 -0
  344. package/lib/Utils/use-single-file-auth-state.d.ts +10 -0
  345. package/lib/Utils/use-single-file-auth-state.js +111 -0
  346. package/lib/Utils/use-sqlite-auth-state.d.ts +13 -0
  347. package/lib/Utils/use-sqlite-auth-state.js +171 -0
  348. package/lib/Utils/username.d.ts +22 -0
  349. package/lib/Utils/username.js +59 -0
  350. package/lib/Utils/validate-connection.d.ts +43 -0
  351. package/lib/Utils/validate-connection.js +197 -0
  352. package/lib/Utils/vcard.d.ts +40 -0
  353. package/lib/Utils/vcard.js +92 -0
  354. package/lib/Utils/voice-note.d.ts +13 -0
  355. package/lib/Utils/voice-note.js +47 -0
  356. package/lib/VoIP/audio-feeder.d.ts +15 -0
  357. package/lib/VoIP/audio-feeder.js +132 -0
  358. package/lib/VoIP/index.d.ts +22 -0
  359. package/lib/VoIP/index.js +277 -0
  360. package/lib/VoIP/relay-transport.d.ts +16 -0
  361. package/lib/VoIP/relay-transport.js +559 -0
  362. package/lib/VoIP/signaling.d.ts +16 -0
  363. package/lib/VoIP/signaling.js +624 -0
  364. package/lib/VoIP/types.d.ts +11 -0
  365. package/lib/VoIP/types.js +17 -0
  366. package/lib/VoIP/wasm-engine.d.ts +28 -0
  367. package/lib/VoIP/wasm-engine.js +1214 -0
  368. package/lib/VoIP/worker-bootstrap.d.ts +1 -0
  369. package/lib/VoIP/worker-bootstrap.js +1042 -0
  370. package/lib/WABinary/constants.d.ts +61 -0
  371. package/lib/WABinary/constants.js +1466 -0
  372. package/lib/WABinary/decode.d.ts +9 -0
  373. package/lib/WABinary/decode.js +261 -0
  374. package/lib/WABinary/encode.d.ts +2 -0
  375. package/lib/WABinary/encode.js +219 -0
  376. package/lib/WABinary/generic-utils.d.ts +45 -0
  377. package/lib/WABinary/generic-utils.js +285 -0
  378. package/lib/WABinary/index.d.ts +5 -0
  379. package/lib/WABinary/index.js +5 -0
  380. package/lib/WABinary/jid-utils.d.ts +32 -0
  381. package/lib/WABinary/jid-utils.js +102 -0
  382. package/lib/WABinary/types.d.ts +1 -0
  383. package/lib/WABinary/types.js +1 -0
  384. package/lib/WAM/BinaryInfo.d.ts +7 -0
  385. package/lib/WAM/BinaryInfo.js +9 -0
  386. package/lib/WAM/constants.d.ts +34926 -0
  387. package/lib/WAM/constants.js +22852 -0
  388. package/lib/WAM/encode.d.ts +1 -0
  389. package/lib/WAM/encode.js +149 -0
  390. package/lib/WAM/index.d.ts +3 -0
  391. package/lib/WAM/index.js +3 -0
  392. package/lib/WAUSync/Protocols/USyncBusinessProtocol.d.ts +43 -0
  393. package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +32 -0
  394. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +36 -0
  395. package/lib/WAUSync/Protocols/USyncContactProtocol.js +51 -0
  396. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +29 -0
  397. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +60 -0
  398. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
  399. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -0
  400. package/lib/WAUSync/Protocols/USyncFeatureProtocol.d.ts +13 -0
  401. package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +28 -0
  402. package/lib/WAUSync/Protocols/USyncPictureProtocol.d.ts +22 -0
  403. package/lib/WAUSync/Protocols/USyncPictureProtocol.js +28 -0
  404. package/lib/WAUSync/Protocols/USyncSidelistProtocol.d.ts +20 -0
  405. package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +23 -0
  406. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
  407. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +37 -0
  408. package/lib/WAUSync/Protocols/USyncTextStatusProtocol.d.ts +14 -0
  409. package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +24 -0
  410. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +9 -0
  411. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +24 -0
  412. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +38 -0
  413. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +49 -0
  414. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +14 -0
  415. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +28 -0
  416. package/lib/WAUSync/Protocols/index.d.ts +12 -0
  417. package/lib/WAUSync/Protocols/index.js +12 -0
  418. package/lib/WAUSync/USyncQuery.d.ts +25 -0
  419. package/lib/WAUSync/USyncQuery.js +140 -0
  420. package/lib/WAUSync/USyncUser.d.ts +24 -0
  421. package/lib/WAUSync/USyncUser.js +47 -0
  422. package/lib/WAUSync/index.d.ts +3 -0
  423. package/lib/WAUSync/index.js +3 -0
  424. package/lib/assets/wasm/loader.js +5 -0
  425. package/lib/assets/wasm/whatsapp.wasm +0 -0
  426. package/lib/assets/wasm/worker-modules.js +273 -0
  427. package/lib/exports-extra.d.ts +45 -0
  428. package/lib/exports-extra.js +47 -0
  429. package/lib/index.d.ts +16 -0
  430. package/lib/index.js +24 -0
  431. package/package.json +161 -4
@@ -0,0 +1,1145 @@
1
+ // Vanz@Port --- ported from @vinzsocket/baileys 3.3.13 (rich-messages.js). Creator credits untouched. See NOTICE.md.
2
+ import { proto } from "../../WAProto/index.js";
3
+ import { DEFAULT_AI_BOT_JID } from "../Defaults/bot-jid.js";
4
+ import { generateMessageIDV2 } from "./generics.js";
5
+ import { randomBytes, randomUUID } from "crypto";
6
+ const JS_KEYWORDS = new Set([
7
+ "import",
8
+ "export",
9
+ "from",
10
+ "default",
11
+ "as",
12
+ "const",
13
+ "let",
14
+ "var",
15
+ "function",
16
+ "class",
17
+ "extends",
18
+ "new",
19
+ "return",
20
+ "if",
21
+ "else",
22
+ "for",
23
+ "while",
24
+ "do",
25
+ "switch",
26
+ "case",
27
+ "break",
28
+ "continue",
29
+ "try",
30
+ "catch",
31
+ "finally",
32
+ "throw",
33
+ "async",
34
+ "await",
35
+ "yield",
36
+ "typeof",
37
+ "instanceof",
38
+ "in",
39
+ "of",
40
+ "delete",
41
+ "void",
42
+ "true",
43
+ "false",
44
+ "null",
45
+ "undefined",
46
+ "NaN",
47
+ "Infinity",
48
+ "this",
49
+ "super",
50
+ "static",
51
+ "get",
52
+ "set",
53
+ "debugger",
54
+ "with",
55
+ ]);
56
+ const PYTHON_KEYWORDS = new Set([
57
+ "import",
58
+ "from",
59
+ "as",
60
+ "def",
61
+ "class",
62
+ "return",
63
+ "if",
64
+ "elif",
65
+ "else",
66
+ "for",
67
+ "while",
68
+ "break",
69
+ "continue",
70
+ "try",
71
+ "except",
72
+ "finally",
73
+ "raise",
74
+ "with",
75
+ "yield",
76
+ "lambda",
77
+ "pass",
78
+ "del",
79
+ "global",
80
+ "nonlocal",
81
+ "assert",
82
+ "True",
83
+ "False",
84
+ "None",
85
+ "and",
86
+ "or",
87
+ "not",
88
+ "in",
89
+ "is",
90
+ "async",
91
+ "await",
92
+ "self",
93
+ "print",
94
+ ]);
95
+ const GO_KEYWORDS = new Set([
96
+ "func",
97
+ "package",
98
+ "import",
99
+ "return",
100
+ "if",
101
+ "else",
102
+ "for",
103
+ "switch",
104
+ "case",
105
+ "break",
106
+ "continue",
107
+ "type",
108
+ "struct",
109
+ "interface",
110
+ "map",
111
+ "chan",
112
+ "go",
113
+ "defer",
114
+ "const",
115
+ "var",
116
+ "range",
117
+ "true",
118
+ "false",
119
+ "nil",
120
+ "select",
121
+ "default",
122
+ "fallthrough",
123
+ ]);
124
+ export const LUA_KEYWORDS = new Set([
125
+ "function",
126
+ "end",
127
+ "if",
128
+ "then",
129
+ "else",
130
+ "elseif",
131
+ "for",
132
+ "while",
133
+ "do",
134
+ "local",
135
+ "return",
136
+ "true",
137
+ "false",
138
+ "nil",
139
+ "repeat",
140
+ "until",
141
+ "in",
142
+ "not",
143
+ "and",
144
+ "or",
145
+ ]);
146
+ const BASH_KEYWORDS = new Set([
147
+ "if",
148
+ "then",
149
+ "else",
150
+ "elif",
151
+ "fi",
152
+ "for",
153
+ "while",
154
+ "do",
155
+ "done",
156
+ "case",
157
+ "esac",
158
+ "echo",
159
+ "export",
160
+ "return",
161
+ "in",
162
+ "function",
163
+ "local",
164
+ "read",
165
+ "set",
166
+ "unset",
167
+ "true",
168
+ "false",
169
+ "exit",
170
+ "source",
171
+ "alias",
172
+ "declare",
173
+ "typeset",
174
+ ]);
175
+ const LANGUAGE_KEYWORDS = {
176
+ javascript: JS_KEYWORDS,
177
+ typescript: JS_KEYWORDS,
178
+ js: JS_KEYWORDS,
179
+ ts: JS_KEYWORDS,
180
+ python: PYTHON_KEYWORDS,
181
+ py: PYTHON_KEYWORDS,
182
+ go: GO_KEYWORDS,
183
+ golang: GO_KEYWORDS,
184
+ lua: LUA_KEYWORDS,
185
+ bash: BASH_KEYWORDS,
186
+ sh: BASH_KEYWORDS,
187
+ shell: BASH_KEYWORDS,
188
+ };
189
+ var CodeHighlightType;
190
+ (function (CodeHighlightType) {
191
+ CodeHighlightType[(CodeHighlightType["DEFAULT"] = 0)] = "DEFAULT";
192
+ CodeHighlightType[(CodeHighlightType["KEYWORD"] = 1)] = "KEYWORD";
193
+ CodeHighlightType[(CodeHighlightType["METHOD"] = 2)] = "METHOD";
194
+ CodeHighlightType[(CodeHighlightType["STRING"] = 3)] = "STRING";
195
+ CodeHighlightType[(CodeHighlightType["NUMBER"] = 4)] = "NUMBER";
196
+ CodeHighlightType[(CodeHighlightType["COMMENT"] = 5)] = "COMMENT";
197
+ })(CodeHighlightType || (CodeHighlightType = {}));
198
+ var RichSubMessageType;
199
+ (function (RichSubMessageType) {
200
+ RichSubMessageType[(RichSubMessageType["UNKNOWN"] = 0)] = "UNKNOWN";
201
+ RichSubMessageType[(RichSubMessageType["GRID_IMAGE"] = 1)] = "GRID_IMAGE";
202
+ RichSubMessageType[(RichSubMessageType["TEXT"] = 2)] = "TEXT";
203
+ RichSubMessageType[(RichSubMessageType["INLINE_IMAGE"] = 3)] = "INLINE_IMAGE";
204
+ RichSubMessageType[(RichSubMessageType["TABLE"] = 4)] = "TABLE";
205
+ RichSubMessageType[(RichSubMessageType["CODE"] = 5)] = "CODE";
206
+ RichSubMessageType[(RichSubMessageType["DYNAMIC"] = 6)] = "DYNAMIC";
207
+ RichSubMessageType[(RichSubMessageType["MAP"] = 7)] = "MAP";
208
+ RichSubMessageType[(RichSubMessageType["LATEX"] = 8)] = "LATEX";
209
+ RichSubMessageType[(RichSubMessageType["CONTENT_ITEMS"] = 9)] =
210
+ "CONTENT_ITEMS";
211
+ })(RichSubMessageType || (RichSubMessageType = {}));
212
+ const tokenizeCode = (codeStr, language = "javascript") => {
213
+ const keywords = LANGUAGE_KEYWORDS[language] || JS_KEYWORDS;
214
+ const blocks = [];
215
+ const lines = codeStr.split("\n");
216
+ for (let li = 0; li < lines.length; li++) {
217
+ const line = lines[li];
218
+ const isLast = li === lines.length - 1;
219
+ const nl = isLast ? "" : "\n";
220
+ if (!line.trim()) {
221
+ blocks.push({
222
+ highlightType: CodeHighlightType.DEFAULT,
223
+ codeContent: line + nl,
224
+ });
225
+ continue;
226
+ }
227
+ if (line.trim().startsWith("//") || line.trim().startsWith("#")) {
228
+ blocks.push({
229
+ highlightType: CodeHighlightType.COMMENT,
230
+ codeContent: line + nl,
231
+ });
232
+ continue;
233
+ }
234
+ const regex =
235
+ /(\/\/.*$|#.*$)|(["'`](?:[^"'`\\]|\\.)*["'`])|(\b\d+(?:\.\d+)?\b)|(\b[a-zA-Z_$][\w$]*\b)|([^\s\w$"'`]+)|(\s+)/g;
236
+ let match;
237
+ const tokens = [];
238
+ while ((match = regex.exec(line)) !== null) {
239
+ const val = match[0];
240
+ if (match[1]) {
241
+ tokens.push({
242
+ highlightType: CodeHighlightType.COMMENT,
243
+ codeContent: val,
244
+ });
245
+ } else if (match[2]) {
246
+ tokens.push({
247
+ highlightType: CodeHighlightType.STRING,
248
+ codeContent: val,
249
+ });
250
+ } else if (match[3]) {
251
+ tokens.push({
252
+ highlightType: CodeHighlightType.NUMBER,
253
+ codeContent: val,
254
+ });
255
+ } else if (match[4]) {
256
+ if (keywords.has(val)) {
257
+ tokens.push({
258
+ highlightType: CodeHighlightType.KEYWORD,
259
+ codeContent: val,
260
+ });
261
+ } else {
262
+ const after = line.slice(regex.lastIndex).trimStart();
263
+ if (after.startsWith("(")) {
264
+ tokens.push({
265
+ highlightType: CodeHighlightType.METHOD,
266
+ codeContent: val,
267
+ });
268
+ } else {
269
+ tokens.push({
270
+ highlightType: CodeHighlightType.DEFAULT,
271
+ codeContent: val,
272
+ });
273
+ }
274
+ }
275
+ } else {
276
+ tokens.push({
277
+ highlightType: CodeHighlightType.DEFAULT,
278
+ codeContent: val,
279
+ });
280
+ }
281
+ }
282
+ if (tokens.length === 0) {
283
+ blocks.push({
284
+ highlightType: CodeHighlightType.DEFAULT,
285
+ codeContent: line + nl,
286
+ });
287
+ continue;
288
+ }
289
+ const merged = [];
290
+ for (const t of tokens) {
291
+ const prev = merged.length > 0 ? merged[merged.length - 1] : undefined;
292
+ if (prev && prev.highlightType === t.highlightType) {
293
+ prev.codeContent += t.codeContent;
294
+ } else {
295
+ merged.push({ ...t });
296
+ }
297
+ }
298
+ if (merged.length > 0) {
299
+ merged[merged.length - 1].codeContent += nl;
300
+ }
301
+ blocks.push(...merged);
302
+ }
303
+ return blocks;
304
+ };
305
+ export const buildRichContextInfo = (quoted) => {
306
+ const ctxInfo = {
307
+ forwardingScore: 1,
308
+ isForwarded: true,
309
+ forwardedAiBotMessageInfo: { botJid: DEFAULT_AI_BOT_JID },
310
+ forwardOrigin: 4,
311
+ };
312
+ if (quoted?.key) {
313
+ ctxInfo.stanzaId = quoted.key.id;
314
+ ctxInfo.participant =
315
+ quoted.key.participant || quoted.sender || quoted.key.remoteJid;
316
+ ctxInfo.quotedMessage = quoted.message;
317
+ }
318
+ return ctxInfo;
319
+ };
320
+ export const buildBotForwardedMessage = (
321
+ submessages,
322
+ contextInfo,
323
+ unifiedResponse,
324
+ ) => {
325
+ const richResponse = {
326
+ messageType: 1,
327
+ submessages,
328
+ contextInfo,
329
+ };
330
+ if (unifiedResponse) {
331
+ richResponse.unifiedResponse = unifiedResponse;
332
+ }
333
+ return {
334
+ botForwardedMessage: {
335
+ message: {
336
+ richResponseMessage: richResponse,
337
+ },
338
+ },
339
+ };
340
+ };
341
+ export const generateTableContent = (
342
+ title,
343
+ headers,
344
+ rows,
345
+ quoted,
346
+ options = {},
347
+ ) => {
348
+ const { footer, headerText } = options;
349
+ const tableRows = [
350
+ { items: headers, isHeading: true },
351
+ ...rows.map((row) => ({ items: row.map(String) })),
352
+ ];
353
+ const submessages = [];
354
+ if (headerText) {
355
+ submessages.push({ messageType: 2, messageText: headerText });
356
+ }
357
+ submessages.push({
358
+ messageType: 4,
359
+ tableMetadata: { title, rows: tableRows },
360
+ });
361
+ if (footer) {
362
+ submessages.push({ messageType: 2, messageText: footer });
363
+ }
364
+ const ctxInfo = buildRichContextInfo(quoted);
365
+ return {
366
+ message: buildBotForwardedMessage(submessages, ctxInfo),
367
+ messageId: generateMessageIDV2(),
368
+ };
369
+ };
370
+ export const generateListContent = (title, items, quoted, options = {}) => {
371
+ const { footer, headerText } = options;
372
+ const tableRows = items.map((item) => ({
373
+ items: Array.isArray(item) ? item.map(String) : [String(item)],
374
+ }));
375
+ const submessages = [];
376
+ if (headerText) {
377
+ submessages.push({ messageType: 2, messageText: headerText });
378
+ }
379
+ submessages.push({
380
+ messageType: 4,
381
+ tableMetadata: { title, rows: tableRows },
382
+ });
383
+ if (footer) {
384
+ submessages.push({ messageType: 2, messageText: footer });
385
+ }
386
+ const ctxInfo = buildRichContextInfo(quoted);
387
+ return {
388
+ message: buildBotForwardedMessage(submessages, ctxInfo),
389
+ messageId: generateMessageIDV2(),
390
+ };
391
+ };
392
+ export const generateCodeBlockContent = (code, quoted, options = {}) => {
393
+ const { title, footer, language = "javascript" } = options;
394
+ const submessages = [];
395
+ if (title) {
396
+ submessages.push({ messageType: 2, messageText: title });
397
+ }
398
+ submessages.push({
399
+ messageType: 5,
400
+ codeMetadata: {
401
+ codeLanguage: language,
402
+ codeBlocks: tokenizeCode(code, language),
403
+ },
404
+ });
405
+ if (footer) {
406
+ submessages.push({ messageType: 2, messageText: footer });
407
+ }
408
+ const ctxInfo = buildRichContextInfo(quoted);
409
+ return {
410
+ message: buildBotForwardedMessage(submessages, ctxInfo),
411
+ messageId: generateMessageIDV2(),
412
+ };
413
+ };
414
+ export const generateLatexContent = (quoted, options) => {
415
+ const { text, expressions, headerText, footer } = options;
416
+ const submessages = [];
417
+ if (headerText) {
418
+ submessages.push({ messageType: 2, messageText: headerText });
419
+ }
420
+ const latexExpressions = expressions.map((expr) => {
421
+ const entry = {
422
+ latexExpression: expr.latexExpression,
423
+ url: expr.url,
424
+ width: expr.width,
425
+ height: expr.height,
426
+ };
427
+ if (expr.fontHeight !== undefined) entry.fontHeight = expr.fontHeight;
428
+ if (expr.imageTopPadding !== undefined)
429
+ entry.imageTopPadding = expr.imageTopPadding;
430
+ if (expr.imageLeadingPadding !== undefined)
431
+ entry.imageLeadingPadding = expr.imageLeadingPadding;
432
+ if (expr.imageBottomPadding !== undefined)
433
+ entry.imageBottomPadding = expr.imageBottomPadding;
434
+ if (expr.imageTrailingPadding !== undefined)
435
+ entry.imageTrailingPadding = expr.imageTrailingPadding;
436
+ return entry;
437
+ });
438
+ submessages.push({
439
+ messageType: 8,
440
+ latexMetadata: {
441
+ text: text || "",
442
+ expressions: latexExpressions,
443
+ },
444
+ });
445
+ if (footer) {
446
+ submessages.push({ messageType: 2, messageText: footer });
447
+ }
448
+ const ctxInfo = buildRichContextInfo(quoted);
449
+ return {
450
+ message: buildBotForwardedMessage(submessages, ctxInfo),
451
+ messageId: generateMessageIDV2(),
452
+ };
453
+ };
454
+ export const generateLatexImageContent = async (
455
+ quoted,
456
+ options,
457
+ uploadFn,
458
+ renderLatexToPng,
459
+ ) => {
460
+ const { text, expressions, headerText, footer } = options;
461
+ const submessages = [];
462
+ if (headerText) {
463
+ submessages.push({ messageType: 2, messageText: headerText });
464
+ }
465
+ const latexExpressions = await Promise.all(
466
+ expressions.map(async (expr) => {
467
+ const { buffer, width, height } = await renderLatexToPng(
468
+ expr.latexExpression,
469
+ );
470
+ const uploadResult = await uploadFn(buffer, "image");
471
+ const imageUrl = uploadResult.url || uploadResult.directPath;
472
+ return {
473
+ latexExpression: expr.latexExpression,
474
+ url: imageUrl,
475
+ width,
476
+ height,
477
+ };
478
+ }),
479
+ );
480
+ submessages.push({
481
+ messageType: 8,
482
+ latexMetadata: {
483
+ text: text || "",
484
+ expressions: latexExpressions,
485
+ },
486
+ });
487
+ if (footer) {
488
+ submessages.push({ messageType: 2, messageText: footer });
489
+ }
490
+ const ctxInfo = buildRichContextInfo(quoted);
491
+ return {
492
+ message: buildBotForwardedMessage(submessages, ctxInfo),
493
+ messageId: generateMessageIDV2(),
494
+ };
495
+ };
496
+ export const generateLatexInlineImageContent = async (
497
+ quoted,
498
+ options,
499
+ uploadFn,
500
+ renderLatexToPng,
501
+ ) => {
502
+ const { text, expressions, headerText, footer } = options;
503
+ const submessages = [];
504
+ if (headerText) {
505
+ submessages.push({ messageType: 2, messageText: headerText });
506
+ }
507
+ if (text) {
508
+ submessages.push({ messageType: 2, messageText: text });
509
+ }
510
+ for (const expr of expressions) {
511
+ const { buffer, width, height } = await renderLatexToPng(
512
+ expr.latexExpression,
513
+ );
514
+ const uploadResult = await uploadFn(buffer, "image");
515
+ const imageUrl = uploadResult.url || uploadResult.directPath;
516
+ submessages.push({
517
+ messageType: 3,
518
+ imageMetadata: {
519
+ imageUrl: {
520
+ imagePreviewUrl: imageUrl,
521
+ imageHighResUrl: imageUrl,
522
+ },
523
+ imageText: expr.latexExpression,
524
+ alignment: 2,
525
+ },
526
+ });
527
+ }
528
+ if (footer) {
529
+ submessages.push({ messageType: 2, messageText: footer });
530
+ }
531
+ const ctxInfo = buildRichContextInfo(quoted);
532
+ return {
533
+ message: buildBotForwardedMessage(submessages, ctxInfo),
534
+ messageId: generateMessageIDV2(),
535
+ };
536
+ };
537
+ export const captureUnifiedResponse = (msg) => {
538
+ const botFwd = msg?.botForwardedMessage?.message;
539
+ if (!botFwd) return null;
540
+ const rich = botFwd.richResponseMessage;
541
+ if (!rich?.unifiedResponse?.data) return null;
542
+ return {
543
+ unifiedResponse: { data: rich.unifiedResponse.data },
544
+ submessages: rich.submessages || [],
545
+ contextInfo: rich.contextInfo || {},
546
+ };
547
+ };
548
+ export const generateUnifiedResponseContent = (quoted, captured) => {
549
+ const ctxInfo = buildRichContextInfo(quoted);
550
+ return {
551
+ message: buildBotForwardedMessage(
552
+ captured.submessages,
553
+ ctxInfo,
554
+ captured.unifiedResponse,
555
+ ),
556
+ messageId: generateMessageIDV2(),
557
+ };
558
+ };
559
+ export const generateRichMessageContent = (submessages, quoted) => {
560
+ const ctxInfo = buildRichContextInfo(quoted);
561
+ return {
562
+ message: buildBotForwardedMessage(submessages, ctxInfo),
563
+ messageId: generateMessageIDV2(),
564
+ };
565
+ };
566
+ const HIGHLIGHT_TYPE_MAP = {
567
+ 0: "DEFAULT",
568
+ 1: "KEYWORD",
569
+ 2: "METHOD",
570
+ 3: "STR",
571
+ 4: "NUMBER",
572
+ 5: "COMMENT",
573
+ };
574
+ export const tokenizeCodeV2 = (code, language = "javascript") => {
575
+ const keywords = LANGUAGE_KEYWORDS[language] || JS_KEYWORDS;
576
+ const tokens = [];
577
+ let i = 0;
578
+ const n = code.length;
579
+ const push = (codeContent, highlightType) => {
580
+ if (!codeContent) return;
581
+ const last = tokens[tokens.length - 1];
582
+ if (last && last.highlightType === highlightType) {
583
+ last.codeContent += codeContent;
584
+ } else {
585
+ tokens.push({ codeContent, highlightType });
586
+ }
587
+ };
588
+ const isWordStart = (c) => /[a-zA-Z_$]/.test(c);
589
+ const isWord = (c) => /[a-zA-Z0-9_$]/.test(c);
590
+ const isNum = (c) => /[0-9]/.test(c);
591
+ while (i < n) {
592
+ const c = code[i];
593
+ if (c === "\n" || c === "\t" || c === " " || /\s/.test(c)) {
594
+ let s = i;
595
+ while (i < n && /\s/.test(code[i])) i++;
596
+ push(code.slice(s, i), 0);
597
+ continue;
598
+ }
599
+ if (c === "/" && code[i + 1] === "/") {
600
+ let s = i;
601
+ i += 2;
602
+ while (i < n && code[i] !== "\n") i++;
603
+ push(code.slice(s, i), 5);
604
+ continue;
605
+ }
606
+ if (c === "/" && code[i + 1] === "*") {
607
+ let s = i;
608
+ i += 2;
609
+ while (i < n - 1 && !(code[i] === "*" && code[i + 1] === "/")) i++;
610
+ i += 2;
611
+ push(code.slice(s, i), 5);
612
+ continue;
613
+ }
614
+ if (
615
+ c === "#" &&
616
+ (language === "python" ||
617
+ language === "py" ||
618
+ language === "bash" ||
619
+ language === "sh" ||
620
+ language === "shell" ||
621
+ language === "lua")
622
+ ) {
623
+ let s = i;
624
+ i++;
625
+ while (i < n && code[i] !== "\n") i++;
626
+ push(code.slice(s, i), 5);
627
+ continue;
628
+ }
629
+ if (c === '"' || c === "'" || c === "`") {
630
+ let s = i;
631
+ const q = c;
632
+ i++;
633
+ while (i < n) {
634
+ if (code[i] === "\\" && i + 1 < n) {
635
+ i += 2;
636
+ } else if (code[i] === q) {
637
+ i++;
638
+ break;
639
+ } else i++;
640
+ }
641
+ push(code.slice(s, i), 3);
642
+ continue;
643
+ }
644
+ if (isNum(c)) {
645
+ let s = i;
646
+ while (i < n && /[0-9.xXa-fA-FeEbBoO_]/.test(code[i])) i++;
647
+ push(code.slice(s, i), 4);
648
+ continue;
649
+ }
650
+ if (isWordStart(c)) {
651
+ let s = i;
652
+ while (i < n && isWord(code[i])) i++;
653
+ const word = code.slice(s, i);
654
+ let type = 0;
655
+ if (keywords.has(word)) {
656
+ type = 1;
657
+ } else {
658
+ let j = i;
659
+ while (j < n && /\s/.test(code[j])) j++;
660
+ if (code[j] === "(") type = 2;
661
+ }
662
+ push(word, type);
663
+ continue;
664
+ }
665
+ push(c, 0);
666
+ i++;
667
+ }
668
+ return {
669
+ codeBlock: tokens,
670
+ unified_codeBlock: tokens.map((t) => ({
671
+ content: t.codeContent,
672
+ type: HIGHLIGHT_TYPE_MAP[t.highlightType] || "DEFAULT",
673
+ })),
674
+ };
675
+ };
676
+ export const toTableMetadataV2 = (arr) => {
677
+ if (!Array.isArray(arr) || arr.length === 0) {
678
+ throw new Error("Input must be a non-empty array");
679
+ }
680
+ const [title, headerStr, ...rest] = arr;
681
+ const splitCols = (str) => {
682
+ if (typeof str !== "string") return [];
683
+ return str.includes("|")
684
+ ? str.split("|").map((s) => s.trim())
685
+ : str.split(",").map((s) => s.trim());
686
+ };
687
+ const splitRows = (str) => {
688
+ if (typeof str !== "string") return [];
689
+ return str.split(";;").map((row) => splitCols(row));
690
+ };
691
+ const header = splitCols(headerStr);
692
+ const parsedRows = rest.flatMap(splitRows);
693
+ const maxLen = Math.max(header.length, ...parsedRows.map((r) => r.length));
694
+ const unified_rows = [
695
+ {
696
+ is_header: true,
697
+ cells: [...header, ...Array(maxLen - header.length).fill("")],
698
+ },
699
+ ...parsedRows.map((cells) => ({
700
+ is_header: false,
701
+ cells: [...cells, ...Array(maxLen - cells.length).fill("")],
702
+ })),
703
+ ];
704
+ const rows = unified_rows.map((r) => ({
705
+ items: r.cells,
706
+ ...(r.is_header ? { isHeading: true } : {}),
707
+ }));
708
+ return { title, rows, unified_rows };
709
+ };
710
+ export const generateTableContentV2 = (table, quoted, options = {}) => {
711
+ const { title, footer, headerText, text } = options;
712
+ const { unified_rows } = toTableMetadataV2(table);
713
+ const sections = [];
714
+ if (headerText || title) {
715
+ const headingText = headerText || title;
716
+ sections.push({
717
+ view_model: {
718
+ primitive: {
719
+ text: headingText,
720
+ __typename: "GenAIMarkdownTextUXPrimitive",
721
+ },
722
+ __typename: "GenAISingleLayoutViewModel",
723
+ },
724
+ });
725
+ }
726
+ if (text) {
727
+ sections.push({
728
+ view_model: {
729
+ primitive: {
730
+ text,
731
+ __typename: "GenAIMarkdownTextUXPrimitive",
732
+ },
733
+ __typename: "GenAISingleLayoutViewModel",
734
+ },
735
+ });
736
+ }
737
+ sections.push({
738
+ view_model: {
739
+ primitive: {
740
+ rows: unified_rows,
741
+ __typename: "GenATableUXPrimitive",
742
+ },
743
+ __typename: "GenAISingleLayoutViewModel",
744
+ },
745
+ });
746
+ if (footer) {
747
+ sections.push({
748
+ view_model: {
749
+ primitive: {
750
+ text: footer,
751
+ __typename: "GenAIMarkdownTextUXPrimitive",
752
+ },
753
+ __typename: "GenAISingleLayoutViewModel",
754
+ },
755
+ });
756
+ }
757
+ const responseId = randomUUID();
758
+ const unifiedData = {
759
+ response_id: responseId,
760
+ sections,
761
+ };
762
+ const base64Data = Buffer.from(JSON.stringify(unifiedData)).toString(
763
+ "base64",
764
+ );
765
+ const ctxInfo = {
766
+ forwardingScore: 2,
767
+ isForwarded: true,
768
+ forwardedAiBotMessageInfo: { botJid: "259786046210223@bot" },
769
+ forwardOrigin: 4,
770
+ botMessageSharingInfo: {
771
+ botEntryPointOrigin: 1,
772
+ forwardScore: 2,
773
+ },
774
+ };
775
+ if (quoted?.key) {
776
+ ctxInfo.stanzaId = quoted.key.id;
777
+ ctxInfo.participant =
778
+ quoted.key.participant || quoted.sender || quoted.key.remoteJid;
779
+ ctxInfo.quotedMessage = quoted.message;
780
+ }
781
+ const content = {
782
+ messageContextInfo: {
783
+ threadId: [],
784
+ deviceListMetadata: {
785
+ senderKeyIndexes: [],
786
+ recipientKeyIndexes: [],
787
+ recipientKeyHash: "",
788
+ recipientTimestamp: Math.floor(Date.now() / 1000),
789
+ },
790
+ deviceListMetadataVersion: 2,
791
+ messageSecret: randomBytes(32),
792
+ },
793
+ botForwardedMessage: {
794
+ message: {
795
+ richResponseMessage: {
796
+ submessages: [],
797
+ messageType: 1,
798
+ unifiedResponse: { data: base64Data },
799
+ contextInfo: ctxInfo,
800
+ },
801
+ },
802
+ },
803
+ };
804
+ return {
805
+ message: content,
806
+ messageId: generateMessageIDV2(),
807
+ };
808
+ };
809
+ export const generateCodeBlockContentV2 = (code, quoted, options = {}) => {
810
+ const { title, footer, language = "javascript", text } = options;
811
+ const { unified_codeBlock } = tokenizeCodeV2(code, language);
812
+ const sections = [];
813
+ if (text) {
814
+ sections.push({
815
+ view_model: {
816
+ primitive: {
817
+ text,
818
+ __typename: "GenAIMarkdownTextUXPrimitive",
819
+ },
820
+ __typename: "GenAISingleLayoutViewModel",
821
+ },
822
+ });
823
+ }
824
+ sections.push({
825
+ view_model: {
826
+ primitive: {
827
+ language,
828
+ code_blocks: unified_codeBlock,
829
+ __typename: "GenAICodeUXPrimitive",
830
+ },
831
+ __typename: "GenAISingleLayoutViewModel",
832
+ },
833
+ });
834
+ if (footer) {
835
+ sections.push({
836
+ view_model: {
837
+ primitive: {
838
+ text: footer,
839
+ __typename: "GenAIMarkdownTextUXPrimitive",
840
+ },
841
+ __typename: "GenAISingleLayoutViewModel",
842
+ },
843
+ });
844
+ }
845
+ const responseId = randomUUID();
846
+ const unifiedData = {
847
+ response_id: responseId,
848
+ sections,
849
+ };
850
+ const base64Data = Buffer.from(JSON.stringify(unifiedData)).toString(
851
+ "base64",
852
+ );
853
+ const ctxInfo = {
854
+ mentionedJid: [],
855
+ groupMentions: [],
856
+ statusAttributions: [],
857
+ forwardingScore: 2,
858
+ isForwarded: true,
859
+ forwardedAiBotMessageInfo: { botJid: "259786046210223@bot" },
860
+ forwardOrigin: 4,
861
+ botMessageSharingInfo: {
862
+ botEntryPointOrigin: 1,
863
+ forwardScore: 2,
864
+ },
865
+ };
866
+ if (quoted?.key) {
867
+ ctxInfo.stanzaId = quoted.key.id;
868
+ ctxInfo.participant =
869
+ quoted.key.participant || quoted.sender || quoted.key.remoteJid;
870
+ ctxInfo.quotedMessage = quoted.message;
871
+ }
872
+ const content = {
873
+ messageContextInfo: {
874
+ threadId: [],
875
+ deviceListMetadata: {
876
+ senderKeyIndexes: [],
877
+ recipientKeyIndexes: [],
878
+ recipientKeyHash: "",
879
+ recipientTimestamp: Math.floor(Date.now() / 1000),
880
+ },
881
+ deviceListMetadataVersion: 2,
882
+ messageSecret: randomBytes(32),
883
+ },
884
+ botForwardedMessage: {
885
+ message: {
886
+ richResponseMessage: {
887
+ submessages: [],
888
+ messageType: 1,
889
+ unifiedResponse: { data: base64Data },
890
+ contextInfo: ctxInfo,
891
+ },
892
+ },
893
+ },
894
+ };
895
+ return {
896
+ message: content,
897
+ messageId: generateMessageIDV2(),
898
+ };
899
+ };
900
+ export const generateLinkContent = (text, links, quoted, options = {}) => {
901
+ const {
902
+ footer,
903
+ botJid = DEFAULT_AI_BOT_JID,
904
+ forwardingScore = 3,
905
+ citations = [],
906
+ proofs = [],
907
+ } = options;
908
+ const submessages = [];
909
+ const fullText = footer ? `${text}${footer}` : text;
910
+ submessages.push({ messageType: 2, messageText: fullText });
911
+ const sections = [];
912
+ const inlineEntities = links.map((link, i) => {
913
+ const url = typeof link === "string" ? link : link.url;
914
+ const displayName =
915
+ typeof link === "object" && link.displayName
916
+ ? link.displayName
917
+ : citations[i]?.sourceTitle || `Link ${i + 1}`;
918
+ return {
919
+ key: `IE_${i}`,
920
+ metadata: {
921
+ display_name: displayName,
922
+ is_trusted: false,
923
+ url,
924
+ __typename: "GenAIInlineLinkItem",
925
+ },
926
+ };
927
+ });
928
+ sections.push({
929
+ view_model: {
930
+ primitive: {
931
+ text,
932
+ inline_entities: inlineEntities,
933
+ __typename: "GenAIMarkdownTextUXPrimitive",
934
+ },
935
+ __typename: "GenAISingleLayoutViewModel",
936
+ },
937
+ });
938
+ if (footer) {
939
+ sections.push({
940
+ view_model: {
941
+ primitive: {
942
+ text: footer,
943
+ __typename: "GenAIMarkdownTextUXPrimitive",
944
+ },
945
+ __typename: "GenAISingleLayoutViewModel",
946
+ },
947
+ });
948
+ }
949
+ const responseId = randomUUID();
950
+ const unifiedData = {
951
+ response_id: responseId,
952
+ sections,
953
+ };
954
+ const base64Data = Buffer.from(JSON.stringify(unifiedData)).toString(
955
+ "base64",
956
+ );
957
+ const ctxInfo = {
958
+ forwardingScore,
959
+ isForwarded: true,
960
+ forwardedAiBotMessageInfo: { botJid },
961
+ forwardOrigin: 4,
962
+ botMessageSharingInfo: {
963
+ forwardScore: forwardingScore,
964
+ },
965
+ };
966
+ if (quoted?.key) {
967
+ ctxInfo.stanzaId = quoted.key.id;
968
+ ctxInfo.participant =
969
+ quoted.key.participant || quoted.sender || quoted.key.remoteJid;
970
+ ctxInfo.quotedMessage = quoted.message;
971
+ }
972
+ const messageContextInfo = {
973
+ messageSecret: randomBytes(32),
974
+ };
975
+ if (citations.length > 0 || proofs.length > 0) {
976
+ const botMetadata = {};
977
+ if (citations.length > 0) {
978
+ botMetadata.richResponseSourcesMetadata = {
979
+ sources: citations.map((c, i) => ({
980
+ provider: 1,
981
+ thumbnailCdnUrl: "",
982
+ sourceProviderUrl:
983
+ typeof links[i] === "string" ? links[i] : links[i]?.url || "",
984
+ sourceQuery: c.sourceQuery || "",
985
+ faviconCdnUrl: c.faviconCdnUrl || "",
986
+ citationNumber: c.citationNumber ?? i + 1,
987
+ sourceTitle: c.sourceTitle || "",
988
+ })),
989
+ };
990
+ }
991
+ if (proofs.length > 0) {
992
+ botMetadata.verificationMetadata = {
993
+ proofs: proofs.map((p) => ({
994
+ version: p.version || 1,
995
+ useCase: p.useCase || 1,
996
+ signature: p.signature || "",
997
+ certificateChain: p.certificateChain || [],
998
+ })),
999
+ };
1000
+ }
1001
+ messageContextInfo.botMetadata = botMetadata;
1002
+ }
1003
+ const content = {
1004
+ messageContextInfo,
1005
+ botForwardedMessage: {
1006
+ message: {
1007
+ richResponseMessage: {
1008
+ messageType: 1,
1009
+ submessages,
1010
+ unifiedResponse: { data: base64Data },
1011
+ contextInfo: ctxInfo,
1012
+ },
1013
+ },
1014
+ },
1015
+ };
1016
+ return {
1017
+ message: content,
1018
+ messageId: generateMessageIDV2(),
1019
+ };
1020
+ };
1021
+ export const generateLinkContentV2 = (text, links, quoted, options = {}) => {
1022
+ const { footer, searchEngine = "MAME" } = options;
1023
+ const submessages = [];
1024
+ const fullText = footer ? `${text}${footer}` : text;
1025
+ submessages.push({ messageType: 2, messageText: fullText });
1026
+ const sections = [];
1027
+ const inlineEntities = links.map((link, i) => {
1028
+ const url = typeof link === "string" ? link : link.url;
1029
+ const displayName =
1030
+ typeof link === "object" && link.displayName
1031
+ ? link.displayName
1032
+ : `Link ${i + 1}`;
1033
+ const sourceDisplayName =
1034
+ typeof link === "object" && link.sourceDisplayName
1035
+ ? link.sourceDisplayName
1036
+ : `Source ${i + 1}`;
1037
+ const sourceSubtitle =
1038
+ typeof link === "object" && link.sourceSubtitle
1039
+ ? link.sourceSubtitle
1040
+ : "";
1041
+ return {
1042
+ key: `IE_${i}`,
1043
+ metadata: {
1044
+ reference_id: i + 1,
1045
+ reference_url: url,
1046
+ reference_title: displayName,
1047
+ reference_display_name: displayName,
1048
+ sources: [
1049
+ {
1050
+ source_type: "THIRD_PARTY",
1051
+ source_display_name: sourceDisplayName,
1052
+ source_subtitle: sourceSubtitle,
1053
+ source_url: url,
1054
+ },
1055
+ ],
1056
+ __typename: "GenAISearchCitationItem",
1057
+ },
1058
+ };
1059
+ });
1060
+ sections.push({
1061
+ view_model: {
1062
+ primitive: {
1063
+ text,
1064
+ inline_entities: inlineEntities,
1065
+ __typename: "GenAIMarkdownTextUXPrimitive",
1066
+ },
1067
+ __typename: "GenAISingleLayoutViewModel",
1068
+ },
1069
+ });
1070
+ const searchSources = links.map((link, i) => {
1071
+ const url = typeof link === "string" ? link : link.url;
1072
+ const sourceDisplayName =
1073
+ typeof link === "object" && link.sourceDisplayName
1074
+ ? link.sourceDisplayName
1075
+ : `Source ${i + 1}`;
1076
+ const sourceSubtitle =
1077
+ typeof link === "object" && link.sourceSubtitle
1078
+ ? link.sourceSubtitle
1079
+ : "";
1080
+ return {
1081
+ source_type: "THIRD_PARTY",
1082
+ source_display_name: sourceDisplayName,
1083
+ source_subtitle: sourceSubtitle,
1084
+ source_url: url,
1085
+ };
1086
+ });
1087
+ sections.push({
1088
+ view_model: {
1089
+ primitive: {
1090
+ sources: searchSources,
1091
+ search_engine: searchEngine,
1092
+ __typename: "GenAISearchResultPrimitive",
1093
+ },
1094
+ __typename: "GenAISingleLayoutViewModel",
1095
+ },
1096
+ });
1097
+ if (footer) {
1098
+ sections.push({
1099
+ view_model: {
1100
+ primitive: {
1101
+ text: footer,
1102
+ __typename: "GenAIMarkdownTextUXPrimitive",
1103
+ },
1104
+ __typename: "GenAISingleLayoutViewModel",
1105
+ },
1106
+ });
1107
+ }
1108
+ const responseId = randomUUID();
1109
+ const unifiedData = {
1110
+ response_id: responseId,
1111
+ sections,
1112
+ };
1113
+ const base64Data = Buffer.from(JSON.stringify(unifiedData)).toString(
1114
+ "base64",
1115
+ );
1116
+ const ctxInfo = {
1117
+ isForwarded: true,
1118
+ forwardOrigin: 4,
1119
+ };
1120
+ if (quoted?.key) {
1121
+ ctxInfo.participant =
1122
+ quoted.key.participant || quoted.sender || quoted.key.remoteJid;
1123
+ ctxInfo.quotedMessage = quoted.message;
1124
+ }
1125
+ const content = {
1126
+ messageContextInfo: {
1127
+ threadId: [],
1128
+ messageSecret: randomBytes(32),
1129
+ },
1130
+ botForwardedMessage: {
1131
+ message: {
1132
+ richResponseMessage: {
1133
+ messageType: 1,
1134
+ submessages,
1135
+ unifiedResponse: { data: base64Data },
1136
+ contextInfo: ctxInfo,
1137
+ },
1138
+ },
1139
+ },
1140
+ };
1141
+ return {
1142
+ message: content,
1143
+ messageId: generateMessageIDV2(),
1144
+ };
1145
+ };