@lobu/runtime-server 24.1.1 → 24.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (322) hide show
  1. package/dist/catalogs/connectors.json +175 -39
  2. package/dist/catalogs/skills.json +2 -2
  3. package/dist/component.json +1 -1
  4. package/dist/connectors/gchat.ts +31 -1
  5. package/dist/connectors/google_gmail.ts +70 -41
  6. package/dist/connectors/google_gmail_references.ts +406 -0
  7. package/dist/connectors/linkedin-inbox-adapter.js +107 -36
  8. package/dist/connectors/linkedin-inbox.ts +13 -0
  9. package/dist/connectors/linkedin.ts +1 -1
  10. package/dist/connectors/postgres.ts +14 -8
  11. package/dist/connectors/reddit.ts +171 -5
  12. package/dist/connectors/whatsapp-web-adapter.js +147 -61
  13. package/dist/connectors/whatsapp-web-helpers.ts +6 -2
  14. package/dist/connectors/whatsapp_web.ts +48 -17
  15. package/dist/connectors/x-dm-adapter.js +252 -35
  16. package/dist/connectors/x.ts +189 -13
  17. package/dist/db/migrations/20261020140000_view_attachments_by_page.sql +3 -1
  18. package/dist/db/migrations/20261024050000_events_source_reference_arrival.sql +27 -0
  19. package/dist/db/migrations/20261026000000_turn_write_receipts.sql +36 -0
  20. package/dist/db/migrations/20261026190000_federated_relationship_endpoints.sql +143 -0
  21. package/dist/dependencies.bun.lock +137 -202
  22. package/dist/embeddings-server.mjs +81 -11
  23. package/dist/guest.bundle.js +62 -25
  24. package/dist/owletto/dist/assets/_-XKF0m81R.js +3 -0
  25. package/dist/owletto/dist/assets/_-e8MbEBtw.js +2 -0
  26. package/dist/owletto/dist/assets/_agentId-Cv9goIFf.js +2 -0
  27. package/dist/owletto/dist/assets/_agentId-emObu67X.js +2 -0
  28. package/dist/owletto/dist/assets/_automationId-CfFFAYK1.js +2 -0
  29. package/dist/owletto/dist/assets/_connectorKey._connectionId-D6NKXSOE.js +2 -0
  30. package/dist/owletto/dist/assets/_connectorKey.index-DFrkLLTU.js +2 -0
  31. package/dist/owletto/dist/assets/_conversationId-D3vuAQPe.js +2 -0
  32. package/dist/owletto/dist/assets/_eventId-BV5SQaUA.js +2 -0
  33. package/dist/owletto/dist/assets/_name-DjtJMop4.js +2 -0
  34. package/dist/owletto/dist/assets/_owner-oBX68rb9.js +3 -0
  35. package/dist/owletto/dist/assets/_shape-C4lLPAwI.js +2 -0
  36. package/dist/owletto/dist/assets/_skillKey-Cw-7q6hI.js +2 -0
  37. package/dist/owletto/dist/assets/_slug-B2g5qzn3.js +2 -0
  38. package/dist/owletto/dist/assets/_viewKey-CIKGCtdK.js +2 -0
  39. package/dist/owletto/dist/assets/_viewKey-Dx4kJo7o.js +2 -0
  40. package/dist/owletto/dist/assets/accept-invitation-38lHBvjO.js +2 -0
  41. package/dist/owletto/dist/assets/activity-route-view-voRYSM3a.js +2 -0
  42. package/dist/owletto/dist/assets/agent-card-controls-DiU7Un5w.js +2 -0
  43. package/dist/owletto/dist/assets/{agent-client-setup-list-BlXB4SE5.js → agent-client-setup-list-Bkyw22GW.js} +4 -4
  44. package/dist/owletto/dist/assets/agent-connect-pages-CpBxQCpx.js +2 -0
  45. package/dist/owletto/dist/assets/{agent-editor-form-DsSoeQeF.js → agent-editor-form-QrIDroFL.js} +2 -2
  46. package/dist/owletto/dist/assets/agent-guardrails-route-CyoGSxcZ.js +2 -0
  47. package/dist/owletto/dist/assets/{agent-loading-shells-B7v6Cffw.js → agent-loading-shells-CamDtzHY.js} +2 -2
  48. package/dist/owletto/dist/assets/agent-permissions-matrix-CgsQ8BK_.js +2 -0
  49. package/dist/owletto/dist/assets/{agent-skill-context-DFucg4c4.js → agent-skill-context-lWbXKEm1.js} +2 -2
  50. package/dist/owletto/dist/assets/agent-skills-route-D-w3tY_2.js +2 -0
  51. package/dist/owletto/dist/assets/agent-subpage-shell-CLqpn5Tb.js +2 -0
  52. package/dist/owletto/dist/assets/{agent-thread-D38STyeu.js → agent-thread-CsRexwTv.js} +4 -4
  53. package/dist/owletto/dist/assets/agents-DzH_FFKU.js +2 -0
  54. package/dist/owletto/dist/assets/agents-workbench-CmGrMvPC.js +2 -0
  55. package/dist/owletto/dist/assets/app-bridge-C4nPtae3.js +121 -0
  56. package/dist/owletto/dist/assets/app._appId-BO7G38fL.js +2 -0
  57. package/dist/owletto/dist/assets/automation-detail-content-DMYxs6F6.js +2 -0
  58. package/dist/owletto/dist/assets/automations-DzH_FFKU.js +2 -0
  59. package/dist/owletto/dist/assets/calendar-DDCCSPW6.js +2 -0
  60. package/dist/owletto/dist/assets/callback-DFciMR8u.js +2 -0
  61. package/dist/owletto/dist/assets/{card-jzhQrMDP.js → card-BCsbrdGs.js} +2 -2
  62. package/dist/owletto/dist/assets/{claim-B-wq745Q.js → claim-BRua2b_7.js} +2 -2
  63. package/dist/owletto/dist/assets/client-activity-scopes-BLIy1Zc3.js +2 -0
  64. package/dist/owletto/dist/assets/client-rows-DiJQ5D1z.js +2 -0
  65. package/dist/owletto/dist/assets/clients-8-EpRjsm.js +2 -0
  66. package/dist/owletto/dist/assets/{code-editor-CEqoCky-.js → code-editor-BFZa4EIt.js} +3 -3
  67. package/dist/owletto/dist/assets/connect-C0cHE9Xl.js +2 -0
  68. package/dist/owletto/dist/assets/connect-menu-D2K4tmvW.js +2 -0
  69. package/dist/owletto/dist/assets/connect._clientId-D4EG5a0v.js +2 -0
  70. package/dist/owletto/dist/assets/connected._clientId-DhoCT6sT.js +2 -0
  71. package/dist/owletto/dist/assets/connected._clientId.activity-Dn4qw2Us.js +2 -0
  72. package/dist/owletto/dist/assets/connected._clientId.index-BTI5JXA3.js +2 -0
  73. package/dist/owletto/dist/assets/connection-X9VU9Ijm.js +2 -0
  74. package/dist/owletto/dist/assets/connection-feed-detail-B6ydKasK.js +2 -0
  75. package/dist/owletto/dist/assets/connections-browser-BMV8bf54.js +2 -0
  76. package/dist/owletto/dist/assets/connector-boxes-DqZA-FdG.js +2 -0
  77. package/dist/owletto/dist/assets/{connector-provenance-D-ECOlMJ.js → connector-provenance-BIg8P8WY.js} +2 -2
  78. package/dist/owletto/dist/assets/connector-scope-lists-CJYz53YF.js +2 -0
  79. package/dist/owletto/dist/assets/{connectors-CH4KBZyT.js → connectors-BroKpwhB.js} +2 -2
  80. package/dist/owletto/dist/assets/{consent-C9ZpHb7V.js → consent-fzLN-Qy7.js} +2 -2
  81. package/dist/owletto/dist/assets/copy-button-Df7QXE0w.js +2 -0
  82. package/dist/owletto/dist/assets/{core.esm-BupT3V0i.js → core.esm-A1UnFbGs.js} +2 -2
  83. package/dist/owletto/dist/assets/create-BjwsYarn.js +2 -0
  84. package/dist/owletto/dist/assets/create-Dzr4mlr0.js +2 -0
  85. package/dist/owletto/dist/assets/create-automation-form-DHW6OUoS.js +3 -0
  86. package/dist/owletto/dist/assets/create-c94SPL21.js +2 -0
  87. package/dist/owletto/dist/assets/create._connectorKey-DLLn2nej.js +2 -0
  88. package/dist/owletto/dist/assets/{cronstrue-CWImw-kf.js → cronstrue-xxpD1P2-.js} +2 -2
  89. package/dist/owletto/dist/assets/{device-D-7WBe9E.js → device-C3AEoL5c.js} +2 -2
  90. package/dist/owletto/dist/assets/{device-pin-tombstone-2U0UMu3_.js → device-pin-tombstone-B_te59GE.js} +2 -2
  91. package/dist/owletto/dist/assets/device._deviceId-ZU09qrot.js +2 -0
  92. package/dist/owletto/dist/assets/elk-worker.min-BENGc9gn.js +23 -0
  93. package/dist/owletto/dist/assets/{entity-avatar-mdh7Kq5D.js → entity-avatar-CEV4ttUQ.js} +2 -2
  94. package/dist/owletto/dist/assets/entity-options-DJv2EhVV.js +2 -0
  95. package/dist/owletto/dist/assets/entity-page-BUghWZ1s.js +2 -0
  96. package/dist/owletto/dist/assets/entity-type-page-Lf6ONdpf.js +2 -0
  97. package/dist/owletto/dist/assets/event-card-CBlsG32u.js +2 -0
  98. package/dist/owletto/dist/assets/event-detail-BKSGEOdW.js +2 -0
  99. package/dist/owletto/dist/assets/events-feed-VfU4csn2.js +2 -0
  100. package/dist/owletto/dist/assets/feed-event-kinds-BYuZCoU4.js +2 -0
  101. package/dist/owletto/dist/assets/filter-bar-COU0sBFQ.js +2 -0
  102. package/dist/owletto/dist/assets/{full-page-spinner-BVbcpW3R.js → full-page-spinner-C1Q_jEzD.js} +2 -2
  103. package/dist/owletto/dist/assets/guardrails-6ZJv1uzM.js +2 -0
  104. package/dist/owletto/dist/assets/identity-BaFLmbSo.js +2 -0
  105. package/dist/owletto/dist/assets/index-008wj-Pz.js +7950 -0
  106. package/dist/owletto/dist/assets/index-BaetvYLa.js +2 -0
  107. package/dist/owletto/dist/assets/index-BiEf5xOE.css +1 -0
  108. package/dist/owletto/dist/assets/{index-CxF2XXzl.js → index-BrDP4PCs.js} +2 -2
  109. package/dist/owletto/dist/assets/index-BuXIeK7D.js +2 -0
  110. package/dist/owletto/dist/assets/index-CAVcR9za.js +2 -0
  111. package/dist/owletto/dist/assets/index-CMLfWGPU.js +2 -0
  112. package/dist/owletto/dist/assets/index-D0YEYP7N.js +2 -0
  113. package/dist/owletto/dist/assets/index-DFyBbp7b.js +2 -0
  114. package/dist/owletto/dist/assets/{index-D7gHOpfg.js → index-DNtYqkiA.js} +2 -2
  115. package/dist/owletto/dist/assets/index-DQxzeM37.js +2 -0
  116. package/dist/owletto/dist/assets/index-DkO0nPex.js +2 -0
  117. package/dist/owletto/dist/assets/index-KlRId0g6.js +2 -0
  118. package/dist/owletto/dist/assets/index-Ywnqi4A6.js +2 -0
  119. package/dist/owletto/dist/assets/index-wHFQv1aT.js +12 -0
  120. package/dist/owletto/dist/assets/index-xnxhf3Op.js +2 -0
  121. package/dist/owletto/dist/assets/{index-BTlx9K_t.js → index-yIub2xUM.js} +2 -2
  122. package/dist/owletto/dist/assets/json-diff-LE_vNZrM.js +4 -0
  123. package/dist/owletto/dist/assets/{list-skeleton-CepswBka.js → list-skeleton-Kzxi2OXB.js} +2 -2
  124. package/dist/owletto/dist/assets/login-DWOT6jtS.js +2 -0
  125. package/dist/owletto/dist/assets/logout-Dt_VDilG.js +2 -0
  126. package/dist/owletto/dist/assets/{member-scope-gate-DD4YBFn-.js → member-scope-gate-De75CR7W.js} +2 -2
  127. package/dist/owletto/dist/assets/memory-browse-page-p2vIbfkC.js +74 -0
  128. package/dist/owletto/dist/assets/{model-selector-CDrAjH31.js → model-selector-3l9lY50C.js} +2 -2
  129. package/dist/owletto/dist/assets/model-udnQ_S43.js +2 -0
  130. package/dist/owletto/dist/assets/models-CQj7GIOp.js +2 -0
  131. package/dist/owletto/dist/assets/new-BOwIHkre.js +2 -0
  132. package/dist/owletto/dist/assets/{new-ktz9Cs_P.js → new-BbdwuJPm.js} +2 -2
  133. package/dist/owletto/dist/assets/new-DTuFCQhV.js +2 -0
  134. package/dist/owletto/dist/assets/{oauth-workspace-access-lZNZ9gul.js → oauth-workspace-access-QPo4YwRX.js} +2 -2
  135. package/dist/owletto/dist/assets/organization-BDzjnqPf.js +2 -0
  136. package/dist/owletto/dist/assets/peek-pane-content-D7yt0PrA.js +2 -0
  137. package/dist/owletto/dist/assets/permissions-CfoY4WFY.js +2 -0
  138. package/dist/owletto/dist/assets/proposal-review-shell-CVkLnnKo.js +2 -0
  139. package/dist/owletto/dist/assets/public-shell-ready-DXUTTGGp.js +2 -0
  140. package/dist/owletto/dist/assets/record-activity-BXhvJbd9.js +2 -0
  141. package/dist/owletto/dist/assets/{record-session-Pbr5czGw.js → record-session-D07szzqN.js} +2 -2
  142. package/dist/owletto/dist/assets/renderer-AJxSmE3-.js +97 -0
  143. package/dist/owletto/dist/assets/reset-password-kRYyQuTY.js +2 -0
  144. package/dist/owletto/dist/assets/runs-lG2ChtOt.js +2 -0
  145. package/dist/owletto/dist/assets/runs-panel-LnGpHCAQ.js +2 -0
  146. package/dist/owletto/dist/assets/schema-type-editor-panel-C_Es0qDf.js +2 -0
  147. package/dist/owletto/dist/assets/settings-CEAOg7fr.js +2 -0
  148. package/dist/owletto/dist/assets/settings-gGYXbFfd.js +2 -0
  149. package/dist/owletto/dist/assets/skills-BOL5c_Tk.js +2 -0
  150. package/dist/owletto/dist/assets/source-record-panels-CjFPgKKJ.js +2 -0
  151. package/dist/owletto/dist/assets/status-dot-CSBtKT4g.js +2 -0
  152. package/dist/owletto/dist/assets/table-DHM-vCxP.js +2 -0
  153. package/dist/owletto/dist/assets/use-automations-C4TSie1i.js +2 -0
  154. package/dist/owletto/dist/assets/{use-mention-search-Dcunv4L0.js → use-mention-search-PfZrNbu_.js} +4 -4
  155. package/dist/owletto/dist/assets/use-scroll-sentinel-D-fJx_Md.js +2 -0
  156. package/dist/owletto/dist/assets/view-param-filters-DkX4YdDT.js +2 -0
  157. package/dist/owletto/dist/assets/views-access-required-2ubIf_3N.js +2 -0
  158. package/dist/owletto/dist/index.html +2 -2
  159. package/dist/server-main.bundle.mjs +137007 -132255
  160. package/npm-shrinkwrap.json +723 -1095
  161. package/package.json +7 -10
  162. package/vendor/@better-auth-kysely-adapter/LICENSE.md +20 -0
  163. package/vendor/@better-auth-kysely-adapter/README.md +17 -0
  164. package/vendor/@better-auth-kysely-adapter/dist/bun-sqlite-dialect-DoOVo4ja.mjs +123 -0
  165. package/vendor/@better-auth-kysely-adapter/dist/d1-sqlite-dialect-Cru74LbR.mjs +133 -0
  166. package/vendor/@better-auth-kysely-adapter/dist/index.d.mts +116 -0
  167. package/vendor/@better-auth-kysely-adapter/dist/index.mjs +719 -0
  168. package/vendor/@better-auth-kysely-adapter/dist/node-sqlite-dialect.d.mts +27 -0
  169. package/vendor/@better-auth-kysely-adapter/dist/node-sqlite-dialect.mjs +123 -0
  170. package/vendor/@better-auth-kysely-adapter/dist/sqlite-introspector-DSCAP82F.mjs +90 -0
  171. package/vendor/@better-auth-kysely-adapter/package.json +52 -0
  172. package/vendor/connector-sdk/dist/browser-requirement.js +1 -1
  173. package/vendor/connector-sdk/dist/connector-types.d.ts +34 -1
  174. package/vendor/connector-sdk/dist/index.d.ts +3 -1
  175. package/vendor/connector-sdk/dist/index.js +4 -0
  176. package/vendor/connector-sdk/dist/redact.d.ts +10 -0
  177. package/vendor/connector-sdk/dist/redact.js +130 -0
  178. package/vendor/connector-sdk/dist/types.d.ts +2 -1
  179. package/vendor/connector-sdk/package.json +6 -1
  180. package/vendor/core/dist/agent-tooling.d.ts +8 -0
  181. package/vendor/core/dist/agent-tooling.js +9 -1
  182. package/vendor/core/dist/capabilities.d.ts +1 -1
  183. package/vendor/core/dist/capabilities.js +5 -0
  184. package/vendor/core/dist/connector-query-errors.d.ts +6 -0
  185. package/vendor/core/dist/connector-query-errors.js +4 -0
  186. package/vendor/core/dist/contracts/entity-reference.d.ts +3 -0
  187. package/vendor/core/dist/contracts/entity-reference.js +31 -0
  188. package/vendor/core/dist/contracts/tools/manage-automations.d.ts +3 -0
  189. package/vendor/core/dist/contracts/tools/manage-automations.js +4 -1
  190. package/vendor/core/dist/contracts/tools/manage-connections.js +1 -1
  191. package/vendor/core/dist/contracts/tools/manage-entity-schema.js +2 -2
  192. package/vendor/core/dist/contracts/tools/manage-entity.d.ts +117 -34
  193. package/vendor/core/dist/contracts/tools/manage-entity.js +47 -14
  194. package/vendor/core/dist/contracts/tools/manage-operations.d.ts +13 -4
  195. package/vendor/core/dist/contracts/tools/manage-operations.js +19 -7
  196. package/vendor/core/dist/contracts/tools/read-knowledge.d.ts +6 -1
  197. package/vendor/core/dist/contracts/tools/read-knowledge.js +20 -1
  198. package/vendor/core/dist/contracts/tools/view-attach.d.ts +1 -1
  199. package/vendor/core/dist/contracts/tools/view-runtime.d.ts +2 -0
  200. package/vendor/core/dist/contracts/tools/view-runtime.js +3 -1
  201. package/vendor/core/dist/contracts/worker/device-automation.d.ts +4 -9
  202. package/vendor/core/dist/contracts/worker/device-automation.js +10 -15
  203. package/vendor/core/dist/contracts/worker/protocol.d.ts +20 -0
  204. package/vendor/core/dist/contracts/worker/protocol.js +20 -0
  205. package/vendor/core/dist/errors.d.ts +0 -20
  206. package/vendor/core/dist/errors.js +1 -25
  207. package/vendor/core/dist/otel.js +38 -10
  208. package/vendor/core/dist/reserved.d.ts +6 -3
  209. package/vendor/core/dist/reserved.js +6 -3
  210. package/vendor/core/dist/utils/ajv.js +3 -1
  211. package/vendor/core/dist/worker/auth.d.ts +3 -2
  212. package/vendor/core/package.json +31 -5
  213. package/vendor/postgres/.bun-tag-22d644c2873790db +0 -0
  214. package/vendor/postgres/cf/src/query.js +3 -1
  215. package/vendor/postgres/cjs/src/query.js +3 -1
  216. package/vendor/postgres/src/query.js +3 -1
  217. package/vendor/views/dist/api.js +31 -7
  218. package/vendor/views/dist/bridge.d.ts +2 -1
  219. package/vendor/views/dist/bridge.js +10 -1
  220. package/vendor/views/package.json +1 -1
  221. package/dist/owletto/dist/assets/_-BorucF19.js +0 -3
  222. package/dist/owletto/dist/assets/_-CkGyNi0G.js +0 -2
  223. package/dist/owletto/dist/assets/_agentId-BrhcaxUk.js +0 -2
  224. package/dist/owletto/dist/assets/_agentId-DgRrCE2B.js +0 -2
  225. package/dist/owletto/dist/assets/_automationId-DSrZIYcs.js +0 -2
  226. package/dist/owletto/dist/assets/_connectorKey._connectionId-DWxv1uoi.js +0 -2
  227. package/dist/owletto/dist/assets/_connectorKey.index-BTP5ijdT.js +0 -2
  228. package/dist/owletto/dist/assets/_conversationId-98Y3RuRO.js +0 -2
  229. package/dist/owletto/dist/assets/_deploymentId-B1UWPY0i.js +0 -2
  230. package/dist/owletto/dist/assets/_eventId-BAnr8g8z.js +0 -2
  231. package/dist/owletto/dist/assets/_name-BUfFO_A0.js +0 -2
  232. package/dist/owletto/dist/assets/_owner-C79BwQ0I.js +0 -3
  233. package/dist/owletto/dist/assets/_shape-Ep6JpyFX.js +0 -2
  234. package/dist/owletto/dist/assets/_skillKey-B24alBfT.js +0 -2
  235. package/dist/owletto/dist/assets/_slug-DbPdDc-5.js +0 -2
  236. package/dist/owletto/dist/assets/_viewKey-DDUxjjFD.js +0 -2
  237. package/dist/owletto/dist/assets/_viewKey-hdpq3RoX.js +0 -2
  238. package/dist/owletto/dist/assets/accept-invitation-UXU5Fx2G.js +0 -2
  239. package/dist/owletto/dist/assets/activity-route-view-D7ORHntE.js +0 -2
  240. package/dist/owletto/dist/assets/agent-card-controls-CplnPhbv.js +0 -2
  241. package/dist/owletto/dist/assets/agent-connect-pages-BmknviTI.js +0 -2
  242. package/dist/owletto/dist/assets/agent-guardrails-route-TdvvIc_J.js +0 -2
  243. package/dist/owletto/dist/assets/agent-permissions-matrix-BkZu1LYE.js +0 -2
  244. package/dist/owletto/dist/assets/agent-skills-route-B3vvvZZe.js +0 -2
  245. package/dist/owletto/dist/assets/agent-subpage-shell-CZJvnjNC.js +0 -2
  246. package/dist/owletto/dist/assets/agents-DAOln24A.js +0 -2
  247. package/dist/owletto/dist/assets/agents-workbench-DJ67GZ93.js +0 -2
  248. package/dist/owletto/dist/assets/app-bridge-BCm4muqj.js +0 -128
  249. package/dist/owletto/dist/assets/app._appId-Cp78oEZ9.js +0 -2
  250. package/dist/owletto/dist/assets/automation-detail-content-DSwbRpbx.js +0 -2
  251. package/dist/owletto/dist/assets/automations-DAOln24A.js +0 -2
  252. package/dist/owletto/dist/assets/callback-CBexCo3F.js +0 -2
  253. package/dist/owletto/dist/assets/client-rows-BYbsXGy9.js +0 -2
  254. package/dist/owletto/dist/assets/clients-BhNl1tVq.js +0 -2
  255. package/dist/owletto/dist/assets/connect-wx-qqLir.js +0 -2
  256. package/dist/owletto/dist/assets/connect._clientId-kk0_4Svo.js +0 -2
  257. package/dist/owletto/dist/assets/connected._clientId-QR8o-7M5.js +0 -2
  258. package/dist/owletto/dist/assets/connected._clientId.activity-BqprYeOX.js +0 -2
  259. package/dist/owletto/dist/assets/connected._clientId.index-DhRoSzBr.js +0 -2
  260. package/dist/owletto/dist/assets/connection-CNm2ukrI.js +0 -2
  261. package/dist/owletto/dist/assets/connection-feed-detail-WcGCA6qY.js +0 -2
  262. package/dist/owletto/dist/assets/connections-browser-CrtnAs0Q.js +0 -2
  263. package/dist/owletto/dist/assets/connector-scope-lists-CRFEpSvk.js +0 -2
  264. package/dist/owletto/dist/assets/conversations-table-D_HOe1jN.js +0 -2
  265. package/dist/owletto/dist/assets/create-C4lptGWj.js +0 -2
  266. package/dist/owletto/dist/assets/create-CCjZxIkK.js +0 -2
  267. package/dist/owletto/dist/assets/create-DkgUQAbB.js +0 -2
  268. package/dist/owletto/dist/assets/create-automation-form-Bpy92SM5.js +0 -3
  269. package/dist/owletto/dist/assets/create._connectorKey-D6Kc-YQ3.js +0 -2
  270. package/dist/owletto/dist/assets/deployments-C5hvipQh.js +0 -2
  271. package/dist/owletto/dist/assets/deployments-CPpFAd_w.js +0 -2
  272. package/dist/owletto/dist/assets/deployments-body-DGII20dQ.js +0 -2
  273. package/dist/owletto/dist/assets/device._deviceId-Bn37UpWH.js +0 -2
  274. package/dist/owletto/dist/assets/entity-options-Clz_WXK-.js +0 -2
  275. package/dist/owletto/dist/assets/entity-page-D3e4iPle.js +0 -2
  276. package/dist/owletto/dist/assets/entity-type-page-DebN1vCM.js +0 -2
  277. package/dist/owletto/dist/assets/event-detail-DV_zfWnC.js +0 -2
  278. package/dist/owletto/dist/assets/events-feed-DO3IiJO2.js +0 -2
  279. package/dist/owletto/dist/assets/filter-editors-Bwhqj7lY.js +0 -2
  280. package/dist/owletto/dist/assets/guardrails-BiJollCA.js +0 -2
  281. package/dist/owletto/dist/assets/identity-HCFWtdaI.js +0 -2
  282. package/dist/owletto/dist/assets/index-8wxsyxqt.js +0 -2
  283. package/dist/owletto/dist/assets/index-9YuSRymd.js +0 -7950
  284. package/dist/owletto/dist/assets/index-B3c-0eZG.js +0 -2
  285. package/dist/owletto/dist/assets/index-B64PGxQm.js +0 -2
  286. package/dist/owletto/dist/assets/index-BSH07yVD.css +0 -1
  287. package/dist/owletto/dist/assets/index-BX0EA_oB.js +0 -2
  288. package/dist/owletto/dist/assets/index-CDz3-ieP.js +0 -12
  289. package/dist/owletto/dist/assets/index-CdJJaQDX.js +0 -2
  290. package/dist/owletto/dist/assets/index-CfT_W8Vo.js +0 -2
  291. package/dist/owletto/dist/assets/index-D3WHeGql.js +0 -2
  292. package/dist/owletto/dist/assets/index-DB1iWI_a.js +0 -2
  293. package/dist/owletto/dist/assets/index-DMNzF8Lf.js +0 -2
  294. package/dist/owletto/dist/assets/index-DyB3IzOA.js +0 -2
  295. package/dist/owletto/dist/assets/index-Vcq4gwWv.js +0 -2
  296. package/dist/owletto/dist/assets/index-fgAJydgX.js +0 -2
  297. package/dist/owletto/dist/assets/json-diff-DIN5Jhfx.js +0 -4
  298. package/dist/owletto/dist/assets/login-DxGYyE4n.js +0 -2
  299. package/dist/owletto/dist/assets/logout-Bkzc7J44.js +0 -2
  300. package/dist/owletto/dist/assets/memory-browse-page-BnuhLJ6X.css +0 -1
  301. package/dist/owletto/dist/assets/memory-browse-page-D_UlBa27.js +0 -103
  302. package/dist/owletto/dist/assets/models-BAVeysNq.js +0 -2
  303. package/dist/owletto/dist/assets/new-C2av0diq.js +0 -2
  304. package/dist/owletto/dist/assets/new-snm1ctHn.js +0 -2
  305. package/dist/owletto/dist/assets/organization-Cb0W823y.js +0 -2
  306. package/dist/owletto/dist/assets/peek-pane-content-BNR9ImQY.js +0 -2
  307. package/dist/owletto/dist/assets/permissions-Dv39zWKt.js +0 -2
  308. package/dist/owletto/dist/assets/proposal-review-shell-CFhOqCLf.js +0 -2
  309. package/dist/owletto/dist/assets/public-shell-ready-DqX8AXfw.js +0 -2
  310. package/dist/owletto/dist/assets/recent-QhnLDU1_.js +0 -2
  311. package/dist/owletto/dist/assets/record-activity-ZJntBfN_.js +0 -2
  312. package/dist/owletto/dist/assets/record-field-peek-Brh1IQGy.js +0 -2
  313. package/dist/owletto/dist/assets/reset-password-CzZw6RcC.js +0 -2
  314. package/dist/owletto/dist/assets/runs-panel-C0_DNTcq.js +0 -2
  315. package/dist/owletto/dist/assets/runs-table-B1APZv7d.js +0 -2
  316. package/dist/owletto/dist/assets/schema-value-normalization-CKdPjdPC.js +0 -97
  317. package/dist/owletto/dist/assets/settings-CgZ5Z7wD.js +0 -2
  318. package/dist/owletto/dist/assets/settings-VDNiffKU.js +0 -2
  319. package/dist/owletto/dist/assets/skills-DgDGscm5.js +0 -2
  320. package/dist/owletto/dist/assets/source-record-panels-BdfOVPWn.js +0 -2
  321. package/dist/owletto/dist/assets/view-param-filters-B0quibBi.js +0 -2
  322. /package/vendor/{postgres/.bun-tag-2f292c6554a8475e → @better-auth-kysely-adapter/.bun-tag-abf95749a412716} +0 -0
@@ -1647,7 +1647,7 @@
1647
1647
  {
1648
1648
  "id": "google.gmail",
1649
1649
  "name": "Gmail",
1650
- "version": "1.0.7",
1650
+ "version": "1.1.0",
1651
1651
  "description": "Syncs Gmail threads, live-reads matching messages, and supports sending, drafts, and replies.",
1652
1652
  "detail": {
1653
1653
  "source_path": "google_gmail.ts",
@@ -1686,6 +1686,84 @@
1686
1686
  "browser": null,
1687
1687
  "webhook": null,
1688
1688
  "feeds_schema": {
1689
+ "message_references": {
1690
+ "key": "message_references",
1691
+ "name": "Message references",
1692
+ "userManaged": true,
1693
+ "requiredScopes": [
1694
+ "https://www.googleapis.com/auth/gmail.readonly"
1695
+ ],
1696
+ "description": "ID-only references to available messages and subsequent additions, including spam, trash, imports and drafts. No subjects, senders, snippets, bodies or provider occurrence dates. Use created_at for arrival previews; source_occurred_at is unknown. History expiry is a visible gap; recovery lists currently available messages. Sync-only, explicitly triggered or scheduled. Not a current-state mirror, edit/deletion archive or observer subscription.",
1697
+ "configSchema": {
1698
+ "type": "object",
1699
+ "properties": {
1700
+ "max_results": {
1701
+ "type": "integer",
1702
+ "minimum": 1,
1703
+ "maximum": 500,
1704
+ "default": 500,
1705
+ "description": "Maximum message references per pass, without individual message downloads. Unfinished inventory/history resumes immediately from its committed checkpoint, even without a schedule."
1706
+ }
1707
+ }
1708
+ },
1709
+ "eventKinds": {
1710
+ "message_reference": {
1711
+ "description": "An available Gmail message reference, without email content",
1712
+ "metadataSchema": {
1713
+ "type": "object",
1714
+ "properties": {
1715
+ "source_id": {
1716
+ "type": "string"
1717
+ },
1718
+ "thread_id": {
1719
+ "type": "string"
1720
+ },
1721
+ "source_occurred_at": {
1722
+ "type": "null"
1723
+ },
1724
+ "timestamp_basis": {
1725
+ "type": "string",
1726
+ "enum": [
1727
+ "unknown"
1728
+ ]
1729
+ }
1730
+ }
1731
+ }
1732
+ },
1733
+ "source_gap": {
1734
+ "description": "A retained Gmail history discontinuity; available inventory cannot restore deleted or expired history",
1735
+ "metadataSchema": {
1736
+ "type": "object",
1737
+ "properties": {
1738
+ "reason": {
1739
+ "type": "string"
1740
+ },
1741
+ "from_history_id": {
1742
+ "type": "string"
1743
+ },
1744
+ "to_history_id": {
1745
+ "type": "string"
1746
+ },
1747
+ "recovery": {
1748
+ "type": "string"
1749
+ },
1750
+ "source_occurred_at": {
1751
+ "type": "null"
1752
+ },
1753
+ "timestamp_basis": {
1754
+ "type": "string",
1755
+ "enum": [
1756
+ "unknown"
1757
+ ]
1758
+ }
1759
+ }
1760
+ }
1761
+ }
1762
+ },
1763
+ "operations": [
1764
+ "sync"
1765
+ ]
1766
+ },
1689
1767
  "threads": {
1690
1768
  "key": "threads",
1691
1769
  "name": "Threads",
@@ -1797,34 +1875,6 @@
1797
1875
  "mergeStrategy": "overwrite"
1798
1876
  }
1799
1877
  }
1800
- },
1801
- {
1802
- "role": "authored_by",
1803
- "autoCreate": true,
1804
- "target": {
1805
- "entityType": "person",
1806
- "createWhen": {
1807
- "path": "metadata.replied",
1808
- "equals": true
1809
- },
1810
- "titlePath": "metadata.from_name",
1811
- "identities": [
1812
- {
1813
- "namespace": "email",
1814
- "eventPath": "metadata.from_email"
1815
- }
1816
- ]
1817
- },
1818
- "traits": {
1819
- "from_name": {
1820
- "eventPath": "metadata.from_name",
1821
- "mergeStrategy": "prefer_non_empty"
1822
- },
1823
- "last_email_at": {
1824
- "eventPath": "occurred_at",
1825
- "mergeStrategy": "overwrite"
1826
- }
1827
- }
1828
1878
  }
1829
1879
  ]
1830
1880
  }
@@ -11139,7 +11189,7 @@
11139
11189
  {
11140
11190
  "id": "gchat",
11141
11191
  "name": "Google Chat",
11142
- "version": "1.0.2",
11192
+ "version": "1.0.3",
11143
11193
  "description": "Connect a Google Chat app to Lobu.",
11144
11194
  "detail": {
11145
11195
  "source_path": "gchat.ts",
@@ -11152,7 +11202,29 @@
11152
11202
  ]
11153
11203
  },
11154
11204
  "browser": null,
11155
- "webhook": null,
11205
+ "webhook": {
11206
+ "delivery": "app_installation",
11207
+ "deliveryKind": "chat",
11208
+ "verification": {
11209
+ "type": "google-jwt",
11210
+ "appIdKey": "GOOGLE_CHAT_PROJECT_NUMBER",
11211
+ "audiences": [
11212
+ "app_id",
11213
+ "endpoint_url"
11214
+ ],
11215
+ "signers": [
11216
+ "chat@system.gserviceaccount.com",
11217
+ "service-{appId}@gcp-sa-gsuiteaddons.iam.gserviceaccount.com"
11218
+ ]
11219
+ },
11220
+ "routingKeyPaths": [
11221
+ "space.name",
11222
+ "chat.messagePayload.space.name",
11223
+ "chat.addedToSpacePayload.space.name",
11224
+ "chat.removedFromSpacePayload.space.name",
11225
+ "chat.appCommandPayload.space.name"
11226
+ ]
11227
+ },
11156
11228
  "feeds_schema": null,
11157
11229
  "actions_schema": null,
11158
11230
  "automation_events": [
@@ -18840,7 +18912,7 @@
18840
18912
  {
18841
18913
  "id": "linkedin",
18842
18914
  "name": "LinkedIn",
18843
- "version": "3.20.1",
18915
+ "version": "3.20.2",
18844
18916
  "description": "Read LinkedIn feeds, notifications, and recent inbox messages through paired Chrome. Subscribe to source changes, answer direct messages, and prepare message, post, or comment drafts for human submission. Also supports local LinkedIn Data Export CSV files.",
18845
18917
  "detail": {
18846
18918
  "source_path": "linkedin.ts",
@@ -20729,8 +20801,8 @@
20729
20801
  {
20730
20802
  "id": "reddit",
20731
20803
  "name": "Reddit",
20732
- "version": "1.2.1",
20733
- "description": "Fetches posts and comments from Reddit subreddits or search queries, and the connected user's home feed.",
20804
+ "version": "1.3.0",
20805
+ "description": "Fetches posts and comments from Reddit subreddits or search queries, the connected user's home feed, and inbox notification references.",
20734
20806
  "detail": {
20735
20807
  "source_path": "reddit.ts",
20736
20808
  "auth_schema": {
@@ -20743,6 +20815,9 @@
20743
20815
  "read",
20744
20816
  "history"
20745
20817
  ],
20818
+ "optionalScopes": [
20819
+ "privatemessages"
20820
+ ],
20746
20821
  "loginScopes": [
20747
20822
  "identity"
20748
20823
  ],
@@ -20756,6 +20831,42 @@
20756
20831
  "browser": null,
20757
20832
  "webhook": null,
20758
20833
  "feeds_schema": {
20834
+ "inbox": {
20835
+ "key": "inbox",
20836
+ "name": "Inbox notifications",
20837
+ "description": "Capture metadata-only references to the OAuth inbox (comment/post replies, mentions and legacy private messages exposed by Reddit). Read original bodies explicitly from the source. Does not mark messages read. Chat, reactions and the modern notification bell are not covered by this API.",
20838
+ "requiredScopes": [
20839
+ "privatemessages"
20840
+ ],
20841
+ "eventKinds": {
20842
+ "inbox_notification": {
20843
+ "description": "A source reference to an item in the Reddit OAuth inbox",
20844
+ "metadataSchema": {
20845
+ "type": "object",
20846
+ "properties": {
20847
+ "source_id": {
20848
+ "type": "string"
20849
+ },
20850
+ "source_kind": {
20851
+ "type": "string"
20852
+ },
20853
+ "category": {
20854
+ "type": "string"
20855
+ }
20856
+ },
20857
+ "required": [
20858
+ "source_id",
20859
+ "source_kind",
20860
+ "category"
20861
+ ]
20862
+ }
20863
+ }
20864
+ },
20865
+ "operations": [
20866
+ "sync",
20867
+ "read"
20868
+ ]
20869
+ },
20759
20870
  "posts": {
20760
20871
  "key": "posts",
20761
20872
  "name": "Posts",
@@ -21523,7 +21634,7 @@
21523
21634
  {
21524
21635
  "id": "whatsapp.web",
21525
21636
  "name": "WhatsApp",
21526
- "version": "2.2.0",
21637
+ "version": "2.3.0",
21527
21638
  "description": "Personal WhatsApp messages read live from WhatsApp Web in the paired Owletto Chrome without importing message history. Automations react to new-message references and read content on demand. Search, draft, send, edit, react to, and revoke messages.",
21528
21639
  "detail": {
21529
21640
  "source_path": "whatsapp_web.ts",
@@ -21541,7 +21652,7 @@
21541
21652
  ],
21542
21653
  "accountProbe": {
21543
21654
  "url": "https://web.whatsapp.com/",
21544
- "expression": "(async () => {\n (function whatsAppWebAdapterProgram() {\n const SYSTEM_TYPES = new Set([\n \"gp2\",\n \"notification_template\",\n \"e2e_notification\"\n ]);\n let readinessSignature = null, readinessStableSince = 0;\n const existing = globalThis.__owlettoWhatsAppAdapterV1;\n if (existing?.version === 26)\n return;\n existing?.detach?.();\n const listeners = new Map;\n function detach(bindingId) {\n const selected = bindingId ? [listeners.get(bindingId)] : [...listeners.values()];\n for (const state of selected) {\n if (!state)\n continue;\n state.collection.off(\"add\", state.onAdd);\n state.collection.off(\"change\", state.onChange);\n window.removeEventListener(\"message\", state.onReply);\n listeners.delete(state.id);\n }\n }\n function listen(request) {\n const collection = requireFirst([\"WAWebCollections\"])?.Msg;\n if (typeof collection?.on !== \"function\" || typeof collection?.off !== \"function\")\n throw Error(\"WhatsApp message observation is unavailable in this build\");\n if (!request.bridge_id || !request.token)\n throw Error(\"A feed bridge is required\");\n const post = (state2, entry) => window.postMessage({\n type: \"lobu-feed-record\",\n token: state2.token,\n sequence: entry.sequence,\n record: entry.record\n }, location.origin), reportError = (state2, message, sequence = ++state2.sequence) => {\n state2.error = message;\n post(state2, {\n sequence,\n record: {\n id: \"whatsapp-web:source-observation-error\",\n source_error: message\n }\n });\n }, resident = listeners.get(request.bridge_id), previous = resident?.request.chat_filter === request.chat_filter && resident?.request.minimum_timestamp === request.minimum_timestamp ? resident : null;\n detach(request.bridge_id);\n const state = {\n ...previous ?? {\n id: request.bridge_id,\n collection,\n sequence: 0,\n pending: new Map,\n fingerprints: new Map,\n pendingBytes: 0,\n fingerprintBytes: 0,\n error: null\n },\n collection,\n error: null\n };\n state.token = request.token;\n state.request = request;\n state.post = (entry) => post(state, entry);\n const observe = (model) => {\n if (state.error)\n return;\n const sequence = ++state.sequence;\n new Promise((resolve) => resolve(messageReference(model))).then((record) => {\n if (listeners.get(state.id) !== state || !record || record.timestamp <= 0)\n return;\n if (state.request.chat_filter === \"group\" && !record.is_group)\n return;\n if (state.request.chat_filter === \"individual\" && record.is_group)\n return;\n if (state.request.minimum_timestamp != null && record.timestamp < state.request.minimum_timestamp)\n return;\n record = {\n id: record.id,\n events: [{\n id: record.id,\n event_type: \"message.created\",\n resource_ref: record.id,\n resource_type: \"message\",\n occurred_at: new Date(record.timestamp * 1000).toISOString()\n }]\n };\n const previous2 = state.pending.get(record.id), seen = state.fingerprints.get(record.id);\n if (seen && seen.sequence >= sequence)\n return;\n const fingerprint = JSON.stringify(record);\n if (seen?.fingerprint === fingerprint) {\n seen.sequence = sequence;\n return;\n }\n const bytes = new TextEncoder().encode(fingerprint).length;\n if (bytes > 131072 || state.pendingBytes - (previous2?.bytes ?? 0) + bytes > 16777216 || state.pending.size >= 1e4 && !previous2) {\n reportError(state, \"WhatsApp page observation buffer overflowed; recovery is required\", sequence);\n return;\n }\n const entry = { sequence, record, bytes };\n state.pendingBytes += bytes - (previous2?.bytes ?? 0);\n state.pending.set(record.id, entry);\n state.fingerprintBytes += bytes - (seen?.bytes ?? 0);\n state.fingerprints.delete(record.id);\n state.fingerprints.set(record.id, { fingerprint, sequence, bytes });\n while (state.fingerprints.size > 1e4 || state.fingerprintBytes > 16777216) {\n const oldest = state.fingerprints.keys().next().value;\n state.fingerprintBytes -= state.fingerprints.get(oldest).bytes;\n state.fingerprints.delete(oldest);\n }\n post(state, entry);\n }).catch(() => {\n if (listeners.get(state.id) !== state)\n return;\n reportError(state, \"WhatsApp source observation failed; recovery is required\", sequence);\n });\n };\n state.onAdd = (model) => observe(model);\n state.onChange = (model) => observe(model);\n state.onReply = (event) => {\n if (event.source !== window || event.origin !== location.origin || event.data?.token !== state.token)\n return;\n if (event.data.type === \"lobu-feed-record:stop\") {\n detach(state.id);\n return;\n }\n if (event.data.type !== \"lobu-feed-record:ack\")\n return;\n for (const [id, entry] of state.pending) {\n if (entry.sequence !== event.data.sequence)\n continue;\n if (event.data.ok) {\n state.pendingBytes -= entry.bytes;\n state.pending.delete(id);\n entry.resolve?.();\n } else\n entry.reject?.(Error(\"Browser rejected the source reference batch\"));\n break;\n }\n };\n listeners.set(state.id, state);\n try {\n collection.on(\"add\", state.onAdd);\n collection.on(\"change\", state.onChange);\n window.addEventListener(\"message\", state.onReply);\n } catch (error) {\n reportError(state, \"WhatsApp source observation failed; recovery is required\");\n throw error;\n }\n if (previous?.error)\n post(state, {\n sequence: ++state.sequence,\n record: { id: \"whatsapp-web:source-observation-error\", source_error: previous.error }\n });\n for (const entry of state.pending.values())\n post(state, entry);\n return { ok: !0, listening: !0 };\n }\n async function publishChanges(request) {\n const state = listeners.get(request.bridge_id);\n if (!state || state.token !== request.token)\n throw Error(\"Source listener is unavailable\");\n const record = request.batch, bytes = new TextEncoder().encode(JSON.stringify(record)).length, previous = state.pending.get(record.id);\n if (bytes > 131072 || state.pendingBytes - (previous?.bytes ?? 0) + bytes > 16777216 || state.pending.size >= 1e4 && !previous)\n throw Error(\"Source replay buffer is full\");\n await new Promise((resolve, reject) => {\n const timer = setTimeout(() => reject(Error(\"Source replay was not accepted by the browser\")), 1e4), entry = {\n record,\n bytes,\n sequence: ++state.sequence,\n resolve: () => {\n clearTimeout(timer);\n resolve();\n },\n reject: (error) => {\n clearTimeout(timer);\n reject(error);\n }\n };\n state.pendingBytes += bytes - (previous?.bytes ?? 0);\n state.pending.set(record.id, entry);\n state.post(entry);\n });\n return { ok: !0 };\n }\n function requireFirst(names) {\n for (const name of names)\n try {\n const module2 = window.require?.(name);\n if (module2)\n return module2;\n } catch {}\n return null;\n }\n function meUser() {\n const module2 = requireFirst([\n \"WAWebUserPrefsMeUser\",\n \"WAWebUserPrefsMe\",\n \"WAWebUserPrefs\"\n ]);\n if (!module2)\n return null;\n for (const accessor of [\n \"getMaybeMePnUser\",\n \"getMaybeMeUser\",\n \"getMeUser\",\n \"getMeUserOrThrow\",\n \"getMaybeMeLidUser\"\n ])\n try {\n const value = module2[accessor]?.();\n if (value)\n return value;\n } catch {}\n try {\n return module2.me ?? null;\n } catch {}\n return null;\n }\n async function ownJids() {\n const module2 = requireFirst([\"WAWebUserPrefsMeUser\"]), candidates = [meUser()];\n for (const accessor of [\"getMaybeMePnUser\", \"getMaybeMeLidUser\"])\n try {\n candidates.push(module2?.[accessor]?.());\n } catch {}\n const forms = new Set;\n for (const value of candidates) {\n const own = await canonicalJid(value);\n if (own.jid)\n forms.add(own.jid);\n if (own.lid)\n forms.add(own.lid);\n }\n return forms;\n }\n async function mentionsOwnAccount(row) {\n const addressed = [\n ...Array.isArray(row.mentionedJidList) ? row.mentionedJidList : [],\n row.quotedParticipant\n ].filter(Boolean);\n if (addressed.length === 0)\n return !1;\n const own = await ownJids();\n for (const value of addressed) {\n const candidate = await canonicalJid(value);\n if (own.has(candidate.jid) || candidate.lid && own.has(candidate.lid))\n return !0;\n }\n return !1;\n }\n const SEND_MODULES = [\n \"WAWebSendTextMsgChatAction\",\n \"WAWebSendMsgChatAction\",\n \"WAWebSendMessage\"\n ], REACTION_MODULES = [\n \"WAWebSendReactionMsgAction\",\n \"WAWebSendReactionMsg\",\n \"WAWebReactionAction\"\n ], REVOKE_MODULES = [\n \"WAWebChatSendMessages\",\n \"WAWebRevokeMsgAction\",\n \"WAWebDeleteChatAction\",\n \"WAWebRevokeMessage\"\n ], EDIT_MODULES = [\"WAWebSendMessageEditAction\", \"WAWebEditMessage\"], DRAFT_MODULES = [\n \"WAWebChatDraftUtils\",\n \"WAWebSetDraft\",\n \"WAWebComposeBoxActions\"\n ];\n function modelData(model) {\n return model?.attributes ?? model?._data ?? model ?? {};\n }\n function messageReference(model) {\n const row = modelData(model), key = row.id ?? model?.id, id = rawId(key), remote = widString(key?.remote ?? row.chatId ?? (key?.fromMe ? row.to : row.from));\n if (!id || !remote || remote === \"status@broadcast\" || remote.endsWith(\"@newsletter\") || SYSTEM_TYPES.has(row.type))\n return null;\n return { id, timestamp: unixSeconds(row), is_group: remote.endsWith(\"@g.us\") };\n }\n async function observeMessages(input = {}) {\n const after = input.after ?? null;\n if (after !== null && (!Number.isSafeInteger(after) || after < 0))\n throw Error(\"Invalid WhatsApp observation cursor\");\n const database = await new Promise((resolve, reject) => {\n const request = indexedDB.open(\"model-storage\");\n request.onupgradeneeded = () => {\n request.transaction.abort();\n reject(Error(\"WhatsApp source history database is unavailable\"));\n };\n request.onerror = () => reject(request.error);\n request.onblocked = () => reject(Error(\"WhatsApp source history database is blocked\"));\n request.onsuccess = () => resolve(request.result);\n });\n let rows;\n try {\n rows = await new Promise((resolve, reject) => {\n const transaction = database.transaction(\"message\", \"readonly\");\n transaction.onabort = () => reject(transaction.error ?? Error(\"WhatsApp source observation aborted\"));\n const request = transaction.objectStore(\"message\").index(\"rowId\").openCursor(after === null ? null : IDBKeyRange.lowerBound(after, !0), after === null ? \"prev\" : \"next\"), page2 = [];\n request.onerror = () => reject(request.error);\n request.onsuccess = () => {\n const cursor = request.result;\n if (!cursor) {\n resolve(page2);\n return;\n }\n if (!Number.isSafeInteger(cursor.key) || cursor.key <= 0 || typeof cursor.value.id !== \"string\") {\n reject(Error(\"WhatsApp source history has an unsupported key layout\"));\n return;\n }\n page2.push({ position: cursor.key, id: cursor.value.id, timestamp: unixSeconds(cursor.value), type: cursor.value.type });\n if (after === null || page2.length > 500)\n resolve(page2);\n else\n cursor.continue();\n };\n });\n } finally {\n database.close();\n }\n if (after === null)\n return { after: rows[0]?.position ?? 0, references: [], hasMore: !1 };\n const page = rows.slice(0, 500), references = [];\n if (page.length) {\n const keys = requireFirst([\"WAWebMsgKey\"]);\n if (typeof keys?.fromString !== \"function\")\n throw Error(\"WhatsApp source message keys are unavailable\");\n for (const row of page) {\n const reference = messageReference({ id: keys.fromString(row.id), t: row.timestamp, type: row.type });\n if (!reference)\n continue;\n if (reference.timestamp <= 0)\n continue;\n if (reference.timestamp < input.started_at)\n continue;\n if (input.chat_filter === \"group\" && !reference.is_group)\n continue;\n if (input.chat_filter === \"individual\" && reference.is_group)\n continue;\n references.push(reference);\n }\n }\n return { after: page[page.length - 1]?.position ?? after, references, hasMore: rows.length > 500 };\n }\n function models(collection) {\n if (Array.isArray(collection?._models))\n return collection._models;\n if (Array.isArray(collection?.models))\n return collection.models;\n if (typeof collection?.toArray === \"function\")\n try {\n return collection.toArray();\n } catch {}\n return [];\n }\n function widString(value) {\n if (typeof value === \"string\")\n return value;\n if (!value)\n return null;\n if (typeof value._serialized === \"string\")\n return value._serialized;\n try {\n const rendered = value.toString?.();\n return rendered && rendered !== \"[object Object]\" ? String(rendered) : null;\n } catch {\n return null;\n }\n }\n function rawId(value) {\n if (typeof value === \"string\")\n return value && !/^(?:true|false)_/i.test(value) ? value : null;\n if (typeof value?.id === \"string\")\n return value.id && !/^(?:true|false)_/i.test(value.id) ? value.id : null;\n return null;\n }\n function unixSeconds(row) {\n const value = Number(row?.t ?? row?.timestamp ?? row?.ephemeralStartTimestamp ?? 0);\n return Number.isFinite(value) && value > 0 ? Math.floor(value) : 0;\n }\n async function canonicalJid(value) {\n const original = widString(value);\n if (!original)\n return { jid: null, lid: null };\n let jid = original.toLowerCase();\n if (jid.endsWith(\"@c.us\"))\n jid = `${jid.slice(0, -5)}@s.whatsapp.net`;\n if (!jid.endsWith(\"@lid\"))\n return { jid, lid: null };\n const migration = requireFirst([\n \"WAWebLidMigrationUtils\",\n \"WAWebLidMigration\"\n ]), toPn = migration?.toPn ?? migration?.getPnForLid ?? migration?.lidToPhone;\n if (typeof toPn === \"function\")\n try {\n const converted = await toPn.call(migration, value), phoneJid = widString(converted);\n if (phoneJid)\n return {\n jid: phoneJid.endsWith(\"@c.us\") ? `${phoneJid.slice(0, -5)}@s.whatsapp.net` : phoneJid,\n lid: jid\n };\n } catch {}\n return { jid, lid: jid };\n }\n function collectionByRawId(collection, id) {\n if (!id)\n return null;\n for (const model of models(collection)) {\n const row = modelData(model);\n if (rawId(row.id ?? model?.id) === id)\n return model;\n }\n return null;\n }\n function reactionTargetId(row) {\n return rawId(row.reactionParentKey) ?? rawId(row.parentMsgKey) ?? rawId(row.parentMessageKey) ?? (typeof row.quotedStanzaID === \"string\" ? row.quotedStanzaID : null);\n }\n function normalizeReactions(row) {\n const source = row.reactions ?? row.reactionCollection ?? row.reactionsBySender;\n return (Array.isArray(source) ? source : models(source)).map((reaction) => {\n const data = modelData(reaction);\n return {\n emoji: data.text ?? data.reactionText ?? data.emoji ?? null,\n sender_jid: widString(data.senderUserJid ?? data.sender ?? data.author),\n from_me: Boolean(data.fromMe)\n };\n }).filter((reaction) => typeof reaction.emoji === \"string\" && reaction.emoji.length > 0);\n }\n function nameIndex(collections) {\n const byId = (collection) => {\n const map = new Map;\n for (const model of models(collection)) {\n const id = widString(modelData(model).id ?? model?.id);\n if (id && !map.has(id))\n map.set(id, model);\n }\n return map;\n };\n return { chats: byId(collections?.Chat), contacts: byId(collections?.Contact) };\n }\n function contactName(names, jid) {\n if (!jid)\n return null;\n const contact = names?.contacts?.get(jid);\n if (!contact)\n return null;\n const row = modelData(contact);\n return row.name ?? row.pushname ?? row.shortName ?? row.formattedName ?? null;\n }\n function chatName(names, jid) {\n if (!jid)\n return null;\n const chat = names?.chats?.get(jid);\n if (!chat)\n return null;\n const row = modelData(chat);\n return row.name ?? row.formattedTitle ?? row.contact?.name ?? row.contact?.pushname ?? null;\n }\n async function normalizeMessage(model, eventType = \"snapshot\", collectionsOverride = null, names = null) {\n const collections = collectionsOverride ?? requireFirst([\"WAWebCollections\"]);\n if (!collections)\n return null;\n const nameLookup = names ?? nameIndex(collections);\n let row = modelData(model), key = row.id ?? model?.id, id = rawId(key);\n if (!id)\n return null;\n if (row.type === \"reaction\") {\n const targetId = reactionTargetId(row), target = collectionByRawId(collections.Msg, targetId);\n if (target) {\n model = target;\n row = modelData(model);\n key = row.id ?? model?.id;\n id = rawId(key);\n }\n }\n const fromMe = Boolean(key?.fromMe ?? row.fromMe), remoteRaw = key?.remote ?? row.chatId, fromRaw = row.from, toRaw = row.to, authorRaw = row.author ?? key?.participant, chatRaw = remoteRaw ?? (fromMe ? toRaw : fromRaw), chat = await canonicalJid(chatRaw);\n if (!chat.jid || chat.jid === \"status@broadcast\" || chat.jid.endsWith(\"@newsletter\"))\n return null;\n const senderRaw = fromMe ? fromRaw : authorRaw ?? fromRaw, sender = await canonicalJid(senderRaw), participant = await canonicalJid(key?.participant ?? row.participant ?? (fromMe ? toRaw : null)), timestamp = unixSeconds(row), body = typeof row.body === \"string\" ? row.body : \"\", caption = typeof row.caption === \"string\" ? row.caption : \"\", quotedId = typeof row.quotedStanzaID === \"string\" ? row.quotedStanzaID : rawId(row.quotedMsg?.id ?? row.quotedMsgKey), type = typeof row.type === \"string\" ? row.type : \"unknown\";\n return {\n id,\n chat_jid: chat.jid,\n chat_lid: chat.lid,\n chat_name: chatName(nameLookup, widString(chatRaw)),\n sender_jid: sender.jid,\n sender_lid: sender.lid,\n push_name: contactName(nameLookup, widString(senderRaw)) ?? row.notifyName ?? null,\n participant: participant.jid,\n from_me: fromMe,\n is_group: chat.jid.endsWith(\"@g.us\"),\n timestamp,\n occurred_at: timestamp > 0 ? new Date(timestamp * 1000).toISOString() : null,\n body,\n caption,\n message_type: type,\n media_kind: type === \"ptt\" ? \"audio\" : [\"image\", \"video\", \"audio\", \"document\", \"sticker\"].includes(type) ? type : null,\n media_type: typeof row.mimetype === \"string\" ? row.mimetype : null,\n media_size: Number.isFinite(Number(row.size ?? row.fileSize)) ? Number(row.size ?? row.fileSize) : null,\n media_filename: row.filename ?? row.fileName ?? row.title ?? null,\n quoted_id: quotedId,\n mentions_me: await mentionsOwnAccount(row),\n is_forwarded: Boolean(row.isForwarded || Number(row.forwardingScore) > 0),\n is_starred: Boolean(row.star ?? row.isStarred),\n is_system_event: SYSTEM_TYPES.has(type),\n edited: Boolean(row.isEdited || row.editVersion || row.latestEditMsgKey),\n edit_timestamp: Number(row.editTimestamp ?? row.lastEditTimestamp) || null,\n revoked: Boolean(row.isRevoked || row.revoked || type === \"revoked\"),\n reactions: normalizeReactions(row),\n event_type: eventType\n };\n }\n function readiness() {\n if (typeof window.require !== \"function\")\n return {\n ready: !1,\n state: \"hydrating\",\n reason: \"whatsapp_runtime_unavailable\"\n };\n const collections = requireFirst([\"WAWebCollections\"]);\n if (!collections?.Msg || !collections?.Chat)\n return {\n ready: !1,\n state: \"hydrating\",\n reason: \"collections_unavailable\"\n };\n const me = meUser(), qrVisible = Boolean(document.querySelector('[data-testid=\"qrcode\"], canvas[aria-label*=\"Scan\" i], [data-ref] canvas'));\n if (!me && qrVisible)\n return { ready: !1, state: \"logged_out\", reason: \"qr_code_visible\" };\n if (!me)\n return {\n ready: !1,\n state: \"hydrating\",\n reason: \"authenticated_self_identity_unavailable\"\n };\n const socket = requireFirst([\"WAWebSocketModel\"])?.Socket, connection = socket ?? requireFirst([\"WAWebSocketState\", \"WAWebConn\", \"WAWebConnectionState\"]), connectionState = String(connection?.getSocketState?.() ?? connection?.state ?? connection?.socketState ?? \"\").toLowerCase();\n if (!connectionState)\n return {\n ready: !1,\n state: \"capability_unavailable\",\n reason: \"connection_state_unavailable\"\n };\n if (!/^(connected|open|ready|syncing)$/.test(connectionState))\n return {\n ready: !1,\n state: \"not_ready\",\n reason: `connection_${connectionState}`\n };\n if (socket) {\n const stream = String(socket.stream ?? \"\").toLowerCase();\n if (!stream)\n return {\n ready: !1,\n state: \"capability_unavailable\",\n reason: \"stream_state_unavailable\"\n };\n if (!/^(connected|open|ready)$/.test(stream))\n return { ready: !1, state: \"not_ready\", reason: `stream_${stream}` };\n if (socket.hasSynced === !1)\n return {\n ready: !1,\n state: \"hydrating\",\n reason: \"initial_sync_incomplete\"\n };\n }\n const offlineDelivery = requireFirst([\n \"WAWebOfflineDelivery\",\n \"WAWebOfflineDeliveryState\"\n ]);\n if ((offlineDelivery?.isOfflineDeliveryComplete?.() ?? offlineDelivery?.offlineDeliveryComplete ?? offlineDelivery?.isComplete) === !1)\n return {\n ready: !1,\n state: \"hydrating\",\n reason: \"offline_delivery_incomplete\"\n };\n const hydration = requireFirst([\n \"WAWebInitialSyncInfo\",\n \"WAWebHistorySync\",\n \"WAWebAppState\"\n ]);\n if ((hydration?.isInitialSyncComplete?.() ?? hydration?.initialSyncComplete ?? hydration?.isHydrated ?? !0) !== !0)\n return {\n ready: !1,\n state: \"hydrating\",\n reason: \"initial_sync_incomplete\"\n };\n if (!Array.isArray(collections.Chat._models) && !Array.isArray(collections.Chat.models))\n return {\n ready: !1,\n state: \"hydrating\",\n reason: \"chat_store_placeholder\"\n };\n const signature = `${widString(me)}:${models(collections.Chat).length}:${models(collections.Msg).length}`;\n if (signature !== readinessSignature) {\n readinessSignature = signature;\n readinessStableSince = Date.now();\n return { ready: !1, state: \"hydrating\", reason: \"stores_settling\" };\n }\n if (Date.now() - readinessStableSince < 500)\n return { ready: !1, state: \"hydrating\", reason: \"stores_settling\" };\n return {\n ready: !0,\n state: \"ready\",\n message_count: models(collections.Msg).length,\n chat_count: models(collections.Chat).length\n };\n }\n function operationCapabilities() {\n const search = requireFirst([\n \"WAWebChatMessageSearch\",\n \"WAWebMessageSearch\",\n \"WAWebSearchMessages\"\n ]), draft = requireFirst(DRAFT_MODULES), send = requireFirst(SEND_MODULES), edit = requireFirst(EDIT_MODULES), reaction = requireFirst(REACTION_MODULES), revoke = requireFirst(REVOKE_MODULES), hasFunction = (module2, names) => names.some((name) => typeof module2?.[name] === \"function\");\n return {\n read_messages: typeof indexedDB < \"u\" && typeof requireFirst([\"WAWebMsgKey\"])?.fromString === \"function\" && typeof requireFirst([\"WAWebCollections\"])?.Msg?.getMessagesById === \"function\",\n search_messages: hasFunction(search, [\"searchMessages\", \"searchMsgs\", \"search\"]) || Boolean(requireFirst([\"WAWebCollections\"])?.Msg),\n draft_message: hasFunction(draft, [\n \"setDraft\",\n \"setChatDraft\",\n \"saveDraft\"\n ]),\n send_message: hasFunction(send, [\n \"sendTextMsgToChat\",\n \"sendMessage\",\n \"addAndSendTextMsg\"\n ]),\n edit_message: hasFunction(edit, [\"sendMessageEdit\", \"editMessage\"]),\n react_message: hasFunction(reaction, [\n \"sendReactionToMsg\",\n \"sendReaction\"\n ]),\n revoke_message: hasFunction(revoke, [\"sendRevokeMsgs\", \"revokeMessage\"])\n };\n }\n function uniqueMessageModels(collections) {\n const byId = new Map;\n for (const message of models(collections.Msg)) {\n const id = rawId(modelData(message).id ?? message?.id);\n if (id)\n byId.set(id, message);\n }\n for (const chat of models(collections.Chat))\n for (const message of models(modelData(chat).msgs ?? chat?.msgs)) {\n const id = rawId(modelData(message).id ?? message?.id);\n if (id)\n byId.set(id, message);\n }\n return [...byId.values()];\n }\n async function resolveChat(collections, input) {\n if (input?.self_chat === !0) {\n const me = meUser(), selfJid = (await canonicalJid(me)).jid;\n let self = null;\n for (const chat of models(collections.Chat))\n if ((await canonicalJid(modelData(chat).id ?? chat?.id)).jid === selfJid) {\n self = chat;\n break;\n }\n if (!self)\n throw Error(\"WhatsApp self chat is not loaded\");\n return self;\n }\n const requestedJidRaw = typeof input?.chat_jid === \"string\" ? input.chat_jid.trim().toLowerCase() : null, requestedJid = requestedJidRaw ? (await canonicalJid(requestedJidRaw)).jid : null, requestedName = typeof input?.chat_name === \"string\" ? input.chat_name.trim().toLowerCase() : null, matches = [];\n for (const chat of models(collections.Chat)) {\n const row = modelData(chat), jid = (await canonicalJid(row.id ?? chat?.id)).jid, name = String(row.name ?? row.formattedTitle ?? row.contact?.name ?? \"\").trim().toLowerCase();\n if (requestedJid ? jid === requestedJid : requestedName && name === requestedName)\n matches.push(chat);\n }\n if (matches.length === 0)\n throw Error(\"WhatsApp chat not found; pass an exact canonical chat_jid or exact chat_name\");\n if (matches.length > 1)\n throw Error(\"WhatsApp chat name is ambiguous; pass chat_jid\");\n return matches[0];\n }\n async function waitForPostState(check, label, timeoutMs = 2000) {\n const deadline = Date.now() + timeoutMs;\n do {\n if (check())\n return;\n await new Promise((resolve) => setTimeout(resolve, 50));\n } while (Date.now() < deadline);\n throw Error(`WhatsApp did not confirm ${label}`);\n }\n async function readMessages(input = {}) {\n const query = String(input.query ?? \"\").trim(), chatFilter = input.chat_filter ?? \"all\", limit = Math.min(100, Math.max(1, Math.trunc(Number(input.limit) || 50)));\n let before = null;\n if (input.cursor) {\n const cursor = JSON.parse(input.cursor);\n if (cursor.v !== 1 || !Number.isSafeInteger(cursor.before) || cursor.before <= 0 || cursor.query !== query || cursor.chat_filter !== chatFilter)\n throw Error(\"Invalid WhatsApp source cursor or changed query scope\");\n before = cursor.before;\n }\n const keyModule = requireFirst([\"WAWebMsgKey\"]), exactId = query.startsWith(\"id:\") ? query.slice(3) : null;\n let chatJid = null;\n if (query.startsWith(\"chat:\")) {\n const chat = await resolveChat(requireFirst([\"WAWebCollections\"]), { chat_jid: query.slice(5) });\n chatJid = (await canonicalJid(modelData(chat).id ?? chat?.id)).jid;\n }\n const database = await new Promise((resolve, reject) => {\n const request = indexedDB.open(\"model-storage\");\n request.onupgradeneeded = () => {\n request.transaction.abort();\n reject(Error(\"WhatsApp source history database is unavailable\"));\n };\n request.onerror = () => reject(request.error);\n request.onblocked = () => reject(Error(\"WhatsApp source history database is blocked\"));\n request.onsuccess = () => resolve(request.result);\n });\n let sourceRows;\n try {\n sourceRows = await new Promise((resolve, reject) => {\n const transaction = database.transaction(\"message\", \"readonly\");\n transaction.onabort = () => reject(transaction.error ?? Error(\"WhatsApp source read aborted\"));\n const index = transaction.objectStore(\"message\").index(\"rowId\"), range = before === null ? null : IDBKeyRange.upperBound(before, !0), request = index.openCursor(range, \"prev\"), rows = [];\n request.onerror = () => reject(request.error);\n request.onsuccess = () => {\n const cursor = request.result;\n if (!cursor) {\n resolve(rows);\n return;\n }\n if (!Number.isSafeInteger(cursor.key) || cursor.key <= 0 || typeof cursor.value.id !== \"string\") {\n reject(Error(\"WhatsApp source history has an unsupported key layout\"));\n return;\n }\n if (exactId !== null) {\n if (keyModule.fromString(cursor.value.id).id !== exactId) {\n cursor.continue();\n return;\n }\n resolve([{ position: cursor.key, id: cursor.value.id }]);\n return;\n }\n rows.push({ position: cursor.key, id: cursor.value.id });\n if (rows.length > (chatJid === null ? limit : 20000))\n resolve(rows);\n else\n cursor.continue();\n };\n });\n } finally {\n database.close();\n }\n let hasMore = sourceRows.length > limit, page = sourceRows.slice(0, limit), last = page[page.length - 1];\n if (chatJid !== null) {\n const examined = sourceRows.slice(0, 20000), canonical = new Map, matches = [];\n for (const row of examined) {\n const remote = keyModule.fromString(row.id).remote, raw = widString(remote);\n if (!canonical.has(raw))\n canonical.set(raw, (await canonicalJid(remote)).jid);\n if (canonical.get(raw) !== chatJid)\n continue;\n matches.push(row);\n if (matches.length > limit)\n break;\n }\n page = matches.slice(0, limit);\n hasMore = matches.length > limit || sourceRows.length > 20000;\n last = matches.length > limit ? page[page.length - 1] : examined[examined.length - 1];\n }\n const collections = requireFirst([\"WAWebCollections\"]), selected = [];\n for (const row of page) {\n const key = keyModule.fromString(row.id);\n if (exactId !== null && key.id !== exactId)\n continue;\n const remote = widString(key.remote);\n if (remote === \"status@broadcast\" || remote.endsWith(\"@newsletter\"))\n continue;\n const isGroup = remote.endsWith(\"@g.us\");\n if (chatFilter === \"group\" && !isGroup || chatFilter === \"individual\" && isGroup)\n continue;\n selected.push(row);\n }\n const results = [];\n if (selected.length) {\n const loaded = await collections.Msg.getMessagesById(selected.map((row) => row.id));\n if (loaded?.canceled || !Array.isArray(loaded?.messages))\n throw Error(\"Source message loading was canceled or unavailable\");\n const byKey = new Map(loaded.messages.map((model) => [String(model.id ?? modelData(model).id), model])), names = nameIndex(collections);\n for (const row of selected) {\n const model = byKey.get(row.id);\n if (!model)\n throw Error(\"Source message could not be loaded; retry the read\");\n const message = await normalizeMessage(model, \"snapshot\", collections, names);\n if (!message || message.timestamp <= 0)\n continue;\n if (exactId === null && chatJid === null && query && !`${message.body}\n${message.caption}`.toLowerCase().includes(query.toLowerCase()))\n continue;\n results.push(message);\n }\n }\n return {\n results,\n hasMore,\n ...hasMore ? { nextCursor: JSON.stringify({ v: 1, before: last.position, query, chat_filter: chatFilter }) } : {}\n };\n }\n async function searchMessages(input) {\n const collections = requireFirst([\"WAWebCollections\"]), query = String(input?.query ?? \"\").trim();\n if (!query)\n throw Error(\"query is required\");\n const offset = Math.max(0, Number(input?.offset) || 0), requestedLimit = Math.max(1, Math.min(Number(input?.limit) || 50, 100));\n if (offset >= 100)\n throw Error(\"WhatsApp source search supports only the first 100 matches\");\n const limit = Math.min(requestedLimit, 100 - offset), searchSourceLimit = 100, chatFilter = [\"all\", \"individual\", \"group\"].includes(input?.chat_filter) ? input.chat_filter : \"all\", chat = input?.chat_jid || input?.chat_name || input?.self_chat === !0 ? await resolveChat(collections, input) : null;\n let scopedChats = chat ? [chat] : void 0;\n if (!chat && chatFilter !== \"all\") {\n scopedChats = [];\n for (const candidate of models(collections.Chat)) {\n const jid = (await canonicalJid(modelData(candidate).id ?? candidate?.id)).jid;\n if (!jid || jid === \"status@broadcast\" || jid.endsWith(\"@newsletter\"))\n continue;\n const isGroup = jid.endsWith(\"@g.us\");\n if (chatFilter === \"group\" ? isGroup : !isGroup)\n scopedChats.push(candidate);\n }\n }\n const search = requireFirst([\n \"WAWebChatMessageSearch\",\n \"WAWebMessageSearch\",\n \"WAWebSearchMessages\"\n ]);\n let found = null;\n for (const fn of [\n search?.searchMessages,\n search?.searchMsgs,\n search?.search\n ]) {\n if (typeof fn !== \"function\")\n continue;\n try {\n found = await fn.call(search, query, scopedChats, searchSourceLimit);\n break;\n } catch {}\n }\n let source = \"whatsapp_fts\", candidates = Array.isArray(found) ? found : models(found?.messages ?? found);\n if (!found) {\n source = \"loaded_model_fallback\";\n const needle = query.toLowerCase();\n candidates = uniqueMessageModels(collections).filter((model) => {\n const row = modelData(model);\n if (chat) {\n const chatId = widString(modelData(chat).id ?? chat?.id);\n if (widString(row.id?.remote ?? row.chatId) !== chatId)\n return !1;\n }\n return String(row.body ?? row.caption ?? \"\").toLowerCase().includes(needle);\n });\n }\n const normalized = [], names = nameIndex(collections);\n for (const candidate of candidates) {\n const model = candidate?.msg ?? candidate?.message ?? candidate, message = await normalizeMessage(model, \"search\", collections, names);\n if (!message || Number(message.timestamp) <= 0)\n continue;\n if (chatFilter === \"group\" && !message.is_group)\n continue;\n if (chatFilter === \"individual\" && message.is_group)\n continue;\n normalized.push(message);\n if (normalized.length >= searchSourceLimit)\n break;\n }\n return {\n source,\n results: normalized.slice(offset, offset + limit),\n hasMore: offset + limit < normalized.length\n };\n }\n async function draftMessage(input) {\n const collections = requireFirst([\"WAWebCollections\"]), chat = await resolveChat(collections, input), text = String(input?.text ?? \"\");\n if (!text.trim())\n throw Error(\"text is required\");\n const draft = {\n body: text,\n timestamp: Math.floor(Date.now() / 1000),\n type: \"chat\",\n mentionedJidList: [],\n quotedMsg: null\n }, module2 = requireFirst(DRAFT_MODULES);\n let applied = !1;\n for (const fn of [\n module2?.setDraft,\n module2?.setChatDraft,\n module2?.saveDraft\n ]) {\n if (typeof fn !== \"function\")\n continue;\n try {\n await fn.call(module2, chat, draft);\n applied = !0;\n break;\n } catch {\n try {\n await fn.call(module2, draft, chat);\n applied = !0;\n break;\n } catch {}\n }\n }\n if (!applied && typeof chat?.setDraft === \"function\") {\n await chat.setDraft(draft);\n applied = !0;\n }\n if (!applied)\n throw Error(\"WhatsApp draft capability is unavailable in this web build\");\n const stored = modelData(chat).draft ?? chat.get?.(\"draft\") ?? null;\n if (!stored || typeof stored !== \"object\" || stored.body !== text)\n throw Error(\"WhatsApp rejected the persistent draft shape\");\n return {\n drafted: !0,\n sent: !1,\n chat_jid: widString(modelData(chat).id ?? chat?.id),\n draft\n };\n }\n async function sendMessage(input) {\n const collections = requireFirst([\"WAWebCollections\"]), chat = await resolveChat(collections, input), text = String(input?.text ?? \"\");\n if (!text.trim())\n throw Error(\"text is required\");\n const module2 = requireFirst(SEND_MODULES);\n if (typeof module2?.createTextMsgData === \"function\" && typeof module2?.addAndSendTextMsg === \"function\") {\n const data = await module2.createTextMsgData(chat, text), plannedId = rawId(data?.id);\n if (!plannedId)\n throw Error(\"WhatsApp did not assign an id to the outgoing message\");\n await module2.addAndSendTextMsg(chat, data);\n return {\n sent: !0,\n chat_jid: widString(modelData(chat).id ?? chat?.id),\n message_id: plannedId\n };\n }\n const fn = module2?.sendTextMsgToChat ?? module2?.sendMessage ?? chat?.sendMessage;\n if (typeof fn !== \"function\")\n throw Error(\"WhatsApp send capability is unavailable in this web build\");\n const result = fn === chat?.sendMessage ? await fn.call(chat, text) : await fn.call(module2, chat, text), messageId = rawId(modelData(result).id ?? result?.id);\n if (!messageId)\n throw Error(\"WhatsApp send acknowledgment has no raw message ID\");\n return {\n sent: !0,\n chat_jid: widString(modelData(chat).id ?? chat?.id),\n message_id: messageId\n };\n }\n function messageActionAllowed(message, predicateNames, legacyFlags) {\n const row = modelData(message);\n for (const flag of legacyFlags)\n if (row[flag] === !0)\n return !0;\n const capability = requireFirst([\"WAWebMsgActionCapability\"]);\n for (const name of predicateNames) {\n if (typeof capability?.[name] !== \"function\")\n continue;\n try {\n if (capability[name](message) === !0)\n return !0;\n } catch {}\n }\n return !1;\n }\n function resolveMessage(collections, id) {\n const raw = String(id ?? \"\").trim();\n if (!raw)\n throw Error(\"message_id is required\");\n const message = collectionByRawId(collections.Msg, raw);\n if (!message)\n throw Error(`WhatsApp message ${raw} is not loaded; read it with id:${raw} from the live messages feed or search it first`);\n return message;\n }\n async function editMessage(input) {\n const collections = requireFirst([\"WAWebCollections\"]), message = resolveMessage(collections, input?.message_id), before = modelData(message);\n if (!(before.id?.fromMe ?? before.fromMe))\n throw Error(\"WhatsApp only permits editing outgoing messages\");\n if (!messageActionAllowed(message, [\"canEditText\", \"canEditCaption\", \"canEnterEditingFlow\"], [\"canEdit\", \"isEditable\"]))\n throw Error(\"WhatsApp did not affirm that this message is currently editable\");\n const text = String(input?.text ?? \"\");\n if (!text.trim())\n throw Error(\"text is required\");\n const module2 = requireFirst(EDIT_MODULES), fn = module2?.sendMessageEdit ?? module2?.editMessage ?? message?.edit;\n if (typeof fn !== \"function\")\n throw Error(\"WhatsApp edit capability is unavailable in this web build\");\n await (fn === message?.edit ? fn.call(message, text) : fn.call(module2, message, text, {}));\n await waitForPostState(() => {\n const row = modelData(message);\n return row.body === text && Boolean(row.isEdited || row.editVersion || row.latestEditMsgKey);\n }, \"message edit\");\n return {\n edited: !0,\n message_id: rawId(modelData(message).id ?? message?.id)\n };\n }\n async function reactMessage(input) {\n const collections = requireFirst([\"WAWebCollections\"]), message = resolveMessage(collections, input?.message_id), emoji = input?.remove ? \"\" : String(input?.emoji ?? \"\");\n if (!input?.remove && !emoji)\n throw Error(\"emoji is required unless remove=true\");\n const module2 = requireFirst(REACTION_MODULES), fn = module2?.sendReactionToMsg ?? module2?.sendReaction ?? message?.react;\n if (typeof fn !== \"function\")\n throw Error(\"WhatsApp reaction capability is unavailable in this web build\");\n await (fn === message?.react ? fn.call(message, emoji) : fn.call(module2, message, emoji));\n await waitForPostState(() => {\n const row = modelData(message), reactions = normalizeReactions(row);\n if (reactions.length > 0)\n return input?.remove ? !reactions.some((reaction) => reaction.from_me) : reactions.some((reaction) => reaction.from_me && reaction.emoji === emoji);\n return input?.remove ? !0 : row.hasReaction === !0;\n }, \"reaction state\");\n return {\n reacted: !0,\n confirmed: input?.remove ? normalizeReactions(modelData(message)).length > 0 : !0,\n removed: Boolean(input?.remove),\n emoji: emoji || null,\n message_id: rawId(modelData(message).id ?? message?.id)\n };\n }\n async function revokeMessage(input) {\n const collections = requireFirst([\"WAWebCollections\"]), message = resolveMessage(collections, input?.message_id), before = modelData(message);\n if (!(before.id?.fromMe ?? before.fromMe))\n throw Error(\"WhatsApp only permits revoking outgoing messages\");\n if (!messageActionAllowed(message, [\"canSenderRevokeMsg\", \"canAdminRevokeMsg\"], [\"canRevoke\", \"isRevokable\"]))\n throw Error(\"WhatsApp did not affirm that this message is currently revokable\");\n const module2 = requireFirst(REVOKE_MODULES), fn = module2?.sendRevokeMsgs ?? module2?.sendRevoke ?? module2?.revokeMessage ?? message?.sendRevoke ?? message?.revoke;\n if (typeof fn !== \"function\")\n throw Error(\"WhatsApp revoke capability is unavailable in this web build\");\n if (fn === message?.sendRevoke || fn === message?.revoke)\n await fn.call(message);\n else\n await fn.call(module2, [message], modelData(message).id?.remote);\n await waitForPostState(() => {\n const row = modelData(message);\n return Boolean(row.isRevoked || row.revoked || row.type === \"revoked\");\n }, \"message revoke\");\n return {\n revoked: !0,\n message_id: rawId(modelData(message).id ?? message?.id)\n };\n }\n async function invoke(request) {\n try {\n if (Number(request?.adapter_version) !== 26)\n return {\n ok: !1,\n error: {\n state: \"adapter_mismatch\",\n reason: \"expected 26\"\n }\n };\n if (request.op === \"account_identity\") {\n const accountId = widString(meUser());\n return accountId ? { accountId } : null;\n }\n if (request.op === \"probe\") {\n const status = readiness();\n return status.ready ? { ok: !0, status, capabilities: operationCapabilities() } : { ok: !1, error: status };\n }\n if (request.op === \"listen\")\n return listen(request);\n if (request.op === \"publish_changes\")\n return await publishChanges(request);\n if (request.op === \"observe_messages\")\n return { ok: !0, ...await observeMessages(request.input) };\n if (operationCapabilities()[request.op] !== !0)\n return {\n ok: !1,\n error: {\n state: \"capability_unavailable\",\n reason: `${request.op} is unavailable in this WhatsApp Web build`\n }\n };\n if (request.op === \"read_messages\")\n return { ok: !0, ...await readMessages(request.input) };\n if (request.op === \"search_messages\")\n return { ok: !0, ...await searchMessages(request.input) };\n if (request.op === \"draft_message\")\n return { ok: !0, ...await draftMessage(request.input) };\n if (request.op === \"send_message\")\n return { ok: !0, ...await sendMessage(request.input) };\n if (request.op === \"edit_message\")\n return { ok: !0, ...await editMessage(request.input) };\n if (request.op === \"react_message\")\n return { ok: !0, ...await reactMessage(request.input) };\n if (request.op === \"revoke_message\")\n return { ok: !0, ...await revokeMessage(request.input) };\n return {\n ok: !1,\n error: { state: \"unsupported_operation\", reason: String(request?.op) }\n };\n } catch (error) {\n return {\n ok: !1,\n error: {\n state: \"operation_failed\",\n reason: error instanceof Error ? error.message : String(error)\n }\n };\n }\n }\n globalThis.__owlettoWhatsAppAdapterV1 = { version: 26, invoke, detach };\n })();\n for (let i = 0; i < 40; i++) {\n const identity = await globalThis.__owlettoWhatsAppAdapterV1.invoke({ op: \"account_identity\", adapter_version: 26 });\n if (identity?.accountId) return identity;\n await new Promise(resolve => setTimeout(resolve, 250));\n }\n return null;\n })()"
21655
+ "expression": "(async () => {\n (function whatsAppWebAdapterProgram() {\n const SYSTEM_TYPES = new Set([\n \"gp2\",\n \"notification_template\",\n \"e2e_notification\"\n ]);\n let readinessSignature = null, readinessStableSince = 0;\n const existing = globalThis.__owlettoWhatsAppAdapterV1;\n if (existing?.version === 27)\n return;\n existing?.detach?.(void 0, \"WhatsApp adapter was replaced; recovery is required\");\n const listeners = new Map;\n function detach(bindingId, reason) {\n const selected = bindingId ? [listeners.get(bindingId)] : [...listeners.values()];\n for (const state of selected) {\n if (!state)\n continue;\n if (reason) {\n state.error = reason;\n state.post({ sequence: ++state.sequence, record: { id: \"whatsapp-web:source-observation-error\", source_error: reason } });\n }\n for (const entry of state.pending.values())\n entry.reject?.(Error(reason ?? \"Source listener was detached\"));\n state.collection.off(\"add\", state.onAdd);\n state.collection.off(\"change\", state.onChange);\n window.removeEventListener(\"message\", state.onReply);\n listeners.delete(state.id);\n }\n }\n function assertAccount(account) {\n if (typeof account !== \"string\" || !account || widString(meUser()) !== account)\n throw Error(\"WhatsApp saved account changed or is unavailable; reconnect this connection\");\n }\n async function digest(value) {\n const bytes = await crypto.subtle.digest(\"SHA-256\", new TextEncoder().encode(value));\n return Array.from(new Uint8Array(bytes), (byte) => byte.toString(16).padStart(2, \"0\")).join(\"\");\n }\n function listen(request) {\n assertAccount(request.account_id);\n const collection = requireFirst([\"WAWebCollections\"])?.Msg;\n if (typeof collection?.on !== \"function\" || typeof collection?.off !== \"function\")\n throw Error(\"WhatsApp message observation is unavailable in this build\");\n if (!request.bridge_id || !request.token)\n throw Error(\"A feed bridge is required\");\n const post = (state2, entry) => window.postMessage({\n type: \"lobu-feed-record\",\n token: state2.token,\n sequence: entry.sequence,\n record: entry.record\n }, location.origin), reportError = (state2, message, sequence = ++state2.sequence) => {\n state2.error = message;\n post(state2, {\n sequence,\n record: {\n id: \"whatsapp-web:source-observation-error\",\n source_error: message\n }\n });\n }, resident = listeners.get(request.bridge_id), previous = resident?.request.account_id === request.account_id && resident?.request.chat_filter === request.chat_filter && resident?.request.minimum_timestamp === request.minimum_timestamp ? resident : null;\n detach(request.bridge_id);\n const state = {\n ...previous ?? {\n id: request.bridge_id,\n collection,\n sequence: 0,\n pending: new Map,\n fingerprints: new Map,\n pendingBytes: 0,\n fingerprintBytes: 0,\n error: null\n },\n collection,\n error: null\n };\n state.token = request.token;\n state.request = request;\n state.post = (entry) => post(state, entry);\n const observe = (model) => {\n if (state.error)\n return;\n const sequence = ++state.sequence;\n new Promise((resolve) => {\n assertAccount(state.request.account_id);\n resolve(messageReference(model));\n }).then((record) => {\n if (listeners.get(state.id) !== state)\n return;\n assertAccount(state.request.account_id);\n if (!record || record.timestamp <= 0)\n return;\n if (state.request.chat_filter === \"group\" && !record.is_group)\n return;\n if (state.request.chat_filter === \"individual\" && record.is_group)\n return;\n if (state.request.minimum_timestamp != null && record.timestamp < state.request.minimum_timestamp)\n return;\n record = {\n id: record.id,\n events: [{\n id: record.id,\n event_type: \"message.created\",\n resource_ref: record.id,\n resource_type: \"message\",\n occurred_at: new Date(record.timestamp * 1000).toISOString()\n }]\n };\n const previous2 = state.pending.get(record.id), seen = state.fingerprints.get(record.id);\n if (seen && seen.sequence >= sequence)\n return;\n const fingerprint = JSON.stringify(record);\n if (seen?.fingerprint === fingerprint) {\n seen.sequence = sequence;\n return;\n }\n const bytes = new TextEncoder().encode(fingerprint).length;\n if (bytes > 131072 || state.pendingBytes - (previous2?.bytes ?? 0) + bytes > 16777216 || state.pending.size >= 1e4 && !previous2) {\n reportError(state, \"WhatsApp page observation buffer overflowed; recovery is required\", sequence);\n return;\n }\n const entry = { sequence, record, bytes };\n state.pendingBytes += bytes - (previous2?.bytes ?? 0);\n state.pending.set(record.id, entry);\n state.fingerprintBytes += bytes - (seen?.bytes ?? 0);\n state.fingerprints.delete(record.id);\n state.fingerprints.set(record.id, { fingerprint, sequence, bytes });\n while (state.fingerprints.size > 1e4 || state.fingerprintBytes > 16777216) {\n const oldest = state.fingerprints.keys().next().value;\n state.fingerprintBytes -= state.fingerprints.get(oldest).bytes;\n state.fingerprints.delete(oldest);\n }\n post(state, entry);\n }).catch(() => {\n if (listeners.get(state.id) !== state)\n return;\n reportError(state, \"WhatsApp source observation failed; recovery is required\", sequence);\n });\n };\n state.onAdd = (model) => observe(model);\n state.onChange = (model) => observe(model);\n state.onReply = (event) => {\n if (event.source !== window || event.origin !== location.origin || event.data?.token !== state.token)\n return;\n if (event.data.type === \"lobu-feed-record:stop\") {\n detach(state.id);\n return;\n }\n if (event.data.type !== \"lobu-feed-record:ack\")\n return;\n try {\n assertAccount(state.request.account_id);\n } catch {\n detach(state.id, \"WhatsApp saved account changed; recovery is required\");\n return;\n }\n for (const [id, entry] of state.pending) {\n if (entry.sequence !== event.data.sequence)\n continue;\n if (event.data.ok) {\n state.pendingBytes -= entry.bytes;\n state.pending.delete(id);\n entry.resolve?.();\n } else\n entry.reject?.(Error(\"Browser rejected the source reference batch\"));\n break;\n }\n };\n listeners.set(state.id, state);\n try {\n collection.on(\"add\", state.onAdd);\n collection.on(\"change\", state.onChange);\n window.addEventListener(\"message\", state.onReply);\n } catch (error) {\n reportError(state, \"WhatsApp source observation failed; recovery is required\");\n throw error;\n }\n if (previous?.error)\n post(state, {\n sequence: ++state.sequence,\n record: { id: \"whatsapp-web:source-observation-error\", source_error: previous.error }\n });\n for (const entry of state.pending.values())\n post(state, entry);\n return { ok: !0, listening: !0 };\n }\n async function publishChanges(request) {\n const state = listeners.get(request.bridge_id);\n if (!state || state.token !== request.token)\n throw Error(\"Source listener is unavailable\");\n assertAccount(state.request.account_id);\n const record = { ...request.batch, id: `replay:${await digest(JSON.stringify([request.transition ?? null, request.batch]))}` };\n if (listeners.get(state.id) !== state)\n throw Error(\"Source listener was replaced\");\n assertAccount(state.request.account_id);\n const bytes = new TextEncoder().encode(JSON.stringify(record)).length, previous = state.pending.get(record.id);\n if (bytes > 131072 || state.pendingBytes - (previous?.bytes ?? 0) + bytes > 16777216 || state.pending.size >= 1e4 && !previous)\n throw Error(\"Source replay buffer is full\");\n await new Promise((resolve, reject) => {\n const timer = setTimeout(() => reject(Error(\"Source replay was not accepted by the browser\")), 1e4), entry = {\n record,\n bytes,\n sequence: ++state.sequence,\n resolve: () => {\n clearTimeout(timer);\n resolve();\n },\n reject: (error) => {\n clearTimeout(timer);\n reject(error);\n }\n };\n state.pendingBytes += bytes - (previous?.bytes ?? 0);\n state.pending.set(record.id, entry);\n state.post(entry);\n });\n return { ok: !0 };\n }\n function requireFirst(names) {\n for (const name of names)\n try {\n const module2 = window.require?.(name);\n if (module2)\n return module2;\n } catch {}\n return null;\n }\n function meUser() {\n const module2 = requireFirst([\n \"WAWebUserPrefsMeUser\",\n \"WAWebUserPrefsMe\",\n \"WAWebUserPrefs\"\n ]);\n if (!module2)\n return null;\n for (const accessor of [\n \"getMaybeMePnUser\",\n \"getMaybeMeUser\",\n \"getMeUser\",\n \"getMeUserOrThrow\",\n \"getMaybeMeLidUser\"\n ])\n try {\n const value = module2[accessor]?.();\n if (value)\n return value;\n } catch {}\n try {\n return module2.me ?? null;\n } catch {}\n return null;\n }\n async function ownJids() {\n const module2 = requireFirst([\"WAWebUserPrefsMeUser\"]), candidates = [meUser()];\n for (const accessor of [\"getMaybeMePnUser\", \"getMaybeMeLidUser\"])\n try {\n candidates.push(module2?.[accessor]?.());\n } catch {}\n const forms = new Set;\n for (const value of candidates) {\n const own = await canonicalJid(value);\n if (own.jid)\n forms.add(own.jid);\n if (own.lid)\n forms.add(own.lid);\n }\n return forms;\n }\n async function mentionsOwnAccount(row) {\n const addressed = [\n ...Array.isArray(row.mentionedJidList) ? row.mentionedJidList : [],\n row.quotedParticipant\n ].filter(Boolean);\n if (addressed.length === 0)\n return !1;\n const own = await ownJids();\n for (const value of addressed) {\n const candidate = await canonicalJid(value);\n if (own.has(candidate.jid) || candidate.lid && own.has(candidate.lid))\n return !0;\n }\n return !1;\n }\n const SEND_MODULES = [\n \"WAWebSendTextMsgChatAction\",\n \"WAWebSendMsgChatAction\",\n \"WAWebSendMessage\"\n ], REACTION_MODULES = [\n \"WAWebSendReactionMsgAction\",\n \"WAWebSendReactionMsg\",\n \"WAWebReactionAction\"\n ], REVOKE_MODULES = [\n \"WAWebChatSendMessages\",\n \"WAWebRevokeMsgAction\",\n \"WAWebDeleteChatAction\",\n \"WAWebRevokeMessage\"\n ], EDIT_MODULES = [\"WAWebSendMessageEditAction\", \"WAWebEditMessage\"], DRAFT_MODULES = [\n \"WAWebChatDraftUtils\",\n \"WAWebSetDraft\",\n \"WAWebComposeBoxActions\"\n ];\n function modelData(model) {\n return model?.attributes ?? model?._data ?? model ?? {};\n }\n function messageReference(model) {\n const row = modelData(model), key = row.id ?? model?.id, id = rawId(key), remote = widString(key?.remote ?? row.chatId ?? (key?.fromMe ? row.to : row.from));\n if (!id || !remote || remote === \"status@broadcast\" || remote.endsWith(\"@newsletter\") || SYSTEM_TYPES.has(row.type))\n return null;\n return { id, timestamp: unixSeconds(row), is_group: remote.endsWith(\"@g.us\") };\n }\n async function observeMessages(input = {}) {\n const after = input.after ?? null;\n if (after !== null && (!Number.isSafeInteger(after) || after < 0))\n throw Error(\"Invalid WhatsApp observation cursor\");\n const pending = input.unresolved ?? [];\n if (!Array.isArray(pending) || pending.length > 32 || pending.some((row) => !Number.isSafeInteger(row.position) || row.position <= 0 || typeof row.id !== \"string\" || row.id.length > 512 || !Number.isSafeInteger(row.first_seen) || row.first_seen < 0))\n throw Error(\"Invalid WhatsApp pending placeholder cursor\");\n const database = await new Promise((resolve, reject) => {\n const request = indexedDB.open(\"model-storage\");\n request.onupgradeneeded = () => {\n request.transaction.abort();\n reject(Error(\"WhatsApp source history database is unavailable\"));\n };\n request.onerror = () => reject(request.error);\n request.onblocked = () => reject(Error(\"WhatsApp source history database is blocked\"));\n request.onsuccess = () => resolve(request.result);\n }), now = Math.floor(Date.now() / 1000), gaps = [], gap = (reason, detail) => gaps.push({ reason, detail }), scan = (position, limit, direction = \"next\", inclusive = !1) => new Promise((resolve, reject) => {\n const transaction = database.transaction(\"message\", \"readonly\");\n transaction.onabort = () => reject(transaction.error ?? Error(\"WhatsApp source observation aborted\"));\n const request = transaction.objectStore(\"message\").index(\"rowId\").openCursor(position === null ? null : IDBKeyRange.lowerBound(position, !inclusive), direction), page2 = [];\n request.onerror = () => reject(request.error);\n request.onsuccess = () => {\n const cursor = request.result;\n if (!cursor) {\n resolve(page2);\n return;\n }\n if (!Number.isSafeInteger(cursor.key) || cursor.key <= 0 || typeof cursor.value.id !== \"string\" || cursor.value.id.length > 512) {\n reject(Error(\"WhatsApp source history has an unsupported key layout\"));\n return;\n }\n page2.push({ position: cursor.key, id: cursor.value.id, timestamp: unixSeconds(cursor.value), type: cursor.value.type });\n if (page2.length >= limit)\n resolve(page2);\n else\n cursor.continue();\n };\n });\n let rows, rechecks;\n try {\n if (after === null) {\n rows = await scan(null, 1, \"prev\");\n const head = rows[0];\n return {\n after: head?.position ?? 0,\n anchor: head?.id ?? null,\n unresolved: head?.timestamp === 0 ? [{ position: head.position, id: head.id, first_seen: now }] : [],\n references: [],\n gaps: [],\n hasMore: !1\n };\n }\n let start = after;\n if (after > 0) {\n const [anchor] = await scan(after, 1, \"next\", !0);\n if (!input.anchor || anchor?.position !== after || anchor.id !== input.anchor) {\n gap(\"history-continuity\", [after, input.anchor ?? null]);\n start = 0;\n }\n }\n rechecks = await Promise.all(pending.map(async (item) => ({ item, row: (await scan(item.position, 1, \"next\", !0))[0] })));\n rows = await scan(start, 501);\n } finally {\n database.close();\n }\n const page = rows.slice(0, 500), references = new Map, unresolved = new Map, keys = requireFirst([\"WAWebMsgKey\"]);\n if ((page.length || rechecks.length) && typeof keys?.fromString !== \"function\")\n throw Error(\"WhatsApp source message keys are unavailable\");\n const accept = (row, firstSeen = now) => {\n const reference = messageReference({ id: keys.fromString(row.id), t: row.timestamp, type: row.type });\n if (!reference)\n return;\n if (input.chat_filter === \"group\" && !reference.is_group)\n return;\n if (input.chat_filter === \"individual\" && reference.is_group)\n return;\n if (reference.timestamp <= 0) {\n if (now - firstSeen >= 604800)\n gap(\"placeholder-expired\", [row.position, row.id, firstSeen]);\n else if (unresolved.size < 32 || unresolved.has(row.id))\n unresolved.set(row.id, { position: row.position, id: row.id, first_seen: firstSeen });\n else\n gap(\"placeholder-capacity\", [row.position, row.id]);\n return;\n }\n if (reference.timestamp >= input.started_at)\n references.set(reference.id, reference);\n }, checked = new Set;\n for (const { item, row } of rechecks)\n if (!row || row.position !== item.position || row.id !== item.id)\n gap(\"placeholder-unavailable\", [item.position, item.id]);\n else {\n checked.add(item.id);\n accept(row, item.first_seen);\n }\n for (const row of page)\n if (!checked.has(row.id))\n accept(row);\n const last = page[page.length - 1], rebased = gaps.some((item) => item.reason === \"history-continuity\");\n return {\n after: last?.position ?? (rebased ? 0 : after),\n anchor: last?.id ?? (rebased ? null : input.anchor ?? null),\n unresolved: [...unresolved.values()],\n references: [...references.values()],\n hasMore: rows.length > 500,\n gaps: await Promise.all(gaps.map(async (item) => {\n const identity = await digest(JSON.stringify([input.account_id, input.started_at, input.chat_filter, item]));\n return {\n id: `gap:${identity}`,\n event_type: \"source.gap\",\n resource_type: \"message\",\n resource_ref: `whatsapp:${item.reason}:${identity}`\n };\n }))\n };\n }\n function models(collection) {\n if (Array.isArray(collection?._models))\n return collection._models;\n if (Array.isArray(collection?.models))\n return collection.models;\n if (typeof collection?.toArray === \"function\")\n try {\n return collection.toArray();\n } catch {}\n return [];\n }\n function widString(value) {\n if (typeof value === \"string\")\n return value;\n if (!value)\n return null;\n if (typeof value._serialized === \"string\")\n return value._serialized;\n try {\n const rendered = value.toString?.();\n return rendered && rendered !== \"[object Object]\" ? String(rendered) : null;\n } catch {\n return null;\n }\n }\n function rawId(value) {\n if (typeof value === \"string\")\n return value && !/^(?:true|false)_/i.test(value) ? value : null;\n if (typeof value?.id === \"string\")\n return value.id && !/^(?:true|false)_/i.test(value.id) ? value.id : null;\n return null;\n }\n function unixSeconds(row) {\n const value = Number(row?.t ?? row?.timestamp ?? row?.ephemeralStartTimestamp ?? 0);\n return Number.isFinite(value) && value > 0 ? Math.floor(value) : 0;\n }\n async function canonicalJid(value) {\n const original = widString(value);\n if (!original)\n return { jid: null, lid: null };\n let jid = original.toLowerCase();\n if (jid.endsWith(\"@c.us\"))\n jid = `${jid.slice(0, -5)}@s.whatsapp.net`;\n if (!jid.endsWith(\"@lid\"))\n return { jid, lid: null };\n const migration = requireFirst([\n \"WAWebLidMigrationUtils\",\n \"WAWebLidMigration\"\n ]), toPn = migration?.toPn ?? migration?.getPnForLid ?? migration?.lidToPhone;\n if (typeof toPn === \"function\")\n try {\n const converted = await toPn.call(migration, value), phoneJid = widString(converted);\n if (phoneJid)\n return {\n jid: phoneJid.endsWith(\"@c.us\") ? `${phoneJid.slice(0, -5)}@s.whatsapp.net` : phoneJid,\n lid: jid\n };\n } catch {}\n return { jid, lid: jid };\n }\n function collectionByRawId(collection, id) {\n if (!id)\n return null;\n for (const model of models(collection)) {\n const row = modelData(model);\n if (rawId(row.id ?? model?.id) === id)\n return model;\n }\n return null;\n }\n function reactionTargetId(row) {\n return rawId(row.reactionParentKey) ?? rawId(row.parentMsgKey) ?? rawId(row.parentMessageKey) ?? (typeof row.quotedStanzaID === \"string\" ? row.quotedStanzaID : null);\n }\n function normalizeReactions(row) {\n const source = row.reactions ?? row.reactionCollection ?? row.reactionsBySender;\n return (Array.isArray(source) ? source : models(source)).map((reaction) => {\n const data = modelData(reaction);\n return {\n emoji: data.text ?? data.reactionText ?? data.emoji ?? null,\n sender_jid: widString(data.senderUserJid ?? data.sender ?? data.author),\n from_me: Boolean(data.fromMe)\n };\n }).filter((reaction) => typeof reaction.emoji === \"string\" && reaction.emoji.length > 0);\n }\n function nameIndex(collections) {\n const byId = (collection) => {\n const map = new Map;\n for (const model of models(collection)) {\n const id = widString(modelData(model).id ?? model?.id);\n if (id && !map.has(id))\n map.set(id, model);\n }\n return map;\n };\n return { chats: byId(collections?.Chat), contacts: byId(collections?.Contact) };\n }\n function contactName(names, jid) {\n if (!jid)\n return null;\n const contact = names?.contacts?.get(jid);\n if (!contact)\n return null;\n const row = modelData(contact);\n return row.name ?? row.pushname ?? row.shortName ?? row.formattedName ?? null;\n }\n function chatName(names, jid) {\n if (!jid)\n return null;\n const chat = names?.chats?.get(jid);\n if (!chat)\n return null;\n const row = modelData(chat);\n return row.name ?? row.formattedTitle ?? row.contact?.name ?? row.contact?.pushname ?? null;\n }\n async function normalizeMessage(model, eventType = \"snapshot\", collectionsOverride = null, names = null) {\n const collections = collectionsOverride ?? requireFirst([\"WAWebCollections\"]);\n if (!collections)\n return null;\n const nameLookup = names ?? nameIndex(collections);\n let row = modelData(model), key = row.id ?? model?.id, id = rawId(key);\n if (!id)\n return null;\n if (row.type === \"reaction\") {\n const targetId = reactionTargetId(row), target = collectionByRawId(collections.Msg, targetId);\n if (target) {\n model = target;\n row = modelData(model);\n key = row.id ?? model?.id;\n id = rawId(key);\n }\n }\n const fromMe = Boolean(key?.fromMe ?? row.fromMe), remoteRaw = key?.remote ?? row.chatId, fromRaw = row.from, toRaw = row.to, authorRaw = row.author ?? key?.participant, chatRaw = remoteRaw ?? (fromMe ? toRaw : fromRaw), chat = await canonicalJid(chatRaw);\n if (!chat.jid || chat.jid === \"status@broadcast\" || chat.jid.endsWith(\"@newsletter\"))\n return null;\n const senderRaw = fromMe ? fromRaw : authorRaw ?? fromRaw, sender = await canonicalJid(senderRaw), participant = await canonicalJid(key?.participant ?? row.participant ?? (fromMe ? toRaw : null)), timestamp = unixSeconds(row), body = typeof row.body === \"string\" ? row.body : \"\", caption = typeof row.caption === \"string\" ? row.caption : \"\", quotedId = typeof row.quotedStanzaID === \"string\" ? row.quotedStanzaID : rawId(row.quotedMsg?.id ?? row.quotedMsgKey), type = typeof row.type === \"string\" ? row.type : \"unknown\";\n return {\n id,\n chat_jid: chat.jid,\n chat_lid: chat.lid,\n chat_name: chatName(nameLookup, widString(chatRaw)),\n sender_jid: sender.jid,\n sender_lid: sender.lid,\n push_name: contactName(nameLookup, widString(senderRaw)) ?? row.notifyName ?? null,\n participant: participant.jid,\n from_me: fromMe,\n is_group: chat.jid.endsWith(\"@g.us\"),\n timestamp,\n occurred_at: timestamp > 0 ? new Date(timestamp * 1000).toISOString() : null,\n body,\n caption,\n message_type: type,\n media_kind: type === \"ptt\" ? \"audio\" : [\"image\", \"video\", \"audio\", \"document\", \"sticker\"].includes(type) ? type : null,\n media_type: typeof row.mimetype === \"string\" ? row.mimetype : null,\n media_size: Number.isFinite(Number(row.size ?? row.fileSize)) ? Number(row.size ?? row.fileSize) : null,\n media_filename: row.filename ?? row.fileName ?? row.title ?? null,\n quoted_id: quotedId,\n mentions_me: await mentionsOwnAccount(row),\n is_forwarded: Boolean(row.isForwarded || Number(row.forwardingScore) > 0),\n is_starred: Boolean(row.star ?? row.isStarred),\n is_system_event: SYSTEM_TYPES.has(type),\n edited: Boolean(row.isEdited || row.editVersion || row.latestEditMsgKey),\n edit_timestamp: Number(row.editTimestamp ?? row.lastEditTimestamp) || null,\n revoked: Boolean(row.isRevoked || row.revoked || type === \"revoked\"),\n reactions: normalizeReactions(row),\n event_type: eventType\n };\n }\n function readiness() {\n if (typeof window.require !== \"function\")\n return {\n ready: !1,\n state: \"hydrating\",\n reason: \"whatsapp_runtime_unavailable\"\n };\n const collections = requireFirst([\"WAWebCollections\"]);\n if (!collections?.Msg || !collections?.Chat)\n return {\n ready: !1,\n state: \"hydrating\",\n reason: \"collections_unavailable\"\n };\n const me = meUser(), qrVisible = Boolean(document.querySelector('[data-testid=\"qrcode\"], canvas[aria-label*=\"Scan\" i], [data-ref] canvas'));\n if (!me && qrVisible)\n return { ready: !1, state: \"logged_out\", reason: \"qr_code_visible\" };\n if (!me)\n return {\n ready: !1,\n state: \"hydrating\",\n reason: \"authenticated_self_identity_unavailable\"\n };\n const socket = requireFirst([\"WAWebSocketModel\"])?.Socket, connection = socket ?? requireFirst([\"WAWebSocketState\", \"WAWebConn\", \"WAWebConnectionState\"]), connectionState = String(connection?.getSocketState?.() ?? connection?.state ?? connection?.socketState ?? \"\").toLowerCase();\n if (!connectionState)\n return {\n ready: !1,\n state: \"capability_unavailable\",\n reason: \"connection_state_unavailable\"\n };\n if (!/^(connected|open|ready|syncing)$/.test(connectionState))\n return {\n ready: !1,\n state: \"not_ready\",\n reason: `connection_${connectionState}`\n };\n if (socket) {\n const stream = String(socket.stream ?? \"\").toLowerCase();\n if (!stream)\n return {\n ready: !1,\n state: \"capability_unavailable\",\n reason: \"stream_state_unavailable\"\n };\n if (!/^(connected|open|ready)$/.test(stream))\n return { ready: !1, state: \"not_ready\", reason: `stream_${stream}` };\n if (socket.hasSynced === !1)\n return {\n ready: !1,\n state: \"hydrating\",\n reason: \"initial_sync_incomplete\"\n };\n }\n const offlineDelivery = requireFirst([\n \"WAWebOfflineDelivery\",\n \"WAWebOfflineDeliveryState\"\n ]);\n if ((offlineDelivery?.isOfflineDeliveryComplete?.() ?? offlineDelivery?.offlineDeliveryComplete ?? offlineDelivery?.isComplete) === !1)\n return {\n ready: !1,\n state: \"hydrating\",\n reason: \"offline_delivery_incomplete\"\n };\n const hydration = requireFirst([\n \"WAWebInitialSyncInfo\",\n \"WAWebHistorySync\",\n \"WAWebAppState\"\n ]);\n if ((hydration?.isInitialSyncComplete?.() ?? hydration?.initialSyncComplete ?? hydration?.isHydrated ?? !0) !== !0)\n return {\n ready: !1,\n state: \"hydrating\",\n reason: \"initial_sync_incomplete\"\n };\n if (!Array.isArray(collections.Chat._models) && !Array.isArray(collections.Chat.models))\n return {\n ready: !1,\n state: \"hydrating\",\n reason: \"chat_store_placeholder\"\n };\n const signature = `${widString(me)}:${models(collections.Chat).length}:${models(collections.Msg).length}`;\n if (signature !== readinessSignature) {\n readinessSignature = signature;\n readinessStableSince = Date.now();\n return { ready: !1, state: \"hydrating\", reason: \"stores_settling\" };\n }\n if (Date.now() - readinessStableSince < 500)\n return { ready: !1, state: \"hydrating\", reason: \"stores_settling\" };\n return {\n ready: !0,\n state: \"ready\",\n message_count: models(collections.Msg).length,\n chat_count: models(collections.Chat).length\n };\n }\n function operationCapabilities() {\n const search = requireFirst([\n \"WAWebChatMessageSearch\",\n \"WAWebMessageSearch\",\n \"WAWebSearchMessages\"\n ]), draft = requireFirst(DRAFT_MODULES), send = requireFirst(SEND_MODULES), edit = requireFirst(EDIT_MODULES), reaction = requireFirst(REACTION_MODULES), revoke = requireFirst(REVOKE_MODULES), hasFunction = (module2, names) => names.some((name) => typeof module2?.[name] === \"function\");\n return {\n read_messages: typeof indexedDB < \"u\" && typeof requireFirst([\"WAWebMsgKey\"])?.fromString === \"function\" && typeof requireFirst([\"WAWebCollections\"])?.Msg?.getMessagesById === \"function\",\n search_messages: hasFunction(search, [\"searchMessages\", \"searchMsgs\", \"search\"]) || Boolean(requireFirst([\"WAWebCollections\"])?.Msg),\n draft_message: hasFunction(draft, [\n \"setDraft\",\n \"setChatDraft\",\n \"saveDraft\"\n ]),\n send_message: hasFunction(send, [\n \"sendTextMsgToChat\",\n \"sendMessage\",\n \"addAndSendTextMsg\"\n ]),\n edit_message: hasFunction(edit, [\"sendMessageEdit\", \"editMessage\"]),\n react_message: hasFunction(reaction, [\n \"sendReactionToMsg\",\n \"sendReaction\"\n ]),\n revoke_message: hasFunction(revoke, [\"sendRevokeMsgs\", \"revokeMessage\"])\n };\n }\n function uniqueMessageModels(collections) {\n const byId = new Map;\n for (const message of models(collections.Msg)) {\n const id = rawId(modelData(message).id ?? message?.id);\n if (id)\n byId.set(id, message);\n }\n for (const chat of models(collections.Chat))\n for (const message of models(modelData(chat).msgs ?? chat?.msgs)) {\n const id = rawId(modelData(message).id ?? message?.id);\n if (id)\n byId.set(id, message);\n }\n return [...byId.values()];\n }\n async function resolveChat(collections, input) {\n if (input?.self_chat === !0) {\n const me = meUser(), selfJid = (await canonicalJid(me)).jid;\n let self = null;\n for (const chat of models(collections.Chat))\n if ((await canonicalJid(modelData(chat).id ?? chat?.id)).jid === selfJid) {\n self = chat;\n break;\n }\n if (!self)\n throw Error(\"WhatsApp self chat is not loaded\");\n return self;\n }\n const requestedJidRaw = typeof input?.chat_jid === \"string\" ? input.chat_jid.trim().toLowerCase() : null, requestedJid = requestedJidRaw ? (await canonicalJid(requestedJidRaw)).jid : null, requestedName = typeof input?.chat_name === \"string\" ? input.chat_name.trim().toLowerCase() : null, matches = [];\n for (const chat of models(collections.Chat)) {\n const row = modelData(chat), jid = (await canonicalJid(row.id ?? chat?.id)).jid, name = String(row.name ?? row.formattedTitle ?? row.contact?.name ?? \"\").trim().toLowerCase();\n if (requestedJid ? jid === requestedJid : requestedName && name === requestedName)\n matches.push(chat);\n }\n if (matches.length === 0)\n throw Error(\"WhatsApp chat not found; pass an exact canonical chat_jid or exact chat_name\");\n if (matches.length > 1)\n throw Error(\"WhatsApp chat name is ambiguous; pass chat_jid\");\n return matches[0];\n }\n async function waitForPostState(check, label, timeoutMs = 2000) {\n const deadline = Date.now() + timeoutMs;\n do {\n if (check())\n return;\n await new Promise((resolve) => setTimeout(resolve, 50));\n } while (Date.now() < deadline);\n throw Error(`WhatsApp did not confirm ${label}`);\n }\n async function readMessages(input = {}, account) {\n const query = String(input.query ?? \"\").trim(), chatFilter = input.chat_filter ?? \"all\", limit = Math.min(100, Math.max(1, Math.trunc(Number(input.limit) || 50)));\n let before = null;\n if (input.cursor) {\n const cursor = JSON.parse(input.cursor);\n if (cursor.v !== 1 || !Number.isSafeInteger(cursor.before) || cursor.before <= 0 || cursor.query !== query || cursor.chat_filter !== chatFilter || cursor.account !== account)\n throw Error(\"Invalid WhatsApp source cursor or changed query scope\");\n before = cursor.before;\n }\n const keyModule = requireFirst([\"WAWebMsgKey\"]), exactId = query.startsWith(\"id:\") ? query.slice(3) : null;\n let chatJid = null;\n if (query.startsWith(\"chat:\")) {\n const chat = await resolveChat(requireFirst([\"WAWebCollections\"]), { chat_jid: query.slice(5) });\n chatJid = (await canonicalJid(modelData(chat).id ?? chat?.id)).jid;\n }\n const database = await new Promise((resolve, reject) => {\n const request = indexedDB.open(\"model-storage\");\n request.onupgradeneeded = () => {\n request.transaction.abort();\n reject(Error(\"WhatsApp source history database is unavailable\"));\n };\n request.onerror = () => reject(request.error);\n request.onblocked = () => reject(Error(\"WhatsApp source history database is blocked\"));\n request.onsuccess = () => resolve(request.result);\n });\n let sourceRows;\n try {\n sourceRows = await new Promise((resolve, reject) => {\n const transaction = database.transaction(\"message\", \"readonly\");\n transaction.onabort = () => reject(transaction.error ?? Error(\"WhatsApp source read aborted\"));\n const index = transaction.objectStore(\"message\").index(\"rowId\"), range = before === null ? null : IDBKeyRange.upperBound(before, !0), request = index.openCursor(range, \"prev\"), rows = [];\n request.onerror = () => reject(request.error);\n request.onsuccess = () => {\n const cursor = request.result;\n if (!cursor) {\n resolve(rows);\n return;\n }\n if (!Number.isSafeInteger(cursor.key) || cursor.key <= 0 || typeof cursor.value.id !== \"string\") {\n reject(Error(\"WhatsApp source history has an unsupported key layout\"));\n return;\n }\n if (exactId !== null) {\n if (keyModule.fromString(cursor.value.id).id !== exactId) {\n cursor.continue();\n return;\n }\n resolve([{ position: cursor.key, id: cursor.value.id }]);\n return;\n }\n rows.push({ position: cursor.key, id: cursor.value.id });\n if (rows.length > (chatJid === null ? limit : 20000))\n resolve(rows);\n else\n cursor.continue();\n };\n });\n } finally {\n database.close();\n }\n let hasMore = sourceRows.length > limit, page = sourceRows.slice(0, limit), last = page[page.length - 1];\n if (chatJid !== null) {\n const examined = sourceRows.slice(0, 20000), canonical = new Map, matches = [];\n for (const row of examined) {\n const remote = keyModule.fromString(row.id).remote, raw = widString(remote);\n if (!canonical.has(raw))\n canonical.set(raw, (await canonicalJid(remote)).jid);\n if (canonical.get(raw) !== chatJid)\n continue;\n matches.push(row);\n if (matches.length > limit)\n break;\n }\n page = matches.slice(0, limit);\n hasMore = matches.length > limit || sourceRows.length > 20000;\n last = matches.length > limit ? page[page.length - 1] : examined[examined.length - 1];\n }\n const collections = requireFirst([\"WAWebCollections\"]), selected = [];\n for (const row of page) {\n const key = keyModule.fromString(row.id);\n if (exactId !== null && key.id !== exactId)\n continue;\n const remote = widString(key.remote);\n if (remote === \"status@broadcast\" || remote.endsWith(\"@newsletter\"))\n continue;\n const isGroup = remote.endsWith(\"@g.us\");\n if (chatFilter === \"group\" && !isGroup || chatFilter === \"individual\" && isGroup)\n continue;\n selected.push(row);\n }\n const results = [];\n if (selected.length) {\n const loaded = await collections.Msg.getMessagesById(selected.map((row) => row.id));\n if (loaded?.canceled || !Array.isArray(loaded?.messages))\n throw Error(\"Source message loading was canceled or unavailable\");\n const byKey = new Map(loaded.messages.map((model) => [String(model.id ?? modelData(model).id), model])), names = nameIndex(collections);\n for (const row of selected) {\n const model = byKey.get(row.id);\n if (!model)\n throw Error(\"Source message could not be loaded; retry the read\");\n const message = await normalizeMessage(model, \"snapshot\", collections, names);\n if (!message || message.timestamp <= 0)\n continue;\n if (exactId === null && chatJid === null && query && !`${message.body}\n${message.caption}`.toLowerCase().includes(query.toLowerCase()))\n continue;\n results.push(message);\n }\n }\n return {\n results,\n hasMore,\n ...hasMore ? { nextCursor: JSON.stringify({ v: 1, before: last.position, query, chat_filter: chatFilter, account }) } : {}\n };\n }\n async function searchMessages(input) {\n const collections = requireFirst([\"WAWebCollections\"]), query = String(input?.query ?? \"\").trim();\n if (!query)\n throw Error(\"query is required\");\n const offset = Math.max(0, Number(input?.offset) || 0), requestedLimit = Math.max(1, Math.min(Number(input?.limit) || 50, 100));\n if (offset >= 100)\n throw Error(\"WhatsApp source search supports only the first 100 matches\");\n const limit = Math.min(requestedLimit, 100 - offset), searchSourceLimit = 100, chatFilter = [\"all\", \"individual\", \"group\"].includes(input?.chat_filter) ? input.chat_filter : \"all\", chat = input?.chat_jid || input?.chat_name || input?.self_chat === !0 ? await resolveChat(collections, input) : null;\n let scopedChats = chat ? [chat] : void 0;\n if (!chat && chatFilter !== \"all\") {\n scopedChats = [];\n for (const candidate of models(collections.Chat)) {\n const jid = (await canonicalJid(modelData(candidate).id ?? candidate?.id)).jid;\n if (!jid || jid === \"status@broadcast\" || jid.endsWith(\"@newsletter\"))\n continue;\n const isGroup = jid.endsWith(\"@g.us\");\n if (chatFilter === \"group\" ? isGroup : !isGroup)\n scopedChats.push(candidate);\n }\n }\n const search = requireFirst([\n \"WAWebChatMessageSearch\",\n \"WAWebMessageSearch\",\n \"WAWebSearchMessages\"\n ]);\n let found = null;\n for (const fn of [\n search?.searchMessages,\n search?.searchMsgs,\n search?.search\n ]) {\n if (typeof fn !== \"function\")\n continue;\n try {\n found = await fn.call(search, query, scopedChats, searchSourceLimit);\n break;\n } catch {}\n }\n let source = \"whatsapp_fts\", candidates = Array.isArray(found) ? found : models(found?.messages ?? found);\n if (!found) {\n source = \"loaded_model_fallback\";\n const needle = query.toLowerCase();\n candidates = uniqueMessageModels(collections).filter((model) => {\n const row = modelData(model);\n if (chat) {\n const chatId = widString(modelData(chat).id ?? chat?.id);\n if (widString(row.id?.remote ?? row.chatId) !== chatId)\n return !1;\n }\n return String(row.body ?? row.caption ?? \"\").toLowerCase().includes(needle);\n });\n }\n const normalized = [], names = nameIndex(collections);\n for (const candidate of candidates) {\n const model = candidate?.msg ?? candidate?.message ?? candidate, message = await normalizeMessage(model, \"search\", collections, names);\n if (!message || Number(message.timestamp) <= 0)\n continue;\n if (chatFilter === \"group\" && !message.is_group)\n continue;\n if (chatFilter === \"individual\" && message.is_group)\n continue;\n normalized.push(message);\n if (normalized.length >= searchSourceLimit)\n break;\n }\n return {\n source,\n results: normalized.slice(offset, offset + limit),\n hasMore: offset + limit < normalized.length\n };\n }\n async function draftMessage(input, account) {\n const collections = requireFirst([\"WAWebCollections\"]), chat = await resolveChat(collections, input), text = String(input?.text ?? \"\");\n if (!text.trim())\n throw Error(\"text is required\");\n const draft = {\n body: text,\n timestamp: Math.floor(Date.now() / 1000),\n type: \"chat\",\n mentionedJidList: [],\n quotedMsg: null\n }, module2 = requireFirst(DRAFT_MODULES);\n let applied = !1;\n for (const fn of [\n module2?.setDraft,\n module2?.setChatDraft,\n module2?.saveDraft\n ]) {\n if (typeof fn !== \"function\")\n continue;\n try {\n assertAccount(account);\n await fn.call(module2, chat, draft);\n applied = !0;\n break;\n } catch {\n try {\n assertAccount(account);\n await fn.call(module2, draft, chat);\n applied = !0;\n break;\n } catch {}\n }\n }\n if (!applied && typeof chat?.setDraft === \"function\") {\n assertAccount(account);\n await chat.setDraft(draft);\n applied = !0;\n }\n if (!applied)\n throw Error(\"WhatsApp draft capability is unavailable in this web build\");\n const stored = modelData(chat).draft ?? chat.get?.(\"draft\") ?? null;\n if (!stored || typeof stored !== \"object\" || stored.body !== text)\n throw Error(\"WhatsApp rejected the persistent draft shape\");\n return {\n drafted: !0,\n sent: !1,\n chat_jid: widString(modelData(chat).id ?? chat?.id),\n draft\n };\n }\n async function sendMessage(input, account) {\n const collections = requireFirst([\"WAWebCollections\"]), chat = await resolveChat(collections, input), text = String(input?.text ?? \"\");\n if (!text.trim())\n throw Error(\"text is required\");\n const module2 = requireFirst(SEND_MODULES);\n if (typeof module2?.createTextMsgData === \"function\" && typeof module2?.addAndSendTextMsg === \"function\") {\n const data = await module2.createTextMsgData(chat, text), plannedId = rawId(data?.id);\n if (!plannedId)\n throw Error(\"WhatsApp did not assign an id to the outgoing message\");\n assertAccount(account);\n await module2.addAndSendTextMsg(chat, data);\n return {\n sent: !0,\n chat_jid: widString(modelData(chat).id ?? chat?.id),\n message_id: plannedId\n };\n }\n const fn = module2?.sendTextMsgToChat ?? module2?.sendMessage ?? chat?.sendMessage;\n if (typeof fn !== \"function\")\n throw Error(\"WhatsApp send capability is unavailable in this web build\");\n assertAccount(account);\n const result = fn === chat?.sendMessage ? await fn.call(chat, text) : await fn.call(module2, chat, text), messageId = rawId(modelData(result).id ?? result?.id);\n if (!messageId)\n throw Error(\"WhatsApp send acknowledgment has no raw message ID\");\n return {\n sent: !0,\n chat_jid: widString(modelData(chat).id ?? chat?.id),\n message_id: messageId\n };\n }\n function messageActionAllowed(message, predicateNames, legacyFlags) {\n const row = modelData(message);\n for (const flag of legacyFlags)\n if (row[flag] === !0)\n return !0;\n const capability = requireFirst([\"WAWebMsgActionCapability\"]);\n for (const name of predicateNames) {\n if (typeof capability?.[name] !== \"function\")\n continue;\n try {\n if (capability[name](message) === !0)\n return !0;\n } catch {}\n }\n return !1;\n }\n function resolveMessage(collections, id) {\n const raw = String(id ?? \"\").trim();\n if (!raw)\n throw Error(\"message_id is required\");\n const message = collectionByRawId(collections.Msg, raw);\n if (!message)\n throw Error(`WhatsApp message ${raw} is not loaded; read it with id:${raw} from the live messages feed or search it first`);\n return message;\n }\n async function editMessage(input, account) {\n const collections = requireFirst([\"WAWebCollections\"]), message = resolveMessage(collections, input?.message_id), before = modelData(message);\n if (!(before.id?.fromMe ?? before.fromMe))\n throw Error(\"WhatsApp only permits editing outgoing messages\");\n if (!messageActionAllowed(message, [\"canEditText\", \"canEditCaption\", \"canEnterEditingFlow\"], [\"canEdit\", \"isEditable\"]))\n throw Error(\"WhatsApp did not affirm that this message is currently editable\");\n const text = String(input?.text ?? \"\");\n if (!text.trim())\n throw Error(\"text is required\");\n const module2 = requireFirst(EDIT_MODULES), fn = module2?.sendMessageEdit ?? module2?.editMessage ?? message?.edit;\n if (typeof fn !== \"function\")\n throw Error(\"WhatsApp edit capability is unavailable in this web build\");\n assertAccount(account);\n await (fn === message?.edit ? fn.call(message, text) : fn.call(module2, message, text, {}));\n await waitForPostState(() => {\n const row = modelData(message);\n return row.body === text && Boolean(row.isEdited || row.editVersion || row.latestEditMsgKey);\n }, \"message edit\");\n return {\n edited: !0,\n message_id: rawId(modelData(message).id ?? message?.id)\n };\n }\n async function reactMessage(input, account) {\n const collections = requireFirst([\"WAWebCollections\"]), message = resolveMessage(collections, input?.message_id), emoji = input?.remove ? \"\" : String(input?.emoji ?? \"\");\n if (!input?.remove && !emoji)\n throw Error(\"emoji is required unless remove=true\");\n const module2 = requireFirst(REACTION_MODULES), fn = module2?.sendReactionToMsg ?? module2?.sendReaction ?? message?.react;\n if (typeof fn !== \"function\")\n throw Error(\"WhatsApp reaction capability is unavailable in this web build\");\n assertAccount(account);\n await (fn === message?.react ? fn.call(message, emoji) : fn.call(module2, message, emoji));\n await waitForPostState(() => {\n const row = modelData(message), reactions = normalizeReactions(row);\n if (reactions.length > 0)\n return input?.remove ? !reactions.some((reaction) => reaction.from_me) : reactions.some((reaction) => reaction.from_me && reaction.emoji === emoji);\n return input?.remove ? !0 : row.hasReaction === !0;\n }, \"reaction state\");\n return {\n reacted: !0,\n confirmed: input?.remove ? normalizeReactions(modelData(message)).length > 0 : !0,\n removed: Boolean(input?.remove),\n emoji: emoji || null,\n message_id: rawId(modelData(message).id ?? message?.id)\n };\n }\n async function revokeMessage(input, account) {\n const collections = requireFirst([\"WAWebCollections\"]), message = resolveMessage(collections, input?.message_id), before = modelData(message);\n if (!(before.id?.fromMe ?? before.fromMe))\n throw Error(\"WhatsApp only permits revoking outgoing messages\");\n if (!messageActionAllowed(message, [\"canSenderRevokeMsg\", \"canAdminRevokeMsg\"], [\"canRevoke\", \"isRevokable\"]))\n throw Error(\"WhatsApp did not affirm that this message is currently revokable\");\n const module2 = requireFirst(REVOKE_MODULES), fn = module2?.sendRevokeMsgs ?? module2?.sendRevoke ?? module2?.revokeMessage ?? message?.sendRevoke ?? message?.revoke;\n if (typeof fn !== \"function\")\n throw Error(\"WhatsApp revoke capability is unavailable in this web build\");\n assertAccount(account);\n if (fn === message?.sendRevoke || fn === message?.revoke)\n await fn.call(message);\n else\n await fn.call(module2, [message], modelData(message).id?.remote);\n await waitForPostState(() => {\n const row = modelData(message);\n return Boolean(row.isRevoked || row.revoked || row.type === \"revoked\");\n }, \"message revoke\");\n return {\n revoked: !0,\n message_id: rawId(modelData(message).id ?? message?.id)\n };\n }\n async function invoke(request) {\n try {\n if (Number(request?.adapter_version) !== 27)\n return {\n ok: !1,\n error: {\n state: \"adapter_mismatch\",\n reason: \"expected 27\"\n }\n };\n if (request.op === \"account_identity\") {\n const accountId = widString(meUser());\n return accountId ? { accountId } : null;\n }\n if (request.op === \"probe\") {\n const status = readiness();\n return status.ready ? { ok: !0, status, capabilities: operationCapabilities() } : { ok: !1, error: status };\n }\n assertAccount(request.account_id);\n const input = { ...request.input, account_id: request.account_id }, finish = async (promise) => {\n const value = await promise;\n assertAccount(request.account_id);\n return { ok: !0, ...value };\n };\n if (request.op === \"listen\")\n return listen(request);\n if (request.op === \"publish_changes\")\n return await publishChanges(request);\n if (request.op === \"observe_messages\")\n return await finish(observeMessages(input));\n if (operationCapabilities()[request.op] !== !0)\n return {\n ok: !1,\n error: {\n state: \"capability_unavailable\",\n reason: `${request.op} is unavailable in this WhatsApp Web build`\n }\n };\n if (request.op === \"read_messages\")\n return await finish(readMessages(input, request.account_id));\n if (request.op === \"search_messages\")\n return await finish(searchMessages(input));\n if (request.op === \"draft_message\")\n return await finish(draftMessage(input, request.account_id));\n if (request.op === \"send_message\")\n return await finish(sendMessage(input, request.account_id));\n if (request.op === \"edit_message\")\n return await finish(editMessage(input, request.account_id));\n if (request.op === \"react_message\")\n return await finish(reactMessage(input, request.account_id));\n if (request.op === \"revoke_message\")\n return await finish(revokeMessage(input, request.account_id));\n return {\n ok: !1,\n error: { state: \"unsupported_operation\", reason: String(request?.op) }\n };\n } catch (error) {\n if (request?.account_id && widString(meUser()) !== request.account_id)\n error = Error(\"WhatsApp saved account changed or is unavailable; reconnect this connection\");\n return {\n ok: !1,\n error: {\n state: \"operation_failed\",\n reason: error instanceof Error ? error.message : String(error)\n }\n };\n }\n }\n globalThis.__owlettoWhatsAppAdapterV1 = { version: 27, invoke, detach };\n })();\n for (let i = 0; i < 40; i++) {\n const identity = await globalThis.__owlettoWhatsAppAdapterV1.invoke({ op: \"account_identity\", adapter_version: 27 });\n if (identity?.accountId) return identity;\n await new Promise(resolve => setTimeout(resolve, 250));\n }\n return null;\n })()"
21545
21656
  }
21546
21657
  },
21547
21658
  "webhook": null,
@@ -21553,7 +21664,8 @@
21553
21664
  "webhook": {
21554
21665
  "mode": "trigger",
21555
21666
  "events": [
21556
- "message.created"
21667
+ "message.created",
21668
+ "source.gap"
21557
21669
  ]
21558
21670
  },
21559
21671
  "configSchema": {
@@ -21921,6 +22033,12 @@
21921
22033
  "capabilities": {
21922
22034
  "replyToSource": true
21923
22035
  }
22036
+ },
22037
+ {
22038
+ "key": "source.gap",
22039
+ "label": "Source history gap",
22040
+ "resourceType": "message",
22041
+ "description": "WhatsApp local history or an unresolved placeholder could not be recovered completely. Read retained messages separately; this is not a new message."
21924
22042
  }
21925
22043
  ],
21926
22044
  "options_schema": null,
@@ -22020,8 +22138,8 @@
22020
22138
  {
22021
22139
  "id": "x",
22022
22140
  "name": "X (Twitter)",
22023
- "version": "3.15.0",
22024
- "description": "Fetches tweets, browser-visible like history, bookmarks, and DMs through the X API v2 or the paired Owletto Chrome extension, reads the chronological Following timeline live through the X API, and reads and answers DMs live in the paired browser. Links social actors into the person graph.",
22141
+ "version": "3.16.0",
22142
+ "description": "Fetches tweets, browser-visible like history, bookmarks, and DMs through the X API v2 or the paired Owletto Chrome extension, reads the chronological Following timeline live through the X API, captures notification references, and reads and answers DMs live in the paired browser. Links social actors into the person graph.",
22025
22143
  "detail": {
22026
22144
  "source_path": "x.ts",
22027
22145
  "auth_schema": {
@@ -22079,6 +22197,20 @@
22079
22197
  },
22080
22198
  "webhook": null,
22081
22199
  "feeds_schema": {
22200
+ "notifications": {
22201
+ "key": "notifications",
22202
+ "name": "Notifications",
22203
+ "description": "Read the signed-in account's retained All notifications timeline and capture metadata-only references without opening the notification panel or marking items seen. Includes source-exposed grouped reactions/follows and post entries; source icon categories are retained. History is limited by X. For post entries the source date is post creation time, not an invented notification time. Requires browser authentication; this is not OS push interception.",
22204
+ "eventKinds": {
22205
+ "notification": {
22206
+ "description": "A metadata-only reference to an X notification timeline item"
22207
+ }
22208
+ },
22209
+ "operations": [
22210
+ "sync",
22211
+ "read"
22212
+ ]
22213
+ },
22082
22214
  "live_messages": {
22083
22215
  "key": "live_messages",
22084
22216
  "name": "Live messages",
@@ -23513,6 +23645,10 @@
23513
23645
  {
23514
23646
  "key": "dm_message",
23515
23647
  "label": "DM Message"
23648
+ },
23649
+ {
23650
+ "key": "notification",
23651
+ "label": "Notification"
23516
23652
  }
23517
23653
  ],
23518
23654
  "options_schema": null,