Files
writing-agent/tools/st-request-diff/inspect-capture.mjs
T

21 lines
1.3 KiB
JavaScript

// 看一份抓包的逐条消息:role、额外字段(name 等)、字数、头尾片段。
// 用法: node inspect-capture.mjs captures/st-001-xxx.json [--full 序号]
import { readFileSync } from "node:fs";
const file = process.argv[2];
const fullIdx = process.argv.indexOf("--full");
const full = fullIdx > 0 ? Number(process.argv[fullIdx + 1]) : -1;
const outer = JSON.parse(readFileSync(file, "utf8"));
const body = JSON.parse(outer.body);
console.log("url: " + outer.url + ", 顶层字段: " + Object.keys(body).join(", ")); if (body.tools) { console.log("tool_choice: " + JSON.stringify(body.tool_choice)); console.log("tools(" + body.tools.length + "): " + JSON.stringify(body.tools).slice(0, 1200)); }
(body.messages || []).forEach((m, i) => {
const text = typeof m.content === "string" ? m.content : JSON.stringify(m.content);
const extras = Object.keys(m).filter((k) => k !== "role" && k !== "content");
const head = text.replace(/\s+/g, " ").slice(0, 70);
const tail = text.replace(/\s+/g, " ").slice(-50);
console.log("#" + i + " [" + m.role + "] " + text.length + " 字 extra=" + JSON.stringify(extras) + (extras.length ? " name=" + JSON.stringify(m.name) : ""));
console.log(" 头: " + head);
console.log(" 尾: " + tail);
if (i === full) console.log("----全文----\n" + text);
});