feat(canvas): 云端 Agent 交互 - 展示错误动作并支持连接器与提示词预填
This commit is contained in:
@@ -29,6 +29,7 @@ import {
|
||||
type AgentRun,
|
||||
} from "@/services/api/agent";
|
||||
import { agentApprovalMatchesSettings, agentApprovalTargetGenerating } from "@/lib/canvas/agent-media-approval";
|
||||
import { appendAgentPromptPrefill } from "@/lib/canvas/agent-prompt-prefill";
|
||||
import type { CanvasNodeData } from "@/types/canvas";
|
||||
import type { AgentMediaSettings } from "@/services/api/agent";
|
||||
import { addSkill, listAddedSkills, listSkillLibraryCategories, listSkills, listSkillPresets, type Skill, type SkillCategory, type SkillLibraryCategory, type SkillPreset } from "@/services/api/skills";
|
||||
@@ -56,6 +57,7 @@ import { useAgentPanelLayout } from "./use-agent-panel-layout";
|
||||
import "./canvas-cloud-agent.css";
|
||||
import { appendAgentError, appendUniqueMessage, applyAgentEvent, positiveNumber, type ApprovalState } from "./canvas-cloud-agent-events";
|
||||
import { AgentContextRing, AgentConversation, AgentHeader, AgentHistory, AgentLauncher, ComposerControls } from "./canvas-cloud-agent-panel-parts";
|
||||
import { AgentConnectorsBar } from "./canvas-cloud-agent-connectors";
|
||||
|
||||
type CloudAgentPanelProps = {
|
||||
canvasId: string;
|
||||
@@ -64,7 +66,8 @@ type CloudAgentPanelProps = {
|
||||
selectedNodeIds: string[];
|
||||
references: CanvasResourceReference[];
|
||||
open: boolean;
|
||||
prefillPrompt?: string;
|
||||
/** 外部预填请求(如右键“发送到 Agent”);id 变化即追加一次 text。 */
|
||||
prefillRequest?: { id: number; text: string } | null;
|
||||
onOpen: () => void;
|
||||
onCollapse: () => void;
|
||||
onFocusNode?: (nodeId: string) => void;
|
||||
@@ -74,7 +77,7 @@ type CloudAgentPanelProps = {
|
||||
};
|
||||
type AgentPanelView = "chat" | "history" | "settings";
|
||||
|
||||
export function CanvasCloudAgentPanel({ canvasId, domainProjectId, nodeCount, selectedNodeIds, references, open, prefillPrompt, onOpen, onCollapse, onFocusNode, canvasNodes, runningNodeId }: CloudAgentPanelProps) {
|
||||
export function CanvasCloudAgentPanel({ canvasId, domainProjectId, nodeCount, selectedNodeIds, references, open, prefillRequest, onOpen, onCollapse, onFocusNode, canvasNodes, runningNodeId }: CloudAgentPanelProps) {
|
||||
const userId = useUserStore((state) => state.user?.id);
|
||||
const theme = canvasThemes[useActiveTheme()];
|
||||
const config = useEffectiveConfig();
|
||||
@@ -87,7 +90,7 @@ export function CanvasCloudAgentPanel({ canvasId, domainProjectId, nodeCount, se
|
||||
const [connectionEpoch, setConnectionEpoch] = useState(0);
|
||||
const [messages, setMessages] = useState<CloudAgentChatMessage[]>([]);
|
||||
const [prompt, setPrompt] = useState("");
|
||||
const lastPrefillPromptRef = useRef("");
|
||||
const lastPrefillIdRef = useRef(0);
|
||||
const [reasoningMode, setReasoningMode] = useState<AgentReasoningMode>("off");
|
||||
const [profileView, setProfileView] = useState<AgentProfileView | null>(null);
|
||||
const [profileLoading, setProfileLoading] = useState(false);
|
||||
@@ -128,6 +131,8 @@ export function CanvasCloudAgentPanel({ canvasId, domainProjectId, nodeCount, se
|
||||
const [scenePresets, setScenePresets] = useState<SkillPreset[]>([]);
|
||||
const [presetApplyingId, setPresetApplyingId] = useState("");
|
||||
const presetApplyingRef = useRef<string | null>(null);
|
||||
// 连接器条默认展示,关闭后本次会话内不再显示。
|
||||
const [connectorsVisible, setConnectorsVisible] = useState(true);
|
||||
const panelLayout = useAgentPanelLayout();
|
||||
const lastSeqRef = useRef(0);
|
||||
const canvasSyncRef = useRef<ReturnType<typeof createAgentCanvasSync> | null>(null);
|
||||
@@ -304,12 +309,12 @@ export function CanvasCloudAgentPanel({ canvasId, domainProjectId, nodeCount, se
|
||||
const statusColor = status === "failed" ? "#e66b6b" : status === "rejected" || status === "cancelled" ? theme.node.muted : status === "waiting_approval" ? "#d6a24a" : status === "running" || status === "queued" ? "#69c29b" : theme.node.muted;
|
||||
|
||||
useEffect(() => {
|
||||
const value = prefillPrompt?.trim();
|
||||
if (!value || value === lastPrefillPromptRef.current) return;
|
||||
lastPrefillPromptRef.current = value;
|
||||
setPrompt(value);
|
||||
if (!prefillRequest || prefillRequest.id === lastPrefillIdRef.current) return;
|
||||
lastPrefillIdRef.current = prefillRequest.id;
|
||||
if (!prefillRequest.text.trim()) return;
|
||||
setPrompt((current) => appendAgentPromptPrefill(current, prefillRequest.text));
|
||||
setView("chat");
|
||||
}, [prefillPrompt]);
|
||||
}, [prefillRequest]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!open || view !== "chat") setSkillsOpen(false);
|
||||
@@ -1032,6 +1037,7 @@ export function CanvasCloudAgentPanel({ canvasId, domainProjectId, nodeCount, se
|
||||
slashSkills={installedSkills}
|
||||
includeAssetLibrary={false}
|
||||
submitAccessory={<AgentContextRing view={presentAgentContextUsage(contextUsage)} />}
|
||||
footer={connectorsVisible ? <AgentConnectorsBar onClose={() => setConnectorsVisible(false)} /> : null}
|
||||
left={
|
||||
<ComposerControls
|
||||
config={config}
|
||||
|
||||
Reference in New Issue
Block a user