111 lines
4.7 KiB
TypeScript
111 lines
4.7 KiB
TypeScript
import { notFound, redirect } from "next/navigation";
|
||
import { z } from "zod";
|
||
import { auth } from "@/app/(auth)/auth";
|
||
import { feedbackReceipt, findCanvasFeedback } from "@/lib/canvas/feedback-store";
|
||
import { formatFeedbackTime } from "@/lib/canvas/feedback-contract";
|
||
|
||
export const dynamic = "force-dynamic";
|
||
|
||
export default async function CanvasFeedbackPage({ params }: { params: Promise<{ id: string }> }) {
|
||
const { id } = await params;
|
||
if (!z.string().uuid().safeParse(id).success) notFound();
|
||
const session = await auth();
|
||
if (!session?.user?.id || session.user.type === "guest") {
|
||
const query = new URLSearchParams({ callbackUrl: `/feedback/${id}` });
|
||
redirect(`/login?${query}`);
|
||
}
|
||
const feedback = await findCanvasFeedback(id);
|
||
if (!feedback || (feedback.userId !== session.user.id && session.user.type !== "admin"))
|
||
notFound();
|
||
const { reporter, project, request, client, userAgent } = feedback.snapshot;
|
||
const fields = [
|
||
["反馈编号", feedback.id],
|
||
["反馈人", `${reporter.name} · ${reporter.email} · ${reporter.department || "未登记部门"}`],
|
||
["用户编号", reporter.id],
|
||
["反馈时间", formatFeedbackTime(feedback.createdAt.toISOString())],
|
||
["画布", `${project.title}(${project.id})`],
|
||
["对话编号", client.chatId || "未打开对话"],
|
||
["请求号", request?.requestId || "尚未获取"],
|
||
["任务或消息编号", request?.id || "未关联"],
|
||
["请求时间", request?.createdAt ? formatFeedbackTime(request.createdAt) : "未记录"],
|
||
["状态与模型", `${request?.status || "页面问题"} / ${request?.model || "未记录"}`],
|
||
[
|
||
"处理耗时",
|
||
request?.durationMs != null
|
||
? `${(request.durationMs / 1000).toFixed(1)} 秒`
|
||
: "未记录或尚未结束",
|
||
],
|
||
[
|
||
"资料来源",
|
||
request?.evidence === "browser"
|
||
? "浏览器当前对话,服务端尚无对应消息记录"
|
||
: "服务端记录及浏览器当前页面",
|
||
],
|
||
["页面版本", client.pageVersion],
|
||
["浏览器", userAgent],
|
||
[
|
||
"窗口与网络",
|
||
`${client.viewport.width} × ${client.viewport.height} · ${client.online ? "在线" : "离线"}`,
|
||
],
|
||
];
|
||
return (
|
||
<main className="mx-auto max-w-3xl space-y-6 px-6 py-8 text-foreground">
|
||
<h1 className="text-2xl font-semibold">画布问题反馈</h1>
|
||
<p className="text-sm text-muted-foreground">{feedbackReceipt(feedback).message}</p>
|
||
<dl className="space-y-3">
|
||
{fields.map(([label, value]) => (
|
||
<div key={label} className="grid gap-1 text-sm sm:grid-cols-[8rem_1fr]">
|
||
<dt className="text-muted-foreground">{label}</dt>
|
||
<dd className="whitespace-pre-wrap break-words">{value}</dd>
|
||
</div>
|
||
))}
|
||
</dl>
|
||
{[
|
||
["用户说明", feedback.description || "未补充说明"],
|
||
["请求内容", request?.prompt || "未关联具体请求"],
|
||
["错误信息", request?.error || client.errors.join("\n") || "未记录明确错误"],
|
||
].map(([label, value]) => (
|
||
<section key={label} className="space-y-2">
|
||
<h2 className="text-base font-medium">{label}</h2>
|
||
<p className="whitespace-pre-wrap break-words rounded-lg bg-muted p-4 text-sm">{value}</p>
|
||
</section>
|
||
))}
|
||
{request?.parameters && Object.keys(request.parameters).length > 0 && (
|
||
<section className="space-y-2">
|
||
<h2 className="text-base font-medium">请求参数</h2>
|
||
<pre className="overflow-auto whitespace-pre-wrap break-all rounded-lg bg-muted p-4 text-sm">
|
||
{JSON.stringify(request.parameters, null, 2)}
|
||
</pre>
|
||
</section>
|
||
)}
|
||
{client.nodes.length > 0 && (
|
||
<details className="text-sm">
|
||
<summary className="cursor-pointer">相关画布节点</summary>
|
||
<pre className="mt-3 overflow-auto whitespace-pre-wrap break-all">
|
||
{JSON.stringify(client.nodes, null, 2)}
|
||
</pre>
|
||
</details>
|
||
)}
|
||
<details className="text-sm">
|
||
<summary className="cursor-pointer">当前对话上下文</summary>
|
||
<div className="mt-4 space-y-4">
|
||
{client.messages.map((item) => (
|
||
<div key={item.id} className="space-y-1">
|
||
<p className="text-muted-foreground">
|
||
{item.role === "user" ? "用户" : "助手"} · {item.id}
|
||
</p>
|
||
<p className="whitespace-pre-wrap break-words">{item.text}</p>
|
||
</div>
|
||
))}
|
||
</div>
|
||
</details>
|
||
<a
|
||
className="inline-block text-sm underline underline-offset-4"
|
||
href={`/canvas/${project.id}`}
|
||
>
|
||
打开相关画布
|
||
</a>
|
||
</main>
|
||
);
|
||
}
|