Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: show the end of long prompts in the API monitor (#14241)

Daniel Han2c7c841f6939
diff --git a/studio/frontend/src/features/api-monitor/api-monitor-page.tsx b/studio/frontend/src/features/api-monitor/api-monitor-page.tsx
index 2aff136c7e0..b44840b5d45 100644
--- a/studio/frontend/src/features/api-monitor/api-monitor-page.tsx
+++ b/studio/frontend/src/features/api-monitor/api-monitor-page.tsx
@@ -50,6 +50,7 @@ import { type ReactElement, useEffect, useMemo, useRef, useState } from "react";
import { ApiModelLoadControls } from "./components/api-model-load-controls";
import { SavedModelSettingsPanel } from "./components/saved-model-settings";
import { isLifecycleEntry, lifecycleLabel } from "./lifecycle";
+import { PAYLOAD_SHOW_ALL_MAX_CHARS, payloadPreview } from "./payload-preview";
import { ToolbarTooltip } from "./components/toolbar-tooltip";
import { unloadResident } from "./unload-resident";
import {
@@ -356,10 +357,13 @@ function PayloadBlock({
loading?: boolean;
tone?: "error";
}): ReactElement {
- const preview =
- body.length > 12_000
- ? `${body.slice(0, 11_997).replace(/[\uD800-\uDBFF]$/, "")}...`
- : body;
+ const [showAll, setShowAll] = useState(false);
+ const preview = payloadPreview(body);
+ const canShowAll =
+ !truncated &&
+ preview !== body &&
+ body.length <= PAYLOAD_SHOW_ALL_MAX_CHARS;
+ const shown = showAll && canShowAll ? body : preview;
return (
<section className="flex min-w-0 flex-col gap-1.5">
<div className="flex items-center justify-between gap-2">
@@ -367,7 +371,18 @@ function PayloadBlock({
{title}
</h3>
<div className="flex items-center gap-1">
- {truncated || preview !== body ? (
+ {canShowAll ? (
+ <Button
+ type="button"
+ variant="ghost"
+ size="xs"
+ aria-pressed={showAll}
+ onClick={() => setShowAll((value) => !value)}
+ className="text-ui-10 text-muted-foreground"
+ >
+ {showAll ? "Show less" : "Show all"}
+ </Button>
+ ) : truncated || preview !== body ? (
<span className="text-ui-10 text-muted-foreground">
preview only
</span>
@@ -385,7 +400,7 @@ function PayloadBlock({
tone === "error" && "bg-red-500/5 text-red-700 dark:text-red-400",
)}
>
- {loading && !body ? "Loading…" : preview || "–"}
+ {loading && !body ? "Loading…" : shown || "–"}
</pre>
</section>
);
@@ -536,12 +551,14 @@ function RequestDetail({
) : null}
<PayloadBlock
+ key={`${entry.id}:prompt`}
title="Prompt"
body={prompt}
truncated={entry.prompt_truncated && detail?.prompt == null}
loading={loading}
/>
<PayloadBlock
+ key={`${entry.id}:reply`}
title="Reply"
body={reply}
truncated={entry.reply_truncated && !detailIsCurrent}
diff --git a/studio/frontend/src/features/api-monitor/payload-preview.ts b/studio/frontend/src/features/api-monitor/payload-preview.ts
new file mode 100644
index 00000000000..fef97e73268
--- /dev/null
+++ b/studio/frontend/src/features/api-monitor/payload-preview.ts
@@ -0,0 +1,33 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+// Split out of api-monitor-page.tsx so it runs under `node --test`.
+
+export const PAYLOAD_PREVIEW_CHARS = 12_000;
+// Above this a full render stalls the page; Copy still has the whole body.
+export const PAYLOAD_SHOW_ALL_MAX_CHARS = 1_000_000;
+
+const ENDS_IN_HIGH_SURROGATE = /[\uD800-\uDBFF]$/;
+const STARTS_WITH_LOW_SURROGATE = /^[\uDC00-\uDFFF]/;
+
+// Head and tail, as SGLang's request log cuts: agent prompts put the long system prompt
+// first and the turn being answered last, so a head-only cut showed only instructions.
+export function payloadPreview(
+ body: string,
+ limit: number = PAYLOAD_PREVIEW_CHARS,
+): string {
+ if (body.length <= limit) {
+ return body;
+ }
+ const half = Math.floor(limit / 2);
+ let head = body.slice(0, half);
+ let tail = body.slice(body.length - half);
+ if (ENDS_IN_HIGH_SURROGATE.test(head)) {
+ head = head.slice(0, -1);
+ }
+ if (STARTS_WITH_LOW_SURROGATE.test(tail)) {
+ tail = tail.slice(1);
+ }
+ const omitted = body.length - head.length - tail.length;
+ return `${head}\n\n[... ${omitted.toLocaleString("en-US")} characters omitted ...]\n\n${tail}`;
+}
diff --git a/studio/frontend/tests/api-monitor-payload-preview.test.ts b/studio/frontend/tests/api-monitor-payload-preview.test.ts
new file mode 100644
index 00000000000..2249d12d130
--- /dev/null
+++ b/studio/frontend/tests/api-monitor-payload-preview.test.ts
@@ -0,0 +1,50 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+import assert from "node:assert/strict";
+import test from "node:test";
+
+import {
+ PAYLOAD_PREVIEW_CHARS,
+ payloadPreview,
+} from "../src/features/api-monitor/payload-preview.ts";
+
+const LONE_HIGH = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])/;
+const LONE_LOW = /(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/;
+
+test("short payloads are shown whole", () => {
+ for (const body of ["", "hi", "x".repeat(PAYLOAD_PREVIEW_CHARS)]) {
+ assert.equal(payloadPreview(body), body);
+ }
+});
+
+test("an agent prompt keeps the system head and the latest user turn", () => {
+ const system = `system: ${"You are a coding agent. ".repeat(2_000)}`;
+ const body = `${system}\n\nuser: fix the failing test in parser.py`;
+ const preview = payloadPreview(body);
+
+ assert.ok(preview.startsWith("system: You are a coding agent."));
+ assert.ok(preview.endsWith("user: fix the failing test in parser.py"));
+ const omitted = body.length - PAYLOAD_PREVIEW_CHARS;
+ assert.ok(
+ preview.includes(
+ `[... ${omitted.toLocaleString("en-US")} characters omitted ...]`,
+ ),
+ );
+ assert.ok(preview.length < PAYLOAD_PREVIEW_CHARS + 64);
+});
+
+test("neither cut splits a surrogate pair", () => {
+ // "a" lands the head cut inside a pair, "b" the tail cut.
+ for (const [prefix, suffix] of [
+ ["", ""],
+ ["a", ""],
+ ["", "b"],
+ ]) {
+ const body = prefix + "\u{1F9A5}".repeat(20_000) + suffix;
+ const preview = payloadPreview(body);
+ const label = JSON.stringify([prefix, suffix]);
+ assert.ok(!LONE_HIGH.test(preview), label);
+ assert.ok(!LONE_LOW.test(preview), label);
+ }
+});