kage-baileys 25.3.9 → 25.3.11
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/lib/Framework/Bot.js +36 -1
- package/lib/Utils/generics.d.ts +7 -0
- package/lib/Utils/generics.js +50 -1
- package/lib/Utils/kage-airich.js +23 -0
- package/lib/index.d.ts +14 -1
- package/lib/index.js +7 -69
- package/lib/index.mjs +1 -0
- package/package.json +1 -1
package/lib/Framework/Bot.js
CHANGED
|
@@ -3,7 +3,42 @@ import makeWASocket from "../Socket/index.js";
|
|
|
3
3
|
import { DisconnectReason } from "../Types/index.js";
|
|
4
4
|
import { isJidGroup } from "../WABinary/index.js";
|
|
5
5
|
import defaultLogger from "../Utils/logger.js";
|
|
6
|
-
import
|
|
6
|
+
import generics from "../Utils/generics.js";
|
|
7
|
+
|
|
8
|
+
// Import CommonJS utilities through their default namespace. Node's synthetic
|
|
9
|
+
// named-export detection can miss exports appended by compiled/merged CJS files.
|
|
10
|
+
// Keep startup compatible with older installs that only expose the legacy
|
|
11
|
+
// version lookup helpers.
|
|
12
|
+
const fetchBestWaVersion = async (options = {}) => {
|
|
13
|
+
const isValid = (value) => Array.isArray(value?.version) && value.version.length === 3;
|
|
14
|
+
|
|
15
|
+
if (typeof generics.fetchBestWaVersion === "function") {
|
|
16
|
+
try {
|
|
17
|
+
const result = await generics.fetchBestWaVersion(options);
|
|
18
|
+
if (isValid(result)) return result;
|
|
19
|
+
} catch (error) {
|
|
20
|
+
// Continue to the legacy lookup functions; version lookup must not stop
|
|
21
|
+
// the bot from starting when WhatsApp's public endpoint is unavailable.
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
for (const [name, source] of [
|
|
26
|
+
["fetchLatestWaWebVersion", "wa-web"],
|
|
27
|
+
["fetchLatestBaileysVersion", "baileys-upstream"]
|
|
28
|
+
]) {
|
|
29
|
+
const lookup = generics[name];
|
|
30
|
+
if (typeof lookup !== "function") continue;
|
|
31
|
+
try {
|
|
32
|
+
const result = await lookup(options);
|
|
33
|
+
if (isValid(result) && !result.error) return { ...result, source };
|
|
34
|
+
} catch (error) {
|
|
35
|
+
// Try the next known source. resolveSocketVersionConfig keeps the
|
|
36
|
+
// configured/default version when all lookups fail.
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
throw new Error("No compatible Baileys version lookup is available");
|
|
41
|
+
};
|
|
7
42
|
import { SQLiteStore } from "./Store/SQLiteStore.js";
|
|
8
43
|
import { Context } from "./Context.js";
|
|
9
44
|
import { SessionManager } from "./SessionManager.js";
|
package/lib/Utils/generics.d.ts
CHANGED
|
@@ -31,6 +31,13 @@ export function delayCancellable(ms: any): {
|
|
|
31
31
|
export function generateMessageIDV2(userId: any): string;
|
|
32
32
|
export function generateMessageID(): string;
|
|
33
33
|
export function bindWaitForConnectionUpdate(ev: any): (check: any, timeoutMs: any) => Promise<void>;
|
|
34
|
+
export function fetchBestWaVersion(options?: {}): Promise<{
|
|
35
|
+
version: number[];
|
|
36
|
+
isLatest: boolean;
|
|
37
|
+
source: "wa-web" | "baileys-upstream" | "hardcoded-fallback";
|
|
38
|
+
error?: unknown;
|
|
39
|
+
webError?: unknown;
|
|
40
|
+
}>;
|
|
34
41
|
export function fetchLatestBaileysVersion(options?: {}): Promise<{
|
|
35
42
|
version: number[];
|
|
36
43
|
isLatest: boolean;
|
package/lib/Utils/generics.js
CHANGED
|
@@ -285,7 +285,34 @@ const fetchLatestKageVersion = async (options = {}) => {
|
|
|
285
285
|
exports.fetchLatestKageVersion = fetchLatestKageVersion;
|
|
286
286
|
|
|
287
287
|
|
|
288
|
-
const fetchLatestBaileysVersion = async (options = {}) =>
|
|
288
|
+
const fetchLatestBaileysVersion = async (options = {}) => {
|
|
289
|
+
const URL = 'https://raw.githubusercontent.com/WhiskeySockets/Baileys/master/src/Defaults/index.ts';
|
|
290
|
+
try {
|
|
291
|
+
const { timeoutMs = 15000, ...fetchOptions } = options || {};
|
|
292
|
+
const response = await fetch(URL, {
|
|
293
|
+
...fetchOptions,
|
|
294
|
+
method: 'GET',
|
|
295
|
+
headers: options?.headers,
|
|
296
|
+
signal: fetchOptions.signal || AbortSignal.timeout(timeoutMs)
|
|
297
|
+
});
|
|
298
|
+
if (!response.ok) {
|
|
299
|
+
throw new Error(`Failed to fetch upstream Baileys version: ${response.status} ${response.statusText || ''}`.trim());
|
|
300
|
+
}
|
|
301
|
+
const text = await response.text();
|
|
302
|
+
const match = text.match(/const\s+version\s*=\s*\[(\d+),\s*(\d+),\s*(\d+)\]/);
|
|
303
|
+
if (!match) {
|
|
304
|
+
throw new Error('Could not parse upstream Baileys version');
|
|
305
|
+
}
|
|
306
|
+
const version = match.slice(1).map(Number);
|
|
307
|
+
const fallbackVersion = kageVersionJson.version;
|
|
308
|
+
if (version[0] !== fallbackVersion[0] || version[1] < fallbackVersion[1]) {
|
|
309
|
+
throw new Error(`Rejected incompatible upstream version ${version.join('.')}`);
|
|
310
|
+
}
|
|
311
|
+
return { version, isLatest: true };
|
|
312
|
+
} catch (error) {
|
|
313
|
+
return { version: kageVersionJson.version, isLatest: false, error };
|
|
314
|
+
}
|
|
315
|
+
};
|
|
289
316
|
exports.fetchLatestBaileysVersion = fetchLatestBaileysVersion;
|
|
290
317
|
|
|
291
318
|
|
|
@@ -1395,3 +1422,25 @@ for (const key of Object.keys(__kageModule169)) {
|
|
|
1395
1422
|
if (key !== '__esModule' && !Object.prototype.hasOwnProperty.call(exports,key)) Object.defineProperty(exports,key,{enumerable:true,configurable:true,get:()=>__kageModule169[key]});
|
|
1396
1423
|
}
|
|
1397
1424
|
Object.defineProperty(exports, Symbol.for('kage.advanced'), {value:__kageModule169, configurable:true});
|
|
1425
|
+
|
|
1426
|
+
|
|
1427
|
+
// Compatibility export required by lib/Framework/Bot.js.
|
|
1428
|
+
// Kage exposes fetchLatestWaWebVersion already; use it once and label the
|
|
1429
|
+
// result so Bot can log the source without making a duplicate network call.
|
|
1430
|
+
exports.fetchBestWaVersion = async function fetchBestWaVersion(options = {}) {
|
|
1431
|
+
const webResult = await exports.fetchLatestWaWebVersion(options);
|
|
1432
|
+
if (webResult?.isLatest) {
|
|
1433
|
+
return { ...webResult, source: 'wa-web' };
|
|
1434
|
+
}
|
|
1435
|
+
|
|
1436
|
+
const baileysResult = await exports.fetchLatestBaileysVersion(options);
|
|
1437
|
+
if (baileysResult?.isLatest) {
|
|
1438
|
+
return { ...baileysResult, source: 'baileys-upstream', webError: webResult?.error };
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1441
|
+
return {
|
|
1442
|
+
...baileysResult,
|
|
1443
|
+
source: 'hardcoded-fallback',
|
|
1444
|
+
error: baileysResult?.error || webResult?.error
|
|
1445
|
+
};
|
|
1446
|
+
};
|
package/lib/Utils/kage-airich.js
CHANGED
|
@@ -109,6 +109,24 @@ class KageAIRich {
|
|
|
109
109
|
return this;
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
+
/** Add a pre-built GenAI section without converting it into media. */
|
|
113
|
+
addSection(section) {
|
|
114
|
+
if (!section || typeof section !== 'object' || Array.isArray(section)) {
|
|
115
|
+
throw new TypeError('addSection(section) requiere un objeto');
|
|
116
|
+
}
|
|
117
|
+
if (!section.view_model || typeof section.view_model !== 'object' || Array.isArray(section.view_model)) {
|
|
118
|
+
throw new TypeError('addSection(section) requiere section.view_model');
|
|
119
|
+
}
|
|
120
|
+
let normalized;
|
|
121
|
+
try {
|
|
122
|
+
normalized = structuredClone(section);
|
|
123
|
+
} catch (error) {
|
|
124
|
+
throw new TypeError(`addSection(section) debe ser clonable: ${error?.message || error}`);
|
|
125
|
+
}
|
|
126
|
+
this._sections.push(normalized);
|
|
127
|
+
return this;
|
|
128
|
+
}
|
|
129
|
+
|
|
112
130
|
setContextInfo(contextInfo) {
|
|
113
131
|
if (contextInfo && typeof contextInfo === 'object' && !Array.isArray(contextInfo)) {
|
|
114
132
|
this._contextInfo = { ...this._contextInfo, ...contextInfo };
|
|
@@ -372,6 +390,11 @@ class KageAIRich {
|
|
|
372
390
|
userJidLid,
|
|
373
391
|
timestamp,
|
|
374
392
|
ephemeralExpiration,
|
|
393
|
+
// Compatibility flags accepted by the higher-level helper. KageAIRich
|
|
394
|
+
// deliberately performs one relay and never sends a follow-up edit.
|
|
395
|
+
bypassDownload: _bypassDownload,
|
|
396
|
+
nativeEdit: _nativeEdit,
|
|
397
|
+
skipImageFallback: _skipImageFallback,
|
|
375
398
|
...relayOptions
|
|
376
399
|
} = options;
|
|
377
400
|
|
package/lib/index.d.ts
CHANGED
|
@@ -11,7 +11,20 @@ export default makeWASocket;
|
|
|
11
11
|
import makeWASocket from './Socket/index.js';
|
|
12
12
|
//# sourceMappingURL=index.d.ts.map
|
|
13
13
|
// Builders (from lib/Builders)
|
|
14
|
-
export declare class AIRich {
|
|
14
|
+
export declare class AIRich {
|
|
15
|
+
constructor(sock: any);
|
|
16
|
+
setTitle(title: string): this;
|
|
17
|
+
setFooter(footer: string): this;
|
|
18
|
+
setContextInfo(contextInfo: Record<string, any>): this;
|
|
19
|
+
addSection(section: { view_model: Record<string, any>; [key: string]: any }): this;
|
|
20
|
+
addText(text: string): this;
|
|
21
|
+
addTable(rows: any[][]): this;
|
|
22
|
+
addHtml(html: string, options?: Record<string, any>): this;
|
|
23
|
+
build(jid: string, options?: Record<string, any>): Promise<any>;
|
|
24
|
+
send(jid: string, options?: Record<string, any>): Promise<{ key: { remoteJid: string; fromMe: true; id: string }; message: any }>;
|
|
25
|
+
}
|
|
26
|
+
export { AIRich as KageAIRich };
|
|
27
|
+
export declare function createAIRich(sock: any): AIRich;
|
|
15
28
|
export declare class Button { /* ... */ }
|
|
16
29
|
export declare class ButtonV2 { /* ... */ }
|
|
17
30
|
export declare class ButtonV3 { /* ... */ }
|
package/lib/index.js
CHANGED
|
@@ -154,53 +154,6 @@ __exportStar(require('./Utils/profile-tools.js'), exports);
|
|
|
154
154
|
Object.assign(exports.default, exports);
|
|
155
155
|
|
|
156
156
|
|
|
157
|
-
// Kage AIRich + media (integrado)
|
|
158
|
-
try {
|
|
159
|
-
const kageAirich = require('./Utils/kage-airich');
|
|
160
|
-
const kageMedia = require('./Utils/kage-media-resolve');
|
|
161
|
-
exports.AIRich = kageAirich.AIRich;
|
|
162
|
-
exports.KageAIRich = kageAirich.KageAIRich;
|
|
163
|
-
exports.createAIRich = kageAirich.createAIRich;
|
|
164
|
-
exports.resolvePublicImageUrl = kageMedia.resolvePublicImageUrl;
|
|
165
|
-
exports.toBuffer = kageMedia.toBuffer;
|
|
166
|
-
exports.DEFAULT_IMAGE = kageMedia.DEFAULT_IMAGE;
|
|
167
|
-
if (exports.default && typeof exports.default === 'object') {
|
|
168
|
-
Object.assign(exports.default, {
|
|
169
|
-
AIRich: kageAirich.AIRich,
|
|
170
|
-
KageAIRich: kageAirich.KageAIRich,
|
|
171
|
-
createAIRich: kageAirich.createAIRich,
|
|
172
|
-
DEFAULT_IMAGE: kageMedia.DEFAULT_IMAGE,
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
} catch (_) {}
|
|
176
|
-
|
|
177
|
-
try {
|
|
178
|
-
const { sendTable } = require('./Utils/kage-send-table');
|
|
179
|
-
exports.sendTable = sendTable;
|
|
180
|
-
if (exports.default && typeof exports.default === 'object') {
|
|
181
|
-
exports.default.sendTable = sendTable;
|
|
182
|
-
}
|
|
183
|
-
} catch (_) {}
|
|
184
|
-
|
|
185
|
-
try {
|
|
186
|
-
const richM = require('./Utils/kage-rich-methods');
|
|
187
|
-
Object.assign(exports, {
|
|
188
|
-
sendCodeBlock: richM.sendCodeBlock,
|
|
189
|
-
sendLatexInlineImage: richM.sendLatexInlineImage,
|
|
190
|
-
sendAIRich: richM.sendAIRich,
|
|
191
|
-
sendHtml: richM.sendHtml,
|
|
192
|
-
installRichMethods: richM.installRichMethods,
|
|
193
|
-
});
|
|
194
|
-
if (exports.default && typeof exports.default === 'object') {
|
|
195
|
-
Object.assign(exports.default, {
|
|
196
|
-
sendCodeBlock: richM.sendCodeBlock,
|
|
197
|
-
sendLatexInlineImage: richM.sendLatexInlineImage,
|
|
198
|
-
installRichMethods: richM.installRichMethods,
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
} catch (_) {}
|
|
202
|
-
|
|
203
|
-
|
|
204
157
|
// Kage rich API completa
|
|
205
158
|
try {
|
|
206
159
|
const kageAirich = require('./Utils/kage-airich');
|
|
@@ -228,26 +181,11 @@ try {
|
|
|
228
181
|
});
|
|
229
182
|
} catch (e) {}
|
|
230
183
|
|
|
184
|
+
// Async access to the full ESM Builder suite without forcing an ESM import
|
|
185
|
+
// through the CommonJS entry point.
|
|
186
|
+
exports.getBuilders = async function getBuilders() {
|
|
187
|
+
return import('./Builders/index.js');
|
|
188
|
+
};
|
|
231
189
|
|
|
232
|
-
//
|
|
233
|
-
|
|
234
|
-
// or: import { AIRich, Button, Carousel } from 'kage-baileys'
|
|
235
|
-
try {
|
|
236
|
-
// Attempt to surface names if the environment supports it
|
|
237
|
-
const buildersPath = require("path").join(__dirname, "Builders", "index.js");
|
|
238
|
-
// Pure ESM cannot be required synchronously in all Node versions.
|
|
239
|
-
// We expose a helper that returns the builders via dynamic import.
|
|
240
|
-
exports.getBuilders = async () => {
|
|
241
|
-
const mod = await import(buildersPath);
|
|
242
|
-
return mod;
|
|
243
|
-
};
|
|
244
|
-
exports.AIRich = null; // placeholder – use await import() or getBuilders()
|
|
245
|
-
exports.Button = null;
|
|
246
|
-
exports.ButtonV2 = null;
|
|
247
|
-
exports.ButtonV3 = null;
|
|
248
|
-
exports.Carousel = null;
|
|
249
|
-
exports.A2UI = null;
|
|
250
|
-
exports.BuilderHub = null;
|
|
251
|
-
} catch (e) {
|
|
252
|
-
// ignore
|
|
253
|
-
}
|
|
190
|
+
// Keep default export in sync with the stable CommonJS public exports.
|
|
191
|
+
Object.assign(exports.default, exports);
|
package/lib/index.mjs
CHANGED
|
@@ -22,6 +22,7 @@ export const generateMessageID = api.generateMessageID;
|
|
|
22
22
|
export const bindWaitForConnectionUpdate = api.bindWaitForConnectionUpdate;
|
|
23
23
|
export const printQRIfNecessaryListener = api.printQRIfNecessaryListener;
|
|
24
24
|
export const fetchLatestBaileysVersion = api.fetchLatestBaileysVersion;
|
|
25
|
+
export const fetchBestWaVersion = api.fetchBestWaVersion;
|
|
25
26
|
export const fetchLatestKageVersion = api.fetchLatestKageVersion;
|
|
26
27
|
export const fetchLatestWaWebVersion = api.fetchLatestWaWebVersion;
|
|
27
28
|
export const generateMdTagPrefix = api.generateMdTagPrefix;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kage-baileys",
|
|
3
|
-
"version": "25.3.
|
|
3
|
+
"version": "25.3.11",
|
|
4
4
|
"description": "Kage Baileys full merge — Builders + mbuilder + Framework + advanced sticker packs + KAGE pairing + extended WAProto + full TypeScript defs (.d.ts + maps) from elray + path utils. Multi-device ready.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"kage-baileys",
|