@codexverified/baileys 2.7.5
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/LICENSE +21 -0
- package/README.md +233 -0
- package/WAProto/V +1 -0
- package/WAProto/WAProto.proto +8051 -0
- package/WAProto/index.js +289292 -0
- package/engine-requirements.js +13 -0
- package/lib/Defaults/index.js +158 -0
- package/lib/Signal/Group/ciphertext-message.js +11 -0
- package/lib/Signal/Group/group-session-builder.js +29 -0
- package/lib/Signal/Group/group_cipher.js +81 -0
- package/lib/Signal/Group/index.js +11 -0
- package/lib/Signal/Group/keyhelper.js +17 -0
- package/lib/Signal/Group/sender-chain-key.js +25 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +62 -0
- package/lib/Signal/Group/sender-key-message.js +65 -0
- package/lib/Signal/Group/sender-key-name.js +47 -0
- package/lib/Signal/Group/sender-key-record.js +40 -0
- package/lib/Signal/Group/sender-key-state.js +83 -0
- package/lib/Signal/Group/sender-message-key.js +25 -0
- package/lib/Signal/libsignal.js +428 -0
- package/lib/Signal/lid-mapping.js +280 -0
- package/lib/Socket/Client/index.js +2 -0
- package/lib/Socket/Client/types.js +10 -0
- package/lib/Socket/Client/websocket.js +53 -0
- package/lib/Socket/aigroups.js +315 -0
- package/lib/Socket/business.js +407 -0
- package/lib/Socket/chats.js +1831 -0
- package/lib/Socket/communities.js +431 -0
- package/lib/Socket/graphql.js +899 -0
- package/lib/Socket/groups.js +549 -0
- package/lib/Socket/index.js +79 -0
- package/lib/Socket/interactive-handler.js +600 -0
- package/lib/Socket/interop.js +563 -0
- package/lib/Socket/managed-account.js +208 -0
- package/lib/Socket/messages-recv.js +2144 -0
- package/lib/Socket/messages-send.js +2030 -0
- package/lib/Socket/mex.js +41 -0
- package/lib/Socket/newsletter.js +226 -0
- package/lib/Socket/privacy.js +446 -0
- package/lib/Socket/registration.js +428 -0
- package/lib/Socket/socket.js +1017 -0
- package/lib/Socket/username.js +229 -0
- package/lib/Store/index.js +4 -0
- package/lib/Store/make-cache-manager-store.js +89 -0
- package/lib/Store/make-in-memory-store.js +420 -0
- package/lib/Store/make-ordered-dictionary.js +78 -0
- package/lib/Store/object-repository.js +23 -0
- package/lib/Types/Auth.js +1 -0
- package/lib/Types/Bussines.js +1 -0
- package/lib/Types/Call.js +1 -0
- package/lib/Types/Chat.js +7 -0
- package/lib/Types/Contact.js +1 -0
- package/lib/Types/Events.js +1 -0
- package/lib/Types/GroupMetadata.js +1 -0
- package/lib/Types/Label.js +24 -0
- package/lib/Types/LabelAssociation.js +6 -0
- package/lib/Types/Message.js +17 -0
- package/lib/Types/Mex.js +39 -0
- package/lib/Types/Product.js +1 -0
- package/lib/Types/RichType.js +22 -0
- package/lib/Types/Signal.js +1 -0
- package/lib/Types/Socket.js +2 -0
- package/lib/Types/State.js +48 -0
- package/lib/Types/USync.js +1 -0
- package/lib/Types/index.js +25 -0
- package/lib/Utils/auth-utils.js +301 -0
- package/lib/Utils/bot-planning-replay.js +169 -0
- package/lib/Utils/browser-utils.js +28 -0
- package/lib/Utils/business.js +230 -0
- package/lib/Utils/chat-utils.js +885 -0
- package/lib/Utils/companion-reg-client-utils.js +32 -0
- package/lib/Utils/consumer-application.js +102 -0
- package/lib/Utils/crypto.js +117 -0
- package/lib/Utils/decode-wa-message.js +484 -0
- package/lib/Utils/event-buffer.js +589 -0
- package/lib/Utils/generics.js +388 -0
- package/lib/Utils/group-history.js +56 -0
- package/lib/Utils/history.js +130 -0
- package/lib/Utils/identity-change-handler.js +48 -0
- package/lib/Utils/index.js +34 -0
- package/lib/Utils/jid-display-normalization.js +209 -0
- package/lib/Utils/link-preview.js +84 -0
- package/lib/Utils/logger.js +2 -0
- package/lib/Utils/lt-hash.js +7 -0
- package/lib/Utils/make-mutex.js +32 -0
- package/lib/Utils/message-composer.js +467 -0
- package/lib/Utils/message-inspect.js +67 -0
- package/lib/Utils/message-retry-manager.js +241 -0
- package/lib/Utils/messages-media.js +1006 -0
- package/lib/Utils/messages.js +1851 -0
- package/lib/Utils/meta-ai-msmsg.js +130 -0
- package/lib/Utils/meta-compositing.js +194 -0
- package/lib/Utils/noise-handler.js +200 -0
- package/lib/Utils/offline-node-processor.js +39 -0
- package/lib/Utils/pre-key-manager.js +105 -0
- package/lib/Utils/process-message.js +527 -0
- package/lib/Utils/reporting-utils.js +257 -0
- package/lib/Utils/rich-message-utils.js +439 -0
- package/lib/Utils/signal.js +200 -0
- package/lib/Utils/stanza-ack.js +37 -0
- package/lib/Utils/sync-action-utils.js +47 -0
- package/lib/Utils/tc-token-utils.js +162 -0
- package/lib/Utils/use-multi-file-auth-state.js +120 -0
- package/lib/Utils/use-single-file-auth-state.js +96 -0
- package/lib/Utils/use-sqlite-auth-state.js +108 -0
- package/lib/Utils/validate-connection.js +206 -0
- package/lib/Utils/voip-rekey.js +20 -0
- package/lib/Utils/welcome-flow.js +217 -0
- package/lib/WABinary/constants.js +1463 -0
- package/lib/WABinary/decode.js +261 -0
- package/lib/WABinary/encode.js +219 -0
- package/lib/WABinary/generic-utils.js +227 -0
- package/lib/WABinary/index.js +5 -0
- package/lib/WABinary/jid-utils.js +95 -0
- package/lib/WABinary/types.js +1 -0
- package/lib/WAM/BinaryInfo.js +9 -0
- package/lib/WAM/constants.js +22852 -0
- package/lib/WAM/encode.js +149 -0
- package/lib/WAM/index.js +3 -0
- package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +96 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +56 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +53 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -0
- package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +70 -0
- package/lib/WAUSync/Protocols/USyncPictureProtocol.js +28 -0
- package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +25 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +37 -0
- package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +34 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +24 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +28 -0
- package/lib/WAUSync/Protocols/index.js +12 -0
- package/lib/WAUSync/USyncQuery.js +201 -0
- package/lib/WAUSync/USyncUser.js +54 -0
- package/lib/WAUSync/index.js +3 -0
- package/lib/antiban.cjs +4726 -0
- package/lib/index.d.ts +286 -0
- package/lib/index.js +18 -0
- package/package.json +121 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Boom } from '@hapi/boom';
|
|
2
|
+
export var SyncState;
|
|
3
|
+
(function (SyncState) {
|
|
4
|
+
/** The socket is connecting, but we haven't received pending notifications yet. */
|
|
5
|
+
SyncState[SyncState["Connecting"] = 0] = "Connecting";
|
|
6
|
+
/** Pending notifications received. Buffering events until we decide whether to sync or not. */
|
|
7
|
+
SyncState[SyncState["AwaitingInitialSync"] = 1] = "AwaitingInitialSync";
|
|
8
|
+
/** The initial app state sync (history, etc.) is in progress. Buffering continues. */
|
|
9
|
+
SyncState[SyncState["Syncing"] = 2] = "Syncing";
|
|
10
|
+
/** Initial sync is complete, or was skipped. The socket is fully operational and events are processed in real-time. */
|
|
11
|
+
SyncState[SyncState["Online"] = 3] = "Online";
|
|
12
|
+
})(SyncState || (SyncState = {}));
|
|
13
|
+
export var ReachoutTimelockEnforcementType;
|
|
14
|
+
(function (ReachoutTimelockEnforcementType) {
|
|
15
|
+
ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_ALCOHOL"] = "BIZ_COMMERCE_VIOLATION_ALCOHOL";
|
|
16
|
+
ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_ADULT"] = "BIZ_COMMERCE_VIOLATION_ADULT";
|
|
17
|
+
ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_ANIMALS"] = "BIZ_COMMERCE_VIOLATION_ANIMALS";
|
|
18
|
+
ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_BODY_PARTS_FLUIDS"] = "BIZ_COMMERCE_VIOLATION_BODY_PARTS_FLUIDS";
|
|
19
|
+
ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_DATING"] = "BIZ_COMMERCE_VIOLATION_DATING";
|
|
20
|
+
ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_DIGITAL_SERVICES_PRODUCTS"] = "BIZ_COMMERCE_VIOLATION_DIGITAL_SERVICES_PRODUCTS";
|
|
21
|
+
ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_DRUGS"] = "BIZ_COMMERCE_VIOLATION_DRUGS";
|
|
22
|
+
ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_DRUGS_ONLY_OTC"] = "BIZ_COMMERCE_VIOLATION_DRUGS_ONLY_OTC";
|
|
23
|
+
ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_GAMBLING"] = "BIZ_COMMERCE_VIOLATION_GAMBLING";
|
|
24
|
+
ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_HEALTHCARE"] = "BIZ_COMMERCE_VIOLATION_HEALTHCARE";
|
|
25
|
+
ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_REAL_FAKE_CURRENCY"] = "BIZ_COMMERCE_VIOLATION_REAL_FAKE_CURRENCY";
|
|
26
|
+
ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_SUPPLEMENTS"] = "BIZ_COMMERCE_VIOLATION_SUPPLEMENTS";
|
|
27
|
+
ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_TOBACCO"] = "BIZ_COMMERCE_VIOLATION_TOBACCO";
|
|
28
|
+
ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_VIOLENT_CONTENT"] = "BIZ_COMMERCE_VIOLATION_VIOLENT_CONTENT";
|
|
29
|
+
ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_WEAPONS"] = "BIZ_COMMERCE_VIOLATION_WEAPONS";
|
|
30
|
+
ReachoutTimelockEnforcementType["BIZ_QUALITY"] = "BIZ_QUALITY";
|
|
31
|
+
/** This means there is no restriction */
|
|
32
|
+
ReachoutTimelockEnforcementType["DEFAULT"] = "DEFAULT";
|
|
33
|
+
ReachoutTimelockEnforcementType["WEB_COMPANION_ONLY"] = "WEB_COMPANION_ONLY";
|
|
34
|
+
})(ReachoutTimelockEnforcementType || (ReachoutTimelockEnforcementType = {}));
|
|
35
|
+
export var NewChatMessageCappingStatusType;
|
|
36
|
+
(function (NewChatMessageCappingStatusType) {
|
|
37
|
+
NewChatMessageCappingStatusType["NONE"] = "NONE";
|
|
38
|
+
NewChatMessageCappingStatusType["FIRST_WARNING"] = "FIRST_WARNING";
|
|
39
|
+
NewChatMessageCappingStatusType["SECOND_WARNING"] = "SECOND_WARNING";
|
|
40
|
+
NewChatMessageCappingStatusType["CAPPED"] = "CAPPED";
|
|
41
|
+
})(NewChatMessageCappingStatusType || (NewChatMessageCappingStatusType = {}));
|
|
42
|
+
export var NewChatMessageCappingMVStatusType;
|
|
43
|
+
(function (NewChatMessageCappingMVStatusType) {
|
|
44
|
+
NewChatMessageCappingMVStatusType["NOT_ELIGIBLE"] = "NOT_ELIGIBLE";
|
|
45
|
+
NewChatMessageCappingMVStatusType["NOT_ACTIVE"] = "NOT_ACTIVE";
|
|
46
|
+
NewChatMessageCappingMVStatusType["ACTIVE"] = "ACTIVE";
|
|
47
|
+
NewChatMessageCappingMVStatusType["ACTIVE_UPGRADE_AVAILABLE"] = "ACTIVE_UPGRADE_AVAILABLE";
|
|
48
|
+
})(NewChatMessageCappingMVStatusType || (NewChatMessageCappingMVStatusType = {}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import { USyncUser } from '../WAUSync/index.js';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export * from './Auth.js';
|
|
2
|
+
export * from './GroupMetadata.js';
|
|
3
|
+
export * from './Chat.js';
|
|
4
|
+
export * from './Contact.js';
|
|
5
|
+
export * from './State.js';
|
|
6
|
+
export * from './Mex.js';
|
|
7
|
+
export * from './Message.js';
|
|
8
|
+
export * from './Socket.js';
|
|
9
|
+
export * from './Events.js';
|
|
10
|
+
export * from './Product.js';
|
|
11
|
+
export * from './Call.js';
|
|
12
|
+
export * from './Signal.js';
|
|
13
|
+
export var DisconnectReason;
|
|
14
|
+
(function (DisconnectReason) {
|
|
15
|
+
DisconnectReason[DisconnectReason["connectionClosed"] = 428] = "connectionClosed";
|
|
16
|
+
DisconnectReason[DisconnectReason["connectionLost"] = 408] = "connectionLost";
|
|
17
|
+
DisconnectReason[DisconnectReason["connectionReplaced"] = 440] = "connectionReplaced";
|
|
18
|
+
DisconnectReason[DisconnectReason["timedOut"] = 408] = "timedOut";
|
|
19
|
+
DisconnectReason[DisconnectReason["loggedOut"] = 401] = "loggedOut";
|
|
20
|
+
DisconnectReason[DisconnectReason["badSession"] = 500] = "badSession";
|
|
21
|
+
DisconnectReason[DisconnectReason["restartRequired"] = 515] = "restartRequired";
|
|
22
|
+
DisconnectReason[DisconnectReason["multideviceMismatch"] = 411] = "multideviceMismatch";
|
|
23
|
+
DisconnectReason[DisconnectReason["forbidden"] = 403] = "forbidden";
|
|
24
|
+
DisconnectReason[DisconnectReason["unavailableService"] = 503] = "unavailableService";
|
|
25
|
+
})(DisconnectReason || (DisconnectReason = {}));
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import NodeCache from '@cacheable/node-cache';
|
|
2
|
+
import { Boom } from '@hapi/boom';
|
|
3
|
+
import { AsyncLocalStorage } from 'async_hooks';
|
|
4
|
+
import { Mutex } from 'async-mutex';
|
|
5
|
+
import { randomBytes } from 'crypto';
|
|
6
|
+
import PQueue from 'p-queue';
|
|
7
|
+
import { DEFAULT_CACHE_TTLS } from '../Defaults/index.js';
|
|
8
|
+
import { Curve, signedKeyPair } from './crypto.js';
|
|
9
|
+
import { delay, generateRegistrationId } from './generics.js';
|
|
10
|
+
import { PreKeyManager } from './pre-key-manager.js';
|
|
11
|
+
/**
|
|
12
|
+
* Adds caching capability to a SignalKeyStore
|
|
13
|
+
* @param store the store to add caching to
|
|
14
|
+
* @param logger to log trace events
|
|
15
|
+
* @param _cache cache store to use
|
|
16
|
+
*/
|
|
17
|
+
export function makeCacheableSignalKeyStore(store, logger, _cache) {
|
|
18
|
+
const cache = _cache ||
|
|
19
|
+
new NodeCache({
|
|
20
|
+
stdTTL: DEFAULT_CACHE_TTLS.SIGNAL_STORE, // 5 minutes
|
|
21
|
+
useClones: false,
|
|
22
|
+
deleteOnExpire: true
|
|
23
|
+
});
|
|
24
|
+
// Mutex for protecting cache operations
|
|
25
|
+
const cacheMutex = new Mutex();
|
|
26
|
+
function getUniqueId(type, id) {
|
|
27
|
+
return `${type}.${id}`;
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
async get(type, ids) {
|
|
31
|
+
return cacheMutex.runExclusive(async () => {
|
|
32
|
+
const data = {};
|
|
33
|
+
const idsToFetch = [];
|
|
34
|
+
for (const id of ids) {
|
|
35
|
+
const item = (await cache.get(getUniqueId(type, id)));
|
|
36
|
+
if (typeof item !== 'undefined') {
|
|
37
|
+
data[id] = item;
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
idsToFetch.push(id);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (idsToFetch.length) {
|
|
44
|
+
logger?.trace({ items: idsToFetch.length }, 'loading from store');
|
|
45
|
+
const fetched = await store.get(type, idsToFetch);
|
|
46
|
+
for (const id of idsToFetch) {
|
|
47
|
+
const item = fetched[id];
|
|
48
|
+
if (item) {
|
|
49
|
+
data[id] = item;
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
51
|
+
await cache.set(getUniqueId(type, id), item);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return data;
|
|
56
|
+
});
|
|
57
|
+
},
|
|
58
|
+
async set(data) {
|
|
59
|
+
return cacheMutex.runExclusive(async () => {
|
|
60
|
+
let keys = 0;
|
|
61
|
+
for (const type in data) {
|
|
62
|
+
for (const id in data[type]) {
|
|
63
|
+
await cache.set(getUniqueId(type, id), data[type][id]);
|
|
64
|
+
keys += 1;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
logger?.trace({ keys }, 'updated cache');
|
|
68
|
+
await store.set(data);
|
|
69
|
+
});
|
|
70
|
+
},
|
|
71
|
+
async clear() {
|
|
72
|
+
await cache.flushAll();
|
|
73
|
+
await store.clear?.();
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Adds DB-like transaction capability to the SignalKeyStore
|
|
79
|
+
* Uses AsyncLocalStorage for automatic context management
|
|
80
|
+
* @param state the key store to apply this capability to
|
|
81
|
+
* @param logger logger to log events
|
|
82
|
+
* @returns SignalKeyStore with transaction capability
|
|
83
|
+
*/
|
|
84
|
+
export const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetweenTriesMs }) => {
|
|
85
|
+
const txStorage = new AsyncLocalStorage();
|
|
86
|
+
// Queues for concurrency control (keyed by signal data type - bounded set)
|
|
87
|
+
const keyQueues = new Map();
|
|
88
|
+
// Transaction mutexes with reference counting for cleanup
|
|
89
|
+
const txMutexes = new Map();
|
|
90
|
+
const txMutexRefCounts = new Map();
|
|
91
|
+
// Pre-key manager for specialized operations
|
|
92
|
+
const preKeyManager = new PreKeyManager(state, logger);
|
|
93
|
+
/**
|
|
94
|
+
* Get or create a queue for a specific key type
|
|
95
|
+
*/
|
|
96
|
+
function getQueue(key) {
|
|
97
|
+
if (!keyQueues.has(key)) {
|
|
98
|
+
keyQueues.set(key, new PQueue({ concurrency: 1 }));
|
|
99
|
+
}
|
|
100
|
+
return keyQueues.get(key);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Get or create a transaction mutex
|
|
104
|
+
*/
|
|
105
|
+
function getTxMutex(key) {
|
|
106
|
+
if (!txMutexes.has(key)) {
|
|
107
|
+
txMutexes.set(key, new Mutex());
|
|
108
|
+
txMutexRefCounts.set(key, 0);
|
|
109
|
+
}
|
|
110
|
+
return txMutexes.get(key);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Acquire a reference to a transaction mutex
|
|
114
|
+
*/
|
|
115
|
+
function acquireTxMutexRef(key) {
|
|
116
|
+
const count = txMutexRefCounts.get(key) ?? 0;
|
|
117
|
+
txMutexRefCounts.set(key, count + 1);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Release a reference to a transaction mutex and cleanup if no longer needed
|
|
121
|
+
*/
|
|
122
|
+
function releaseTxMutexRef(key) {
|
|
123
|
+
const count = (txMutexRefCounts.get(key) ?? 1) - 1;
|
|
124
|
+
txMutexRefCounts.set(key, count);
|
|
125
|
+
// Cleanup if no more references and mutex is not locked
|
|
126
|
+
if (count <= 0) {
|
|
127
|
+
const mutex = txMutexes.get(key);
|
|
128
|
+
if (mutex && !mutex.isLocked()) {
|
|
129
|
+
txMutexes.delete(key);
|
|
130
|
+
txMutexRefCounts.delete(key);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Check if currently in a transaction
|
|
136
|
+
*/
|
|
137
|
+
function isInTransaction() {
|
|
138
|
+
return !!txStorage.getStore();
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Commit transaction with retries
|
|
142
|
+
*/
|
|
143
|
+
async function commitWithRetry(mutations) {
|
|
144
|
+
if (Object.keys(mutations).length === 0) {
|
|
145
|
+
logger.trace('no mutations in transaction');
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
logger.trace('committing transaction');
|
|
149
|
+
for (let attempt = 0; attempt < maxCommitRetries; attempt++) {
|
|
150
|
+
try {
|
|
151
|
+
await state.set(mutations);
|
|
152
|
+
logger.trace({ mutationCount: Object.keys(mutations).length }, 'committed transaction');
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
const retriesLeft = maxCommitRetries - attempt - 1;
|
|
157
|
+
logger.warn(`failed to commit mutations, retries left=${retriesLeft}`);
|
|
158
|
+
if (retriesLeft === 0) {
|
|
159
|
+
throw error;
|
|
160
|
+
}
|
|
161
|
+
await delay(delayBetweenTriesMs);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return {
|
|
166
|
+
get: async (type, ids) => {
|
|
167
|
+
const ctx = txStorage.getStore();
|
|
168
|
+
if (!ctx) {
|
|
169
|
+
// No transaction - direct read without exclusive lock for concurrency
|
|
170
|
+
return state.get(type, ids);
|
|
171
|
+
}
|
|
172
|
+
// In transaction - check cache first
|
|
173
|
+
const cached = ctx.cache[type] || {};
|
|
174
|
+
const missing = ids.filter(id => !(id in cached));
|
|
175
|
+
if (missing.length > 0) {
|
|
176
|
+
ctx.dbQueries++;
|
|
177
|
+
logger.trace({ type, count: missing.length }, 'fetching missing keys in transaction');
|
|
178
|
+
const fetched = await getTxMutex(type).runExclusive(() => state.get(type, missing));
|
|
179
|
+
// Update cache
|
|
180
|
+
ctx.cache[type] = ctx.cache[type] || {};
|
|
181
|
+
Object.assign(ctx.cache[type], fetched);
|
|
182
|
+
}
|
|
183
|
+
// Return requested ids from cache
|
|
184
|
+
const result = {};
|
|
185
|
+
for (const id of ids) {
|
|
186
|
+
const value = ctx.cache[type]?.[id];
|
|
187
|
+
if (value !== undefined && value !== null) {
|
|
188
|
+
result[id] = value;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return result;
|
|
192
|
+
},
|
|
193
|
+
set: async (data) => {
|
|
194
|
+
const ctx = txStorage.getStore();
|
|
195
|
+
if (!ctx) {
|
|
196
|
+
// No transaction - direct write with queue protection
|
|
197
|
+
const types = Object.keys(data);
|
|
198
|
+
// Process pre-keys with validation
|
|
199
|
+
for (const type_ of types) {
|
|
200
|
+
const type = type_;
|
|
201
|
+
if (type === 'pre-key') {
|
|
202
|
+
await preKeyManager.validateDeletions(data, type);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
// Write all data in parallel
|
|
206
|
+
await Promise.all(types.map(type => getQueue(type).add(async () => {
|
|
207
|
+
const typeData = { [type]: data[type] };
|
|
208
|
+
await state.set(typeData);
|
|
209
|
+
})));
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
// In transaction - update cache and mutations
|
|
213
|
+
logger.trace({ types: Object.keys(data) }, 'caching in transaction');
|
|
214
|
+
for (const key_ in data) {
|
|
215
|
+
const key = key_;
|
|
216
|
+
// Ensure structures exist
|
|
217
|
+
ctx.cache[key] = ctx.cache[key] || {};
|
|
218
|
+
ctx.mutations[key] = ctx.mutations[key] || {};
|
|
219
|
+
// Special handling for pre-keys
|
|
220
|
+
if (key === 'pre-key') {
|
|
221
|
+
await preKeyManager.processOperations(data, key, ctx.cache, ctx.mutations, true);
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
// Normal key types
|
|
225
|
+
Object.assign(ctx.cache[key], data[key]);
|
|
226
|
+
Object.assign(ctx.mutations[key], data[key]);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
},
|
|
230
|
+
isInTransaction,
|
|
231
|
+
transaction: async (work, key) => {
|
|
232
|
+
const existing = txStorage.getStore();
|
|
233
|
+
// Nested transaction - reuse existing context
|
|
234
|
+
if (existing) {
|
|
235
|
+
logger.trace('reusing existing transaction context');
|
|
236
|
+
return work();
|
|
237
|
+
}
|
|
238
|
+
// New transaction - acquire mutex and create context
|
|
239
|
+
const mutex = getTxMutex(key);
|
|
240
|
+
acquireTxMutexRef(key);
|
|
241
|
+
try {
|
|
242
|
+
return await mutex.runExclusive(async () => {
|
|
243
|
+
const ctx = {
|
|
244
|
+
cache: {},
|
|
245
|
+
mutations: {},
|
|
246
|
+
dbQueries: 0
|
|
247
|
+
};
|
|
248
|
+
logger.trace('entering transaction');
|
|
249
|
+
try {
|
|
250
|
+
const result = await txStorage.run(ctx, work);
|
|
251
|
+
// Commit mutations
|
|
252
|
+
await commitWithRetry(ctx.mutations);
|
|
253
|
+
logger.trace({ dbQueries: ctx.dbQueries }, 'transaction completed');
|
|
254
|
+
return result;
|
|
255
|
+
}
|
|
256
|
+
catch (error) {
|
|
257
|
+
logger.error({ error }, 'transaction failed, rolling back');
|
|
258
|
+
throw error;
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
finally {
|
|
263
|
+
releaseTxMutexRef(key);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
};
|
|
268
|
+
/**
|
|
269
|
+
* Returns the authenticated user's JID, or throws a Boom-401 if creds are not yet authenticated.
|
|
270
|
+
* Use this anywhere we'd otherwise reach for `creds.me!.id` to fail fast with a descriptive error.
|
|
271
|
+
*/
|
|
272
|
+
export const assertMeId = (creds) => {
|
|
273
|
+
const id = creds.me?.id;
|
|
274
|
+
if (!id) {
|
|
275
|
+
throw new Boom('Cannot proceed: socket is not authenticated yet (creds.me.id is missing)', { statusCode: 401 });
|
|
276
|
+
}
|
|
277
|
+
return id;
|
|
278
|
+
};
|
|
279
|
+
export const initAuthCreds = () => {
|
|
280
|
+
const identityKey = Curve.generateKeyPair();
|
|
281
|
+
return {
|
|
282
|
+
noiseKey: Curve.generateKeyPair(),
|
|
283
|
+
pairingEphemeralKeyPair: Curve.generateKeyPair(),
|
|
284
|
+
signedIdentityKey: identityKey,
|
|
285
|
+
signedPreKey: signedKeyPair(identityKey, 1),
|
|
286
|
+
registrationId: generateRegistrationId(),
|
|
287
|
+
advSecretKey: randomBytes(32).toString('base64'),
|
|
288
|
+
processedHistoryMessages: [],
|
|
289
|
+
nextPreKeyId: 1,
|
|
290
|
+
firstUnuploadedPreKeyId: 1,
|
|
291
|
+
accountSyncCounter: 0,
|
|
292
|
+
accountSettings: {
|
|
293
|
+
unarchiveChats: false
|
|
294
|
+
},
|
|
295
|
+
registered: false,
|
|
296
|
+
pairingCode: undefined,
|
|
297
|
+
lastPropHash: undefined,
|
|
298
|
+
routingInfo: undefined,
|
|
299
|
+
additionalData: undefined
|
|
300
|
+
};
|
|
301
|
+
};
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lia@Changes [WIP]
|
|
3
|
+
* botPlanningReplay Meta AI-style live reasoning feed.
|
|
4
|
+
*
|
|
5
|
+
* UNIVERSAL VERSION: Works on ALL WhatsApp clients.
|
|
6
|
+
* - Native Meta AI rendering for compatible clients
|
|
7
|
+
* - Plain text fallback for regular clients (no "Update WhatsApp")
|
|
8
|
+
*
|
|
9
|
+
* Flow:
|
|
10
|
+
* Send placeholder (all steps pending)
|
|
11
|
+
* edit: step[0] DONE
|
|
12
|
+
* edit: step[1] DONE
|
|
13
|
+
* ...
|
|
14
|
+
* delete placeholder
|
|
15
|
+
* send final message fresh
|
|
16
|
+
*
|
|
17
|
+
* If you use or copy this code, please credit @codexverified/baileys.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { proto } from '../../WAProto/index.js';
|
|
21
|
+
import {
|
|
22
|
+
buildCompositingPlaceholder,
|
|
23
|
+
buildProgressIndicator,
|
|
24
|
+
buildPlainPlaceholder,
|
|
25
|
+
PlanningStepStatus
|
|
26
|
+
} from './meta-compositing.js';
|
|
27
|
+
import { botMetadataSignature, botMetadataCertificate } from './rich-message-utils.js';
|
|
28
|
+
import { BOT_RENDERING_CONFIG_METADATA } from '../Defaults/index.js';
|
|
29
|
+
import { delay } from './generics.js';
|
|
30
|
+
|
|
31
|
+
// Internal: build native Meta AI frame
|
|
32
|
+
const buildReplayFrame = (description, steps, placeholderText = '') => {
|
|
33
|
+
return buildCompositingPlaceholder({ description, steps, placeholderText });
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// Internal: edit planning bubble (native Meta AI)
|
|
37
|
+
const editPlanningBubble = async (sock, jid, key, description, steps, placeholderText) => {
|
|
38
|
+
const updated = buildReplayFrame(description, steps, placeholderText);
|
|
39
|
+
await sock.sendMessage(jid, { raw: true, edit: key, ...updated });
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// Internal: edit plain text bubble (universal)
|
|
43
|
+
const editPlainBubble = async (sock, jid, key, description, steps, placeholderText) => {
|
|
44
|
+
const updated = buildPlainPlaceholder(description, steps, placeholderText);
|
|
45
|
+
await sock.sendMessage(jid, { edit: key, ...updated });
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* replayPlanning full live planning animation (UNIVERSAL).
|
|
50
|
+
*/
|
|
51
|
+
export const replayPlanning = async (sock, jid, steps, finalContent, {
|
|
52
|
+
description = 'Thinking',
|
|
53
|
+
placeholderText = '',
|
|
54
|
+
stepDelayMs = 900,
|
|
55
|
+
finalPauseMs = 600,
|
|
56
|
+
abortOnDisconnect = true,
|
|
57
|
+
sendOptions = {},
|
|
58
|
+
useNativeMeta = false
|
|
59
|
+
} = {}) => {
|
|
60
|
+
if (!steps?.length) {
|
|
61
|
+
throw new Error('replayPlanning: steps array must have at least one entry');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
let aborted = false;
|
|
65
|
+
const onClose = () => { aborted = true; };
|
|
66
|
+
if (abortOnDisconnect) {
|
|
67
|
+
sock.ev?.once?.('connection.update', ({ connection }) => {
|
|
68
|
+
if (connection === 'close') onClose();
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Show typing
|
|
73
|
+
await sock.sendPresenceUpdate('composing', jid);
|
|
74
|
+
|
|
75
|
+
// Build initial steps (all pending)
|
|
76
|
+
const initialSteps = steps.map(step => ({
|
|
77
|
+
...step,
|
|
78
|
+
status: PlanningStepStatus.IN_PROGRESS
|
|
79
|
+
}));
|
|
80
|
+
|
|
81
|
+
// Determine mode
|
|
82
|
+
const isNative = useNativeMeta && false; // Always false for now force universal
|
|
83
|
+
|
|
84
|
+
// Send initial placeholder
|
|
85
|
+
let placeholder;
|
|
86
|
+
if (isNative) {
|
|
87
|
+
placeholder = await sock.sendMessage(jid, {
|
|
88
|
+
raw: true,
|
|
89
|
+
...buildReplayFrame(description, initialSteps, placeholderText)
|
|
90
|
+
});
|
|
91
|
+
} else {
|
|
92
|
+
placeholder = await sock.sendMessage(jid,
|
|
93
|
+
buildPlainPlaceholder(description, initialSteps, placeholderText)
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const key = placeholder?.key;
|
|
98
|
+
|
|
99
|
+
// Replay loop
|
|
100
|
+
try {
|
|
101
|
+
const currentSteps = [...initialSteps];
|
|
102
|
+
|
|
103
|
+
for (let i = 0; i < currentSteps.length; i++) {
|
|
104
|
+
if (aborted) break;
|
|
105
|
+
await delay(stepDelayMs);
|
|
106
|
+
if (aborted) break;
|
|
107
|
+
|
|
108
|
+
currentSteps[i] = { ...currentSteps[i], status: PlanningStepStatus.DONE };
|
|
109
|
+
|
|
110
|
+
if (key) {
|
|
111
|
+
if (isNative) {
|
|
112
|
+
await editPlanningBubble(sock, jid, key, description, currentSteps, placeholderText);
|
|
113
|
+
} else {
|
|
114
|
+
await editPlainBubble(sock, jid, key, description, currentSteps, placeholderText);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (!aborted && finalPauseMs > 0) {
|
|
120
|
+
await delay(finalPauseMs);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (key && !aborted) {
|
|
124
|
+
await sock.sendMessage(jid, { delete: key });
|
|
125
|
+
}
|
|
126
|
+
} catch (err) {
|
|
127
|
+
try { if (key) await sock.sendMessage(jid, { delete: key }); } catch (_) {}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
await sock.sendPresenceUpdate('paused', jid);
|
|
131
|
+
|
|
132
|
+
// Skip final send if _skipFinalSend is set (for replayPlanningOnly)
|
|
133
|
+
if (sendOptions._skipFinalSend) return placeholder;
|
|
134
|
+
|
|
135
|
+
return sock.sendMessage(jid, finalContent, sendOptions);
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* replayPlanningOnly animation WITHOUT final message.
|
|
140
|
+
*/
|
|
141
|
+
export const replayPlanningOnly = async (sock, jid, steps, options = {}) => {
|
|
142
|
+
return replayPlanning(sock, jid, steps, null, {
|
|
143
|
+
...options,
|
|
144
|
+
sendOptions: { ...options.sendOptions, _skipFinalSend: true }
|
|
145
|
+
});
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* buildReasoningSteps steps with isReasoning: true.
|
|
150
|
+
*/
|
|
151
|
+
export const buildReasoningSteps = (titles) =>
|
|
152
|
+
titles.map(title => ({ title, isReasoning: true }));
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* buildSearchSteps steps with isEnhancedSearch: true.
|
|
156
|
+
*/
|
|
157
|
+
export const buildSearchSteps = (titles) =>
|
|
158
|
+
titles.map(title => ({ title, isEnhancedSearch: true }));
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* mixedSteps mix reasoning + search + plain steps.
|
|
162
|
+
*/
|
|
163
|
+
export const mixedSteps = (defs) =>
|
|
164
|
+
defs.map(({ title, body, type }) => ({
|
|
165
|
+
title,
|
|
166
|
+
...(body ? { body } : {}),
|
|
167
|
+
...(type === 'reasoning' ? { isReasoning: true } : {}),
|
|
168
|
+
...(type === 'search' ? { isEnhancedSearch: true } : {})
|
|
169
|
+
}));
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { platform, release } from 'node:os';
|
|
2
|
+
import { proto } from '../../WAProto/index.js';
|
|
3
|
+
const PLATFORM_MAP = {
|
|
4
|
+
aix: 'AIX',
|
|
5
|
+
darwin: 'Mac OS',
|
|
6
|
+
win32: 'Windows',
|
|
7
|
+
android: 'Android',
|
|
8
|
+
freebsd: 'FreeBSD',
|
|
9
|
+
openbsd: 'OpenBSD',
|
|
10
|
+
sunos: 'Solaris',
|
|
11
|
+
linux: undefined,
|
|
12
|
+
haiku: undefined,
|
|
13
|
+
cygwin: undefined,
|
|
14
|
+
netbsd: undefined
|
|
15
|
+
};
|
|
16
|
+
export const Browsers = {
|
|
17
|
+
ubuntu: browser => ['Ubuntu', browser, '22.04.4'],
|
|
18
|
+
macOS: browser => ['Mac OS', browser, '14.4.1'],
|
|
19
|
+
baileys: browser => ['Baileys', browser, '6.5.0'],
|
|
20
|
+
windows: browser => ['Windows', browser, '10.0.22631'],
|
|
21
|
+
android: browser => [browser, 'Android', ''],
|
|
22
|
+
/** The appropriate browser based on your OS & release */
|
|
23
|
+
appropriate: browser => [PLATFORM_MAP[platform()] || 'Ubuntu', browser, release()]
|
|
24
|
+
};
|
|
25
|
+
export const getPlatformId = (browser) => {
|
|
26
|
+
const platformType = proto.DeviceProps.PlatformType[browser.toUpperCase()];
|
|
27
|
+
return platformType ? platformType.toString() : '1'; //chrome
|
|
28
|
+
};
|