fix: report endpoint reads report.md from workspace, clean ReportView
This commit is contained in:
parent
dd2c4449fd
commit
dcc6c4d28d
@ -16,6 +16,7 @@ use super::{ApiResult, db_err};
|
||||
|
||||
#[derive(serde::Serialize)]
|
||||
struct ReportResponse {
|
||||
project_id: String,
|
||||
report: String,
|
||||
}
|
||||
|
||||
@ -181,11 +182,25 @@ async fn get_report(
|
||||
.await
|
||||
.map_err(db_err)?;
|
||||
|
||||
match wf {
|
||||
Some(w) if !w.report.is_empty() => Ok(Json(ReportResponse { report: w.report })),
|
||||
Some(_) => Err((StatusCode::NOT_FOUND, "Report not yet generated").into_response()),
|
||||
None => Err((StatusCode::NOT_FOUND, "Workflow not found").into_response()),
|
||||
let wf = match wf {
|
||||
Some(w) => w,
|
||||
None => return Err((StatusCode::NOT_FOUND, "Workflow not found").into_response()),
|
||||
};
|
||||
|
||||
// Read report.md from workspace
|
||||
let workspace_root = if std::path::Path::new("/app/data/workspaces").is_dir() {
|
||||
"/app/data/workspaces"
|
||||
} else {
|
||||
"data/workspaces"
|
||||
};
|
||||
let report_path = format!("{}/{}/report.md", workspace_root, wf.project_id);
|
||||
let report = tokio::fs::read_to_string(&report_path).await.unwrap_or_default();
|
||||
|
||||
if report.is_empty() {
|
||||
return Err((StatusCode::NOT_FOUND, "report.md not found").into_response());
|
||||
}
|
||||
|
||||
Ok(Json(ReportResponse { project_id: wf.project_id, report }))
|
||||
}
|
||||
|
||||
async fn get_plan(
|
||||
|
||||
@ -67,7 +67,7 @@ export const api = {
|
||||
}),
|
||||
|
||||
getReport: (workflowId: string) =>
|
||||
request<{ report: string }>(`/workflows/${workflowId}/report`),
|
||||
request<{ project_id: string; report: string }>(`/workflows/${workflowId}/report`),
|
||||
|
||||
listPlanSteps: (workflowId: string) =>
|
||||
request<PlanStepInfo[]>(`/workflows/${workflowId}/plan`),
|
||||
|
||||
@ -289,7 +289,7 @@ function goHome() {
|
||||
|
||||
<template>
|
||||
<div v-if="isReportPage" class="report-fullpage">
|
||||
<ReportView :workflowId="reportWorkflowId" :projectId="selectedProjectId" :key="reportWorkflowId" />
|
||||
<ReportView :workflowId="reportWorkflowId" :key="reportWorkflowId" />
|
||||
</div>
|
||||
<div v-else class="app-layout">
|
||||
<header class="app-header">
|
||||
|
||||
@ -2,10 +2,10 @@
|
||||
import { ref, onMounted, nextTick } from 'vue'
|
||||
import { marked } from 'marked'
|
||||
import mermaid from 'mermaid'
|
||||
import { api } from '../api'
|
||||
|
||||
const props = defineProps<{
|
||||
workflowId: string
|
||||
projectId: string
|
||||
}>()
|
||||
|
||||
const html = ref('')
|
||||
@ -38,15 +38,10 @@ async function renderMermaid() {
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
const res = await fetch(`/tori/api/projects/${props.projectId}/files/report.md?raw`)
|
||||
if (res.ok) {
|
||||
const md = await res.text()
|
||||
html.value = await marked.parse(md)
|
||||
} else {
|
||||
error.value = '暂无报告。Agent 完成后会生成 report.md。'
|
||||
}
|
||||
} catch (e: any) {
|
||||
error.value = e.message
|
||||
const res = await api.getReport(props.workflowId)
|
||||
html.value = await marked.parse(res.report)
|
||||
} catch {
|
||||
error.value = '暂无报告。Agent 完成后会生成 report.md。'
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
@ -67,171 +62,34 @@ onMounted(async () => {
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.report-page {
|
||||
max-width: 860px;
|
||||
margin: 0 auto;
|
||||
padding: 24px 32px;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.report-toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
margin-bottom: 24px;
|
||||
padding-bottom: 12px;
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.back-link {
|
||||
color: var(--accent);
|
||||
text-decoration: none;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.back-link:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.report-title {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: var(--text-secondary);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.5px;
|
||||
}
|
||||
|
||||
.report-loading,
|
||||
.report-error {
|
||||
text-align: center;
|
||||
padding: 48px;
|
||||
color: var(--text-secondary);
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.report-error {
|
||||
color: var(--error);
|
||||
}
|
||||
.report-page { max-width: 860px; margin: 0 auto; padding: 24px 32px; min-height: 100vh; }
|
||||
.report-toolbar { display: flex; align-items: center; gap: 16px; margin-bottom: 24px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
|
||||
.back-link { color: var(--accent); text-decoration: none; font-size: 14px; font-weight: 500; }
|
||||
.back-link:hover { text-decoration: underline; }
|
||||
.report-title { font-size: 14px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px; }
|
||||
.report-loading, .report-error { text-align: center; padding: 48px; color: var(--text-secondary); font-size: 14px; }
|
||||
.report-error { color: var(--error); }
|
||||
</style>
|
||||
|
||||
<style>
|
||||
/* Unscoped styles for rendered markdown */
|
||||
.report-body {
|
||||
line-height: 1.7;
|
||||
color: var(--text-primary);
|
||||
font-size: 15px;
|
||||
}
|
||||
|
||||
.report-body h1 {
|
||||
font-size: 24px;
|
||||
font-weight: 700;
|
||||
margin: 0 0 16px;
|
||||
padding-bottom: 8px;
|
||||
border-bottom: 2px solid var(--border);
|
||||
}
|
||||
|
||||
.report-body h2 {
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
margin: 24px 0 12px;
|
||||
}
|
||||
|
||||
.report-body h3 {
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
margin: 20px 0 8px;
|
||||
}
|
||||
|
||||
.report-body p {
|
||||
margin: 0 0 12px;
|
||||
}
|
||||
|
||||
.report-body ul,
|
||||
.report-body ol {
|
||||
margin: 0 0 12px;
|
||||
padding-left: 24px;
|
||||
}
|
||||
|
||||
.report-body li {
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.report-body pre {
|
||||
background: var(--bg-secondary);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 6px;
|
||||
padding: 12px 16px;
|
||||
overflow-x: auto;
|
||||
margin: 0 0 12px;
|
||||
font-size: 13px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.report-body code {
|
||||
font-family: 'JetBrains Mono', 'Fira Code', monospace;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.report-body :not(pre) > code {
|
||||
background: var(--bg-secondary);
|
||||
padding: 2px 6px;
|
||||
border-radius: 4px;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.report-body table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
margin: 0 0 12px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.report-body th,
|
||||
.report-body td {
|
||||
border: 1px solid var(--border);
|
||||
padding: 8px 12px;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.report-body th {
|
||||
background: var(--bg-secondary);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.report-body blockquote {
|
||||
border-left: 3px solid var(--accent);
|
||||
padding-left: 16px;
|
||||
margin: 0 0 12px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.report-body a {
|
||||
color: var(--accent);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.report-body a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.report-body .mermaid-chart {
|
||||
margin: 16px 0;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.report-body .mermaid-chart svg {
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.report-body img {
|
||||
max-width: 100%;
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.report-body hr {
|
||||
border: none;
|
||||
border-top: 1px solid var(--border);
|
||||
margin: 20px 0;
|
||||
}
|
||||
.report-body { line-height: 1.7; color: var(--text-primary); font-size: 15px; }
|
||||
.report-body h1 { font-size: 24px; font-weight: 700; margin: 0 0 16px; padding-bottom: 8px; border-bottom: 2px solid var(--border); }
|
||||
.report-body h2 { font-size: 20px; font-weight: 600; margin: 24px 0 12px; }
|
||||
.report-body h3 { font-size: 16px; font-weight: 600; margin: 20px 0 8px; }
|
||||
.report-body p { margin: 0 0 12px; }
|
||||
.report-body ul, .report-body ol { margin: 0 0 12px; padding-left: 24px; }
|
||||
.report-body li { margin-bottom: 4px; }
|
||||
.report-body pre { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: 6px; padding: 12px 16px; overflow-x: auto; margin: 0 0 12px; font-size: 13px; line-height: 1.5; }
|
||||
.report-body code { font-family: 'JetBrains Mono', 'Fira Code', monospace; font-size: 13px; }
|
||||
.report-body :not(pre) > code { background: var(--bg-secondary); padding: 2px 6px; border-radius: 4px; }
|
||||
.report-body table { width: 100%; border-collapse: collapse; margin: 0 0 12px; font-size: 14px; }
|
||||
.report-body th, .report-body td { border: 1px solid var(--border); padding: 8px 12px; text-align: left; }
|
||||
.report-body th { background: var(--bg-secondary); font-weight: 600; }
|
||||
.report-body blockquote { border-left: 3px solid var(--accent); padding-left: 16px; margin: 0 0 12px; color: var(--text-secondary); }
|
||||
.report-body a { color: var(--accent); text-decoration: none; }
|
||||
.report-body a:hover { text-decoration: underline; }
|
||||
.report-body .mermaid-chart { margin: 16px 0; text-align: center; }
|
||||
.report-body .mermaid-chart svg { max-width: 100%; }
|
||||
.report-body img { max-width: 100%; border-radius: 6px; }
|
||||
.report-body hr { border: none; border-top: 1px solid var(--border); margin: 20px 0; }
|
||||
</style>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user