text
stringlengths
0
1.47k
addEventListener("message", onMessage);
return () => removeEventListener("message", onMessage);
}, []);
const doc = (0, react.useMemo)(() => buildStreamShellDoc({
...resolveTheme(),
reportToken: "streaming-preview"
}), []);
(0, react.useEffect)(() => {
if (!loaded || !hasContent) return;
frameRef.current?.contentWindow?.postMessage({
type: STREAM_MESSAGE_TYPE,
token: "streaming-preview",
fragment: preview
}, "*");
}, [
loaded,
hasContent,
preview
]);
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
style: wrapStyle,
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
style: labelStyle,
children: hasContent ? "Visualize · streaming preview" : "Visualize · composing…"
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("iframe", {
ref: frameRef,
sandbox: "allow-scripts",
referrerPolicy: "no-referrer",
title: "Visualization streaming preview",
srcDoc: doc,
style: {
...frameStyle,
height: hasContent ? Math.min(contentHeight, PREVIEW_MAX_HEIGHT) : 0
},
onLoad: () => setLoaded(true)
})]
});
}
/**
* Dock entry: mounts the preview exactly while the streaming partial carries
* a `visualize` tool-call block.
*/
function StreamingPreview({ session }) {
const blocks = session?.partial?.blocks;
if (blocks === void 0) return null;
let argsRaw;
for (const block of blocks) if (block.kind === "tool-call" && block.name === "visualize") argsRaw = block.argsRaw;
if (argsRaw === void 0) return null;
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Preview, { argsRaw });
}
//#endregion
//#region src/client/folding.ts
/** Settings namespace owned by the host Chat target. */
const CHAT_NAMESPACE = "ui-chat";
/**
* Whether a saved mode folds on a 0.1.7+ host. An unset value is the host's
* `standard` default.
* @param view - saved `transcriptView`.
* @returns true unless the reader chose `verbose`.
*/
function configFormsFolds(view) {
return view !== "verbose";
}
/**
* Whether a saved mode folds on a 0.1.2–0.1.6 host. An unset value is the
* host's `compact` default.
* @param view - saved `transcriptView`.
* @returns true for `compact` or unset.
*/
function settingsScopeFolds(view) {
return view === void 0 || view === "compact";
}
/**
* Adapt a settings face into a boolean observable.
* @param face - the host namespace binding.
* @param folds - the generation's mode rule.
* @returns an observable whose snapshot is a primitive, so it is stable.
*/
function observe(face, folds) {
return {
getSnapshot: () => folds(face.getSnapshot().value?.transcriptView),
subscribe: (listener) => {
const dispose = face.subscribe(listener);
return typeof dispose === "function" ? dispose : () => void 0;
}
};
}
/**
* Narrow an unknown value to an object exposing a method.
* @param value - candidate service.
* @param method - required method name.
* @returns the value when it carries the method.
*/
function hasMethod(value, method) {
return typeof value === "object" && value !== null && typeof value[method] === "function";
}
/**
* Resolve the folding observable for this host. Call it once the Chat target
* is up (its turn-tail declaration is the signal), when both settings
* services, where present, are already provided.