fix: chain workflow with agent presets
This commit is contained in:
parent
0b6a794097
commit
fbbc63f865
@ -61,6 +61,7 @@ import {
|
|||||||
AgentWorkflowPanel,
|
AgentWorkflowPanel,
|
||||||
type AgentWorkflowInputs,
|
type AgentWorkflowInputs,
|
||||||
} from "@/components/agents/AgentWorkflowPanel";
|
} from "@/components/agents/AgentWorkflowPanel";
|
||||||
|
import { AgentPresetPanel } from "@/components/agents/AgentPresetPanel";
|
||||||
import { CanvasWorkspace } from "@/components/canvas";
|
import { CanvasWorkspace } from "@/components/canvas";
|
||||||
import { CanvasChatPanel } from "@/components/canvas/CanvasChatPanel";
|
import { CanvasChatPanel } from "@/components/canvas/CanvasChatPanel";
|
||||||
import { CanvasFileListPanel } from "@/components/canvas/CanvasFileListPanel";
|
import { CanvasFileListPanel } from "@/components/canvas/CanvasFileListPanel";
|
||||||
@ -159,6 +160,7 @@ export default function CanvasEditorPage({ params }: PageProps) {
|
|||||||
const [workflowSelections, setWorkflowSelections] = useState<
|
const [workflowSelections, setWorkflowSelections] = useState<
|
||||||
Partial<Record<AgentWorkflowStepKey, string>>
|
Partial<Record<AgentWorkflowStepKey, string>>
|
||||||
>({});
|
>({});
|
||||||
|
const [selectedAgentPresetId, setSelectedAgentPresetId] = useState<string | null>(null);
|
||||||
const [workflowHydrationSource, setWorkflowHydrationSource] = useState<
|
const [workflowHydrationSource, setWorkflowHydrationSource] = useState<
|
||||||
"pending" | "project" | "local" | "empty"
|
"pending" | "project" | "local" | "empty"
|
||||||
>("pending");
|
>("pending");
|
||||||
@ -261,6 +263,7 @@ export default function CanvasEditorPage({ params }: PageProps) {
|
|||||||
store: "",
|
store: "",
|
||||||
});
|
});
|
||||||
setWorkflowSelections({});
|
setWorkflowSelections({});
|
||||||
|
setSelectedAgentPresetId(null);
|
||||||
|
|
||||||
// 🆕 先清空当前画布状态,确保切换时不会显示旧数据
|
// 🆕 先清空当前画布状态,确保切换时不会显示旧数据
|
||||||
useCanvasStore.getState().clearCanvas();
|
useCanvasStore.getState().clearCanvas();
|
||||||
@ -280,6 +283,9 @@ export default function CanvasEditorPage({ params }: PageProps) {
|
|||||||
store: String(persistedWorkflow.inputs?.store || "").trim(),
|
store: String(persistedWorkflow.inputs?.store || "").trim(),
|
||||||
});
|
});
|
||||||
setWorkflowSelections(persistedWorkflow.selections || {});
|
setWorkflowSelections(persistedWorkflow.selections || {});
|
||||||
|
setSelectedAgentPresetId(
|
||||||
|
String(persistedWorkflow.selectedAgentPresetId || "").trim() || null
|
||||||
|
);
|
||||||
setWorkflowHydrationSource("project");
|
setWorkflowHydrationSource("project");
|
||||||
} else {
|
} else {
|
||||||
setWorkflowHydrationSource("empty");
|
setWorkflowHydrationSource("empty");
|
||||||
@ -329,13 +335,14 @@ export default function CanvasEditorPage({ params }: PageProps) {
|
|||||||
store: workflowInputs.store.trim(),
|
store: workflowInputs.store.trim(),
|
||||||
},
|
},
|
||||||
selections: workflowSelections,
|
selections: workflowSelections,
|
||||||
|
selectedAgentPresetId: selectedAgentPresetId || null,
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...getCanvasState(),
|
...getCanvasState(),
|
||||||
workflowState,
|
workflowState,
|
||||||
};
|
};
|
||||||
}, [getCanvasState, workflowInputs, workflowSelections]);
|
}, [getCanvasState, workflowInputs, workflowSelections, selectedAgentPresetId]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (typeof window === "undefined") return;
|
if (typeof window === "undefined") return;
|
||||||
@ -356,6 +363,7 @@ export default function CanvasEditorPage({ params }: PageProps) {
|
|||||||
store: String(parsed.inputs?.store || "").trim(),
|
store: String(parsed.inputs?.store || "").trim(),
|
||||||
});
|
});
|
||||||
setWorkflowSelections(parsed.selections || {});
|
setWorkflowSelections(parsed.selections || {});
|
||||||
|
setSelectedAgentPresetId(String(parsed.selectedAgentPresetId || "").trim() || null);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.warn("[Canvas] Failed to hydrate workflow state from localStorage:", error);
|
console.warn("[Canvas] Failed to hydrate workflow state from localStorage:", error);
|
||||||
} finally {
|
} finally {
|
||||||
@ -372,12 +380,19 @@ export default function CanvasEditorPage({ params }: PageProps) {
|
|||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
inputs: workflowInputs,
|
inputs: workflowInputs,
|
||||||
selections: workflowSelections,
|
selections: workflowSelections,
|
||||||
|
selectedAgentPresetId,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.warn("[Canvas] Failed to persist workflow state:", error);
|
console.warn("[Canvas] Failed to persist workflow state:", error);
|
||||||
}
|
}
|
||||||
}, [workflowHydrationSource, workflowInputs, workflowSelections, workflowStorageKey]);
|
}, [
|
||||||
|
workflowHydrationSource,
|
||||||
|
workflowInputs,
|
||||||
|
workflowSelections,
|
||||||
|
workflowStorageKey,
|
||||||
|
selectedAgentPresetId,
|
||||||
|
]);
|
||||||
|
|
||||||
const persistCanvasState = useCallback(
|
const persistCanvasState = useCallback(
|
||||||
async (reason: "autosave" | "delete" | "beforeunload") => {
|
async (reason: "autosave" | "delete" | "beforeunload") => {
|
||||||
@ -868,22 +883,35 @@ export default function CanvasEditorPage({ params }: PageProps) {
|
|||||||
|
|
||||||
<div className="absolute inset-0 flex pt-[72px]">
|
<div className="absolute inset-0 flex pt-[72px]">
|
||||||
<div className="min-w-0 flex-1 border-r bg-white dark:bg-zinc-950">
|
<div className="min-w-0 flex-1 border-r bg-white dark:bg-zinc-950">
|
||||||
<AgentWorkflowPanel
|
<div className="grid h-full grid-rows-[minmax(0,1fr)_minmax(0,1fr)]">
|
||||||
config={resolvedWorkflowUiConfig}
|
<div className="min-h-0 border-b">
|
||||||
inputs={workflowInputs}
|
<AgentWorkflowPanel
|
||||||
onInputsChange={setWorkflowInputs}
|
embedded
|
||||||
selections={workflowSelections}
|
config={resolvedWorkflowUiConfig}
|
||||||
onSelectionsChange={setWorkflowSelections}
|
inputs={workflowInputs}
|
||||||
onReset={() => {
|
onInputsChange={setWorkflowInputs}
|
||||||
setWorkflowInputs({
|
selections={workflowSelections}
|
||||||
primarySku: "",
|
onSelectionsChange={setWorkflowSelections}
|
||||||
secondarySku: "",
|
onReset={() => {
|
||||||
brand: "",
|
setWorkflowInputs({
|
||||||
store: "",
|
primarySku: "",
|
||||||
});
|
secondarySku: "",
|
||||||
setWorkflowSelections({});
|
brand: "",
|
||||||
}}
|
store: "",
|
||||||
/>
|
});
|
||||||
|
setWorkflowSelections({});
|
||||||
|
setSelectedAgentPresetId(null);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="min-h-0">
|
||||||
|
<AgentPresetPanel
|
||||||
|
embedded
|
||||||
|
selectedPresetId={selectedAgentPresetId}
|
||||||
|
onSelectPreset={setSelectedAgentPresetId}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
@ -894,7 +922,7 @@ export default function CanvasEditorPage({ params }: PageProps) {
|
|||||||
<CanvasChatPanel
|
<CanvasChatPanel
|
||||||
chatId={`canvas-${id}`}
|
chatId={`canvas-${id}`}
|
||||||
onClose={() => {}}
|
onClose={() => {}}
|
||||||
selectedAgentPresetId={null}
|
selectedAgentPresetId={isAgentFeatureEnabled ? selectedAgentPresetId : null}
|
||||||
chatScope="agent"
|
chatScope="agent"
|
||||||
workflowContext={workflowContext}
|
workflowContext={workflowContext}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import useSWR from "swr";
|
|||||||
import { Loader2, Plus, Sparkles } from "lucide-react";
|
import { Loader2, Plus, Sparkles } from "lucide-react";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { fetcher } from "@/lib/utils";
|
import { fetcher } from "@/lib/utils";
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { ScrollArea } from "@/components/ui/scroll-area";
|
import { ScrollArea } from "@/components/ui/scroll-area";
|
||||||
@ -23,11 +24,13 @@ import { AgentPresetDialog } from "@/components/agents/AgentPresetDialog";
|
|||||||
interface AgentPresetPanelProps {
|
interface AgentPresetPanelProps {
|
||||||
selectedPresetId?: string | null;
|
selectedPresetId?: string | null;
|
||||||
onSelectPreset: (presetId: string | null) => void;
|
onSelectPreset: (presetId: string | null) => void;
|
||||||
|
embedded?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function AgentPresetPanel({
|
export function AgentPresetPanel({
|
||||||
selectedPresetId,
|
selectedPresetId,
|
||||||
onSelectPreset,
|
onSelectPreset,
|
||||||
|
embedded = false,
|
||||||
}: AgentPresetPanelProps) {
|
}: AgentPresetPanelProps) {
|
||||||
const [keyword, setKeyword] = useState("");
|
const [keyword, setKeyword] = useState("");
|
||||||
const [categoryFilters, setCategoryFilters] = useState({
|
const [categoryFilters, setCategoryFilters] = useState({
|
||||||
@ -149,7 +152,12 @@ export function AgentPresetPanel({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="flex h-full flex-col border-r bg-white dark:bg-zinc-950">
|
<div
|
||||||
|
className={cn(
|
||||||
|
"flex h-full flex-col bg-white dark:bg-zinc-950",
|
||||||
|
embedded ? "" : "border-r"
|
||||||
|
)}
|
||||||
|
>
|
||||||
<div className="border-b p-4">
|
<div className="border-b p-4">
|
||||||
<div className="mb-3 flex items-center justify-between">
|
<div className="mb-3 flex items-center justify-between">
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
@ -33,6 +33,7 @@ interface AgentWorkflowPanelProps {
|
|||||||
selections: Partial<Record<AgentWorkflowStepKey, string>>;
|
selections: Partial<Record<AgentWorkflowStepKey, string>>;
|
||||||
onSelectionsChange: (next: Partial<Record<AgentWorkflowStepKey, string>>) => void;
|
onSelectionsChange: (next: Partial<Record<AgentWorkflowStepKey, string>>) => void;
|
||||||
onReset?: () => void;
|
onReset?: () => void;
|
||||||
|
embedded?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildSelectionSummary(params: {
|
function buildSelectionSummary(params: {
|
||||||
@ -67,6 +68,7 @@ export function AgentWorkflowPanel({
|
|||||||
selections,
|
selections,
|
||||||
onSelectionsChange,
|
onSelectionsChange,
|
||||||
onReset,
|
onReset,
|
||||||
|
embedded = false,
|
||||||
}: AgentWorkflowPanelProps) {
|
}: AgentWorkflowPanelProps) {
|
||||||
const resolvedConfig = useMemo(() => {
|
const resolvedConfig = useMemo(() => {
|
||||||
const source = config?.steps?.length ? config : defaultAgentWorkflowUiConfig;
|
const source = config?.steps?.length ? config : defaultAgentWorkflowUiConfig;
|
||||||
@ -116,7 +118,12 @@ export function AgentWorkflowPanel({
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex h-full flex-col border-r bg-white dark:bg-zinc-950">
|
<div
|
||||||
|
className={cn(
|
||||||
|
"flex h-full flex-col bg-white dark:bg-zinc-950",
|
||||||
|
embedded ? "" : "border-r"
|
||||||
|
)}
|
||||||
|
>
|
||||||
<div className="border-b p-4">
|
<div className="border-b p-4">
|
||||||
<div className="flex items-start justify-between gap-3">
|
<div className="flex items-start justify-between gap-3">
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
@ -609,6 +609,7 @@ export const canvasProject = pgTable("CanvasProject", {
|
|||||||
store?: string;
|
store?: string;
|
||||||
};
|
};
|
||||||
selections?: Record<string, string>;
|
selections?: Record<string, string>;
|
||||||
|
selectedAgentPresetId?: string | null;
|
||||||
};
|
};
|
||||||
}>(),
|
}>(),
|
||||||
createdAt: timestamp("createdAt").notNull().defaultNow(),
|
createdAt: timestamp("createdAt").notNull().defaultNow(),
|
||||||
|
|||||||
@ -69,6 +69,7 @@ export interface AgentWorkflowPersistedState {
|
|||||||
store: string;
|
store: string;
|
||||||
};
|
};
|
||||||
selections: Partial<Record<AgentWorkflowStepKey, string>>;
|
selections: Partial<Record<AgentWorkflowStepKey, string>>;
|
||||||
|
selectedAgentPresetId?: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AgentCategoryTreeConfig {
|
export interface AgentCategoryTreeConfig {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user