text
stringlengths
0
1.47k
const meta = visualizeMetaFrom(block.meta) ?? visualizeMetaFromArgs(argsRaw);
if (meta === void 0) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
style: headerStyle,
children: firstResultLine(block.content)
});
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Frame, {
meta,
callId
});
}
//#endregion
//#region src/client/StreamingPreview.tsx
/**
* Live streaming preview docked under the composer: while the model is still
* generating a `visualize` call, the accumulated argument stream
* (`assistant/chunk` tool-call deltas folded into the conversation snapshot's
* `partial`) is parsed for the fragment prefix and rendered into the same
* sandboxed frame the settled card uses — markup and style only, scripts
* neutered until the call settles (a half-streamed script body is almost
* never valid JavaScript). Renders nothing when no `visualize` call is
* streaming; once the call settles the preview unmounts and the transcript
* card takes over.
*/
/**
* Flush interval for posting fragment updates into the persistent shell.
* Updates are incremental DOM syncs, not reloads, so this can run near
* per-delta speed; 150ms keeps the reveal continuous at negligible cost.
*/
const FLUSH_MS = 150;
/**
* Preview height ceiling. The frame tracks the shell's *measured* content
* height (its height reports), so invisible early markup — style blocks,
* empty containers — keeps the frame collapsed and painted components grow
* it; the cap stops a tall fragment from crowding out the composer. Reserving
* space no paint has claimed reads as a layout bug, not as anticipation.
*/
const PREVIEW_MAX_HEIGHT = 300;
/**
* The input dock spans the conversation view, not the composer column, so the
* preview constrains itself to the composer's width family and centers.
*/
const wrapStyle = {
margin: "6px auto 2px",
maxWidth: 760,
width: "100%"
};
const labelStyle = {
fontSize: 12,
opacity: .65,
margin: "0 0 4px"
};
const frameStyle = {
display: "block",
width: "100%",
border: 0,
background: "transparent",
transition: "height 240ms ease"
};
/**
* Throttle a fast-changing string: re-emits at most every {@link FLUSH_MS},
* with a trailing flush so the final value always lands. A plain trailing
* debounce would starve under a continuous token stream — every delta would
* reset the timer — so this flushes on the leading edge when the interval has
* already elapsed.
* @param value - the raw per-render value.
* @returns the throttled value.
*/
function useThrottled(value) {
const [shown, setShown] = (0, react.useState)(value);
const lastFlush = (0, react.useRef)(0);
(0, react.useEffect)(() => {
const elapsed = Date.now() - lastFlush.current;
if (elapsed >= FLUSH_MS) {
lastFlush.current = Date.now();
setShown(value);
return;
}
const timer = setTimeout(() => {
lastFlush.current = Date.now();
setShown(value);
}, FLUSH_MS - elapsed);
return () => clearTimeout(timer);
}, [value]);
return shown;
}
/** The mounted preview, split out so hooks only run while a call streams. */
function Preview({ argsRaw }) {
const fragment = extractStreamingFragment(useThrottled(argsRaw));
const preview = fragment === void 0 ? "" : trimStreamingScripts(fragment);
const hasContent = preview.trim().length > 0;
const frameRef = (0, react.useRef)(null);
const [loaded, setLoaded] = (0, react.useState)(false);
const [contentHeight, setContentHeight] = (0, react.useState)(0);
(0, react.useEffect)(() => {
const onMessage = (event) => {
const report = event.data;
if (report?.type !== "dsh-visualize:height" || report.token !== "streaming-preview") return;
if (typeof report.height !== "number" || !Number.isFinite(report.height)) return;
setContentHeight(Math.max(0, Math.ceil(report.height)));
};