mirror of
https://github.com/RuoJi6/ARTEX.git
synced 2026-12-02 20:01:51 +08:00
feat: improve finding reports and evidence exports
This commit is contained in:
1 parent
fb672389b0
commit
b0a29236f8
14 files changed
+485
-45
No files matched your search
@@ -208,7 +208,9 @@ export function FindingReproductionPanel({ finding, contextTask }: { finding: Fi
|
||||
[finding.evidence, finding.report, finding.summary],
|
||||
);
|
||||
const [traffic, setTraffic] = React.useState<FindingTrafficBinding[] | undefined>(undefined);
|
||||
const overview = reportSection(finding.report ?? "", ["概述", "影响与危害", "受影响范围"]);
|
||||
const overviewSections = ["概述", "影响与危害", "受影响范围"]
|
||||
.map((heading) => ({ heading, content: reportSection(finding.report ?? "", [heading]) }))
|
||||
.filter((item) => item.content);
|
||||
const outcome = reportSection(finding.report ?? "", ["最终结果"]);
|
||||
const rootCause = reportSection(finding.report ?? "", ["根因分析"]);
|
||||
const remediation = reportSection(finding.report ?? "", ["修复建议"]);
|
||||
@@ -242,11 +244,11 @@ export function FindingReproductionPanel({ finding, contextTask }: { finding: Fi
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-3">
|
||||
{overview ? (
|
||||
<div className="rounded-lg bg-muted/30 px-3 py-2.5 text-sm">
|
||||
<Markdown text={overview} />
|
||||
{overviewSections.map((section) => (
|
||||
<div key={section.heading} className="rounded-lg bg-muted/30 px-3 py-2.5 text-sm">
|
||||
<Markdown text={`## ${section.heading}\n\n${section.content}`} />
|
||||
</div>
|
||||
) : null}
|
||||
))}
|
||||
{steps.map((step, index) => {
|
||||
const binding = traffic?.find((item) => item.position === index) ?? traffic?.[index];
|
||||
return (
|
||||
|
||||
@@ -1,9 +1,70 @@
|
||||
"use client";
|
||||
|
||||
import * as React from "react";
|
||||
import ReactMarkdown, { type Components } from "react-markdown";
|
||||
import ReactMarkdown, { defaultUrlTransform, type Components } from "react-markdown";
|
||||
import remarkGfm from "remark-gfm";
|
||||
|
||||
import { auth } from "@/lib/auth";
|
||||
|
||||
function AuthenticatedImage({
|
||||
src,
|
||||
alt,
|
||||
...props
|
||||
}: React.ImgHTMLAttributes<HTMLImageElement>) {
|
||||
const [objectURL, setObjectURL] = React.useState<string | null>(null);
|
||||
const [captureTimestamp, setCaptureTimestamp] = React.useState<string | null>(null);
|
||||
const imageSrc = typeof src === "string" ? src : undefined;
|
||||
|
||||
React.useEffect(() => {
|
||||
let cancelled = false;
|
||||
let url: string | null = null;
|
||||
|
||||
if (!imageSrc || !imageSrc.startsWith("/api/workspace/preview")) {
|
||||
setObjectURL(null);
|
||||
setCaptureTimestamp(null);
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}
|
||||
|
||||
const token = auth.getToken();
|
||||
setCaptureTimestamp(null);
|
||||
fetch(imageSrc, {
|
||||
credentials: "same-origin",
|
||||
headers: token ? { Authorization: `Bearer ${token}` } : undefined,
|
||||
})
|
||||
.then((response) => {
|
||||
if (!response.ok) throw new Error(`图片读取失败: ${response.status}`);
|
||||
setCaptureTimestamp(response.headers.get("X-Report-Screenshot-Timestamp"));
|
||||
return response.blob();
|
||||
})
|
||||
.then((blob) => {
|
||||
if (cancelled) return;
|
||||
url = URL.createObjectURL(blob);
|
||||
setObjectURL(url);
|
||||
})
|
||||
.catch(() => {
|
||||
if (!cancelled) setObjectURL(null);
|
||||
});
|
||||
|
||||
return () => {
|
||||
cancelled = true;
|
||||
if (url) URL.revokeObjectURL(url);
|
||||
};
|
||||
}, [imageSrc]);
|
||||
|
||||
return (
|
||||
<span className="relative my-2 inline-block max-w-full">
|
||||
<img {...props} src={objectURL ?? imageSrc} alt={alt || "报告截图"} />
|
||||
{captureTimestamp && (
|
||||
<span className="pointer-events-none absolute right-2 top-2 rounded bg-black/70 px-2 py-1 font-mono text-[11px] text-white shadow">
|
||||
{captureTimestamp}
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
// Tailwind-styled element overrides (no typography plugin in this project, so we
|
||||
// style each element). `node` is stripped — it's not a valid DOM attribute.
|
||||
const components: Components = {
|
||||
@@ -22,14 +83,20 @@ const components: Components = {
|
||||
const resolvedSrc =
|
||||
typeof src === "string" && src.startsWith("workspace://")
|
||||
? `/api/workspace/preview?path=${encodeURIComponent(src.slice("workspace://".length))}`
|
||||
: typeof src === "string" && src.startsWith("findings/screenshots/")
|
||||
? `/api/workspace/preview?path=${encodeURIComponent(src)}`
|
||||
: src;
|
||||
return (
|
||||
<img
|
||||
<AuthenticatedImage
|
||||
{...p}
|
||||
className="my-2 max-h-[520px] max-w-full rounded-md border object-contain"
|
||||
src={resolvedSrc}
|
||||
alt={alt || "报告截图"}
|
||||
loading="lazy"
|
||||
{...p}
|
||||
// Report screenshots are evidence and must be fetched while the report is
|
||||
// rendered; Edge may replace lazy images with placeholders indefinitely
|
||||
// when the markdown section is outside the initial viewport.
|
||||
loading="eager"
|
||||
decoding="async"
|
||||
/>
|
||||
);
|
||||
},
|
||||
@@ -64,7 +131,13 @@ const components: Components = {
|
||||
export function Markdown({ text }: { text: string }) {
|
||||
return (
|
||||
<div className="min-w-0 space-y-1.5 text-sm [&>*:first-child]:mt-0">
|
||||
<ReactMarkdown remarkPlugins={[remarkGfm]} components={components}>
|
||||
<ReactMarkdown
|
||||
remarkPlugins={[remarkGfm]}
|
||||
components={components}
|
||||
urlTransform={(url) =>
|
||||
url.startsWith("workspace://") || url.startsWith("findings/screenshots/") ? url : defaultUrlTransform(url)
|
||||
}
|
||||
>
|
||||
{text}
|
||||
</ReactMarkdown>
|
||||
</div>
|
||||
|
||||
@@ -248,6 +248,7 @@ export function SideQuestionWorkspace({
|
||||
side,
|
||||
label,
|
||||
children,
|
||||
mode = "split",
|
||||
composerLayout = "stacked",
|
||||
suggestions,
|
||||
placeholder,
|
||||
@@ -257,6 +258,7 @@ export function SideQuestionWorkspace({
|
||||
side: SideQuestions;
|
||||
label: string;
|
||||
children: ReactNode;
|
||||
mode?: "split" | "floating";
|
||||
composerLayout?: ComposerLayout;
|
||||
suggestions?: string[];
|
||||
placeholder?: string;
|
||||
@@ -265,9 +267,25 @@ export function SideQuestionWorkspace({
|
||||
}) {
|
||||
const mobile = useIsMobile();
|
||||
const desktopSideOpen = side.open && side.enabled && !mobile;
|
||||
const floatingSideOpen = desktopSideOpen && mode === "floating";
|
||||
return (
|
||||
<>
|
||||
{desktopSideOpen ? (
|
||||
{floatingSideOpen ? (
|
||||
<>
|
||||
<div className={cn("min-h-0 min-w-0 flex-1", className, mainClassName)}>{children}</div>
|
||||
<div className="pointer-events-none fixed inset-x-0 top-20 z-40 flex justify-end px-4 pb-4 sm:px-6">
|
||||
<div className="pointer-events-auto h-[calc(100svh-6rem)] w-[min(420px,calc(100vw-2rem))] overflow-hidden rounded-xl border bg-background shadow-2xl">
|
||||
<SidePanel
|
||||
side={side}
|
||||
label={label}
|
||||
composerLayout={composerLayout}
|
||||
suggestions={suggestions}
|
||||
placeholder={placeholder}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
) : desktopSideOpen ? (
|
||||
<ResizablePanelGroup orientation="horizontal" className={cn("min-h-0 min-w-0 flex-1", className)}>
|
||||
<ResizablePanel
|
||||
id="main-conversation"
|
||||
|
||||
Reference in new issue
Block a user