forked from longtao.wu/droboticflow
7244 lines
361 KiB
TypeScript
7244 lines
361 KiB
TypeScript
import React, { useState, useCallback, memo, useEffect, useMemo, useRef } from "react";
|
||
import { Logo } from "../components/Logo";
|
||
import ReactFlow, {
|
||
addEdge,
|
||
Background,
|
||
type Connection,
|
||
Controls,
|
||
MiniMap,
|
||
type Edge,
|
||
type EdgeMouseHandler,
|
||
type Node,
|
||
type NodeMouseHandler,
|
||
type NodeProps,
|
||
type ReactFlowInstance,
|
||
useNodesState,
|
||
useEdgesState,
|
||
Panel,
|
||
Handle,
|
||
Position,
|
||
ControlButton,
|
||
} from "reactflow";
|
||
import "reactflow/dist/style.css";
|
||
import dagre from "dagre";
|
||
import { ArtifactPreviewPanel } from "../components/ArtifactPreviewPanel";
|
||
import { HoloBrainTrainingReportCard } from "../components/HoloBrainTrainingReportCard";
|
||
import { LightweightOperatorCodeEditor } from "../components/LightweightOperatorCodeEditor";
|
||
import { WorkflowRunControl, WorkflowSaveControl } from "../components/WorkflowEditorControls";
|
||
import {
|
||
Plus,
|
||
GripVertical,
|
||
ChevronLeft,
|
||
Download,
|
||
Settings,
|
||
Maximize2,
|
||
Minimize2,
|
||
Box,
|
||
Code,
|
||
Lock,
|
||
Clock,
|
||
FolderOpen,
|
||
Info,
|
||
Database,
|
||
X,
|
||
Search,
|
||
Loader2,
|
||
ChevronRight,
|
||
Layout,
|
||
Terminal,
|
||
GitMerge,
|
||
Divide,
|
||
Cpu,
|
||
CheckCircle2,
|
||
ClipboardCheck,
|
||
Shuffle,
|
||
GitBranch,
|
||
Scissors,
|
||
Type,
|
||
RotateCcw,
|
||
RefreshCw,
|
||
Activity,
|
||
Star,
|
||
Users,
|
||
Shield,
|
||
} from "lucide-react";
|
||
import { useNavigate, useSearchParams, useParams, useLocation } from "react-router-dom";
|
||
import { useTimeZone } from "../context/TimeZoneContext";
|
||
import { useUser } from "../context/UserContext";
|
||
import { cn } from "../lib/utils";
|
||
import { getActionErrorMessage } from "../lib/action-errors.js";
|
||
import { formatClockTime, formatCompactDateTime } from "../lib/datetime";
|
||
import { buildDataAssetsPath, DATA_ASSET_PACKAGES_TAB, DATA_ASSET_SOURCE_TAB } from "../lib/data-assets.js";
|
||
import { getWorkflowGPUCapacityBlocker, gpuCapacityStatus, hasPositiveGPURequest } from "../lib/gpu-capacity.js";
|
||
import { summarizeHoloBrainRun } from "../lib/holobrain-training-report.js";
|
||
import { selectNodeRunLogs, summarizeNodeRuntime } from "../lib/run-logs.js";
|
||
import { canManagePipelineDesign } from "../lib/user-roles";
|
||
import {
|
||
decorateWorkflowEdges,
|
||
decorateWorkflowNodes,
|
||
getCurrentNodeLabel,
|
||
getEdgeOutputArtifacts,
|
||
getNodeExecutionState,
|
||
getRunDisplayStatus,
|
||
getTrackedRunId,
|
||
isRunInFlight,
|
||
} from "../lib/workflow-run.js";
|
||
import { buildWorkflowSystemEnvVarsPreview } from "../lib/workflow-system-env.js";
|
||
import {
|
||
buildSelectedNodeEnvRows,
|
||
getWorkflowRunActionState,
|
||
isWorkflowSettingsLocked,
|
||
} from "../lib/workflow-editor.js";
|
||
import {
|
||
loadWorkflowDraft,
|
||
removeWorkflowDraft,
|
||
saveWorkflowDraft,
|
||
workflowDraftConflicts,
|
||
workflowDraftFingerprint,
|
||
} from "../lib/workflow-draft.js";
|
||
import {
|
||
canConnectToInput,
|
||
findInputConnectionConflicts,
|
||
removeSelectedCanvasElements,
|
||
validateSingleConnectedWorkflowGraph,
|
||
} from "../lib/workflow-canvas.js";
|
||
import { getOperatorLibrarySections } from "../lib/operator-library.js";
|
||
import {
|
||
applyScanConfigPatchToWorkflow,
|
||
buildScheduledWorkflowSchedule,
|
||
ensureScanWorkflowShell,
|
||
effectiveWorkflowScheduleMode,
|
||
getScanWorkflowConfigIssue,
|
||
getScanWorkflowDraftIssue,
|
||
isDedicatedScanSourceNode,
|
||
isWorkflowScheduleEnabled,
|
||
isScanSourceNode,
|
||
normalizeDirectoryDepth,
|
||
normalizeNonNegativeInteger,
|
||
normalizePositiveInteger,
|
||
normalizeWorkflowSchedule,
|
||
stripScanWorkflowShell,
|
||
} from "../lib/scan-workflows.js";
|
||
import {
|
||
buildStorageHistoryScopeKey,
|
||
filterRecentPathsAgainstFavorites,
|
||
listFavoriteStoragePaths,
|
||
listFavoriteStoragePathRecords,
|
||
normalizeFavoriteStoragePathRecords,
|
||
listRecentStoragePaths,
|
||
mergeFavoriteStoragePathRecords,
|
||
rememberStoragePath,
|
||
replaceFavoriteStoragePathRecords,
|
||
toggleFavoriteStoragePath,
|
||
} from "../lib/storage-path-history.js";
|
||
import { validateStorageConnectionEndpoint } from "../lib/storage-connections.js";
|
||
import { buildTemplatePayload, getTemplatePayloadIssue } from "../lib/templates.js";
|
||
import { monitoringApi } from "../services/api/monitoring";
|
||
import { mongoConnectionsApi } from "../services/api/mongo-connections";
|
||
import { storageConnectionsApi } from "../services/api/storage-connections";
|
||
import { workerApi } from "../services/api/worker";
|
||
import { motion, AnimatePresence } from "motion/react";
|
||
import { workflowsApi } from "../services/api/workflows";
|
||
import { templatesApi } from "../services/api/templates";
|
||
import { projectsApi } from "../services/api/projects";
|
||
import type {
|
||
ExecutionData,
|
||
ExecutionRun,
|
||
ExecutionRunSummary,
|
||
MongoConnection,
|
||
Operator,
|
||
PortDefinition,
|
||
StorageConnection,
|
||
HyperParam,
|
||
Workflow,
|
||
WorkflowNodeSourceState,
|
||
WorkflowType,
|
||
WorkflowSchedule,
|
||
WorkflowTemplate,
|
||
WorkerCapacity,
|
||
} from "../types";
|
||
import { operatorsApi } from "../services/api/operators";
|
||
import { usersApi } from "../services/api/users";
|
||
|
||
type OperatorExecutionState = "idle" | "running" | "cancelled" | "waiting_for_audit" | "completed" | "failed";
|
||
type EditorSaveState = "idle" | "dirty" | "saving" | "saved" | "error";
|
||
|
||
type EditorDraftRecovery = {
|
||
payload: Workflow | WorkflowTemplate;
|
||
baseUpdatedAt?: string;
|
||
savedAt?: string;
|
||
conflict: boolean;
|
||
};
|
||
|
||
const GLOBAL_BOS_ENDPOINT_LABEL = "全局 BOS_ENDPOINT";
|
||
const defaultLightweightMountPath = "/opt/droboticflow/lightweight/operator";
|
||
|
||
const workflowScheduleIntegerFields: Array<[string, string]> = [
|
||
["interval", "schedule.interval"],
|
||
["intervalHours", "schedule.intervalHours"],
|
||
["dayInterval", "schedule.dayInterval"],
|
||
];
|
||
|
||
const workflowExecutionIntegerFields: Array<[string, string]> = [
|
||
["maxConcurrentRuns", "maxConcurrentRuns"],
|
||
["nodeTimeoutSeconds", "nodeTimeoutSeconds"],
|
||
["runTimeoutSeconds", "runTimeoutSeconds"],
|
||
["maxRetryAttempts", "maxRetryAttempts"],
|
||
["retryBackoffSeconds", "retryBackoffSeconds"],
|
||
];
|
||
|
||
function validateNonNegativeIntegerPatch(patch: Record<string, unknown>, fields: Array<[string, string]>) {
|
||
fields.forEach(([key, field]) => {
|
||
if (Object.prototype.hasOwnProperty.call(patch, key)) {
|
||
normalizeNonNegativeInteger(patch[key], field);
|
||
}
|
||
});
|
||
}
|
||
|
||
interface OperatorNodeData {
|
||
label: string;
|
||
category?: string;
|
||
description?: string;
|
||
inputs?: PortDefinition[];
|
||
outputs?: PortDefinition[];
|
||
operatorId?: string;
|
||
operatorVersion?: string;
|
||
operatorImageId?: string;
|
||
image?: string;
|
||
containerCommand?: string[];
|
||
containerArgs?: string[];
|
||
runtimeContract?: Record<string, unknown>;
|
||
hyperparams?: HyperParam[];
|
||
publicationStatus?: Operator["publicationStatus"];
|
||
generationSource?: Operator["generationSource"];
|
||
publicationEvidence?: Operator["publicationEvidence"];
|
||
cpu?: string;
|
||
memory?: string;
|
||
gpu?: string;
|
||
executionState?: OperatorExecutionState;
|
||
}
|
||
|
||
function isOperatorCandidate(value: unknown): value is Operator {
|
||
if (!value || typeof value !== "object") {
|
||
return false;
|
||
}
|
||
const candidate = value as Partial<Operator>;
|
||
return (
|
||
typeof candidate.name === "string" &&
|
||
typeof candidate.category === "string" &&
|
||
typeof candidate.description === "string" &&
|
||
Array.isArray(candidate.inputs) &&
|
||
Array.isArray(candidate.outputs)
|
||
);
|
||
}
|
||
|
||
function workflowExecutionScope(entity: Workflow | WorkflowTemplate | null) {
|
||
return entity?.executionScope === "sandbox" ? "sandbox" : "production";
|
||
}
|
||
|
||
function isAIGeneratedOperator(op: Partial<Operator> | OperatorNodeData | null | undefined) {
|
||
return op?.generationSource === "ai" || Boolean(op?.runtimeContract?.generatedRepository);
|
||
}
|
||
|
||
function operatorPublicationStatus(op: Partial<Operator> | OperatorNodeData | null | undefined) {
|
||
if (op?.publicationStatus) {
|
||
return op.publicationStatus;
|
||
}
|
||
return isAIGeneratedOperator(op) ? "draft" : "published";
|
||
}
|
||
|
||
function canUseOperatorInWorkflow(op: Operator, scope: string) {
|
||
return scope === "sandbox" || !isAIGeneratedOperator(op) || operatorPublicationStatus(op) === "published";
|
||
}
|
||
|
||
function publicationStatusLabel(status?: string) {
|
||
switch (status) {
|
||
case "draft":
|
||
return "草稿";
|
||
case "built":
|
||
return "已构建";
|
||
case "verified":
|
||
return "已验证";
|
||
case "published":
|
||
return "已发布";
|
||
default:
|
||
return "已发布";
|
||
}
|
||
}
|
||
|
||
// Custom Node with Multiple Ports
|
||
const OperatorNode = memo(({ data, selected }: NodeProps<OperatorNodeData>) => {
|
||
const executionState = data.executionState || "idle";
|
||
const executionStyles =
|
||
executionState === "running"
|
||
? "border-blue-400 shadow-[0_0_24px_rgba(59,130,246,0.28)] animate-node-flash z-10"
|
||
: executionState === "cancelled"
|
||
? "border-slate-400 shadow-[0_0_14px_rgba(148,163,184,0.16)]"
|
||
: executionState === "waiting_for_audit"
|
||
? "border-amber-400 shadow-[0_0_18px_rgba(245,158,11,0.2)] z-10"
|
||
: executionState === "completed"
|
||
? "border-emerald-400 shadow-[0_0_18px_rgba(52,211,153,0.16)]"
|
||
: executionState === "failed"
|
||
? "border-red-400 shadow-[0_0_18px_rgba(248,113,113,0.18)]"
|
||
: "";
|
||
const statusLabel =
|
||
executionState === "running"
|
||
? "运行中"
|
||
: executionState === "cancelled"
|
||
? "已取消"
|
||
: executionState === "waiting_for_audit"
|
||
? "待审核"
|
||
: executionState === "completed"
|
||
? "已完成"
|
||
: executionState === "failed"
|
||
? "失败"
|
||
: "";
|
||
|
||
const getPortColor = (type: string) => {
|
||
switch (type) {
|
||
case "video":
|
||
return "bg-purple-500";
|
||
case "image":
|
||
return "bg-blue-500";
|
||
case "json":
|
||
return "bg-yellow-500";
|
||
case "tensor":
|
||
return "bg-orange-500";
|
||
default:
|
||
return "bg-gray-500";
|
||
}
|
||
};
|
||
|
||
return (
|
||
<div
|
||
className={cn(
|
||
"bg-[#1e293b] border rounded-lg min-w-[200px] shadow-2xl transition-all overflow-visible relative",
|
||
selected ? "border-blue-500 ring-1 ring-blue-500" : "border-[#2a2b2f]",
|
||
executionStyles,
|
||
)}
|
||
>
|
||
{executionState !== "idle" && (
|
||
<div
|
||
className={cn(
|
||
"absolute -top-2 -right-2 w-5 h-5 rounded-full flex items-center justify-center z-20",
|
||
executionState === "running" && "bg-blue-500 shadow-[0_0_10px_rgba(59,130,246,0.8)]",
|
||
executionState === "cancelled" && "bg-slate-500 shadow-[0_0_10px_rgba(148,163,184,0.6)]",
|
||
executionState === "waiting_for_audit" && "bg-amber-500 shadow-[0_0_10px_rgba(245,158,11,0.7)]",
|
||
executionState === "completed" && "bg-emerald-500 shadow-[0_0_10px_rgba(52,211,153,0.6)]",
|
||
executionState === "failed" && "bg-red-500 shadow-[0_0_10px_rgba(248,113,113,0.7)]",
|
||
)}
|
||
>
|
||
{executionState === "running" ? (
|
||
<Loader2 className="w-2.5 h-2.5 text-white animate-spin" />
|
||
) : executionState === "cancelled" ? (
|
||
<X className="w-2.5 h-2.5 text-white" />
|
||
) : executionState === "waiting_for_audit" ? (
|
||
<Clock className="w-2.5 h-2.5 text-white" />
|
||
) : executionState === "completed" ? (
|
||
<CheckCircle2 className="w-2.5 h-2.5 text-white" />
|
||
) : (
|
||
<X className="w-2.5 h-2.5 text-white" />
|
||
)}
|
||
</div>
|
||
)}
|
||
{/* Header */}
|
||
<div className="p-3 border-b border-[#2a2b2f] bg-[#151619]/50 rounded-t-lg">
|
||
<div className="flex items-center gap-2 mb-1">
|
||
<div className="w-5 h-5 bg-blue-500/20 rounded flex items-center justify-center text-blue-400">
|
||
{(() => {
|
||
const label = data.label || "";
|
||
if (label.includes("导出")) return <Download className="w-3 h-3" />;
|
||
if (label.includes("合并")) return <GitMerge className="w-3 h-3" />;
|
||
if (label.includes("交集")) return <Divide className="w-3 h-3" />;
|
||
if (label.includes("分配")) return <Shuffle className="w-3 h-3" />;
|
||
if (label.includes("分割")) return <Scissors className="w-3 h-3" />;
|
||
if (label.includes("标注")) return <Type className="w-3 h-3" />;
|
||
if (label.includes("扫描")) return <Search className="w-3 h-3" />;
|
||
switch (data.category) {
|
||
case "IO":
|
||
return <Box className="w-3 h-3" />;
|
||
case "MATH":
|
||
return <Divide className="w-3 h-3" />;
|
||
case "AI":
|
||
return <Cpu className="w-3 h-3" />;
|
||
case "HUMAN":
|
||
return <ClipboardCheck className="w-3 h-3" />;
|
||
case "FLOW":
|
||
return <Shuffle className="w-3 h-3" />;
|
||
default:
|
||
return <Code className="w-3 h-3" />;
|
||
}
|
||
})()}
|
||
</div>
|
||
<span className="text-[9px] font-mono text-gray-500 uppercase tracking-widest">{data.category}</span>
|
||
{statusLabel && (
|
||
<span
|
||
className={cn(
|
||
"ml-auto rounded-full border px-1.5 py-0.5 text-[8px] font-mono uppercase tracking-[0.2em]",
|
||
executionState === "running" && "border-blue-400/40 bg-blue-500/10 text-blue-300",
|
||
executionState === "cancelled" && "border-slate-400/40 bg-slate-500/10 text-slate-200",
|
||
executionState === "waiting_for_audit" && "border-amber-400/40 bg-amber-500/10 text-amber-200",
|
||
executionState === "completed" && "border-emerald-400/40 bg-emerald-500/10 text-emerald-200",
|
||
executionState === "failed" && "border-red-400/40 bg-red-500/10 text-red-200",
|
||
)}
|
||
>
|
||
{statusLabel}
|
||
</span>
|
||
)}
|
||
</div>
|
||
<div className="text-xs font-bold text-white truncate">{data.label}</div>
|
||
</div>
|
||
|
||
<div className="p-3 space-y-4">
|
||
{/* Input Ports Section */}
|
||
<div className="space-y-2">
|
||
{(data.inputs || []).map((port, i) => (
|
||
<div key={port.id || `in-${i}`} className="flex items-center gap-2 relative">
|
||
<Handle
|
||
type="target"
|
||
position={Position.Left}
|
||
id={port.id || `in-${i}`}
|
||
className={cn("w-2.5 h-2.5 border-2 border-[#0a0a0a] -left-[18px]", getPortColor(port.type))}
|
||
/>
|
||
<div className="flex flex-col">
|
||
<span className="text-[10px] text-gray-300 font-medium leading-none">{port.name}</span>
|
||
<span className="text-[8px] text-gray-500 uppercase mt-0.5">{port.type}</span>
|
||
</div>
|
||
</div>
|
||
))}
|
||
</div>
|
||
|
||
{/* Output Ports Section */}
|
||
<div className="space-y-2">
|
||
{(data.outputs || []).map((port, i) => (
|
||
<div key={port.id || `out-${i}`} className="flex items-center justify-end gap-2 relative text-right">
|
||
<div className="flex flex-col">
|
||
<span className="text-[10px] text-gray-300 font-medium leading-none">{port.name}</span>
|
||
<span className="text-[8px] text-gray-500 uppercase mt-0.5">{port.type}</span>
|
||
</div>
|
||
<Handle
|
||
type="source"
|
||
position={Position.Right}
|
||
id={port.id || `out-${i}`}
|
||
className={cn("w-2.5 h-2.5 border-2 border-[#0a0a0a] -right-[18px]", getPortColor(port.type))}
|
||
/>
|
||
</div>
|
||
))}
|
||
</div>
|
||
</div>
|
||
</div>
|
||
);
|
||
});
|
||
|
||
const nodeTypes = {
|
||
operator: OperatorNode,
|
||
};
|
||
|
||
const runStatusLabels: Record<string, string> = {
|
||
queued: "排队中",
|
||
running: "运行中",
|
||
stopping: "停止中",
|
||
waiting_for_audit: "等待人工审核",
|
||
completed: "运行完成",
|
||
failed: "运行失败",
|
||
cancelled: "已取消",
|
||
};
|
||
|
||
const runTriggerLabels: Record<string, string> = {
|
||
manual: "手动",
|
||
scheduled: "周期",
|
||
retry: "自动重试",
|
||
rerun_subtree: "子链路重跑",
|
||
};
|
||
|
||
const duplicateInputConnectionMessage =
|
||
"检测到同一输入端口存在多条上游连线。每个输入端口只能连接一条上游连线;如需上传多个结果,请为每个结果添加单独的上传算子。";
|
||
const invalidGraphFallbackMessage = "工作流必须是单连通链路,不能存在孤立算子或多条完全独立链路。";
|
||
|
||
const runStatusClasses: Record<string, string> = {
|
||
queued: "border-slate-500/40 bg-slate-500/10 text-slate-200",
|
||
running: "border-blue-500/40 bg-blue-500/10 text-blue-200",
|
||
stopping: "border-amber-500/40 bg-amber-500/10 text-amber-200",
|
||
waiting_for_audit: "border-amber-500/40 bg-amber-500/10 text-amber-200",
|
||
completed: "border-emerald-500/40 bg-emerald-500/10 text-emerald-200",
|
||
failed: "border-red-500/40 bg-red-500/10 text-red-200",
|
||
cancelled: "border-gray-500/40 bg-gray-500/10 text-gray-200",
|
||
};
|
||
|
||
const executionStateLabels: Record<string, string> = {
|
||
idle: "尚未执行",
|
||
running: "正在执行中",
|
||
cancelled: "已取消",
|
||
waiting_for_audit: "等待审核",
|
||
completed: "执行完成",
|
||
failed: "执行失败",
|
||
};
|
||
|
||
function formatRuntimeDuration(durationMs: number) {
|
||
const totalSeconds = Math.max(0, Math.floor(durationMs / 1000));
|
||
const hours = Math.floor(totalSeconds / 3600);
|
||
const minutes = Math.floor((totalSeconds % 3600) / 60);
|
||
const seconds = totalSeconds % 60;
|
||
if (hours > 0) {
|
||
return `${hours}h ${minutes}m ${seconds}s`;
|
||
}
|
||
if (minutes > 0) {
|
||
return `${minutes}m ${seconds}s`;
|
||
}
|
||
return `${seconds}s`;
|
||
}
|
||
|
||
function isOssNode(node: Node | null | undefined) {
|
||
return Boolean(node?.data?.label?.includes("OSS"));
|
||
}
|
||
|
||
function isMongoWriteNode(node: Node | null | undefined) {
|
||
return Boolean(
|
||
node?.data?.label?.includes("MongoDB") ||
|
||
String(node?.data?.label || "")
|
||
.toLowerCase()
|
||
.includes("mongo"),
|
||
);
|
||
}
|
||
|
||
function getNodeHyperparamValue(node: Node | null | undefined, key: string) {
|
||
const hyperparams = Array.isArray(node?.data?.hyperparams) ? node.data.hyperparams : [];
|
||
const match = (hyperparams as HyperParam[]).find((item) => item?.key === key);
|
||
return typeof match?.value === "string" ? match.value.trim() : "";
|
||
}
|
||
|
||
function normalizeStoragePrefix(value: string) {
|
||
return String(value || "")
|
||
.trim()
|
||
.replace(/^\/+|\/+$/g, "");
|
||
}
|
||
|
||
function buildBosSourcePath(bucket: string, prefix: string) {
|
||
const normalizedBucket = String(bucket || "").trim();
|
||
if (!normalizedBucket) {
|
||
return "";
|
||
}
|
||
const normalizedPrefix = normalizeStoragePrefix(prefix);
|
||
return normalizedPrefix ? `bos://${normalizedBucket}/${normalizedPrefix}` : `bos://${normalizedBucket}`;
|
||
}
|
||
|
||
function getLightweightOperatorRuntime(data: OperatorNodeData | null | undefined) {
|
||
const raw = data?.runtimeContract?.lightweightOperator;
|
||
const contract = raw && typeof raw === "object" ? (raw as Record<string, unknown>) : {};
|
||
const codeSubPath = normalizeStoragePrefix(String(contract.codeSubPath || ""));
|
||
const mountPath = String(contract.mountPath || "").trim() || defaultLightweightMountPath;
|
||
const enabled = Boolean(contract.enabled || codeSubPath);
|
||
return {
|
||
enabled,
|
||
codeSubPath,
|
||
mountPath,
|
||
pvcName: "droboticflow-workspace",
|
||
workspacePath: codeSubPath ? `/workspace/${codeSubPath}` : "/workspace",
|
||
};
|
||
}
|
||
|
||
function findNodePort(node: Node | null | undefined, direction: "inputs" | "outputs", handleId: string) {
|
||
const ports: PortDefinition[] = Array.isArray(node?.data?.[direction]) ? node.data[direction] : [];
|
||
return (
|
||
ports.find((port) => String(port?.id || "").trim() === handleId) ||
|
||
ports.find((port) => String(port?.name || "").trim() === handleId) ||
|
||
null
|
||
);
|
||
}
|
||
|
||
function upsertNodeHyperparams(
|
||
hyperparams: Array<{ key?: string; value?: string; [key: string]: any }> | undefined,
|
||
updates: Record<string, string>,
|
||
) {
|
||
const next = Array.isArray(hyperparams) ? hyperparams.map((item) => ({ ...item })) : [];
|
||
const indexByKey = new Map<string, number>();
|
||
next.forEach((item, index) => {
|
||
if (typeof item?.key === "string" && item.key.trim()) {
|
||
indexByKey.set(item.key, index);
|
||
}
|
||
});
|
||
Object.entries(updates).forEach(([key, value]) => {
|
||
if (!key.trim()) {
|
||
return;
|
||
}
|
||
const existingIndex = indexByKey.get(key);
|
||
if (existingIndex === undefined) {
|
||
next.push({ key, value });
|
||
indexByKey.set(key, next.length - 1);
|
||
return;
|
||
}
|
||
next[existingIndex] = {
|
||
...next[existingIndex],
|
||
key,
|
||
value,
|
||
};
|
||
});
|
||
return next;
|
||
}
|
||
|
||
function normalizeWorkflowEnvKey(value: string | undefined) {
|
||
return String(value || "")
|
||
.trim()
|
||
.toUpperCase();
|
||
}
|
||
|
||
function duplicateWorkflowEnvKeys(
|
||
hyperparams: Array<{ key?: string; value?: string; [key: string]: any }> | undefined,
|
||
) {
|
||
const seen = new Set<string>();
|
||
const duplicates = new Set<string>();
|
||
(Array.isArray(hyperparams) ? hyperparams : []).forEach((item) => {
|
||
const normalized = normalizeWorkflowEnvKey(item?.key);
|
||
if (!normalized) {
|
||
return;
|
||
}
|
||
if (seen.has(normalized)) {
|
||
duplicates.add(normalized);
|
||
return;
|
||
}
|
||
seen.add(normalized);
|
||
});
|
||
return duplicates;
|
||
}
|
||
|
||
function cleanEditableHyperparams(
|
||
hyperparams: Array<{ key?: string; value?: string; [key: string]: any }> | undefined,
|
||
) {
|
||
return (Array.isArray(hyperparams) ? hyperparams : [])
|
||
.map((item) => ({
|
||
...item,
|
||
key: String(item?.key || "").trim(),
|
||
value: String(item?.value || ""),
|
||
description: typeof item?.description === "string" ? item.description : "",
|
||
}))
|
||
.filter((item) => item.key);
|
||
}
|
||
|
||
function isReactFlowNode(value: unknown): value is Node {
|
||
return typeof value === "object" && value !== null && typeof (value as { id?: unknown }).id === "string";
|
||
}
|
||
|
||
function isReactFlowNodeArray(value: unknown): value is Node[] {
|
||
return Array.isArray(value) && value.every(isReactFlowNode);
|
||
}
|
||
|
||
function isReactFlowEdge(value: unknown): value is Edge {
|
||
return typeof value === "object" && value !== null && typeof (value as { id?: unknown }).id === "string";
|
||
}
|
||
|
||
function isReactFlowEdgeArray(value: unknown): value is Edge[] {
|
||
return Array.isArray(value) && value.every(isReactFlowEdge);
|
||
}
|
||
|
||
const OPERATOR_DRAG_MIME = "application/droboticflow-operator";
|
||
const OPERATOR_DRAG_TEXT_MIME = "text/plain";
|
||
|
||
function dataTransferHasType(types: DataTransfer["types"], type: string) {
|
||
const normalizedType = type.toLowerCase();
|
||
if (typeof (types as unknown as { contains?: (value: string) => boolean }).contains === "function") {
|
||
return (types as unknown as { contains: (value: string) => boolean }).contains(type);
|
||
}
|
||
return Array.from(types).some((item) => item.toLowerCase() === normalizedType);
|
||
}
|
||
|
||
export default function WorkflowEditor() {
|
||
const { id } = useParams();
|
||
const navigate = useNavigate();
|
||
const location = useLocation();
|
||
const [searchParams, setSearchParams] = useSearchParams();
|
||
const { role, currentUser } = useUser();
|
||
const { timeZone } = useTimeZone();
|
||
const isReadOnly = searchParams.get("readOnly") === "true";
|
||
const isTemplate = searchParams.get("type") === "template";
|
||
const draftKind = isTemplate ? "template" : "workflow";
|
||
const requestedRunId = searchParams.get("runId")?.trim() || "";
|
||
const requestedFocusNodeId = searchParams.get("focusNodeId")?.trim() || "";
|
||
const requestedOpenConfigPanel = searchParams.get("openConfigPanel") === "true";
|
||
|
||
const canManage = canManagePipelineDesign(role);
|
||
|
||
const initialNodesData = isReactFlowNodeArray(location.state?.nodes) ? location.state.nodes : [];
|
||
const initialEdgesData = isReactFlowEdgeArray(location.state?.edges) ? location.state.edges : [];
|
||
|
||
const [nodes, setNodes, onNodesChange] = useNodesState(initialNodesData);
|
||
const [edges, setEdges, onEdgesChange] = useEdgesState(initialEdgesData);
|
||
const [entity, setEntity] = useState<Workflow | WorkflowTemplate | null>(null);
|
||
const [operators, setOperators] = useState<Operator[]>([]);
|
||
const [workerCapacity, setWorkerCapacity] = useState<WorkerCapacity | null>(null);
|
||
const [workerCapacityError, setWorkerCapacityError] = useState("");
|
||
const [operatorSearchQuery, setOperatorSearchQuery] = useState("");
|
||
const [selectedNode, setSelectedNode] = useState<Node | null>(null);
|
||
const [selectedEdgeId, setSelectedEdgeId] = useState("");
|
||
const [selectedEdgeArtifactId, setSelectedEdgeArtifactId] = useState("");
|
||
const [canvasNotice, setCanvasNotice] = useState("");
|
||
const [editorLoadError, setEditorLoadError] = useState("");
|
||
const [editorReloadToken, setEditorReloadToken] = useState(0);
|
||
const [saveState, setSaveState] = useState<EditorSaveState>("idle");
|
||
const [saveError, setSaveError] = useState("");
|
||
const [draftRecovery, setDraftRecovery] = useState<EditorDraftRecovery | null>(null);
|
||
const [isSavingDraftCopy, setIsSavingDraftCopy] = useState(false);
|
||
const [isExecuting, setIsExecuting] = useState(false);
|
||
const [activeRun, setActiveRun] = useState<ExecutionRun | null>(null);
|
||
const [activeRunError, setActiveRunError] = useState("");
|
||
const [isRunHistoryOpen, setIsRunHistoryOpen] = useState(false);
|
||
const [workflowRuns, setWorkflowRuns] = useState<ExecutionRunSummary[]>([]);
|
||
const [isWorkflowRunsLoading, setIsWorkflowRunsLoading] = useState(false);
|
||
const [workflowRunsError, setWorkflowRunsError] = useState("");
|
||
const [rerunSubtreePendingNodeId, setRerunSubtreePendingNodeId] = useState("");
|
||
const [runStopPending, setRunStopPending] = useState<"" | "graceful" | "force">("");
|
||
const [isLibOpen, setIsLibOpen] = useState(true);
|
||
const [isConfigOpen, setIsConfigOpen] = useState(false);
|
||
const [nodeConfigPanelTab, setNodeConfigPanelTab] = useState<"config" | "runtime" | "logs">("config");
|
||
const [liveRunLogs, setLiveRunLogs] = useState<ExecutionRun["logs"]>([]);
|
||
const [liveRunLogsError, setLiveRunLogsError] = useState("");
|
||
const [isLiveRunLogsLoading, setIsLiveRunLogsLoading] = useState(false);
|
||
const [liveRunLogsUpdatedAt, setLiveRunLogsUpdatedAt] = useState("");
|
||
const [liveRunLogsRefreshToken, setLiveRunLogsRefreshToken] = useState(0);
|
||
const [isConfigPanelExpanded, setIsConfigPanelExpanded] = useState(false);
|
||
const [isLightweightCodeEditorFullscreen, setIsLightweightCodeEditorFullscreen] = useState(false);
|
||
const [isOutputPreviewFullscreen, setIsOutputPreviewFullscreen] = useState(false);
|
||
const [configPanelMaxHeight, setConfigPanelMaxHeight] = useState(640);
|
||
const [isWorkflowSettingsOpen, setIsWorkflowSettingsOpen] = useState(false);
|
||
const [isExportTemplateOpen, setIsExportTemplateOpen] = useState(false);
|
||
const [templateDraft, setTemplateDraft] = useState({
|
||
name: "",
|
||
description: "",
|
||
});
|
||
const workflowSettingsPanelRef = useRef<HTMLDivElement | null>(null);
|
||
const workflowSettingsTriggerRef = useRef<HTMLButtonElement | null>(null);
|
||
const configPanelRef = useRef<HTMLDivElement | null>(null);
|
||
const nodeLogsPanelRef = useRef<HTMLDivElement | null>(null);
|
||
const nodeLogsFollowRef = useRef(true);
|
||
const reactFlowWrapperRef = useRef<HTMLDivElement | null>(null);
|
||
const reactFlowInstanceRef = useRef<ReactFlowInstance | null>(null);
|
||
const draggedOperatorRef = useRef<Operator | null>(null);
|
||
const autoFocusHandledRef = useRef(false);
|
||
const editorLoadedRef = useRef(false);
|
||
const lastSavedFingerprintRef = useRef("");
|
||
const serverUpdatedAtRef = useRef("");
|
||
const [isCanvasDragActive, setIsCanvasDragActive] = useState(false);
|
||
const [storageConnections, setStorageConnections] = useState<StorageConnection[]>([]);
|
||
const [isStorageConnectionsLoading, setIsStorageConnectionsLoading] = useState(false);
|
||
const [storageConnectionsError, setStorageConnectionsError] = useState("");
|
||
const [mongoConnections, setMongoConnections] = useState<MongoConnection[]>([]);
|
||
const [isMongoConnectionsLoading, setIsMongoConnectionsLoading] = useState(false);
|
||
const [mongoConnectionsError, setMongoConnectionsError] = useState("");
|
||
const [isStorageConnectionFormOpen, setIsStorageConnectionFormOpen] = useState(false);
|
||
const [isSavingStorageConnection, setIsSavingStorageConnection] = useState(false);
|
||
const [storageConnectionDraft, setStorageConnectionDraft] = useState({
|
||
name: "",
|
||
description: "",
|
||
endpoint: "",
|
||
accessKeyId: "",
|
||
secretAccessKey: "",
|
||
});
|
||
const [sourceState, setSourceState] = useState<WorkflowNodeSourceState | null>(null);
|
||
const [isSourceStateLoading, setIsSourceStateLoading] = useState(false);
|
||
const [sourceStateError, setSourceStateError] = useState("");
|
||
const [isResettingSourceState, setIsResettingSourceState] = useState(false);
|
||
const [sourceStateRefreshKey, setSourceStateRefreshKey] = useState(0);
|
||
const workflowEntity = !isTemplate && entity && "projectId" in entity ? (entity as Workflow) : null;
|
||
const workflowProjectId = workflowEntity?.projectId || searchParams.get("projectId") || "";
|
||
const workflowConfigEntity = entity as Workflow | WorkflowTemplate | null;
|
||
const currentExecutionScope = workflowExecutionScope(workflowConfigEntity);
|
||
const hasScanSourceNode = useMemo(() => nodes.some((node) => isScanSourceNode(node)), [nodes]);
|
||
const isScanWorkflow = Boolean(
|
||
workflowConfigEntity?.kind === "scan" || workflowConfigEntity?.scanConfig || hasScanSourceNode,
|
||
);
|
||
const workflowAssetsPath =
|
||
workflowEntity && !isTemplate
|
||
? buildDataAssetsPath({
|
||
tab: isScanWorkflow ? DATA_ASSET_SOURCE_TAB : DATA_ASSET_PACKAGES_TAB,
|
||
projectId: workflowProjectId,
|
||
workflowId: workflowEntity.id,
|
||
workflowName: workflowEntity.name,
|
||
runId: requestedRunId || workflowEntity.lastRunId || "",
|
||
})
|
||
: "";
|
||
const isStreaming = workflowConfigEntity?.type === "streaming";
|
||
const workflowSchedule = normalizeWorkflowSchedule(workflowConfigEntity?.schedule || {});
|
||
const workflowScheduleMode = effectiveWorkflowScheduleMode(workflowConfigEntity?.schedule) || "interval_seconds";
|
||
const standardTriggerMode =
|
||
isStreaming && isWorkflowScheduleEnabled(workflowConfigEntity?.schedule) ? "scheduled" : "manual";
|
||
const scanTriggerMode =
|
||
workflowConfigEntity?.scanConfig?.enabled && isWorkflowScheduleEnabled(workflowConfigEntity?.schedule)
|
||
? "scheduled"
|
||
: "manual";
|
||
const scheduledHistoryEnabled = Boolean(workflowEntity) && isWorkflowScheduleEnabled(workflowConfigEntity?.schedule);
|
||
const workflowLevelHyperparams = useMemo(
|
||
() => (Array.isArray(workflowConfigEntity?.hyperparams) ? workflowConfigEntity.hyperparams : []),
|
||
[workflowConfigEntity?.hyperparams],
|
||
);
|
||
const workflowLevelEnvDuplicates = useMemo(
|
||
() => duplicateWorkflowEnvKeys(workflowLevelHyperparams),
|
||
[workflowLevelHyperparams],
|
||
);
|
||
const activeRunStatus = useMemo(() => getRunDisplayStatus(activeRun), [activeRun]);
|
||
const activeRunInFlight = isRunInFlight(activeRun);
|
||
const gpuStatus = useMemo(() => gpuCapacityStatus(workerCapacity?.gpu), [workerCapacity?.gpu]);
|
||
const selectedNodeRequestsGPU = hasPositiveGPURequest((selectedNode?.data as OperatorNodeData | undefined)?.gpu);
|
||
const selectedNodeGPUBlocked = selectedNodeRequestsGPU && workerCapacity?.gpu && !workerCapacity.gpu.available;
|
||
const workflowGPUCapacityBlocker = useMemo(
|
||
() =>
|
||
getWorkflowGPUCapacityBlocker({
|
||
nodes,
|
||
gpu: workerCapacity?.gpu,
|
||
capacityError: workerCapacityError,
|
||
}),
|
||
[nodes, workerCapacity?.gpu, workerCapacityError],
|
||
);
|
||
const hydrateLoadedEntity = useCallback((loaded: Workflow | WorkflowTemplate) => {
|
||
if (!loaded.nodes?.some((node) => isScanSourceNode(node)) || loaded.scanConfig) {
|
||
return loaded;
|
||
}
|
||
return (applyScanConfigPatchToWorkflow(loaded, {
|
||
enabled:
|
||
Boolean(loaded.scanConfig?.enabled) ||
|
||
(loaded.type === "streaming" && isWorkflowScheduleEnabled(loaded.schedule)),
|
||
...normalizeWorkflowSchedule(loaded.schedule || {}),
|
||
}) ?? loaded) as Workflow | WorkflowTemplate;
|
||
}, []);
|
||
useEffect(() => {
|
||
if (!activeRunInFlight) {
|
||
setRunStopPending("");
|
||
}
|
||
}, [activeRunInFlight]);
|
||
|
||
useEffect(() => {
|
||
if (!isConfigOpen) {
|
||
return undefined;
|
||
}
|
||
|
||
let frame = 0;
|
||
const updateConfigPanelHeight = () => {
|
||
window.cancelAnimationFrame(frame);
|
||
frame = window.requestAnimationFrame(() => {
|
||
const top = configPanelRef.current?.getBoundingClientRect().top ?? 0;
|
||
const nextHeight = Math.max(320, Math.floor(window.innerHeight - top - 24));
|
||
setConfigPanelMaxHeight((current) => (Math.abs(current - nextHeight) > 2 ? nextHeight : current));
|
||
});
|
||
};
|
||
|
||
updateConfigPanelHeight();
|
||
window.addEventListener("resize", updateConfigPanelHeight);
|
||
window.addEventListener("scroll", updateConfigPanelHeight, true);
|
||
|
||
return () => {
|
||
window.cancelAnimationFrame(frame);
|
||
window.removeEventListener("resize", updateConfigPanelHeight);
|
||
window.removeEventListener("scroll", updateConfigPanelHeight, true);
|
||
};
|
||
}, [isConfigOpen]);
|
||
|
||
const workflowSettingsReadOnly = isWorkflowSettingsLocked({
|
||
isReadOnly,
|
||
workflowStatus: workflowEntity?.status,
|
||
activeRunStatus,
|
||
});
|
||
const inputConnectionConflicts = useMemo(() => findInputConnectionConflicts(edges), [edges]);
|
||
const hasInputConnectionConflicts = inputConnectionConflicts.length > 0;
|
||
const workflowGraphValidation = useMemo(() => validateSingleConnectedWorkflowGraph(nodes, edges), [nodes, edges]);
|
||
const hasWorkflowGraphIssue = !workflowGraphValidation.valid;
|
||
const workflowGraphIssueMessage = workflowGraphValidation.issue || invalidGraphFallbackMessage;
|
||
const hasBlockingGraphIssue = hasInputConnectionConflicts || hasWorkflowGraphIssue;
|
||
const blockingGraphIssueMessage = hasInputConnectionConflicts
|
||
? duplicateInputConnectionMessage
|
||
: workflowGraphIssueMessage;
|
||
const prepareEntityForPersistence = useCallback(
|
||
(draft: Workflow | WorkflowTemplate | null) => {
|
||
if (!draft) {
|
||
return draft;
|
||
}
|
||
const next = {
|
||
...draft,
|
||
nodes,
|
||
edges,
|
||
hyperparams: cleanEditableHyperparams(draft.hyperparams),
|
||
};
|
||
if (!nodes.some((node) => isScanSourceNode(node))) {
|
||
return next;
|
||
}
|
||
return applyScanConfigPatchToWorkflow(next, {
|
||
enabled:
|
||
Boolean(draft.scanConfig?.enabled) ||
|
||
(draft.type === "streaming" && isWorkflowScheduleEnabled(draft.schedule)),
|
||
...normalizeWorkflowSchedule(draft.schedule || {}),
|
||
}) as Workflow | WorkflowTemplate;
|
||
},
|
||
[edges, nodes],
|
||
);
|
||
const currentDraftPayload = useMemo(
|
||
() => prepareEntityForPersistence(entity as Workflow | WorkflowTemplate | null),
|
||
[entity, prepareEntityForPersistence],
|
||
);
|
||
const currentDraftFingerprint = useMemo(() => workflowDraftFingerprint(currentDraftPayload), [currentDraftPayload]);
|
||
const scanWorkflowConfigIssue = isScanWorkflow
|
||
? getScanWorkflowConfigIssue({
|
||
...(workflowConfigEntity || {}),
|
||
nodes,
|
||
})
|
||
: "";
|
||
const scanWorkflowConfigReady = !isScanWorkflow || scanWorkflowConfigIssue === "";
|
||
const baseRunAction = getWorkflowRunActionState({
|
||
isTemplate,
|
||
isReadOnly,
|
||
workflowStatus: workflowEntity?.status,
|
||
activeRunStatus,
|
||
isExecuting,
|
||
});
|
||
const runAction =
|
||
!baseRunAction.disabled && hasInputConnectionConflicts
|
||
? {
|
||
disabled: true,
|
||
label: "修复输入连线后再运行",
|
||
reason: "invalidConnections",
|
||
message: duplicateInputConnectionMessage,
|
||
}
|
||
: !baseRunAction.disabled && hasWorkflowGraphIssue
|
||
? {
|
||
disabled: true,
|
||
label: "修复链路后再运行",
|
||
reason: "invalidGraph",
|
||
message: workflowGraphIssueMessage,
|
||
}
|
||
: !baseRunAction.disabled && !scanWorkflowConfigReady
|
||
? {
|
||
disabled: true,
|
||
label: "请先配置扫描源",
|
||
reason: "scanConfig",
|
||
message: scanWorkflowConfigIssue,
|
||
}
|
||
: !baseRunAction.disabled && workflowGPUCapacityBlocker.blocked
|
||
? {
|
||
disabled: true,
|
||
label: "GPU 不可调度",
|
||
reason: workflowGPUCapacityBlocker.reason,
|
||
message: workflowGPUCapacityBlocker.message,
|
||
}
|
||
: baseRunAction;
|
||
|
||
useEffect(() => {
|
||
if (!id) return;
|
||
let cancelled = false;
|
||
editorLoadedRef.current = false;
|
||
setEditorLoadError("");
|
||
const loader = isTemplate ? templatesApi.get(id) : workflowsApi.get(id);
|
||
loader
|
||
.then((loaded) => {
|
||
if (cancelled) {
|
||
return;
|
||
}
|
||
const hydrated = hydrateLoadedEntity(loaded as Workflow | WorkflowTemplate);
|
||
setEntity(hydrated);
|
||
if (isReactFlowNodeArray(hydrated.nodes)) {
|
||
setNodes(hydrated.nodes);
|
||
}
|
||
if (isReactFlowEdgeArray(hydrated.edges)) {
|
||
setEdges(hydrated.edges);
|
||
}
|
||
const normalizedHydrated = {
|
||
...hydrated,
|
||
nodes: hydrated.nodes || [],
|
||
edges: hydrated.edges || [],
|
||
hyperparams: cleanEditableHyperparams(hydrated.hyperparams),
|
||
};
|
||
const serverFingerprint = workflowDraftFingerprint(normalizedHydrated);
|
||
lastSavedFingerprintRef.current = serverFingerprint;
|
||
serverUpdatedAtRef.current = hydrated.updatedAt || "";
|
||
setSaveState("idle");
|
||
setSaveError("");
|
||
const storedDraft = loadWorkflowDraft(window.sessionStorage, { id, kind: draftKind });
|
||
if (storedDraft && workflowDraftFingerprint(storedDraft.payload) !== serverFingerprint) {
|
||
setDraftRecovery({
|
||
payload: storedDraft.payload as Workflow | WorkflowTemplate,
|
||
baseUpdatedAt: storedDraft.baseUpdatedAt,
|
||
savedAt: storedDraft.savedAt,
|
||
conflict: workflowDraftConflicts(storedDraft, hydrated.updatedAt || ""),
|
||
});
|
||
} else {
|
||
removeWorkflowDraft(window.sessionStorage, { id, kind: draftKind });
|
||
setDraftRecovery(null);
|
||
}
|
||
editorLoadedRef.current = true;
|
||
})
|
||
.catch((error) => {
|
||
if (cancelled) {
|
||
return;
|
||
}
|
||
console.error("Failed to load workflow editor entity", error);
|
||
setEditorLoadError(getActionErrorMessage(error, "加载工作流失败"));
|
||
});
|
||
return () => {
|
||
cancelled = true;
|
||
};
|
||
}, [draftKind, editorReloadToken, hydrateLoadedEntity, id, isTemplate, setEdges, setNodes]);
|
||
|
||
useEffect(() => {
|
||
if (!editorLoadedRef.current || isReadOnly || !canManage || !id || !currentDraftPayload) {
|
||
return undefined;
|
||
}
|
||
if (draftRecovery) {
|
||
return undefined;
|
||
}
|
||
const dirty = currentDraftFingerprint !== lastSavedFingerprintRef.current;
|
||
if (!dirty) {
|
||
removeWorkflowDraft(window.sessionStorage, { id, kind: draftKind });
|
||
setSaveState((current) => (current === "saving" || current === "saved" ? current : "idle"));
|
||
return undefined;
|
||
}
|
||
setSaveState((current) => (current === "saving" ? current : "dirty"));
|
||
setSaveError("");
|
||
const timer = window.setTimeout(() => {
|
||
saveWorkflowDraft(window.sessionStorage, {
|
||
id,
|
||
kind: draftKind,
|
||
baseUpdatedAt: serverUpdatedAtRef.current,
|
||
payload: currentDraftPayload,
|
||
});
|
||
}, 600);
|
||
return () => window.clearTimeout(timer);
|
||
}, [canManage, currentDraftFingerprint, currentDraftPayload, draftKind, draftRecovery, id, isReadOnly]);
|
||
|
||
useEffect(() => {
|
||
const hasUnsavedWork = saveState === "dirty" || saveState === "saving" || saveState === "error";
|
||
if (!hasUnsavedWork) {
|
||
return undefined;
|
||
}
|
||
const handleBeforeUnload = (event: BeforeUnloadEvent) => {
|
||
event.preventDefault();
|
||
event.returnValue = "";
|
||
};
|
||
window.addEventListener("beforeunload", handleBeforeUnload);
|
||
return () => window.removeEventListener("beforeunload", handleBeforeUnload);
|
||
}, [saveState]);
|
||
|
||
const restoreStoredDraft = useCallback(() => {
|
||
if (!draftRecovery) {
|
||
return;
|
||
}
|
||
const restored = hydrateLoadedEntity(draftRecovery.payload);
|
||
setEntity(restored);
|
||
if (isReactFlowNodeArray(restored.nodes)) {
|
||
setNodes(restored.nodes);
|
||
}
|
||
if (isReactFlowEdgeArray(restored.edges)) {
|
||
setEdges(restored.edges);
|
||
}
|
||
setDraftRecovery(null);
|
||
setSaveState("dirty");
|
||
setCanvasNotice(
|
||
draftRecovery.conflict ? "已恢复本地草稿;服务器版本有更新,请保存或另存后再运行。" : "已恢复本地草稿",
|
||
);
|
||
}, [draftRecovery, hydrateLoadedEntity, setEdges, setNodes]);
|
||
|
||
const discardStoredDraft = useCallback(() => {
|
||
if (!id) {
|
||
return;
|
||
}
|
||
removeWorkflowDraft(window.sessionStorage, { id, kind: draftKind });
|
||
setDraftRecovery(null);
|
||
setCanvasNotice("已保留服务器版本并丢弃本地草稿");
|
||
}, [draftKind, id]);
|
||
|
||
const saveStoredDraftAsCopy = useCallback(async () => {
|
||
if (!draftRecovery || !id || isSavingDraftCopy) {
|
||
return;
|
||
}
|
||
setIsSavingDraftCopy(true);
|
||
setSaveError("");
|
||
try {
|
||
const source = draftRecovery.payload;
|
||
const copyName = `${source.name || "未命名"}(本地草稿)`;
|
||
let created: Workflow | WorkflowTemplate;
|
||
if (isTemplate) {
|
||
created = await templatesApi.create({
|
||
...source,
|
||
id: undefined,
|
||
name: copyName,
|
||
createdAt: undefined,
|
||
updatedAt: undefined,
|
||
});
|
||
} else {
|
||
if (!workflowProjectId) {
|
||
throw new Error("当前工作流缺少项目 ID,无法另存草稿");
|
||
}
|
||
created = await projectsApi.createWorkflow(workflowProjectId, {
|
||
...source,
|
||
id: undefined,
|
||
name: copyName,
|
||
status: "draft",
|
||
lastRunId: undefined,
|
||
lastRunAt: undefined,
|
||
createdAt: undefined,
|
||
updatedAt: undefined,
|
||
});
|
||
}
|
||
removeWorkflowDraft(window.sessionStorage, { id, kind: draftKind });
|
||
setDraftRecovery(null);
|
||
navigate(
|
||
isTemplate
|
||
? `/workflow/${created.id}?type=template`
|
||
: `/workflow/${created.id}?projectId=${encodeURIComponent(workflowProjectId)}`,
|
||
);
|
||
} catch (error) {
|
||
console.error("Failed to save local workflow draft as copy", error);
|
||
setSaveError(getActionErrorMessage(error, "另存本地草稿失败"));
|
||
} finally {
|
||
setIsSavingDraftCopy(false);
|
||
}
|
||
}, [draftKind, draftRecovery, id, isSavingDraftCopy, isTemplate, navigate, workflowProjectId]);
|
||
|
||
const persistCurrentEditorEntity = useCallback(async () => {
|
||
if (isReadOnly || !canManage || !id || !entity) {
|
||
return null;
|
||
}
|
||
if (hasBlockingGraphIssue) {
|
||
setCanvasNotice(blockingGraphIssueMessage);
|
||
return null;
|
||
}
|
||
if (workflowLevelEnvDuplicates.size > 0) {
|
||
setCanvasNotice("工作流级环境变量存在重复 key,请先去重后再保存。");
|
||
return null;
|
||
}
|
||
const payload = prepareEntityForPersistence(entity as Workflow | WorkflowTemplate);
|
||
const payloadIssue = getScanWorkflowDraftIssue(payload);
|
||
if (payloadIssue) {
|
||
setCanvasNotice(payloadIssue);
|
||
return null;
|
||
}
|
||
|
||
setSaveState("saving");
|
||
setSaveError("");
|
||
try {
|
||
const latest = isTemplate ? await templatesApi.get(id) : await workflowsApi.get(id);
|
||
if (serverUpdatedAtRef.current && latest.updatedAt && latest.updatedAt !== serverUpdatedAtRef.current) {
|
||
const draftBaseUpdatedAt = serverUpdatedAtRef.current;
|
||
saveWorkflowDraft(window.sessionStorage, {
|
||
id,
|
||
kind: draftKind,
|
||
baseUpdatedAt: draftBaseUpdatedAt,
|
||
payload,
|
||
});
|
||
const hydratedLatest = hydrateLoadedEntity(latest as Workflow | WorkflowTemplate);
|
||
setEntity(hydratedLatest);
|
||
setNodes(isReactFlowNodeArray(hydratedLatest.nodes) ? hydratedLatest.nodes : []);
|
||
setEdges(isReactFlowEdgeArray(hydratedLatest.edges) ? hydratedLatest.edges : []);
|
||
lastSavedFingerprintRef.current = workflowDraftFingerprint({
|
||
...hydratedLatest,
|
||
nodes: hydratedLatest.nodes || [],
|
||
edges: hydratedLatest.edges || [],
|
||
hyperparams: cleanEditableHyperparams(hydratedLatest.hyperparams),
|
||
});
|
||
serverUpdatedAtRef.current = hydratedLatest.updatedAt || "";
|
||
setDraftRecovery({
|
||
payload,
|
||
baseUpdatedAt: draftBaseUpdatedAt,
|
||
savedAt: new Date().toISOString(),
|
||
conflict: true,
|
||
});
|
||
setSaveState("idle");
|
||
setCanvasNotice("服务器版本已变化,已停止覆盖;请选择恢复本地草稿、保留服务器版本或另存副本。");
|
||
return null;
|
||
}
|
||
const updated = isTemplate
|
||
? await templatesApi.update(id, payload as Partial<WorkflowTemplate>)
|
||
: await workflowsApi.update(id, { ...(payload as Workflow) });
|
||
setEntity(updated);
|
||
const persistedPayload = prepareEntityForPersistence(updated as Workflow | WorkflowTemplate) || updated;
|
||
lastSavedFingerprintRef.current = workflowDraftFingerprint(persistedPayload);
|
||
serverUpdatedAtRef.current = updated.updatedAt || "";
|
||
removeWorkflowDraft(window.sessionStorage, { id, kind: draftKind });
|
||
setDraftRecovery(null);
|
||
setSaveState("saved");
|
||
return updated;
|
||
} catch (error) {
|
||
const message = getActionErrorMessage(error, "保存失败,请稍后重试");
|
||
setSaveState("error");
|
||
setSaveError(message);
|
||
throw error;
|
||
}
|
||
}, [
|
||
blockingGraphIssueMessage,
|
||
canManage,
|
||
draftKind,
|
||
entity,
|
||
hasBlockingGraphIssue,
|
||
hydrateLoadedEntity,
|
||
id,
|
||
isReadOnly,
|
||
isTemplate,
|
||
prepareEntityForPersistence,
|
||
setEdges,
|
||
setNodes,
|
||
workflowLevelEnvDuplicates,
|
||
]);
|
||
|
||
useEffect(() => {
|
||
operatorsApi
|
||
.list()
|
||
.then(setOperators)
|
||
.catch((error) => {
|
||
console.error("Failed to load operators", error);
|
||
setOperators([]);
|
||
});
|
||
}, []);
|
||
|
||
useEffect(() => {
|
||
workerApi
|
||
.capacity()
|
||
.then((loaded) => {
|
||
setWorkerCapacity(loaded);
|
||
setWorkerCapacityError("");
|
||
})
|
||
.catch((error) => {
|
||
console.error("Failed to load worker capacity", error);
|
||
setWorkerCapacity(null);
|
||
setWorkerCapacityError(getActionErrorMessage(error, "加载 Worker 调度能力失败"));
|
||
});
|
||
}, []);
|
||
|
||
const focusNodeConfigInput = useCallback(() => {
|
||
let attempts = 0;
|
||
const tryFocus = () => {
|
||
const firstField = document.querySelector(
|
||
".node-config-panel input, .node-config-panel select, .node-config-panel textarea",
|
||
);
|
||
if (firstField instanceof HTMLInputElement) {
|
||
firstField.focus();
|
||
firstField.select();
|
||
return;
|
||
}
|
||
if (firstField instanceof HTMLSelectElement || firstField instanceof HTMLTextAreaElement) {
|
||
firstField.focus();
|
||
return;
|
||
}
|
||
attempts += 1;
|
||
if (attempts < 12) {
|
||
window.setTimeout(tryFocus, 50);
|
||
}
|
||
};
|
||
window.setTimeout(tryFocus, 0);
|
||
}, []);
|
||
|
||
useEffect(() => {
|
||
if (autoFocusHandledRef.current || !requestedFocusNodeId || nodes.length === 0) {
|
||
return;
|
||
}
|
||
const targetNode = nodes.find((node) => node.id === requestedFocusNodeId);
|
||
if (!targetNode) {
|
||
return;
|
||
}
|
||
autoFocusHandledRef.current = true;
|
||
setSelectedNode(targetNode);
|
||
setSelectedEdgeId("");
|
||
if (requestedOpenConfigPanel) {
|
||
setIsConfigOpen(true);
|
||
focusNodeConfigInput();
|
||
}
|
||
const nextParams = new URLSearchParams(searchParams);
|
||
nextParams.delete("focusNodeId");
|
||
nextParams.delete("openConfigPanel");
|
||
setSearchParams(nextParams, { replace: true });
|
||
}, [focusNodeConfigInput, nodes, requestedFocusNodeId, requestedOpenConfigPanel, searchParams, setSearchParams]);
|
||
|
||
useEffect(() => {
|
||
if (!selectedEdgeId) {
|
||
return;
|
||
}
|
||
if (edges.some((edge) => edge.id === selectedEdgeId)) {
|
||
return;
|
||
}
|
||
setSelectedEdgeId("");
|
||
}, [edges, selectedEdgeId]);
|
||
|
||
const loadStorageConnections = useCallback(() => {
|
||
setIsStorageConnectionsLoading(true);
|
||
setStorageConnectionsError("");
|
||
return storageConnectionsApi
|
||
.list()
|
||
.then((items) => {
|
||
setStorageConnections(items);
|
||
})
|
||
.catch((error) => {
|
||
console.error("Failed to load storage connections", error);
|
||
setStorageConnections([]);
|
||
setStorageConnectionsError(getActionErrorMessage(error, "加载存储连接失败"));
|
||
})
|
||
.finally(() => {
|
||
setIsStorageConnectionsLoading(false);
|
||
});
|
||
}, []);
|
||
|
||
useEffect(() => {
|
||
loadStorageConnections();
|
||
}, [loadStorageConnections]);
|
||
|
||
const loadMongoConnections = useCallback(() => {
|
||
setIsMongoConnectionsLoading(true);
|
||
setMongoConnectionsError("");
|
||
return mongoConnectionsApi
|
||
.list()
|
||
.then((items) => {
|
||
setMongoConnections(items);
|
||
})
|
||
.catch((error) => {
|
||
console.error("Failed to load mongo connections", error);
|
||
setMongoConnections([]);
|
||
setMongoConnectionsError(getActionErrorMessage(error, "加载 MongoDB 连接失败"));
|
||
})
|
||
.finally(() => {
|
||
setIsMongoConnectionsLoading(false);
|
||
});
|
||
}, []);
|
||
|
||
useEffect(() => {
|
||
loadMongoConnections();
|
||
}, [loadMongoConnections]);
|
||
|
||
const normalizedOperatorSearch = operatorSearchQuery.trim().toLowerCase();
|
||
const filteredOperators = operators.filter((operator) => {
|
||
if (!normalizedOperatorSearch) {
|
||
return true;
|
||
}
|
||
return [operator.name, operator.description, operator.category, operator.type]
|
||
.filter(Boolean)
|
||
.some((value) => value.toLowerCase().includes(normalizedOperatorSearch));
|
||
});
|
||
const operatorLibrarySections = useMemo(() => getOperatorLibrarySections(filteredOperators), [filteredOperators]);
|
||
|
||
const displayNodes = useMemo(() => decorateWorkflowNodes(nodes, activeRun), [nodes, activeRun]);
|
||
const displayEdges = useMemo(() => {
|
||
const nodeLabelById = new Map(nodes.map((node) => [node.id, node.data?.label || node.id]));
|
||
return decorateWorkflowEdges(edges, nodes, activeRun).map((edge) => {
|
||
const sourceLabel = nodeLabelById.get(edge.source) || edge.source;
|
||
const targetLabel = nodeLabelById.get(edge.target) || edge.target;
|
||
const baseEdge = {
|
||
...edge,
|
||
ariaLabel: `${sourceLabel} 到 ${targetLabel} 连线`,
|
||
};
|
||
if (edge.id !== selectedEdgeId) {
|
||
return baseEdge;
|
||
}
|
||
return {
|
||
...baseEdge,
|
||
style: {
|
||
...edge.style,
|
||
strokeWidth: Math.max(Number(edge.style?.strokeWidth || 1.5), 3.5),
|
||
filter: "drop-shadow(0 0 8px rgba(96,165,250,0.45))",
|
||
},
|
||
};
|
||
});
|
||
}, [activeRun, edges, nodes, selectedEdgeId]);
|
||
const selectedEdge = useMemo<Edge | null>(
|
||
() =>
|
||
displayEdges.find((edge) => edge.id === selectedEdgeId) ||
|
||
edges.find((edge) => edge.id === selectedEdgeId) ||
|
||
null,
|
||
[displayEdges, edges, selectedEdgeId],
|
||
);
|
||
const selectedEdgeSourceNode = useMemo(
|
||
() => nodes.find((node) => node.id === selectedEdge?.source) || null,
|
||
[nodes, selectedEdge?.source],
|
||
);
|
||
const selectedEdgeTargetNode = useMemo(
|
||
() => nodes.find((node) => node.id === selectedEdge?.target) || null,
|
||
[nodes, selectedEdge?.target],
|
||
);
|
||
const selectedEdgeOutputPort = useMemo(() => {
|
||
const sourceHandle = String(selectedEdge?.sourceHandle || "").trim();
|
||
if (!sourceHandle) {
|
||
return null;
|
||
}
|
||
return findNodePort(selectedEdgeSourceNode, "outputs", sourceHandle);
|
||
}, [selectedEdge?.sourceHandle, selectedEdgeSourceNode]);
|
||
const selectedEdgeArtifacts = useMemo<ExecutionData[]>(
|
||
() => getEdgeOutputArtifacts(selectedEdge, activeRun, nodes),
|
||
[activeRun, nodes, selectedEdge],
|
||
);
|
||
const selectedEdgeExecutionState = String(selectedEdge?.data?.executionState || "").trim() || "idle";
|
||
const selectedEdgeArtifact = useMemo(
|
||
() =>
|
||
selectedEdgeArtifacts.find((artifact) => artifact.id === selectedEdgeArtifactId) ||
|
||
selectedEdgeArtifacts[0] ||
|
||
null,
|
||
[selectedEdgeArtifactId, selectedEdgeArtifacts],
|
||
);
|
||
useEffect(() => {
|
||
if (!selectedEdge || selectedEdgeArtifacts.length === 0) {
|
||
setSelectedEdgeArtifactId("");
|
||
return;
|
||
}
|
||
if (selectedEdgeArtifactId && selectedEdgeArtifacts.some((artifact) => artifact.id === selectedEdgeArtifactId)) {
|
||
return;
|
||
}
|
||
setSelectedEdgeArtifactId(selectedEdgeArtifacts[0].id);
|
||
}, [selectedEdge, selectedEdgeArtifactId, selectedEdgeArtifacts]);
|
||
useEffect(() => {
|
||
if (!selectedEdgeArtifact) {
|
||
setIsOutputPreviewFullscreen(false);
|
||
}
|
||
}, [selectedEdgeArtifact]);
|
||
useEffect(() => {
|
||
if (!isOutputPreviewFullscreen) {
|
||
return;
|
||
}
|
||
const closeOnEscape = (event: KeyboardEvent) => {
|
||
if (event.key === "Escape") {
|
||
setIsOutputPreviewFullscreen(false);
|
||
}
|
||
};
|
||
window.addEventListener("keydown", closeOnEscape);
|
||
return () => {
|
||
window.removeEventListener("keydown", closeOnEscape);
|
||
};
|
||
}, [isOutputPreviewFullscreen]);
|
||
const selectedEdgeSourceLabel = selectedEdgeSourceNode?.data?.label || selectedEdge?.source || "上游节点";
|
||
const selectedEdgeTargetLabel = selectedEdgeTargetNode?.data?.label || selectedEdge?.target || "下游节点";
|
||
const selectedEdgePortLabel =
|
||
String(selectedEdgeOutputPort?.name || selectedEdge?.sourceHandle || "").trim() || "默认输出";
|
||
const selectedEdgeEmptyStateMessage = useMemo(() => {
|
||
if (!selectedEdge) {
|
||
return "";
|
||
}
|
||
if (!activeRun?.id) {
|
||
return "当前没有已加载的运行上下文。重新打开最近一次执行过的工作流,或先运行一次工作流后再查看这条连线。";
|
||
}
|
||
if (selectedEdgeExecutionState === "running") {
|
||
return "上游节点已经产出该连线的数据,下游节点仍在处理,当前端口暂时还没有更多可预览内容。";
|
||
}
|
||
if (selectedEdgeExecutionState === "waiting_for_audit") {
|
||
return "上游节点已经产出该连线的数据,当前流程停在人工审核,待审核后可继续观察下游消费结果。";
|
||
}
|
||
if (selectedEdgeExecutionState === "failed") {
|
||
return "当前工作流已失败,这条连线没有留下可预览的输出文件。通常表示上游节点未成功产出或失败发生在这条连线之前。";
|
||
}
|
||
if (selectedEdgeExecutionState === "completed") {
|
||
return "当前工作流已完成,但没有检索到这条连线对应端口的输出文件。请检查上游端口映射或算子是否实际产出 artifact。";
|
||
}
|
||
return "当前运行还没有经过这条连线,待上游节点执行并产出数据后,这里会显示该线的输出文件。";
|
||
}, [activeRun?.id, selectedEdge, selectedEdgeExecutionState]);
|
||
const selectedNodeExecution = useMemo(
|
||
() => activeRun?.nodeExecutions?.find((execution) => execution.nodeId === selectedNode?.id) || null,
|
||
[activeRun?.nodeExecutions, selectedNode?.id],
|
||
);
|
||
const selectedNodeLogs = useMemo(
|
||
() =>
|
||
selectNodeRunLogs(liveRunLogs, {
|
||
nodeId: selectedNode?.id || "",
|
||
nodeLabel: selectedNodeExecution?.nodeLabel || String(selectedNode?.data?.label || ""),
|
||
fallback: selectedNodeExecution?.logs || [],
|
||
}),
|
||
[
|
||
liveRunLogs,
|
||
selectedNode?.data?.label,
|
||
selectedNode?.id,
|
||
selectedNodeExecution?.logs,
|
||
selectedNodeExecution?.nodeLabel,
|
||
],
|
||
);
|
||
const selectedNodeRuntime = useMemo(
|
||
() => summarizeNodeRuntime(activeRun, selectedNodeExecution, selectedNodeLogs),
|
||
[activeRun, selectedNodeExecution, selectedNodeLogs],
|
||
);
|
||
const selectedNodeLatestResource = selectedNodeExecution?.resourceSeries?.length
|
||
? selectedNodeExecution.resourceSeries[selectedNodeExecution.resourceSeries.length - 1]
|
||
: null;
|
||
const selectedNodeExecutionState = getNodeExecutionState(activeRun, selectedNode?.id);
|
||
const selectedLightweightRuntime = useMemo(
|
||
() => getLightweightOperatorRuntime(selectedNode?.data as OperatorNodeData | undefined),
|
||
[selectedNode?.data?.runtimeContract],
|
||
);
|
||
const selectedLightweightManifest = useMemo(() => {
|
||
const nodeId = selectedNode?.id || "";
|
||
if (!nodeId) {
|
||
return null;
|
||
}
|
||
return activeRun?.metadata?.lightweightOperatorCodeManifests?.[nodeId] || null;
|
||
}, [activeRun?.metadata?.lightweightOperatorCodeManifests, selectedNode?.id]);
|
||
const selectedLightweightOperatorId = (selectedNode?.data as OperatorNodeData | undefined)?.operatorId || "";
|
||
const selectedLightweightCommand = (selectedNode?.data as OperatorNodeData | undefined)?.containerCommand || [];
|
||
const selectedLightweightArgs = (selectedNode?.data as OperatorNodeData | undefined)?.containerArgs || [];
|
||
useEffect(() => {
|
||
setNodeConfigPanelTab("config");
|
||
}, [selectedNode?.id]);
|
||
useEffect(() => {
|
||
setLiveRunLogs([]);
|
||
setLiveRunLogsError("");
|
||
setLiveRunLogsUpdatedAt("");
|
||
}, [activeRun?.id, selectedNode?.id]);
|
||
useEffect(() => {
|
||
if (nodeConfigPanelTab !== "logs" || !nodeLogsPanelRef.current || !nodeLogsFollowRef.current) {
|
||
return;
|
||
}
|
||
nodeLogsPanelRef.current.scrollTop = nodeLogsPanelRef.current.scrollHeight;
|
||
}, [selectedNodeLogs.length]);
|
||
useEffect(() => {
|
||
if (nodeConfigPanelTab !== "logs" || !nodeLogsPanelRef.current) {
|
||
return;
|
||
}
|
||
nodeLogsFollowRef.current = true;
|
||
nodeLogsPanelRef.current.scrollTop = nodeLogsPanelRef.current.scrollHeight;
|
||
}, [nodeConfigPanelTab, selectedNode?.id]);
|
||
useEffect(() => {
|
||
if (!selectedLightweightRuntime.enabled) {
|
||
setIsLightweightCodeEditorFullscreen(false);
|
||
}
|
||
}, [selectedLightweightRuntime.enabled, selectedNode?.id]);
|
||
useEffect(() => {
|
||
if (!isLightweightCodeEditorFullscreen) {
|
||
return;
|
||
}
|
||
const closeOnEscape = (event: KeyboardEvent) => {
|
||
if (event.key === "Escape") {
|
||
setIsLightweightCodeEditorFullscreen(false);
|
||
}
|
||
};
|
||
window.addEventListener("keydown", closeOnEscape);
|
||
return () => {
|
||
window.removeEventListener("keydown", closeOnEscape);
|
||
};
|
||
}, [isLightweightCodeEditorFullscreen]);
|
||
const isSelectedScanSourceNode =
|
||
Boolean(workflowEntity) && !isTemplate && isScanWorkflow && isScanSourceNode(selectedNode);
|
||
const refreshSourceState = useCallback(() => {
|
||
setSourceStateRefreshKey((current) => current + 1);
|
||
}, []);
|
||
const scanStorageConnection = useMemo(() => {
|
||
const connectionId = workflowConfigEntity?.scanConfig?.connectionId?.trim();
|
||
if (!connectionId) {
|
||
return null;
|
||
}
|
||
return storageConnections.find((item) => item.id === connectionId) || null;
|
||
}, [storageConnections, workflowConfigEntity?.scanConfig?.connectionId]);
|
||
const selectedNodeStorageScope =
|
||
isScanWorkflow && isScanSourceNode(selectedNode) ? "scan" : isOssNode(selectedNode) ? "node" : null;
|
||
const nodeStorageConnection = useMemo(() => {
|
||
const connectionId = String(selectedNode?.data?.connectionId || "").trim();
|
||
if (!connectionId) {
|
||
return null;
|
||
}
|
||
return storageConnections.find((item) => item.id === connectionId) || null;
|
||
}, [selectedNode?.data?.connectionId, storageConnections]);
|
||
const selectedNodeMongoConnectionId = getNodeHyperparamValue(selectedNode, "MONGO_CONNECTION_ID");
|
||
const selectedNodeMongoConnection = useMemo(() => {
|
||
if (!selectedNodeMongoConnectionId) {
|
||
return null;
|
||
}
|
||
return mongoConnections.find((item) => item.id === selectedNodeMongoConnectionId) || null;
|
||
}, [mongoConnections, selectedNodeMongoConnectionId]);
|
||
const shouldIncludeScheduledRunTimestamps = useMemo(() => {
|
||
if (activeRun?.id) {
|
||
return activeRun.trigger === "scheduled";
|
||
}
|
||
return scheduledHistoryEnabled;
|
||
}, [activeRun?.id, activeRun?.trigger, scheduledHistoryEnabled]);
|
||
const selectedNodeEnvRows = useMemo(() => {
|
||
const systemRows =
|
||
selectedNode?.type === "operator" && shouldIncludeScheduledRunTimestamps
|
||
? buildWorkflowSystemEnvVarsPreview({
|
||
workflowLastRunAt: workflowEntity?.lastRunAt || "",
|
||
run: activeRun,
|
||
includePrevious: true,
|
||
includeCurrent: true,
|
||
})
|
||
: [];
|
||
return buildSelectedNodeEnvRows({
|
||
nodeHyperparams: selectedNode?.data?.hyperparams,
|
||
workflowHyperparams: workflowLevelHyperparams,
|
||
systemRows,
|
||
});
|
||
}, [
|
||
activeRun,
|
||
selectedNode?.data?.hyperparams,
|
||
selectedNode?.type,
|
||
shouldIncludeScheduledRunTimestamps,
|
||
workflowLevelHyperparams,
|
||
workflowEntity?.lastRunAt,
|
||
]);
|
||
const selectedNodeIds = useMemo(() => nodes.filter((node) => node.selected).map((node) => node.id), [nodes]);
|
||
const selectedEdgeIds = useMemo(() => edges.filter((edge) => edge.selected).map((edge) => edge.id), [edges]);
|
||
const hasCanvasSelection = selectedNodeIds.length > 0 || selectedEdgeIds.length > 0;
|
||
const activeRunCurrentNodeLabel = useMemo(() => getCurrentNodeLabel(activeRun, nodes), [activeRun, nodes]);
|
||
const activeHoloBrainSummary = useMemo(() => summarizeHoloBrainRun(activeRun, nodes), [activeRun, nodes]);
|
||
|
||
useEffect(() => {
|
||
if (!id || isTemplate || !workflowEntity?.id || !selectedNode?.id || !isSelectedScanSourceNode) {
|
||
setSourceState(null);
|
||
setSourceStateError("");
|
||
setIsSourceStateLoading(false);
|
||
return;
|
||
}
|
||
let cancelled = false;
|
||
setIsSourceStateLoading(true);
|
||
setSourceStateError("");
|
||
workflowsApi
|
||
.getSourceState(id, selectedNode.id)
|
||
.then((payload) => {
|
||
if (cancelled) {
|
||
return;
|
||
}
|
||
setSourceState(payload);
|
||
})
|
||
.catch((error) => {
|
||
if (cancelled) {
|
||
return;
|
||
}
|
||
console.error("Failed to load source state", error);
|
||
setSourceState(null);
|
||
setSourceStateError(getActionErrorMessage(error, "加载扫描状态失败"));
|
||
})
|
||
.finally(() => {
|
||
if (!cancelled) {
|
||
setIsSourceStateLoading(false);
|
||
}
|
||
});
|
||
return () => {
|
||
cancelled = true;
|
||
};
|
||
}, [
|
||
id,
|
||
isSelectedScanSourceNode,
|
||
isTemplate,
|
||
selectedNode?.id,
|
||
sourceStateRefreshKey,
|
||
workflowEntity?.id,
|
||
workflowEntity?.updatedAt,
|
||
]);
|
||
|
||
useEffect(() => {
|
||
if (!isSelectedScanSourceNode || !activeRun?.id) {
|
||
return;
|
||
}
|
||
if (activeRunStatus === "completed" || activeRunStatus === "failed" || activeRunStatus === "cancelled") {
|
||
refreshSourceState();
|
||
}
|
||
}, [activeRun?.endedAt, activeRun?.id, activeRunStatus, isSelectedScanSourceNode, refreshSourceState]);
|
||
|
||
useEffect(() => {
|
||
setActiveRun(null);
|
||
setActiveRunError("");
|
||
setCanvasNotice("");
|
||
setIsWorkflowSettingsOpen(false);
|
||
}, [id]);
|
||
|
||
useEffect(() => {
|
||
if (!canvasNotice) {
|
||
return;
|
||
}
|
||
const timer = window.setTimeout(() => setCanvasNotice(""), 3000);
|
||
return () => window.clearTimeout(timer);
|
||
}, [canvasNotice]);
|
||
|
||
useEffect(() => {
|
||
if (!isWorkflowSettingsOpen) {
|
||
return;
|
||
}
|
||
|
||
const handlePointerDown = (event: MouseEvent) => {
|
||
const target = event.target as HTMLElement | null;
|
||
if (workflowSettingsPanelRef.current?.contains(target) || workflowSettingsTriggerRef.current?.contains(target)) {
|
||
return;
|
||
}
|
||
setIsWorkflowSettingsOpen(false);
|
||
};
|
||
|
||
document.addEventListener("mousedown", handlePointerDown);
|
||
return () => {
|
||
document.removeEventListener("mousedown", handlePointerDown);
|
||
};
|
||
}, [isWorkflowSettingsOpen]);
|
||
|
||
useEffect(() => {
|
||
if (isTemplate || !entity || !id) {
|
||
return;
|
||
}
|
||
|
||
const trackedRunId = getTrackedRunId(requestedRunId, entity);
|
||
if (!trackedRunId || activeRun?.id === trackedRunId) {
|
||
return;
|
||
}
|
||
|
||
let cancelled = false;
|
||
|
||
monitoringApi
|
||
.getRun(trackedRunId)
|
||
.then((run) => {
|
||
if (cancelled || run.workflowId !== id) {
|
||
return;
|
||
}
|
||
setActiveRun(run);
|
||
setActiveRunError("");
|
||
})
|
||
.catch((error) => {
|
||
if (cancelled) {
|
||
return;
|
||
}
|
||
console.error("Failed to restore workflow run context", error);
|
||
setActiveRunError(getActionErrorMessage(error, "无法恢复当前工作流运行状态"));
|
||
});
|
||
|
||
return () => {
|
||
cancelled = true;
|
||
};
|
||
}, [activeRun?.id, entity, id, isTemplate, requestedRunId]);
|
||
|
||
const updateRunSearchParam = useCallback(
|
||
(runId: string) => {
|
||
const nextParams = new URLSearchParams(searchParams);
|
||
if (runId.trim()) {
|
||
nextParams.set("runId", runId.trim());
|
||
} else {
|
||
nextParams.delete("runId");
|
||
}
|
||
setSearchParams(nextParams, { replace: true });
|
||
},
|
||
[searchParams, setSearchParams],
|
||
);
|
||
|
||
const loadWorkflowRuns = useCallback(async () => {
|
||
if (!id || isTemplate || !scheduledHistoryEnabled) {
|
||
setWorkflowRuns([]);
|
||
setWorkflowRunsError("");
|
||
return;
|
||
}
|
||
setIsWorkflowRunsLoading(true);
|
||
setWorkflowRunsError("");
|
||
try {
|
||
const items = await workflowsApi.listRuns(id);
|
||
setWorkflowRuns(items);
|
||
} catch (error) {
|
||
console.error("Failed to load workflow runs", error);
|
||
setWorkflowRunsError(getActionErrorMessage(error, "无法加载周期运行记录"));
|
||
} finally {
|
||
setIsWorkflowRunsLoading(false);
|
||
}
|
||
}, [id, isTemplate, scheduledHistoryEnabled]);
|
||
|
||
const handleSelectWorkflowRun = useCallback(
|
||
async (runId: string) => {
|
||
if (!runId.trim()) {
|
||
return;
|
||
}
|
||
try {
|
||
const run = await monitoringApi.getRun(runId);
|
||
if (id && run.workflowId !== id) {
|
||
return;
|
||
}
|
||
setActiveRun(run);
|
||
setActiveRunError("");
|
||
updateRunSearchParam(run.id);
|
||
} catch (error) {
|
||
console.error("Failed to load workflow run", error);
|
||
setActiveRunError(getActionErrorMessage(error, "无法加载该次运行详情"));
|
||
}
|
||
},
|
||
[id, updateRunSearchParam],
|
||
);
|
||
|
||
useEffect(() => {
|
||
if (!isRunHistoryOpen) {
|
||
return;
|
||
}
|
||
void loadWorkflowRuns();
|
||
}, [isRunHistoryOpen, loadWorkflowRuns]);
|
||
|
||
useEffect(() => {
|
||
if (!activeRun?.id || !activeRunInFlight) {
|
||
return;
|
||
}
|
||
|
||
let cancelled = false;
|
||
let timer = 0;
|
||
let failureCount = 0;
|
||
let controller: AbortController | null = null;
|
||
|
||
const baseDelay = activeRunStatus === "waiting_for_audit" ? 12000 : activeRunStatus === "running" ? 8000 : 10000;
|
||
|
||
const scheduleRefresh = () => {
|
||
window.clearTimeout(timer);
|
||
if (!cancelled && document.visibilityState === "visible") {
|
||
const nextDelay = Math.min(baseDelay * Math.max(1, 2 ** failureCount), 30000);
|
||
timer = window.setTimeout(refreshRun, nextDelay);
|
||
}
|
||
};
|
||
|
||
const refreshRun = async () => {
|
||
if (cancelled || document.visibilityState !== "visible") {
|
||
return;
|
||
}
|
||
controller?.abort();
|
||
controller = new AbortController();
|
||
try {
|
||
const latest = await monitoringApi.getRun(activeRun.id, controller.signal);
|
||
if (cancelled) {
|
||
return;
|
||
}
|
||
setActiveRun(latest);
|
||
setActiveRunError("");
|
||
failureCount = 0;
|
||
} catch (error) {
|
||
if (cancelled || (error as Error)?.name === "AbortError") {
|
||
return;
|
||
}
|
||
console.error("Failed to refresh workflow run status", error);
|
||
setActiveRunError(getActionErrorMessage(error, "无法刷新当前工作流运行状态"));
|
||
failureCount += 1;
|
||
} finally {
|
||
scheduleRefresh();
|
||
}
|
||
};
|
||
|
||
const handleVisibilityChange = () => {
|
||
window.clearTimeout(timer);
|
||
if (document.visibilityState === "hidden") {
|
||
controller?.abort();
|
||
return;
|
||
}
|
||
void refreshRun();
|
||
};
|
||
|
||
timer = window.setTimeout(refreshRun, baseDelay);
|
||
document.addEventListener("visibilitychange", handleVisibilityChange);
|
||
return () => {
|
||
cancelled = true;
|
||
window.clearTimeout(timer);
|
||
controller?.abort();
|
||
document.removeEventListener("visibilitychange", handleVisibilityChange);
|
||
};
|
||
}, [activeRun?.id, activeRunInFlight, activeRunStatus]);
|
||
|
||
useEffect(() => {
|
||
if (!activeRun?.id || !selectedNode?.id || nodeConfigPanelTab === "config") {
|
||
return;
|
||
}
|
||
|
||
let cancelled = false;
|
||
let timer = 0;
|
||
let controller: AbortController | null = null;
|
||
|
||
const refreshLogs = async () => {
|
||
if (cancelled || document.visibilityState !== "visible") {
|
||
return;
|
||
}
|
||
controller?.abort();
|
||
controller = new AbortController();
|
||
setIsLiveRunLogsLoading(true);
|
||
try {
|
||
const logs = await monitoringApi.getLogs(activeRun.id, controller.signal);
|
||
if (cancelled) {
|
||
return;
|
||
}
|
||
setLiveRunLogs(logs);
|
||
setLiveRunLogsError("");
|
||
setLiveRunLogsUpdatedAt(new Date().toISOString());
|
||
} catch (error) {
|
||
if (cancelled || (error as Error)?.name === "AbortError") {
|
||
return;
|
||
}
|
||
console.error("Failed to load live node logs", error);
|
||
setLiveRunLogsError(getActionErrorMessage(error, "无法加载当前节点日志"));
|
||
} finally {
|
||
if (!cancelled) {
|
||
setIsLiveRunLogsLoading(false);
|
||
if (activeRunInFlight && document.visibilityState === "visible") {
|
||
timer = window.setTimeout(refreshLogs, 5000);
|
||
}
|
||
}
|
||
}
|
||
};
|
||
|
||
const handleVisibilityChange = () => {
|
||
window.clearTimeout(timer);
|
||
if (document.visibilityState === "hidden") {
|
||
controller?.abort();
|
||
return;
|
||
}
|
||
void refreshLogs();
|
||
};
|
||
|
||
if (document.visibilityState === "visible") {
|
||
void refreshLogs();
|
||
}
|
||
document.addEventListener("visibilitychange", handleVisibilityChange);
|
||
return () => {
|
||
cancelled = true;
|
||
window.clearTimeout(timer);
|
||
controller?.abort();
|
||
document.removeEventListener("visibilitychange", handleVisibilityChange);
|
||
};
|
||
}, [activeRun?.id, activeRunInFlight, liveRunLogsRefreshToken, nodeConfigPanelTab, selectedNode?.id]);
|
||
|
||
const handleRun = useCallback(async () => {
|
||
if (!workflowEntity || !id || runAction.disabled) {
|
||
if (runAction.reason === "running") {
|
||
setActiveRunError("当前工作流仍在执行中,请等待本次运行结束。");
|
||
} else if (runAction.reason === "invalidConnections") {
|
||
setActiveRunError(duplicateInputConnectionMessage);
|
||
} else if (runAction.reason === "invalidGraph") {
|
||
setActiveRunError(runAction.message || workflowGraphIssueMessage);
|
||
} else if (runAction.reason === "scanConfig") {
|
||
setActiveRunError(
|
||
scanWorkflowConfigIssue || "扫描源配置未完成,请先在扫描源节点配置数据源、目标路径和访问密钥。",
|
||
);
|
||
} else if (runAction.reason === "gpuUnavailable" || runAction.reason === "gpuInsufficient") {
|
||
setActiveRunError(
|
||
runAction.message || workflowGPUCapacityBlocker.message || "当前工作流请求 GPU,但集群无可调度 GPU。",
|
||
);
|
||
} else if (runAction.reason === "gpuCapacityUnavailable") {
|
||
setActiveRunError(runAction.message || workflowGPUCapacityBlocker.message || "无法读取 Worker GPU 调度能力。");
|
||
}
|
||
return;
|
||
}
|
||
if (workflowLevelEnvDuplicates.size > 0) {
|
||
setActiveRunError("工作流级环境变量存在重复 key,请先去重后再运行。");
|
||
return;
|
||
}
|
||
setIsExecuting(true);
|
||
setActiveRunError("");
|
||
try {
|
||
const updatedWorkflow = await persistCurrentEditorEntity();
|
||
if (!updatedWorkflow) {
|
||
return;
|
||
}
|
||
const run = await workflowsApi.run(id);
|
||
setActiveRun(run);
|
||
updateRunSearchParam(run.id);
|
||
if (scheduledHistoryEnabled) {
|
||
setIsRunHistoryOpen(true);
|
||
void loadWorkflowRuns();
|
||
}
|
||
} catch (error) {
|
||
console.error("Failed to enqueue workflow run", error);
|
||
setActiveRunError(getActionErrorMessage(error, "工作流启动失败,请稍后重试"));
|
||
} finally {
|
||
setIsExecuting(false);
|
||
}
|
||
}, [
|
||
id,
|
||
loadWorkflowRuns,
|
||
persistCurrentEditorEntity,
|
||
runAction.disabled,
|
||
runAction.message,
|
||
runAction.reason,
|
||
scanWorkflowConfigIssue,
|
||
scheduledHistoryEnabled,
|
||
updateRunSearchParam,
|
||
workflowLevelEnvDuplicates,
|
||
workflowEntity,
|
||
workflowGraphIssueMessage,
|
||
workflowGPUCapacityBlocker.message,
|
||
]);
|
||
|
||
const handleGracefulStop = useCallback(async () => {
|
||
if (!activeRun?.id || runStopPending) {
|
||
return;
|
||
}
|
||
setRunStopPending("graceful");
|
||
setActiveRunError("");
|
||
try {
|
||
const stopped = await monitoringApi.stopRun(activeRun.id);
|
||
setActiveRun(stopped);
|
||
} catch (error) {
|
||
console.error("Failed to request graceful stop", error);
|
||
setActiveRunError(getActionErrorMessage(error, "停止工作流失败,请稍后重试"));
|
||
setRunStopPending("");
|
||
}
|
||
}, [activeRun?.id, runStopPending]);
|
||
|
||
const handleForceStop = useCallback(async () => {
|
||
if (!activeRun?.id || runStopPending) {
|
||
return;
|
||
}
|
||
setRunStopPending("force");
|
||
setActiveRunError("");
|
||
try {
|
||
const stopped = await monitoringApi.forceStopRun(activeRun.id);
|
||
setActiveRun(stopped);
|
||
} catch (error) {
|
||
console.error("Failed to force stop run", error);
|
||
setActiveRunError(getActionErrorMessage(error, "强制停止工作流失败,请稍后重试"));
|
||
setRunStopPending("");
|
||
}
|
||
}, [activeRun?.id, runStopPending]);
|
||
|
||
const handleRerunSubtree = useCallback(async () => {
|
||
if (!activeRun?.id || activeRun.status !== "failed" || !selectedNode?.id) {
|
||
return;
|
||
}
|
||
setRerunSubtreePendingNodeId(selectedNode.id);
|
||
setActiveRunError("");
|
||
try {
|
||
const rerun = await monitoringApi.rerunSubtree(activeRun.id, selectedNode.id);
|
||
setActiveRun(rerun);
|
||
updateRunSearchParam(rerun.id);
|
||
setCanvasNotice(`已创建从节点 ${selectedNode.data.label} 重新执行下游的子链路运行`);
|
||
if (scheduledHistoryEnabled) {
|
||
setIsRunHistoryOpen(true);
|
||
await loadWorkflowRuns();
|
||
}
|
||
} catch (error) {
|
||
console.error("Failed to rerun subtree", error);
|
||
setActiveRunError(getActionErrorMessage(error, "创建子链路重跑失败,请稍后重试"));
|
||
} finally {
|
||
setRerunSubtreePendingNodeId("");
|
||
}
|
||
}, [activeRun?.id, activeRun?.status, loadWorkflowRuns, scheduledHistoryEnabled, selectedNode, updateRunSearchParam]);
|
||
|
||
const positiveIntegerOrNotice = useCallback((value: unknown, field: string) => {
|
||
try {
|
||
return normalizePositiveInteger(value, field);
|
||
} catch (error) {
|
||
setCanvasNotice(getActionErrorMessage(error, `${field} must be a positive integer`));
|
||
return null;
|
||
}
|
||
}, []);
|
||
|
||
const nonNegativeIntegerOrNotice = useCallback((value: unknown, field: string) => {
|
||
try {
|
||
return normalizeNonNegativeInteger(value, field);
|
||
} catch (error) {
|
||
setCanvasNotice(getActionErrorMessage(error, `${field} must be a non-negative integer`));
|
||
return null;
|
||
}
|
||
}, []);
|
||
|
||
const updateWorkflowSchedule = useCallback(
|
||
(patch: Partial<WorkflowSchedule>) => {
|
||
if (workflowSettingsReadOnly) {
|
||
return;
|
||
}
|
||
try {
|
||
validateNonNegativeIntegerPatch(patch as Record<string, unknown>, workflowScheduleIntegerFields);
|
||
} catch (error) {
|
||
setCanvasNotice(getActionErrorMessage(error, "调度数值必须是非负整数"));
|
||
return;
|
||
}
|
||
setEntity((previous) => {
|
||
if (!previous) {
|
||
return previous;
|
||
}
|
||
const nextSchedule = normalizeWorkflowSchedule({
|
||
...(previous.schedule || {}),
|
||
...patch,
|
||
});
|
||
return {
|
||
...previous,
|
||
schedule: nextSchedule,
|
||
};
|
||
});
|
||
},
|
||
[workflowSettingsReadOnly],
|
||
);
|
||
|
||
const updateWorkflowSettings = useCallback(
|
||
(patch: Partial<Workflow | WorkflowTemplate>) => {
|
||
if (workflowSettingsReadOnly) {
|
||
return;
|
||
}
|
||
try {
|
||
validateNonNegativeIntegerPatch(patch as Record<string, unknown>, workflowExecutionIntegerFields);
|
||
} catch (error) {
|
||
setCanvasNotice(getActionErrorMessage(error, "工作流执行配置必须是非负整数"));
|
||
return;
|
||
}
|
||
setEntity((previous) => {
|
||
if (!previous) {
|
||
return previous;
|
||
}
|
||
return {
|
||
...previous,
|
||
...patch,
|
||
};
|
||
});
|
||
},
|
||
[workflowSettingsReadOnly],
|
||
);
|
||
|
||
const updateWorkflowHyperparams = useCallback(
|
||
(
|
||
updater: (
|
||
current: Array<{ key?: string; value?: string; [key: string]: any }>,
|
||
) => Array<{ key?: string; value?: string; [key: string]: any }>,
|
||
) => {
|
||
if (workflowSettingsReadOnly) {
|
||
return;
|
||
}
|
||
setEntity((previous) => {
|
||
if (!previous) {
|
||
return previous;
|
||
}
|
||
const current = Array.isArray(previous.hyperparams) ? previous.hyperparams.map((item) => ({ ...item })) : [];
|
||
return {
|
||
...previous,
|
||
hyperparams: updater(current),
|
||
};
|
||
});
|
||
},
|
||
[workflowSettingsReadOnly],
|
||
);
|
||
|
||
const appendWorkflowHyperparam = useCallback(() => {
|
||
updateWorkflowHyperparams((current) => [...current, { key: "", value: "", description: "" }]);
|
||
}, [updateWorkflowHyperparams]);
|
||
|
||
const updateWorkflowHyperparamField = useCallback(
|
||
(index: number, field: "key" | "value" | "description", value: string) => {
|
||
updateWorkflowHyperparams((current) =>
|
||
current.map((item, itemIndex) =>
|
||
itemIndex === index
|
||
? {
|
||
...item,
|
||
[field]: value,
|
||
}
|
||
: item,
|
||
),
|
||
);
|
||
},
|
||
[updateWorkflowHyperparams],
|
||
);
|
||
|
||
const removeWorkflowHyperparam = useCallback(
|
||
(index: number) => {
|
||
updateWorkflowHyperparams((current) => current.filter((_, itemIndex) => itemIndex !== index));
|
||
},
|
||
[updateWorkflowHyperparams],
|
||
);
|
||
|
||
const updateWorkflowTriggerMode = useCallback(
|
||
(mode: "manual" | "scheduled") => {
|
||
if (workflowSettingsReadOnly) {
|
||
return;
|
||
}
|
||
setEntity((previous) => {
|
||
if (!previous) {
|
||
return previous;
|
||
}
|
||
const nextSchedule =
|
||
mode === "scheduled"
|
||
? buildScheduledWorkflowSchedule(previous.schedule || {})
|
||
: normalizeWorkflowSchedule(previous.schedule || {});
|
||
if (nodes.some((node) => isScanSourceNode(node))) {
|
||
const patched = applyScanConfigPatchToWorkflow(
|
||
{
|
||
...previous,
|
||
nodes,
|
||
},
|
||
{
|
||
enabled: mode === "scheduled",
|
||
...nextSchedule,
|
||
},
|
||
);
|
||
if (isReactFlowNodeArray(patched.nodes)) {
|
||
setNodes(patched.nodes);
|
||
}
|
||
return patched as Workflow | WorkflowTemplate;
|
||
}
|
||
const nextType: WorkflowType = mode === "scheduled" ? "streaming" : "batch";
|
||
return {
|
||
...previous,
|
||
type: nextType,
|
||
schedule: nextSchedule,
|
||
};
|
||
});
|
||
},
|
||
[nodes, setNodes, workflowSettingsReadOnly],
|
||
);
|
||
|
||
const updateScanWorkflowConfig = useCallback(
|
||
(patch: Record<string, unknown>) => {
|
||
if (workflowSettingsReadOnly) {
|
||
return;
|
||
}
|
||
try {
|
||
validateNonNegativeIntegerPatch(patch, workflowScheduleIntegerFields);
|
||
if (Object.prototype.hasOwnProperty.call(patch, "directoryDepth")) {
|
||
normalizeDirectoryDepth(patch.directoryDepth);
|
||
}
|
||
} catch (error) {
|
||
setCanvasNotice(getActionErrorMessage(error, "扫描工作流数值配置不合法"));
|
||
return;
|
||
}
|
||
setEntity((previous) => {
|
||
if (!previous) {
|
||
return previous;
|
||
}
|
||
const patched = applyScanConfigPatchToWorkflow(
|
||
{
|
||
...previous,
|
||
nodes,
|
||
},
|
||
patch,
|
||
);
|
||
if (isReactFlowNodeArray(patched.nodes)) {
|
||
setNodes(patched.nodes);
|
||
setSelectedNode((current) => {
|
||
if (!current) {
|
||
return current;
|
||
}
|
||
const matched = patched.nodes.find((node) => node.id === current.id);
|
||
return matched || current;
|
||
});
|
||
}
|
||
return patched as Workflow | WorkflowTemplate;
|
||
});
|
||
},
|
||
[nodes, setNodes, workflowSettingsReadOnly],
|
||
);
|
||
|
||
const updateOssNodeConfig = useCallback(
|
||
(patch: Record<string, unknown>) => {
|
||
if (isReadOnly || !selectedNode || !isOssNode(selectedNode)) {
|
||
return;
|
||
}
|
||
const nextBucket = String(patch.bucket ?? selectedNode.data.bucket ?? "").trim();
|
||
const nextPrefix = normalizeStoragePrefix(String(patch.prefix ?? selectedNode.data.prefix ?? ""));
|
||
const nextConnectionID = String(patch.connectionId ?? selectedNode.data.connectionId ?? "").trim();
|
||
const matchedConnection = storageConnections.find((item) => item.id === nextConnectionID);
|
||
const currentSourcePath = getNodeHyperparamValue(selectedNode, "SOURCE_PATH");
|
||
const derivedSourcePath = buildBosSourcePath(nextBucket, nextPrefix);
|
||
const currentDataSource = getNodeHyperparamValue(selectedNode, "DATA_SOURCE") || "BOS";
|
||
const existingEndpoint = getNodeHyperparamValue(selectedNode, "BOS_ENDPOINT");
|
||
const existingAccessKeyID = getNodeHyperparamValue(selectedNode, "BOS_ACCESS_KEY_ID");
|
||
const existingSecretAccessKey = getNodeHyperparamValue(selectedNode, "BOS_SECRET_ACCESS_KEY");
|
||
const nextEndpoint = nextConnectionID
|
||
? matchedConnection?.endpoint || ""
|
||
: patch.endpoint !== undefined
|
||
? String(patch.endpoint).trim()
|
||
: existingEndpoint;
|
||
const nextData = {
|
||
...selectedNode.data,
|
||
...patch,
|
||
bucket: nextBucket,
|
||
prefix: nextPrefix,
|
||
connectionId: nextConnectionID,
|
||
hyperparams: upsertNodeHyperparams(selectedNode.data.hyperparams, {
|
||
DATA_SOURCE: nextConnectionID || nextBucket || nextPrefix ? "BOS" : currentDataSource,
|
||
SOURCE_PATH: derivedSourcePath || currentSourcePath,
|
||
BOS_ENDPOINT: nextEndpoint,
|
||
BOS_ACCESS_KEY_ID: nextConnectionID ? "" : existingAccessKeyID,
|
||
BOS_SECRET_ACCESS_KEY: nextConnectionID ? "" : existingSecretAccessKey,
|
||
}),
|
||
};
|
||
setNodes((nds) => nds.map((node) => (node.id === selectedNode.id ? { ...node, data: nextData } : node)));
|
||
setSelectedNode((previous) =>
|
||
previous && previous.id === selectedNode.id ? { ...previous, data: nextData } : previous,
|
||
);
|
||
},
|
||
[isReadOnly, selectedNode, setNodes, storageConnections],
|
||
);
|
||
|
||
const handleStorageConnectionSelect = useCallback(
|
||
(nextConnectionId: string, scope: "scan" | "node" = "scan") => {
|
||
const connectionId = nextConnectionId.trim();
|
||
if (scope === "node") {
|
||
updateOssNodeConfig({ connectionId });
|
||
return;
|
||
}
|
||
const matched = storageConnections.find((item) => item.id === connectionId);
|
||
updateScanWorkflowConfig({
|
||
connectionId,
|
||
endpoint: connectionId ? matched?.endpoint || "" : "",
|
||
accessKeyId: "",
|
||
secretAccessKey: "",
|
||
});
|
||
},
|
||
[storageConnections, updateOssNodeConfig, updateScanWorkflowConfig],
|
||
);
|
||
|
||
const resetStorageConnectionDraft = useCallback(() => {
|
||
setStorageConnectionDraft({
|
||
name: "",
|
||
description: "",
|
||
endpoint: "",
|
||
accessKeyId: "",
|
||
secretAccessKey: "",
|
||
});
|
||
}, []);
|
||
|
||
const handleCreateStorageConnection = useCallback(async () => {
|
||
if (workflowSettingsReadOnly || isSavingStorageConnection) {
|
||
return;
|
||
}
|
||
const name = storageConnectionDraft.name.trim();
|
||
const endpoint = storageConnectionDraft.endpoint.trim();
|
||
const accessKeyId = storageConnectionDraft.accessKeyId.trim();
|
||
const secretAccessKey = storageConnectionDraft.secretAccessKey.trim();
|
||
if (!name || !accessKeyId || !secretAccessKey) {
|
||
setStorageConnectionsError("新建连接时必须填写名称、Access Key ID 和 Secret Access Key。");
|
||
return;
|
||
}
|
||
const endpointValidationError = validateStorageConnectionEndpoint(endpoint);
|
||
if (endpointValidationError) {
|
||
setStorageConnectionsError(endpointValidationError);
|
||
return;
|
||
}
|
||
setIsSavingStorageConnection(true);
|
||
setStorageConnectionsError("");
|
||
try {
|
||
const created = await storageConnectionsApi.create({
|
||
name,
|
||
description: storageConnectionDraft.description.trim(),
|
||
provider: "BOS",
|
||
endpoint,
|
||
accessKeyId,
|
||
secretAccessKey,
|
||
});
|
||
setStorageConnections((previous) => [created, ...previous.filter((item) => item.id !== created.id)]);
|
||
handleStorageConnectionSelect(
|
||
created.id,
|
||
isOssNode(selectedNode) && !(isScanWorkflow && isScanSourceNode(selectedNode)) ? "node" : "scan",
|
||
);
|
||
setIsStorageConnectionFormOpen(false);
|
||
resetStorageConnectionDraft();
|
||
} catch (error) {
|
||
console.error("Failed to create storage connection", error);
|
||
setStorageConnectionsError(getActionErrorMessage(error, "创建存储连接失败"));
|
||
} finally {
|
||
setIsSavingStorageConnection(false);
|
||
}
|
||
}, [
|
||
handleStorageConnectionSelect,
|
||
isSavingStorageConnection,
|
||
resetStorageConnectionDraft,
|
||
selectedNode,
|
||
isScanWorkflow,
|
||
storageConnectionDraft,
|
||
workflowSettingsReadOnly,
|
||
]);
|
||
|
||
const handleMongoConnectionSelect = useCallback(
|
||
(nextConnectionId: string) => {
|
||
if (isReadOnly || !selectedNode || !isMongoWriteNode(selectedNode)) {
|
||
return;
|
||
}
|
||
const connectionId = nextConnectionId.trim();
|
||
const nextData = {
|
||
...selectedNode.data,
|
||
hyperparams: upsertNodeHyperparams(selectedNode.data.hyperparams, {
|
||
MONGO_CONNECTION_ID: connectionId,
|
||
}),
|
||
};
|
||
setNodes((nds) => nds.map((node) => (node.id === selectedNode.id ? { ...node, data: nextData } : node)));
|
||
setSelectedNode((previous) =>
|
||
previous && previous.id === selectedNode.id ? { ...previous, data: nextData } : previous,
|
||
);
|
||
},
|
||
[isReadOnly, selectedNode, setNodes],
|
||
);
|
||
|
||
const onLayout = useCallback(() => {
|
||
const dagreGraph = new dagre.graphlib.Graph();
|
||
dagreGraph.setDefaultEdgeLabel(() => ({}));
|
||
dagreGraph.setGraph({ rankdir: "LR", ranksep: 100, nodesep: 50 });
|
||
|
||
nodes.forEach((node) => {
|
||
dagreGraph.setNode(node.id, { width: 200, height: 150 });
|
||
});
|
||
|
||
edges.forEach((edge) => {
|
||
dagreGraph.setEdge(edge.source, edge.target);
|
||
});
|
||
|
||
dagre.layout(dagreGraph);
|
||
|
||
const layoutedNodes = nodes.map((node) => {
|
||
const nodeWithPosition = dagreGraph.node(node.id);
|
||
return {
|
||
...node,
|
||
position: {
|
||
x: nodeWithPosition.x - 100,
|
||
y: nodeWithPosition.y - 75,
|
||
},
|
||
};
|
||
});
|
||
|
||
setNodes(layoutedNodes);
|
||
}, [nodes, edges, setNodes]);
|
||
|
||
const resolveCanvasPosition = useCallback((point?: { x: number; y: number }) => {
|
||
if (point && reactFlowInstanceRef.current?.screenToFlowPosition) {
|
||
return reactFlowInstanceRef.current.screenToFlowPosition(point);
|
||
}
|
||
|
||
if (point && reactFlowWrapperRef.current && reactFlowInstanceRef.current?.project) {
|
||
const bounds = reactFlowWrapperRef.current.getBoundingClientRect();
|
||
return reactFlowInstanceRef.current.project({
|
||
x: point.x - bounds.left,
|
||
y: point.y - bounds.top,
|
||
});
|
||
}
|
||
|
||
const bounds = reactFlowWrapperRef.current?.getBoundingClientRect();
|
||
if (bounds && reactFlowInstanceRef.current?.screenToFlowPosition) {
|
||
return reactFlowInstanceRef.current.screenToFlowPosition({
|
||
x: bounds.left + bounds.width / 2,
|
||
y: bounds.top + bounds.height / 2,
|
||
});
|
||
}
|
||
|
||
if (bounds && reactFlowInstanceRef.current?.project) {
|
||
return reactFlowInstanceRef.current.project({
|
||
x: bounds.width / 2,
|
||
y: bounds.height / 2,
|
||
});
|
||
}
|
||
|
||
return { x: 120, y: 120 };
|
||
}, []);
|
||
|
||
const addOperatorToCanvas = useCallback(
|
||
(op: Operator, point?: { x: number; y: number }) => {
|
||
if (isReadOnly || !canManage) {
|
||
return;
|
||
}
|
||
if (!canUseOperatorInWorkflow(op, currentExecutionScope)) {
|
||
setCanvasNotice("生产工作流不能添加未发布的 AI 生成算子;请切换为沙盒验证或发布后再使用。");
|
||
return;
|
||
}
|
||
|
||
const position = resolveCanvasPosition(point);
|
||
const newNode: Node<OperatorNodeData> = {
|
||
id: `node-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`,
|
||
type: "operator",
|
||
position,
|
||
data: {
|
||
label: op.name,
|
||
category: op.category,
|
||
description: op.description,
|
||
inputs: op.inputs,
|
||
outputs: op.outputs,
|
||
operatorId: op.id,
|
||
operatorVersion: op.version,
|
||
operatorImageId: op.imageId || op.image,
|
||
image: op.image,
|
||
containerCommand: op.containerCommand || [],
|
||
containerArgs: op.containerArgs || [],
|
||
runtimeContract: op.runtimeContract || {},
|
||
generationSource: op.generationSource,
|
||
publicationStatus: op.publicationStatus,
|
||
publicationEvidence: op.publicationEvidence,
|
||
hyperparams: op.hyperparams || [],
|
||
cpu: op.resources?.cpuLimit || "",
|
||
memory: op.resources?.memoryLimit || "",
|
||
gpu: op.resources?.gpuLimit || "",
|
||
},
|
||
};
|
||
|
||
setNodes((currentNodes) =>
|
||
currentNodes
|
||
.map((node) => ({ ...node, selected: false }))
|
||
.concat({
|
||
...newNode,
|
||
selected: true,
|
||
}),
|
||
);
|
||
if (String(op?.name || "").trim() === "BOS 增量扫描") {
|
||
setEntity((previous) =>
|
||
previous
|
||
? (ensureScanWorkflowShell(previous, {
|
||
dataSource: "BOS",
|
||
}) as Workflow | WorkflowTemplate)
|
||
: previous,
|
||
);
|
||
}
|
||
setSelectedNode(newNode);
|
||
setCanvasNotice(`已添加算子 ${op.name}`);
|
||
},
|
||
[canManage, currentExecutionScope, isReadOnly, resolveCanvasPosition, setNodes],
|
||
);
|
||
|
||
const handleOperatorDragStart = useCallback(
|
||
(event: React.DragEvent<HTMLDivElement>, operator: Operator) => {
|
||
if (isReadOnly || !canManage) {
|
||
event.preventDefault();
|
||
return;
|
||
}
|
||
if (!canUseOperatorInWorkflow(operator, currentExecutionScope)) {
|
||
event.preventDefault();
|
||
setCanvasNotice("生产工作流不能拖入未发布的 AI 生成算子。");
|
||
return;
|
||
}
|
||
draggedOperatorRef.current = operator;
|
||
event.dataTransfer.effectAllowed = "copy";
|
||
event.dataTransfer.setData(OPERATOR_DRAG_MIME, JSON.stringify(operator));
|
||
event.dataTransfer.setData(OPERATOR_DRAG_TEXT_MIME, operator.id);
|
||
setIsCanvasDragActive(true);
|
||
},
|
||
[canManage, currentExecutionScope, isReadOnly],
|
||
);
|
||
|
||
const handleOperatorDragEnd = useCallback(() => {
|
||
draggedOperatorRef.current = null;
|
||
setIsCanvasDragActive(false);
|
||
}, []);
|
||
|
||
const handleCanvasDragOver = useCallback(
|
||
(event: React.DragEvent<HTMLDivElement>) => {
|
||
if (isReadOnly || !canManage) {
|
||
return;
|
||
}
|
||
if (!draggedOperatorRef.current && !dataTransferHasType(event.dataTransfer.types, OPERATOR_DRAG_MIME)) {
|
||
return;
|
||
}
|
||
event.preventDefault();
|
||
event.dataTransfer.dropEffect = "copy";
|
||
if (!isCanvasDragActive) {
|
||
setIsCanvasDragActive(true);
|
||
}
|
||
},
|
||
[canManage, isCanvasDragActive, isReadOnly],
|
||
);
|
||
|
||
const handleCanvasDragLeave = useCallback((event: React.DragEvent<HTMLDivElement>) => {
|
||
if (!reactFlowWrapperRef.current) {
|
||
setIsCanvasDragActive(false);
|
||
return;
|
||
}
|
||
const nextTarget = event.relatedTarget as globalThis.Node | null;
|
||
if (nextTarget && reactFlowWrapperRef.current.contains(nextTarget)) {
|
||
return;
|
||
}
|
||
setIsCanvasDragActive(false);
|
||
}, []);
|
||
|
||
const handleCanvasDrop = useCallback(
|
||
(event: React.DragEvent<HTMLDivElement>) => {
|
||
if (isReadOnly || !canManage) {
|
||
return;
|
||
}
|
||
event.preventDefault();
|
||
setIsCanvasDragActive(false);
|
||
|
||
try {
|
||
const payload = event.dataTransfer.getData(OPERATOR_DRAG_MIME);
|
||
const textPayload = event.dataTransfer.getData(OPERATOR_DRAG_TEXT_MIME);
|
||
const parsed = payload ? JSON.parse(payload) : draggedOperatorRef.current;
|
||
const operator = isOperatorCandidate(parsed) ? parsed : null;
|
||
const fallbackOperator = textPayload ? operators.find((item) => item.id === textPayload) || null : null;
|
||
if (!operator && !fallbackOperator) {
|
||
return;
|
||
}
|
||
addOperatorToCanvas(operator || fallbackOperator, { x: event.clientX, y: event.clientY });
|
||
} catch (error) {
|
||
console.error("Failed to drop operator onto canvas", error);
|
||
setCanvasNotice("拖拽添加算子失败,请重试");
|
||
} finally {
|
||
draggedOperatorRef.current = null;
|
||
}
|
||
},
|
||
[addOperatorToCanvas, canManage, isReadOnly, operators],
|
||
);
|
||
|
||
const [buckets, setBuckets] = useState<string[]>([]);
|
||
const [isOssBrowsing, setIsOssBrowsing] = useState(false);
|
||
const [ossObjects, setOssObjects] = useState<string[]>([]);
|
||
const [isOssLoading, setIsOssLoading] = useState(false);
|
||
const [ossBrowseError, setOssBrowseError] = useState("");
|
||
const [favoriteStoragePaths, setFavoriteStoragePaths] = useState<
|
||
Array<{ bucket: string; prefix: string; label: string }>
|
||
>([]);
|
||
const [projectFavoriteStoragePathRecords, setProjectFavoriteStoragePathRecords] = useState<
|
||
Array<{ scopeKey: string; bucket: string; prefix?: string; label?: string }>
|
||
>([]);
|
||
const favoriteStorageMutationVersionRef = useRef(0);
|
||
const projectFavoriteStorageMutationVersionRef = useRef(0);
|
||
const [recentStoragePaths, setRecentStoragePaths] = useState<
|
||
Array<{ bucket: string; prefix: string; label: string }>
|
||
>([]);
|
||
const selectedNodeSourcePath = getNodeHyperparamValue(selectedNode, "SOURCE_PATH");
|
||
const selectedNodeConnectionId =
|
||
selectedNodeStorageScope === "scan"
|
||
? workflowConfigEntity?.scanConfig?.connectionId?.trim() || ""
|
||
: String(selectedNode?.data?.connectionId || "").trim();
|
||
const selectedStorageConnection = selectedNodeStorageScope === "scan" ? scanStorageConnection : nodeStorageConnection;
|
||
const canBrowseSelectedStorage = Boolean(selectedNodeConnectionId || selectedNodeSourcePath);
|
||
const selectedNodeBucket =
|
||
(selectedNodeStorageScope === "scan" ? workflowConfigEntity?.scanConfig?.bucket : selectedNode?.data?.bucket) || "";
|
||
const selectedNodePrefix =
|
||
(selectedNodeStorageScope === "scan" ? workflowConfigEntity?.scanConfig?.prefix : selectedNode?.data?.prefix) || "";
|
||
const selectedStoragePathKey = selectedNodeBucket
|
||
? `${selectedNodeBucket}/${normalizeStoragePrefix(selectedNodePrefix)}`
|
||
: "";
|
||
const favoriteStoragePathKeys = useMemo(
|
||
() => new Set(favoriteStoragePaths.map((item) => `${item.bucket}/${normalizeStoragePrefix(item.prefix)}`)),
|
||
[favoriteStoragePaths],
|
||
);
|
||
const selectedStorageScopeKey = useMemo(
|
||
() =>
|
||
buildStorageHistoryScopeKey({
|
||
connectionId: selectedNodeConnectionId,
|
||
sourcePath: selectedNodeSourcePath,
|
||
}),
|
||
[selectedNodeConnectionId, selectedNodeSourcePath],
|
||
);
|
||
const projectFavoriteStoragePaths = useMemo(
|
||
() =>
|
||
projectFavoriteStoragePathRecords
|
||
.filter((item) => item.scopeKey === selectedStorageScopeKey)
|
||
.slice(0, 12)
|
||
.map((item) => ({
|
||
bucket: item.bucket,
|
||
prefix: item.prefix || "",
|
||
label: item.label || (item.prefix ? `${item.bucket}/${item.prefix}` : item.bucket),
|
||
})),
|
||
[projectFavoriteStoragePathRecords, selectedStorageScopeKey],
|
||
);
|
||
const projectFavoriteStoragePathKeys = useMemo(
|
||
() => new Set(projectFavoriteStoragePaths.map((item) => `${item.bucket}/${normalizeStoragePrefix(item.prefix)}`)),
|
||
[projectFavoriteStoragePaths],
|
||
);
|
||
const visibleUserFavoriteStoragePaths = useMemo(
|
||
() => filterRecentPathsAgainstFavorites(favoriteStoragePaths, projectFavoriteStoragePaths),
|
||
[favoriteStoragePaths, projectFavoriteStoragePaths],
|
||
);
|
||
const isCurrentStoragePathFavorite = Boolean(
|
||
selectedStoragePathKey && favoriteStoragePathKeys.has(selectedStoragePathKey),
|
||
);
|
||
const isCurrentProjectStoragePathFavorite = Boolean(
|
||
selectedStoragePathKey && projectFavoriteStoragePathKeys.has(selectedStoragePathKey),
|
||
);
|
||
const visibleRecentStoragePaths = useMemo(
|
||
() =>
|
||
filterRecentPathsAgainstFavorites(recentStoragePaths, [...projectFavoriteStoragePaths, ...favoriteStoragePaths]),
|
||
[favoriteStoragePaths, projectFavoriteStoragePaths, recentStoragePaths],
|
||
);
|
||
const selectedBrowseRootLabel = selectedNodeConnectionId
|
||
? selectedStorageConnection?.name || selectedNodeConnectionId
|
||
: selectedNodeSourcePath || buildBosSourcePath(selectedNodeBucket, selectedNodePrefix);
|
||
const canBrowseStorageNode = Boolean(
|
||
isOssNode(selectedNode) ||
|
||
(isScanWorkflow &&
|
||
isScanSourceNode(selectedNode) &&
|
||
(workflowConfigEntity?.scanConfig?.dataSource || "BOS") === "BOS"),
|
||
);
|
||
const refreshRecentStoragePaths = useCallback(() => {
|
||
setRecentStoragePaths(
|
||
listRecentStoragePaths({
|
||
connectionId: selectedNodeConnectionId,
|
||
sourcePath: selectedNodeSourcePath,
|
||
}),
|
||
);
|
||
}, [selectedNodeConnectionId, selectedNodeSourcePath]);
|
||
|
||
const refreshFavoriteStoragePaths = useCallback(() => {
|
||
setFavoriteStoragePaths(
|
||
listFavoriteStoragePaths({
|
||
connectionId: selectedNodeConnectionId,
|
||
sourcePath: selectedNodeSourcePath,
|
||
}),
|
||
);
|
||
}, [selectedNodeConnectionId, selectedNodeSourcePath]);
|
||
const refreshFavoriteStoragePathsRef = useRef(refreshFavoriteStoragePaths);
|
||
|
||
const rememberRecentStoragePath = useCallback(
|
||
(bucket: string, prefix: string) => {
|
||
setRecentStoragePaths(
|
||
rememberStoragePath(
|
||
{
|
||
connectionId: selectedNodeConnectionId,
|
||
sourcePath: selectedNodeSourcePath,
|
||
},
|
||
{ bucket, prefix },
|
||
),
|
||
);
|
||
},
|
||
[selectedNodeConnectionId, selectedNodeSourcePath],
|
||
);
|
||
|
||
useEffect(() => {
|
||
refreshRecentStoragePaths();
|
||
}, [refreshRecentStoragePaths]);
|
||
|
||
useEffect(() => {
|
||
refreshFavoriteStoragePaths();
|
||
}, [refreshFavoriteStoragePaths]);
|
||
|
||
useEffect(() => {
|
||
refreshFavoriteStoragePathsRef.current = refreshFavoriteStoragePaths;
|
||
}, [refreshFavoriteStoragePaths]);
|
||
|
||
useEffect(() => {
|
||
const localRecords = listFavoriteStoragePathRecords();
|
||
if (!currentUser?.id) {
|
||
replaceFavoriteStoragePathRecords(localRecords);
|
||
refreshFavoriteStoragePathsRef.current();
|
||
return;
|
||
}
|
||
let cancelled = false;
|
||
const loadVersion = favoriteStorageMutationVersionRef.current;
|
||
usersApi
|
||
.listStoragePathFavorites(currentUser.id)
|
||
.then((remoteRecords) => {
|
||
if (cancelled || loadVersion !== favoriteStorageMutationVersionRef.current) {
|
||
return;
|
||
}
|
||
const currentLocalRecords = listFavoriteStoragePathRecords();
|
||
const mergedRecords = mergeFavoriteStoragePathRecords(remoteRecords, currentLocalRecords);
|
||
const normalizedRemote = normalizeFavoriteStoragePathRecords(remoteRecords);
|
||
const normalizedMerged = replaceFavoriteStoragePathRecords(mergedRecords);
|
||
refreshFavoriteStoragePathsRef.current();
|
||
if (loadVersion !== favoriteStorageMutationVersionRef.current) {
|
||
return;
|
||
}
|
||
if (JSON.stringify(normalizedMerged) === JSON.stringify(normalizedRemote)) {
|
||
return;
|
||
}
|
||
usersApi
|
||
.updateStoragePathFavorites(currentUser.id, normalizedMerged)
|
||
.then((response) => {
|
||
if (cancelled || loadVersion !== favoriteStorageMutationVersionRef.current) {
|
||
return;
|
||
}
|
||
replaceFavoriteStoragePathRecords(response.items);
|
||
refreshFavoriteStoragePathsRef.current();
|
||
})
|
||
.catch((error) => {
|
||
if (cancelled) {
|
||
return;
|
||
}
|
||
console.error("Failed to merge storage favorites to server", error);
|
||
setCanvasNotice("常用路径同步失败,将继续使用浏览器收藏");
|
||
});
|
||
})
|
||
.catch((error) => {
|
||
if (cancelled) {
|
||
return;
|
||
}
|
||
console.error("Failed to load storage favorites from server", error);
|
||
replaceFavoriteStoragePathRecords(localRecords);
|
||
refreshFavoriteStoragePathsRef.current();
|
||
});
|
||
return () => {
|
||
cancelled = true;
|
||
};
|
||
}, [currentUser?.id]);
|
||
|
||
useEffect(() => {
|
||
if (!workflowProjectId) {
|
||
setProjectFavoriteStoragePathRecords([]);
|
||
return;
|
||
}
|
||
let cancelled = false;
|
||
const loadVersion = projectFavoriteStorageMutationVersionRef.current;
|
||
projectsApi
|
||
.listStoragePathFavorites(workflowProjectId)
|
||
.then((items) => {
|
||
if (cancelled || loadVersion !== projectFavoriteStorageMutationVersionRef.current) {
|
||
return;
|
||
}
|
||
setProjectFavoriteStoragePathRecords(normalizeFavoriteStoragePathRecords(items));
|
||
})
|
||
.catch((error) => {
|
||
if (cancelled) {
|
||
return;
|
||
}
|
||
console.error("Failed to load project storage favorites", error);
|
||
setProjectFavoriteStoragePathRecords([]);
|
||
});
|
||
return () => {
|
||
cancelled = true;
|
||
};
|
||
}, [workflowProjectId]);
|
||
|
||
const applyStorageBrowserSelection = useCallback(
|
||
(value: string, closeAfterSelect: boolean) => {
|
||
const nextPrefix = normalizeStoragePrefix(value);
|
||
if (selectedNodeStorageScope === "scan") {
|
||
updateScanWorkflowConfig({ prefix: nextPrefix });
|
||
} else if (selectedNodeStorageScope === "node") {
|
||
updateOssNodeConfig({ prefix: nextPrefix });
|
||
}
|
||
rememberRecentStoragePath(selectedNodeBucket, nextPrefix);
|
||
if (closeAfterSelect) {
|
||
setIsOssBrowsing(false);
|
||
}
|
||
},
|
||
[
|
||
rememberRecentStoragePath,
|
||
selectedNodeBucket,
|
||
selectedNodeStorageScope,
|
||
updateOssNodeConfig,
|
||
updateScanWorkflowConfig,
|
||
],
|
||
);
|
||
|
||
const applyRecentStoragePath = useCallback(
|
||
(bucket: string, prefix: string) => {
|
||
if (selectedNodeStorageScope === "scan") {
|
||
updateScanWorkflowConfig({ bucket, prefix });
|
||
} else if (selectedNodeStorageScope === "node") {
|
||
updateOssNodeConfig({ bucket, prefix });
|
||
}
|
||
rememberRecentStoragePath(bucket, prefix);
|
||
},
|
||
[rememberRecentStoragePath, selectedNodeStorageScope, updateOssNodeConfig, updateScanWorkflowConfig],
|
||
);
|
||
|
||
const applyFavoriteStoragePath = useCallback(
|
||
(bucket: string, prefix: string) => {
|
||
if (selectedNodeStorageScope === "scan") {
|
||
updateScanWorkflowConfig({ bucket, prefix });
|
||
} else if (selectedNodeStorageScope === "node") {
|
||
updateOssNodeConfig({ bucket, prefix });
|
||
}
|
||
rememberRecentStoragePath(bucket, prefix);
|
||
},
|
||
[rememberRecentStoragePath, selectedNodeStorageScope, updateOssNodeConfig, updateScanWorkflowConfig],
|
||
);
|
||
|
||
const toggleCurrentStoragePathFavorite = useCallback(async () => {
|
||
favoriteStorageMutationVersionRef.current += 1;
|
||
const target = {
|
||
connectionId: selectedNodeConnectionId,
|
||
sourcePath: selectedNodeSourcePath,
|
||
};
|
||
const previousRecords = listFavoriteStoragePathRecords();
|
||
const nextScopeItems = toggleFavoriteStoragePath(target, {
|
||
bucket: selectedNodeBucket,
|
||
prefix: selectedNodePrefix,
|
||
});
|
||
setFavoriteStoragePaths(nextScopeItems);
|
||
if (!currentUser?.id) {
|
||
return;
|
||
}
|
||
try {
|
||
const nextRecords = listFavoriteStoragePathRecords();
|
||
const response = await usersApi.updateStoragePathFavorites(currentUser.id, nextRecords);
|
||
replaceFavoriteStoragePathRecords(response.items);
|
||
refreshFavoriteStoragePaths();
|
||
} catch (error) {
|
||
console.error("Failed to save storage favorites", error);
|
||
replaceFavoriteStoragePathRecords(previousRecords);
|
||
refreshFavoriteStoragePaths();
|
||
setCanvasNotice("常用路径同步失败,已回退");
|
||
}
|
||
}, [
|
||
currentUser?.id,
|
||
refreshFavoriteStoragePaths,
|
||
selectedNodeBucket,
|
||
selectedNodeConnectionId,
|
||
selectedNodePrefix,
|
||
selectedNodeSourcePath,
|
||
]);
|
||
|
||
const toggleCurrentProjectStoragePathFavorite = useCallback(async () => {
|
||
if (!workflowProjectId || !selectedStorageScopeKey || !selectedNodeBucket) {
|
||
return;
|
||
}
|
||
projectFavoriteStorageMutationVersionRef.current += 1;
|
||
const record = {
|
||
scopeKey: selectedStorageScopeKey,
|
||
bucket: selectedNodeBucket,
|
||
prefix: normalizeStoragePrefix(selectedNodePrefix),
|
||
label: normalizeStoragePrefix(selectedNodePrefix)
|
||
? `${selectedNodeBucket}/${normalizeStoragePrefix(selectedNodePrefix)}`
|
||
: selectedNodeBucket,
|
||
};
|
||
const previousRecords = projectFavoriteStoragePathRecords;
|
||
const nextRecords = isCurrentProjectStoragePathFavorite
|
||
? previousRecords.filter(
|
||
(item) =>
|
||
!(
|
||
item.scopeKey === record.scopeKey &&
|
||
item.bucket === record.bucket &&
|
||
normalizeStoragePrefix(item.prefix || "") === record.prefix
|
||
),
|
||
)
|
||
: normalizeFavoriteStoragePathRecords([record, ...previousRecords]);
|
||
setProjectFavoriteStoragePathRecords(nextRecords);
|
||
try {
|
||
const response = await projectsApi.updateStoragePathFavorites(workflowProjectId, nextRecords);
|
||
setProjectFavoriteStoragePathRecords(normalizeFavoriteStoragePathRecords(response.items));
|
||
} catch (error) {
|
||
console.error("Failed to save project storage favorites", error);
|
||
setProjectFavoriteStoragePathRecords(previousRecords);
|
||
setCanvasNotice("项目常用路径同步失败,已回退");
|
||
}
|
||
}, [
|
||
isCurrentProjectStoragePathFavorite,
|
||
projectFavoriteStoragePathRecords,
|
||
selectedNodeBucket,
|
||
selectedNodePrefix,
|
||
selectedStorageScopeKey,
|
||
workflowProjectId,
|
||
]);
|
||
|
||
useEffect(() => {
|
||
if (!canBrowseStorageNode) {
|
||
setBuckets([]);
|
||
setOssBrowseError("");
|
||
return;
|
||
}
|
||
if (!canBrowseSelectedStorage) {
|
||
setBuckets([]);
|
||
setOssBrowseError("");
|
||
return;
|
||
}
|
||
let cancelled = false;
|
||
monitoringApi
|
||
.listOssBuckets({
|
||
sourcePath: selectedNodeConnectionId ? "" : selectedNodeSourcePath,
|
||
connectionId: selectedNodeConnectionId,
|
||
})
|
||
.then((items) => {
|
||
if (cancelled) {
|
||
return;
|
||
}
|
||
setBuckets(items);
|
||
setOssBrowseError("");
|
||
})
|
||
.catch((error) => {
|
||
if (cancelled) {
|
||
return;
|
||
}
|
||
console.error("Failed to load OSS buckets", error);
|
||
setBuckets([]);
|
||
setOssBrowseError(getActionErrorMessage(error, "无法读取当前节点的 OSS 根目录"));
|
||
});
|
||
return () => {
|
||
cancelled = true;
|
||
};
|
||
}, [
|
||
canBrowseSelectedStorage,
|
||
canBrowseStorageNode,
|
||
nodeStorageConnection,
|
||
scanStorageConnection,
|
||
selectedNodeStorageScope,
|
||
selectedNodeConnectionId,
|
||
selectedNode?.id,
|
||
selectedNode?.data.hyperparams,
|
||
selectedNode?.data.label,
|
||
selectedNodeSourcePath,
|
||
]);
|
||
|
||
useEffect(() => {
|
||
if (!isOssBrowsing) {
|
||
return;
|
||
}
|
||
if (!canBrowseSelectedStorage) {
|
||
setOssObjects([]);
|
||
setOssBrowseError("请先选择存储连接,或配置 SOURCE_PATH");
|
||
return;
|
||
}
|
||
if (!selectedNodeBucket) {
|
||
setOssObjects([]);
|
||
setOssBrowseError("");
|
||
return;
|
||
}
|
||
let cancelled = false;
|
||
setIsOssLoading(true);
|
||
setOssBrowseError("");
|
||
monitoringApi
|
||
.listOssObjects(
|
||
{
|
||
sourcePath: selectedNodeConnectionId ? "" : selectedNodeSourcePath,
|
||
connectionId: selectedNodeConnectionId,
|
||
},
|
||
selectedNodeBucket,
|
||
selectedNodePrefix,
|
||
)
|
||
.then((items) => {
|
||
if (cancelled) {
|
||
return;
|
||
}
|
||
setOssObjects(items);
|
||
})
|
||
.catch((error) => {
|
||
if (cancelled) {
|
||
return;
|
||
}
|
||
console.error("Failed to load OSS objects", error);
|
||
setOssObjects([]);
|
||
setOssBrowseError(getActionErrorMessage(error, "无法读取当前节点的 OSS 路径"));
|
||
})
|
||
.finally(() => {
|
||
if (!cancelled) {
|
||
setIsOssLoading(false);
|
||
}
|
||
});
|
||
return () => {
|
||
cancelled = true;
|
||
};
|
||
}, [
|
||
canBrowseSelectedStorage,
|
||
isOssBrowsing,
|
||
selectedNodeBucket,
|
||
selectedNodeConnectionId,
|
||
selectedNodePrefix,
|
||
selectedNodeSourcePath,
|
||
]);
|
||
|
||
const deleteSelectedCanvasElements = useCallback(() => {
|
||
const result = removeSelectedCanvasElements(nodes, edges);
|
||
if (result.removedNodeIds.length === 0 && result.removedEdgeIds.length === 0) {
|
||
return;
|
||
}
|
||
|
||
setNodes(result.nodes);
|
||
setEdges(result.edges);
|
||
setEntity((previous) => {
|
||
if (!previous) {
|
||
return previous;
|
||
}
|
||
if (result.nodes.some((node) => isDedicatedScanSourceNode(node))) {
|
||
return previous;
|
||
}
|
||
if (previous.kind !== "scan" && !previous.scanConfig) {
|
||
return previous;
|
||
}
|
||
return stripScanWorkflowShell(previous) as Workflow | WorkflowTemplate;
|
||
});
|
||
setSelectedNode((previous) => (previous && result.removedNodeIds.includes(previous.id) ? null : previous));
|
||
setSelectedEdgeId((previous) => (previous && result.removedEdgeIds.includes(previous) ? "" : previous));
|
||
setCanvasNotice(`已删除 ${result.removedNodeIds.length} 个节点和 ${result.removedEdgeIds.length} 条连线`);
|
||
}, [edges, nodes, setEdges, setNodes]);
|
||
|
||
useEffect(() => {
|
||
if (isReadOnly || !canManage) {
|
||
return;
|
||
}
|
||
|
||
const handleKeyDown = (event: KeyboardEvent) => {
|
||
const target = event.target as HTMLElement | null;
|
||
const isEditableTarget =
|
||
target instanceof HTMLInputElement ||
|
||
target instanceof HTMLTextAreaElement ||
|
||
target instanceof HTMLSelectElement ||
|
||
target?.isContentEditable;
|
||
if (isEditableTarget) {
|
||
return;
|
||
}
|
||
if (event.key !== "Delete" && event.key !== "Backspace") {
|
||
return;
|
||
}
|
||
if (!hasCanvasSelection) {
|
||
return;
|
||
}
|
||
event.preventDefault();
|
||
deleteSelectedCanvasElements();
|
||
};
|
||
|
||
window.addEventListener("keydown", handleKeyDown);
|
||
return () => window.removeEventListener("keydown", handleKeyDown);
|
||
}, [canManage, deleteSelectedCanvasElements, hasCanvasSelection, isReadOnly]);
|
||
|
||
const onConnect = useCallback(
|
||
(params: Connection) => {
|
||
if (isReadOnly || !canManage) {
|
||
return;
|
||
}
|
||
setEdges((currentEdges) => {
|
||
if (!canConnectToInput(currentEdges, params)) {
|
||
setCanvasNotice("每个输入端口只能连接一条上游连线");
|
||
return currentEdges;
|
||
}
|
||
return addEdge(params, currentEdges);
|
||
});
|
||
},
|
||
[canManage, isReadOnly, setEdges],
|
||
);
|
||
|
||
const onNodeClick: NodeMouseHandler = useCallback((_, node) => {
|
||
setSelectedNode(node);
|
||
setSelectedEdgeId("");
|
||
}, []);
|
||
|
||
const onEdgeClick: EdgeMouseHandler = useCallback((_, edge) => {
|
||
setSelectedNode(null);
|
||
setSelectedEdgeId(edge.id);
|
||
setIsConfigOpen(true);
|
||
}, []);
|
||
|
||
const onPaneClick = useCallback(() => {
|
||
setSelectedNode(null);
|
||
setSelectedEdgeId("");
|
||
}, []);
|
||
|
||
const onNodeDoubleClick: NodeMouseHandler = useCallback(
|
||
(_, node) => {
|
||
setSelectedNode(node);
|
||
setSelectedEdgeId("");
|
||
setIsConfigOpen(true);
|
||
focusNodeConfigInput();
|
||
},
|
||
[focusNodeConfigInput],
|
||
);
|
||
|
||
const updateNodeData = useCallback(
|
||
(newData: Partial<OperatorNodeData>) => {
|
||
if (isReadOnly || !selectedNode) return;
|
||
|
||
setNodes((nds) =>
|
||
nds.map((node) => (node.id === selectedNode.id ? { ...node, data: { ...node.data, ...newData } } : node)),
|
||
);
|
||
setSelectedNode((prev) => (prev ? { ...prev, data: { ...prev.data, ...newData } } : null));
|
||
},
|
||
[isReadOnly, selectedNode, setNodes],
|
||
);
|
||
|
||
const handleResetSourceState = useCallback(async () => {
|
||
if (
|
||
isReadOnly ||
|
||
!canManage ||
|
||
!id ||
|
||
!selectedNode?.id ||
|
||
!isSelectedScanSourceNode ||
|
||
!sourceState?.currentFingerprint
|
||
) {
|
||
return;
|
||
}
|
||
try {
|
||
setIsResettingSourceState(true);
|
||
setSourceStateError("");
|
||
await workflowsApi.resetSourceState(id, selectedNode.id);
|
||
refreshSourceState();
|
||
setCanvasNotice("已重置当前扫描源的增量状态");
|
||
} catch (error) {
|
||
console.error("Failed to reset source state", error);
|
||
setSourceStateError(getActionErrorMessage(error, "重置扫描状态失败"));
|
||
} finally {
|
||
setIsResettingSourceState(false);
|
||
}
|
||
}, [
|
||
canManage,
|
||
id,
|
||
isReadOnly,
|
||
isSelectedScanSourceNode,
|
||
refreshSourceState,
|
||
selectedNode?.id,
|
||
sourceState?.currentFingerprint,
|
||
]);
|
||
|
||
const handleSave = useCallback(async () => {
|
||
try {
|
||
await persistCurrentEditorEntity();
|
||
} catch (error) {
|
||
console.error("Failed to save workflow", error);
|
||
}
|
||
}, [persistCurrentEditorEntity]);
|
||
|
||
useEffect(() => {
|
||
if (isReadOnly || !canManage) {
|
||
return undefined;
|
||
}
|
||
const handleSaveShortcut = (event: KeyboardEvent) => {
|
||
if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === "s") {
|
||
event.preventDefault();
|
||
void handleSave();
|
||
}
|
||
};
|
||
window.addEventListener("keydown", handleSaveShortcut);
|
||
return () => window.removeEventListener("keydown", handleSaveShortcut);
|
||
}, [canManage, handleSave, isReadOnly]);
|
||
|
||
const openExportTemplateModal = useCallback(() => {
|
||
if (hasBlockingGraphIssue) {
|
||
setCanvasNotice(blockingGraphIssueMessage);
|
||
return;
|
||
}
|
||
if (workflowLevelEnvDuplicates.size > 0) {
|
||
setCanvasNotice("工作流级环境变量存在重复 key,请先去重后再导出模板。");
|
||
return;
|
||
}
|
||
setTemplateDraft({
|
||
name: `${entity?.name || "工作流"} 模板`,
|
||
description: ("description" in (entity || {}) && entity?.description) || "从工作流导出的模板",
|
||
});
|
||
setIsExportTemplateOpen(true);
|
||
}, [blockingGraphIssueMessage, entity, hasBlockingGraphIssue, workflowLevelEnvDuplicates]);
|
||
|
||
const handleExportTemplate = useCallback(async () => {
|
||
if (!templateDraft.name.trim()) {
|
||
return;
|
||
}
|
||
if (hasBlockingGraphIssue) {
|
||
setCanvasNotice(blockingGraphIssueMessage);
|
||
return;
|
||
}
|
||
if (workflowLevelEnvDuplicates.size > 0) {
|
||
setCanvasNotice("工作流级环境变量存在重复 key,请先去重后再导出模板。");
|
||
return;
|
||
}
|
||
try {
|
||
const source = prepareEntityForPersistence(entity as Workflow | WorkflowTemplate) || {
|
||
...(entity || {}),
|
||
nodes,
|
||
edges,
|
||
};
|
||
const overrides = {
|
||
name: templateDraft.name.trim(),
|
||
description: templateDraft.description.trim(),
|
||
};
|
||
const payloadIssue = getTemplatePayloadIssue(source, overrides);
|
||
if (payloadIssue) {
|
||
setCanvasNotice(payloadIssue);
|
||
return;
|
||
}
|
||
const created = await templatesApi.create(buildTemplatePayload(source, overrides));
|
||
setIsExportTemplateOpen(false);
|
||
navigate(`/workflow/${created.id}?type=template`);
|
||
} catch (error) {
|
||
console.error("Failed to export workflow as template", error);
|
||
}
|
||
}, [
|
||
edges,
|
||
blockingGraphIssueMessage,
|
||
entity,
|
||
hasBlockingGraphIssue,
|
||
navigate,
|
||
nodes,
|
||
prepareEntityForPersistence,
|
||
templateDraft.description,
|
||
templateDraft.name,
|
||
workflowLevelEnvDuplicates,
|
||
]);
|
||
|
||
return (
|
||
<div className="h-full flex flex-col -m-8">
|
||
<div className="h-14 bg-[#151619] border-b border-[#2a2b2f] flex items-center justify-between px-6 shrink-0">
|
||
<div className="flex items-center gap-4">
|
||
<button
|
||
onClick={() => navigate(-1)}
|
||
className="p-2 hover:bg-white/5 rounded-md text-gray-400 hover:text-white transition-colors"
|
||
>
|
||
<ChevronLeft className="w-5 h-5" />
|
||
</button>
|
||
<div className="flex items-center gap-3">
|
||
<Logo size="md" />
|
||
<div>
|
||
<h1 className="text-sm font-bold text-white flex items-center gap-2">
|
||
{entity?.name || "数据工作流"}
|
||
{isReadOnly && <Lock className="w-3.5 h-3.5 text-orange-500" />}
|
||
</h1>
|
||
<p className="text-[10px] text-gray-500">Drobodata 工作流编辑器</p>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div className="flex items-center gap-3 relative">
|
||
{workflowConfigEntity && (
|
||
<div className="relative">
|
||
<button
|
||
ref={workflowSettingsTriggerRef}
|
||
onClick={() => setIsWorkflowSettingsOpen((open) => !open)}
|
||
className="flex items-center gap-2 px-3 py-1.5 text-xs font-medium text-gray-400 hover:text-white hover:bg-white/5 rounded-md transition-colors"
|
||
>
|
||
<Settings className="w-4 h-4" />
|
||
工作流配置
|
||
</button>
|
||
<AnimatePresence>
|
||
{isWorkflowSettingsOpen && (
|
||
<motion.div
|
||
ref={workflowSettingsPanelRef}
|
||
initial={{ opacity: 0, y: -8, scale: 0.98 }}
|
||
animate={{ opacity: 1, y: 0, scale: 1 }}
|
||
exit={{ opacity: 0, y: -8, scale: 0.98 }}
|
||
className="absolute right-0 top-full z-50 mt-2 w-[320px] rounded-xl border border-[#2a2b2f] bg-[#151619] shadow-2xl"
|
||
>
|
||
<div className="flex items-center justify-between border-b border-[#2a2b2f] px-4 py-3">
|
||
<div>
|
||
<h3 className="text-xs font-bold uppercase tracking-wider text-white">工作流配置</h3>
|
||
<p className="mt-1 text-[10px] text-gray-500">
|
||
工作流级设置统一放在这里,避免和节点参数混在一起。
|
||
</p>
|
||
</div>
|
||
<button
|
||
onClick={() => setIsWorkflowSettingsOpen(false)}
|
||
className="rounded-md p-1.5 text-gray-500 hover:bg-white/5 hover:text-white transition-colors"
|
||
>
|
||
<X className="w-4 h-4" />
|
||
</button>
|
||
</div>
|
||
|
||
<div className="space-y-4 p-4">
|
||
{workflowSettingsReadOnly && (
|
||
<div className="flex items-start gap-2 rounded-lg border border-orange-500/20 bg-orange-500/10 px-3 py-2 text-[10px] text-orange-200">
|
||
<Lock className="mt-0.5 h-3 w-3 shrink-0" />
|
||
<span>流程正在执行,工作流级配置暂时锁定。</span>
|
||
</div>
|
||
)}
|
||
|
||
<div className="space-y-3 rounded-lg border border-pink-500/20 bg-pink-500/5 p-3">
|
||
<div className="flex items-center gap-2 text-pink-300">
|
||
<Shield className="h-3.5 w-3.5" />
|
||
<span className="text-[10px] font-bold uppercase">执行范围</span>
|
||
</div>
|
||
<div className="grid grid-cols-2 gap-2">
|
||
<button
|
||
type="button"
|
||
onClick={() => updateWorkflowSettings({ executionScope: "production" })}
|
||
disabled={workflowSettingsReadOnly}
|
||
className={cn(
|
||
"rounded-lg border px-3 py-2 text-left text-xs transition-colors disabled:opacity-50",
|
||
currentExecutionScope === "production"
|
||
? "border-pink-400/50 bg-pink-500/15 text-white"
|
||
: "border-[#2a2b2f] bg-[#0a0a0a] text-gray-400 hover:border-pink-400/30",
|
||
)}
|
||
>
|
||
<div className="font-semibold">生产</div>
|
||
<div className="mt-1 text-[10px] text-gray-500">只允许已发布算子</div>
|
||
</button>
|
||
<button
|
||
type="button"
|
||
onClick={() => updateWorkflowSettings({ executionScope: "sandbox" })}
|
||
disabled={workflowSettingsReadOnly}
|
||
className={cn(
|
||
"rounded-lg border px-3 py-2 text-left text-xs transition-colors disabled:opacity-50",
|
||
currentExecutionScope === "sandbox"
|
||
? "border-pink-400/50 bg-pink-500/15 text-white"
|
||
: "border-[#2a2b2f] bg-[#0a0a0a] text-gray-400 hover:border-pink-400/30",
|
||
)}
|
||
>
|
||
<div className="font-semibold">沙盒验证</div>
|
||
<div className="mt-1 text-[10px] text-gray-500">允许 AI 草稿验证</div>
|
||
</button>
|
||
</div>
|
||
</div>
|
||
|
||
{isScanWorkflow && (
|
||
<div className="space-y-4 rounded-lg border border-purple-500/20 bg-purple-500/5 p-3">
|
||
<div className="flex items-center justify-between gap-3">
|
||
<div className="flex items-center gap-2 text-purple-400">
|
||
<Clock className="w-3.5 h-3.5" />
|
||
<span className="text-[10px] font-bold uppercase">触发方式</span>
|
||
</div>
|
||
<button
|
||
type="button"
|
||
onClick={() => {
|
||
const scanSourceNode = nodes.find((node) => isScanSourceNode(node));
|
||
if (!scanSourceNode) {
|
||
return;
|
||
}
|
||
setSelectedNode(scanSourceNode as Node);
|
||
setIsConfigOpen(true);
|
||
setIsWorkflowSettingsOpen(false);
|
||
}}
|
||
className="rounded-md border border-purple-500/20 px-2 py-1 text-[10px] text-purple-200 hover:bg-purple-500/10 disabled:opacity-50"
|
||
disabled={!nodes.some((node) => isScanSourceNode(node))}
|
||
>
|
||
前往扫描源节点
|
||
</button>
|
||
</div>
|
||
<div className="space-y-2">
|
||
<label className="text-[9px] text-gray-500 uppercase font-mono">触发方式</label>
|
||
<div className="grid grid-cols-3 gap-2">
|
||
<button
|
||
type="button"
|
||
onClick={() =>
|
||
updateScanWorkflowConfig({
|
||
enabled: false,
|
||
interval: 0,
|
||
})
|
||
}
|
||
disabled={workflowSettingsReadOnly}
|
||
className={cn(
|
||
"rounded-lg border px-3 py-2 text-left transition-colors",
|
||
scanTriggerMode === "manual"
|
||
? "border-blue-500/50 bg-blue-500/10 text-blue-100"
|
||
: "border-[#2a2b2f] bg-[#0a0a0a] text-gray-300 hover:border-blue-500/30",
|
||
)}
|
||
>
|
||
<div className="text-xs font-semibold">手动执行</div>
|
||
<div className="mt-1 text-[10px] text-gray-500">只在点击运行时生成一次 run。</div>
|
||
</button>
|
||
<button
|
||
type="button"
|
||
onClick={() =>
|
||
updateScanWorkflowConfig({
|
||
enabled: true,
|
||
...buildScheduledWorkflowSchedule(
|
||
workflowConfigEntity.schedule || {},
|
||
workflowScheduleMode,
|
||
),
|
||
})
|
||
}
|
||
disabled={workflowSettingsReadOnly}
|
||
className={cn(
|
||
"rounded-lg border px-3 py-2 text-left transition-colors",
|
||
scanTriggerMode === "scheduled"
|
||
? "border-purple-500/50 bg-purple-500/10 text-purple-100"
|
||
: "border-[#2a2b2f] bg-[#0a0a0a] text-gray-300 hover:border-purple-500/30",
|
||
)}
|
||
>
|
||
<div className="text-xs font-semibold">周期执行</div>
|
||
<div className="mt-1 text-[10px] text-gray-500">按间隔反复触发新的 run。</div>
|
||
</button>
|
||
</div>
|
||
</div>
|
||
{scanTriggerMode === "scheduled" && (
|
||
<div className="space-y-3">
|
||
<div className="space-y-1">
|
||
<label className="text-[9px] text-gray-500 uppercase font-mono">调度方式</label>
|
||
<select
|
||
value={workflowScheduleMode}
|
||
onChange={(e) =>
|
||
updateScanWorkflowConfig({
|
||
enabled: true,
|
||
...buildScheduledWorkflowSchedule(
|
||
workflowConfigEntity.schedule || {},
|
||
e.target.value,
|
||
),
|
||
})
|
||
}
|
||
disabled={workflowSettingsReadOnly}
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs focus:outline-none focus:border-purple-500 disabled:opacity-50"
|
||
>
|
||
<option value="interval_seconds">按秒</option>
|
||
<option value="every_hours">按小时</option>
|
||
<option value="every_days_at_time">按天</option>
|
||
</select>
|
||
</div>
|
||
{workflowScheduleMode === "interval_seconds" && (
|
||
<div className="space-y-1">
|
||
<label className="text-[9px] text-gray-500 uppercase font-mono">调度间隔 (秒)</label>
|
||
<input
|
||
type="number"
|
||
min={1}
|
||
value={workflowSchedule.interval || 60}
|
||
onChange={(e) => {
|
||
const interval = positiveIntegerOrNotice(e.target.value, "schedule.interval");
|
||
if (interval === null) {
|
||
return;
|
||
}
|
||
updateScanWorkflowConfig({
|
||
enabled: true,
|
||
interval,
|
||
});
|
||
}}
|
||
disabled={workflowSettingsReadOnly}
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs focus:outline-none focus:border-purple-500 disabled:opacity-50"
|
||
/>
|
||
</div>
|
||
)}
|
||
{workflowScheduleMode === "every_hours" && (
|
||
<div className="space-y-1">
|
||
<label className="text-[9px] text-gray-500 uppercase font-mono">每 N 小时</label>
|
||
<input
|
||
type="number"
|
||
min={1}
|
||
value={workflowSchedule.intervalHours || 1}
|
||
onChange={(e) => {
|
||
const intervalHours = positiveIntegerOrNotice(
|
||
e.target.value,
|
||
"schedule.intervalHours",
|
||
);
|
||
if (intervalHours === null) {
|
||
return;
|
||
}
|
||
updateScanWorkflowConfig({
|
||
enabled: true,
|
||
intervalHours,
|
||
});
|
||
}}
|
||
disabled={workflowSettingsReadOnly}
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs focus:outline-none focus:border-purple-500 disabled:opacity-50"
|
||
/>
|
||
</div>
|
||
)}
|
||
{workflowScheduleMode === "every_days_at_time" && (
|
||
<div className="grid grid-cols-2 gap-2">
|
||
<div className="space-y-1">
|
||
<label className="text-[9px] text-gray-500 uppercase font-mono">每 N 天</label>
|
||
<input
|
||
type="number"
|
||
min={1}
|
||
value={workflowSchedule.dayInterval || 1}
|
||
onChange={(e) => {
|
||
const dayInterval = positiveIntegerOrNotice(
|
||
e.target.value,
|
||
"schedule.dayInterval",
|
||
);
|
||
if (dayInterval === null) {
|
||
return;
|
||
}
|
||
updateScanWorkflowConfig({
|
||
enabled: true,
|
||
dayInterval,
|
||
});
|
||
}}
|
||
disabled={workflowSettingsReadOnly}
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs focus:outline-none focus:border-purple-500 disabled:opacity-50"
|
||
/>
|
||
</div>
|
||
<div className="space-y-1">
|
||
<label className="text-[9px] text-gray-500 uppercase font-mono">执行时间</label>
|
||
<input
|
||
type="time"
|
||
value={workflowSchedule.timeOfDay || "09:00"}
|
||
onChange={(e) =>
|
||
updateScanWorkflowConfig({
|
||
enabled: true,
|
||
timeOfDay: e.target.value,
|
||
})
|
||
}
|
||
disabled={workflowSettingsReadOnly}
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs focus:outline-none focus:border-purple-500 disabled:opacity-50"
|
||
/>
|
||
</div>
|
||
</div>
|
||
)}
|
||
</div>
|
||
)}
|
||
<p className="text-[10px] text-gray-500">
|
||
如果流程使用扫描源算子,bucket、prefix、连接信息以及 FULL/INCREMENTAL
|
||
都在扫描源节点里配置;这里只控制触发方式和调度策略。
|
||
</p>
|
||
</div>
|
||
)}
|
||
|
||
{!isScanWorkflow && (
|
||
<div className="space-y-4 rounded-lg border border-purple-500/20 bg-purple-500/5 p-3">
|
||
<div className="flex items-center gap-2 text-purple-400">
|
||
<Clock className="w-3.5 h-3.5" />
|
||
<span className="text-[10px] font-bold uppercase">触发方式</span>
|
||
</div>
|
||
<div className="space-y-3">
|
||
<div className="grid grid-cols-2 gap-2">
|
||
<button
|
||
type="button"
|
||
onClick={() => updateWorkflowTriggerMode("manual")}
|
||
disabled={workflowSettingsReadOnly}
|
||
className={cn(
|
||
"rounded-lg border px-3 py-2 text-left transition-colors",
|
||
standardTriggerMode === "manual"
|
||
? "border-blue-500/50 bg-blue-500/10 text-blue-100"
|
||
: "border-[#2a2b2f] bg-[#0a0a0a] text-gray-300 hover:border-blue-500/30",
|
||
)}
|
||
>
|
||
<div className="text-xs font-semibold">手动执行</div>
|
||
<div className="mt-1 text-[10px] text-gray-500">只在点击运行时生成一次 run。</div>
|
||
</button>
|
||
<button
|
||
type="button"
|
||
onClick={() => updateWorkflowTriggerMode("scheduled")}
|
||
disabled={workflowSettingsReadOnly}
|
||
className={cn(
|
||
"rounded-lg border px-3 py-2 text-left transition-colors",
|
||
standardTriggerMode === "scheduled"
|
||
? "border-purple-500/50 bg-purple-500/10 text-purple-100"
|
||
: "border-[#2a2b2f] bg-[#0a0a0a] text-gray-300 hover:border-purple-500/30",
|
||
)}
|
||
>
|
||
<div className="text-xs font-semibold">周期执行</div>
|
||
<div className="mt-1 text-[10px] text-gray-500">按固定间隔重复创建新的 run。</div>
|
||
</button>
|
||
</div>
|
||
{standardTriggerMode === "scheduled" && (
|
||
<div className="space-y-3">
|
||
<div className="space-y-1">
|
||
<label className="text-[9px] text-gray-500 uppercase font-mono">调度方式</label>
|
||
<select
|
||
value={workflowScheduleMode}
|
||
onChange={(e) =>
|
||
updateWorkflowSchedule(
|
||
buildScheduledWorkflowSchedule(
|
||
workflowConfigEntity.schedule || {},
|
||
e.target.value,
|
||
),
|
||
)
|
||
}
|
||
disabled={workflowSettingsReadOnly}
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs focus:outline-none focus:border-purple-500 disabled:opacity-50"
|
||
>
|
||
<option value="interval_seconds">按秒</option>
|
||
<option value="every_hours">按小时</option>
|
||
<option value="every_days_at_time">按天</option>
|
||
</select>
|
||
</div>
|
||
{workflowScheduleMode === "interval_seconds" && (
|
||
<div className="space-y-1">
|
||
<label className="text-[9px] text-gray-500 uppercase font-mono">
|
||
调度间隔 (秒)
|
||
</label>
|
||
<input
|
||
type="number"
|
||
min={1}
|
||
value={workflowSchedule.interval || 60}
|
||
onChange={(e) => {
|
||
const interval = positiveIntegerOrNotice(e.target.value, "schedule.interval");
|
||
if (interval === null) {
|
||
return;
|
||
}
|
||
updateWorkflowSchedule({
|
||
interval,
|
||
});
|
||
}}
|
||
disabled={workflowSettingsReadOnly}
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs focus:outline-none focus:border-purple-500 disabled:opacity-50"
|
||
/>
|
||
</div>
|
||
)}
|
||
{workflowScheduleMode === "every_hours" && (
|
||
<div className="space-y-1">
|
||
<label className="text-[9px] text-gray-500 uppercase font-mono">每 N 小时</label>
|
||
<input
|
||
type="number"
|
||
min={1}
|
||
value={workflowSchedule.intervalHours || 1}
|
||
onChange={(e) => {
|
||
const intervalHours = positiveIntegerOrNotice(
|
||
e.target.value,
|
||
"schedule.intervalHours",
|
||
);
|
||
if (intervalHours === null) {
|
||
return;
|
||
}
|
||
updateWorkflowSchedule({
|
||
intervalHours,
|
||
});
|
||
}}
|
||
disabled={workflowSettingsReadOnly}
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs focus:outline-none focus:border-purple-500 disabled:opacity-50"
|
||
/>
|
||
</div>
|
||
)}
|
||
{workflowScheduleMode === "every_days_at_time" && (
|
||
<div className="grid grid-cols-2 gap-2">
|
||
<div className="space-y-1">
|
||
<label className="text-[9px] text-gray-500 uppercase font-mono">每 N 天</label>
|
||
<input
|
||
type="number"
|
||
min={1}
|
||
value={workflowSchedule.dayInterval || 1}
|
||
onChange={(e) => {
|
||
const dayInterval = positiveIntegerOrNotice(
|
||
e.target.value,
|
||
"schedule.dayInterval",
|
||
);
|
||
if (dayInterval === null) {
|
||
return;
|
||
}
|
||
updateWorkflowSchedule({
|
||
dayInterval,
|
||
});
|
||
}}
|
||
disabled={workflowSettingsReadOnly}
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs focus:outline-none focus:border-purple-500 disabled:opacity-50"
|
||
/>
|
||
</div>
|
||
<div className="space-y-1">
|
||
<label className="text-[9px] text-gray-500 uppercase font-mono">执行时间</label>
|
||
<input
|
||
type="time"
|
||
value={workflowSchedule.timeOfDay || "09:00"}
|
||
onChange={(e) =>
|
||
updateWorkflowSchedule({
|
||
timeOfDay: e.target.value,
|
||
})
|
||
}
|
||
disabled={workflowSettingsReadOnly}
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs focus:outline-none focus:border-purple-500 disabled:opacity-50"
|
||
/>
|
||
</div>
|
||
</div>
|
||
)}
|
||
</div>
|
||
)}
|
||
<p className="text-[10px] text-gray-500">
|
||
工作流配置只控制触发策略。数据输入、连接信息和增量逻辑应放在具体算子节点中配置。
|
||
</p>
|
||
</div>
|
||
</div>
|
||
)}
|
||
|
||
<div className="space-y-4 rounded-lg border border-sky-500/20 bg-sky-500/5 p-3">
|
||
<div className="flex items-center justify-between gap-2">
|
||
<div className="flex items-center gap-2 text-sky-400">
|
||
<Terminal className="w-3.5 h-3.5" />
|
||
<span className="text-[10px] font-bold uppercase">全局环境变量</span>
|
||
</div>
|
||
<button
|
||
type="button"
|
||
onClick={appendWorkflowHyperparam}
|
||
disabled={workflowSettingsReadOnly}
|
||
className="inline-flex items-center gap-1 rounded-md border border-sky-500/20 px-2 py-1 text-[10px] text-sky-200 hover:bg-sky-500/10 disabled:opacity-50"
|
||
>
|
||
<Plus className="h-3 w-3" />
|
||
新增
|
||
</button>
|
||
</div>
|
||
<p className="text-[10px] text-gray-500 leading-relaxed">
|
||
这里配置的 env 会注入到全部算子节点。模板中的配置会被实例化继承;如果某个节点配置了同名
|
||
env,则以节点级配置为准。
|
||
</p>
|
||
{workflowLevelEnvDuplicates.size > 0 && (
|
||
<div className="rounded-lg border border-red-500/20 bg-red-500/10 px-3 py-2 text-[10px] text-red-200">
|
||
存在重复环境变量 key:{Array.from(workflowLevelEnvDuplicates).join("、")}
|
||
。请先去重后再保存、运行或导出模板。
|
||
</div>
|
||
)}
|
||
<div className="space-y-2">
|
||
{workflowLevelHyperparams.length === 0 && (
|
||
<div className="rounded-lg border border-dashed border-sky-500/20 px-3 py-3 text-[10px] text-gray-500">
|
||
尚未配置工作流级环境变量。
|
||
</div>
|
||
)}
|
||
{workflowLevelHyperparams.map((item, index) => {
|
||
const isDuplicate = workflowLevelEnvDuplicates.has(normalizeWorkflowEnvKey(item?.key));
|
||
return (
|
||
<div
|
||
key={`workflow-env-${index}`}
|
||
className={cn(
|
||
"space-y-2 rounded-lg border px-3 py-3",
|
||
isDuplicate ? "border-red-500/30 bg-red-500/5" : "border-sky-500/20 bg-[#0f1720]/40",
|
||
)}
|
||
>
|
||
<div className="flex items-center justify-between gap-2">
|
||
<span className="text-[9px] font-mono uppercase tracking-wider text-gray-500">
|
||
ENV #{index + 1}
|
||
</span>
|
||
<button
|
||
type="button"
|
||
onClick={() => removeWorkflowHyperparam(index)}
|
||
disabled={workflowSettingsReadOnly}
|
||
className="rounded-md p-1 text-gray-500 hover:bg-white/5 hover:text-white disabled:opacity-50"
|
||
>
|
||
<X className="h-3 w-3" />
|
||
</button>
|
||
</div>
|
||
<div className="space-y-1">
|
||
<label className="text-[9px] text-gray-500 uppercase font-mono">Key</label>
|
||
<input
|
||
type="text"
|
||
value={item?.key || ""}
|
||
onChange={(e) => updateWorkflowHyperparamField(index, "key", e.target.value)}
|
||
disabled={workflowSettingsReadOnly}
|
||
className={cn(
|
||
"w-full rounded border bg-[#0a0a0a] px-2 py-1 text-xs font-mono focus:outline-none disabled:opacity-50",
|
||
isDuplicate
|
||
? "border-red-500/40 focus:border-red-500"
|
||
: "border-[#2a2b2f] focus:border-sky-500",
|
||
)}
|
||
placeholder="GLOBAL_ENV"
|
||
/>
|
||
</div>
|
||
<div className="space-y-1">
|
||
<label className="text-[9px] text-gray-500 uppercase font-mono">Value</label>
|
||
<input
|
||
type="text"
|
||
value={item?.value || ""}
|
||
onChange={(e) => updateWorkflowHyperparamField(index, "value", e.target.value)}
|
||
disabled={workflowSettingsReadOnly}
|
||
className="w-full rounded border border-[#2a2b2f] bg-[#0a0a0a] px-2 py-1 text-xs font-mono focus:outline-none focus:border-sky-500 disabled:opacity-50"
|
||
placeholder="shared-value"
|
||
/>
|
||
</div>
|
||
</div>
|
||
);
|
||
})}
|
||
</div>
|
||
</div>
|
||
|
||
<div className="space-y-4 rounded-lg border border-blue-500/20 bg-blue-500/5 p-3">
|
||
<div className="flex items-center gap-2 text-blue-400">
|
||
<Cpu className="w-3.5 h-3.5" />
|
||
<span className="text-[10px] font-bold uppercase">运行并发设置</span>
|
||
</div>
|
||
<div className="space-y-1">
|
||
<label className="text-[9px] text-gray-500 uppercase font-mono">工作流最大并发数</label>
|
||
<input
|
||
type="number"
|
||
min={0}
|
||
value={workflowConfigEntity.maxConcurrentRuns ?? 0}
|
||
onChange={(e) => {
|
||
const maxConcurrentRuns = nonNegativeIntegerOrNotice(e.target.value, "maxConcurrentRuns");
|
||
if (maxConcurrentRuns === null) {
|
||
return;
|
||
}
|
||
updateWorkflowSettings({
|
||
maxConcurrentRuns,
|
||
});
|
||
}}
|
||
disabled={workflowSettingsReadOnly}
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs focus:outline-none focus:border-blue-500 disabled:opacity-50"
|
||
/>
|
||
<p className="text-[10px] text-gray-500">
|
||
设为 `0`
|
||
表示继承系统默认并发数;会影响当前工作流的排队调度,以及单次执行里可同时运行的分支节点数。
|
||
</p>
|
||
</div>
|
||
</div>
|
||
|
||
<div className="space-y-4 rounded-lg border border-emerald-500/20 bg-emerald-500/5 p-3">
|
||
<div className="flex items-center gap-2 text-emerald-400">
|
||
<Clock className="w-3.5 h-3.5" />
|
||
<span className="text-[10px] font-bold uppercase">执行保障</span>
|
||
</div>
|
||
<div className="space-y-3">
|
||
<div className="space-y-1">
|
||
<label className="text-[9px] text-gray-500 uppercase font-mono">单节点超时 (秒)</label>
|
||
<input
|
||
type="number"
|
||
min={0}
|
||
value={workflowConfigEntity.nodeTimeoutSeconds ?? 0}
|
||
onChange={(e) => {
|
||
const nodeTimeoutSeconds = nonNegativeIntegerOrNotice(
|
||
e.target.value,
|
||
"nodeTimeoutSeconds",
|
||
);
|
||
if (nodeTimeoutSeconds === null) {
|
||
return;
|
||
}
|
||
updateWorkflowSettings({
|
||
nodeTimeoutSeconds,
|
||
});
|
||
}}
|
||
disabled={workflowSettingsReadOnly}
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs focus:outline-none focus:border-emerald-500 disabled:opacity-50"
|
||
/>
|
||
<p className="text-[10px] text-gray-500">
|
||
设为 `0` 表示不启用单节点超时;超时后当前节点失败,整条 run 按失败处理。
|
||
</p>
|
||
</div>
|
||
|
||
<div className="space-y-1">
|
||
<label className="text-[9px] text-gray-500 uppercase font-mono">运行超时 (秒)</label>
|
||
<input
|
||
type="number"
|
||
min={0}
|
||
value={workflowConfigEntity.runTimeoutSeconds ?? 0}
|
||
onChange={(e) => {
|
||
const runTimeoutSeconds = nonNegativeIntegerOrNotice(
|
||
e.target.value,
|
||
"runTimeoutSeconds",
|
||
);
|
||
if (runTimeoutSeconds === null) {
|
||
return;
|
||
}
|
||
updateWorkflowSettings({
|
||
runTimeoutSeconds,
|
||
});
|
||
}}
|
||
disabled={workflowSettingsReadOnly}
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs focus:outline-none focus:border-emerald-500 disabled:opacity-50"
|
||
/>
|
||
<p className="text-[10px] text-gray-500">
|
||
设为 `0` 表示不启用工作流级超时;超时后当前 run 会真实失败。
|
||
</p>
|
||
</div>
|
||
|
||
<div className="space-y-1">
|
||
<label className="text-[9px] text-gray-500 uppercase font-mono">失败自动重试次数</label>
|
||
<div className="relative">
|
||
<RotateCcw className="absolute left-2 top-1/2 -translate-y-1/2 h-3 w-3 text-gray-600" />
|
||
<input
|
||
type="number"
|
||
min={0}
|
||
value={workflowConfigEntity.maxRetryAttempts ?? 0}
|
||
onChange={(e) => {
|
||
const maxRetryAttempts = nonNegativeIntegerOrNotice(
|
||
e.target.value,
|
||
"maxRetryAttempts",
|
||
);
|
||
if (maxRetryAttempts === null) {
|
||
return;
|
||
}
|
||
updateWorkflowSettings({
|
||
maxRetryAttempts,
|
||
});
|
||
}}
|
||
disabled={workflowSettingsReadOnly}
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded pl-7 pr-2 py-1 text-xs focus:outline-none focus:border-emerald-500 disabled:opacity-50"
|
||
/>
|
||
</div>
|
||
<p className="text-[10px] text-gray-500">
|
||
设为 `0` 表示失败后不自动重试;重试会创建新的 retry run。
|
||
</p>
|
||
</div>
|
||
|
||
<div className="space-y-1">
|
||
<label className="text-[9px] text-gray-500 uppercase font-mono">失败重试间隔 (秒)</label>
|
||
<input
|
||
type="number"
|
||
min={0}
|
||
value={workflowConfigEntity.retryBackoffSeconds ?? 0}
|
||
onChange={(e) => {
|
||
const retryBackoffSeconds = nonNegativeIntegerOrNotice(
|
||
e.target.value,
|
||
"retryBackoffSeconds",
|
||
);
|
||
if (retryBackoffSeconds === null) {
|
||
return;
|
||
}
|
||
updateWorkflowSettings({
|
||
retryBackoffSeconds,
|
||
});
|
||
}}
|
||
disabled={workflowSettingsReadOnly}
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs focus:outline-none focus:border-emerald-500 disabled:opacity-50"
|
||
/>
|
||
<p className="text-[10px] text-gray-500">
|
||
设为 `0` 表示失败后立刻进入下一次 retry run;大于 `0` 时会按秒数延迟重试调度。
|
||
</p>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</motion.div>
|
||
)}
|
||
</AnimatePresence>
|
||
</div>
|
||
)}
|
||
{canManage &&
|
||
(!isTemplate && workflowEntity ? (
|
||
<button
|
||
onClick={() => navigate(workflowAssetsPath)}
|
||
className="flex items-center gap-2 px-3 py-1.5 text-xs font-medium rounded-md transition-colors text-gray-400 hover:text-white hover:bg-white/5"
|
||
>
|
||
<Database className="w-4 h-4" />
|
||
相关数据资产
|
||
</button>
|
||
) : null)}
|
||
{canManage && (
|
||
<button
|
||
onClick={openExportTemplateModal}
|
||
disabled={nodes.length === 0 || hasBlockingGraphIssue}
|
||
title={hasBlockingGraphIssue ? blockingGraphIssueMessage : undefined}
|
||
className={cn(
|
||
"flex items-center gap-2 px-3 py-1.5 text-xs font-medium rounded-md transition-colors",
|
||
nodes.length > 0 && !hasBlockingGraphIssue
|
||
? "text-gray-400 hover:text-white hover:bg-white/5"
|
||
: "text-gray-600 cursor-not-allowed",
|
||
)}
|
||
>
|
||
<Download className="w-4 h-4" />
|
||
导出模板
|
||
</button>
|
||
)}
|
||
{!isReadOnly && canManage && (
|
||
<WorkflowSaveControl
|
||
state={saveState}
|
||
error={saveError}
|
||
blocked={hasBlockingGraphIssue}
|
||
blockedMessage={blockingGraphIssueMessage}
|
||
onSave={() => void handleSave()}
|
||
/>
|
||
)}
|
||
{!isReadOnly && canManage && (
|
||
<button
|
||
onClick={deleteSelectedCanvasElements}
|
||
disabled={!hasCanvasSelection}
|
||
className={cn(
|
||
"flex items-center gap-2 px-3 py-1.5 text-xs font-medium rounded-md transition-colors",
|
||
hasCanvasSelection
|
||
? "text-red-300 hover:text-white hover:bg-red-500/10"
|
||
: "text-gray-600 cursor-not-allowed",
|
||
)}
|
||
title="选中节点或连线后删除"
|
||
>
|
||
<X className="w-4 h-4" />
|
||
删除选中
|
||
</button>
|
||
)}
|
||
{canManage && workflowEntity && (
|
||
<WorkflowRunControl
|
||
action={runAction}
|
||
onRun={() => void handleRun()}
|
||
title={
|
||
runAction.reason === "invalidConnections"
|
||
? duplicateInputConnectionMessage
|
||
: runAction.reason === "invalidGraph"
|
||
? runAction.message
|
||
: runAction.reason === "gpuUnavailable" ||
|
||
runAction.reason === "gpuInsufficient" ||
|
||
runAction.reason === "gpuCapacityUnavailable"
|
||
? runAction.message
|
||
: undefined
|
||
}
|
||
/>
|
||
)}
|
||
{workflowEntity && scheduledHistoryEnabled && (
|
||
<button
|
||
onClick={() => setIsRunHistoryOpen((current) => !current)}
|
||
className={cn(
|
||
"flex items-center gap-2 px-3 py-1.5 text-xs font-medium rounded-md transition-colors border",
|
||
isRunHistoryOpen
|
||
? "border-cyan-500/40 bg-cyan-500/10 text-cyan-100"
|
||
: "border-[#2a2b2f] text-gray-300 hover:border-cyan-500/30 hover:bg-cyan-500/10 hover:text-cyan-100",
|
||
)}
|
||
>
|
||
<Clock className="w-4 h-4" />
|
||
周期运行记录
|
||
</button>
|
||
)}
|
||
{canManage && activeRun && activeRunInFlight && (
|
||
<button
|
||
onClick={handleGracefulStop}
|
||
disabled={runStopPending !== "" || activeRunStatus === "stopping"}
|
||
className={cn(
|
||
"flex items-center gap-2 px-4 py-1.5 text-xs font-medium rounded-md transition-all",
|
||
runStopPending !== "" || activeRunStatus === "stopping"
|
||
? "bg-amber-500/20 text-amber-200/60 cursor-not-allowed"
|
||
: "bg-amber-500/15 hover:bg-amber-500/25 text-amber-100 border border-amber-500/30",
|
||
)}
|
||
>
|
||
{runStopPending === "graceful" ? (
|
||
<Loader2 className="w-4 h-4 animate-spin" />
|
||
) : (
|
||
<Clock className="w-4 h-4" />
|
||
)}
|
||
{activeRunStatus === "stopping" ? "停止中" : "停止"}
|
||
</button>
|
||
)}
|
||
{canManage && activeRun && activeRunInFlight && (
|
||
<button
|
||
onClick={handleForceStop}
|
||
disabled={runStopPending !== ""}
|
||
className={cn(
|
||
"flex items-center gap-2 px-4 py-1.5 text-xs font-medium rounded-md transition-all",
|
||
runStopPending !== ""
|
||
? "bg-red-500/20 text-red-200/60 cursor-not-allowed"
|
||
: "bg-red-500/15 hover:bg-red-500/25 text-red-100 border border-red-500/30",
|
||
)}
|
||
>
|
||
{runStopPending === "force" ? <Loader2 className="w-4 h-4 animate-spin" /> : <X className="w-4 h-4" />}
|
||
强制停止
|
||
</button>
|
||
)}
|
||
</div>
|
||
</div>
|
||
|
||
{editorLoadError && (
|
||
<div className="shrink-0 border-b border-red-500/20 bg-red-500/10 px-6 py-2 text-[11px] text-red-200 flex items-center justify-between gap-3">
|
||
<span>{editorLoadError}</span>
|
||
<button
|
||
type="button"
|
||
onClick={() => setEditorReloadToken((current) => current + 1)}
|
||
className="rounded-md border border-red-400/30 px-3 py-1 font-medium hover:bg-red-500/10"
|
||
>
|
||
重新加载
|
||
</button>
|
||
</div>
|
||
)}
|
||
|
||
{draftRecovery && (
|
||
<div className="shrink-0 border-b border-amber-500/20 bg-amber-500/10 px-6 py-2.5 text-[11px] text-amber-100 flex flex-wrap items-center justify-between gap-3">
|
||
<span>
|
||
{draftRecovery.conflict
|
||
? "检测到本地草稿,但服务器版本已变化。请选择恢复草稿、保留服务器版本或另存副本。"
|
||
: "检测到上次未保存的本地草稿,是否恢复?"}
|
||
</span>
|
||
<div className="flex items-center gap-2">
|
||
<button
|
||
type="button"
|
||
onClick={restoreStoredDraft}
|
||
className="rounded-md border border-amber-400/40 bg-amber-500/10 px-3 py-1 font-medium hover:bg-amber-500/20"
|
||
>
|
||
恢复本地草稿
|
||
</button>
|
||
<button
|
||
type="button"
|
||
onClick={discardStoredDraft}
|
||
className="rounded-md border border-[#45413a] px-3 py-1 font-medium text-gray-300 hover:bg-white/5"
|
||
>
|
||
保留服务器版本
|
||
</button>
|
||
<button
|
||
type="button"
|
||
onClick={saveStoredDraftAsCopy}
|
||
disabled={isSavingDraftCopy}
|
||
className="rounded-md border border-blue-400/30 px-3 py-1 font-medium text-blue-200 hover:bg-blue-500/10 disabled:opacity-50"
|
||
>
|
||
{isSavingDraftCopy ? "另存中…" : "另存副本"}
|
||
</button>
|
||
</div>
|
||
</div>
|
||
)}
|
||
|
||
{saveError && !draftRecovery && (
|
||
<div className="shrink-0 border-b border-red-500/20 bg-red-500/10 px-6 py-2 text-[11px] text-red-200">
|
||
保存失败:{saveError}。本地草稿已保留,可修改后重试。
|
||
</div>
|
||
)}
|
||
|
||
<AnimatePresence initial={false}>
|
||
{(activeRun || activeRunError) && (
|
||
<motion.div
|
||
initial={{ opacity: 0, y: -8 }}
|
||
animate={{ opacity: 1, y: 0 }}
|
||
exit={{ opacity: 0, y: -8 }}
|
||
className="shrink-0 border-b border-[#2a2b2f] bg-[#0f1117]/95 backdrop-blur"
|
||
>
|
||
<div className="px-6 py-3 flex flex-wrap items-center justify-between gap-3">
|
||
<div className="flex flex-col gap-2">
|
||
{activeRun && (
|
||
<div className="flex flex-wrap items-center gap-2 text-[11px]">
|
||
<span
|
||
className={cn(
|
||
"rounded-full border px-2 py-1 font-semibold tracking-wide",
|
||
runStatusClasses[activeRunStatus || activeRun.status] ||
|
||
"border-slate-500/40 bg-slate-500/10 text-slate-200",
|
||
)}
|
||
>
|
||
{runStatusLabels[activeRunStatus || activeRun.status] || activeRunStatus || activeRun.status}
|
||
</span>
|
||
<span className="font-mono text-gray-400">Run {activeRun.id}</span>
|
||
<span className="rounded-full border border-cyan-500/20 bg-cyan-500/10 px-2 py-1 text-cyan-100">
|
||
{runTriggerLabels[activeRun.trigger] || activeRun.trigger}
|
||
</span>
|
||
{activeRun.restartFromNodeId && (
|
||
<span className="text-gray-300">
|
||
重跑起点: <span className="font-mono text-white">{activeRun.restartFromNodeId}</span>
|
||
</span>
|
||
)}
|
||
{activeRunCurrentNodeLabel && (
|
||
<span className="text-gray-300">
|
||
当前节点: <span className="text-white">{activeRunCurrentNodeLabel}</span>
|
||
</span>
|
||
)}
|
||
</div>
|
||
)}
|
||
{activeRunError && <div className="text-[11px] text-red-300">{activeRunError}</div>}
|
||
{activeRun && (
|
||
<div className="text-[10px] text-gray-500">
|
||
运行会停留在当前画布,节点高亮和连线动画会实时反映真实执行进度。
|
||
</div>
|
||
)}
|
||
</div>
|
||
|
||
<div className="flex items-center gap-2">
|
||
{activeRun && (
|
||
<button
|
||
onClick={() => navigate(`/monitoring?runId=${encodeURIComponent(activeRun.id)}`)}
|
||
className="rounded-md border border-[#2a2b2f] px-3 py-1.5 text-[11px] font-medium text-gray-300 hover:border-blue-500/40 hover:text-white hover:bg-blue-500/10 transition-colors"
|
||
>
|
||
查看执行监控
|
||
</button>
|
||
)}
|
||
{activeRun && !activeRunInFlight && (
|
||
<button
|
||
onClick={() => {
|
||
setActiveRun(null);
|
||
setActiveRunError("");
|
||
}}
|
||
className="rounded-md border border-[#2a2b2f] px-3 py-1.5 text-[11px] font-medium text-gray-500 hover:text-white hover:bg-white/5 transition-colors"
|
||
>
|
||
收起结果
|
||
</button>
|
||
)}
|
||
</div>
|
||
</div>
|
||
{activeHoloBrainSummary && (
|
||
<div className="px-6 pb-3">
|
||
<HoloBrainTrainingReportCard summary={activeHoloBrainSummary} compact collapsible />
|
||
</div>
|
||
)}
|
||
</motion.div>
|
||
)}
|
||
</AnimatePresence>
|
||
|
||
<AnimatePresence initial={false}>
|
||
{scheduledHistoryEnabled && isRunHistoryOpen && (
|
||
<motion.div
|
||
initial={{ opacity: 0, y: -8 }}
|
||
animate={{ opacity: 1, y: 0 }}
|
||
exit={{ opacity: 0, y: -8 }}
|
||
className="shrink-0 border-b border-[#2a2b2f] bg-[#0c1117]/95 backdrop-blur"
|
||
>
|
||
<div className="px-6 py-3 space-y-3">
|
||
<div className="flex flex-wrap items-center justify-between gap-3">
|
||
<div>
|
||
<div className="text-[11px] font-semibold text-cyan-100">周期运行记录</div>
|
||
<div className="text-[10px] text-gray-500">
|
||
查看该周期工作流的实际运行历史,并在失败 run 上从任意节点重新执行下游子链路。
|
||
</div>
|
||
</div>
|
||
<div className="flex items-center gap-2">
|
||
<button
|
||
onClick={() => void loadWorkflowRuns()}
|
||
className="rounded-md border border-[#2a2b2f] px-3 py-1.5 text-[11px] font-medium text-gray-300 hover:border-cyan-500/30 hover:bg-cyan-500/10 hover:text-cyan-100 transition-colors"
|
||
>
|
||
刷新
|
||
</button>
|
||
<button
|
||
onClick={() => setIsRunHistoryOpen(false)}
|
||
className="rounded-md border border-[#2a2b2f] px-3 py-1.5 text-[11px] font-medium text-gray-500 hover:text-white hover:bg-white/5 transition-colors"
|
||
>
|
||
收起
|
||
</button>
|
||
</div>
|
||
</div>
|
||
|
||
{workflowRunsError && (
|
||
<div className="rounded border border-red-500/20 bg-red-500/10 px-3 py-2 text-[11px] text-red-200">
|
||
{workflowRunsError}
|
||
</div>
|
||
)}
|
||
|
||
{isWorkflowRunsLoading ? (
|
||
<div className="rounded border border-cyan-500/20 bg-cyan-500/5 px-3 py-3 text-[11px] text-cyan-100">
|
||
正在加载周期运行记录...
|
||
</div>
|
||
) : workflowRuns.length === 0 ? (
|
||
<div className="rounded border border-[#2a2b2f] bg-[#090b10] px-3 py-3 text-[11px] text-gray-400">
|
||
当前工作流还没有周期运行记录。
|
||
</div>
|
||
) : (
|
||
<div className="grid gap-2 md:grid-cols-2 xl:grid-cols-3">
|
||
{workflowRuns.map((run) => {
|
||
const isActiveRun = activeRun?.id === run.id;
|
||
return (
|
||
<button
|
||
key={run.id}
|
||
type="button"
|
||
onClick={() => void handleSelectWorkflowRun(run.id)}
|
||
className={cn(
|
||
"rounded-lg border px-3 py-3 text-left transition-colors",
|
||
isActiveRun
|
||
? "border-cyan-500/40 bg-cyan-500/10"
|
||
: "border-[#2a2b2f] bg-[#090b10] hover:border-cyan-500/30 hover:bg-cyan-500/5",
|
||
)}
|
||
>
|
||
<div className="flex flex-wrap items-center gap-2 text-[10px]">
|
||
<span
|
||
className={cn(
|
||
"rounded-full border px-2 py-0.5 font-semibold",
|
||
runStatusClasses[run.status] || "border-slate-500/40 bg-slate-500/10 text-slate-200",
|
||
)}
|
||
>
|
||
{runStatusLabels[run.status] || run.status}
|
||
</span>
|
||
<span className="rounded-full border border-cyan-500/20 bg-cyan-500/10 px-2 py-0.5 text-cyan-100">
|
||
{runTriggerLabels[run.trigger] || run.trigger}
|
||
</span>
|
||
<span className="font-mono text-gray-500">Run {run.id}</span>
|
||
</div>
|
||
<div className="mt-2 space-y-1 text-[10px] text-gray-400">
|
||
<div>创建于 {formatCompactDateTime(run.createdAt, timeZone, "--")}</div>
|
||
<div>状态节点 {run.currentNodeId || "--"}</div>
|
||
<div>尝试次数 {run.attempt || 1}</div>
|
||
{run.parentRunId && <div className="break-all">父运行 {run.parentRunId}</div>}
|
||
{run.restartFromNodeId && <div>重跑起点 {run.restartFromNodeId}</div>}
|
||
{run.error && <div className="line-clamp-2 text-red-200">{run.error}</div>}
|
||
</div>
|
||
</button>
|
||
);
|
||
})}
|
||
</div>
|
||
)}
|
||
</div>
|
||
</motion.div>
|
||
)}
|
||
</AnimatePresence>
|
||
|
||
{hasBlockingGraphIssue && (
|
||
<div className="shrink-0 border-b border-red-500/20 bg-red-500/10 px-6 py-2 text-[11px] text-red-100">
|
||
{blockingGraphIssueMessage}
|
||
</div>
|
||
)}
|
||
|
||
{canvasNotice && (
|
||
<div className="shrink-0 border-b border-[#2a2b2f] bg-amber-500/10 px-6 py-2 text-[11px] text-amber-100">
|
||
{canvasNotice}
|
||
</div>
|
||
)}
|
||
|
||
<div className="flex-1 relative bg-[#0a0a0a] flex overflow-hidden">
|
||
{/* Left Sidebar: Operator Library */}
|
||
<motion.div
|
||
initial={false}
|
||
animate={{ width: isLibOpen ? 256 : 48 }}
|
||
className="bg-[#151619] border-r border-[#2a2b2f] flex flex-col overflow-hidden shrink-0 relative"
|
||
>
|
||
{/* Toggle Button */}
|
||
<button
|
||
onClick={() => setIsLibOpen(!isLibOpen)}
|
||
className="absolute -right-3 top-1/2 -translate-y-1/2 z-50 w-6 h-12 bg-[#2a2b2f] border border-[#3a3b3f] rounded-full flex items-center justify-center text-gray-400 hover:text-white transition-colors shadow-xl"
|
||
>
|
||
{isLibOpen ? <ChevronLeft className="w-4 h-4" /> : <ChevronRight className="w-4 h-4" />}
|
||
</button>
|
||
|
||
{isLibOpen ? (
|
||
<>
|
||
<div className="p-4 border-b border-[#2a2b2f] flex items-center justify-between">
|
||
<div>
|
||
<h3 className="text-xs font-bold text-white uppercase tracking-wider">算子库</h3>
|
||
<div data-testid="operator-library-count" className="mt-1 text-[10px] text-gray-500">
|
||
{filteredOperators.length} / {operators.length} 个算子
|
||
</div>
|
||
</div>
|
||
<Box className="w-4 h-4 text-gray-500" />
|
||
</div>
|
||
<div className="p-3">
|
||
<div className="relative">
|
||
<Search className="absolute left-2 top-1/2 -translate-y-1/2 w-3 h-3 text-gray-600" />
|
||
<input
|
||
type="text"
|
||
placeholder="搜索算子..."
|
||
value={operatorSearchQuery}
|
||
onChange={(event) => setOperatorSearchQuery(event.target.value)}
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-7 py-1.5 text-[10px] focus:outline-none focus:border-blue-500"
|
||
/>
|
||
</div>
|
||
</div>
|
||
<div className="flex-1 overflow-y-auto p-3 space-y-4">
|
||
{operatorLibrarySections.map(({ category, operators: categoryOperators }) => {
|
||
return (
|
||
<div key={category} className="space-y-2">
|
||
<div className="flex items-center justify-between px-1">
|
||
<div className="text-[9px] font-bold text-gray-600 uppercase tracking-widest">{category}</div>
|
||
<div className="text-[9px] text-gray-600">{categoryOperators.length}</div>
|
||
</div>
|
||
<div className="space-y-1">
|
||
{categoryOperators.map((op) => {
|
||
const operatorUsable = canUseOperatorInWorkflow(op, currentExecutionScope);
|
||
const aiOperator = isAIGeneratedOperator(op);
|
||
return (
|
||
<div
|
||
key={op.id}
|
||
data-testid="operator-library-item"
|
||
data-operator-name={op.name}
|
||
draggable={!isReadOnly && canManage && operatorUsable}
|
||
onDragStart={(event) => handleOperatorDragStart(event, op)}
|
||
onDragEnd={handleOperatorDragEnd}
|
||
className={cn(
|
||
"group p-2 bg-[#0a0a0a] border border-[#2a2b2f] rounded-lg transition-all",
|
||
operatorUsable && "hover:border-blue-500/50",
|
||
!isReadOnly && canManage && operatorUsable
|
||
? "cursor-grab active:cursor-grabbing"
|
||
: "cursor-default opacity-60",
|
||
)}
|
||
>
|
||
<div className="flex items-center justify-between mb-1">
|
||
<div className="flex items-center gap-2 min-w-0">
|
||
{!isReadOnly && canManage && operatorUsable && (
|
||
<GripVertical className="w-3 h-3 shrink-0 text-gray-700 group-hover:text-blue-500" />
|
||
)}
|
||
<span className="truncate text-[10px] font-bold text-gray-300 group-hover:text-blue-400">
|
||
{op.name}
|
||
</span>
|
||
</div>
|
||
<button
|
||
type="button"
|
||
onClick={(event) => {
|
||
event.stopPropagation();
|
||
addOperatorToCanvas(op);
|
||
}}
|
||
disabled={isReadOnly || !canManage || !operatorUsable}
|
||
className={cn(
|
||
"rounded p-0.5 transition-colors",
|
||
!isReadOnly && canManage && operatorUsable
|
||
? "text-gray-700 group-hover:text-blue-500 hover:bg-blue-500/10"
|
||
: "text-gray-800 cursor-not-allowed",
|
||
)}
|
||
title={
|
||
operatorUsable
|
||
? !isReadOnly && canManage
|
||
? "点击添加到画布"
|
||
: "当前不可编辑"
|
||
: "未发布 AI 生成算子只能用于沙盒验证"
|
||
}
|
||
>
|
||
<Plus className="w-3 h-3" />
|
||
</button>
|
||
</div>
|
||
{aiOperator && (
|
||
<div className="mb-1 inline-flex rounded border border-pink-400/25 bg-pink-500/10 px-1.5 py-0.5 text-[8px] font-semibold text-pink-200">
|
||
AI {publicationStatusLabel(operatorPublicationStatus(op))}
|
||
</div>
|
||
)}
|
||
<p className="text-[9px] text-gray-600 line-clamp-1">{op.description}</p>
|
||
{!isReadOnly && canManage && operatorUsable && (
|
||
<div className="mt-1 text-[9px] text-gray-700 group-hover:text-gray-500">
|
||
拖到画布添加
|
||
</div>
|
||
)}
|
||
{!operatorUsable && (
|
||
<div className="mt-1 text-[9px] text-pink-300/80">生产不可用,切换沙盒后可验证</div>
|
||
)}
|
||
</div>
|
||
);
|
||
})}
|
||
</div>
|
||
</div>
|
||
);
|
||
})}
|
||
{filteredOperators.length === 0 && (
|
||
<div className="rounded-lg border border-dashed border-[#2a2b2f] bg-[#0a0a0a] px-3 py-6 text-center text-[10px] text-gray-500">
|
||
没有匹配的算子,请调整搜索条件。
|
||
</div>
|
||
)}
|
||
</div>
|
||
</>
|
||
) : (
|
||
<div className="flex flex-col items-center py-6 gap-8">
|
||
<Box className="w-5 h-5 text-blue-500" />
|
||
<div className="flex flex-col gap-6">
|
||
{operatorLibrarySections.map(({ category }) => (
|
||
<div
|
||
key={category}
|
||
title={category}
|
||
className="w-8 h-8 rounded-lg bg-[#0a0a0a] border border-[#2a2b2f] flex items-center justify-center text-[9px] font-bold text-gray-500 hover:border-blue-500/50 hover:text-blue-400 cursor-pointer transition-all"
|
||
>
|
||
{category.slice(0, 2)}
|
||
</div>
|
||
))}
|
||
</div>
|
||
<button
|
||
onClick={() => setIsLibOpen(true)}
|
||
className="mt-auto mb-4 p-2 hover:bg-white/5 rounded-md text-gray-500 hover:text-white transition-colors"
|
||
>
|
||
<Search className="w-4 h-4" />
|
||
</button>
|
||
</div>
|
||
)}
|
||
</motion.div>
|
||
|
||
<div
|
||
ref={reactFlowWrapperRef}
|
||
className={cn(
|
||
"flex-1 relative transition-colors",
|
||
isCanvasDragActive && !isReadOnly && canManage && "bg-blue-500/[0.04]",
|
||
)}
|
||
onDragOver={handleCanvasDragOver}
|
||
onDragLeave={handleCanvasDragLeave}
|
||
onDrop={handleCanvasDrop}
|
||
>
|
||
<ReactFlow
|
||
nodes={displayNodes}
|
||
edges={displayEdges}
|
||
onNodesChange={onNodesChange}
|
||
onEdgesChange={onEdgesChange}
|
||
onConnect={onConnect}
|
||
onInit={(instance) => {
|
||
reactFlowInstanceRef.current = instance;
|
||
}}
|
||
onNodeClick={onNodeClick}
|
||
onEdgeClick={onEdgeClick}
|
||
onNodeDoubleClick={onNodeDoubleClick}
|
||
onPaneClick={onPaneClick}
|
||
nodeTypes={nodeTypes}
|
||
fitView
|
||
theme="dark"
|
||
deleteKeyCode={null}
|
||
nodesDraggable={!isReadOnly && canManage}
|
||
nodesConnectable={!isReadOnly && canManage}
|
||
elementsSelectable={!isReadOnly && canManage}
|
||
nodesFocusable={!isReadOnly && canManage}
|
||
edgesFocusable={!isReadOnly && canManage}
|
||
>
|
||
<Background color="#2a2b2f" gap={20} />
|
||
<Controls>
|
||
<ControlButton onClick={onLayout} title="一键排版">
|
||
<Layout className="w-4 h-4 text-gray-800" />
|
||
</ControlButton>
|
||
</Controls>
|
||
<MiniMap
|
||
style={{ background: "#151619" }}
|
||
nodeColor={(n: any) => n.data?.minimapColor || "#3b82f6"}
|
||
maskColor="rgba(0,0,0,0.5)"
|
||
/>
|
||
<Panel position="top-right">
|
||
<motion.div
|
||
ref={configPanelRef}
|
||
initial={false}
|
||
animate={{
|
||
width: isConfigOpen ? (isConfigPanelExpanded ? 720 : 360) : 48,
|
||
height: isConfigOpen ? configPanelMaxHeight : 48,
|
||
}}
|
||
style={{
|
||
maxWidth: isConfigOpen ? "calc(100vw - 5rem)" : 48,
|
||
maxHeight: isConfigOpen ? configPanelMaxHeight : 48,
|
||
}}
|
||
className="bg-[#151619] border border-[#2a2b2f] rounded-xl shadow-2xl overflow-hidden flex flex-col"
|
||
>
|
||
<div
|
||
className={cn(
|
||
"flex items-center justify-between hover:bg-white/5 transition-colors",
|
||
isConfigOpen ? "cursor-default" : "cursor-pointer",
|
||
isConfigOpen ? "p-4 border-b border-[#2a2b2f]" : "p-3",
|
||
)}
|
||
onClick={() => {
|
||
if (!isConfigOpen) {
|
||
setIsConfigOpen(true);
|
||
}
|
||
}}
|
||
>
|
||
{isConfigOpen ? (
|
||
<>
|
||
<div className="min-w-0">
|
||
<h3 className="text-xs font-bold text-white uppercase tracking-wider">配置面板</h3>
|
||
<p className="mt-1 text-[10px] text-gray-500">
|
||
{isConfigPanelExpanded ? "最大化视图" : "标准视图"}
|
||
</p>
|
||
</div>
|
||
<div className="flex shrink-0 items-center gap-1">
|
||
<button
|
||
type="button"
|
||
onClick={(event) => {
|
||
event.stopPropagation();
|
||
setIsConfigPanelExpanded((current) => !current);
|
||
}}
|
||
className="rounded-md p-1.5 text-gray-500 transition-colors hover:bg-white/10 hover:text-white"
|
||
title={isConfigPanelExpanded ? "缩小配置面板" : "最大化配置面板"}
|
||
aria-label={isConfigPanelExpanded ? "缩小配置面板" : "最大化配置面板"}
|
||
>
|
||
{isConfigPanelExpanded ? (
|
||
<Minimize2 className="h-4 w-4" />
|
||
) : (
|
||
<Maximize2 className="h-4 w-4" />
|
||
)}
|
||
</button>
|
||
<button
|
||
type="button"
|
||
onClick={(event) => {
|
||
event.stopPropagation();
|
||
setIsConfigOpen(false);
|
||
}}
|
||
className="rounded-md p-1.5 text-gray-500 transition-colors hover:bg-white/10 hover:text-white"
|
||
title="收起配置面板"
|
||
aria-label="收起配置面板"
|
||
>
|
||
<ChevronRight className="h-4 w-4" />
|
||
</button>
|
||
</div>
|
||
</>
|
||
) : (
|
||
<Settings className="w-5 h-5 text-blue-500 mx-auto" />
|
||
)}
|
||
</div>
|
||
|
||
{isConfigOpen && (
|
||
<div
|
||
className={cn(
|
||
"min-h-0 flex-1 space-y-6 overflow-y-auto p-4 pb-6 scrollbar-thin scrollbar-thumb-gray-800",
|
||
isConfigPanelExpanded && "px-5",
|
||
)}
|
||
>
|
||
{isReadOnly && (
|
||
<div className="p-2 bg-orange-500/10 border border-orange-500/20 rounded text-[10px] text-orange-200 flex items-start gap-2">
|
||
<Lock className="w-3 h-3 shrink-0 mt-0.5" />
|
||
<span>流程正在执行或已成功,配置已锁定。</span>
|
||
</div>
|
||
)}
|
||
|
||
<div className="space-y-6">
|
||
{selectedNode ? (
|
||
<div className={cn("space-y-4 node-config-panel", isConfigPanelExpanded && "pb-2")}>
|
||
{/* Node Status Indicator */}
|
||
{selectedNodeExecutionState !== "idle" && (
|
||
<div
|
||
className={cn(
|
||
"flex items-center gap-2 px-3 py-2 rounded-md",
|
||
selectedNodeExecutionState === "running" &&
|
||
"bg-blue-500/10 border border-blue-500/20 animate-pulse",
|
||
selectedNodeExecutionState === "waiting_for_audit" &&
|
||
"bg-amber-500/10 border border-amber-500/20",
|
||
selectedNodeExecutionState === "completed" &&
|
||
"bg-emerald-500/10 border border-emerald-500/20",
|
||
selectedNodeExecutionState === "failed" && "bg-red-500/10 border border-red-500/20",
|
||
)}
|
||
>
|
||
{selectedNodeExecutionState === "running" ? (
|
||
<Loader2 className="w-3.5 h-3.5 text-blue-500 animate-spin" />
|
||
) : selectedNodeExecutionState === "waiting_for_audit" ? (
|
||
<Clock className="w-3.5 h-3.5 text-amber-400" />
|
||
) : selectedNodeExecutionState === "completed" ? (
|
||
<CheckCircle2 className="w-3.5 h-3.5 text-emerald-400" />
|
||
) : (
|
||
<X className="w-3.5 h-3.5 text-red-400" />
|
||
)}
|
||
<span
|
||
className={cn(
|
||
"text-[10px] font-bold uppercase tracking-wider",
|
||
selectedNodeExecutionState === "running" && "text-blue-400",
|
||
selectedNodeExecutionState === "waiting_for_audit" && "text-amber-300",
|
||
selectedNodeExecutionState === "completed" && "text-emerald-300",
|
||
selectedNodeExecutionState === "failed" && "text-red-300",
|
||
)}
|
||
>
|
||
{executionStateLabels[selectedNodeExecutionState]}
|
||
</span>
|
||
</div>
|
||
)}
|
||
|
||
{canManage && activeRun?.status === "failed" && (
|
||
<button
|
||
type="button"
|
||
onClick={() => void handleRerunSubtree()}
|
||
disabled={rerunSubtreePendingNodeId !== ""}
|
||
className={cn(
|
||
"w-full rounded-md border px-3 py-2 text-[11px] font-medium transition-colors",
|
||
rerunSubtreePendingNodeId !== ""
|
||
? "border-emerald-500/20 bg-emerald-500/10 text-emerald-100/60 cursor-not-allowed"
|
||
: "border-emerald-500/30 bg-emerald-500/10 text-emerald-100 hover:bg-emerald-500/15",
|
||
)}
|
||
>
|
||
<span className="inline-flex items-center gap-2">
|
||
{rerunSubtreePendingNodeId === selectedNode.id ? (
|
||
<Loader2 className="h-3.5 w-3.5 animate-spin" />
|
||
) : (
|
||
<RotateCcw className="h-3.5 w-3.5" />
|
||
)}
|
||
从该节点重新执行下游
|
||
</span>
|
||
</button>
|
||
)}
|
||
|
||
<div className="flex items-center gap-2 text-blue-500">
|
||
<Box className="w-3.5 h-3.5" />
|
||
<span className="text-[10px] font-bold uppercase">节点参数: {selectedNode.data.label}</span>
|
||
{!isReadOnly && canManage && (
|
||
<button
|
||
onClick={() => {
|
||
setNodes((currentNodes) =>
|
||
currentNodes.filter((node) => node.id !== selectedNode.id),
|
||
);
|
||
setEdges((currentEdges) =>
|
||
currentEdges.filter(
|
||
(edge) => edge.source !== selectedNode.id && edge.target !== selectedNode.id,
|
||
),
|
||
);
|
||
setEntity((previous) => {
|
||
if (!previous) {
|
||
return previous;
|
||
}
|
||
const nextNodes = nodes.filter((node) => node.id !== selectedNode.id);
|
||
if (nextNodes.some((node) => isDedicatedScanSourceNode(node))) {
|
||
return previous;
|
||
}
|
||
if (previous.kind !== "scan" && !previous.scanConfig) {
|
||
return previous;
|
||
}
|
||
return stripScanWorkflowShell(previous) as Workflow | WorkflowTemplate;
|
||
});
|
||
setSelectedNode(null);
|
||
setCanvasNotice("已删除 1 个节点和相关连线");
|
||
}}
|
||
className="ml-auto rounded-md p-1.5 text-red-300 hover:bg-red-500/10 hover:text-white transition-colors"
|
||
title="删除当前节点"
|
||
>
|
||
<X className="w-3.5 h-3.5" />
|
||
</button>
|
||
)}
|
||
</div>
|
||
|
||
{/* Tabs for configuration, live runtime state, and logs. */}
|
||
<div className="flex border-b border-[#2a2b2f]">
|
||
<button
|
||
type="button"
|
||
onClick={() => setNodeConfigPanelTab("config")}
|
||
className={cn(
|
||
"px-3 py-1.5 text-[10px] font-bold uppercase transition-colors",
|
||
nodeConfigPanelTab === "config"
|
||
? "border-b-2 border-blue-500 text-blue-500"
|
||
: "text-gray-500 hover:text-white",
|
||
)}
|
||
>
|
||
配置
|
||
</button>
|
||
<button
|
||
type="button"
|
||
onClick={() => setNodeConfigPanelTab("runtime")}
|
||
className={cn(
|
||
"px-3 py-1.5 text-[10px] font-bold uppercase transition-colors",
|
||
nodeConfigPanelTab === "runtime"
|
||
? "border-b-2 border-blue-500 text-blue-500"
|
||
: "text-gray-500 hover:text-white",
|
||
)}
|
||
>
|
||
运行
|
||
</button>
|
||
<button
|
||
type="button"
|
||
onClick={() => setNodeConfigPanelTab("logs")}
|
||
className={cn(
|
||
"px-3 py-1.5 text-[10px] font-bold uppercase transition-colors",
|
||
nodeConfigPanelTab === "logs"
|
||
? "border-b-2 border-blue-500 text-blue-500"
|
||
: "text-gray-500 hover:text-white",
|
||
)}
|
||
>
|
||
日志
|
||
</button>
|
||
</div>
|
||
|
||
{nodeConfigPanelTab === "runtime" && (
|
||
<div className="space-y-3" data-testid="node-runtime-panel">
|
||
{!activeRun?.id || !selectedNodeExecution ? (
|
||
<div className="rounded-md border border-[#2a2b2f] bg-[#0a0a0a] px-3 py-8 text-center text-[11px] text-gray-600">
|
||
当前算子还没有运行记录。
|
||
</div>
|
||
) : (
|
||
<>
|
||
<div
|
||
className={cn(
|
||
"flex items-center justify-between gap-3 rounded-md border px-3 py-2",
|
||
runStatusClasses[selectedNodeExecutionState] || runStatusClasses.queued,
|
||
)}
|
||
>
|
||
<div className="flex min-w-0 items-center gap-2">
|
||
{selectedNodeExecutionState === "running" ? (
|
||
<Loader2 className="h-4 w-4 shrink-0 animate-spin" />
|
||
) : (
|
||
<Activity className="h-4 w-4 shrink-0" />
|
||
)}
|
||
<div className="min-w-0">
|
||
<div className="text-[9px] font-mono uppercase opacity-70">当前节点状态</div>
|
||
<div className="truncate text-xs font-semibold">
|
||
{executionStateLabels[selectedNodeExecutionState] ||
|
||
selectedNodeExecutionState}
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div className="shrink-0 text-right font-mono text-[10px]">
|
||
{formatRuntimeDuration(selectedNodeRuntime.durationMs)}
|
||
</div>
|
||
</div>
|
||
|
||
<div className="grid grid-cols-1 gap-2 text-[10px] md:grid-cols-2">
|
||
<div className="rounded border border-[#2a2b2f] bg-[#0a0a0a] px-2 py-1.5">
|
||
<div className="text-[9px] uppercase text-gray-600">Run ID</div>
|
||
<div className="mt-0.5 break-all font-mono text-gray-300">{activeRun.id}</div>
|
||
</div>
|
||
<div className="rounded border border-[#2a2b2f] bg-[#0a0a0a] px-2 py-1.5">
|
||
<div className="text-[9px] uppercase text-gray-600">Node ID / Attempt</div>
|
||
<div className="mt-0.5 break-all font-mono text-gray-300">
|
||
{selectedNodeExecution.nodeId} /{" "}
|
||
{selectedNodeExecution.attempt || activeRun.attempt || 1}
|
||
</div>
|
||
</div>
|
||
<div className="rounded border border-[#2a2b2f] bg-[#0a0a0a] px-2 py-1.5">
|
||
<div className="text-[9px] uppercase text-gray-600">开始时间</div>
|
||
<div className="mt-0.5 font-mono text-gray-300">
|
||
{selectedNodeExecution.startedAt
|
||
? formatCompactDateTime(selectedNodeExecution.startedAt, timeZone)
|
||
: "--"}
|
||
</div>
|
||
</div>
|
||
<div className="rounded border border-[#2a2b2f] bg-[#0a0a0a] px-2 py-1.5">
|
||
<div className="text-[9px] uppercase text-gray-600">结束时间</div>
|
||
<div className="mt-0.5 font-mono text-gray-300">
|
||
{selectedNodeExecution.endedAt
|
||
? formatCompactDateTime(selectedNodeExecution.endedAt, timeZone)
|
||
: "运行中"}
|
||
</div>
|
||
</div>
|
||
<div className="rounded border border-[#2a2b2f] bg-[#0a0a0a] px-2 py-1.5 md:col-span-2">
|
||
<div className="text-[9px] uppercase text-gray-600">容器镜像</div>
|
||
<div className="mt-0.5 break-all font-mono text-gray-300">
|
||
{selectedNodeExecution.operatorImageId ||
|
||
selectedNodeExecution.operatorImage ||
|
||
"--"}
|
||
</div>
|
||
</div>
|
||
<div className="rounded border border-[#2a2b2f] bg-[#0a0a0a] px-2 py-1.5 md:col-span-2">
|
||
<div className="text-[9px] uppercase text-gray-600">Kubernetes Job</div>
|
||
<div className="mt-0.5 break-all font-mono text-gray-300">
|
||
{selectedNodeRuntime.jobRef
|
||
? `${selectedNodeRuntime.jobRef.namespace}/${selectedNodeRuntime.jobRef.jobName}`
|
||
: selectedNodeExecutionState === "running"
|
||
? "等待运行任务引用回写"
|
||
: "--"}
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div className="grid grid-cols-3 gap-2 text-center font-mono text-[10px]">
|
||
<div className="rounded border border-[#2a2b2f] bg-[#0a0a0a] px-2 py-2">
|
||
<div className="text-gray-500">日志</div>
|
||
<div className="mt-1 text-gray-200">{selectedNodeRuntime.logCount}</div>
|
||
</div>
|
||
<div className="rounded border border-[#2a2b2f] bg-[#0a0a0a] px-2 py-2">
|
||
<div className="text-gray-500">产物</div>
|
||
<div className="mt-1 text-gray-200">{selectedNodeRuntime.artifactCount}</div>
|
||
</div>
|
||
<div className="rounded border border-[#2a2b2f] bg-[#0a0a0a] px-2 py-2">
|
||
<div className="text-gray-500">资源采样</div>
|
||
<div className="mt-1 text-gray-200">{selectedNodeRuntime.resourceCount}</div>
|
||
</div>
|
||
</div>
|
||
|
||
{selectedNodeLatestResource && (
|
||
<div className="rounded border border-[#2a2b2f] bg-[#0a0a0a] px-3 py-2 text-[10px]">
|
||
<div className="text-[9px] uppercase text-gray-600">最新资源状态</div>
|
||
<div className="mt-1 font-mono text-gray-300">
|
||
GPU {selectedNodeLatestResource.gpuName || "--"} · 显存{" "}
|
||
{selectedNodeLatestResource.gpuMemoryUsedMiB || 0}/
|
||
{selectedNodeLatestResource.gpuMemoryTotalMiB || 0} MiB · CPU{" "}
|
||
{selectedNodeLatestResource.cpu || 0}%
|
||
</div>
|
||
</div>
|
||
)}
|
||
|
||
{selectedNodeExecution.error && (
|
||
<div className="rounded border border-red-500/30 bg-red-500/10 px-3 py-2 text-[10px] text-red-200">
|
||
{selectedNodeExecution.error}
|
||
</div>
|
||
)}
|
||
|
||
<button
|
||
type="button"
|
||
onClick={() => navigate(`/monitoring?runId=${encodeURIComponent(activeRun.id)}`)}
|
||
className="inline-flex w-full items-center justify-center gap-2 rounded-md border border-[#2a2b2f] px-3 py-2 text-[11px] font-medium text-gray-300 transition-colors hover:border-blue-500/40 hover:bg-blue-500/10 hover:text-white"
|
||
>
|
||
<Activity className="h-3.5 w-3.5" />
|
||
查看完整执行监控
|
||
</button>
|
||
</>
|
||
)}
|
||
</div>
|
||
)}
|
||
|
||
{nodeConfigPanelTab === "logs" && (
|
||
<div className="space-y-2" data-testid="node-live-logs-panel">
|
||
<div className="flex items-center justify-between">
|
||
<div>
|
||
<label className="text-[10px] text-gray-500 uppercase font-mono">实时运行日志</label>
|
||
<div className="mt-0.5 font-mono text-[9px] text-gray-600">
|
||
{selectedNodeLogs.length} 条
|
||
{liveRunLogsUpdatedAt
|
||
? ` · ${formatClockTime(liveRunLogsUpdatedAt, timeZone)} 更新`
|
||
: ""}
|
||
</div>
|
||
</div>
|
||
<button
|
||
type="button"
|
||
onClick={() => setLiveRunLogsRefreshToken((current) => current + 1)}
|
||
className="rounded-md border border-[#2a2b2f] p-1.5 text-gray-400 transition-colors hover:bg-white/5 hover:text-white"
|
||
title="刷新当前节点日志"
|
||
>
|
||
<RefreshCw className={cn("h-3.5 w-3.5", isLiveRunLogsLoading && "animate-spin")} />
|
||
</button>
|
||
</div>
|
||
{liveRunLogsError && (
|
||
<div className="rounded border border-red-500/30 bg-red-500/10 px-2 py-1.5 text-[10px] text-red-200">
|
||
{liveRunLogsError}
|
||
</div>
|
||
)}
|
||
<div
|
||
ref={nodeLogsPanelRef}
|
||
onScroll={(event) => {
|
||
const panel = event.currentTarget;
|
||
nodeLogsFollowRef.current =
|
||
panel.scrollHeight - panel.scrollTop - panel.clientHeight <= 64;
|
||
}}
|
||
className="h-[34rem] max-h-[60vh] overflow-y-auto rounded-lg border border-[#2a2b2f] bg-[#0a0a0a] p-2 font-mono text-[10px] space-y-1 scrollbar-thin scrollbar-thumb-gray-800"
|
||
>
|
||
{selectedNodeLogs.length ? (
|
||
selectedNodeLogs.map((log: any, i: number) => (
|
||
<div
|
||
key={`${log.timestamp || i}-${log.message || "log"}`}
|
||
className={cn(
|
||
"flex gap-2",
|
||
log.level === "ERROR"
|
||
? "text-red-400"
|
||
: log.level === "WARN"
|
||
? "text-amber-300"
|
||
: log.level === "INFO"
|
||
? "text-gray-300"
|
||
: "text-blue-300",
|
||
)}
|
||
>
|
||
<span className="text-gray-600 shrink-0">
|
||
[{formatClockTime(log.timestamp, timeZone)}]
|
||
</span>
|
||
<span className="uppercase text-gray-500 shrink-0">{log.level}</span>
|
||
<span className="whitespace-pre-wrap break-words">{log.message}</span>
|
||
</div>
|
||
))
|
||
) : nodes.find((n) => n.id === selectedNode.id)?.data.logs?.length > 0 ? (
|
||
nodes
|
||
.find((n) => n.id === selectedNode.id)
|
||
?.data.logs.map((log: any, i: number) => (
|
||
<div
|
||
key={i}
|
||
className={cn(
|
||
"flex gap-2",
|
||
log.type === "success"
|
||
? "text-green-400"
|
||
: log.type === "error"
|
||
? "text-red-400"
|
||
: "text-gray-400",
|
||
)}
|
||
>
|
||
<span className="text-gray-600 shrink-0">[{log.time}]</span>
|
||
<span>{log.message}</span>
|
||
</div>
|
||
))
|
||
) : (
|
||
<div className="space-y-3 py-10 text-center">
|
||
<div className="text-gray-700 italic">节点日志会在真实运行后实时同步到这里。</div>
|
||
{activeRun?.id && (
|
||
<button
|
||
type="button"
|
||
onClick={() =>
|
||
navigate(`/monitoring?runId=${encodeURIComponent(activeRun.id)}`)
|
||
}
|
||
className="inline-flex items-center gap-2 rounded-md border border-[#2a2b2f] px-3 py-1.5 text-[11px] font-medium text-gray-300 transition-colors hover:border-blue-500/40 hover:bg-blue-500/10 hover:text-white"
|
||
>
|
||
<Terminal className="h-3.5 w-3.5" />
|
||
查看执行监控
|
||
</button>
|
||
)}
|
||
</div>
|
||
)}
|
||
</div>
|
||
</div>
|
||
)}
|
||
|
||
<div className={cn("space-y-3", nodeConfigPanelTab !== "config" && "hidden")}>
|
||
<div className="space-y-1">
|
||
<label className="text-[10px] text-gray-500 uppercase font-mono">算子名称</label>
|
||
<input
|
||
type="text"
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs focus:outline-none focus:border-blue-500 disabled:opacity-50"
|
||
value={
|
||
nodes.find((n) => n.id === selectedNode.id)?.data.label || selectedNode.data.label
|
||
}
|
||
onChange={(e) => updateNodeData({ label: e.target.value })}
|
||
readOnly={isReadOnly}
|
||
disabled={isReadOnly}
|
||
/>
|
||
</div>
|
||
|
||
{selectedLightweightRuntime.enabled && (
|
||
<div className="rounded-lg border border-emerald-500/20 bg-emerald-500/5 p-3 space-y-3">
|
||
<div className="flex items-center justify-between gap-2">
|
||
<div className="flex items-center gap-2 text-emerald-300">
|
||
<FolderOpen className="h-3.5 w-3.5" />
|
||
<span className="text-[9px] font-bold uppercase tracking-wider">
|
||
轻量算子挂载目录
|
||
</span>
|
||
</div>
|
||
<div className="flex items-center gap-2">
|
||
<button
|
||
type="button"
|
||
onClick={() => setIsConfigPanelExpanded(true)}
|
||
className="inline-flex items-center gap-1 rounded-md border border-[#2a2b2f] bg-white/5 px-2 py-1 text-[10px] text-gray-200 transition-colors hover:bg-white/10"
|
||
title="放大配置面板"
|
||
>
|
||
<Maximize2 className="h-3 w-3" />
|
||
放大面板
|
||
</button>
|
||
<button
|
||
type="button"
|
||
onClick={() => setIsLightweightCodeEditorFullscreen(true)}
|
||
className="inline-flex items-center gap-1 rounded-md border border-emerald-500/30 bg-emerald-500/10 px-2 py-1 text-[10px] text-emerald-100 transition-colors hover:bg-emerald-500/15"
|
||
title="打开代码目录编辑器"
|
||
>
|
||
<FolderOpen className="h-3 w-3" />
|
||
打开目录
|
||
</button>
|
||
</div>
|
||
</div>
|
||
|
||
<div className="grid grid-cols-1 gap-2 text-[10px] md:grid-cols-2">
|
||
<div className="rounded border border-[#2a2b2f] bg-[#0a0a0a] px-2 py-1.5">
|
||
<div className="text-[9px] uppercase font-mono text-gray-500">PVC</div>
|
||
<div className="mt-0.5 break-all font-mono text-gray-200">
|
||
{selectedLightweightRuntime.pvcName}
|
||
</div>
|
||
</div>
|
||
<div className="rounded border border-[#2a2b2f] bg-[#0a0a0a] px-2 py-1.5">
|
||
<div className="text-[9px] uppercase font-mono text-gray-500">容器挂载路径</div>
|
||
<div className="mt-0.5 break-all font-mono text-gray-200">
|
||
{selectedLightweightRuntime.mountPath}
|
||
</div>
|
||
</div>
|
||
<div className="rounded border border-[#2a2b2f] bg-[#0a0a0a] px-2 py-1.5 md:col-span-2">
|
||
<div className="text-[9px] uppercase font-mono text-gray-500">
|
||
Workspace 代码目录
|
||
</div>
|
||
<div className="mt-0.5 break-all font-mono text-gray-200">
|
||
{selectedLightweightRuntime.codeSubPath || "未配置"}
|
||
</div>
|
||
<div className="mt-1 break-all font-mono text-gray-500">
|
||
{selectedLightweightRuntime.workspacePath}
|
||
</div>
|
||
</div>
|
||
<div className="rounded border border-[#2a2b2f] bg-[#0a0a0a] px-2 py-1.5">
|
||
<div className="text-[9px] uppercase font-mono text-gray-500">代码挂载</div>
|
||
<div className="mt-0.5 font-mono text-gray-200">
|
||
{selectedLightweightManifest?.readOnly ? "read-only" : "read-only by default"}
|
||
</div>
|
||
</div>
|
||
<div className="rounded border border-[#2a2b2f] bg-[#0a0a0a] px-2 py-1.5">
|
||
<div className="text-[9px] uppercase font-mono text-gray-500">代码 Hash</div>
|
||
<div className="mt-0.5 break-all font-mono text-gray-200">
|
||
{selectedLightweightManifest?.sha256?.slice(0, 24) || "未生成"}
|
||
</div>
|
||
</div>
|
||
<div className="rounded border border-[#2a2b2f] bg-[#0a0a0a] px-2 py-1.5 md:col-span-2">
|
||
<div className="text-[9px] uppercase font-mono text-gray-500">启动命令</div>
|
||
<div className="mt-0.5 break-all font-mono text-gray-200">
|
||
{JSON.stringify(selectedLightweightCommand)}
|
||
</div>
|
||
<div className="mt-1 text-[9px] uppercase font-mono text-gray-500">启动参数</div>
|
||
<div className="mt-0.5 break-all font-mono text-gray-200">
|
||
{JSON.stringify(selectedLightweightArgs)}
|
||
</div>
|
||
</div>
|
||
{selectedLightweightManifest && (
|
||
<div className="rounded border border-[#2a2b2f] bg-[#0a0a0a] px-2 py-1.5 md:col-span-2">
|
||
<div className="text-[9px] uppercase font-mono text-gray-500">Manifest</div>
|
||
<div className="mt-0.5 break-all font-mono text-gray-200">
|
||
{selectedLightweightManifest.fileCount} files ·{" "}
|
||
{selectedLightweightManifest.totalBytes} bytes
|
||
</div>
|
||
<div className="mt-1 break-all font-mono text-gray-500">
|
||
{selectedLightweightManifest.generatedAt}
|
||
</div>
|
||
</div>
|
||
)}
|
||
</div>
|
||
|
||
<div className="rounded border border-[#2a2b2f] bg-[#0a0a0a] p-2">
|
||
<div className="mb-2 flex items-center justify-between gap-2">
|
||
<span className="text-[9px] font-mono uppercase text-gray-500">目录文件</span>
|
||
<span className="font-mono text-[9px] text-gray-600">workspace</span>
|
||
</div>
|
||
<LightweightOperatorCodeEditor
|
||
operatorId={selectedLightweightOperatorId}
|
||
showSummary={false}
|
||
unavailableMessage="当前节点没有 operatorId,无法加载轻量算子代码目录。"
|
||
/>
|
||
</div>
|
||
</div>
|
||
)}
|
||
|
||
{/* Execution Logs Section */}
|
||
<div className="mt-6 space-y-2">
|
||
<div className="flex items-center justify-between">
|
||
<label className="text-[10px] text-gray-500 uppercase font-mono">运行日志</label>
|
||
<Terminal className="w-3 h-3 text-gray-600" />
|
||
</div>
|
||
<div className="bg-[#0a0a0a] border border-[#2a2b2f] rounded-lg p-2 h-48 overflow-y-auto font-mono text-[10px] space-y-1 scrollbar-thin scrollbar-thumb-gray-800">
|
||
{selectedNodeExecution?.logs?.length ? (
|
||
selectedNodeExecution.logs.map((log: any, i: number) => (
|
||
<div
|
||
key={`${log.timestamp || i}-${log.message || "log"}`}
|
||
className={cn(
|
||
"flex gap-2",
|
||
log.level === "ERROR"
|
||
? "text-red-400"
|
||
: log.level === "WARN"
|
||
? "text-amber-300"
|
||
: log.level === "INFO"
|
||
? "text-gray-300"
|
||
: "text-blue-300",
|
||
)}
|
||
>
|
||
<span className="text-gray-600 shrink-0">
|
||
[{formatClockTime(log.timestamp, timeZone)}]
|
||
</span>
|
||
<span className="uppercase text-gray-500 shrink-0">{log.level}</span>
|
||
<span>{log.message}</span>
|
||
</div>
|
||
))
|
||
) : nodes.find((n) => n.id === selectedNode.id)?.data.logs?.length > 0 ? (
|
||
nodes
|
||
.find((n) => n.id === selectedNode.id)
|
||
?.data.logs.map((log: any, i: number) => (
|
||
<div
|
||
key={i}
|
||
className={cn(
|
||
"flex gap-2",
|
||
log.type === "success"
|
||
? "text-green-400"
|
||
: log.type === "error"
|
||
? "text-red-400"
|
||
: "text-gray-400",
|
||
)}
|
||
>
|
||
<span className="text-gray-600 shrink-0">[{log.time}]</span>
|
||
<span>{log.message}</span>
|
||
</div>
|
||
))
|
||
) : (
|
||
<div className="text-gray-700 italic text-center mt-10">
|
||
节点日志会在真实运行后实时同步到这里。
|
||
</div>
|
||
)}
|
||
</div>
|
||
</div>
|
||
|
||
{isScanWorkflow && isScanSourceNode(selectedNode) && (
|
||
<div className="p-3 bg-cyan-500/5 border border-cyan-500/20 rounded-lg space-y-3">
|
||
<div className="flex items-center gap-2 text-cyan-400 mb-1">
|
||
<Database className="w-3 h-3" />
|
||
<span className="text-[9px] font-bold uppercase tracking-wider">扫描源配置</span>
|
||
</div>
|
||
|
||
<div className="space-y-1">
|
||
<label className="text-[9px] text-gray-500 uppercase font-mono">数据源类型</label>
|
||
<select
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs focus:outline-none focus:border-cyan-500 disabled:opacity-50"
|
||
value={workflowConfigEntity?.scanConfig?.dataSource || "BOS"}
|
||
onChange={(e) =>
|
||
updateScanWorkflowConfig({
|
||
dataSource: e.target.value,
|
||
})
|
||
}
|
||
disabled={isReadOnly}
|
||
>
|
||
<option value="BOS">BOS</option>
|
||
</select>
|
||
</div>
|
||
|
||
{(workflowConfigEntity?.scanConfig?.dataSource || "BOS") === "BOS" ? (
|
||
<>
|
||
<div className="grid grid-cols-1 gap-3 md:grid-cols-2">
|
||
<div className="space-y-1">
|
||
<label className="text-[9px] text-gray-500 uppercase font-mono">Bucket</label>
|
||
{scanStorageConnection ? (
|
||
<select
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs focus:outline-none focus:border-cyan-500 disabled:opacity-50"
|
||
value={workflowConfigEntity?.scanConfig?.bucket || ""}
|
||
onChange={(e) => {
|
||
const nextBucket = e.target.value;
|
||
updateScanWorkflowConfig({
|
||
bucket: nextBucket,
|
||
});
|
||
rememberRecentStoragePath(
|
||
nextBucket,
|
||
workflowConfigEntity?.scanConfig?.prefix || "",
|
||
);
|
||
}}
|
||
disabled={isReadOnly || isStorageConnectionsLoading}
|
||
>
|
||
<option value="">选择 Bucket...</option>
|
||
{buckets.map((bucket) => (
|
||
<option key={bucket} value={bucket}>
|
||
{bucket}
|
||
</option>
|
||
))}
|
||
</select>
|
||
) : (
|
||
<input
|
||
type="text"
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs focus:outline-none focus:border-cyan-500 disabled:opacity-50"
|
||
value={workflowConfigEntity?.scanConfig?.bucket || ""}
|
||
onChange={(e) =>
|
||
updateScanWorkflowConfig({
|
||
bucket: e.target.value,
|
||
})
|
||
}
|
||
onBlur={(e) =>
|
||
rememberRecentStoragePath(
|
||
e.target.value,
|
||
workflowConfigEntity?.scanConfig?.prefix || "",
|
||
)
|
||
}
|
||
readOnly={isReadOnly}
|
||
disabled={isReadOnly}
|
||
/>
|
||
)}
|
||
</div>
|
||
<div className="space-y-1">
|
||
<label className="text-[9px] text-gray-500 uppercase font-mono">Prefix</label>
|
||
<div className="relative">
|
||
<input
|
||
type="text"
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs focus:outline-none focus:border-cyan-500 disabled:opacity-50"
|
||
value={workflowConfigEntity?.scanConfig?.prefix || ""}
|
||
onChange={(e) =>
|
||
updateScanWorkflowConfig({
|
||
prefix: e.target.value,
|
||
})
|
||
}
|
||
onBlur={(e) =>
|
||
rememberRecentStoragePath(
|
||
workflowConfigEntity?.scanConfig?.bucket || "",
|
||
e.target.value,
|
||
)
|
||
}
|
||
readOnly={isReadOnly}
|
||
disabled={isReadOnly}
|
||
/>
|
||
<button
|
||
type="button"
|
||
onClick={() => setIsOssBrowsing(true)}
|
||
className="absolute right-1 top-1/2 -translate-y-1/2 p-1 hover:bg-white/5 rounded text-cyan-400 disabled:opacity-50"
|
||
disabled={
|
||
isReadOnly ||
|
||
(!workflowConfigEntity?.scanConfig?.bucket &&
|
||
visibleRecentStoragePaths.length === 0 &&
|
||
favoriteStoragePaths.length === 0 &&
|
||
projectFavoriteStoragePaths.length === 0) ||
|
||
!workflowConfigEntity?.scanConfig?.connectionId
|
||
}
|
||
title="浏览前缀"
|
||
>
|
||
<FolderOpen className="w-3 h-3" />
|
||
</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
{selectedStoragePathKey && (
|
||
<div className="flex justify-end">
|
||
<button
|
||
type="button"
|
||
onClick={toggleCurrentStoragePathFavorite}
|
||
className={cn(
|
||
"inline-flex items-center gap-1 rounded border px-2 py-1 text-[10px] transition-colors disabled:opacity-50",
|
||
isCurrentStoragePathFavorite
|
||
? "border-amber-500/30 bg-amber-500/10 text-amber-200 hover:bg-amber-500/15"
|
||
: "border-[#2a2b2f] bg-[#0a0a0a] text-gray-300 hover:border-amber-500/30 hover:text-amber-200",
|
||
)}
|
||
disabled={isReadOnly}
|
||
>
|
||
<Star
|
||
className="h-3 w-3"
|
||
fill={isCurrentStoragePathFavorite ? "currentColor" : "none"}
|
||
/>
|
||
{isCurrentStoragePathFavorite ? "取消收藏当前路径" : "收藏当前路径"}
|
||
</button>
|
||
{workflowProjectId && (
|
||
<button
|
||
type="button"
|
||
onClick={() => void toggleCurrentProjectStoragePathFavorite()}
|
||
className={cn(
|
||
"inline-flex items-center gap-1 rounded border px-2 py-1 text-[10px] transition-colors disabled:opacity-50",
|
||
isCurrentProjectStoragePathFavorite
|
||
? "border-cyan-500/30 bg-cyan-500/10 text-cyan-200 hover:bg-cyan-500/15"
|
||
: "border-[#2a2b2f] bg-[#0a0a0a] text-gray-300 hover:border-cyan-500/30 hover:text-cyan-200",
|
||
)}
|
||
disabled={isReadOnly}
|
||
>
|
||
<Users className="h-3 w-3" />
|
||
{isCurrentProjectStoragePathFavorite ? "移出项目常用" : "加入项目常用"}
|
||
</button>
|
||
)}
|
||
</div>
|
||
)}
|
||
|
||
{projectFavoriteStoragePaths.length > 0 && (
|
||
<div className="space-y-1">
|
||
<div className="flex items-center gap-1 text-[9px] font-mono uppercase text-cyan-300">
|
||
<Users className="h-2.5 w-2.5" />
|
||
项目常用路径
|
||
</div>
|
||
<div className="flex flex-wrap gap-1.5">
|
||
{projectFavoriteStoragePaths.map((item) => (
|
||
<button
|
||
key={`${item.bucket}/${item.prefix}`}
|
||
type="button"
|
||
onClick={() => applyFavoriteStoragePath(item.bucket, item.prefix)}
|
||
className="rounded-full border border-cyan-500/20 bg-cyan-500/10 px-2 py-1 text-[10px] text-cyan-100 hover:bg-cyan-500/15 disabled:opacity-50"
|
||
disabled={isReadOnly}
|
||
title={item.label}
|
||
>
|
||
{item.label}
|
||
</button>
|
||
))}
|
||
</div>
|
||
</div>
|
||
)}
|
||
|
||
{visibleUserFavoriteStoragePaths.length > 0 && (
|
||
<div className="space-y-1">
|
||
<div className="flex items-center gap-1 text-[9px] font-mono uppercase text-amber-300">
|
||
<Star className="h-2.5 w-2.5" />
|
||
我的常用路径
|
||
</div>
|
||
<div className="flex flex-wrap gap-1.5">
|
||
{visibleUserFavoriteStoragePaths.map((item) => (
|
||
<button
|
||
key={`${item.bucket}/${item.prefix}`}
|
||
type="button"
|
||
onClick={() => applyFavoriteStoragePath(item.bucket, item.prefix)}
|
||
className="rounded-full border border-amber-500/20 bg-amber-500/10 px-2 py-1 text-[10px] text-amber-100 hover:bg-amber-500/15 disabled:opacity-50"
|
||
disabled={isReadOnly}
|
||
title={item.label}
|
||
>
|
||
{item.label}
|
||
</button>
|
||
))}
|
||
</div>
|
||
</div>
|
||
)}
|
||
|
||
{visibleRecentStoragePaths.length > 0 && (
|
||
<div className="space-y-1">
|
||
<div className="flex items-center gap-1 text-[9px] font-mono uppercase text-gray-500">
|
||
<RotateCcw className="h-2.5 w-2.5" />
|
||
最近使用路径
|
||
</div>
|
||
<div className="flex flex-wrap gap-1.5">
|
||
{visibleRecentStoragePaths.map((item) => (
|
||
<button
|
||
key={`${item.bucket}/${item.prefix}`}
|
||
type="button"
|
||
onClick={() => applyRecentStoragePath(item.bucket, item.prefix)}
|
||
className="rounded-full border border-cyan-500/20 bg-cyan-500/10 px-2 py-1 text-[10px] text-cyan-100 hover:bg-cyan-500/15 disabled:opacity-50"
|
||
disabled={isReadOnly}
|
||
title={item.label}
|
||
>
|
||
{item.label}
|
||
</button>
|
||
))}
|
||
</div>
|
||
</div>
|
||
)}
|
||
|
||
<div className="space-y-3 rounded-lg border border-cyan-500/20 bg-cyan-500/5 p-3">
|
||
<div className="flex items-center justify-between gap-3">
|
||
<div>
|
||
<div className="text-[9px] font-mono uppercase text-gray-500">BOS 连接</div>
|
||
<div className="text-[11px] text-gray-400">
|
||
连接保存 endpoint 和密钥,工作流只引用连接 ID。
|
||
</div>
|
||
</div>
|
||
<div className="flex items-center gap-2">
|
||
<button
|
||
type="button"
|
||
onClick={() => loadStorageConnections()}
|
||
className="rounded border border-[#2a2b2f] px-2 py-1 text-[10px] text-gray-300 hover:border-cyan-500/40 hover:text-cyan-300 disabled:opacity-50"
|
||
disabled={isReadOnly || isStorageConnectionsLoading}
|
||
>
|
||
{isStorageConnectionsLoading ? "刷新中..." : "刷新"}
|
||
</button>
|
||
<button
|
||
type="button"
|
||
onClick={() => setIsStorageConnectionFormOpen((current) => !current)}
|
||
className="rounded border border-cyan-500/30 bg-cyan-500/10 px-2 py-1 text-[10px] text-cyan-200 hover:bg-cyan-500/15 disabled:opacity-50"
|
||
disabled={isReadOnly}
|
||
>
|
||
{isStorageConnectionFormOpen ? "收起新建" : "新建连接"}
|
||
</button>
|
||
</div>
|
||
</div>
|
||
|
||
<div className="space-y-1">
|
||
<label className="text-[9px] text-gray-500 uppercase font-mono">已选连接</label>
|
||
<select
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs focus:outline-none focus:border-cyan-500 disabled:opacity-50"
|
||
value={workflowConfigEntity?.scanConfig?.connectionId || ""}
|
||
onChange={(e) => handleStorageConnectionSelect(e.target.value, "scan")}
|
||
disabled={isReadOnly || isStorageConnectionsLoading}
|
||
>
|
||
<option value="">直接在当前工作流填写 BOS 凭据</option>
|
||
{storageConnections.map((connection) => (
|
||
<option key={connection.id} value={connection.id}>
|
||
{connection.name}
|
||
</option>
|
||
))}
|
||
</select>
|
||
</div>
|
||
|
||
{storageConnectionsError && (
|
||
<div className="rounded border border-amber-500/20 bg-amber-500/10 px-2 py-1 text-[10px] text-amber-200">
|
||
{storageConnectionsError}
|
||
</div>
|
||
)}
|
||
|
||
{scanStorageConnection && (
|
||
<div className="grid grid-cols-1 gap-3 md:grid-cols-3">
|
||
<div className="rounded border border-[#2a2b2f] bg-[#0a0a0a] px-2 py-2">
|
||
<div className="text-[9px] font-mono uppercase text-gray-500">Endpoint</div>
|
||
<div className="mt-1 break-all text-[11px] text-gray-200">
|
||
{scanStorageConnection.endpoint || GLOBAL_BOS_ENDPOINT_LABEL}
|
||
</div>
|
||
</div>
|
||
<div className="rounded border border-[#2a2b2f] bg-[#0a0a0a] px-2 py-2">
|
||
<div className="text-[9px] font-mono uppercase text-gray-500">
|
||
Access Key
|
||
</div>
|
||
<div className="mt-1 text-[11px] text-gray-200">
|
||
{scanStorageConnection.accessKeyPreview || "已保存"}
|
||
</div>
|
||
</div>
|
||
<div className="rounded border border-[#2a2b2f] bg-[#0a0a0a] px-2 py-2">
|
||
<div className="text-[9px] font-mono uppercase text-gray-500">
|
||
Secret Key
|
||
</div>
|
||
<div className="mt-1 text-[11px] text-gray-200">
|
||
{scanStorageConnection.secretAccessKeyPreview || "已保存"}
|
||
</div>
|
||
</div>
|
||
</div>
|
||
)}
|
||
|
||
{isStorageConnectionFormOpen && (
|
||
<div className="grid grid-cols-1 gap-3 md:grid-cols-2">
|
||
<div className="space-y-1">
|
||
<label className="text-[9px] text-gray-500 uppercase font-mono">
|
||
连接名称
|
||
</label>
|
||
<input
|
||
type="text"
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs focus:outline-none focus:border-cyan-500 disabled:opacity-50"
|
||
value={storageConnectionDraft.name}
|
||
onChange={(e) =>
|
||
setStorageConnectionDraft((current) => ({
|
||
...current,
|
||
name: e.target.value,
|
||
}))
|
||
}
|
||
readOnly={isReadOnly}
|
||
disabled={isReadOnly || isSavingStorageConnection}
|
||
/>
|
||
</div>
|
||
<div className="space-y-1">
|
||
<label className="text-[9px] text-gray-500 uppercase font-mono">描述</label>
|
||
<input
|
||
type="text"
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs focus:outline-none focus:border-cyan-500 disabled:opacity-50"
|
||
value={storageConnectionDraft.description}
|
||
onChange={(e) =>
|
||
setStorageConnectionDraft((current) => ({
|
||
...current,
|
||
description: e.target.value,
|
||
}))
|
||
}
|
||
readOnly={isReadOnly}
|
||
disabled={isReadOnly || isSavingStorageConnection}
|
||
/>
|
||
</div>
|
||
<div className="space-y-1 md:col-span-2">
|
||
<label className="text-[9px] text-gray-500 uppercase font-mono">
|
||
Endpoint
|
||
</label>
|
||
<input
|
||
type="text"
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs focus:outline-none focus:border-cyan-500 disabled:opacity-50"
|
||
value={storageConnectionDraft.endpoint}
|
||
onChange={(e) =>
|
||
setStorageConnectionDraft((current) => ({
|
||
...current,
|
||
endpoint: e.target.value,
|
||
}))
|
||
}
|
||
placeholder="可选;留空则依赖全局 BOS_ENDPOINT"
|
||
readOnly={isReadOnly}
|
||
disabled={isReadOnly || isSavingStorageConnection}
|
||
/>
|
||
</div>
|
||
<div className="space-y-1">
|
||
<label className="text-[9px] text-gray-500 uppercase font-mono">
|
||
Access Key ID
|
||
</label>
|
||
<input
|
||
type="password"
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs focus:outline-none focus:border-cyan-500 disabled:opacity-50"
|
||
value={storageConnectionDraft.accessKeyId}
|
||
onChange={(e) =>
|
||
setStorageConnectionDraft((current) => ({
|
||
...current,
|
||
accessKeyId: e.target.value,
|
||
}))
|
||
}
|
||
readOnly={isReadOnly}
|
||
disabled={isReadOnly || isSavingStorageConnection}
|
||
/>
|
||
</div>
|
||
<div className="space-y-1">
|
||
<label className="text-[9px] text-gray-500 uppercase font-mono">
|
||
Secret Access Key
|
||
</label>
|
||
<input
|
||
type="password"
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs focus:outline-none focus:border-cyan-500 disabled:opacity-50"
|
||
value={storageConnectionDraft.secretAccessKey}
|
||
onChange={(e) =>
|
||
setStorageConnectionDraft((current) => ({
|
||
...current,
|
||
secretAccessKey: e.target.value,
|
||
}))
|
||
}
|
||
readOnly={isReadOnly}
|
||
disabled={isReadOnly || isSavingStorageConnection}
|
||
/>
|
||
</div>
|
||
<div className="md:col-span-2 flex justify-end">
|
||
<button
|
||
type="button"
|
||
onClick={() => void handleCreateStorageConnection()}
|
||
className="rounded border border-cyan-500/30 bg-cyan-500/10 px-3 py-1.5 text-[11px] text-cyan-200 hover:bg-cyan-500/15 disabled:opacity-50"
|
||
disabled={isReadOnly || isSavingStorageConnection}
|
||
>
|
||
{isSavingStorageConnection ? "创建中..." : "保存并使用该连接"}
|
||
</button>
|
||
</div>
|
||
</div>
|
||
)}
|
||
</div>
|
||
|
||
{!workflowConfigEntity?.scanConfig?.connectionId && (
|
||
<div className="grid grid-cols-1 gap-3 md:grid-cols-3">
|
||
<div className="space-y-1">
|
||
<label className="text-[9px] text-gray-500 uppercase font-mono">
|
||
Endpoint
|
||
</label>
|
||
<input
|
||
type="text"
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs focus:outline-none focus:border-cyan-500 disabled:opacity-50"
|
||
value={workflowConfigEntity?.scanConfig?.endpoint || ""}
|
||
onChange={(e) =>
|
||
updateScanWorkflowConfig({
|
||
endpoint: e.target.value,
|
||
})
|
||
}
|
||
placeholder="可选;留空则依赖全局 BOS_ENDPOINT"
|
||
readOnly={isReadOnly}
|
||
disabled={isReadOnly}
|
||
/>
|
||
</div>
|
||
<div className="space-y-1">
|
||
<label className="text-[9px] text-gray-500 uppercase font-mono">
|
||
Access Key ID
|
||
</label>
|
||
<input
|
||
type="password"
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs focus:outline-none focus:border-cyan-500 placeholder:text-gray-600 disabled:opacity-50"
|
||
value={workflowConfigEntity?.scanConfig?.accessKeyId || ""}
|
||
onChange={(e) =>
|
||
updateScanWorkflowConfig({
|
||
accessKeyId: e.target.value,
|
||
})
|
||
}
|
||
placeholder={
|
||
workflowConfigEntity?.scanConfig?.accessKeyPreview
|
||
? `已保存: ${workflowConfigEntity.scanConfig.accessKeyPreview}`
|
||
: "留空则保持服务端已保存密钥"
|
||
}
|
||
readOnly={isReadOnly}
|
||
disabled={isReadOnly}
|
||
/>
|
||
</div>
|
||
<div className="space-y-1">
|
||
<label className="text-[9px] text-gray-500 uppercase font-mono">
|
||
Secret Access Key
|
||
</label>
|
||
<input
|
||
type="password"
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs focus:outline-none focus:border-cyan-500 placeholder:text-gray-600 disabled:opacity-50"
|
||
value={workflowConfigEntity?.scanConfig?.secretAccessKey || ""}
|
||
onChange={(e) =>
|
||
updateScanWorkflowConfig({
|
||
secretAccessKey: e.target.value,
|
||
})
|
||
}
|
||
placeholder={
|
||
workflowConfigEntity?.scanConfig?.secretAccessKeyPreview
|
||
? `已保存: ${workflowConfigEntity.scanConfig.secretAccessKeyPreview}`
|
||
: "留空则保持服务端已保存密钥"
|
||
}
|
||
readOnly={isReadOnly}
|
||
disabled={isReadOnly}
|
||
/>
|
||
</div>
|
||
</div>
|
||
)}
|
||
</>
|
||
) : (
|
||
<div className="space-y-1">
|
||
<label className="text-[9px] text-gray-500 uppercase font-mono">扫描路径</label>
|
||
<input
|
||
type="text"
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs focus:outline-none focus:border-cyan-500 disabled:opacity-50"
|
||
value={workflowConfigEntity?.scanConfig?.sourcePath || ""}
|
||
onChange={(e) =>
|
||
updateScanWorkflowConfig({
|
||
sourcePath: e.target.value,
|
||
})
|
||
}
|
||
readOnly={isReadOnly}
|
||
disabled={isReadOnly}
|
||
/>
|
||
</div>
|
||
)}
|
||
|
||
<div className="grid grid-cols-1 gap-3 md:grid-cols-2">
|
||
<div className="space-y-1">
|
||
<label className="text-[9px] text-gray-500 uppercase font-mono">扫描模式</label>
|
||
<select
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs focus:outline-none focus:border-cyan-500 disabled:opacity-50"
|
||
value={workflowConfigEntity?.scanConfig?.scanMode || "INCREMENTAL"}
|
||
onChange={(e) =>
|
||
updateScanWorkflowConfig({
|
||
scanMode: e.target.value,
|
||
})
|
||
}
|
||
disabled={isReadOnly}
|
||
>
|
||
<option value="INCREMENTAL">INCREMENTAL</option>
|
||
<option value="FULL">FULL</option>
|
||
</select>
|
||
</div>
|
||
<div className="space-y-1">
|
||
<label className="text-[9px] text-gray-500 uppercase font-mono">增量单位</label>
|
||
<select
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs focus:outline-none focus:border-cyan-500 disabled:opacity-50"
|
||
value={workflowConfigEntity?.scanConfig?.incrementalUnit || "OBJECT"}
|
||
onChange={(e) =>
|
||
updateScanWorkflowConfig({
|
||
incrementalUnit: e.target.value,
|
||
})
|
||
}
|
||
disabled={
|
||
isReadOnly ||
|
||
(workflowConfigEntity?.scanConfig?.scanMode || "INCREMENTAL") === "FULL"
|
||
}
|
||
>
|
||
<option value="OBJECT">OBJECT</option>
|
||
<option value="DIRECTORY">DIRECTORY</option>
|
||
</select>
|
||
</div>
|
||
<div className="space-y-1">
|
||
<label className="text-[9px] text-gray-500 uppercase font-mono">目录层级</label>
|
||
<input
|
||
type="number"
|
||
min={1}
|
||
step={1}
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs focus:outline-none focus:border-cyan-500 disabled:opacity-50"
|
||
value={workflowConfigEntity?.scanConfig?.directoryDepth || 1}
|
||
onChange={(e) =>
|
||
updateScanWorkflowConfig({
|
||
directoryDepth: e.target.value,
|
||
})
|
||
}
|
||
readOnly={
|
||
isReadOnly ||
|
||
(workflowConfigEntity?.scanConfig?.scanMode || "INCREMENTAL") === "FULL"
|
||
}
|
||
disabled={
|
||
isReadOnly ||
|
||
(workflowConfigEntity?.scanConfig?.scanMode || "INCREMENTAL") === "FULL"
|
||
}
|
||
/>
|
||
</div>
|
||
<div className="space-y-1">
|
||
<label className="text-[9px] text-gray-500 uppercase font-mono">
|
||
文件匹配 Pattern
|
||
</label>
|
||
<input
|
||
type="text"
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs focus:outline-none focus:border-cyan-500 disabled:opacity-50"
|
||
value={workflowConfigEntity?.scanConfig?.pattern || ""}
|
||
onChange={(e) =>
|
||
updateScanWorkflowConfig({
|
||
pattern: e.target.value,
|
||
})
|
||
}
|
||
readOnly={isReadOnly}
|
||
disabled={isReadOnly}
|
||
/>
|
||
</div>
|
||
</div>
|
||
|
||
<p className="text-[9px] text-gray-500">
|
||
增量扫描状态会按 `workflow + node + bucket/prefix + 增量单位/目录层级`
|
||
独立维护;`OBJECT` 按文件增量发射,`DIRECTORY`
|
||
会在检测到新目录时一次性发射该目录下全部对象;切到 `FULL`
|
||
会重新处理当前范围内全部对象。
|
||
</p>
|
||
|
||
<div className="rounded-lg border border-cyan-500/20 bg-[#0a0a0a] p-3 space-y-3">
|
||
<div className="flex items-center justify-between gap-3">
|
||
<div className="flex items-center gap-2 text-cyan-300">
|
||
<Database className="w-3 h-3" />
|
||
<span className="text-[9px] font-bold uppercase tracking-wider">增量状态</span>
|
||
</div>
|
||
<button
|
||
type="button"
|
||
onClick={() => void handleResetSourceState()}
|
||
className="inline-flex items-center gap-1 rounded border border-cyan-500/20 bg-cyan-500/10 px-2 py-1 text-[10px] text-cyan-200 hover:bg-cyan-500/15 disabled:opacity-50"
|
||
disabled={
|
||
isReadOnly ||
|
||
!canManage ||
|
||
isResettingSourceState ||
|
||
!sourceState?.currentFingerprint ||
|
||
!sourceState?.current
|
||
}
|
||
>
|
||
<RotateCcw className="h-3 w-3" />
|
||
{isResettingSourceState ? "重置中..." : "重置当前状态"}
|
||
</button>
|
||
</div>
|
||
|
||
<p className="text-[9px] text-gray-500">
|
||
这里只显示服务端已保存的扫描源状态。修改 `bucket/prefix/scanMode`
|
||
后请先保存;状态只会在整条工作流成功后提交。
|
||
</p>
|
||
|
||
{isSourceStateLoading ? (
|
||
<div className="rounded border border-cyan-500/20 bg-cyan-500/5 px-2 py-3 text-[11px] text-cyan-200">
|
||
正在加载当前扫描源状态...
|
||
</div>
|
||
) : sourceStateError ? (
|
||
<div className="rounded border border-red-500/20 bg-red-500/10 px-2 py-3 text-[11px] text-red-200">
|
||
{sourceStateError}
|
||
</div>
|
||
) : !sourceState?.supported ? (
|
||
<div className="rounded border border-[#2a2b2f] bg-[#050505] px-2 py-3 text-[11px] text-gray-400">
|
||
{sourceState?.reason || "当前节点没有持久化状态"}
|
||
</div>
|
||
) : !sourceState.stateful ? (
|
||
<div className="rounded border border-amber-500/20 bg-amber-500/10 px-2 py-3 text-[11px] text-amber-100">
|
||
{sourceState.reason || "当前为 FULL 模式,不会持久化增量状态。"}
|
||
</div>
|
||
) : sourceState.current ? (
|
||
<div className="space-y-3">
|
||
<div className="grid grid-cols-2 gap-2">
|
||
<div className="rounded border border-[#2a2b2f] bg-[#050505] px-2 py-2">
|
||
<div className="text-[9px] font-mono uppercase text-gray-500">已记住对象</div>
|
||
<div className="mt-1 text-sm font-semibold text-white">
|
||
{sourceState.current.seenFingerprints?.length || 0}
|
||
</div>
|
||
</div>
|
||
<div className="rounded border border-[#2a2b2f] bg-[#050505] px-2 py-2">
|
||
<div className="text-[9px] font-mono uppercase text-gray-500">上次列出</div>
|
||
<div className="mt-1 text-sm font-semibold text-white">
|
||
{sourceState.current.lastListedCount ?? 0}
|
||
</div>
|
||
</div>
|
||
<div className="rounded border border-[#2a2b2f] bg-[#050505] px-2 py-2">
|
||
<div className="text-[9px] font-mono uppercase text-gray-500">上次新增</div>
|
||
<div className="mt-1 text-sm font-semibold text-white">
|
||
{sourceState.current.lastNewCount ?? 0}
|
||
</div>
|
||
</div>
|
||
<div className="rounded border border-[#2a2b2f] bg-[#050505] px-2 py-2">
|
||
<div className="text-[9px] font-mono uppercase text-gray-500">上次完成</div>
|
||
<div className="mt-1 text-[11px] text-white">
|
||
{sourceState.current.lastScanCompletedAt
|
||
? formatCompactDateTime(sourceState.current.lastScanCompletedAt, timeZone)
|
||
: "--"}
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div className="grid grid-cols-1 gap-2">
|
||
<div className="rounded border border-[#2a2b2f] bg-[#050505] px-2 py-2">
|
||
<div className="text-[9px] font-mono uppercase text-gray-500">
|
||
当前状态指纹
|
||
</div>
|
||
<div className="mt-1 break-all font-mono text-[10px] text-cyan-200">
|
||
{sourceState.currentFingerprint || "--"}
|
||
</div>
|
||
</div>
|
||
<div className="rounded border border-[#2a2b2f] bg-[#050505] px-2 py-2">
|
||
<div className="text-[9px] font-mono uppercase text-gray-500">
|
||
最近写入 Run
|
||
</div>
|
||
<div className="mt-1 break-all font-mono text-[10px] text-white">
|
||
{sourceState.current.lastRunId || "--"}
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
) : (
|
||
<div className="rounded border border-[#2a2b2f] bg-[#050505] px-2 py-3 text-[11px] text-gray-400">
|
||
{sourceState?.reason || "当前配置下还没有已提交的增量状态。"}
|
||
</div>
|
||
)}
|
||
|
||
{sourceState?.versions && sourceState.versions.length > 0 && (
|
||
<div className="space-y-1">
|
||
<div className="text-[9px] font-mono uppercase text-gray-500">
|
||
历史状态版本 {sourceState.versions.length}
|
||
</div>
|
||
<div className="space-y-1">
|
||
{sourceState.versions.slice(0, 3).map((item) => (
|
||
<div
|
||
key={item.id}
|
||
className="rounded border border-[#2a2b2f] bg-[#050505] px-2 py-2 text-[10px] text-gray-300"
|
||
>
|
||
<div className="flex items-center justify-between gap-2">
|
||
<span className="font-mono text-cyan-200">
|
||
{item.sourceFingerprint.slice(0, 10)}...
|
||
</span>
|
||
<span className="text-gray-500">
|
||
{item.updatedAt
|
||
? formatCompactDateTime(item.updatedAt, timeZone)
|
||
: "--"}
|
||
</span>
|
||
</div>
|
||
<div className="mt-1 text-gray-400">
|
||
Run {item.lastRunId || "--"} · listed {item.lastListedCount ?? 0} · new{" "}
|
||
{item.lastNewCount ?? 0}
|
||
</div>
|
||
</div>
|
||
))}
|
||
</div>
|
||
</div>
|
||
)}
|
||
</div>
|
||
</div>
|
||
)}
|
||
|
||
{isMongoWriteNode(selectedNode) && (
|
||
<div className="space-y-3 rounded-lg border border-emerald-500/20 bg-emerald-500/5 p-3">
|
||
<div className="flex items-center gap-2 text-emerald-400">
|
||
<Database className="h-3 w-3" />
|
||
<span className="text-[9px] font-bold uppercase tracking-wider">
|
||
MongoDB 写入配置
|
||
</span>
|
||
</div>
|
||
|
||
<div className="flex items-start justify-between gap-3">
|
||
<div>
|
||
<div className="text-[9px] font-mono uppercase text-gray-500">
|
||
业务 MongoDB 连接
|
||
</div>
|
||
<div className="text-[11px] text-gray-400">
|
||
平台库不会作为写入目标。请选择一个用户创建的业务 MongoDB 连接,或显式填写 URI/DB
|
||
超参。
|
||
</div>
|
||
</div>
|
||
<div className="flex items-center gap-2">
|
||
<button
|
||
type="button"
|
||
onClick={() => loadMongoConnections()}
|
||
className="rounded border border-[#2a2b2f] px-2 py-1 text-[10px] text-gray-300 hover:border-emerald-500/40 hover:text-emerald-300 disabled:opacity-50"
|
||
disabled={isReadOnly || isMongoConnectionsLoading}
|
||
>
|
||
{isMongoConnectionsLoading ? "刷新中..." : "刷新"}
|
||
</button>
|
||
<button
|
||
type="button"
|
||
onClick={() => navigate("/database")}
|
||
className="rounded border border-emerald-500/30 bg-emerald-500/10 px-2 py-1 text-[10px] text-emerald-200 hover:bg-emerald-500/15"
|
||
>
|
||
管理连接
|
||
</button>
|
||
</div>
|
||
</div>
|
||
|
||
<div className="space-y-1">
|
||
<label className="text-[9px] font-mono uppercase text-gray-500">已选连接</label>
|
||
<select
|
||
className="w-full rounded border border-[#2a2b2f] bg-[#0a0a0a] px-2 py-1 text-xs focus:border-emerald-500 focus:outline-none disabled:opacity-50"
|
||
value={selectedNodeMongoConnectionId}
|
||
onChange={(event) => handleMongoConnectionSelect(event.target.value)}
|
||
disabled={isReadOnly || isMongoConnectionsLoading}
|
||
>
|
||
<option value="">使用节点超参里的 MONGO_URI / MONGO_DB</option>
|
||
{mongoConnections.map((connection) => (
|
||
<option key={connection.id} value={connection.id}>
|
||
{connection.name}
|
||
</option>
|
||
))}
|
||
</select>
|
||
</div>
|
||
|
||
{mongoConnectionsError && (
|
||
<div className="rounded border border-amber-500/20 bg-amber-500/10 px-2 py-1 text-[10px] text-amber-200">
|
||
{mongoConnectionsError}
|
||
</div>
|
||
)}
|
||
|
||
{selectedNodeMongoConnection ? (
|
||
<div className="grid grid-cols-1 gap-3 md:grid-cols-3">
|
||
<div className="rounded border border-[#2a2b2f] bg-[#0a0a0a] px-2 py-2">
|
||
<div className="text-[9px] font-mono uppercase text-gray-500">连接名称</div>
|
||
<div className="mt-1 text-[11px] text-gray-100">
|
||
{selectedNodeMongoConnection.name}
|
||
</div>
|
||
</div>
|
||
<div className="rounded border border-[#2a2b2f] bg-[#0a0a0a] px-2 py-2">
|
||
<div className="text-[9px] font-mono uppercase text-gray-500">数据库</div>
|
||
<div className="mt-1 break-all text-[11px] text-gray-100">
|
||
{selectedNodeMongoConnection.database || "--"}
|
||
</div>
|
||
</div>
|
||
<div className="rounded border border-[#2a2b2f] bg-[#0a0a0a] px-2 py-2">
|
||
<div className="text-[9px] font-mono uppercase text-gray-500">Mongo URI</div>
|
||
<div className="mt-1 break-all text-[11px] text-gray-100">
|
||
{selectedNodeMongoConnection.uriPreview || "已保存"}
|
||
</div>
|
||
</div>
|
||
</div>
|
||
) : (
|
||
<div className="rounded border border-[#2a2b2f] bg-[#050505] px-2 py-3 text-[11px] text-gray-400">
|
||
当前没有绑定业务 MongoDB 连接。若不选择连接,节点将只使用超参里的
|
||
<span className="mx-1 font-mono text-emerald-200">MONGO_URI / MONGO_DB</span>
|
||
显式配置。
|
||
</div>
|
||
)}
|
||
</div>
|
||
)}
|
||
|
||
{/* Specialized OSS Config */}
|
||
{isOssNode(selectedNode) && (
|
||
<div className="p-3 bg-blue-500/5 border border-blue-500/20 rounded-lg space-y-3">
|
||
<div className="flex items-center gap-2 text-blue-400 mb-1">
|
||
<Database className="w-3 h-3" />
|
||
<span className="text-[9px] font-bold uppercase tracking-wider">OSS 数据源配置</span>
|
||
</div>
|
||
|
||
<div className="space-y-3 rounded-lg border border-blue-500/20 bg-blue-500/5 p-3">
|
||
<div className="flex items-center justify-between gap-3">
|
||
<div>
|
||
<div className="text-[9px] font-mono uppercase text-gray-500">BOS 连接</div>
|
||
<div className="text-[11px] text-gray-400">
|
||
节点优先引用存储连接;浏览器会直接列出该连接下的真实 bucket 和前缀。
|
||
</div>
|
||
</div>
|
||
<div className="flex items-center gap-2">
|
||
<button
|
||
type="button"
|
||
onClick={() => loadStorageConnections()}
|
||
className="rounded border border-[#2a2b2f] px-2 py-1 text-[10px] text-gray-300 hover:border-blue-500/40 hover:text-blue-300 disabled:opacity-50"
|
||
disabled={isReadOnly || isStorageConnectionsLoading}
|
||
>
|
||
{isStorageConnectionsLoading ? "刷新中..." : "刷新"}
|
||
</button>
|
||
<button
|
||
type="button"
|
||
onClick={() => setIsStorageConnectionFormOpen((current) => !current)}
|
||
className="rounded border border-blue-500/30 bg-blue-500/10 px-2 py-1 text-[10px] text-blue-200 hover:bg-blue-500/15 disabled:opacity-50"
|
||
disabled={isReadOnly}
|
||
>
|
||
{isStorageConnectionFormOpen ? "收起新建" : "新建连接"}
|
||
</button>
|
||
</div>
|
||
</div>
|
||
|
||
<div className="space-y-1">
|
||
<label className="text-[9px] text-gray-500 uppercase font-mono">已选连接</label>
|
||
<select
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs focus:outline-none focus:border-blue-500 disabled:opacity-50"
|
||
value={selectedNode.data.connectionId || ""}
|
||
onChange={(e) => handleStorageConnectionSelect(e.target.value, "node")}
|
||
disabled={isReadOnly || isStorageConnectionsLoading}
|
||
>
|
||
<option value="">继续使用节点超参里的 BOS 凭据</option>
|
||
{storageConnections.map((connection) => (
|
||
<option key={connection.id} value={connection.id}>
|
||
{connection.name}
|
||
</option>
|
||
))}
|
||
</select>
|
||
</div>
|
||
|
||
{storageConnectionsError && (
|
||
<div className="rounded border border-amber-500/20 bg-amber-500/10 px-2 py-1 text-[10px] text-amber-200">
|
||
{storageConnectionsError}
|
||
</div>
|
||
)}
|
||
|
||
{nodeStorageConnection && (
|
||
<div className="grid grid-cols-1 gap-3 md:grid-cols-3">
|
||
<div className="rounded border border-[#2a2b2f] bg-[#0a0a0a] px-2 py-2">
|
||
<div className="text-[9px] font-mono uppercase text-gray-500">Endpoint</div>
|
||
<div className="mt-1 break-all text-[11px] text-gray-200">
|
||
{nodeStorageConnection.endpoint || GLOBAL_BOS_ENDPOINT_LABEL}
|
||
</div>
|
||
</div>
|
||
<div className="rounded border border-[#2a2b2f] bg-[#0a0a0a] px-2 py-2">
|
||
<div className="text-[9px] font-mono uppercase text-gray-500">Access Key</div>
|
||
<div className="mt-1 text-[11px] text-gray-200">
|
||
{nodeStorageConnection.accessKeyPreview || "已保存"}
|
||
</div>
|
||
</div>
|
||
<div className="rounded border border-[#2a2b2f] bg-[#0a0a0a] px-2 py-2">
|
||
<div className="text-[9px] font-mono uppercase text-gray-500">Secret Key</div>
|
||
<div className="mt-1 text-[11px] text-gray-200">
|
||
{nodeStorageConnection.secretAccessKeyPreview || "已保存"}
|
||
</div>
|
||
</div>
|
||
</div>
|
||
)}
|
||
|
||
{isStorageConnectionFormOpen && (
|
||
<div className="grid grid-cols-1 gap-3 md:grid-cols-2">
|
||
<div className="space-y-1">
|
||
<label className="text-[9px] text-gray-500 uppercase font-mono">连接名称</label>
|
||
<input
|
||
type="text"
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs focus:outline-none focus:border-blue-500 disabled:opacity-50"
|
||
value={storageConnectionDraft.name}
|
||
onChange={(e) =>
|
||
setStorageConnectionDraft((current) => ({
|
||
...current,
|
||
name: e.target.value,
|
||
}))
|
||
}
|
||
readOnly={isReadOnly}
|
||
disabled={isReadOnly || isSavingStorageConnection}
|
||
/>
|
||
</div>
|
||
<div className="space-y-1">
|
||
<label className="text-[9px] text-gray-500 uppercase font-mono">描述</label>
|
||
<input
|
||
type="text"
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs focus:outline-none focus:border-blue-500 disabled:opacity-50"
|
||
value={storageConnectionDraft.description}
|
||
onChange={(e) =>
|
||
setStorageConnectionDraft((current) => ({
|
||
...current,
|
||
description: e.target.value,
|
||
}))
|
||
}
|
||
readOnly={isReadOnly}
|
||
disabled={isReadOnly || isSavingStorageConnection}
|
||
/>
|
||
</div>
|
||
<div className="space-y-1 md:col-span-2">
|
||
<label className="text-[9px] text-gray-500 uppercase font-mono">Endpoint</label>
|
||
<input
|
||
type="text"
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs focus:outline-none focus:border-blue-500 disabled:opacity-50"
|
||
value={storageConnectionDraft.endpoint}
|
||
onChange={(e) =>
|
||
setStorageConnectionDraft((current) => ({
|
||
...current,
|
||
endpoint: e.target.value,
|
||
}))
|
||
}
|
||
placeholder="可选;留空则依赖全局 BOS_ENDPOINT"
|
||
readOnly={isReadOnly}
|
||
disabled={isReadOnly || isSavingStorageConnection}
|
||
/>
|
||
</div>
|
||
<div className="space-y-1">
|
||
<label className="text-[9px] text-gray-500 uppercase font-mono">
|
||
Access Key ID
|
||
</label>
|
||
<input
|
||
type="password"
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs focus:outline-none focus:border-blue-500 disabled:opacity-50"
|
||
value={storageConnectionDraft.accessKeyId}
|
||
onChange={(e) =>
|
||
setStorageConnectionDraft((current) => ({
|
||
...current,
|
||
accessKeyId: e.target.value,
|
||
}))
|
||
}
|
||
readOnly={isReadOnly}
|
||
disabled={isReadOnly || isSavingStorageConnection}
|
||
/>
|
||
</div>
|
||
<div className="space-y-1">
|
||
<label className="text-[9px] text-gray-500 uppercase font-mono">
|
||
Secret Access Key
|
||
</label>
|
||
<input
|
||
type="password"
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs focus:outline-none focus:border-blue-500 disabled:opacity-50"
|
||
value={storageConnectionDraft.secretAccessKey}
|
||
onChange={(e) =>
|
||
setStorageConnectionDraft((current) => ({
|
||
...current,
|
||
secretAccessKey: e.target.value,
|
||
}))
|
||
}
|
||
readOnly={isReadOnly}
|
||
disabled={isReadOnly || isSavingStorageConnection}
|
||
/>
|
||
</div>
|
||
<div className="md:col-span-2 flex justify-end">
|
||
<button
|
||
type="button"
|
||
onClick={() => void handleCreateStorageConnection()}
|
||
className="rounded border border-blue-500/30 bg-blue-500/10 px-3 py-1.5 text-[11px] text-blue-200 hover:bg-blue-500/15 disabled:opacity-50"
|
||
disabled={isReadOnly || isSavingStorageConnection}
|
||
>
|
||
{isSavingStorageConnection ? "创建中..." : "保存并绑定该连接"}
|
||
</button>
|
||
</div>
|
||
</div>
|
||
)}
|
||
</div>
|
||
|
||
<div className="space-y-1">
|
||
<label className="text-[9px] text-gray-500 uppercase font-mono">SOURCE_PATH</label>
|
||
<input
|
||
type="text"
|
||
placeholder="请在下方超参配置中填写 SOURCE_PATH"
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs text-gray-400 font-mono"
|
||
value={selectedNodeSourcePath}
|
||
readOnly
|
||
/>
|
||
<p className="text-[9px] text-gray-600">
|
||
优先使用节点绑定的 BOS 连接浏览真实
|
||
bucket/prefix;未绑定连接时,回退读取节点超参里的 `SOURCE_PATH`。
|
||
</p>
|
||
</div>
|
||
|
||
<div className="space-y-1">
|
||
<label className="text-[9px] text-gray-500 uppercase font-mono">
|
||
存储桶 (Bucket)
|
||
</label>
|
||
{selectedStoragePathKey && (
|
||
<div className="mb-2 flex justify-end">
|
||
<button
|
||
type="button"
|
||
onClick={toggleCurrentStoragePathFavorite}
|
||
className={cn(
|
||
"inline-flex items-center gap-1 rounded border px-2 py-1 text-[10px] transition-colors disabled:opacity-50",
|
||
isCurrentStoragePathFavorite
|
||
? "border-amber-500/30 bg-amber-500/10 text-amber-200 hover:bg-amber-500/15"
|
||
: "border-[#2a2b2f] bg-[#0a0a0a] text-gray-300 hover:border-amber-500/30 hover:text-amber-200",
|
||
)}
|
||
disabled={isReadOnly}
|
||
>
|
||
<Star
|
||
className="h-3 w-3"
|
||
fill={isCurrentStoragePathFavorite ? "currentColor" : "none"}
|
||
/>
|
||
{isCurrentStoragePathFavorite ? "取消收藏当前路径" : "收藏当前路径"}
|
||
</button>
|
||
{workflowProjectId && (
|
||
<button
|
||
type="button"
|
||
onClick={() => void toggleCurrentProjectStoragePathFavorite()}
|
||
className={cn(
|
||
"inline-flex items-center gap-1 rounded border px-2 py-1 text-[10px] transition-colors disabled:opacity-50",
|
||
isCurrentProjectStoragePathFavorite
|
||
? "border-cyan-500/30 bg-cyan-500/10 text-cyan-200 hover:bg-cyan-500/15"
|
||
: "border-[#2a2b2f] bg-[#0a0a0a] text-gray-300 hover:border-cyan-500/30 hover:text-cyan-200",
|
||
)}
|
||
disabled={isReadOnly}
|
||
>
|
||
<Users className="h-3 w-3" />
|
||
{isCurrentProjectStoragePathFavorite ? "移出项目常用" : "加入项目常用"}
|
||
</button>
|
||
)}
|
||
</div>
|
||
)}
|
||
{projectFavoriteStoragePaths.length > 0 && (
|
||
<div className="mb-2 space-y-1">
|
||
<div className="flex items-center gap-1 text-[9px] font-mono uppercase text-cyan-300">
|
||
<Users className="h-2.5 w-2.5" />
|
||
项目常用路径
|
||
</div>
|
||
<div className="flex flex-wrap gap-1.5">
|
||
{projectFavoriteStoragePaths.map((item) => (
|
||
<button
|
||
key={`${item.bucket}/${item.prefix}`}
|
||
type="button"
|
||
onClick={() => applyFavoriteStoragePath(item.bucket, item.prefix)}
|
||
className="rounded-full border border-cyan-500/20 bg-cyan-500/10 px-2 py-1 text-[10px] text-cyan-100 hover:bg-cyan-500/15 disabled:opacity-50"
|
||
disabled={isReadOnly}
|
||
title={item.label}
|
||
>
|
||
{item.label}
|
||
</button>
|
||
))}
|
||
</div>
|
||
</div>
|
||
)}
|
||
{visibleUserFavoriteStoragePaths.length > 0 && (
|
||
<div className="mb-2 space-y-1">
|
||
<div className="flex items-center gap-1 text-[9px] font-mono uppercase text-amber-300">
|
||
<Star className="h-2.5 w-2.5" />
|
||
我的常用路径
|
||
</div>
|
||
<div className="flex flex-wrap gap-1.5">
|
||
{visibleUserFavoriteStoragePaths.map((item) => (
|
||
<button
|
||
key={`${item.bucket}/${item.prefix}`}
|
||
type="button"
|
||
onClick={() => applyFavoriteStoragePath(item.bucket, item.prefix)}
|
||
className="rounded-full border border-amber-500/20 bg-amber-500/10 px-2 py-1 text-[10px] text-amber-100 hover:bg-amber-500/15 disabled:opacity-50"
|
||
disabled={isReadOnly}
|
||
title={item.label}
|
||
>
|
||
{item.label}
|
||
</button>
|
||
))}
|
||
</div>
|
||
</div>
|
||
)}
|
||
{visibleRecentStoragePaths.length > 0 && (
|
||
<div className="mb-2 space-y-1">
|
||
<div className="flex items-center gap-1 text-[9px] font-mono uppercase text-gray-500">
|
||
<RotateCcw className="h-2.5 w-2.5" />
|
||
最近使用路径
|
||
</div>
|
||
<div className="flex flex-wrap gap-1.5">
|
||
{visibleRecentStoragePaths.map((item) => (
|
||
<button
|
||
key={`${item.bucket}/${item.prefix}`}
|
||
type="button"
|
||
onClick={() => applyRecentStoragePath(item.bucket, item.prefix)}
|
||
className="rounded-full border border-blue-500/20 bg-blue-500/10 px-2 py-1 text-[10px] text-blue-100 hover:bg-blue-500/15 disabled:opacity-50"
|
||
disabled={isReadOnly}
|
||
title={item.label}
|
||
>
|
||
{item.label}
|
||
</button>
|
||
))}
|
||
</div>
|
||
</div>
|
||
)}
|
||
<select
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs focus:outline-none focus:border-blue-500 disabled:opacity-50"
|
||
value={selectedNode.data.bucket || ""}
|
||
onChange={(e) => {
|
||
const nextBucket = e.target.value;
|
||
updateOssNodeConfig({ bucket: nextBucket });
|
||
rememberRecentStoragePath(nextBucket, selectedNode.data.prefix || "");
|
||
}}
|
||
disabled={isReadOnly || !canBrowseSelectedStorage}
|
||
>
|
||
<option value="">
|
||
{canBrowseSelectedStorage ? "选择存储桶..." : "请先选择连接或配置 SOURCE_PATH"}
|
||
</option>
|
||
{buckets.map((b) => (
|
||
<option key={b} value={b}>
|
||
{b}
|
||
</option>
|
||
))}
|
||
</select>
|
||
{!canBrowseSelectedStorage && (
|
||
<p className="text-[9px] text-amber-400">
|
||
先绑定 BOS 连接,或在节点超参里配置 `SOURCE_PATH`,再浏览该路径下的 bucket。
|
||
</p>
|
||
)}
|
||
</div>
|
||
|
||
<div className="space-y-1">
|
||
<label className="text-[9px] text-gray-500 uppercase font-mono">
|
||
路径前缀 (Prefix)
|
||
</label>
|
||
<div className="relative">
|
||
<input
|
||
type="text"
|
||
placeholder="e.g. dataset/v1/"
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs focus:outline-none focus:border-blue-500 disabled:opacity-50"
|
||
value={selectedNode.data.prefix || ""}
|
||
onChange={(e) =>
|
||
updateOssNodeConfig({
|
||
prefix: e.target.value,
|
||
})
|
||
}
|
||
onBlur={(e) =>
|
||
rememberRecentStoragePath(selectedNode.data.bucket || "", e.target.value)
|
||
}
|
||
readOnly={isReadOnly}
|
||
disabled={isReadOnly}
|
||
/>
|
||
<button
|
||
type="button"
|
||
onClick={() => setIsOssBrowsing(true)}
|
||
className="absolute right-1 top-1/2 -translate-y-1/2 p-1 hover:bg-white/5 rounded text-blue-500"
|
||
disabled={
|
||
isReadOnly ||
|
||
(!selectedNode.data.bucket &&
|
||
visibleRecentStoragePaths.length === 0 &&
|
||
favoriteStoragePaths.length === 0 &&
|
||
projectFavoriteStoragePaths.length === 0) ||
|
||
!canBrowseSelectedStorage
|
||
}
|
||
>
|
||
<FolderOpen className="w-3 h-3" />
|
||
</button>
|
||
</div>
|
||
</div>
|
||
|
||
<div className="space-y-1">
|
||
<label className="text-[9px] text-gray-500 uppercase font-mono">
|
||
文件过滤 (Pattern)
|
||
</label>
|
||
<input
|
||
type="text"
|
||
placeholder="e.g. *.mp4"
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs focus:outline-none focus:border-blue-500 disabled:opacity-50"
|
||
value={selectedNode.data.pattern || ""}
|
||
onChange={(e) =>
|
||
updateOssNodeConfig({
|
||
pattern: e.target.value,
|
||
})
|
||
}
|
||
readOnly={isReadOnly}
|
||
disabled={isReadOnly}
|
||
/>
|
||
</div>
|
||
|
||
{ossBrowseError && !isOssBrowsing && (
|
||
<p className="text-[9px] text-amber-400 break-all">{ossBrowseError}</p>
|
||
)}
|
||
</div>
|
||
)}
|
||
|
||
{/* Specialized Task Distribution Config */}
|
||
{selectedNode.data.label.includes("分配") && (
|
||
<div className="p-3 bg-purple-500/5 border border-purple-500/20 rounded-lg space-y-3">
|
||
<div className="flex items-center gap-2 text-purple-400 mb-1">
|
||
<Shuffle className="w-3 h-3" />
|
||
<span className="text-[9px] font-bold uppercase tracking-wider">任务分配配置</span>
|
||
</div>
|
||
|
||
<div className="flex items-center justify-between">
|
||
<label className="text-[9px] text-gray-500 uppercase font-mono">
|
||
开启 Shuffle (洗牌)
|
||
</label>
|
||
<input
|
||
type="checkbox"
|
||
className="w-4 h-4 rounded bg-[#0a0a0a] border-[#2a2b2f] text-purple-500 focus:ring-purple-500"
|
||
checked={selectedNode.data.shuffle !== false}
|
||
onChange={(e) =>
|
||
updateNodeData({
|
||
shuffle: e.target.checked,
|
||
})
|
||
}
|
||
disabled={isReadOnly}
|
||
/>
|
||
</div>
|
||
|
||
<div className="space-y-1">
|
||
<label className="text-[9px] text-gray-500 uppercase font-mono">分配模式</label>
|
||
<select
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs focus:outline-none focus:border-purple-500 disabled:opacity-50"
|
||
value={selectedNode.data.distMode || "ratio"}
|
||
onChange={(e) =>
|
||
updateNodeData({
|
||
distMode: e.target.value,
|
||
})
|
||
}
|
||
disabled={isReadOnly}
|
||
>
|
||
<option value="ratio">按比例分配 (%)</option>
|
||
<option value="count">按数量分配 (Count)</option>
|
||
</select>
|
||
</div>
|
||
|
||
<div className="space-y-2">
|
||
<label className="text-[9px] text-gray-500 uppercase font-mono">出口权重设置</label>
|
||
{(selectedNode.data.outputs || []).map((port: any, idx: number) => (
|
||
<div key={port.id} className="flex items-center gap-2">
|
||
<span className="text-[10px] text-gray-400 w-12 truncate">{port.name}</span>
|
||
<input
|
||
type="number"
|
||
className="flex-1 bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs focus:outline-none focus:border-purple-500 disabled:opacity-50"
|
||
placeholder={selectedNode.data.distMode === "ratio" ? "比例" : "数量"}
|
||
value={selectedNode.data.weights?.[port.id] || ""}
|
||
onChange={(e) => {
|
||
const newWeights = {
|
||
...(selectedNode.data.weights || {}),
|
||
[port.id]: e.target.value,
|
||
};
|
||
updateNodeData({
|
||
weights: newWeights,
|
||
});
|
||
}}
|
||
disabled={isReadOnly}
|
||
/>
|
||
<span className="text-[9px] text-gray-600">
|
||
{selectedNode.data.distMode === "ratio" ? "%" : "pcs"}
|
||
</span>
|
||
</div>
|
||
))}
|
||
</div>
|
||
</div>
|
||
)}
|
||
|
||
{/* Hyperparameters Config (K8s Env Vars) */}
|
||
{selectedNode?.type === "operator" && selectedNodeEnvRows.length > 0 && (
|
||
<div className="p-3 bg-green-500/5 border border-green-500/20 rounded-lg space-y-3">
|
||
<div className="flex items-center gap-2 text-green-400 mb-1">
|
||
<Terminal className="w-3 h-3" />
|
||
<span className="text-[9px] font-bold uppercase tracking-wider">
|
||
超参配置 (K8s Job Env)
|
||
</span>
|
||
</div>
|
||
<p className="text-[10px] text-gray-500 leading-relaxed">
|
||
节点自定义 env 可编辑;继承自工作流和系统注入项为只读。
|
||
系统时间戳只会在周期执行时出现,值与实际运行时完全一致。 已加载 run
|
||
时显示真实值;未加载 run 时显示“如果现在按当前调度执行”的预览值。 时间格式固定为{" "}
|
||
<code>Asia/Shanghai</code>。
|
||
</p>
|
||
|
||
<div className="space-y-3">
|
||
{selectedNodeEnvRows.map((hp: any) => {
|
||
const isSystemEnv = hp.source === "system";
|
||
const isWorkflowEnv = hp.source === "workflow";
|
||
return (
|
||
<div key={`${hp.source}-${hp.key}-${hp.index ?? ""}`} className="space-y-1.5">
|
||
<div className="flex flex-wrap items-center gap-2">
|
||
<label className="min-w-0 break-all text-[9px] text-gray-500 uppercase font-mono">
|
||
{hp.key}
|
||
</label>
|
||
{isSystemEnv && (
|
||
<span className="shrink-0 rounded border border-emerald-400/30 bg-emerald-500/10 px-1.5 py-0.5 text-[8px] font-mono uppercase tracking-wider text-emerald-200">
|
||
系统注入
|
||
</span>
|
||
)}
|
||
{isWorkflowEnv && (
|
||
<span className="shrink-0 rounded border border-sky-400/30 bg-sky-500/10 px-1.5 py-0.5 text-[8px] font-mono uppercase tracking-wider text-sky-200">
|
||
继承自工作流
|
||
</span>
|
||
)}
|
||
</div>
|
||
{hp.description && (
|
||
<p className="text-[10px] leading-relaxed text-gray-500">{hp.description}</p>
|
||
)}
|
||
<input
|
||
type="text"
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs focus:outline-none focus:border-green-500 disabled:opacity-100 font-mono"
|
||
value={hp.value}
|
||
onChange={
|
||
isSystemEnv || isWorkflowEnv
|
||
? undefined
|
||
: (e) => {
|
||
const newHyperparams = [...selectedNode.data.hyperparams];
|
||
newHyperparams[hp.index] = {
|
||
...newHyperparams[hp.index],
|
||
value: e.target.value,
|
||
};
|
||
updateNodeData({
|
||
hyperparams: newHyperparams,
|
||
});
|
||
}
|
||
}
|
||
readOnly={isReadOnly || isSystemEnv || isWorkflowEnv}
|
||
disabled={isReadOnly || isSystemEnv || isWorkflowEnv}
|
||
/>
|
||
</div>
|
||
);
|
||
})}
|
||
</div>
|
||
</div>
|
||
)}
|
||
|
||
{selectedNode?.type === "operator" &&
|
||
isAIGeneratedOperator(selectedNode.data as OperatorNodeData) && (
|
||
<div className="space-y-2 rounded-lg border border-pink-500/20 bg-pink-500/5 p-3">
|
||
<div className="flex items-center justify-between gap-3">
|
||
<div className="flex items-center gap-2 text-pink-200">
|
||
<Shield className="h-3.5 w-3.5" />
|
||
<span className="text-[9px] font-bold uppercase tracking-wider">
|
||
AI 算子发布状态
|
||
</span>
|
||
</div>
|
||
<span className="rounded border border-pink-400/30 bg-pink-500/10 px-2 py-0.5 text-[9px] font-semibold text-pink-100">
|
||
{publicationStatusLabel(
|
||
operatorPublicationStatus(selectedNode.data as OperatorNodeData),
|
||
)}
|
||
</span>
|
||
</div>
|
||
<div className="grid grid-cols-1 gap-2 text-[10px] text-gray-500">
|
||
{selectedNode.data.publicationEvidence?.repositoryUrl && (
|
||
<div className="break-all">
|
||
Repo: {selectedNode.data.publicationEvidence.repositoryUrl}
|
||
</div>
|
||
)}
|
||
{selectedNode.data.publicationEvidence?.acceptanceRunId && (
|
||
<div className="break-all">
|
||
验收 Run: {selectedNode.data.publicationEvidence.acceptanceRunId}
|
||
</div>
|
||
)}
|
||
{operatorPublicationStatus(selectedNode.data as OperatorNodeData) !==
|
||
"published" && (
|
||
<div className="text-pink-200">
|
||
当前只适合沙盒验证;发布前需要真实代码、单测、CCR digest 和 workflow 验收证据。
|
||
</div>
|
||
)}
|
||
</div>
|
||
</div>
|
||
)}
|
||
|
||
<div className="space-y-1">
|
||
<label className="text-[10px] text-gray-500 uppercase font-mono">
|
||
容器镜像 (Docker Image)
|
||
</label>
|
||
<input
|
||
type="text"
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs focus:outline-none focus:border-blue-500 disabled:opacity-50"
|
||
value={selectedNode.data.image || ""}
|
||
onChange={(e) => updateNodeData({ image: e.target.value })}
|
||
readOnly={isReadOnly}
|
||
disabled={isReadOnly}
|
||
/>
|
||
</div>
|
||
|
||
{(selectedNode.data.operatorVersion || selectedNode.data.operatorImageId) && (
|
||
<div className="grid grid-cols-1 gap-2">
|
||
{selectedNode.data.operatorVersion && (
|
||
<div className="space-y-1">
|
||
<label className="text-[10px] text-gray-500 uppercase font-mono">
|
||
算子版本 (Pinned Version)
|
||
</label>
|
||
<input
|
||
type="text"
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs text-amber-300 disabled:opacity-80"
|
||
value={selectedNode.data.operatorVersion}
|
||
readOnly
|
||
disabled
|
||
/>
|
||
</div>
|
||
)}
|
||
{selectedNode.data.operatorImageId && (
|
||
<div className="space-y-1">
|
||
<label className="text-[10px] text-gray-500 uppercase font-mono">
|
||
镜像 Digest (Image ID)
|
||
</label>
|
||
<input
|
||
type="text"
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs text-gray-400 disabled:opacity-80"
|
||
value={selectedNode.data.operatorImageId}
|
||
readOnly
|
||
disabled
|
||
/>
|
||
</div>
|
||
)}
|
||
</div>
|
||
)}
|
||
|
||
<div className={cn("grid gap-2", isConfigPanelExpanded ? "grid-cols-3" : "grid-cols-2")}>
|
||
<div className="space-y-1">
|
||
<label className="text-[10px] text-gray-500 uppercase font-mono">资源限制 (CPU)</label>
|
||
<input
|
||
type="text"
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs focus:outline-none focus:border-blue-500 disabled:opacity-50"
|
||
value={selectedNode.data.cpu || "500m"}
|
||
onChange={(e) => updateNodeData({ cpu: e.target.value })}
|
||
readOnly={isReadOnly}
|
||
disabled={isReadOnly}
|
||
/>
|
||
</div>
|
||
<div className="space-y-1">
|
||
<label className="text-[10px] text-gray-500 uppercase font-mono">资源限制 (MEM)</label>
|
||
<input
|
||
type="text"
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs focus:outline-none focus:border-blue-500 disabled:opacity-50"
|
||
value={selectedNode.data.memory || "1Gi"}
|
||
onChange={(e) => updateNodeData({ memory: e.target.value })}
|
||
readOnly={isReadOnly}
|
||
disabled={isReadOnly}
|
||
/>
|
||
</div>
|
||
<div className="space-y-1">
|
||
<label className="text-[10px] text-gray-500 uppercase font-mono">GPU 数量</label>
|
||
<input
|
||
type="text"
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs focus:outline-none focus:border-blue-500 disabled:opacity-50"
|
||
value={selectedNode.data.gpu || ""}
|
||
placeholder="0"
|
||
onChange={(e) => updateNodeData({ gpu: e.target.value })}
|
||
readOnly={isReadOnly}
|
||
disabled={isReadOnly}
|
||
/>
|
||
{selectedNodeGPUBlocked && (
|
||
<p className="rounded border border-amber-500/20 bg-amber-500/10 px-2 py-1 text-[10px] leading-snug text-amber-300">
|
||
{gpuStatus.label}:{gpuStatus.detail}
|
||
</p>
|
||
)}
|
||
{selectedNodeRequestsGPU && workerCapacityError && (
|
||
<p className="rounded border border-red-500/20 bg-red-500/10 px-2 py-1 text-[10px] leading-snug text-red-300">
|
||
{workerCapacityError}
|
||
</p>
|
||
)}
|
||
</div>
|
||
</div>
|
||
|
||
<div className="space-y-3">
|
||
<div className="flex items-center justify-between">
|
||
<label className="text-[10px] text-gray-500 uppercase font-mono">
|
||
输入端口 (Inputs)
|
||
</label>
|
||
{!isReadOnly && (
|
||
<button
|
||
onClick={() => {
|
||
const newInputs = [
|
||
...(selectedNode.data.inputs || []),
|
||
{
|
||
id: `in-${Date.now()}`,
|
||
name: "new_input",
|
||
type: "json",
|
||
},
|
||
];
|
||
updateNodeData({ inputs: newInputs });
|
||
}}
|
||
className="text-[10px] text-blue-500 hover:underline"
|
||
>
|
||
+ 添加
|
||
</button>
|
||
)}
|
||
</div>
|
||
<div className="space-y-2">
|
||
{(selectedNode.data.inputs || []).map((port: any, idx: number) => (
|
||
<div
|
||
key={port.id}
|
||
className="flex items-center gap-2 bg-[#0a0a0a] p-2 rounded border border-[#2a2b2f]"
|
||
>
|
||
<input
|
||
type="text"
|
||
className="flex-1 bg-transparent text-[10px] text-white focus:outline-none"
|
||
value={port.name}
|
||
onChange={(e) => {
|
||
const newInputs = [...selectedNode.data.inputs];
|
||
newInputs[idx] = {
|
||
...port,
|
||
name: e.target.value,
|
||
};
|
||
updateNodeData({ inputs: newInputs });
|
||
}}
|
||
readOnly={isReadOnly}
|
||
/>
|
||
<select
|
||
className="bg-transparent text-[10px] text-gray-500 focus:outline-none"
|
||
value={port.type}
|
||
onChange={(e) => {
|
||
const newInputs = [...selectedNode.data.inputs];
|
||
newInputs[idx] = {
|
||
...port,
|
||
type: e.target.value,
|
||
};
|
||
updateNodeData({ inputs: newInputs });
|
||
}}
|
||
disabled={isReadOnly}
|
||
>
|
||
<option value="json">JSON</option>
|
||
<option value="video">Video</option>
|
||
<option value="image">Image</option>
|
||
<option value="tensor">Tensor</option>
|
||
<option value="file">File</option>
|
||
</select>
|
||
{!isReadOnly && (
|
||
<button
|
||
onClick={() => {
|
||
const newInputs = selectedNode.data.inputs.filter(
|
||
(_: any, i: number) => i !== idx,
|
||
);
|
||
updateNodeData({
|
||
inputs: newInputs,
|
||
});
|
||
}}
|
||
className="text-gray-600 hover:text-red-500"
|
||
>
|
||
<X className="w-3 h-3" />
|
||
</button>
|
||
)}
|
||
</div>
|
||
))}
|
||
</div>
|
||
</div>
|
||
|
||
<div className="space-y-3">
|
||
<div className="flex items-center justify-between">
|
||
<label className="text-[10px] text-gray-500 uppercase font-mono">
|
||
输出端口 (Outputs)
|
||
</label>
|
||
{!isReadOnly && (
|
||
<button
|
||
onClick={() => {
|
||
const newOutputs = [
|
||
...(selectedNode.data.outputs || []),
|
||
{
|
||
id: `out-${Date.now()}`,
|
||
name: "new_output",
|
||
type: "json",
|
||
},
|
||
];
|
||
updateNodeData({ outputs: newOutputs });
|
||
}}
|
||
className="text-[10px] text-blue-500 hover:underline"
|
||
>
|
||
+ 添加
|
||
</button>
|
||
)}
|
||
</div>
|
||
<div className="space-y-2">
|
||
{(selectedNode.data.outputs || []).map((port: any, idx: number) => (
|
||
<div
|
||
key={port.id}
|
||
className="flex items-center gap-2 bg-[#0a0a0a] p-2 rounded border border-[#2a2b2f]"
|
||
>
|
||
<input
|
||
type="text"
|
||
className="flex-1 bg-transparent text-[10px] text-white focus:outline-none"
|
||
value={port.name}
|
||
onChange={(e) => {
|
||
const newOutputs = [...selectedNode.data.outputs];
|
||
newOutputs[idx] = {
|
||
...port,
|
||
name: e.target.value,
|
||
};
|
||
updateNodeData({
|
||
outputs: newOutputs,
|
||
});
|
||
}}
|
||
readOnly={isReadOnly}
|
||
/>
|
||
<select
|
||
className="bg-transparent text-[10px] text-gray-500 focus:outline-none"
|
||
value={port.type}
|
||
onChange={(e) => {
|
||
const newOutputs = [...selectedNode.data.outputs];
|
||
newOutputs[idx] = {
|
||
...port,
|
||
type: e.target.value,
|
||
};
|
||
updateNodeData({
|
||
outputs: newOutputs,
|
||
});
|
||
}}
|
||
disabled={isReadOnly}
|
||
>
|
||
<option value="json">JSON</option>
|
||
<option value="video">Video</option>
|
||
<option value="image">Image</option>
|
||
<option value="tensor">Tensor</option>
|
||
<option value="file">File</option>
|
||
</select>
|
||
{!isReadOnly && (
|
||
<button
|
||
onClick={() => {
|
||
const newOutputs = selectedNode.data.outputs.filter(
|
||
(_: any, i: number) => i !== idx,
|
||
);
|
||
updateNodeData({
|
||
outputs: newOutputs,
|
||
});
|
||
}}
|
||
className="text-gray-600 hover:text-red-500"
|
||
>
|
||
<X className="w-3 h-3" />
|
||
</button>
|
||
)}
|
||
</div>
|
||
))}
|
||
</div>
|
||
</div>
|
||
|
||
<div className="space-y-1">
|
||
<label className="text-[10px] text-gray-500 uppercase font-mono">算子描述</label>
|
||
<textarea
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs focus:outline-none focus:border-blue-500 disabled:opacity-50 min-h-[60px] resize-none"
|
||
value={selectedNode.data.description || ""}
|
||
onChange={(e) =>
|
||
updateNodeData({
|
||
description: e.target.value,
|
||
})
|
||
}
|
||
readOnly={isReadOnly}
|
||
disabled={isReadOnly}
|
||
/>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
) : selectedEdge ? (
|
||
<div className="space-y-4 edge-output-panel">
|
||
<div
|
||
className={cn(
|
||
"flex items-center gap-2 px-3 py-2 rounded-md",
|
||
selectedEdgeExecutionState === "running" &&
|
||
"bg-blue-500/10 border border-blue-500/20 animate-pulse",
|
||
selectedEdgeExecutionState === "waiting_for_audit" &&
|
||
"bg-amber-500/10 border border-amber-500/20",
|
||
selectedEdgeExecutionState === "completed" &&
|
||
"bg-emerald-500/10 border border-emerald-500/20",
|
||
selectedEdgeExecutionState === "failed" && "bg-red-500/10 border border-red-500/20",
|
||
selectedEdgeExecutionState === "idle" && "bg-slate-500/10 border border-slate-500/20",
|
||
)}
|
||
>
|
||
{selectedEdgeExecutionState === "running" ? (
|
||
<Loader2 className="w-3.5 h-3.5 text-blue-500 animate-spin" />
|
||
) : selectedEdgeExecutionState === "waiting_for_audit" ? (
|
||
<Clock className="w-3.5 h-3.5 text-amber-400" />
|
||
) : selectedEdgeExecutionState === "completed" ? (
|
||
<CheckCircle2 className="w-3.5 h-3.5 text-emerald-400" />
|
||
) : selectedEdgeExecutionState === "failed" ? (
|
||
<X className="w-3.5 h-3.5 text-red-400" />
|
||
) : (
|
||
<Info className="w-3.5 h-3.5 text-slate-300" />
|
||
)}
|
||
<span
|
||
className={cn(
|
||
"text-[10px] font-bold uppercase tracking-wider",
|
||
selectedEdgeExecutionState === "running" && "text-blue-400",
|
||
selectedEdgeExecutionState === "waiting_for_audit" && "text-amber-300",
|
||
selectedEdgeExecutionState === "completed" && "text-emerald-300",
|
||
selectedEdgeExecutionState === "failed" && "text-red-300",
|
||
selectedEdgeExecutionState === "idle" && "text-slate-300",
|
||
)}
|
||
>
|
||
{executionStateLabels[selectedEdgeExecutionState] || selectedEdgeExecutionState}
|
||
</span>
|
||
</div>
|
||
|
||
<div className="flex items-center gap-2 text-blue-500">
|
||
<GitBranch className="w-3.5 h-3.5" />
|
||
<span className="text-[10px] font-bold uppercase">连线输出</span>
|
||
{!isReadOnly && canManage && (
|
||
<button
|
||
onClick={() => {
|
||
setEdges((currentEdges) =>
|
||
currentEdges.filter((edge) => edge.id !== selectedEdge.id),
|
||
);
|
||
setSelectedEdgeId("");
|
||
setCanvasNotice("已删除 1 条连线");
|
||
}}
|
||
className="ml-auto rounded-md p-1.5 text-red-300 hover:bg-red-500/10 hover:text-white transition-colors"
|
||
title="删除当前连线"
|
||
>
|
||
<X className="w-3.5 h-3.5" />
|
||
</button>
|
||
)}
|
||
</div>
|
||
|
||
<div className="rounded-lg border border-[#2a2b2f] bg-[#111317] p-3 space-y-3">
|
||
<div className="grid grid-cols-1 gap-3">
|
||
<div>
|
||
<div className="text-[10px] uppercase text-gray-500 font-mono">数据流向</div>
|
||
<div className="mt-1 text-xs text-white leading-5">
|
||
{selectedEdgeSourceLabel}
|
||
<span className="mx-1 text-gray-500">→</span>
|
||
{selectedEdgeTargetLabel}
|
||
</div>
|
||
</div>
|
||
<div>
|
||
<div className="text-[10px] uppercase text-gray-500 font-mono">输出端口</div>
|
||
<div className="mt-1 text-xs text-blue-200">{selectedEdgePortLabel}</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div className="grid grid-cols-2 gap-3 text-xs">
|
||
<div className="rounded-lg border border-[#2a2b2f] bg-[#16181c] p-3">
|
||
<div className="text-gray-500">当前 Run</div>
|
||
<div className="mt-1 text-gray-200 break-all">{activeRun?.id || "未加载"}</div>
|
||
</div>
|
||
<div className="rounded-lg border border-[#2a2b2f] bg-[#16181c] p-3">
|
||
<div className="text-gray-500">输出文件数</div>
|
||
<div className="mt-1 text-gray-200">{selectedEdgeArtifacts.length}</div>
|
||
</div>
|
||
</div>
|
||
|
||
{selectedEdgeArtifacts.length > 0 ? (
|
||
<div className="space-y-3">
|
||
<div className="space-y-2">
|
||
<div className="text-[10px] uppercase text-gray-500 font-mono">该连线输出文件</div>
|
||
<div className="space-y-2">
|
||
{selectedEdgeArtifacts.map((artifact) => (
|
||
<button
|
||
key={artifact.id}
|
||
type="button"
|
||
onClick={() => setSelectedEdgeArtifactId(artifact.id)}
|
||
className={cn(
|
||
"w-full rounded-lg border px-3 py-2 text-left transition-colors",
|
||
selectedEdgeArtifact?.id === artifact.id
|
||
? "border-blue-500/50 bg-blue-500/10"
|
||
: "border-[#2a2b2f] bg-[#0a0a0a] hover:border-blue-500/30",
|
||
)}
|
||
>
|
||
<div className="flex items-center justify-between gap-3">
|
||
<div className="min-w-0">
|
||
<div className="truncate text-xs font-medium text-white">
|
||
{artifact.name}
|
||
</div>
|
||
<div className="mt-1 text-[10px] text-gray-500">
|
||
{artifact.portName || selectedEdgePortLabel} ·{" "}
|
||
{artifact.type.toUpperCase()}
|
||
</div>
|
||
</div>
|
||
<div className="shrink-0 text-[10px] text-gray-500">{artifact.size}</div>
|
||
</div>
|
||
</button>
|
||
))}
|
||
</div>
|
||
</div>
|
||
|
||
<div className="space-y-2">
|
||
<div className="flex items-center justify-between gap-2">
|
||
<div className="text-[10px] uppercase text-gray-500 font-mono">输出预览</div>
|
||
<button
|
||
type="button"
|
||
onClick={() => setIsOutputPreviewFullscreen(true)}
|
||
disabled={!selectedEdgeArtifact}
|
||
className="inline-flex h-7 w-7 items-center justify-center rounded-md border border-[#2a2b2f] bg-white/5 text-gray-400 transition-colors hover:border-blue-500/40 hover:bg-blue-500/10 hover:text-white disabled:cursor-not-allowed disabled:opacity-40"
|
||
title="全屏预览输出"
|
||
aria-label="全屏预览输出"
|
||
>
|
||
<Maximize2 className="h-3.5 w-3.5" />
|
||
</button>
|
||
</div>
|
||
<ArtifactPreviewPanel item={selectedEdgeArtifact} />
|
||
</div>
|
||
</div>
|
||
) : (
|
||
<div className="rounded-lg border border-[#2a2b2f] bg-[#0a0a0a] p-4 text-xs text-gray-400 leading-6">
|
||
{selectedEdgeEmptyStateMessage}
|
||
</div>
|
||
)}
|
||
</div>
|
||
</div>
|
||
) : (
|
||
<div className="py-12 text-center">
|
||
<Info className="w-8 h-8 text-gray-700 mx-auto mb-2" />
|
||
<p className="text-xs text-gray-600">选择算子或连线查看配置与输出</p>
|
||
<p className="mt-2 text-[11px] text-gray-700">工作流级配置请使用顶部的“工作流配置”入口。</p>
|
||
</div>
|
||
)}
|
||
</div>
|
||
</div>
|
||
)}
|
||
</motion.div>
|
||
</Panel>
|
||
</ReactFlow>
|
||
{isCanvasDragActive && !isReadOnly && canManage && (
|
||
<div className="pointer-events-none absolute inset-4 rounded-2xl border border-dashed border-blue-500/60 bg-blue-500/[0.04] flex items-center justify-center text-sm font-medium text-blue-200">
|
||
拖到此处添加算子
|
||
</div>
|
||
)}
|
||
</div>
|
||
|
||
<AnimatePresence>
|
||
{isOutputPreviewFullscreen && selectedEdgeArtifact && (
|
||
<div className="fixed inset-0 z-[140] flex flex-col bg-black/85 backdrop-blur-sm">
|
||
<motion.div
|
||
initial={{ opacity: 0 }}
|
||
animate={{ opacity: 1 }}
|
||
exit={{ opacity: 0 }}
|
||
onClick={() => setIsOutputPreviewFullscreen(false)}
|
||
className="absolute inset-0"
|
||
/>
|
||
<motion.div
|
||
initial={{ opacity: 0, scale: 0.98 }}
|
||
animate={{ opacity: 1, scale: 1 }}
|
||
exit={{ opacity: 0, scale: 0.98 }}
|
||
className="relative z-10 flex min-h-0 flex-1 flex-col p-4 sm:p-6"
|
||
>
|
||
<div className="mb-3 flex shrink-0 items-center justify-between gap-3 rounded-xl border border-[#2a2b2f] bg-[#151619] px-4 py-3 shadow-2xl">
|
||
<div className="min-w-0">
|
||
<div className="truncate text-sm font-semibold text-white">{selectedEdgeArtifact.name}</div>
|
||
<div className="mt-1 truncate text-xs text-gray-500">
|
||
{selectedEdgeArtifact.portName || selectedEdgePortLabel} ·{" "}
|
||
{selectedEdgeArtifact.type.toUpperCase()}
|
||
</div>
|
||
</div>
|
||
<button
|
||
type="button"
|
||
onClick={() => setIsOutputPreviewFullscreen(false)}
|
||
className="inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-lg border border-[#2a2b2f] bg-white/5 text-gray-400 transition-colors hover:bg-white/10 hover:text-white"
|
||
title="关闭全屏预览"
|
||
aria-label="关闭全屏预览"
|
||
>
|
||
<X className="h-4 w-4" />
|
||
</button>
|
||
</div>
|
||
<div className="min-h-0 flex-1 overflow-auto rounded-2xl border border-[#2a2b2f] bg-[#0a0a0a] p-3 shadow-2xl">
|
||
<ArtifactPreviewPanel item={selectedEdgeArtifact} fullscreen />
|
||
</div>
|
||
</motion.div>
|
||
</div>
|
||
)}
|
||
</AnimatePresence>
|
||
|
||
<AnimatePresence>
|
||
{isLightweightCodeEditorFullscreen && selectedLightweightRuntime.enabled && (
|
||
<div className="fixed inset-0 z-[145] flex flex-col bg-black/85 backdrop-blur-sm">
|
||
<motion.div
|
||
initial={{ opacity: 0 }}
|
||
animate={{ opacity: 1 }}
|
||
exit={{ opacity: 0 }}
|
||
onClick={() => setIsLightweightCodeEditorFullscreen(false)}
|
||
className="absolute inset-0"
|
||
/>
|
||
<motion.div
|
||
initial={{ opacity: 0, scale: 0.98 }}
|
||
animate={{ opacity: 1, scale: 1 }}
|
||
exit={{ opacity: 0, scale: 0.98 }}
|
||
className="relative z-10 flex min-h-0 flex-1 flex-col p-4 sm:p-6"
|
||
>
|
||
<div className="mb-3 flex shrink-0 items-center justify-between gap-3 rounded-xl border border-[#2a2b2f] bg-[#151619] px-4 py-3 shadow-2xl">
|
||
<div className="min-w-0">
|
||
<div className="truncate text-sm font-semibold text-white">
|
||
{selectedNode?.data?.label || "轻量算子代码目录"}
|
||
</div>
|
||
<div className="mt-1 truncate font-mono text-xs text-gray-500">
|
||
{selectedLightweightRuntime.codeSubPath || selectedLightweightRuntime.mountPath}
|
||
</div>
|
||
</div>
|
||
<button
|
||
type="button"
|
||
onClick={() => setIsLightweightCodeEditorFullscreen(false)}
|
||
className="inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-lg border border-[#2a2b2f] bg-white/5 text-gray-400 transition-colors hover:bg-white/10 hover:text-white"
|
||
title="关闭代码目录"
|
||
aria-label="关闭代码目录"
|
||
>
|
||
<X className="h-4 w-4" />
|
||
</button>
|
||
</div>
|
||
<div className="min-h-0 flex-1 overflow-auto rounded-2xl border border-[#2a2b2f] bg-[#101113] p-4 shadow-2xl">
|
||
<LightweightOperatorCodeEditor
|
||
operatorId={selectedLightweightOperatorId}
|
||
showSummary
|
||
unavailableMessage="当前节点没有 operatorId,无法加载轻量算子代码目录。"
|
||
/>
|
||
</div>
|
||
</motion.div>
|
||
</div>
|
||
)}
|
||
</AnimatePresence>
|
||
|
||
{/* OSS Browser Modal */}
|
||
<AnimatePresence>
|
||
{isExportTemplateOpen && (
|
||
<div className="fixed inset-0 z-[110] flex items-center justify-center p-6">
|
||
<motion.div
|
||
initial={{ opacity: 0 }}
|
||
animate={{ opacity: 1 }}
|
||
exit={{ opacity: 0 }}
|
||
onClick={() => setIsExportTemplateOpen(false)}
|
||
className="absolute inset-0 bg-black/80 backdrop-blur-sm"
|
||
/>
|
||
<motion.div
|
||
initial={{ opacity: 0, scale: 0.95, y: 20 }}
|
||
animate={{ opacity: 1, scale: 1, y: 0 }}
|
||
exit={{ opacity: 0, scale: 0.95, y: 20 }}
|
||
className="relative w-full max-w-md bg-[#151619] border border-[#2a2b2f] rounded-2xl shadow-2xl overflow-hidden"
|
||
>
|
||
<div className="px-6 py-4 border-b border-[#2a2b2f] flex items-center justify-between bg-[#1a1b1e]">
|
||
<h3 className="text-sm font-bold text-white uppercase tracking-wider">导出为模板</h3>
|
||
<button
|
||
onClick={() => setIsExportTemplateOpen(false)}
|
||
className="p-2 hover:bg-white/5 rounded-full text-gray-500 hover:text-white transition-colors"
|
||
>
|
||
<X className="w-5 h-5" />
|
||
</button>
|
||
</div>
|
||
<div className="p-6 space-y-4">
|
||
<div className="space-y-1.5">
|
||
<label className="text-xs font-medium text-gray-400 uppercase tracking-wider">模板名称</label>
|
||
<input
|
||
type="text"
|
||
value={templateDraft.name}
|
||
onChange={(event) =>
|
||
setTemplateDraft((previous) => ({
|
||
...previous,
|
||
name: event.target.value,
|
||
}))
|
||
}
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded-md px-4 py-2 text-sm focus:outline-none focus:border-blue-500 text-white"
|
||
/>
|
||
</div>
|
||
<div className="space-y-1.5">
|
||
<label className="text-xs font-medium text-gray-400 uppercase tracking-wider">模板描述</label>
|
||
<textarea
|
||
rows={4}
|
||
value={templateDraft.description}
|
||
onChange={(event) =>
|
||
setTemplateDraft((previous) => ({
|
||
...previous,
|
||
description: event.target.value,
|
||
}))
|
||
}
|
||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded-md px-4 py-2 text-sm focus:outline-none focus:border-blue-500 text-white resize-none"
|
||
/>
|
||
</div>
|
||
</div>
|
||
<div className="px-6 py-4 border-t border-[#2a2b2f] bg-[#1a1b1e] flex justify-end gap-3">
|
||
<button
|
||
onClick={() => setIsExportTemplateOpen(false)}
|
||
className="px-4 py-2 text-sm font-medium text-gray-400 hover:text-white transition-colors"
|
||
>
|
||
取消
|
||
</button>
|
||
<button
|
||
onClick={handleExportTemplate}
|
||
disabled={!templateDraft.name.trim()}
|
||
className={cn(
|
||
"px-4 py-2 bg-blue-600 hover:bg-blue-500 text-white rounded-lg text-xs font-bold transition-colors",
|
||
!templateDraft.name.trim() && "opacity-50 cursor-not-allowed",
|
||
)}
|
||
>
|
||
创建模板
|
||
</button>
|
||
</div>
|
||
</motion.div>
|
||
</div>
|
||
)}
|
||
{isOssBrowsing && (
|
||
<div className="fixed inset-0 z-[100] flex items-center justify-center p-6">
|
||
<motion.div
|
||
initial={{ opacity: 0 }}
|
||
animate={{ opacity: 1 }}
|
||
exit={{ opacity: 0 }}
|
||
onClick={() => setIsOssBrowsing(false)}
|
||
className="absolute inset-0 bg-black/80 backdrop-blur-sm"
|
||
/>
|
||
<motion.div
|
||
initial={{ opacity: 0, scale: 0.95, y: 20 }}
|
||
animate={{ opacity: 1, scale: 1, y: 0 }}
|
||
exit={{ opacity: 0, scale: 0.95, y: 20 }}
|
||
className="relative w-full max-w-2xl bg-[#151619] border border-[#2a2b2f] rounded-2xl shadow-2xl overflow-hidden flex flex-col max-h-[70vh]"
|
||
>
|
||
<div className="px-6 py-4 border-b border-[#2a2b2f] flex items-center justify-between bg-[#1a1b1e]">
|
||
<div className="flex items-center gap-3">
|
||
<div className="w-8 h-8 bg-blue-500/10 rounded-lg flex items-center justify-center text-blue-500">
|
||
<Database className="w-4 h-4" />
|
||
</div>
|
||
<div>
|
||
<h3 className="text-sm font-bold text-white uppercase tracking-wider">OSS 资源浏览器</h3>
|
||
<p className="text-[10px] text-gray-500 font-mono">
|
||
{selectedBrowseRootLabel || "未配置连接或 SOURCE_PATH"} / {selectedNodeBucket || "未选择存储桶"}{" "}
|
||
/ {selectedNodePrefix || ""}
|
||
</p>
|
||
</div>
|
||
</div>
|
||
<button
|
||
onClick={() => setIsOssBrowsing(false)}
|
||
className="p-2 hover:bg-white/5 rounded-full text-gray-500 hover:text-white transition-colors"
|
||
>
|
||
<X className="w-5 h-5" />
|
||
</button>
|
||
</div>
|
||
|
||
<div className="flex-1 overflow-y-auto p-4">
|
||
{projectFavoriteStoragePaths.length > 0 && (
|
||
<div className="mb-4 rounded-xl border border-cyan-500/15 bg-cyan-500/[0.04] p-3">
|
||
<div className="mb-2 flex items-center gap-2 text-[10px] font-mono uppercase tracking-wide text-cyan-200">
|
||
<Users className="h-3 w-3" />
|
||
项目常用路径
|
||
</div>
|
||
<div className="flex flex-wrap gap-2">
|
||
{projectFavoriteStoragePaths.map((item) => {
|
||
const itemKey = `${item.bucket}/${normalizeStoragePrefix(item.prefix)}`;
|
||
const isCurrent = itemKey === selectedStoragePathKey;
|
||
return (
|
||
<button
|
||
key={itemKey}
|
||
type="button"
|
||
onClick={() => applyFavoriteStoragePath(item.bucket, item.prefix)}
|
||
className={cn(
|
||
"rounded-full border px-2.5 py-1 text-[10px] transition-colors",
|
||
isCurrent
|
||
? "border-cyan-400/40 bg-cyan-500/15 text-cyan-100"
|
||
: "border-[#2a2b2f] bg-[#0a0a0a] text-gray-300 hover:border-cyan-500/40 hover:text-cyan-200",
|
||
)}
|
||
title={item.label}
|
||
>
|
||
{item.label}
|
||
</button>
|
||
);
|
||
})}
|
||
</div>
|
||
<p className="mt-2 text-[10px] text-gray-500">
|
||
项目成员共享的 bucket/prefix,会跟随项目一起保留。
|
||
</p>
|
||
</div>
|
||
)}
|
||
{visibleUserFavoriteStoragePaths.length > 0 && (
|
||
<div className="mb-4 rounded-xl border border-amber-500/15 bg-amber-500/[0.04] p-3">
|
||
<div className="mb-2 flex items-center gap-2 text-[10px] font-mono uppercase tracking-wide text-amber-200">
|
||
<Star className="h-3 w-3" fill="currentColor" />
|
||
我的常用路径
|
||
</div>
|
||
<div className="flex flex-wrap gap-2">
|
||
{visibleUserFavoriteStoragePaths.map((item) => {
|
||
const itemKey = `${item.bucket}/${normalizeStoragePrefix(item.prefix)}`;
|
||
const isCurrent = itemKey === selectedStoragePathKey;
|
||
return (
|
||
<button
|
||
key={itemKey}
|
||
type="button"
|
||
onClick={() => applyFavoriteStoragePath(item.bucket, item.prefix)}
|
||
className={cn(
|
||
"rounded-full border px-2.5 py-1 text-[10px] transition-colors",
|
||
isCurrent
|
||
? "border-amber-400/40 bg-amber-500/15 text-amber-100"
|
||
: "border-[#2a2b2f] bg-[#0a0a0a] text-gray-300 hover:border-amber-500/40 hover:text-amber-200",
|
||
)}
|
||
title={item.label}
|
||
>
|
||
{item.label}
|
||
</button>
|
||
);
|
||
})}
|
||
</div>
|
||
<p className="mt-2 text-[10px] text-gray-500">仅当前用户可见的常用 bucket/prefix。</p>
|
||
</div>
|
||
)}
|
||
{visibleRecentStoragePaths.length > 0 && (
|
||
<div className="mb-4 rounded-xl border border-blue-500/15 bg-blue-500/[0.04] p-3">
|
||
<div className="mb-2 flex items-center gap-2 text-[10px] font-mono uppercase tracking-wide text-blue-200">
|
||
<RotateCcw className="h-3 w-3" />
|
||
最近使用路径
|
||
</div>
|
||
<div className="flex flex-wrap gap-2">
|
||
{visibleRecentStoragePaths.map((item) => {
|
||
const itemKey = `${item.bucket}/${normalizeStoragePrefix(item.prefix)}`;
|
||
const isCurrent = itemKey === selectedStoragePathKey;
|
||
return (
|
||
<button
|
||
key={itemKey}
|
||
type="button"
|
||
onClick={() => applyRecentStoragePath(item.bucket, item.prefix)}
|
||
className={cn(
|
||
"rounded-full border px-2.5 py-1 text-[10px] transition-colors",
|
||
isCurrent
|
||
? "border-blue-400/40 bg-blue-500/15 text-blue-100"
|
||
: "border-[#2a2b2f] bg-[#0a0a0a] text-gray-300 hover:border-blue-500/40 hover:text-blue-200",
|
||
)}
|
||
title={item.label}
|
||
>
|
||
{item.label}
|
||
</button>
|
||
);
|
||
})}
|
||
</div>
|
||
<p className="mt-2 text-[10px] text-gray-500">
|
||
点击可直接切换当前 bucket/prefix,并在此窗口继续浏览该路径。
|
||
</p>
|
||
</div>
|
||
)}
|
||
{!canBrowseSelectedStorage ? (
|
||
<div className="h-64 flex flex-col items-center justify-center text-center">
|
||
<Info className="w-8 h-8 text-gray-700 mb-2" />
|
||
<p className="text-sm text-gray-500">请先绑定 BOS 连接,或在当前节点超参里配置 SOURCE_PATH</p>
|
||
</div>
|
||
) : !selectedNodeBucket ? (
|
||
<div className="h-64 flex flex-col items-center justify-center text-center">
|
||
<Info className="w-8 h-8 text-gray-700 mb-2" />
|
||
<p className="text-sm text-gray-500">
|
||
请先在参数面板选择存储桶,或点击上方常用路径 / 最近使用路径直接切换
|
||
</p>
|
||
</div>
|
||
) : isOssLoading ? (
|
||
<div className="h-64 flex flex-col items-center justify-center">
|
||
<Loader2 className="w-8 h-8 text-blue-500 animate-spin mb-2" />
|
||
<p className="text-xs text-gray-600">正在扫描 OSS 目录...</p>
|
||
</div>
|
||
) : ossBrowseError ? (
|
||
<div className="h-64 flex flex-col items-center justify-center text-center">
|
||
<Info className="w-8 h-8 text-amber-400 mb-2" />
|
||
<p className="text-sm text-amber-300 break-all">{ossBrowseError}</p>
|
||
</div>
|
||
) : ossObjects.length === 0 ? (
|
||
<div className="h-64 flex flex-col items-center justify-center text-center">
|
||
<Info className="w-8 h-8 text-gray-700 mb-2" />
|
||
<p className="text-sm text-gray-500">当前路径下没有可选对象</p>
|
||
</div>
|
||
) : (
|
||
<div className="space-y-1">
|
||
{ossObjects.map((obj, i) => (
|
||
<button
|
||
key={i}
|
||
onClick={() => {
|
||
if (obj.endsWith("/")) {
|
||
applyStorageBrowserSelection(obj, false);
|
||
} else {
|
||
applyStorageBrowserSelection(obj, true);
|
||
}
|
||
}}
|
||
className="w-full flex items-center justify-between p-3 rounded-lg hover:bg-white/5 border border-transparent hover:border-[#2a2b2f] transition-all group"
|
||
>
|
||
<div className="flex items-center gap-3">
|
||
{obj.endsWith("/") ? (
|
||
<FolderOpen className="w-4 h-4 text-blue-400" />
|
||
) : (
|
||
<Box className="w-4 h-4 text-gray-500" />
|
||
)}
|
||
<span className="text-xs text-gray-300 font-mono">{obj}</span>
|
||
</div>
|
||
<ChevronRight className="w-3 h-3 text-gray-700 group-hover:text-blue-500 transition-colors" />
|
||
</button>
|
||
))}
|
||
</div>
|
||
)}
|
||
</div>
|
||
|
||
<div className="px-6 py-4 border-t border-[#2a2b2f] bg-[#1a1b1e] flex justify-end">
|
||
<button
|
||
onClick={() => setIsOssBrowsing(false)}
|
||
className="px-4 py-2 bg-blue-600 hover:bg-blue-500 text-white rounded-lg text-xs font-bold transition-colors"
|
||
>
|
||
确定选择
|
||
</button>
|
||
</div>
|
||
</motion.div>
|
||
</div>
|
||
)}
|
||
</AnimatePresence>
|
||
</div>
|
||
</div>
|
||
);
|
||
}
|