You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.6 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import type { QuoteCaptureSignals } from "@/workers/rpa/quote-capture/types";
const RAW_LOG_LIMIT = 4_000;
/** 契约失败时输出诊断json=0 时始终打 network summary */
export function logQuoteDebugRaw(signals: QuoteCaptureSignals): void {
const trace = signals.networkTrace ?? [];
const reqCount = trace.filter((t) => t.kind === "req").length;
const respCount = trace.filter((t) => t.kind === "resp").length;
console.log(
`[rpa] quote-debug: contract=${signals.contractPayloads.length} json=${signals.jsonPayloads.length} trace req=${reqCount} resp=${respCount} url=${signals.resultUrl}`,
);
const quoteLike = trace.filter(
(t) =>
/quote|rate|graphql|pricing|mothership/i.test(t.url) &&
!/segment|analytics|hotjar|sentry/i.test(t.url),
);
if (quoteLike.length > 0) {
for (const entry of quoteLike.slice(0, 20)) {
console.log(`[rpa] quote-debug trace: ${JSON.stringify(entry)}`);
}
} else if (trace.length > 0) {
console.log(
`[rpa] quote-debug: 无 quote-like 请求;最近 RESP${trace
.filter((t) => t.kind === "resp")
.slice(-8)
.map((t) => t.url)
.join(" | ")}`,
);
}
if (process.env.RPA_QUOTE_DEBUG_RAW !== "true") {
return;
}
for (const payload of signals.jsonPayloads) {
let serialized = "";
try {
serialized = JSON.stringify(payload.body);
} catch {
serialized = String(payload.body);
}
const clipped =
serialized.length > RAW_LOG_LIMIT
? `${serialized.slice(0, RAW_LOG_LIMIT)}`
: serialized;
console.log(`[rpa] quote-debug raw url=${payload.url} body=${clipped}`);
}
}