feat: add thread status documents and safe thread reply handling

This commit is contained in:
kris
2026-04-04 11:50:46 +08:00
parent 010d8eda2d
commit 4d9b8e2976
10 changed files with 487 additions and 57 deletions

View File

@@ -1,6 +1,7 @@
import { NextRequest, NextResponse } from "next/server";
import { requireRequestSession } from "@/lib/boss-auth";
import { readState } from "@/lib/boss-data";
import { getProjectDetailView } from "@/lib/boss-projections";
export async function GET(
request: NextRequest,
@@ -13,8 +14,8 @@ export async function GET(
const { projectId } = await context.params;
const state = await readState();
const project = state.projects.find((item) => item.id === projectId);
if (!project) {
const detail = getProjectDetailView(state, projectId, session.account);
if (!detail) {
return NextResponse.json({ ok: false, message: "PROJECT_NOT_FOUND" }, { status: 404 });
}

View File

@@ -0,0 +1,161 @@
import { notFound } from "next/navigation";
import { AppShell, PageNav, StatusBar } from "@/components/app-ui";
import { requirePageSession } from "@/lib/boss-auth";
import { readState } from "@/lib/boss-data";
import { getProjectDetailView } from "@/lib/boss-projections";
import { formatTimestampLabel } from "@/lib/boss-projections";
export const dynamic = "force-dynamic";
function renderMetadataLine(parts: Array<string | undefined>) {
return parts.filter((part) => part && part.trim()).join(" · ");
}
function renderFallback(value: string | undefined, fallback: string) {
return value && value.trim() ? value : fallback;
}
export default async function ThreadStatusPage({
params,
}: {
params: Promise<{ projectId: string }>;
}) {
const session = await requirePageSession();
const { projectId } = await params;
const state = await readState();
const detail = getProjectDetailView(state, projectId, session.account);
if (!detail) notFound();
const threadStatusDocument =
state.threadStatusDocuments.find((item) => item.projectId === projectId) ?? null;
const recentProgressEvents = state.threadProgressEvents
.filter((item) => item.projectId === projectId)
.sort((a, b) => b.createdAt.localeCompare(a.createdAt))
.slice(0, 5);
const subtitle = threadStatusDocument?.folderName?.trim()
? `${threadStatusDocument.folderName} · 只读`
: "只读状态文档";
return (
<AppShell bottomNav={false}>
<StatusBar />
<PageNav title="线程状态" backHref={`/conversations/${projectId}`} />
<div className="space-y-3 px-[18px] pb-6">
<div className="rounded-2xl border border-[#E5E5EA] bg-white px-4 py-4">
<div className="text-[18px] font-semibold text-[#111111]">{detail.project.name}</div>
<div className="mt-1 text-[13px] text-[#8C8C8C]">{subtitle}</div>
<div className="mt-3 text-[12px] leading-6 text-[#57606A]">
{threadStatusDocument
? renderMetadataLine([
threadStatusDocument.threadId,
threadStatusDocument.deviceId,
`更新于 ${formatTimestampLabel(threadStatusDocument.updatedAt)}`,
])
: "当前还没有线程状态文档。"}
</div>
</div>
{threadStatusDocument ? (
<>
<div className="rounded-2xl border border-[#E5E5EA] bg-white px-4 py-4">
<div className="text-[14px] font-semibold text-[#111111]"></div>
<div className="mt-2 whitespace-pre-wrap text-[13px] leading-6 text-[#57606A]">
{renderFallback(threadStatusDocument.projectGoal, "暂无目标")}
</div>
</div>
<div className="rounded-2xl border border-[#E5E5EA] bg-white px-4 py-4">
<div className="text-[14px] font-semibold text-[#111111]"></div>
<div className="mt-2 whitespace-pre-wrap text-[13px] leading-6 text-[#57606A]">
{renderFallback(threadStatusDocument.currentPhase, "暂无阶段")}
</div>
</div>
<div className="rounded-2xl border border-[#E5E5EA] bg-white px-4 py-4">
<div className="text-[14px] font-semibold text-[#111111]"></div>
<div className="mt-2 whitespace-pre-wrap text-[13px] leading-6 text-[#57606A]">
{renderFallback(threadStatusDocument.currentProgress, "暂无进度")}
</div>
</div>
<div className="rounded-2xl border border-[#E5E5EA] bg-white px-4 py-4">
<div className="text-[14px] font-semibold text-[#111111]"></div>
<div className="mt-2 whitespace-pre-wrap text-[13px] leading-6 text-[#57606A]">
{renderFallback(threadStatusDocument.technicalArchitecture, "暂无架构")}
</div>
</div>
<div className="rounded-2xl border border-[#E5E5EA] bg-white px-4 py-4">
<div className="text-[14px] font-semibold text-[#111111]"></div>
<div className="mt-2 whitespace-pre-wrap text-[13px] leading-6 text-[#57606A]">
{renderFallback(threadStatusDocument.currentBlockers, "暂无阻塞")}
</div>
</div>
<div className="rounded-2xl border border-[#E5E5EA] bg-white px-4 py-4">
<div className="text-[14px] font-semibold text-[#111111]"></div>
<div className="mt-2 whitespace-pre-wrap text-[13px] leading-6 text-[#57606A]">
{renderFallback(threadStatusDocument.recommendedNextStep, "暂无建议")}
</div>
</div>
<div className="rounded-2xl border border-[#E5E5EA] bg-white px-4 py-4">
<div className="text-[14px] font-semibold text-[#111111]"></div>
<div className="mt-2 whitespace-pre-wrap text-[13px] leading-6 text-[#57606A]">
{threadStatusDocument.keyFiles.length
? threadStatusDocument.keyFiles.join("\n")
: "暂无关键文件"}
</div>
</div>
<div className="rounded-2xl border border-[#E5E5EA] bg-white px-4 py-4">
<div className="text-[14px] font-semibold text-[#111111]"></div>
<div className="mt-2 whitespace-pre-wrap text-[13px] leading-6 text-[#57606A]">
{threadStatusDocument.keyCommands.length
? threadStatusDocument.keyCommands.join("\n")
: "暂无关键命令"}
</div>
</div>
</>
) : (
<div className="rounded-2xl border border-dashed border-[#D9D9D9] bg-white px-4 py-5 text-[13px] leading-6 text-[#57606A]">
线 Agent 线
</div>
)}
<div className="rounded-2xl border border-[#E5E5EA] bg-white px-4 py-4">
<div className="flex items-center justify-between gap-3">
<div className="text-[14px] font-semibold text-[#111111]"></div>
<div className="text-[12px] text-[#8C8C8C]">
{recentProgressEvents.length ? `最近 ${recentProgressEvents.length}` : "暂无事件"}
</div>
</div>
<div className="mt-3 space-y-3">
{recentProgressEvents.length ? (
recentProgressEvents.map((event) => (
<div key={event.eventId} className="rounded-2xl bg-[#F7F8FA] px-3 py-3">
<div className="flex items-center justify-between gap-3 text-[12px] text-[#8C8C8C]">
<span>{renderFallback(event.phase, event.eventType)}</span>
<span>{formatTimestampLabel(event.createdAt)}</span>
</div>
<div className="mt-2 text-[13px] leading-6 text-[#111111]">{event.summary}</div>
<div className="mt-1 text-[12px] leading-5 text-[#57606A]">
{renderMetadataLine([event.threadDisplayName, event.deviceId])}
</div>
{event.blockerDelta ? (
<div className="mt-1 text-[12px] leading-5 text-[#A15C00]">
{event.blockerDelta}
</div>
) : null}
{event.nextStepDelta ? (
<div className="mt-1 text-[12px] leading-5 text-[#215B39]">
{event.nextStepDelta}
</div>
) : null}
</div>
))
) : (
<div className="rounded-2xl bg-[#F7F8FA] px-3 py-3 text-[12px] leading-6 text-[#57606A]">
线
</div>
)}
</div>
</div>
</div>
</AppShell>
);
}