chore: biome format

This commit is contained in:
Peter Steinberger
2025-12-20 18:38:56 +01:00
parent cdb2a0736a
commit 5687a03f0b
4 changed files with 42 additions and 30 deletions

View File

@@ -1,6 +1,6 @@
import type { AgentTool, AgentToolResult } from "@mariozechner/pi-ai"; import type { AgentTool, AgentToolResult } from "@mariozechner/pi-ai";
import { bashTool, codingTools, readTool } from "@mariozechner/pi-coding-agent"; import { bashTool, codingTools, readTool } from "@mariozechner/pi-coding-agent";
import { Type, type TSchema } from "@sinclair/typebox"; import { type TSchema, Type } from "@sinclair/typebox";
import { getImageMetadata, resizeToJpeg } from "../media/image-ops.js"; import { getImageMetadata, resizeToJpeg } from "../media/image-ops.js";
import { detectMime } from "../media/mime.js"; import { detectMime } from "../media/mime.js";

View File

@@ -234,21 +234,21 @@ export async function monitorWebInbox(options: {
conversationId: from, conversationId: from,
to: selfE164 ?? "me", to: selfE164 ?? "me",
body, body,
pushName: senderName, pushName: senderName,
timestamp, timestamp,
chatType: group ? "group" : "direct", chatType: group ? "group" : "direct",
chatId: remoteJid, chatId: remoteJid,
senderJid: participantJid, senderJid: participantJid,
senderE164: senderE164 ?? undefined, senderE164: senderE164 ?? undefined,
senderName, senderName,
groupSubject, groupSubject,
groupParticipants, groupParticipants,
mentionedJids: mentionedJids ?? undefined, mentionedJids: mentionedJids ?? undefined,
selfJid, selfJid,
selfE164, selfE164,
sendComposing, sendComposing,
reply, reply,
sendMedia, sendMedia,
mediaPath, mediaPath,
mediaType, mediaType,
}), }),

View File

@@ -3,6 +3,7 @@ import { randomUUID } from "node:crypto";
import { danger, info, success } from "../globals.js"; import { danger, info, success } from "../globals.js";
import { logInfo } from "../logger.js"; import { logInfo } from "../logger.js";
import { defaultRuntime, type RuntimeEnv } from "../runtime.js"; import { defaultRuntime, type RuntimeEnv } from "../runtime.js";
import { renderQrPngBase64 } from "./qr-image.js";
import { import {
createWaSocket, createWaSocket,
formatError, formatError,
@@ -10,7 +11,6 @@ import {
waitForWaConnection, waitForWaConnection,
webAuthExists, webAuthExists,
} from "./session.js"; } from "./session.js";
import { renderQrPngBase64 } from "./qr-image.js";
type WaSocket = Awaited<ReturnType<typeof createWaSocket>>; type WaSocket = Awaited<ReturnType<typeof createWaSocket>>;
@@ -84,9 +84,12 @@ export async function startWebLoginWithQr(
rejectQr = reject; rejectQr = reject;
}); });
const qrTimer = setTimeout(() => { const qrTimer = setTimeout(
rejectQr?.(new Error("Timed out waiting for WhatsApp QR")); () => {
}, Math.max(opts.timeoutMs ?? 30_000, 5000)); rejectQr?.(new Error("Timed out waiting for WhatsApp QR"));
},
Math.max(opts.timeoutMs ?? 30_000, 5000),
);
let sock: WaSocket; let sock: WaSocket;
try { try {
@@ -151,7 +154,10 @@ export async function waitForWebLogin(
): Promise<{ connected: boolean; message: string }> { ): Promise<{ connected: boolean; message: string }> {
const runtime = opts.runtime ?? defaultRuntime; const runtime = opts.runtime ?? defaultRuntime;
if (!activeLogin) { if (!activeLogin) {
return { connected: false, message: "No active WhatsApp login in progress." }; return {
connected: false,
message: "No active WhatsApp login in progress.",
};
} }
const login = activeLogin; const login = activeLogin;
@@ -166,12 +172,16 @@ export async function waitForWebLogin(
const timeout = new Promise<"timeout">((resolve) => const timeout = new Promise<"timeout">((resolve) =>
setTimeout(() => resolve("timeout"), timeoutMs), setTimeout(() => resolve("timeout"), timeoutMs),
); );
const result = await Promise.race([login.waitPromise.then(() => "done"), timeout]); const result = await Promise.race([
login.waitPromise.then(() => "done"),
timeout,
]);
if (result === "timeout") { if (result === "timeout") {
return { return {
connected: false, connected: false,
message: "Still waiting for the QR scan. Let me know when youve scanned it.", message:
"Still waiting for the QR scan. Let me know when youve scanned it.",
}; };
} }

View File

@@ -12,12 +12,12 @@ type QRCodeConstructor = new (
}; };
const require = createRequire(import.meta.url); const require = createRequire(import.meta.url);
const QRCode = require( const QRCode = require("qrcode-terminal/vendor/QRCode") as QRCodeConstructor;
"qrcode-terminal/vendor/QRCode", const QRErrorCorrectLevel =
) as QRCodeConstructor; require("qrcode-terminal/vendor/QRCode/QRErrorCorrectLevel") as Record<
const QRErrorCorrectLevel = require( string,
"qrcode-terminal/vendor/QRCode/QRErrorCorrectLevel", unknown
) as Record<string, unknown>; >;
function createQrMatrix(input: string) { function createQrMatrix(input: string) {
const qr = new QRCode(-1, QRErrorCorrectLevel.L); const qr = new QRCode(-1, QRErrorCorrectLevel.L);
@@ -85,7 +85,9 @@ function encodePngRgba(buffer: Buffer, width: number, height: number) {
} }
const compressed = deflateSync(raw); const compressed = deflateSync(raw);
const signature = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]); const signature = Buffer.from([
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a,
]);
const ihdr = Buffer.alloc(13); const ihdr = Buffer.alloc(13);
ihdr.writeUInt32BE(width, 0); ihdr.writeUInt32BE(width, 0);
ihdr.writeUInt32BE(height, 4); ihdr.writeUInt32BE(height, 4);