chore: fix type regressions and helpers
This commit is contained in:
@@ -70,8 +70,8 @@ const ClaudeJsonSchema = z
|
||||
num_turns: z.number().optional(),
|
||||
session_id: z.string().optional(),
|
||||
total_cost_usd: z.number().optional(),
|
||||
usage: z.record(z.any()).optional(),
|
||||
modelUsage: z.record(z.any()).optional(),
|
||||
usage: z.record(z.string(), z.any()).optional(),
|
||||
modelUsage: z.record(z.string(), z.any()).optional(),
|
||||
})
|
||||
.passthrough()
|
||||
.refine(
|
||||
|
||||
@@ -197,6 +197,10 @@ With Tailscale:
|
||||
const deps = createDefaultDeps();
|
||||
try {
|
||||
const server = await webhookCommand(opts, deps, defaultRuntime);
|
||||
if (!server) {
|
||||
defaultRuntime.log(info("Webhook dry-run complete; no server started."));
|
||||
return;
|
||||
}
|
||||
process.on("SIGINT", () => {
|
||||
server.close(() => {
|
||||
console.log("\n👋 Webhook stopped");
|
||||
@@ -227,6 +231,10 @@ With Tailscale:
|
||||
const deps = createDefaultDeps();
|
||||
try {
|
||||
const { server } = await upCommand(opts, deps, defaultRuntime);
|
||||
if (!server) {
|
||||
defaultRuntime.log(info("Up dry-run complete; no server started."));
|
||||
return;
|
||||
}
|
||||
process.on("SIGINT", () => {
|
||||
server.close(() => {
|
||||
console.log("\n👋 Webhook stopped");
|
||||
|
||||
@@ -47,7 +47,7 @@ export async function upCommand(
|
||||
}
|
||||
const twilioClient = deps.createClient(env);
|
||||
const senderSid = await deps.findWhatsappSenderSid(
|
||||
twilioClient,
|
||||
twilioClient as unknown as import("../twilio/types.js").TwilioSenderListClient,
|
||||
env.whatsappFrom,
|
||||
env.whatsappSenderSid,
|
||||
runtime,
|
||||
|
||||
@@ -1,18 +1,27 @@
|
||||
import { execFile, spawn } from "node:child_process";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
import { danger, isVerbose } from "../globals.js";
|
||||
import { logDebug, logError } from "../logger.js";
|
||||
|
||||
const execFileAsync = promisify(execFile);
|
||||
|
||||
// Simple promise-wrapped execFile with optional verbosity logging.
|
||||
export async function runExec(
|
||||
command: string,
|
||||
args: string[],
|
||||
timeoutMs = 10_000,
|
||||
opts: number | { timeoutMs?: number; maxBuffer?: number } = 10_000,
|
||||
): Promise<{ stdout: string; stderr: string }> {
|
||||
const options =
|
||||
typeof opts === "number"
|
||||
? { timeout: opts, encoding: "utf8" as const }
|
||||
: {
|
||||
timeout: opts.timeoutMs,
|
||||
maxBuffer: opts.maxBuffer,
|
||||
encoding: "utf8" as const,
|
||||
};
|
||||
try {
|
||||
const { stdout, stderr } = await execFile(command, args, {
|
||||
timeout: timeoutMs,
|
||||
});
|
||||
const { stdout, stderr } = await execFileAsync(command, args, options);
|
||||
if (isVerbose()) {
|
||||
if (stdout.trim()) logDebug(stdout.trim());
|
||||
if (stderr.trim()) logError(stderr.trim());
|
||||
|
||||
@@ -25,8 +25,9 @@ const WA_WEB_AUTH_DIR = path.join(os.homedir(), ".warelay", "credentials");
|
||||
export async function createWaSocket(printQr: boolean, verbose: boolean) {
|
||||
const logger = pino({ level: verbose ? "info" : "silent" });
|
||||
// Some Baileys internals call logger.trace even when silent; ensure it's present.
|
||||
if (typeof (logger as Record<string, unknown>).trace !== "function") {
|
||||
(logger as unknown as { trace: () => void }).trace = () => {};
|
||||
const loggerAny = logger as unknown as Record<string, unknown>;
|
||||
if (typeof loggerAny.trace !== "function") {
|
||||
loggerAny.trace = () => {};
|
||||
}
|
||||
await ensureDir(WA_WEB_AUTH_DIR);
|
||||
const { state, saveCreds } = await useMultiFileAuthState(WA_WEB_AUTH_DIR);
|
||||
@@ -81,7 +82,7 @@ export async function waitForWaConnection(
|
||||
|
||||
const handler = (...args: unknown[]) => {
|
||||
const update = (args[0] ?? {}) as Partial<
|
||||
import("baileys").ConnectionState
|
||||
import("@whiskeysockets/baileys").ConnectionState
|
||||
>;
|
||||
if (update.connection === "open") {
|
||||
evWithOff.off?.("connection.update", handler);
|
||||
@@ -235,7 +236,7 @@ export async function monitorWebInbox(options: {
|
||||
continue;
|
||||
const from = jidToE164(remoteJid);
|
||||
if (!from) continue;
|
||||
const body = extractText(msg.message);
|
||||
const body = extractText(msg.message ?? undefined);
|
||||
if (!body) continue;
|
||||
const chatJid = remoteJid;
|
||||
const sendComposing = async () => {
|
||||
|
||||
@@ -114,7 +114,7 @@ async function handleMessages(
|
||||
if (!m.from || !m.to) continue;
|
||||
try {
|
||||
await deps.autoReplyIfConfigured(
|
||||
client as unknown as {
|
||||
client as unknown as import("./types.js").TwilioRequester & {
|
||||
messages: { create: (opts: unknown) => Promise<unknown> };
|
||||
},
|
||||
m as unknown as MessageInstance,
|
||||
|
||||
@@ -16,8 +16,8 @@ type TwilioRequester = {
|
||||
|
||||
export async function sendTypingIndicator(
|
||||
client: TwilioRequester,
|
||||
messageSid?: string,
|
||||
runtime: RuntimeEnv,
|
||||
messageSid?: string,
|
||||
) {
|
||||
// Best-effort WhatsApp typing indicator (public beta as of Nov 2025).
|
||||
if (!messageSid) {
|
||||
|
||||
@@ -43,7 +43,7 @@ export async function startWebhook(
|
||||
replyText = await getReplyFromConfig(
|
||||
{ Body, From, To, MessageSid },
|
||||
{
|
||||
onReplyStart: () => sendTypingIndicator(client, MessageSid, runtime),
|
||||
onReplyStart: () => sendTypingIndicator(client, runtime, MessageSid),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user