feat(web): 工作台 - 优化 Agent 工作区与技能库
This commit is contained in:
1 parent
b4111a8721
commit
5df5e09c63
22 files changed
+1681
-196
No files matched your search
@@ -0,0 +1,123 @@
|
||||
.canvas-sync-status-trigger {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
min-height: 30px;
|
||||
padding-inline: 9px;
|
||||
border: 1px solid transparent;
|
||||
border-radius: 999px;
|
||||
color: var(--user-ink-muted, var(--muted-foreground));
|
||||
transition: border-color 160ms ease, background 160ms ease, color 160ms ease;
|
||||
}
|
||||
|
||||
.canvas-sync-status-trigger:hover,
|
||||
.canvas-sync-status-trigger[aria-expanded="true"] {
|
||||
background: var(--user-surface-hover, var(--accent));
|
||||
color: var(--user-ink, var(--foreground));
|
||||
}
|
||||
|
||||
.canvas-sync-status-trigger--done { color: var(--status-success, #3f8f68); }
|
||||
.canvas-sync-status-trigger--pending { color: var(--status-warning, #b7791f); }
|
||||
.canvas-sync-status-trigger--error,
|
||||
.canvas-sync-status-trigger--conflict { color: var(--status-error, var(--destructive)); }
|
||||
|
||||
.canvas-sync-popover .ant-popover-inner {
|
||||
overflow: hidden;
|
||||
padding: 0;
|
||||
border: 1px solid var(--user-border, var(--border));
|
||||
border-radius: var(--user-radius-card, 16px);
|
||||
background: var(--user-surface-raised, var(--popover));
|
||||
box-shadow: 0 18px 48px color-mix(in srgb, var(--user-ink, var(--foreground)) 16%, transparent);
|
||||
}
|
||||
|
||||
.canvas-sync-popover .ant-popover-inner-content { padding: 0; }
|
||||
|
||||
.canvas-sync-panel {
|
||||
width: min(340px, calc(100vw - 32px));
|
||||
color: var(--user-ink, var(--foreground));
|
||||
}
|
||||
|
||||
.canvas-sync-panel__header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 11px;
|
||||
padding: 16px 17px 12px;
|
||||
}
|
||||
|
||||
.canvas-sync-panel__status-icon {
|
||||
display: grid;
|
||||
width: 34px;
|
||||
height: 34px;
|
||||
flex: 0 0 34px;
|
||||
place-items: center;
|
||||
border-radius: 11px;
|
||||
background: color-mix(in srgb, var(--user-ink-muted, var(--muted-foreground)) 11%, transparent);
|
||||
color: var(--user-ink-muted, var(--muted-foreground));
|
||||
}
|
||||
|
||||
.canvas-sync-panel__status-icon svg { width: 17px; height: 17px; }
|
||||
.canvas-sync-panel--done .canvas-sync-panel__status-icon { background: color-mix(in srgb, var(--status-success, #3f8f68) 13%, transparent); color: var(--status-success, #3f8f68); }
|
||||
.canvas-sync-panel--pending .canvas-sync-panel__status-icon { background: color-mix(in srgb, var(--status-warning, #b7791f) 14%, transparent); color: var(--status-warning, #b7791f); }
|
||||
.canvas-sync-panel--error .canvas-sync-panel__status-icon,
|
||||
.canvas-sync-panel--conflict .canvas-sync-panel__status-icon { background: color-mix(in srgb, var(--status-error, var(--destructive)) 13%, transparent); color: var(--status-error, var(--destructive)); }
|
||||
|
||||
.canvas-sync-panel__heading { min-width: 0; }
|
||||
.canvas-sync-panel__eyebrow {
|
||||
display: block;
|
||||
margin-bottom: 2px;
|
||||
color: var(--user-ink-soft, var(--muted-foreground));
|
||||
font-size: 11px;
|
||||
letter-spacing: .04em;
|
||||
}
|
||||
.canvas-sync-panel__heading strong { display: block; font-size: 14px; font-weight: 650; }
|
||||
|
||||
.canvas-sync-panel__description {
|
||||
margin: 0;
|
||||
padding: 0 17px 13px;
|
||||
color: var(--user-ink-muted, var(--muted-foreground));
|
||||
font-size: 12px;
|
||||
line-height: 1.65;
|
||||
}
|
||||
|
||||
.canvas-sync-panel__callout {
|
||||
display: grid;
|
||||
gap: 3px;
|
||||
margin: 0 17px 13px;
|
||||
padding: 10px 11px;
|
||||
border: 1px solid color-mix(in srgb, var(--status-warning, #b7791f) 25%, var(--user-border, var(--border)));
|
||||
border-radius: 10px;
|
||||
background: color-mix(in srgb, var(--status-warning, #b7791f) 8%, var(--user-surface, var(--background)));
|
||||
color: var(--user-ink-muted, var(--muted-foreground));
|
||||
font-size: 11px;
|
||||
line-height: 1.55;
|
||||
}
|
||||
.canvas-sync-panel--error .canvas-sync-panel__callout { border-color: color-mix(in srgb, var(--status-error, var(--destructive)) 25%, var(--user-border, var(--border))); background: color-mix(in srgb, var(--status-error, var(--destructive)) 7%, var(--user-surface, var(--background))); }
|
||||
.canvas-sync-panel__callout strong { color: var(--user-ink, var(--foreground)); font-size: 12px; }
|
||||
|
||||
.canvas-sync-panel__actions {
|
||||
display: grid;
|
||||
gap: 8px;
|
||||
padding: 0 17px 15px;
|
||||
}
|
||||
.canvas-sync-panel__actions .ant-btn { border-radius: 9px; }
|
||||
.canvas-sync-panel__secondary-actions {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 4px;
|
||||
margin: 1px -5px -3px;
|
||||
}
|
||||
.canvas-sync-panel__secondary-actions .ant-btn {
|
||||
min-width: 0;
|
||||
padding-inline: 6px;
|
||||
color: var(--user-ink-muted, var(--muted-foreground));
|
||||
font-size: 11px;
|
||||
}
|
||||
.canvas-sync-panel__secondary-actions .ant-btn:hover { color: var(--user-ink, var(--foreground)); background: var(--user-surface-hover, var(--accent)); }
|
||||
|
||||
.canvas-sync-confirm-copy p { margin: 0 0 8px; line-height: 1.65; }
|
||||
.canvas-sync-confirm-copy p:last-child { margin-bottom: 0; color: var(--muted-foreground); font-size: 12px; }
|
||||
.canvas-sync-modal-icon { color: var(--status-warning, #b7791f); }
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.canvas-sync-status-trigger { transition: none; }
|
||||
}
|
||||
@@ -1,65 +1,147 @@
|
||||
import { App, Button, Dropdown, Popover } from "antd";
|
||||
import { CloudCheck, CloudOff, LoaderCircle } from "lucide-react";
|
||||
import { CloudCheck, CloudOff, Download, FileClock, LoaderCircle, RefreshCw } from "lucide-react";
|
||||
import { useState } from "react";
|
||||
import { exportCanvasProjects } from "@/lib/canvas/canvas-export";
|
||||
import { readAllCanvasSyncDrafts, readCanvasSyncDrafts, type CanvasSyncDraft } from "@/services/canvas-sync-drafts";
|
||||
import { getActiveUserScope } from "@/lib/user-scope";
|
||||
import { useCanvasStore } from "@/stores/canvas/use-canvas-store";
|
||||
import { useSyncProgressStore } from "@/stores/use-sync-progress-store";
|
||||
import { retryRemoteUserDataSync } from "@/services/user-data-sync";
|
||||
import "./canvas-sync-status.css";
|
||||
|
||||
export function CanvasSyncStatus({ projectId, onLoadLatest, onOpenVersions }: { projectId: string; onLoadLatest: () => Promise<void>; onOpenVersions?: () => void }) {
|
||||
const { message } = App.useApp();
|
||||
const { message, modal } = App.useApp();
|
||||
const progress = useSyncProgressStore((state) => state.syncingProjects[projectId]);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [statusOpen, setStatusOpen] = useState(false);
|
||||
const phase = progress?.phase;
|
||||
const conflict = phase === "conflict";
|
||||
const failed = phase === "error" || conflict || !phase;
|
||||
const error = phase === "error";
|
||||
const retryScheduled = error && progress?.message?.includes("自动重试");
|
||||
const saving = phase === "pending" || phase === "saving" || phase === "uploading";
|
||||
const label = conflict ? "版本冲突 · 未同步" : !phase ? "尚未同步" : failed ? "云端未保存" : saving ? "正在保存" : "已保存";
|
||||
const tone = conflict ? "conflict" : error ? "error" : saving ? "pending" : phase === "done" ? "done" : "idle";
|
||||
const label = conflict ? "需要处理冲突" : error ? "云端保存失败" : saving ? "正在同步" : phase === "done" ? "已保存到云端" : "尚未同步";
|
||||
const description = conflict
|
||||
? "本地修改没有被覆盖,已保存为本地草稿。"
|
||||
: error
|
||||
? progress?.message || "本地内容仍然保留,云端暂未确认。"
|
||||
: saving
|
||||
? progress?.message || "正在把本地修改同步到云端。"
|
||||
: phase === "done"
|
||||
? progress?.message || "当前画布与云端版本一致。"
|
||||
: "本地内容会先保存到浏览器,再尝试同步到云端。";
|
||||
|
||||
const run = async (operation: () => Promise<unknown>) => {
|
||||
setBusy(true);
|
||||
try {
|
||||
await operation();
|
||||
} catch (error) {
|
||||
message.error(error instanceof Error ? error.message : "操作失败,请重试");
|
||||
} catch (cause) {
|
||||
message.error(cause instanceof Error ? cause.message : "操作失败,请重试");
|
||||
throw cause;
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
const confirmLoadLatest = () => {
|
||||
modal.confirm({
|
||||
title: "加载云端最新版本?",
|
||||
icon: <CloudOff className="canvas-sync-modal-icon" aria-hidden="true" />,
|
||||
content: (
|
||||
<div className="canvas-sync-confirm-copy">
|
||||
<p>这不是合并操作:当前编辑器内容会替换为云端版本。</p>
|
||||
<p>系统会先把本地修改保存为草稿,之后可从“版本记录”查看或下载,不会直接丢失。</p>
|
||||
</div>
|
||||
),
|
||||
okText: "保留草稿并加载",
|
||||
cancelText: "继续编辑",
|
||||
okButtonProps: { danger: true },
|
||||
onOk: () =>
|
||||
run(async () => {
|
||||
await onLoadLatest();
|
||||
setStatusOpen(false);
|
||||
message.success("云端版本已加载,本地内容已保留为草稿");
|
||||
}),
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Popover
|
||||
trigger="click"
|
||||
placement="bottom"
|
||||
open={statusOpen}
|
||||
onOpenChange={setStatusOpen}
|
||||
content={
|
||||
<div className="max-w-80 space-y-3" data-canvas-no-zoom>
|
||||
<p role="status" className="text-sm">
|
||||
{progress?.message || (phase === "done" ? "画布已同步到云端" : "尚未确认云端保存,请保留本地内容")}
|
||||
</p>
|
||||
{conflict ? <p className="text-xs text-muted-foreground">此画布的自动提交已暂停。加载最新版前会保留本地草稿,可下载后从画布列表导入为副本。</p> : null}
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<Button size="small" loading={busy} onClick={() => void run(onLoadLatest)}>
|
||||
加载云端最新版本
|
||||
</Button>
|
||||
<Popover
|
||||
trigger="click"
|
||||
placement="bottom"
|
||||
open={statusOpen}
|
||||
onOpenChange={setStatusOpen}
|
||||
arrow={false}
|
||||
classNames={{ root: "canvas-sync-popover", container: "canvas-sync-popover-surface", content: "canvas-sync-popover-content" }}
|
||||
content={
|
||||
<div className={`canvas-sync-panel canvas-sync-panel--${tone}`} data-canvas-no-zoom>
|
||||
<div className="canvas-sync-panel__header">
|
||||
<span className="canvas-sync-panel__status-icon" aria-hidden="true">
|
||||
{saving ? <LoaderCircle className="animate-spin motion-reduce:animate-none" /> : conflict || error ? <CloudOff /> : <CloudCheck />}
|
||||
</span>
|
||||
<div className="canvas-sync-panel__heading">
|
||||
<span className="canvas-sync-panel__eyebrow">云端同步</span>
|
||||
<strong>{label}</strong>
|
||||
</div>
|
||||
</div>
|
||||
<p className="canvas-sync-panel__description" role="status">{description}</p>
|
||||
{conflict ? (
|
||||
<div className="canvas-sync-panel__callout">
|
||||
<strong>先保护本地,再决定版本</strong>
|
||||
<span>{progress?.draftCount ? `已保留 ${progress.draftCount} 份本地草稿。` : "加载云端版前会先保留本地草稿。"} 这是替换,不是合并。</span>
|
||||
</div>
|
||||
) : error ? (
|
||||
<div className="canvas-sync-panel__callout">
|
||||
<strong>{retryScheduled ? "本地内容仍在,正在等待重试" : "本地内容仍在,未覆盖云端"}</strong>
|
||||
<span>
|
||||
{retryScheduled
|
||||
? "网络恢复后会自动重试;也可以点击“立即重试”。"
|
||||
: "请处理上面的错误后点击“立即重试”;在此之前本地内容不会被覆盖。"}
|
||||
</span>
|
||||
</div>
|
||||
) : null}
|
||||
<div className="canvas-sync-panel__actions">
|
||||
{error ? (
|
||||
<Button
|
||||
type="primary"
|
||||
block
|
||||
icon={<RefreshCw className="size-3.5" />}
|
||||
loading={busy}
|
||||
onClick={() => void run(() => retryRemoteUserDataSync(projectId)).then(() => setStatusOpen(false)).catch(() => undefined)}
|
||||
>
|
||||
立即重试
|
||||
</Button>
|
||||
) : null}
|
||||
<Button
|
||||
block
|
||||
icon={<CloudOff className="size-3.5" />}
|
||||
disabled={busy || saving}
|
||||
onClick={confirmLoadLatest}
|
||||
>
|
||||
加载云端版
|
||||
</Button>
|
||||
<div className="canvas-sync-panel__secondary-actions">
|
||||
<Button
|
||||
type="text"
|
||||
size="small"
|
||||
disabled={busy}
|
||||
icon={<Download className="size-3.5" />}
|
||||
onClick={() =>
|
||||
void run(async () => {
|
||||
const project = useCanvasStore.getState().openProject(projectId);
|
||||
if (project) await exportCanvasProjects([project], `${project.title}-本地草稿`);
|
||||
})
|
||||
if (project) await exportCanvasProjects([project], `${project.title}-本地副本`);
|
||||
message.success("当前内容已下载,可作为新画布导入");
|
||||
}).catch(() => undefined)
|
||||
}
|
||||
>
|
||||
下载当前内容
|
||||
下载本地副本
|
||||
</Button>
|
||||
{onOpenVersions ? (
|
||||
<Button
|
||||
type="text"
|
||||
size="small"
|
||||
disabled={busy}
|
||||
icon={<FileClock className="size-3.5" />}
|
||||
onClick={() => {
|
||||
setStatusOpen(false);
|
||||
onOpenVersions();
|
||||
@@ -70,19 +152,20 @@ export function CanvasSyncStatus({ projectId, onLoadLatest, onOpenVersions }: {
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<Button
|
||||
type="text"
|
||||
size="small"
|
||||
className={`canvas-sync-status-trigger canvas-sync-status-trigger--${tone}`}
|
||||
aria-label={`画布保存状态:${label}`}
|
||||
aria-expanded={statusOpen}
|
||||
icon={saving ? <LoaderCircle className="size-3.5 animate-spin motion-reduce:animate-none" /> : conflict || error ? <CloudOff className="size-3.5" /> : <CloudCheck className="size-3.5" />}
|
||||
>
|
||||
<Button
|
||||
type="text"
|
||||
size="small"
|
||||
danger={failed}
|
||||
aria-label={`画布保存状态:${label}`}
|
||||
icon={saving ? <LoaderCircle className="size-3.5 animate-spin motion-reduce:animate-none" /> : failed ? <CloudOff className="size-3.5" /> : <CloudCheck className="size-3.5" />}
|
||||
>
|
||||
<span className="canvas-sync-status-label text-xs">{label}</span>
|
||||
</Button>
|
||||
</Popover>
|
||||
</>
|
||||
<span className="canvas-sync-status-label text-xs">{label}</span>
|
||||
</Button>
|
||||
</Popover>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -2828,7 +2828,17 @@ function InfiniteCanvasPage() {
|
||||
|
||||
<div className={versions.open ? "hidden" : "contents"}>
|
||||
<CanvasCloudAgentPanel canvasId={projectId} domainProjectId={currentProject?.projectId} nodeCount={nodes.length} selectedNodeIds={Array.from(selectedNodeIds)} references={agentMentionReferences} prefillPrompt={agentPrefillPrompt} open={assistantOpen} onOpen={openAgent} onCollapse={closeAgent} onFocusNode={(nodeId) => {
|
||||
if (!nodesRef.current.some((node) => node.id === nodeId)) { message.info("该节点已删除或尚未同步到画布"); return; }
|
||||
const currentNodes = nodesRef.current;
|
||||
const target = currentNodes.find((node) => node.id === nodeId);
|
||||
if (!target) { message.info("该节点已删除或尚未同步到画布"); return; }
|
||||
|
||||
const parent = target.parentId ? currentNodes.find((node) => node.id === target.parentId) : null;
|
||||
if (parent?.metadata?.frame?.collapsed) toggleFrameCollapsed(parent.id);
|
||||
|
||||
const batchRootId = target.metadata?.batchRootId;
|
||||
const batchRoot = batchRootId ? currentNodes.find((node) => node.id === batchRootId) : null;
|
||||
if (batchRoot && isHiddenBatchChild(target, currentNodes) && !batchRoot.metadata?.imageBatchExpanded) toggleBatchExpanded(batchRoot.id);
|
||||
|
||||
focusCanvasNode(nodeId);
|
||||
}} />
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user