@lobu/runtime-server 22.0.0 → 23.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/catalogs/connectors.json +1353 -181
- package/dist/catalogs/skills.json +1 -1
- package/dist/component.json +1 -1
- package/dist/connectors/README.md +14 -1
- package/dist/connectors/google_gmail.ts +1 -0
- package/dist/connectors/jira-helpers.ts +313 -0
- package/dist/connectors/jira.ts +29 -221
- package/dist/connectors/linkedin-browser-script.ts +13 -0
- package/dist/connectors/linkedin-draft-page.js +104 -0
- package/dist/connectors/linkedin-drafts.ts +73 -0
- package/dist/connectors/linkedin-identity.ts +32 -0
- package/dist/connectors/linkedin-inbox-adapter.js +1185 -0
- package/dist/connectors/linkedin-inbox.ts +156 -0
- package/dist/connectors/linkedin-like.ts +114 -0
- package/dist/connectors/linkedin-takeout.ts +577 -0
- package/dist/connectors/linkedin.ts +3998 -0
- package/dist/connectors/takeout-utils.ts +240 -0
- package/dist/connectors/tiktok-inbox-page.js +9 -9
- package/dist/connectors/tiktok-web-page.js +21 -15
- package/dist/connectors/tiktok_web.ts +63 -30
- package/dist/connectors/whatsapp-web-adapter.js +64 -564
- package/dist/connectors/whatsapp-web-helpers.ts +30 -444
- package/dist/connectors/whatsapp-web-identity.ts +20 -6
- package/dist/connectors/whatsapp_web.ts +45 -645
- package/dist/connectors/x-dm-adapter.js +556 -0
- package/dist/connectors/x-identity.ts +31 -2
- package/dist/connectors/x.ts +266 -120
- package/dist/db/migrations/20261017120000_drop_feeds_kind_virtual.sql +26 -0
- package/dist/db/migrations/20261017130000_drop_retired_dead_code_columns.sql +46 -0
- package/dist/dependencies.bun.lock +41 -41
- package/dist/guest.bundle.js +288 -148
- package/dist/owletto/dist/assets/_-3J-IrxWk.js +2 -0
- package/dist/owletto/dist/assets/{_-CEPl6gU4.js → _-DYUE3ix4.js} +3 -3
- package/dist/owletto/dist/assets/_agentId-Bn2IAjIy.js +2 -0
- package/dist/owletto/dist/assets/{_agentId-CBC_SadO.js → _agentId-Cam7Z0N7.js} +2 -2
- package/dist/owletto/dist/assets/{_automationId-YTTNksw6.js → _automationId-CXEiKVZJ.js} +2 -2
- package/dist/owletto/dist/assets/{_connectorKey._connectionId-fK0h7RAp.js → _connectorKey._connectionId-CS85l61t.js} +2 -2
- package/dist/owletto/dist/assets/{_connectorKey.index-C7TPS598.js → _connectorKey.index-clVDIyW0.js} +2 -2
- package/dist/owletto/dist/assets/{_conversationId-CEhxlTIo.js → _conversationId-Ci2k-BuN.js} +2 -2
- package/dist/owletto/dist/assets/{_deploymentId-BQfYN1U2.js → _deploymentId-BuUzGtVL.js} +2 -2
- package/dist/owletto/dist/assets/{_eventId-Cl8GSdjg.js → _eventId-B0662F8h.js} +2 -2
- package/dist/owletto/dist/assets/_name-CwWePlOl.js +2 -0
- package/dist/owletto/dist/assets/{_owner-cUtGHqSw.js → _owner-dTWkrKsK.js} +3 -3
- package/dist/owletto/dist/assets/_shape-BtS3y4M9.js +2 -0
- package/dist/owletto/dist/assets/_skillKey-Dc9m-nlR.js +2 -0
- package/dist/owletto/dist/assets/{_slug-CU1PuHB9.js → _slug-DQHutM41.js} +2 -2
- package/dist/owletto/dist/assets/_viewKey-B30ik8ma.js +2 -0
- package/dist/owletto/dist/assets/_viewKey-CUHypQnF.js +2 -0
- package/dist/owletto/dist/assets/{accept-invitation-D3OgJG4i.js → accept-invitation-w17IFTtf.js} +2 -2
- package/dist/owletto/dist/assets/{activity-route-view-DQglkhXU.js → activity-route-view-CMqYiiKM.js} +2 -2
- package/dist/owletto/dist/assets/{agent-card-controls-DzRs4Ix9.js → agent-card-controls-mnTN2AZt.js} +2 -2
- package/dist/owletto/dist/assets/{agent-client-setup-list-B2SvH7xD.js → agent-client-setup-list-Bg3hBfUV.js} +2 -2
- package/dist/owletto/dist/assets/{agent-connect-pages-B6uKvT_X.js → agent-connect-pages-B_vrqLVc.js} +2 -2
- package/dist/owletto/dist/assets/{agent-editor-form-oUnIYHd7.js → agent-editor-form-hTs7eO_U.js} +2 -2
- package/dist/owletto/dist/assets/{agent-guardrails-route-BaV1VpDh.js → agent-guardrails-route-BOrCXcAl.js} +2 -2
- package/dist/owletto/dist/assets/{agent-loading-shells-CtZJM2Gc.js → agent-loading-shells-Dqcvky-k.js} +2 -2
- package/dist/owletto/dist/assets/{agent-permissions-matrix-Ds48KFK9.js → agent-permissions-matrix-BOo_4r_4.js} +2 -2
- package/dist/owletto/dist/assets/{agent-skill-context-DPk5r08w.js → agent-skill-context-CCdvtlmH.js} +2 -2
- package/dist/owletto/dist/assets/{agent-skills-route-DYpB5H1J.js → agent-skills-route-BUxIswuq.js} +2 -2
- package/dist/owletto/dist/assets/{agent-subpage-shell-B3K_jPYR.js → agent-subpage-shell-D92imvSt.js} +2 -2
- package/dist/owletto/dist/assets/agent-thread-BJOijbT0.js +6 -0
- package/dist/owletto/dist/assets/agents-9XjpDj_S.js +2 -0
- package/dist/owletto/dist/assets/{agents-workbench-CMyk4PI7.js → agents-workbench-Bt5QCYQ7.js} +2 -2
- package/dist/owletto/dist/assets/{app._appId-DH1Qutz6.js → app._appId-CKv7_squ.js} +2 -2
- package/dist/owletto/dist/assets/{automation-detail-content-CEDNboId.js → automation-detail-content-vUwVumXf.js} +2 -2
- package/dist/owletto/dist/assets/automations-9XjpDj_S.js +2 -0
- package/dist/owletto/dist/assets/{callback-CU-hb8JB.js → callback-BRgcL8gz.js} +2 -2
- package/dist/owletto/dist/assets/{card-DIF8SF9b.js → card-Djgp00r_.js} +2 -2
- package/dist/owletto/dist/assets/{claim-DELEa-gH.js → claim-BYUZnyMp.js} +2 -2
- package/dist/owletto/dist/assets/{clients-CpG676mg.js → clients-D3Zbjxin.js} +2 -2
- package/dist/owletto/dist/assets/{code-editor-V27Z4o3P.js → code-editor-DHeyRGZI.js} +2 -2
- package/dist/owletto/dist/assets/connect-CfsFsy9P.js +2 -0
- package/dist/owletto/dist/assets/connect._clientId-DkiC8xos.js +2 -0
- package/dist/owletto/dist/assets/connected._clientId-CIXrGOsT.js +2 -0
- package/dist/owletto/dist/assets/{connected._clientId.activity-DQWcUqKM.js → connected._clientId.activity-Ckdz6I0y.js} +2 -2
- package/dist/owletto/dist/assets/{connected._clientId.index-BC3R303A.js → connected._clientId.index-CNxafNeo.js} +2 -2
- package/dist/owletto/dist/assets/{connection-DySpRE9x.js → connection-C3XXFEqh.js} +2 -2
- package/dist/owletto/dist/assets/{connection-feed-detail-C_D68j6d.js → connection-feed-detail-CIJJLDP8.js} +2 -2
- package/dist/owletto/dist/assets/{connections-browser-Cnv2iBbZ.js → connections-browser-CKZjzRz6.js} +2 -2
- package/dist/owletto/dist/assets/{connector-provenance-CNXtzYg5.js → connector-provenance-8-d8hl10.js} +2 -2
- package/dist/owletto/dist/assets/{connector-scope-lists-BKDetNDc.js → connector-scope-lists-CadPVsI3.js} +2 -2
- package/dist/owletto/dist/assets/{connectors-BJnk1z_2.js → connectors-lvLJ30lo.js} +2 -2
- package/dist/owletto/dist/assets/{consent-BVzxrAO9.js → consent-CdSvVCgx.js} +2 -2
- package/dist/owletto/dist/assets/{conversations-table-DfZGICl7.js → conversations-table-BdXoZAfc.js} +2 -2
- package/dist/owletto/dist/assets/{core.esm-DiTpULFl.js → core.esm-CYvgWCuv.js} +2 -2
- package/dist/owletto/dist/assets/create-0xW9eXxG.js +2 -0
- package/dist/owletto/dist/assets/{create-JRFM8mMf.js → create-B0qhrrX4.js} +2 -2
- package/dist/owletto/dist/assets/create-CAfF-yI1.js +2 -0
- package/dist/owletto/dist/assets/create-automation-form-CtSSeYj3.js +3 -0
- package/dist/owletto/dist/assets/create._connectorKey-i6xxkWKV.js +2 -0
- package/dist/owletto/dist/assets/{cronstrue-DPXl0qA2.js → cronstrue-n4qGUraE.js} +2 -2
- package/dist/owletto/dist/assets/deployments-4Itm35Xc.js +2 -0
- package/dist/owletto/dist/assets/{deployments-DCQdFdwG.js → deployments-RvUdVkj3.js} +2 -2
- package/dist/owletto/dist/assets/{deployments-body-D6TAWs_6.js → deployments-body-BMp7UsMo.js} +2 -2
- package/dist/owletto/dist/assets/{device-CntqYW65.js → device-CPU6CjkJ.js} +2 -2
- package/dist/owletto/dist/assets/{device-pin-tombstone-Bz4JHHMK.js → device-pin-tombstone-CrjG7gPo.js} +2 -2
- package/dist/owletto/dist/assets/{device._deviceId-D4plO3GM.js → device._deviceId-Cs3ZmXWo.js} +2 -2
- package/dist/owletto/dist/assets/{entity-options-UJs64GdQ.js → entity-options-uXjgT7y9.js} +2 -2
- package/dist/owletto/dist/assets/{entity-page-Djz6T50J.js → entity-page-Dc0LGr5U.js} +2 -2
- package/dist/owletto/dist/assets/{entity-type-page-OznRag6A.js → entity-type-page-CwZxa0BR.js} +2 -2
- package/dist/owletto/dist/assets/{event-detail-04qOUGIP.js → event-detail-ve2d6Gbb.js} +2 -2
- package/dist/owletto/dist/assets/{events-feed-fucGZSJR.js → events-feed-BtvhZF1f.js} +2 -2
- package/dist/owletto/dist/assets/{filter-editors-DCQgGLyR.js → filter-editors-Cj-v6NtH.js} +2 -2
- package/dist/owletto/dist/assets/{full-page-spinner-KpV2FS2u.js → full-page-spinner-DqpH99np.js} +2 -2
- package/dist/owletto/dist/assets/guardrails-HFo2Ut8B.js +2 -0
- package/dist/owletto/dist/assets/identity-BigVSBCl.js +2 -0
- package/dist/owletto/dist/assets/{index-BEvyBdOU.js → index-B9uPN6FC.js} +2 -2
- package/dist/owletto/dist/assets/{index-BNh2cidi.js → index-BQVliQW1.js} +2 -2
- package/dist/owletto/dist/assets/index-BfedB4Rc.js +2 -0
- package/dist/owletto/dist/assets/index-CUw3aKBI.js +2 -0
- package/dist/owletto/dist/assets/index-CXhxUkv3.js +2 -0
- package/dist/owletto/dist/assets/{index-_oPeVpL_.js → index-Cr5hwh-C.js} +66 -66
- package/dist/owletto/dist/assets/index-CzkTV4ZQ.js +2 -0
- package/dist/owletto/dist/assets/index-DKSx8JN_.js +2 -0
- package/dist/owletto/dist/assets/{index-D3s8rhG9.js → index-DVk7Ug0d.js} +2 -2
- package/dist/owletto/dist/assets/index-DmZuKGf8.js +2 -0
- package/dist/owletto/dist/assets/{index-DCdkwg9H.js → index-Hio-HRfo.js} +2 -2
- package/dist/owletto/dist/assets/{index-BJXkc60S.js → index-ICgKp3YK.js} +2 -2
- package/dist/owletto/dist/assets/index-cPcroOH0.js +2 -0
- package/dist/owletto/dist/assets/{index-BOzuAbvi.js → index-n7sTbNv4.js} +2 -2
- package/dist/owletto/dist/assets/index-xiFpcWKv.js +2 -0
- package/dist/owletto/dist/assets/{json-diff-D_Ym3Uku.js → json-diff-DBoag_OS.js} +2 -2
- package/dist/owletto/dist/assets/{list-skeleton-Bl0OS39L.js → list-skeleton-C_GuoxAH.js} +2 -2
- package/dist/owletto/dist/assets/{login-QHdxqX-4.js → login-Ci6ixHuL.js} +2 -2
- package/dist/owletto/dist/assets/{logout-DUccApuZ.js → logout-CLGgeZB7.js} +2 -2
- package/dist/owletto/dist/assets/{member-scope-gate-CFbrq1by.js → member-scope-gate-B44INDPY.js} +2 -2
- package/dist/owletto/dist/assets/{memory-browse-page-IrIXuZTF.js → memory-browse-page-DyQiRvzl.js} +2 -2
- package/dist/owletto/dist/assets/{model-selector-CB1BDvlW.js → model-selector-dAbDgJvx.js} +2 -2
- package/dist/owletto/dist/assets/models-DpVP7ZwX.js +2 -0
- package/dist/owletto/dist/assets/{new-BWo8_Pms.js → new-BUb7AnEW.js} +2 -2
- package/dist/owletto/dist/assets/{new-B5UsLiy6.js → new-BkdULx2r.js} +2 -2
- package/dist/owletto/dist/assets/{new-DpmDXmFI.js → new-CHOr-EcI.js} +2 -2
- package/dist/owletto/dist/assets/{oauth-workspace-access-PGyTnW2K.js → oauth-workspace-access-BxsjwgdH.js} +2 -2
- package/dist/owletto/dist/assets/{organization-BH8PYlVu.js → organization-gxGeDjIV.js} +2 -2
- package/dist/owletto/dist/assets/{peek-pane-content-B2AFNTzP.js → peek-pane-content-CHoQHe2H.js} +2 -2
- package/dist/owletto/dist/assets/{permissions-CwN_YP3u.js → permissions-aPHaKLec.js} +2 -2
- package/dist/owletto/dist/assets/{proposal-review-shell-DKKGu4Ww.js → proposal-review-shell-UcZr87_Q.js} +2 -2
- package/dist/owletto/dist/assets/public-shell-ready-DcnlADmj.js +2 -0
- package/dist/owletto/dist/assets/{recent-DqdZE_TI.js → recent-D-65Pgu-.js} +2 -2
- package/dist/owletto/dist/assets/{record-activity-CvgZyCmw.js → record-activity-CBXH6v1d.js} +2 -2
- package/dist/owletto/dist/assets/{renderer-BL6VcwQH.js → renderer-mEDnVW0O.js} +2 -2
- package/dist/owletto/dist/assets/{reset-password-DAvBYkiI.js → reset-password-uX_V6bip.js} +2 -2
- package/dist/owletto/dist/assets/{runs-BWtc5rmc.js → runs-C0rCgGwX.js} +2 -2
- package/dist/owletto/dist/assets/runs-panel-Du1JMjg5.js +2 -0
- package/dist/owletto/dist/assets/{runs-table-DxIiqrSk.js → runs-table-syPJ6r6T.js} +2 -2
- package/dist/owletto/dist/assets/{settings-Crxlwps-.js → settings-9NkNA1G1.js} +2 -2
- package/dist/owletto/dist/assets/settings-E-10sLQX.js +2 -0
- package/dist/owletto/dist/assets/skills-D2Ri9b4f.js +2 -0
- package/dist/owletto/dist/assets/{source-record-panels-CRIPMWfN.js → source-record-panels-CPyzlfD1.js} +2 -2
- package/dist/owletto/dist/assets/{status-dot-C5KDvvm9.js → status-dot-B-EWMgq6.js} +2 -2
- package/dist/owletto/dist/assets/{tabs-B4Er9hJj.js → tabs-DqIIkCX-.js} +2 -2
- package/dist/owletto/dist/assets/{use-mention-search-DqEykWl_.js → use-mention-search-By8RZyKW.js} +2 -2
- package/dist/owletto/dist/assets/{view-param-filters-Cylutoy1.js → view-param-filters-CqLZQrnO.js} +2 -2
- package/dist/owletto/dist/index.html +1 -1
- package/dist/server-main.bundle.mjs +11447 -10762
- package/npm-shrinkwrap.json +160 -160
- package/package.json +1 -1
- package/vendor/connector-sdk/dist/browser-handoff-banner.d.ts +39 -0
- package/vendor/connector-sdk/dist/browser-handoff-banner.js +175 -0
- package/vendor/connector-sdk/dist/browser-source-read.d.ts +52 -0
- package/vendor/connector-sdk/dist/browser-source-read.js +107 -0
- package/vendor/connector-sdk/dist/connector-types.d.ts +10 -0
- package/vendor/connector-sdk/dist/index.d.ts +3 -0
- package/vendor/connector-sdk/dist/index.js +2 -0
- package/vendor/connector-sdk/package.json +9 -1
- package/vendor/core/dist/capabilities.d.ts +1 -1
- package/vendor/core/dist/capabilities.js +0 -1
- package/vendor/core/dist/connector-query-errors.d.ts +32 -0
- package/vendor/core/dist/connector-query-errors.js +41 -1
- package/vendor/core/dist/contracts/tools/manage-conversations.js +2 -2
- package/vendor/core/dist/contracts/tools/manage-feeds.d.ts +14 -0
- package/vendor/core/dist/contracts/tools/manage-feeds.js +17 -0
- package/vendor/core/dist/contracts/worker/protocol.d.ts +8 -131
- package/vendor/core/dist/contracts/worker/protocol.js +9 -61
- package/vendor/core/dist/device-pin-tombstones.d.ts +44 -0
- package/vendor/core/dist/device-pin-tombstones.js +57 -0
- package/vendor/core/dist/index.d.ts +2 -1
- package/vendor/core/dist/index.js +1 -0
- package/vendor/core/dist/logger.js +10 -25
- package/vendor/core/dist/utils/diagnostic-scrubber.js +258 -21
- package/vendor/core/dist/worker/wire.d.ts +0 -10
- package/vendor/core/package.json +6 -6
- package/vendor/views/package.json +1 -1
- package/dist/owletto/dist/assets/_-C_zNZben.js +0 -2
- package/dist/owletto/dist/assets/_agentId-QQW91cHX.js +0 -2
- package/dist/owletto/dist/assets/_name-t3oBJ6Zf.js +0 -2
- package/dist/owletto/dist/assets/_shape-bo2lMVCu.js +0 -2
- package/dist/owletto/dist/assets/_skillKey-Dwm4Q4wI.js +0 -2
- package/dist/owletto/dist/assets/_viewKey-Bh6E_NxA.js +0 -2
- package/dist/owletto/dist/assets/_viewKey-D4jKl-Zf.js +0 -2
- package/dist/owletto/dist/assets/agent-thread-C8UaUTWc.js +0 -6
- package/dist/owletto/dist/assets/agents-F4mGI2oF.js +0 -2
- package/dist/owletto/dist/assets/automations-F4mGI2oF.js +0 -2
- package/dist/owletto/dist/assets/connect-B2YL6qIK.js +0 -2
- package/dist/owletto/dist/assets/connect._clientId-B6LDmDRV.js +0 -2
- package/dist/owletto/dist/assets/connected._clientId-D_HaKoI1.js +0 -2
- package/dist/owletto/dist/assets/create-CUqO6Kfk.js +0 -2
- package/dist/owletto/dist/assets/create-automation-form-_4vUkrls.js +0 -3
- package/dist/owletto/dist/assets/create-iHcxV0xd.js +0 -2
- package/dist/owletto/dist/assets/create._connectorKey-CCYLEicg.js +0 -2
- package/dist/owletto/dist/assets/deployments-ihkhK1zV.js +0 -2
- package/dist/owletto/dist/assets/guardrails-molekzAF.js +0 -2
- package/dist/owletto/dist/assets/identity-BJcaG66g.js +0 -2
- package/dist/owletto/dist/assets/index-B04ON9Jv.js +0 -2
- package/dist/owletto/dist/assets/index-BOsK-K-2.js +0 -2
- package/dist/owletto/dist/assets/index-Bk1x7A67.js +0 -2
- package/dist/owletto/dist/assets/index-CFnx5huL.js +0 -2
- package/dist/owletto/dist/assets/index-Dbd1jusf.js +0 -2
- package/dist/owletto/dist/assets/index-DqZuqC08.js +0 -2
- package/dist/owletto/dist/assets/index-Dr-Xg_xO.js +0 -2
- package/dist/owletto/dist/assets/index-KPOvMVa-.js +0 -2
- package/dist/owletto/dist/assets/models-DnMb3n-Z.js +0 -2
- package/dist/owletto/dist/assets/public-shell-ready-7KYnww6e.js +0 -2
- package/dist/owletto/dist/assets/runs-panel-BO3h5RkS.js +0 -2
- package/dist/owletto/dist/assets/settings-4Ev-0iNL.js +0 -2
- package/dist/owletto/dist/assets/skills-D0X430X8.js +0 -2
- package/vendor/core/dist/contracts/worker/device-chat.d.ts +0 -4
- package/vendor/core/dist/contracts/worker/device-chat.js +0 -26
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Ported from the Owletto extension's whatsapp-web-main-v1.js. WhatsApp's
|
|
5
5
|
* normalization and action code retain the extension implementation; the
|
|
6
|
-
* connector-owned feed listener below
|
|
7
|
-
* through the generic browser transport.
|
|
8
|
-
* reaches into WhatsApp's own module registry via window.require
|
|
9
|
-
*
|
|
6
|
+
* connector-owned feed listener below observes new messages and emits
|
|
7
|
+
* references only (never content) through the generic browser transport. It
|
|
8
|
+
* reaches into WhatsApp's own module registry via window.require; those private
|
|
9
|
+
* module shapes are load-bearing.
|
|
10
10
|
*
|
|
11
11
|
* How it gets into the page: the connector serialises this function with
|
|
12
12
|
* Function.prototype.toString() and runs `(<source>)()` through the generic
|
|
@@ -33,7 +33,7 @@ export function whatsAppWebAdapterProgram() {
|
|
|
33
33
|
// when this number moves: shipping a fix under the old number leaves every
|
|
34
34
|
// already-open tab running the previous code with nothing to show for it.
|
|
35
35
|
// Keep in lockstep with WHATSAPP_ADAPTER_VERSION in whatsapp-web-helpers.ts.
|
|
36
|
-
const ADAPTER_VERSION =
|
|
36
|
+
const ADAPTER_VERSION = 25;
|
|
37
37
|
const SOURCE_ERROR_ID = "whatsapp-web:source-observation-error";
|
|
38
38
|
const MAX_RECORD_BYTES = 128 * 1024;
|
|
39
39
|
const MAX_BUFFER_BYTES = 16 * 1024 * 1024;
|
|
@@ -91,8 +91,7 @@ export function whatsAppWebAdapterProgram() {
|
|
|
91
91
|
});
|
|
92
92
|
};
|
|
93
93
|
const resident = listeners.get(request.bridge_id);
|
|
94
|
-
const previous = resident?.request.
|
|
95
|
-
&& resident?.request.chat_filter === request.chat_filter
|
|
94
|
+
const previous = resident?.request.chat_filter === request.chat_filter
|
|
96
95
|
&& resident?.request.minimum_timestamp === request.minimum_timestamp ? resident : null;
|
|
97
96
|
detach(request.bridge_id);
|
|
98
97
|
// A new listener identity fences pending normalization from the detached
|
|
@@ -109,19 +108,17 @@ export function whatsAppWebAdapterProgram() {
|
|
|
109
108
|
state.token = request.token;
|
|
110
109
|
state.request = request;
|
|
111
110
|
state.post = (entry) => post(state, entry);
|
|
112
|
-
const observe = (model
|
|
111
|
+
const observe = (model) => {
|
|
113
112
|
if (state.error) return;
|
|
114
113
|
const sequence = ++state.sequence;
|
|
115
|
-
|
|
116
|
-
|
|
114
|
+
// A throwing model getter must reach the error record below, not escape
|
|
115
|
+
// the collection handler, so the reference is read inside the promise.
|
|
116
|
+
void new Promise((resolve) => resolve(messageReference(model))).then((record) => {
|
|
117
117
|
if (listeners.get(state.id) !== state || !record || record.timestamp <= 0) return;
|
|
118
118
|
if (state.request.chat_filter === "group" && !record.is_group) return;
|
|
119
119
|
if (state.request.chat_filter === "individual" && record.is_group) return;
|
|
120
120
|
if (state.request.minimum_timestamp != null && record.timestamp < state.request.minimum_timestamp) return;
|
|
121
|
-
|
|
122
|
-
// still pass; they are exactly what the recent collection window misses.
|
|
123
|
-
if (kind === "add" && record.timestamp < state.request.recent_since) return;
|
|
124
|
-
if (request.references_only) record = {
|
|
121
|
+
record = {
|
|
125
122
|
id: record.id,
|
|
126
123
|
events: [{ id: record.id, event_type: "message.created", resource_ref: record.id,
|
|
127
124
|
resource_type: "message", occurred_at: new Date(record.timestamp * 1000).toISOString() }],
|
|
@@ -154,8 +151,8 @@ export function whatsAppWebAdapterProgram() {
|
|
|
154
151
|
reportError(state, "WhatsApp source observation failed; recovery is required", sequence);
|
|
155
152
|
});
|
|
156
153
|
};
|
|
157
|
-
state.onAdd = (model) => observe(model
|
|
158
|
-
state.onChange = (model) => observe(model
|
|
154
|
+
state.onAdd = (model) => observe(model);
|
|
155
|
+
state.onChange = (model) => observe(model);
|
|
159
156
|
state.onReply = (event) => {
|
|
160
157
|
if (event.source !== window || event.origin !== location.origin || event.data?.token !== state.token) return;
|
|
161
158
|
if (event.data.type === "lobu-feed-record:stop") { detach(state.id); return; }
|
|
@@ -191,7 +188,7 @@ export function whatsAppWebAdapterProgram() {
|
|
|
191
188
|
// not server delivery: the server advances the cursor only with its own commit.
|
|
192
189
|
async function publishChanges(request) {
|
|
193
190
|
const state = listeners.get(request.bridge_id);
|
|
194
|
-
if (!state
|
|
191
|
+
if (!state || state.token !== request.token) throw new Error("Source listener is unavailable");
|
|
195
192
|
const record = request.batch;
|
|
196
193
|
const bytes = new TextEncoder().encode(JSON.stringify(record)).length;
|
|
197
194
|
const previous = state.pending.get(record.id);
|
|
@@ -266,6 +263,50 @@ export function whatsAppWebAdapterProgram() {
|
|
|
266
263
|
return null;
|
|
267
264
|
}
|
|
268
265
|
|
|
266
|
+
/**
|
|
267
|
+
* Every canonical form of the account's own identity. `meUser()` prefers
|
|
268
|
+
* the phone-number WID, but a group can address a member by its LID WID
|
|
269
|
+
* instead, so a mention or a quote of the account must match either form.
|
|
270
|
+
*/
|
|
271
|
+
async function ownJids() {
|
|
272
|
+
const module = requireFirst(["WAWebUserPrefsMeUser"]);
|
|
273
|
+
const candidates = [meUser()];
|
|
274
|
+
for (const accessor of ["getMaybeMePnUser", "getMaybeMeLidUser"]) {
|
|
275
|
+
try {
|
|
276
|
+
candidates.push(module?.[accessor]?.());
|
|
277
|
+
} catch {
|
|
278
|
+
/* WhatsApp's private module graph throws freely; a miss is not fatal. */
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
const forms = new Set();
|
|
282
|
+
for (const value of candidates) {
|
|
283
|
+
const own = await canonicalJid(value);
|
|
284
|
+
if (own.jid) forms.add(own.jid);
|
|
285
|
+
if (own.lid) forms.add(own.lid);
|
|
286
|
+
}
|
|
287
|
+
return forms;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Whether a message addresses the account: it @mentions the account, or it
|
|
292
|
+
* replies to (quotes) one of the account's messages.
|
|
293
|
+
*/
|
|
294
|
+
async function mentionsOwnAccount(row) {
|
|
295
|
+
const addressed = [
|
|
296
|
+
...(Array.isArray(row.mentionedJidList) ? row.mentionedJidList : []),
|
|
297
|
+
row.quotedParticipant,
|
|
298
|
+
].filter(Boolean);
|
|
299
|
+
if (addressed.length === 0) return false;
|
|
300
|
+
const own = await ownJids();
|
|
301
|
+
for (const value of addressed) {
|
|
302
|
+
const candidate = await canonicalJid(value);
|
|
303
|
+
if (own.has(candidate.jid) || (candidate.lid && own.has(candidate.lid))) {
|
|
304
|
+
return true;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
return false;
|
|
308
|
+
}
|
|
309
|
+
|
|
269
310
|
/**
|
|
270
311
|
* Module names for each write op, most-current first.
|
|
271
312
|
*
|
|
@@ -484,20 +525,8 @@ export function whatsAppWebAdapterProgram() {
|
|
|
484
525
|
}
|
|
485
526
|
|
|
486
527
|
/**
|
|
487
|
-
*
|
|
488
|
-
*
|
|
489
|
-
* `normalizeMessage` runs per message and used to walk a whole collection on
|
|
490
|
-
* each call -- the chat name over 947 chats, the sender name over 5323
|
|
491
|
-
* contacts. That is O(messages x collection) of SYNCHRONOUS work: measured on
|
|
492
|
-
* a live prod tab the contact scan alone projects to ~6.8s, a real collect
|
|
493
|
-
* never yielded the main thread, and the extension's 90s run fence killed the
|
|
494
|
-
* run. Every run was slower than the last as backfill grew the store.
|
|
495
|
-
*
|
|
496
|
-
* Built once per collect and thrown away with it -- no cache to invalidate,
|
|
497
|
-
* and nothing here outlives the call. Only names are indexed: they read
|
|
498
|
-
* static fields, whereas `collectionByRawId` serves the reaction paths, which
|
|
499
|
-
* mutate a model in place without changing the collection, so that one keeps
|
|
500
|
-
* scanning.
|
|
528
|
+
* Build name lookups once per read or search so normalizing each message
|
|
529
|
+
* does not rescan every chat and contact. Nothing here outlives the call.
|
|
501
530
|
*/
|
|
502
531
|
function nameIndex(collections) {
|
|
503
532
|
const byId = (collection) => {
|
|
@@ -545,8 +574,7 @@ export function whatsAppWebAdapterProgram() {
|
|
|
545
574
|
const collections =
|
|
546
575
|
collectionsOverride ?? requireFirst(["WAWebCollections"]);
|
|
547
576
|
if (!collections) return null;
|
|
548
|
-
//
|
|
549
|
-
// in so the whole run shares it.
|
|
577
|
+
// Reads and searches share one name index across their result batch.
|
|
550
578
|
const nameLookup = names ?? nameIndex(collections);
|
|
551
579
|
let row = modelData(model);
|
|
552
580
|
let key = row.id ?? model?.id;
|
|
@@ -623,6 +651,7 @@ export function whatsAppWebAdapterProgram() {
|
|
|
623
651
|
: null,
|
|
624
652
|
media_filename: row.filename ?? row.fileName ?? row.title ?? null,
|
|
625
653
|
quoted_id: quotedId,
|
|
654
|
+
mentions_me: await mentionsOwnAccount(row),
|
|
626
655
|
is_forwarded: Boolean(row.isForwarded || Number(row.forwardingScore) > 0),
|
|
627
656
|
is_starred: Boolean(row.star ?? row.isStarred),
|
|
628
657
|
is_system_event: SYSTEM_TYPES.has(type),
|
|
@@ -671,7 +700,7 @@ export function whatsAppWebAdapterProgram() {
|
|
|
671
700
|
// Socket.stream was DISCONNECTED, then both were CONNECTED after reload.
|
|
672
701
|
// Current WhatsApp exposes account and transport state separately. An
|
|
673
702
|
// authenticated account can retain hydrated stores while its stream is
|
|
674
|
-
// disconnected; those cached messages are not a successful live
|
|
703
|
+
// disconnected; those cached messages are not a successful live read.
|
|
675
704
|
const socket = requireFirst(["WAWebSocketModel"])?.Socket;
|
|
676
705
|
const connection =
|
|
677
706
|
socket ??
|
|
@@ -776,7 +805,6 @@ export function whatsAppWebAdapterProgram() {
|
|
|
776
805
|
}
|
|
777
806
|
|
|
778
807
|
function operationCapabilities() {
|
|
779
|
-
const history = requireFirst(["WAWebChatLoadMessages"]);
|
|
780
808
|
const search = requireFirst([
|
|
781
809
|
"WAWebChatMessageSearch",
|
|
782
810
|
"WAWebMessageSearch",
|
|
@@ -787,23 +815,13 @@ export function whatsAppWebAdapterProgram() {
|
|
|
787
815
|
const edit = requireFirst(EDIT_MODULES);
|
|
788
816
|
const reaction = requireFirst(REACTION_MODULES);
|
|
789
817
|
const revoke = requireFirst(REVOKE_MODULES);
|
|
790
|
-
// Same nesting as the download path: the module root only exports
|
|
791
|
-
// `{ enforceKaleidoscopeScore, downloadManager }`.
|
|
792
|
-
const mediaModule = requireFirst(["WAWebDownloadManager"]);
|
|
793
|
-
const media = mediaModule?.downloadManager ?? mediaModule;
|
|
794
818
|
const hasFunction = (module, names) =>
|
|
795
819
|
names.some((name) => typeof module?.[name] === "function");
|
|
796
820
|
return {
|
|
797
|
-
collect: hasFunction(history, ["loadEarlierMsgs"]),
|
|
798
821
|
read_messages:
|
|
799
822
|
typeof indexedDB !== "undefined" &&
|
|
800
823
|
typeof requireFirst(["WAWebMsgKey"])?.fromString === "function" &&
|
|
801
824
|
typeof requireFirst(["WAWebCollections"])?.Msg?.getMessagesById === "function",
|
|
802
|
-
download_media:
|
|
803
|
-
hasFunction(media, ["downloadAndMaybeDecrypt"]) ||
|
|
804
|
-
models(requireFirst(["WAWebCollections"])?.Msg).some(
|
|
805
|
-
(model) => typeof model?.downloadMedia === "function"
|
|
806
|
-
),
|
|
807
825
|
search_messages:
|
|
808
826
|
hasFunction(search, ["searchMessages", "searchMsgs", "search"]) ||
|
|
809
827
|
Boolean(requireFirst(["WAWebCollections"])?.Msg),
|
|
@@ -829,130 +847,6 @@ export function whatsAppWebAdapterProgram() {
|
|
|
829
847
|
};
|
|
830
848
|
}
|
|
831
849
|
|
|
832
|
-
function oldestMessage(chat) {
|
|
833
|
-
let oldest = null;
|
|
834
|
-
for (const message of models(modelData(chat).msgs ?? chat?.msgs)) {
|
|
835
|
-
const row = modelData(message);
|
|
836
|
-
const timestamp = unixSeconds(row);
|
|
837
|
-
const id = rawId(row.id ?? message?.id);
|
|
838
|
-
if (!id) continue;
|
|
839
|
-
if (
|
|
840
|
-
!oldest ||
|
|
841
|
-
timestamp < oldest.timestamp ||
|
|
842
|
-
(timestamp === oldest.timestamp && id < oldest.id)
|
|
843
|
-
) {
|
|
844
|
-
oldest = { timestamp, id };
|
|
845
|
-
}
|
|
846
|
-
}
|
|
847
|
-
return oldest;
|
|
848
|
-
}
|
|
849
|
-
|
|
850
|
-
function chatHasEarlier(chat) {
|
|
851
|
-
const row = modelData(chat);
|
|
852
|
-
const state =
|
|
853
|
-
row.msgs?.msgLoadState ??
|
|
854
|
-
chat?.msgs?.msgLoadState ??
|
|
855
|
-
row.msgLoadState ??
|
|
856
|
-
{};
|
|
857
|
-
if (state.noEarlierMsgs === true || state.hasEarlierMsgs === false)
|
|
858
|
-
return false;
|
|
859
|
-
if (row.hasEarlierMsgs === false) return false;
|
|
860
|
-
return true;
|
|
861
|
-
}
|
|
862
|
-
|
|
863
|
-
async function loadEarlier(chat, limit, deadline) {
|
|
864
|
-
const loader = requireFirst(["WAWebChatLoadMessages"]);
|
|
865
|
-
if (typeof loader?.loadEarlierMsgs !== "function") {
|
|
866
|
-
return {
|
|
867
|
-
available: false,
|
|
868
|
-
reason: "WAWebChatLoadMessages.loadEarlierMsgs unavailable",
|
|
869
|
-
loads: 0,
|
|
870
|
-
};
|
|
871
|
-
}
|
|
872
|
-
let loads = 0;
|
|
873
|
-
const beforeIds = new Set(
|
|
874
|
-
models(modelData(chat).msgs ?? chat?.msgs)
|
|
875
|
-
.map((message) => rawId(modelData(message).id ?? message?.id))
|
|
876
|
-
.filter(Boolean)
|
|
877
|
-
);
|
|
878
|
-
let previous = oldestMessage(chat);
|
|
879
|
-
let madeProgress = false;
|
|
880
|
-
while (loads < limit && chatHasEarlier(chat)) {
|
|
881
|
-
if (deadline && Date.now() >= deadline)
|
|
882
|
-
throw new Error("history deadline budget exhausted");
|
|
883
|
-
await loader.loadEarlierMsgs({ chat, msgCollection: chat.msgs });
|
|
884
|
-
loads += 1;
|
|
885
|
-
const next = oldestMessage(chat);
|
|
886
|
-
if (
|
|
887
|
-
!next ||
|
|
888
|
-
(previous &&
|
|
889
|
-
next.id === previous.id &&
|
|
890
|
-
next.timestamp === previous.timestamp)
|
|
891
|
-
)
|
|
892
|
-
break;
|
|
893
|
-
madeProgress = true;
|
|
894
|
-
previous = next;
|
|
895
|
-
}
|
|
896
|
-
let hasMore = chatHasEarlier(chat);
|
|
897
|
-
const loadedIds = () =>
|
|
898
|
-
models(modelData(chat).msgs ?? chat?.msgs)
|
|
899
|
-
.map((message) => rawId(modelData(message).id ?? message?.id))
|
|
900
|
-
.filter((id) => id && !beforeIds.has(id));
|
|
901
|
-
if (hasMore && !madeProgress) {
|
|
902
|
-
return {
|
|
903
|
-
available: true,
|
|
904
|
-
loads,
|
|
905
|
-
has_more: true,
|
|
906
|
-
loaded_ids: loadedIds(),
|
|
907
|
-
frontier_advanced: false,
|
|
908
|
-
error: "WhatsApp history loader made no progress",
|
|
909
|
-
};
|
|
910
|
-
}
|
|
911
|
-
if (hasMore) {
|
|
912
|
-
const phone =
|
|
913
|
-
loader.loadEarlierMsgsFromPhone ??
|
|
914
|
-
loader.requestEarlierMsgsFromPhone ??
|
|
915
|
-
loader.loadEarlierMsgsFromServer;
|
|
916
|
-
const state =
|
|
917
|
-
modelData(chat).msgs?.msgLoadState ?? chat?.msgs?.msgLoadState ?? {};
|
|
918
|
-
const wantsPhone =
|
|
919
|
-
state.canRequestFromPhone === true || state.hasMoreFromPhone === true;
|
|
920
|
-
if (wantsPhone && typeof phone !== "function") {
|
|
921
|
-
return {
|
|
922
|
-
available: true,
|
|
923
|
-
loads,
|
|
924
|
-
has_more: true,
|
|
925
|
-
loaded_ids: loadedIds(),
|
|
926
|
-
frontier_advanced: false,
|
|
927
|
-
error:
|
|
928
|
-
"phone-assisted WhatsApp history is advertised but its loader is unavailable",
|
|
929
|
-
};
|
|
930
|
-
}
|
|
931
|
-
if (typeof phone === "function" && wantsPhone) {
|
|
932
|
-
try {
|
|
933
|
-
await phone.call(loader, { chat, msgCollection: chat.msgs });
|
|
934
|
-
hasMore = chatHasEarlier(chat);
|
|
935
|
-
} catch (error) {
|
|
936
|
-
return {
|
|
937
|
-
available: true,
|
|
938
|
-
loads,
|
|
939
|
-
has_more: true,
|
|
940
|
-
loaded_ids: loadedIds(),
|
|
941
|
-
frontier_advanced: false,
|
|
942
|
-
error: `phone-assisted history failed: ${String(error)}`,
|
|
943
|
-
};
|
|
944
|
-
}
|
|
945
|
-
}
|
|
946
|
-
}
|
|
947
|
-
return {
|
|
948
|
-
available: true,
|
|
949
|
-
loads,
|
|
950
|
-
has_more: hasMore,
|
|
951
|
-
loaded_ids: loadedIds(),
|
|
952
|
-
frontier_advanced: true,
|
|
953
|
-
};
|
|
954
|
-
}
|
|
955
|
-
|
|
956
850
|
function uniqueMessageModels(collections) {
|
|
957
851
|
const byId = new Map();
|
|
958
852
|
for (const message of models(collections.Msg)) {
|
|
@@ -968,208 +862,6 @@ export function whatsAppWebAdapterProgram() {
|
|
|
968
862
|
return [...byId.values()];
|
|
969
863
|
}
|
|
970
864
|
|
|
971
|
-
async function collect(request) {
|
|
972
|
-
const status = readiness();
|
|
973
|
-
if (!status.ready) return { ok: false, error: status };
|
|
974
|
-
const collections = requireFirst(["WAWebCollections"]);
|
|
975
|
-
const chatFilter = ["all", "individual", "group"].includes(
|
|
976
|
-
request.chat_filter
|
|
977
|
-
)
|
|
978
|
-
? request.chat_filter
|
|
979
|
-
: "all";
|
|
980
|
-
const chatRows = [];
|
|
981
|
-
for (const chat of models(collections.Chat)) {
|
|
982
|
-
const raw = widString(modelData(chat).id ?? chat?.id);
|
|
983
|
-
const jid = (await canonicalJid(raw)).jid;
|
|
984
|
-
if (
|
|
985
|
-
!jid ||
|
|
986
|
-
jid === "status@broadcast" ||
|
|
987
|
-
jid.endsWith("@newsletter") ||
|
|
988
|
-
(chatFilter === "group" && !jid.endsWith("@g.us")) ||
|
|
989
|
-
(chatFilter === "individual" && jid.endsWith("@g.us"))
|
|
990
|
-
)
|
|
991
|
-
continue;
|
|
992
|
-
chatRows.push({ chat, jid });
|
|
993
|
-
}
|
|
994
|
-
chatRows.sort((a, b) => a.jid.localeCompare(b.jid));
|
|
995
|
-
const backfill = request.backfill ?? { complete: false, chats: {} };
|
|
996
|
-
const updates = {};
|
|
997
|
-
let cursor = backfill.cursor_chat_jid ?? null;
|
|
998
|
-
const loadedByChat = new Map();
|
|
999
|
-
const backfillMessageIds = new Set();
|
|
1000
|
-
const eligible = request.backfill_disabled
|
|
1001
|
-
? []
|
|
1002
|
-
: chatRows.filter(
|
|
1003
|
-
(entry) => backfill.chats?.[entry.jid]?.has_more !== false
|
|
1004
|
-
);
|
|
1005
|
-
if (eligible.length > 0) {
|
|
1006
|
-
let start = cursor
|
|
1007
|
-
? eligible.findIndex((entry) => entry.jid > cursor)
|
|
1008
|
-
: 0;
|
|
1009
|
-
if (start < 0) start = 0;
|
|
1010
|
-
const rotated = [...eligible.slice(start), ...eligible.slice(0, start)];
|
|
1011
|
-
const selected = rotated.slice(
|
|
1012
|
-
0,
|
|
1013
|
-
Math.max(1, Number(request.max_chats) || 1)
|
|
1014
|
-
);
|
|
1015
|
-
// The connector sends a relative budget, not an absolute instant: it runs
|
|
1016
|
-
// on a different machine than this page, so any shared epoch would be off
|
|
1017
|
-
// by the clock skew between them. Resolving it here against this page's
|
|
1018
|
-
// own clock keeps the budget exact.
|
|
1019
|
-
const budgetMs = Number(request.budget_ms);
|
|
1020
|
-
const historyDeadline =
|
|
1021
|
-
Number.isFinite(budgetMs) && budgetMs > 0
|
|
1022
|
-
? Date.now() + budgetMs
|
|
1023
|
-
: null;
|
|
1024
|
-
for (const entry of selected) {
|
|
1025
|
-
if (historyDeadline && Date.now() >= historyDeadline) break;
|
|
1026
|
-
try {
|
|
1027
|
-
const loaded = await loadEarlier(
|
|
1028
|
-
entry.chat,
|
|
1029
|
-
Math.max(1, Number(request.max_loads_per_chat) || 1),
|
|
1030
|
-
historyDeadline
|
|
1031
|
-
);
|
|
1032
|
-
if (!loaded.available) {
|
|
1033
|
-
return {
|
|
1034
|
-
ok: false,
|
|
1035
|
-
error: {
|
|
1036
|
-
state: "capability_unavailable",
|
|
1037
|
-
reason: loaded.reason,
|
|
1038
|
-
},
|
|
1039
|
-
};
|
|
1040
|
-
}
|
|
1041
|
-
const oldest = oldestMessage(entry.chat);
|
|
1042
|
-
for (const id of loaded.loaded_ids) backfillMessageIds.add(id);
|
|
1043
|
-
loadedByChat.set(entry.jid, loaded.loaded_ids);
|
|
1044
|
-
if (loaded.frontier_advanced === false) {
|
|
1045
|
-
updates[entry.jid] = {
|
|
1046
|
-
...(backfill.chats?.[entry.jid] ?? {}),
|
|
1047
|
-
error: loaded.error,
|
|
1048
|
-
has_more: true,
|
|
1049
|
-
loads: loaded.loads,
|
|
1050
|
-
};
|
|
1051
|
-
continue;
|
|
1052
|
-
}
|
|
1053
|
-
updates[entry.jid] = {
|
|
1054
|
-
oldest_timestamp: oldest?.timestamp ?? null,
|
|
1055
|
-
oldest_id: oldest?.id ?? null,
|
|
1056
|
-
has_more: loaded.has_more,
|
|
1057
|
-
loads: loaded.loads,
|
|
1058
|
-
};
|
|
1059
|
-
cursor = entry.jid;
|
|
1060
|
-
} catch (error) {
|
|
1061
|
-
if (/unavailable/i.test(String(error))) {
|
|
1062
|
-
return {
|
|
1063
|
-
ok: false,
|
|
1064
|
-
error: {
|
|
1065
|
-
state: "capability_unavailable",
|
|
1066
|
-
reason: String(error),
|
|
1067
|
-
},
|
|
1068
|
-
};
|
|
1069
|
-
}
|
|
1070
|
-
updates[entry.jid] = {
|
|
1071
|
-
...(backfill.chats?.[entry.jid] ?? {}),
|
|
1072
|
-
error: String(error),
|
|
1073
|
-
has_more: true,
|
|
1074
|
-
};
|
|
1075
|
-
}
|
|
1076
|
-
}
|
|
1077
|
-
}
|
|
1078
|
-
|
|
1079
|
-
const minimum = Number.isFinite(Number(request.minimum_timestamp))
|
|
1080
|
-
? Number(request.minimum_timestamp)
|
|
1081
|
-
: null;
|
|
1082
|
-
const recent = Number.isFinite(Number(request.recent_since))
|
|
1083
|
-
? Number(request.recent_since)
|
|
1084
|
-
: null;
|
|
1085
|
-
const dirtyRanges = Array.isArray(request.dirty_ranges)
|
|
1086
|
-
? request.dirty_ranges
|
|
1087
|
-
: [];
|
|
1088
|
-
const dirtyByMessageId = new Map(
|
|
1089
|
-
dirtyRanges
|
|
1090
|
-
.filter((marker) => marker?.message_id)
|
|
1091
|
-
.map((marker) => [marker.message_id, marker])
|
|
1092
|
-
);
|
|
1093
|
-
const normalized = [];
|
|
1094
|
-
const quarantined = [];
|
|
1095
|
-
const names = nameIndex(collections);
|
|
1096
|
-
for (const model of uniqueMessageModels(collections)) {
|
|
1097
|
-
const message = await normalizeMessage(
|
|
1098
|
-
model,
|
|
1099
|
-
"reconcile",
|
|
1100
|
-
collections,
|
|
1101
|
-
names
|
|
1102
|
-
);
|
|
1103
|
-
if (!message) continue;
|
|
1104
|
-
if (message.timestamp <= 0) {
|
|
1105
|
-
quarantined.push({
|
|
1106
|
-
key: `${message.chat_jid}:${message.id}`,
|
|
1107
|
-
message_id: message.id,
|
|
1108
|
-
chat_jid: message.chat_jid,
|
|
1109
|
-
reason: "missing_stable_timestamp",
|
|
1110
|
-
});
|
|
1111
|
-
continue;
|
|
1112
|
-
}
|
|
1113
|
-
if (chatFilter === "group" && !message.is_group) continue;
|
|
1114
|
-
if (chatFilter === "individual" && message.is_group) continue;
|
|
1115
|
-
if (minimum != null && message.timestamp < minimum) continue;
|
|
1116
|
-
if (
|
|
1117
|
-
recent != null &&
|
|
1118
|
-
message.timestamp < recent &&
|
|
1119
|
-
!backfillMessageIds.has(message.id) &&
|
|
1120
|
-
!dirtyByMessageId.has(message.id)
|
|
1121
|
-
)
|
|
1122
|
-
continue;
|
|
1123
|
-
normalized.push(message);
|
|
1124
|
-
}
|
|
1125
|
-
normalized.sort(
|
|
1126
|
-
(a, b) => a.timestamp - b.timestamp || a.id.localeCompare(b.id)
|
|
1127
|
-
);
|
|
1128
|
-
const maxMessages = Math.max(
|
|
1129
|
-
1,
|
|
1130
|
-
Math.min(Number(request.max_messages) || 1_000, 2_000)
|
|
1131
|
-
);
|
|
1132
|
-
const byId = new Map(normalized.map((message) => [message.id, message]));
|
|
1133
|
-
const historyPages = [];
|
|
1134
|
-
for (const [chatJid, ids] of loadedByChat) {
|
|
1135
|
-
historyPages.push({
|
|
1136
|
-
chat_jid: chatJid,
|
|
1137
|
-
...(updates[chatJid] ?? {}),
|
|
1138
|
-
messages: ids.map((id) => byId.get(id)).filter(Boolean),
|
|
1139
|
-
});
|
|
1140
|
-
}
|
|
1141
|
-
const messages = normalized
|
|
1142
|
-
.filter((message) => !backfillMessageIds.has(message.id))
|
|
1143
|
-
.slice(-maxMessages)
|
|
1144
|
-
.sort((a, b) => a.timestamp - b.timestamp || a.id.localeCompare(b.id));
|
|
1145
|
-
const mergedChats = { ...(backfill.chats ?? {}), ...updates };
|
|
1146
|
-
return {
|
|
1147
|
-
ok: true,
|
|
1148
|
-
status,
|
|
1149
|
-
messages,
|
|
1150
|
-
history_pages: historyPages,
|
|
1151
|
-
quarantined,
|
|
1152
|
-
dirty_reconciled: normalized
|
|
1153
|
-
.filter((message) => dirtyByMessageId.has(message.id))
|
|
1154
|
-
.map((message) => ({
|
|
1155
|
-
key: dirtyByMessageId.get(message.id).key,
|
|
1156
|
-
message_id: message.id,
|
|
1157
|
-
})),
|
|
1158
|
-
backfill: {
|
|
1159
|
-
// `chatRows` is empty when the tab answered `probe` but its Chat
|
|
1160
|
-
// collection has not populated yet. A bare `.every()` is vacuously true
|
|
1161
|
-
// there, which would record a finished backfill that never ran.
|
|
1162
|
-
complete:
|
|
1163
|
-
request.backfill_disabled === true ||
|
|
1164
|
-
(chatRows.length > 0 &&
|
|
1165
|
-
chatRows.every((entry) => mergedChats[entry.jid]?.has_more === false)),
|
|
1166
|
-
cursor_chat_jid: cursor,
|
|
1167
|
-
inventory: chatRows.map((entry) => entry.jid),
|
|
1168
|
-
chats: updates,
|
|
1169
|
-
},
|
|
1170
|
-
};
|
|
1171
|
-
}
|
|
1172
|
-
|
|
1173
865
|
async function resolveChat(collections, input) {
|
|
1174
866
|
if (input?.self_chat === true) {
|
|
1175
867
|
const me = meUser();
|
|
@@ -1581,7 +1273,7 @@ export function whatsAppWebAdapterProgram() {
|
|
|
1581
1273
|
const message = collectionByRawId(collections.Msg, raw);
|
|
1582
1274
|
if (!message)
|
|
1583
1275
|
throw new Error(
|
|
1584
|
-
`WhatsApp message ${raw} is not loaded;
|
|
1276
|
+
`WhatsApp message ${raw} is not loaded; read it with id:${raw} from the live messages feed or search it first`
|
|
1585
1277
|
);
|
|
1586
1278
|
return message;
|
|
1587
1279
|
}
|
|
@@ -1731,195 +1423,6 @@ export function whatsAppWebAdapterProgram() {
|
|
|
1731
1423
|
};
|
|
1732
1424
|
}
|
|
1733
1425
|
|
|
1734
|
-
async function blobFromMedia(model) {
|
|
1735
|
-
const row = modelData(model);
|
|
1736
|
-
let result = null;
|
|
1737
|
-
if (typeof model?.downloadMedia === "function") {
|
|
1738
|
-
result = await model.downloadMedia({
|
|
1739
|
-
downloadEvenIfExpensive: true,
|
|
1740
|
-
rmrReason: 1,
|
|
1741
|
-
});
|
|
1742
|
-
}
|
|
1743
|
-
result =
|
|
1744
|
-
result ??
|
|
1745
|
-
modelData(model).mediaData?.mediaBlob ??
|
|
1746
|
-
model?.mediaData?.mediaBlob ??
|
|
1747
|
-
row.mediaBlob ??
|
|
1748
|
-
null;
|
|
1749
|
-
if (!result) {
|
|
1750
|
-
// The module exports `{ enforceKaleidoscopeScore, downloadManager }` —
|
|
1751
|
-
// the method sits on the nested object, so probing the module root only
|
|
1752
|
-
// ever found `undefined` and this fallback never ran.
|
|
1753
|
-
const managerModule = requireFirst(["WAWebDownloadManager"]);
|
|
1754
|
-
const manager = managerModule?.downloadManager ?? managerModule;
|
|
1755
|
-
if (typeof manager?.downloadAndMaybeDecrypt === "function") {
|
|
1756
|
-
// `downloadQpl` is NOT optional: the very first thing the function
|
|
1757
|
-
// does is call `downloadQpl.addAnnotations(...)`, so omitting it threw
|
|
1758
|
-
// "Cannot read properties of undefined" before a byte was fetched.
|
|
1759
|
-
// It is only WhatsApp's performance logger, so a stub that answers
|
|
1760
|
-
// every method with a no-op satisfies it — and a permissive proxy
|
|
1761
|
-
// keeps working when a future build calls a method we have not seen
|
|
1762
|
-
// (this already happened once: `addAnnotations` alone was not enough,
|
|
1763
|
-
// the build also calls `addPoint`).
|
|
1764
|
-
result = await manager.downloadAndMaybeDecrypt({
|
|
1765
|
-
directPath: row.directPath,
|
|
1766
|
-
encFilehash: row.encFilehash,
|
|
1767
|
-
filehash: row.filehash,
|
|
1768
|
-
mediaKey: row.mediaKey,
|
|
1769
|
-
mediaKeyTimestamp: row.mediaKeyTimestamp,
|
|
1770
|
-
type: row.type,
|
|
1771
|
-
mimetype: row.mimetype,
|
|
1772
|
-
downloadOrigin: null,
|
|
1773
|
-
partialVideoOpts: null,
|
|
1774
|
-
downloadQpl: new Proxy(
|
|
1775
|
-
{},
|
|
1776
|
-
{
|
|
1777
|
-
get: () => () => {
|
|
1778
|
-
/* WhatsApp's QPL telemetry; nothing to record here. */
|
|
1779
|
-
},
|
|
1780
|
-
}
|
|
1781
|
-
),
|
|
1782
|
-
signal: new AbortController().signal,
|
|
1783
|
-
});
|
|
1784
|
-
}
|
|
1785
|
-
}
|
|
1786
|
-
if (result === "NEED_POKE" || result?.status === "NEED_POKE")
|
|
1787
|
-
return { status: "NEED_POKE" };
|
|
1788
|
-
const candidate = result?.blob ?? result?.mediaBlob ?? result;
|
|
1789
|
-
if (candidate instanceof Blob)
|
|
1790
|
-
return { status: "downloaded", blob: candidate };
|
|
1791
|
-
// `downloadAndMaybeDecrypt` resolves the decrypted bytes as a raw
|
|
1792
|
-
// ArrayBuffer, not a Blob. Falling through to the Blob checks below
|
|
1793
|
-
// reported a perfectly good download as `unavailable`.
|
|
1794
|
-
if (candidate instanceof ArrayBuffer || ArrayBuffer.isView(candidate))
|
|
1795
|
-
return {
|
|
1796
|
-
status: "downloaded",
|
|
1797
|
-
blob: new Blob([candidate], {
|
|
1798
|
-
type: row.mimetype || "application/octet-stream",
|
|
1799
|
-
}),
|
|
1800
|
-
};
|
|
1801
|
-
if (candidate?.getData) {
|
|
1802
|
-
const data = await candidate.getData();
|
|
1803
|
-
if (data instanceof Blob) return { status: "downloaded", blob: data };
|
|
1804
|
-
if (data instanceof ArrayBuffer || ArrayBuffer.isView(data))
|
|
1805
|
-
return {
|
|
1806
|
-
status: "downloaded",
|
|
1807
|
-
blob: new Blob([data], { type: row.mimetype }),
|
|
1808
|
-
};
|
|
1809
|
-
}
|
|
1810
|
-
return { status: row.directPath ? "unavailable" : "expired" };
|
|
1811
|
-
}
|
|
1812
|
-
|
|
1813
|
-
function bytesToBase64(bytes) {
|
|
1814
|
-
let binary = "";
|
|
1815
|
-
const chunk = 0x8000;
|
|
1816
|
-
for (let i = 0; i < bytes.length; i += chunk) {
|
|
1817
|
-
binary += String.fromCharCode(...bytes.subarray(i, i + chunk));
|
|
1818
|
-
}
|
|
1819
|
-
return btoa(binary);
|
|
1820
|
-
}
|
|
1821
|
-
|
|
1822
|
-
async function downloadMedia(input) {
|
|
1823
|
-
const collections = requireFirst(["WAWebCollections"]);
|
|
1824
|
-
const model = resolveMessage(collections, input?.message_id);
|
|
1825
|
-
const row = modelData(model);
|
|
1826
|
-
if (row.isViewOnce || row.viewOnce || row.type === "view_once")
|
|
1827
|
-
return { status: "view_once" };
|
|
1828
|
-
const limit = Math.max(1, Number(input?.max_bytes) || 1);
|
|
1829
|
-
const size = Number(row.size ?? row.fileSize ?? 0);
|
|
1830
|
-
if (size > limit) return { status: "too_large", size_bytes: size };
|
|
1831
|
-
const isVideo =
|
|
1832
|
-
row.type === "video" || String(row.mimetype ?? "").startsWith("video/");
|
|
1833
|
-
if (isVideo && size <= 0) {
|
|
1834
|
-
return { status: "metadata_only", retryable: true, size_bytes: null };
|
|
1835
|
-
}
|
|
1836
|
-
// Bound the fetch HERE, where the work happens, so the dispatch always
|
|
1837
|
-
// answers. A caller-side timer cannot cancel an in-flight dispatch: it only
|
|
1838
|
-
// stops the caller waiting, and the reply then arrives with nobody left to
|
|
1839
|
-
// receive it. Racing inside the page is safe — there is no IPC child to
|
|
1840
|
-
// outlive — and it turns "too slow" into an ordinary retryable answer.
|
|
1841
|
-
const budgetMs = Math.max(0, Number(input?.timeout_ms) || 0);
|
|
1842
|
-
let downloaded;
|
|
1843
|
-
// Held so a download that wins the race can cancel its own timer. A sync
|
|
1844
|
-
// collects several items, and a stray rejecting timer per item would keep
|
|
1845
|
-
// firing into the page long after its answer shipped.
|
|
1846
|
-
let budgetTimer = null;
|
|
1847
|
-
try {
|
|
1848
|
-
downloaded = budgetMs
|
|
1849
|
-
? await Promise.race([
|
|
1850
|
-
blobFromMedia(model),
|
|
1851
|
-
new Promise((_, reject) => {
|
|
1852
|
-
budgetTimer = setTimeout(
|
|
1853
|
-
() =>
|
|
1854
|
-
reject(
|
|
1855
|
-
Object.assign(
|
|
1856
|
-
new Error("media download exceeded its budget"),
|
|
1857
|
-
{ state: "timeout_retryable" }
|
|
1858
|
-
)
|
|
1859
|
-
),
|
|
1860
|
-
budgetMs
|
|
1861
|
-
);
|
|
1862
|
-
}),
|
|
1863
|
-
])
|
|
1864
|
-
: await blobFromMedia(model);
|
|
1865
|
-
} catch (error) {
|
|
1866
|
-
const detail = String(error);
|
|
1867
|
-
const reported = String(error?.state ?? error?.status ?? "");
|
|
1868
|
-
const explicit = [
|
|
1869
|
-
"NEED_POKE",
|
|
1870
|
-
"awaiting_primary_device",
|
|
1871
|
-
"view_once",
|
|
1872
|
-
"expired",
|
|
1873
|
-
"too_large",
|
|
1874
|
-
"timeout_retryable",
|
|
1875
|
-
"metadata_only",
|
|
1876
|
-
"unavailable",
|
|
1877
|
-
].find(
|
|
1878
|
-
(state) =>
|
|
1879
|
-
reported === state ||
|
|
1880
|
-
detail.toLowerCase().includes(state.toLowerCase())
|
|
1881
|
-
);
|
|
1882
|
-
return {
|
|
1883
|
-
status: explicit ?? "unavailable",
|
|
1884
|
-
retryable: [
|
|
1885
|
-
"NEED_POKE",
|
|
1886
|
-
"awaiting_primary_device",
|
|
1887
|
-
"timeout_retryable",
|
|
1888
|
-
"metadata_only",
|
|
1889
|
-
"unavailable",
|
|
1890
|
-
].includes(explicit ?? "unavailable"),
|
|
1891
|
-
detail: detail.slice(0, 200),
|
|
1892
|
-
};
|
|
1893
|
-
} finally {
|
|
1894
|
-
if (budgetTimer !== null) clearTimeout(budgetTimer);
|
|
1895
|
-
}
|
|
1896
|
-
if (!downloaded.blob) return downloaded;
|
|
1897
|
-
if (downloaded.blob.size > limit)
|
|
1898
|
-
return { status: "too_large", size_bytes: downloaded.blob.size };
|
|
1899
|
-
const bytes = new Uint8Array(await downloaded.blob.arrayBuffer());
|
|
1900
|
-
if (bytes.length === 0) return { status: "unavailable", detail: "empty" };
|
|
1901
|
-
const mime =
|
|
1902
|
-
downloaded.blob.type || row.mimetype || "application/octet-stream";
|
|
1903
|
-
const kind = mime.startsWith("audio/")
|
|
1904
|
-
? "audio"
|
|
1905
|
-
: mime.startsWith("image/")
|
|
1906
|
-
? "image"
|
|
1907
|
-
: "file";
|
|
1908
|
-
return {
|
|
1909
|
-
status: "downloaded",
|
|
1910
|
-
attachment: {
|
|
1911
|
-
kind,
|
|
1912
|
-
filename:
|
|
1913
|
-
row.filename ??
|
|
1914
|
-
row.fileName ??
|
|
1915
|
-
`whatsapp-${rawId(row.id ?? model?.id)}`,
|
|
1916
|
-
mime_type: mime,
|
|
1917
|
-
data: bytesToBase64(bytes),
|
|
1918
|
-
size_bytes: bytes.length,
|
|
1919
|
-
},
|
|
1920
|
-
};
|
|
1921
|
-
}
|
|
1922
|
-
|
|
1923
1426
|
async function invoke(request) {
|
|
1924
1427
|
try {
|
|
1925
1428
|
if (Number(request?.adapter_version) !== ADAPTER_VERSION) {
|
|
@@ -1954,11 +1457,8 @@ export function whatsAppWebAdapterProgram() {
|
|
|
1954
1457
|
},
|
|
1955
1458
|
};
|
|
1956
1459
|
}
|
|
1957
|
-
if (request.op === "collect") return await collect(request);
|
|
1958
1460
|
if (request.op === "read_messages")
|
|
1959
1461
|
return { ok: true, ...(await readMessages(request.input)) };
|
|
1960
|
-
if (request.op === "download_media")
|
|
1961
|
-
return { ok: true, ...(await downloadMedia(request)) };
|
|
1962
1462
|
if (request.op === "search_messages")
|
|
1963
1463
|
return { ok: true, ...(await searchMessages(request.input)) };
|
|
1964
1464
|
if (request.op === "draft_message")
|