write_file 的 content 在每个 SSE chunk 中持续增长,原先会反复触发 React 状态更新并打断整页;现改为按身份入参去重、节流发布 stub,并收口第 3 步为 Markdown 报告工作台。 Co-authored-by: Cursor <cursoragent@cursor.com>
52 lines
2.2 KiB
TypeScript
52 lines
2.2 KiB
TypeScript
import { Check, Loader2, UploadCloud } from "lucide-react";
|
||
|
||
import { cn } from "@/lib/utils";
|
||
import type { TaskArtifactSubmissionController, TaskArtifactTarget } from "@/roundtable-planning/lib/task-artifact-submission";
|
||
|
||
export function TaskArtifactSubmitButton({
|
||
controller,
|
||
target,
|
||
compact = false,
|
||
className,
|
||
}: {
|
||
controller?: TaskArtifactSubmissionController;
|
||
target: TaskArtifactTarget;
|
||
compact?: boolean;
|
||
className?: string;
|
||
}) {
|
||
if (!controller?.enabled || !controller.isMarkdown(target)) return null;
|
||
const state = controller.stateFor(target);
|
||
const error = controller.errorFor(target);
|
||
const isSubmitted = state === "submitted";
|
||
const isSubmitting = state === "submitting";
|
||
const label = isSubmitted ? "已提交" : isSubmitting ? "提交中…" : "提交";
|
||
const title = error || (isSubmitted ? "该 Markdown 产物已提交到任务过程" : "提交 Markdown 过程产物");
|
||
|
||
return (
|
||
<button
|
||
type="button"
|
||
disabled={isSubmitting || isSubmitted}
|
||
aria-label={`${target.name || target.path}:${label}`}
|
||
title={title}
|
||
onClick={(event) => {
|
||
event.stopPropagation();
|
||
void controller.submit(target).catch(() => undefined);
|
||
}}
|
||
className={cn(
|
||
"inline-flex shrink-0 items-center justify-center gap-1 rounded-md border px-2 py-1 text-[10px] font-semibold transition focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/60 disabled:cursor-not-allowed",
|
||
isSubmitted
|
||
? "border-emerald-300 bg-emerald-50 text-emerald-700 dark:border-emerald-500/40 dark:bg-emerald-500/10 dark:text-emerald-300"
|
||
: error
|
||
? "border-rose-300 bg-rose-50 text-rose-700 hover:bg-rose-100 dark:border-rose-500/40 dark:bg-rose-500/10 dark:text-rose-300"
|
||
: "border-primary/35 bg-primary/10 text-primary hover:bg-primary/15",
|
||
// 沙箱头部的其他分段切换器外框为 40px 高,提交入口与之对齐。
|
||
compact && "h-10 px-3 text-xs",
|
||
className,
|
||
)}
|
||
>
|
||
{isSubmitting ? <Loader2 className="size-3 animate-spin" /> : isSubmitted ? <Check className="size-3" /> : <UploadCloud className="size-3" />}
|
||
<span>{label}</span>
|
||
</button>
|
||
);
|
||
}
|