lint: format and stabilize gateway health
This commit is contained in:
@@ -805,13 +805,13 @@ export async function runCommandReply(
|
||||
}
|
||||
},
|
||||
});
|
||||
let stdoutUsed = stdout;
|
||||
let stderrUsed = stderr;
|
||||
let codeUsed = code;
|
||||
let signalUsed = signal;
|
||||
let killedUsed = killed;
|
||||
let rpcAssistantText = extractRpcAssistantText(stdoutUsed);
|
||||
let rawStdout = stdoutUsed.trim();
|
||||
const stdoutUsed = stdout;
|
||||
const stderrUsed = stderr;
|
||||
const codeUsed = code;
|
||||
const signalUsed = signal;
|
||||
const killedUsed = killed;
|
||||
const rpcAssistantText = extractRpcAssistantText(stdoutUsed);
|
||||
const rawStdout = stdoutUsed.trim();
|
||||
let mediaFromCommand: string[] | undefined;
|
||||
const trimmed = stripRpcNoise(rawStdout);
|
||||
if (stderrUsed?.trim()) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { join } from "node:path";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import * as tauRpc from "../process/tau-rpc.js";
|
||||
|
||||
@@ -769,7 +769,11 @@ export async function getReplyFromConfig(
|
||||
const returnedSessionId = meta.agentMeta?.sessionId;
|
||||
// TODO: remove once pi-mono persists stable session ids for custom --session paths.
|
||||
const allowMetaSessionId = false;
|
||||
if (allowMetaSessionId && returnedSessionId && returnedSessionId !== sessionId) {
|
||||
if (
|
||||
allowMetaSessionId &&
|
||||
returnedSessionId &&
|
||||
returnedSessionId !== sessionId
|
||||
) {
|
||||
const entry = sessionEntry ??
|
||||
sessionStore[sessionKey] ?? {
|
||||
sessionId: returnedSessionId,
|
||||
|
||||
@@ -238,7 +238,10 @@ Examples:
|
||||
const webchatPort = opts.webchatPort
|
||||
? Number.parseInt(String(opts.webchatPort), 10)
|
||||
: undefined;
|
||||
if (webchatPort !== undefined && (Number.isNaN(webchatPort) || webchatPort <= 0)) {
|
||||
if (
|
||||
webchatPort !== undefined &&
|
||||
(Number.isNaN(webchatPort) || webchatPort <= 0)
|
||||
) {
|
||||
defaultRuntime.error("Invalid webchat port");
|
||||
defaultRuntime.exit(1);
|
||||
}
|
||||
@@ -290,7 +293,12 @@ Examples:
|
||||
|
||||
const callGatewayCli = async (
|
||||
method: string,
|
||||
opts: { url?: string; token?: string; timeout?: string; expectFinal?: boolean },
|
||||
opts: {
|
||||
url?: string;
|
||||
token?: string;
|
||||
timeout?: string;
|
||||
expectFinal?: boolean;
|
||||
},
|
||||
params?: unknown,
|
||||
) =>
|
||||
callGateway({
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
import { loadConfig } from "../config/config.js";
|
||||
import { loadSessionStore, resolveStorePath } from "../config/sessions.js";
|
||||
import { callGateway } from "../gateway/call.js";
|
||||
import { info } from "../globals.js";
|
||||
import type { RuntimeEnv } from "../runtime.js";
|
||||
import { makeProxyFetch } from "../telegram/proxy.js";
|
||||
import { resolveHeartbeatSeconds } from "../web/reconnect.js";
|
||||
import { getWebAuthAgeMs, logWebSelfId, webAuthExists } from "../web/session.js";
|
||||
import { callGateway } from "../gateway/call.js";
|
||||
import {
|
||||
getWebAuthAgeMs,
|
||||
logWebSelfId,
|
||||
webAuthExists,
|
||||
} from "../web/session.js";
|
||||
|
||||
type TelegramProbe = {
|
||||
ok: boolean;
|
||||
|
||||
@@ -6,11 +6,11 @@ import {
|
||||
resolveStorePath,
|
||||
type SessionEntry,
|
||||
} from "../config/sessions.js";
|
||||
import { callGateway } from "../gateway/call.js";
|
||||
import { info } from "../globals.js";
|
||||
import { buildProviderSummary } from "../infra/provider-summary.js";
|
||||
import { peekSystemEvents } from "../infra/system-events.js";
|
||||
import type { RuntimeEnv } from "../runtime.js";
|
||||
import { callGateway } from "../gateway/call.js";
|
||||
import { resolveHeartbeatSeconds } from "../web/reconnect.js";
|
||||
import {
|
||||
getWebAuthAgeMs,
|
||||
|
||||
@@ -233,7 +233,7 @@ function formatError(err: unknown): string {
|
||||
return JSON.stringify(err, null, 2);
|
||||
}
|
||||
|
||||
async function refreshHealthSnapshot(opts?: { probe?: boolean }) {
|
||||
async function refreshHealthSnapshot(_opts?: { probe?: boolean }) {
|
||||
if (!healthRefresh) {
|
||||
healthRefresh = (async () => {
|
||||
const snap = await getHealthSnapshot(undefined);
|
||||
|
||||
@@ -15,7 +15,9 @@ describe("sendMessageTelegram", () => {
|
||||
message_id: 42,
|
||||
chat: { id: chatId },
|
||||
});
|
||||
const api = { sendMessage } as unknown as { sendMessage: typeof sendMessage };
|
||||
const api = { sendMessage } as unknown as {
|
||||
sendMessage: typeof sendMessage;
|
||||
};
|
||||
|
||||
const res = await sendMessageTelegram(chatId, "_oops_", {
|
||||
token: "tok",
|
||||
|
||||
@@ -327,10 +327,10 @@ export async function runWebHeartbeatOnce(opts: {
|
||||
{ to, reason: "heartbeat-token", rawLength: replyPayload.text?.length },
|
||||
"heartbeat skipped",
|
||||
);
|
||||
console.log(success("heartbeat: ok (HEARTBEAT_OK)"));
|
||||
emitHeartbeatEvent({ status: "ok-token", to });
|
||||
return;
|
||||
}
|
||||
console.log(success("heartbeat: ok (HEARTBEAT_OK)"));
|
||||
emitHeartbeatEvent({ status: "ok-token", to });
|
||||
return;
|
||||
}
|
||||
|
||||
if (hasMedia) {
|
||||
heartbeatLogger.warn(
|
||||
|
||||
@@ -38,7 +38,7 @@ export async function sendMessageWhatsApp(
|
||||
mediaType =
|
||||
media.contentType === "audio/ogg"
|
||||
? "audio/ogg; codecs=opus"
|
||||
: media.contentType ?? "application/octet-stream";
|
||||
: (media.contentType ?? "application/octet-stream");
|
||||
} else if (media.kind === "video") {
|
||||
text = caption ?? "";
|
||||
} else if (media.kind === "image") {
|
||||
@@ -54,18 +54,9 @@ export async function sendMessageWhatsApp(
|
||||
{ jid, hasMedia: Boolean(options.mediaUrl) },
|
||||
"sending message",
|
||||
);
|
||||
const result = await (async () => {
|
||||
if (!active) throw new Error("Active web listener missing");
|
||||
let mediaBuffer: Buffer | undefined;
|
||||
let mediaType: string | undefined;
|
||||
if (options.mediaUrl) {
|
||||
const media = await loadWebMedia(options.mediaUrl);
|
||||
mediaBuffer = media.buffer;
|
||||
mediaType = media.contentType;
|
||||
}
|
||||
await active.sendComposingTo(to);
|
||||
return active.sendMessage(to, text, mediaBuffer, mediaType);
|
||||
})();
|
||||
if (!active) throw new Error("Active web listener missing");
|
||||
await active.sendComposingTo(to);
|
||||
const result = await active.sendMessage(to, text, mediaBuffer, mediaType);
|
||||
const messageId =
|
||||
(result as { messageId?: string })?.messageId ?? "unknown";
|
||||
logInfo(
|
||||
|
||||
@@ -160,9 +160,7 @@ export async function __broadcastGatewayEventForTests() {
|
||||
// no-op
|
||||
}
|
||||
|
||||
export async function ensureWebChatServerFromConfig(
|
||||
overridePort?: number,
|
||||
) {
|
||||
export async function ensureWebChatServerFromConfig(overridePort?: number) {
|
||||
const cfg = loadConfig();
|
||||
if (cfg.webchat?.enabled === false) return null;
|
||||
const port = overridePort ?? cfg.webchat?.port ?? WEBCHAT_DEFAULT_PORT;
|
||||
|
||||
Reference in New Issue
Block a user