UNPKG

@gguf/claw

Version:

Multi-channel AI gateway with extensible messaging integrations

62 lines (60 loc) 2.54 kB
import { t as __exportAll } from "./rolldown-runtime-Cbj13DAv.js"; import { c as logoutWeb, r as resolveWhatsAppAccount } from "./accounts-Dy3mxoHH.js"; import { B as danger, V as info, q as success } from "./registry-C8pj8ctW.js"; import { n as loadConfig } from "./config-DA0pxYcO.js"; import { i as defaultRuntime } from "./subsystem-BfLMZ8kW.js"; import { j as logInfo } from "./agent-scope-OWMdRegz.js"; import { t as formatCliCommand } from "./command-format-sreXrOOr.js"; import { i as waitForWaConnection, n as formatError, t as createWaSocket } from "./session-ODHSPCMl.js"; import { DisconnectReason } from "@whiskeysockets/baileys"; //#region src/web/login.ts var login_exports = /* @__PURE__ */ __exportAll({ loginWeb: () => loginWeb }); async function loginWeb(verbose, waitForConnection, runtime = defaultRuntime, accountId) { const wait = waitForConnection ?? waitForWaConnection; const account = resolveWhatsAppAccount({ cfg: loadConfig(), accountId }); const sock = await createWaSocket(true, verbose, { authDir: account.authDir }); logInfo("Waiting for WhatsApp connection...", runtime); try { await wait(sock); console.log(success("✅ Linked! Credentials saved for future sends.")); } catch (err) { const code = err?.error?.output?.statusCode ?? err?.output?.statusCode; if (code === 515) { console.log(info("WhatsApp asked for a restart after pairing (code 515); creds are saved. Restarting connection once…")); try { sock.ws?.close(); } catch {} const retry = await createWaSocket(false, verbose, { authDir: account.authDir }); try { await wait(retry); console.log(success("✅ Linked after restart; web session ready.")); return; } finally { setTimeout(() => retry.ws?.close(), 500); } } if (code === DisconnectReason.loggedOut) { await logoutWeb({ authDir: account.authDir, isLegacyAuthDir: account.isLegacyAuthDir, runtime }); console.error(danger(`WhatsApp reported the session is logged out. Cleared cached web session; please rerun ${formatCliCommand("openclaw channels login")} and scan the QR again.`)); throw new Error("Session logged out; cache cleared. Re-run login.", { cause: err }); } const formatted = formatError(err); console.error(danger(`WhatsApp Web connection ended before fully opening. ${formatted}`)); throw new Error(formatted, { cause: err }); } finally { setTimeout(() => { try { sock.ws?.close(); } catch {} }, 500); } } //#endregion export { login_exports as n, loginWeb as t };