* refactor: move WhatsApp channel from src/web/ to extensions/whatsapp/ Move all WhatsApp implementation code (77 source/test files + 9 channel plugin files) from src/web/ and src/channels/plugins/*/whatsapp* to extensions/whatsapp/src/. - Leave thin re-export shims at all original locations so cross-cutting imports continue to resolve - Update plugin-sdk/whatsapp.ts to only re-export generic framework utilities; channel-specific functions imported locally by the extension - Update vi.mock paths in 15 cross-cutting test files - Rename outbound.ts -> send.ts to match extension naming conventions and avoid false positive in cfg-threading guard test - Widen tsconfig.plugin-sdk.dts.json rootDir to support shim->extension cross-directory references Part of the core-channels-to-extensions migration (PR 6/10). * style: format WhatsApp extension files * fix: correct stale import paths in WhatsApp extension tests Fix vi.importActual, test mock, and hardcoded source paths that weren't updated during the file move: - media.test.ts: vi.importActual path - onboarding.test.ts: vi.importActual path - test-helpers.ts: test/mocks/baileys.js path - monitor-inbox.test-harness.ts: incomplete media/store mock - login.test.ts: hardcoded source file path - message-action-runner.media.test.ts: vi.mock/importActual path
53 lines
1.6 KiB
TypeScript
53 lines
1.6 KiB
TypeScript
import { randomUUID } from "node:crypto";
|
|
import type { OpenClawConfig } from "../../../src/config/config.js";
|
|
import type { BackoffPolicy } from "../../../src/infra/backoff.js";
|
|
import { computeBackoff, sleepWithAbort } from "../../../src/infra/backoff.js";
|
|
import { clamp } from "../../../src/utils.js";
|
|
|
|
export type ReconnectPolicy = BackoffPolicy & {
|
|
maxAttempts: number;
|
|
};
|
|
|
|
export const DEFAULT_HEARTBEAT_SECONDS = 60;
|
|
export const DEFAULT_RECONNECT_POLICY: ReconnectPolicy = {
|
|
initialMs: 2_000,
|
|
maxMs: 30_000,
|
|
factor: 1.8,
|
|
jitter: 0.25,
|
|
maxAttempts: 12,
|
|
};
|
|
|
|
export function resolveHeartbeatSeconds(cfg: OpenClawConfig, overrideSeconds?: number): number {
|
|
const candidate = overrideSeconds ?? cfg.web?.heartbeatSeconds;
|
|
if (typeof candidate === "number" && candidate > 0) {
|
|
return candidate;
|
|
}
|
|
return DEFAULT_HEARTBEAT_SECONDS;
|
|
}
|
|
|
|
export function resolveReconnectPolicy(
|
|
cfg: OpenClawConfig,
|
|
overrides?: Partial<ReconnectPolicy>,
|
|
): ReconnectPolicy {
|
|
const reconnectOverrides = cfg.web?.reconnect ?? {};
|
|
const overrideConfig = overrides ?? {};
|
|
const merged = {
|
|
...DEFAULT_RECONNECT_POLICY,
|
|
...reconnectOverrides,
|
|
...overrideConfig,
|
|
} as ReconnectPolicy;
|
|
|
|
merged.initialMs = Math.max(250, merged.initialMs);
|
|
merged.maxMs = Math.max(merged.initialMs, merged.maxMs);
|
|
merged.factor = clamp(merged.factor, 1.1, 10);
|
|
merged.jitter = clamp(merged.jitter, 0, 1);
|
|
merged.maxAttempts = Math.max(0, Math.floor(merged.maxAttempts));
|
|
return merged;
|
|
}
|
|
|
|
export { computeBackoff, sleepWithAbort };
|
|
|
|
export function newConnectionId() {
|
|
return randomUUID();
|
|
}
|