chore: migrate to oxlint and oxfmt
Co-authored-by: Christoph Nakazawa <christoph.pojer@gmail.com>
This commit is contained in:
@@ -4,8 +4,7 @@ import { shouldLogSubsystemToConsole } from "../logging.js";
|
||||
import { DEFAULT_WS_SLOW_MS, getGatewayWsLogStyle } from "./ws-logging.js";
|
||||
|
||||
const LOG_VALUE_LIMIT = 240;
|
||||
const UUID_RE =
|
||||
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
||||
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
||||
|
||||
type WsInflightEntry = {
|
||||
ts: number;
|
||||
@@ -32,8 +31,7 @@ export function formatForLog(value: unknown): string {
|
||||
if (value.name) parts.push(value.name);
|
||||
if (value.message) parts.push(value.message);
|
||||
const code =
|
||||
"code" in value &&
|
||||
(typeof value.code === "string" || typeof value.code === "number")
|
||||
"code" in value && (typeof value.code === "string" || typeof value.code === "number")
|
||||
? String(value.code)
|
||||
: "";
|
||||
if (code) parts.push(`code=${code}`);
|
||||
@@ -49,9 +47,7 @@ export function formatForLog(value: unknown): string {
|
||||
if (typeof rec.message === "string" && rec.message.trim()) {
|
||||
const name = typeof rec.name === "string" ? rec.name.trim() : "";
|
||||
const code =
|
||||
typeof rec.code === "string" || typeof rec.code === "number"
|
||||
? String(rec.code)
|
||||
: "";
|
||||
typeof rec.code === "string" || typeof rec.code === "number" ? String(rec.code) : "";
|
||||
const parts = [name, rec.message.trim()].filter(Boolean);
|
||||
if (code) parts.push(`code=${code}`);
|
||||
const combined = parts.join(": ").trim();
|
||||
@@ -65,9 +61,7 @@ export function formatForLog(value: unknown): string {
|
||||
? String(value)
|
||||
: JSON.stringify(value);
|
||||
if (!str) return "";
|
||||
return str.length > LOG_VALUE_LIMIT
|
||||
? `${str.slice(0, LOG_VALUE_LIMIT)}...`
|
||||
: str;
|
||||
return str.length > LOG_VALUE_LIMIT ? `${str.slice(0, LOG_VALUE_LIMIT)}...` : str;
|
||||
} catch {
|
||||
return String(value);
|
||||
}
|
||||
@@ -79,18 +73,14 @@ function compactPreview(input: string, maxLen = 160): string {
|
||||
return `${oneLine.slice(0, Math.max(0, maxLen - 1))}…`;
|
||||
}
|
||||
|
||||
export function summarizeAgentEventForWsLog(
|
||||
payload: unknown,
|
||||
): Record<string, unknown> {
|
||||
export function summarizeAgentEventForWsLog(payload: unknown): Record<string, unknown> {
|
||||
if (!payload || typeof payload !== "object") return {};
|
||||
const rec = payload as Record<string, unknown>;
|
||||
const runId = typeof rec.runId === "string" ? rec.runId : undefined;
|
||||
const stream = typeof rec.stream === "string" ? rec.stream : undefined;
|
||||
const seq = typeof rec.seq === "number" ? rec.seq : undefined;
|
||||
const data =
|
||||
rec.data && typeof rec.data === "object"
|
||||
? (rec.data as Record<string, unknown>)
|
||||
: undefined;
|
||||
rec.data && typeof rec.data === "object" ? (rec.data as Record<string, unknown>) : undefined;
|
||||
|
||||
const extra: Record<string, unknown> = {};
|
||||
if (runId) extra.run = shortId(runId);
|
||||
@@ -102,9 +92,7 @@ export function summarizeAgentEventForWsLog(
|
||||
if (stream === "assistant") {
|
||||
const text = typeof data.text === "string" ? data.text : undefined;
|
||||
if (text?.trim()) extra.text = compactPreview(text);
|
||||
const mediaUrls = Array.isArray(data.mediaUrls)
|
||||
? data.mediaUrls
|
||||
: undefined;
|
||||
const mediaUrls = Array.isArray(data.mediaUrls) ? data.mediaUrls : undefined;
|
||||
if (mediaUrls && mediaUrls.length > 0) extra.media = mediaUrls.length;
|
||||
return extra;
|
||||
}
|
||||
@@ -113,8 +101,7 @@ export function summarizeAgentEventForWsLog(
|
||||
const phase = typeof data.phase === "string" ? data.phase : undefined;
|
||||
const name = typeof data.name === "string" ? data.name : undefined;
|
||||
if (phase || name) extra.tool = `${phase ?? "?"}:${name ?? "?"}`;
|
||||
const toolCallId =
|
||||
typeof data.toolCallId === "string" ? data.toolCallId : undefined;
|
||||
const toolCallId = typeof data.toolCallId === "string" ? data.toolCallId : undefined;
|
||||
if (toolCallId) extra.call = shortId(toolCallId);
|
||||
const meta = typeof data.meta === "string" ? data.meta : undefined;
|
||||
if (meta?.trim()) extra.meta = meta;
|
||||
@@ -136,11 +123,7 @@ export function summarizeAgentEventForWsLog(
|
||||
return extra;
|
||||
}
|
||||
|
||||
export function logWs(
|
||||
direction: "in" | "out",
|
||||
kind: string,
|
||||
meta?: Record<string, unknown>,
|
||||
) {
|
||||
export function logWs(direction: "in" | "out", kind: string, meta?: Record<string, unknown>) {
|
||||
if (!shouldLogSubsystemToConsole("gateway/ws")) return;
|
||||
const style = getGatewayWsLogStyle();
|
||||
if (!isVerbose()) {
|
||||
@@ -192,8 +175,7 @@ export function logWs(
|
||||
: chalk.redBright("✗")
|
||||
: undefined;
|
||||
|
||||
const durationToken =
|
||||
typeof durationMs === "number" ? chalk.dim(`${durationMs}ms`) : undefined;
|
||||
const durationToken = typeof durationMs === "number" ? chalk.dim(`${durationMs}ms`) : undefined;
|
||||
|
||||
const restMeta: string[] = [];
|
||||
if (meta) {
|
||||
@@ -212,23 +194,14 @@ export function logWs(
|
||||
}
|
||||
if (id) trailing.push(`${chalk.dim("id")}=${chalk.gray(shortId(id))}`);
|
||||
|
||||
const tokens = [
|
||||
prefix,
|
||||
statusToken,
|
||||
headline,
|
||||
durationToken,
|
||||
...restMeta,
|
||||
...trailing,
|
||||
].filter((t): t is string => Boolean(t));
|
||||
const tokens = [prefix, statusToken, headline, durationToken, ...restMeta, ...trailing].filter(
|
||||
(t): t is string => Boolean(t),
|
||||
);
|
||||
|
||||
console.log(tokens.join(" "));
|
||||
}
|
||||
|
||||
function logWsOptimized(
|
||||
direction: "in" | "out",
|
||||
kind: string,
|
||||
meta?: Record<string, unknown>,
|
||||
) {
|
||||
function logWsOptimized(direction: "in" | "out", kind: string, meta?: Record<string, unknown>) {
|
||||
const connId = typeof meta?.connId === "string" ? meta.connId : undefined;
|
||||
const id = typeof meta?.id === "string" ? meta.id : undefined;
|
||||
const ok = typeof meta?.ok === "boolean" ? meta.ok : undefined;
|
||||
@@ -243,8 +216,7 @@ function logWsOptimized(
|
||||
}
|
||||
|
||||
if (kind === "parse-error") {
|
||||
const errorMsg =
|
||||
typeof meta?.error === "string" ? formatForLog(meta.error) : undefined;
|
||||
const errorMsg = typeof meta?.error === "string" ? formatForLog(meta.error) : undefined;
|
||||
console.log(
|
||||
[
|
||||
`${chalk.gray("[gws]")} ${chalk.redBright("✗")} ${chalk.bold("parse-error")}`,
|
||||
@@ -259,26 +231,17 @@ function logWsOptimized(
|
||||
|
||||
if (direction !== "out" || kind !== "res") return;
|
||||
|
||||
const startedAt = inflightKey
|
||||
? wsInflightOptimized.get(inflightKey)
|
||||
: undefined;
|
||||
const startedAt = inflightKey ? wsInflightOptimized.get(inflightKey) : undefined;
|
||||
if (inflightKey) wsInflightOptimized.delete(inflightKey);
|
||||
const durationMs =
|
||||
typeof startedAt === "number" ? Date.now() - startedAt : undefined;
|
||||
const durationMs = typeof startedAt === "number" ? Date.now() - startedAt : undefined;
|
||||
|
||||
const shouldLog =
|
||||
ok === false ||
|
||||
(typeof durationMs === "number" && durationMs >= DEFAULT_WS_SLOW_MS);
|
||||
ok === false || (typeof durationMs === "number" && durationMs >= DEFAULT_WS_SLOW_MS);
|
||||
if (!shouldLog) return;
|
||||
|
||||
const statusToken =
|
||||
ok === undefined
|
||||
? undefined
|
||||
: ok
|
||||
? chalk.greenBright("✓")
|
||||
: chalk.redBright("✗");
|
||||
const durationToken =
|
||||
typeof durationMs === "number" ? chalk.dim(`${durationMs}ms`) : undefined;
|
||||
ok === undefined ? undefined : ok ? chalk.greenBright("✓") : chalk.redBright("✗");
|
||||
const durationToken = typeof durationMs === "number" ? chalk.dim(`${durationMs}ms`) : undefined;
|
||||
|
||||
const restMeta: string[] = [];
|
||||
if (meta) {
|
||||
@@ -303,11 +266,7 @@ function logWsOptimized(
|
||||
console.log(tokens.join(" "));
|
||||
}
|
||||
|
||||
function logWsCompact(
|
||||
direction: "in" | "out",
|
||||
kind: string,
|
||||
meta?: Record<string, unknown>,
|
||||
) {
|
||||
function logWsCompact(direction: "in" | "out", kind: string, meta?: Record<string, unknown>) {
|
||||
const now = Date.now();
|
||||
const connId = typeof meta?.connId === "string" ? meta.connId : undefined;
|
||||
const id = typeof meta?.id === "string" ? meta.id : undefined;
|
||||
@@ -348,9 +307,7 @@ function logWsCompact(
|
||||
wsInflightCompact.delete(inflightKey);
|
||||
}
|
||||
const durationToken =
|
||||
typeof startedAt === "number"
|
||||
? chalk.dim(`${now - startedAt}ms`)
|
||||
: undefined;
|
||||
typeof startedAt === "number" ? chalk.dim(`${now - startedAt}ms`) : undefined;
|
||||
|
||||
const headline =
|
||||
(kind === "req" || kind === "res") && method
|
||||
@@ -377,14 +334,9 @@ function logWsCompact(
|
||||
}
|
||||
if (id) trailing.push(`${chalk.dim("id")}=${chalk.gray(shortId(id))}`);
|
||||
|
||||
const tokens = [
|
||||
prefix,
|
||||
statusToken,
|
||||
headline,
|
||||
durationToken,
|
||||
...restMeta,
|
||||
...trailing,
|
||||
].filter((t): t is string => Boolean(t));
|
||||
const tokens = [prefix, statusToken, headline, durationToken, ...restMeta, ...trailing].filter(
|
||||
(t): t is string => Boolean(t),
|
||||
);
|
||||
|
||||
console.log(tokens.join(" "));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user