chore: fix lint after logging tweaks

This commit is contained in:
Peter Steinberger
2025-12-26 09:08:37 +00:00
parent 917cb8fa67
commit d6f07c9f91
5 changed files with 39 additions and 30 deletions

View File

@@ -1,7 +1,6 @@
import { describe, expect, it } from "vitest";
import type { ClawdisConfig } from "../config/config.js";
import { HEARTBEAT_PROMPT } from "../auto-reply/heartbeat.js";
import type { ClawdisConfig } from "../config/config.js";
import {
resolveHeartbeatDeliveryTarget,
resolveHeartbeatIntervalMs,

View File

@@ -1,5 +1,8 @@
import { chunkText } from "../auto-reply/chunk.js";
import { HEARTBEAT_PROMPT, stripHeartbeatToken } from "../auto-reply/heartbeat.js";
import {
HEARTBEAT_PROMPT,
stripHeartbeatToken,
} from "../auto-reply/heartbeat.js";
import { getReplyFromConfig } from "../auto-reply/reply.js";
import type { ReplyPayload } from "../auto-reply/types.js";
import { parseDurationMs } from "../cli/parse-duration.js";
@@ -8,21 +11,21 @@ import { loadConfig } from "../config/config.js";
import {
loadSessionStore,
resolveStorePath,
saveSessionStore,
type SessionEntry,
saveSessionStore,
} from "../config/sessions.js";
import { formatErrorMessage } from "../infra/errors.js";
import { createSubsystemLogger } from "../logging.js";
import { getQueueSize } from "../process/command-queue.js";
import { defaultRuntime, type RuntimeEnv } from "../runtime.js";
import { normalizeE164 } from "../utils.js";
import { sendMessageTelegram } from "../telegram/send.js";
import { normalizeE164 } from "../utils.js";
import { sendMessageWhatsApp } from "../web/outbound.js";
import { emitHeartbeatEvent } from "./heartbeat-events.js";
import {
type HeartbeatRunResult,
requestHeartbeatNow,
setHeartbeatWakeHandler,
type HeartbeatRunResult,
} from "./heartbeat-wake.js";
export type HeartbeatTarget = "last" | "whatsapp" | "telegram" | "none";
@@ -93,7 +96,7 @@ function resolveHeartbeatSender(params: {
lastTo?.trim(),
lastChannel === "telegram" && lastTo ? `telegram:${lastTo}` : undefined,
lastChannel === "whatsapp" && lastTo ? `whatsapp:${lastTo}` : undefined,
].filter((val): val is string => Boolean(val && val.trim()));
].filter((val): val is string => Boolean(val?.trim()));
const allowList = allowFrom
.map((entry) => String(entry))
@@ -156,23 +159,8 @@ export function resolveHeartbeatDeliveryTarget(params: {
(target === "last" ? lastTo : undefined);
if (!channel || !to) {
return { channel: "none", reason: "no-target" };
}
async function restoreHeartbeatUpdatedAt(params: {
storePath: string;
sessionKey: string;
updatedAt?: number;
}) {
const { storePath, sessionKey, updatedAt } = params;
if (typeof updatedAt !== "number") return;
const store = loadSessionStore(storePath);
const entry = store[sessionKey];
if (!entry) return;
if (entry.updatedAt === updatedAt) return;
store[sessionKey] = { ...entry, updatedAt };
await saveSessionStore(storePath, store);
}
return { channel: "none", reason: "no-target" };
}
if (channel !== "whatsapp") {
return { channel, to };
@@ -190,6 +178,21 @@ async function restoreHeartbeatUpdatedAt(params: {
return { channel, to: allowFrom[0], reason: "allowFrom-fallback" };
}
async function restoreHeartbeatUpdatedAt(params: {
storePath: string;
sessionKey: string;
updatedAt?: number;
}) {
const { storePath, sessionKey, updatedAt } = params;
if (typeof updatedAt !== "number") return;
const store = loadSessionStore(storePath);
const entry = store[sessionKey];
if (!entry) return;
if (entry.updatedAt === updatedAt) return;
store[sessionKey] = { ...entry, updatedAt };
await saveSessionStore(storePath, store);
}
function normalizeHeartbeatReply(
payload: ReplyPayload,
responsePrefix?: string,
@@ -334,7 +337,8 @@ export async function runHeartbeatOnce(opts: {
const delivery = resolveHeartbeatDeliveryTarget({ cfg, entry });
const mediaUrls =
replyPayload.mediaUrls ?? (replyPayload.mediaUrl ? [replyPayload.mediaUrl] : []);
replyPayload.mediaUrls ??
(replyPayload.mediaUrl ? [replyPayload.mediaUrl] : []);
if (delivery.channel === "none" || !delivery.to) {
emitHeartbeatEvent({

View File

@@ -58,7 +58,10 @@ export function setHeartbeatWakeHandler(next: HeartbeatWakeHandler | null) {
}
}
export function requestHeartbeatNow(opts?: { reason?: string; coalesceMs?: number }) {
export function requestHeartbeatNow(opts?: {
reason?: string;
coalesceMs?: number;
}) {
pendingReason = opts?.reason ?? pendingReason ?? "requested";
schedule(opts?.coalesceMs ?? DEFAULT_COALESCE_MS);
}