feat: add thread status documents and safe thread reply handling
This commit is contained in:
@@ -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 });
|
||||
}
|
||||
|
||||
|
||||
161
src/app/conversations/[projectId]/thread-status/page.tsx
Normal file
161
src/app/conversations/[projectId]/thread-status/page.tsx
Normal 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>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user