function mountPanel() {
if (!panel.isConnected && document.documentElement) {
document.documentElement.appendChild(panel);
}
}
mountPanel();
const esc = value =>
String(value).replace(/[&<>"']/g, c => ({
"&": "&",
"<": "<",
">": ">",
'"': """,
"'": "'"
})[c]);
function display(value) {
return value ? esc(value) : state.finished ? "本次未返回" : "搜索中…";
}
function modelFamily(slug) {
const m = String(slug || "").match(/^gpt-(\d+)-(\d+)/i);
return m ? `gpt-${m[1]}-${m[2]}` : null;
}
function verdict() {
if (!state.active) return "⏳ 等待发送一条新消息";
if (!state.serverModel) return "🔎 检测中,等待服务端模型标注…";
if (!state.requestModel) return "✅ 已取得服务端模型标注";
if (state.requestModel === state.serverModel) {
return "✅ 请求模型与服务端模型标注一致";
}
const reqFamily = modelFamily(state.requestModel);
const srvFamily = modelFamily(state.serverModel);
if (reqFamily && reqFamily === srvFamily) {
return "✅ 同一模型系列(内部 slug 不同)";
}
return "🚨 请求模型与服务端模型标注不一致";
}
function refreshDomModel() {
const els = document.querySelectorAll('[data-message-author-role="assistant"]');
if (!els.length) return;
const value = els[els.length - 1].getAttribute("data-message-model-slug");
if (value) state.domModel = value;
}
if (typeof obj.resolved_model_slug === "string") {
setField("resolvedModel", obj.resolved_model_slug);
}
for (const value of Object.values(obj)) {
scanObject(value, depth + 1, seen);
}
}
function parseData(raw) {
if (!raw) return;
const text = raw.trim();
if (!text || text === "[DONE]") return;
let obj;
try {
obj = JSON.parse(text);
} catch {
return;
}
dirty = false;
sawServerMeta = false;
scanObject(obj);
if (dirty) render();
if (sawServerMeta) scheduleFinish(1500);
}
function scanWholeText(text) {
if (!text) return;
parseData(text); // 整体可能就是一个 JSON
for (let line of text.split(/\r?\n/)) {
line = line.trim();
if (!line) continue;
if (line.startsWith("data:")) line = line.slice(5).trim();
parseData(line);
}
}
let nl;
while ((nl = buffer.indexOf("\n")) !== -1) {
let line = buffer.slice(0, nl);
buffer = buffer.slice(nl + 1);
if (line.endsWith("\r")) line = line.slice(0, -1);
if (line === "") {
flushEvent();
} else if (line.startsWith("data:")) {
eventLines.push(line.slice(5).trimStart());
} else {
const t = line.trim();
if (t.startsWith("{") || t.startsWith("[")) parseData(t);
}
}
}
const rest = buffer.trim();
if (rest.startsWith("data:")) {
eventLines.push(rest.slice(5).trimStart());
} else if (rest) {
parseData(rest);
}
flushEvent();
} catch (err) {
console.debug("[Route Checker] stream reader:", err);
}
scheduleFinish(3000);
}
// ---------------- Request body ----------------
async function bodyText(body) {
try {
if (body == null) return "";
if (typeof body === "string") return body;
if (body instanceof Blob) return await body.text();
if (body instanceof URLSearchParams) return body.toString();
if (body instanceof ArrayBuffer) return new TextDecoder().decode(body);
if (ArrayBuffer.isView(body)) return new TextDecoder().decode(body);
} catch {}
return "";
}
async function getRequestText(input, init) {
if (init?.body != null) return await bodyText(init.body);
if (input instanceof Request) {
try {
return await input.clone().text();
} catch {}
}
return "";
}