chore: rename relay to gateway

This commit is contained in:
Peter Steinberger
2025-12-09 18:00:01 +00:00
parent bc3a14cde2
commit a3bf2bdd8c
50 changed files with 2022 additions and 2570 deletions

View File

@@ -6,7 +6,7 @@ import path from "node:path";
import sharp from "sharp";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import type { WarelayConfig } from "../config/config.js";
import type { ClawdisConfig } from "../config/config.js";
import { resetLogger, setLoggerOverride } from "../logging.js";
import * as commandQueue from "../process/command-queue.js";
import {
@@ -65,7 +65,7 @@ describe("heartbeat helpers", () => {
});
it("resolves heartbeat minutes with default and overrides", () => {
const cfgBase: WarelayConfig = {
const cfgBase: ClawdisConfig = {
inbound: {
reply: { mode: "command" as const },
},
@@ -94,7 +94,7 @@ describe("resolveHeartbeatRecipients", () => {
it("returns the sole session recipient", async () => {
const now = Date.now();
const store = await makeSessionStore({ "+1000": { updatedAt: now } });
const cfg: WarelayConfig = {
const cfg: ClawdisConfig = {
inbound: {
allowFrom: ["+1999"],
reply: { mode: "command", session: { store: store.storePath } },
@@ -112,7 +112,7 @@ describe("resolveHeartbeatRecipients", () => {
"+1000": { updatedAt: now },
"+2000": { updatedAt: now - 10 },
});
const cfg: WarelayConfig = {
const cfg: ClawdisConfig = {
inbound: {
allowFrom: ["+1999"],
reply: { mode: "command", session: { store: store.storePath } },
@@ -126,7 +126,7 @@ describe("resolveHeartbeatRecipients", () => {
it("filters wildcard allowFrom when no sessions exist", async () => {
const store = await makeSessionStore({});
const cfg: WarelayConfig = {
const cfg: ClawdisConfig = {
inbound: {
allowFrom: ["*"],
reply: { mode: "command", session: { store: store.storePath } },
@@ -141,7 +141,7 @@ describe("resolveHeartbeatRecipients", () => {
it("merges sessions and allowFrom when --all is set", async () => {
const now = Date.now();
const store = await makeSessionStore({ "+1000": { updatedAt: now } });
const cfg: WarelayConfig = {
const cfg: ClawdisConfig = {
inbound: {
allowFrom: ["+1999"],
reply: { mode: "command", session: { store: store.storePath } },
@@ -162,7 +162,7 @@ describe("partial reply gating", () => {
const replyResolver = vi.fn().mockResolvedValue({ text: "final reply" });
const mockConfig: WarelayConfig = {
const mockConfig: ClawdisConfig = {
inbound: {
reply: { mode: "command" },
allowFrom: ["*"],
@@ -342,7 +342,7 @@ describe("runWebHeartbeatOnce", () => {
const replyResolver = vi.fn().mockResolvedValue({ text: HEARTBEAT_TOKEN });
const runtime = { log: vi.fn(), error: vi.fn(), exit: vi.fn() } as never;
const cfg: WarelayConfig = {
const cfg: ClawdisConfig = {
inbound: {
allowFrom: ["+4367"],
reply: {
@@ -385,7 +385,7 @@ describe("runWebHeartbeatOnce", () => {
}));
const resolver = vi.fn(async () => ({ text: HEARTBEAT_TOKEN }));
const cfg: WarelayConfig = {
const cfg: ClawdisConfig = {
inbound: {
allowFrom: ["+1999"],
reply: {

View File

@@ -41,7 +41,7 @@ export function setHeartbeatsEnabled(enabled: boolean) {
}
/**
* Send a message via IPC if relay is running, otherwise fall back to direct.
* Send a message via IPC if gateway is running, otherwise fall back to direct.
* This avoids Signal session corruption from multiple Baileys connections.
*/
async function sendWithIpcFallback(
@@ -52,7 +52,7 @@ async function sendWithIpcFallback(
const ipcResult = await sendViaIpc(to, message, opts.mediaUrl);
if (ipcResult?.success && ipcResult.messageId) {
if (opts.verbose) {
console.log(info(`Sent via relay IPC (avoiding session corruption)`));
console.log(info(`Sent via gateway IPC (avoiding session corruption)`));
}
return { messageId: ipcResult.messageId, toJid: `${to}@s.whatsapp.net` };
}
@@ -720,7 +720,7 @@ export async function monitorWebProvider(
);
// Avoid noisy MaxListenersExceeded warnings in test environments where
// multiple relay instances may be constructed.
// multiple gateway instances may be constructed.
const currentMaxListeners = process.getMaxListeners?.() ?? 10;
if (process.setMaxListeners && currentMaxListeners < 50) {
process.setMaxListeners(50);
@@ -1021,7 +1021,7 @@ export async function monitorWebProvider(
// Surface a concise connection event for the next main-session turn/heartbeat.
const { e164: selfE164 } = readWebSelfId();
enqueueSystemEvent(
`WhatsApp relay connected${selfE164 ? ` as ${selfE164}` : ""}.`,
`WhatsApp gateway connected${selfE164 ? ` as ${selfE164}` : ""}.`,
);
// Start IPC server so `clawdis send` can use this connection
@@ -1099,10 +1099,10 @@ export async function monitorWebProvider(
if (minutesSinceLastMessage && minutesSinceLastMessage > 30) {
heartbeatLogger.warn(
logData,
"⚠️ web relay heartbeat - no messages in 30+ minutes",
"⚠️ web gateway heartbeat - no messages in 30+ minutes",
);
} else {
heartbeatLogger.info(logData, "web relay heartbeat");
heartbeatLogger.info(logData, "web gateway heartbeat");
}
}, heartbeatSeconds * 1000);
@@ -1398,7 +1398,7 @@ export async function monitorWebProvider(
);
enqueueSystemEvent(
`WhatsApp relay disconnected (status ${status ?? "unknown"})`,
`WhatsApp gateway disconnected (status ${status ?? "unknown"})`,
);
if (loggedOut) {

View File

@@ -64,7 +64,7 @@ export async function monitorWebInbox(options: {
onCloseResolve = resolve;
});
try {
// Advertise that the relay is online right after connecting.
// Advertise that the gateway is online right after connecting.
await sock.sendPresenceUpdate("available");
if (isVerbose()) logVerbose("Sent global 'available' presence on connect");
} catch (err) {

View File

@@ -1,7 +1,7 @@
/**
* IPC server for clawdis relay.
* IPC server for clawdis gateway.
*
* When the relay is running, it starts a Unix socket server that allows
* When the gateway is running, it starts a Unix socket server that allows
* `clawdis send` and `clawdis heartbeat` to send messages through the
* existing WhatsApp connection instead of creating new ones.
*
@@ -40,7 +40,7 @@ type SendHandler = (
let server: net.Server | null = null;
/**
* Start the IPC server. Called by the relay when it starts.
* Start the IPC server. Called by the gateway when it starts.
*/
export function startIpcServer(sendHandler: SendHandler): void {
const logger = getChildLogger({ module: "ipc-server" });
@@ -126,7 +126,7 @@ export function startIpcServer(sendHandler: SendHandler): void {
}
/**
* Stop the IPC server. Called when relay shuts down.
* Stop the IPC server. Called when gateway shuts down.
*/
export function stopIpcServer(): void {
if (server) {
@@ -141,7 +141,7 @@ export function stopIpcServer(): void {
}
/**
* Check if the relay IPC server is running.
* Check if the gateway IPC server is running.
*/
export function isRelayRunning(): boolean {
try {
@@ -154,8 +154,8 @@ export function isRelayRunning(): boolean {
}
/**
* Send a message through the running relay's IPC.
* Returns null if relay is not running.
* Send a message through the running gateway's IPC.
* Returns null if gateway is not running.
*/
export async function sendViaIpc(
to: string,
@@ -214,7 +214,7 @@ export async function sendViaIpc(
if (!resolved) {
resolved = true;
clearTimeout(timeout);
// Socket exists but can't connect - relay might have crashed
// Socket exists but can't connect - gateway might have crashed
resolve(null);
}
});

View File

@@ -1,6 +1,6 @@
import { describe, expect, it } from "vitest";
import type { WarelayConfig } from "../config/config.js";
import type { ClawdisConfig } from "../config/config.js";
import {
computeBackoff,
DEFAULT_HEARTBEAT_SECONDS,
@@ -11,7 +11,7 @@ import {
} from "./reconnect.js";
describe("web reconnect helpers", () => {
const cfg: WarelayConfig = {};
const cfg: ClawdisConfig = {};
it("resolves sane reconnect defaults with clamps", () => {
const policy = resolveReconnectPolicy(cfg, {

View File

@@ -1,6 +1,6 @@
import { randomUUID } from "node:crypto";
import type { WarelayConfig } from "../config/config.js";
import type { ClawdisConfig } from "../config/config.js";
export type ReconnectPolicy = {
initialMs: number;
@@ -23,7 +23,7 @@ const clamp = (val: number, min: number, max: number) =>
Math.max(min, Math.min(max, val));
export function resolveHeartbeatSeconds(
cfg: WarelayConfig,
cfg: ClawdisConfig,
overrideSeconds?: number,
): number {
const candidate = overrideSeconds ?? cfg.web?.heartbeatSeconds;
@@ -32,7 +32,7 @@ export function resolveHeartbeatSeconds(
}
export function resolveReconnectPolicy(
cfg: WarelayConfig,
cfg: ClawdisConfig,
overrides?: Partial<ReconnectPolicy>,
): ReconnectPolicy {
const merged = {