Merge upstream v0.4.0 into Gitea fork
This commit is contained in:
@@ -17,7 +17,7 @@ import { BrailleSpinner } from "@/components/braille-spinner";
|
||||
*
|
||||
* job unknown → "dispatched" pulse (the jobs feed hasn't seen it yet)
|
||||
* running → live activity card (activity line + elapsed)
|
||||
* done/error → quiet one-liner ("delivered" / "failed") — the artifact
|
||||
* done/error → quiet one-liner ("finished" / "failed") — the artifact
|
||||
* itself arrives in the steer message right below, so the
|
||||
* box must not duplicate it.
|
||||
*/
|
||||
@@ -57,7 +57,7 @@ export function DispatchCard({ toolCallId, kind }: { toolCallId: string; kind: J
|
||||
>
|
||||
{failed ? <XIcon className="size-3.5 text-red-500" /> : <CheckIcon className="size-3.5" />}
|
||||
<span className="font-medium uppercase tracking-wide">{t(label)}</span>
|
||||
<span>{failed ? t("failed") : t("delivered")}</span>
|
||||
<span>{failed ? t("failed") : t("finished")}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/** Two display-only repairs for inputs the old HTML embedding accepted.
|
||||
* Do not rewrite stored artifacts/downloads or attempt general XML repair.
|
||||
* Comments, CDATA and processing instructions are copied verbatim. */
|
||||
export function svgImageSource(svg: string): string {
|
||||
let foundRoot = false;
|
||||
return svg.replace(
|
||||
/<!--[\s\S]*?(?:-->|$)|<!\[CDATA\[[\s\S]*?(?:\]\]>|$)|<\?[\s\S]*?(?:\?>|$)|<\/?[a-zA-Z](?:[^<>"']|"[^"]*"|'[^']*')*>| /g,
|
||||
(token) => {
|
||||
if (token.startsWith("<!--") || token.startsWith("<![CDATA[") || token.startsWith("<?")) return token;
|
||||
if (!foundRoot && /^<svg(?=[\s/>])/i.test(token)) {
|
||||
foundRoot = true;
|
||||
// Consume complete attribute values, so text mentioning xmlns
|
||||
// inside a different attribute cannot masquerade as a declaration.
|
||||
const attrs = token.matchAll(/\s([^\s=/>]+)(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+))?/g);
|
||||
const hasNamespace = Array.from(attrs).some((attr) => attr[1] === "xmlns");
|
||||
if (!hasNamespace) token = token.replace(/^<svg/i, '$& xmlns="http://www.w3.org/2000/svg"');
|
||||
}
|
||||
return token.replace(/ /g, " ");
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/** Keep generated SVG in an image document, outside the app's CSS and ID scope.
|
||||
* This is a display boundary, not a sanitizer for the original SVG download. */
|
||||
export function SvgImage({
|
||||
svg,
|
||||
className,
|
||||
width,
|
||||
}: {
|
||||
svg: string;
|
||||
className?: string;
|
||||
width?: number;
|
||||
}) {
|
||||
// The source is already an in-memory vector image; no Next image optimization.
|
||||
// eslint-disable-next-line @next/next/no-img-element
|
||||
return <img src={`data:image/svg+xml;charset=utf-8,${encodeURIComponent(svgImageSource(svg))}`} alt="Figure" className={className} width={width} draggable={false} />;
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import { Toggle } from "@/components/settings/controls";
|
||||
import { useSessionMermaid } from "@/components/session-overlay";
|
||||
import { downloadFile } from "@/components/artifacts/download";
|
||||
import { DispatchCard } from "@/components/artifacts/dispatch-card";
|
||||
import { SvgImage } from "@/components/artifacts/svg-image";
|
||||
import type { ArtifactPartProps, VisualResult } from "@/src/core";
|
||||
|
||||
/**
|
||||
@@ -18,22 +19,10 @@ import type { ArtifactPartProps, VisualResult } from "@/src/core";
|
||||
* the chat view's jobs feed). The SVG itself renders from the steer message
|
||||
* (sub-agent result delivery) via VisualOutputCard.
|
||||
*
|
||||
* The SVG is model-authored for the learner's own machine (their own teacher
|
||||
* wrote it, verified by looking) — dangerouslySetInnerHTML is acceptable
|
||||
* here, with a cheap hygiene pass (sanitizeSvg: strip <script> blocks, on*
|
||||
* handlers, and javascript:/data:text/html URLs) since it lands in the
|
||||
* app's DOM.
|
||||
* Both display modes use an SVG image document: generated markup and its
|
||||
* styles never join the app's DOM. Downloads still contain the original SVG.
|
||||
*/
|
||||
|
||||
/** Cheap SVG hygiene — not a full sanitizer, just removing the obvious exec vectors. */
|
||||
export function sanitizeSvg(svg: string): string {
|
||||
return svg
|
||||
.replace(/<script[\s\S]*?<\/script\s*>/gi, "")
|
||||
.replace(/<script[^>]*\/?>/gi, "")
|
||||
.replace(/\son[a-z]+\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+)/gi, "")
|
||||
.replace(/(href|xlink:href)\s*=\s*(?:"\s*(?:javascript|data:text\/html)[^"]*"|'\s*(?:javascript|data:text\/html)[^']*'|(?:javascript|data:text\/html)[^\s>]*)/gi, "");
|
||||
}
|
||||
|
||||
/** The svg root's DECLARED width in px, when there is one — the natural
|
||||
* size the card displays at instead of stretching to full width (owner,
|
||||
* 2026-10-07). %, em, "auto", or a missing attribute → null (the caller
|
||||
@@ -123,13 +112,18 @@ export function VisualOutputCard({
|
||||
<div
|
||||
className={
|
||||
natural !== null
|
||||
? "w-fit max-w-full overflow-hidden rounded-lg bg-white [&_svg]:h-auto [&_svg]:max-w-full"
|
||||
: "w-full overflow-hidden rounded-lg bg-white [&_svg]:h-auto [&_svg]:w-full"
|
||||
? "w-fit max-w-full overflow-hidden rounded-lg bg-white"
|
||||
: "w-full overflow-hidden rounded-lg bg-white"
|
||||
}
|
||||
style={{ filter: inverted ? "invert(1) hue-rotate(180deg)" : undefined }}
|
||||
dangerouslySetInnerHTML={{ __html: sanitizeSvg(result.svg) }}
|
||||
data-testid="visual-svg"
|
||||
/>
|
||||
>
|
||||
<SvgImage
|
||||
svg={result.svg}
|
||||
width={natural ?? undefined}
|
||||
className={natural !== null ? "block h-auto max-w-full" : "block h-auto w-full"}
|
||||
/>
|
||||
</div>
|
||||
<div className="mt-2 flex items-center justify-between gap-2">
|
||||
<div className="text-xs font-medium uppercase tracking-wide text-muted-foreground">{t("Figure")}</div>
|
||||
<div className="flex items-center gap-1.5">
|
||||
|
||||
Reference in New Issue
Block a user