@leg3ndy/otto-bridge 0.6.4 → 0.6.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/README.md +4 -4
- package/dist/executors/native_macos.js +10 -2
- package/dist/types.js +1 -1
- package/dist/whatsapp_background.js +50 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -33,10 +33,10 @@ Enquanto o pacote nao estiver publicado, voce pode gerar um tarball local:
|
|
|
33
33
|
|
|
34
34
|
```bash
|
|
35
35
|
npm pack
|
|
36
|
-
npm install -g ./leg3ndy-otto-bridge-0.6.
|
|
36
|
+
npm install -g ./leg3ndy-otto-bridge-0.6.5.tgz
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
-
No `0.6.
|
|
39
|
+
No `0.6.5`, `playwright` deixa de ser opcional no `otto-bridge`. O primeiro `npm install -g @leg3ndy/otto-bridge` pode demorar mais porque instala o browser persistente usado pelo WhatsApp Web e pelos fluxos web em background do bridge.
|
|
40
40
|
|
|
41
41
|
## Publicacao
|
|
42
42
|
|
|
@@ -106,7 +106,7 @@ otto-bridge run --executor clawd-cursor --clawd-url http://127.0.0.1:3847
|
|
|
106
106
|
|
|
107
107
|
### WhatsApp Web em background
|
|
108
108
|
|
|
109
|
-
Fluxo recomendado no `0.6.
|
|
109
|
+
Fluxo recomendado no `0.6.5`:
|
|
110
110
|
|
|
111
111
|
```bash
|
|
112
112
|
otto-bridge extensions --install whatsappweb
|
|
@@ -116,7 +116,7 @@ otto-bridge extensions --status whatsappweb
|
|
|
116
116
|
|
|
117
117
|
O setup agora abre o login do WhatsApp Web em um browser persistente do proprio bridge. Depois do QR code, o Otto usa a sessao local em background, sem depender de aba visivel no Safari.
|
|
118
118
|
|
|
119
|
-
Contrato do `0.6.
|
|
119
|
+
Contrato do `0.6.5`:
|
|
120
120
|
|
|
121
121
|
- `otto-bridge extensions --setup whatsappweb`: autentica a sessao uma vez
|
|
122
122
|
- `otto-bridge run`: mantem o browser persistente do WhatsApp vivo em background enquanto o runtime estiver ativo
|
|
@@ -33,6 +33,8 @@ const KNOWN_SITES = [
|
|
|
33
33
|
{ label: "X", url: "https://x.com", patterns: [/\bx\.com\b/i, /\btwitter\b/i, /\bxis\b/i] },
|
|
34
34
|
];
|
|
35
35
|
const WHATSAPP_WEB_EXTENSION_SLUG = "whatsappweb";
|
|
36
|
+
const WHATSAPP_EXPECTED_CONNECTED_TIMEOUT_MS = 45_000;
|
|
37
|
+
const WHATSAPP_EXPECTED_CONNECTED_QR_STABILITY_WINDOW_MS = 10_000;
|
|
36
38
|
const FILE_SEARCH_SKIP_DIRS = new Set([
|
|
37
39
|
".git",
|
|
38
40
|
"node_modules",
|
|
@@ -2218,7 +2220,10 @@ return {
|
|
|
2218
2220
|
const backgroundBrowser = await this.getWhatsAppBackgroundBrowser().catch(() => null);
|
|
2219
2221
|
if (backgroundBrowser) {
|
|
2220
2222
|
try {
|
|
2221
|
-
const state = await backgroundBrowser.waitForStableSessionState(
|
|
2223
|
+
const state = await backgroundBrowser.waitForStableSessionState({
|
|
2224
|
+
timeoutMs: WHATSAPP_EXPECTED_CONNECTED_TIMEOUT_MS,
|
|
2225
|
+
qrStabilityWindowMs: WHATSAPP_EXPECTED_CONNECTED_QR_STABILITY_WINDOW_MS,
|
|
2226
|
+
});
|
|
2222
2227
|
if (state.connected) {
|
|
2223
2228
|
await this.syncWhatsAppExtensionState("connected", "Sessao local do WhatsApp Web pronta para uso no browser em background.", { runtimeAttached: true });
|
|
2224
2229
|
return;
|
|
@@ -2317,7 +2322,10 @@ return {
|
|
|
2317
2322
|
return;
|
|
2318
2323
|
}
|
|
2319
2324
|
try {
|
|
2320
|
-
const state = await backgroundBrowser.waitForStableSessionState({
|
|
2325
|
+
const state = await backgroundBrowser.waitForStableSessionState({
|
|
2326
|
+
timeoutMs: WHATSAPP_EXPECTED_CONNECTED_TIMEOUT_MS,
|
|
2327
|
+
qrStabilityWindowMs: WHATSAPP_EXPECTED_CONNECTED_QR_STABILITY_WINDOW_MS,
|
|
2328
|
+
});
|
|
2321
2329
|
if (state.connected) {
|
|
2322
2330
|
await this.syncWhatsAppExtensionState("connected", "Sessao local do WhatsApp Web mantida em background enquanto `otto-bridge run` estiver ativo.", { runtimeAttached: true });
|
|
2323
2331
|
return;
|
package/dist/types.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export const BRIDGE_CONFIG_VERSION = 1;
|
|
2
|
-
export const BRIDGE_VERSION = "0.6.
|
|
2
|
+
export const BRIDGE_VERSION = "0.6.5";
|
|
3
3
|
export const BRIDGE_PACKAGE_NAME = "@leg3ndy/otto-bridge";
|
|
4
4
|
export const DEFAULT_API_BASE_URL = "http://localhost:8000";
|
|
5
5
|
export const DEFAULT_POLL_INTERVAL_MS = 3000;
|
|
@@ -7,6 +7,13 @@ const DEFAULT_SETUP_TIMEOUT_MS = 5 * 60 * 1000;
|
|
|
7
7
|
const DEFAULT_SESSION_SETTLE_TIMEOUT_MS = 15_000;
|
|
8
8
|
const DEFAULT_SESSION_POLL_INTERVAL_MS = 1_000;
|
|
9
9
|
const DEFAULT_QR_STABILITY_WINDOW_MS = 4_000;
|
|
10
|
+
const DEFAULT_EXPECTED_CONNECTED_TIMEOUT_MS = 45_000;
|
|
11
|
+
const DEFAULT_EXPECTED_CONNECTED_QR_STABILITY_WINDOW_MS = 10_000;
|
|
12
|
+
const DEFAULT_POST_LOGIN_STABILIZE_MS = 10_000;
|
|
13
|
+
const DEFAULT_REOPEN_VERIFY_DELAY_MS = 2_000;
|
|
14
|
+
function delay(ms) {
|
|
15
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
16
|
+
}
|
|
10
17
|
function moduleDir() {
|
|
11
18
|
return path.dirname(fileURLToPath(import.meta.url));
|
|
12
19
|
}
|
|
@@ -116,6 +123,9 @@ export class WhatsAppBackgroundBrowser {
|
|
|
116
123
|
}
|
|
117
124
|
await current.close().catch(() => undefined);
|
|
118
125
|
}
|
|
126
|
+
async waitForTimeout(timeoutMs) {
|
|
127
|
+
await this.page?.waitForTimeout(Math.max(0, Number(timeoutMs || 0)));
|
|
128
|
+
}
|
|
119
129
|
async getSessionState() {
|
|
120
130
|
const state = await this.withPage(async (page) => {
|
|
121
131
|
await this.ensureWhatsAppPage();
|
|
@@ -494,7 +504,10 @@ export async function detectWhatsAppBackgroundStatus() {
|
|
|
494
504
|
}
|
|
495
505
|
const browser = new WhatsAppBackgroundBrowser({ headless: true });
|
|
496
506
|
try {
|
|
497
|
-
const state = await browser.waitForStableSessionState(
|
|
507
|
+
const state = await browser.waitForStableSessionState({
|
|
508
|
+
timeoutMs: DEFAULT_EXPECTED_CONNECTED_TIMEOUT_MS,
|
|
509
|
+
qrStabilityWindowMs: DEFAULT_EXPECTED_CONNECTED_QR_STABILITY_WINDOW_MS,
|
|
510
|
+
});
|
|
498
511
|
return sessionStateToStatus(state);
|
|
499
512
|
}
|
|
500
513
|
catch (error) {
|
|
@@ -508,6 +521,20 @@ export async function detectWhatsAppBackgroundStatus() {
|
|
|
508
521
|
await browser.close();
|
|
509
522
|
}
|
|
510
523
|
}
|
|
524
|
+
async function verifyWhatsAppBackgroundSessionPersistence(options) {
|
|
525
|
+
const browser = new WhatsAppBackgroundBrowser({ headless: true });
|
|
526
|
+
try {
|
|
527
|
+
options?.log?.("Confirmando se a sessao persistiu no browser em background do bridge...");
|
|
528
|
+
const state = await browser.waitForStableSessionState({
|
|
529
|
+
timeoutMs: DEFAULT_EXPECTED_CONNECTED_TIMEOUT_MS,
|
|
530
|
+
qrStabilityWindowMs: DEFAULT_EXPECTED_CONNECTED_QR_STABILITY_WINDOW_MS,
|
|
531
|
+
});
|
|
532
|
+
return sessionStateToStatus(state);
|
|
533
|
+
}
|
|
534
|
+
finally {
|
|
535
|
+
await browser.close();
|
|
536
|
+
}
|
|
537
|
+
}
|
|
511
538
|
export async function runWhatsAppBackgroundSetup(options) {
|
|
512
539
|
const browser = new WhatsAppBackgroundBrowser({ headless: false });
|
|
513
540
|
const log = options?.log;
|
|
@@ -530,9 +557,29 @@ export async function runWhatsAppBackgroundSetup(options) {
|
|
|
530
557
|
notes: "O setup abriu o browser persistente, mas o login ainda nao foi concluido.",
|
|
531
558
|
};
|
|
532
559
|
}
|
|
533
|
-
|
|
560
|
+
log?.("Login detectado. Finalizando a sincronizacao local da sessao...");
|
|
561
|
+
await browser.waitForTimeout(DEFAULT_POST_LOGIN_STABILIZE_MS);
|
|
562
|
+
const settledState = await browser.waitForStableSessionState({
|
|
563
|
+
timeoutMs: 20_000,
|
|
564
|
+
qrStabilityWindowMs: DEFAULT_EXPECTED_CONNECTED_QR_STABILITY_WINDOW_MS,
|
|
565
|
+
});
|
|
566
|
+
if (!settledState.connected) {
|
|
567
|
+
return {
|
|
568
|
+
status: "waiting_login",
|
|
569
|
+
notes: "O QR foi autenticado, mas a sessao ainda nao terminou de sincronizar. Aguarde alguns segundos e rode `otto-bridge extensions --status whatsappweb`.",
|
|
570
|
+
};
|
|
571
|
+
}
|
|
534
572
|
}
|
|
535
573
|
finally {
|
|
536
|
-
await browser.close();
|
|
574
|
+
await browser.close().catch(() => undefined);
|
|
575
|
+
}
|
|
576
|
+
await delay(DEFAULT_REOPEN_VERIFY_DELAY_MS);
|
|
577
|
+
const verified = await verifyWhatsAppBackgroundSessionPersistence({ log });
|
|
578
|
+
if (verified.status === "connected") {
|
|
579
|
+
return verified;
|
|
537
580
|
}
|
|
581
|
+
return {
|
|
582
|
+
status: "waiting_login",
|
|
583
|
+
notes: "O login foi detectado, mas a sessao ainda nao ficou pronta para reabrir em background. Aguarde alguns segundos e rode `otto-bridge extensions --status whatsappweb`.",
|
|
584
|
+
};
|
|
538
585
|
}
|