diff --git a/api/src/functions/task.ts b/api/src/functions/task.ts index f387c8a9..4cca50df 100644 --- a/api/src/functions/task.ts +++ b/api/src/functions/task.ts @@ -1,10 +1,12 @@ import Agent from "../models/Agent"; +import Blueprint from "../models/Blueprint"; import LLMLog from "../models/LLMLog"; import Step from "../models/Step"; import Supervising from "../models/Supervising"; import Task from "../models/Task"; import { Op, col, fn } from "sequelize"; import { event } from "@canmingir/link-express/event/client"; +import { pinMockOutputOf, pinOutputModeOf } from "../lib/blueprintNodes"; import llmLog from "./llmLog"; async function create({ @@ -439,6 +441,43 @@ async function resumePinnedStep({ throw new Error(`Pinned step not found: ${stepId}`); } + const task = await Task.findOne({ where: { id: taskId } }); + const blueprint = task?.blueprintId + ? await Blueprint.findByPk(task.blueprintId) + : null; + const node = blueprint?.nodes?.find( + (n: { id: string }) => n.id === step.nodeId, + ); + + if (pinOutputModeOf(node) === "MOCK") { + const mockOutput = pinMockOutputOf(node) ?? ""; + const comment = "Resumed: using mock output."; + + const [updated] = await Step.update( + { status: "COMPLETED", result: mockOutput, comment }, + { where: { id: stepId, status: "PINNED" } }, + ); + + if (updated === 0) { + throw new Error(`Pinned step not found: ${stepId}`); + } + + await event.publish("STEP_COMPLETED", { + taskId, + stepId, + action: step.action, + parameters: step.parameters, + result: mockOutput, + }); + + return { + ...step.toJSON(), + status: "COMPLETED", + result: mockOutput, + comment, + }; + } + const comment = "Resumed: dispatching the real request."; const [updated] = await Step.update( diff --git a/api/src/lib/blueprintNodes.ts b/api/src/lib/blueprintNodes.ts index d58c5f56..c2ba0b13 100644 --- a/api/src/lib/blueprintNodes.ts +++ b/api/src/lib/blueprintNodes.ts @@ -87,6 +87,16 @@ export function isPinnedNode(node: any) { return node?.properties?.pinned === true; } +export function pinOutputModeOf(node: any): "DEFAULT" | "MOCK" { + return node?.properties?.pinOutputMode === "MOCK" ? "MOCK" : "DEFAULT"; +} + +export function pinMockOutputOf(node: any): string | undefined { + return typeof node?.properties?.pinMockOutput === "string" + ? node.properties.pinMockOutput + : undefined; +} + export function forceAllNodes(nodes: T[]) { return nodes.map((node) => ({ ...node, diff --git a/api/src/schemas/Blueprint.ts b/api/src/schemas/Blueprint.ts index 9d8ddd60..da95307a 100644 --- a/api/src/schemas/Blueprint.ts +++ b/api/src/schemas/Blueprint.ts @@ -66,6 +66,8 @@ const Blueprint = { targetBlueprintId: z.string().optional(), force: z.boolean().optional(), pinned: z.boolean().optional(), + pinOutputMode: z.enum(["DEFAULT", "MOCK"]).optional(), + pinMockOutput: z.string().optional(), fields: ApiFieldsSchema.optional(), strict: z.boolean().optional(), timeout: ApiTimeout.optional(), diff --git a/api/src/schemas/Node.ts b/api/src/schemas/Node.ts index 67315e4a..1764dce3 100644 --- a/api/src/schemas/Node.ts +++ b/api/src/schemas/Node.ts @@ -14,6 +14,8 @@ const ConditionNode = z.object({ pseudocodeEnabled: z.boolean().optional(), force: z.boolean().optional(), pinned: z.boolean().optional(), + pinOutputMode: z.enum(["DEFAULT", "MOCK"]).optional(), + pinMockOutput: z.string().optional(), }), }); @@ -29,6 +31,8 @@ const NormalNode = z.object({ pseudocodeEnabled: z.boolean().optional(), force: z.boolean().optional(), pinned: z.boolean().optional(), + pinOutputMode: z.enum(["DEFAULT", "MOCK"]).optional(), + pinMockOutput: z.string().optional(), parameters: z.record(z.string(), z.unknown()).optional(), }), }); @@ -45,6 +49,8 @@ const SwitchNode = z.object({ pseudocodeEnabled: z.boolean().optional(), force: z.boolean().optional(), pinned: z.boolean().optional(), + pinOutputMode: z.enum(["DEFAULT", "MOCK"]).optional(), + pinMockOutput: z.string().optional(), cases: z .array( z.object({ @@ -70,6 +76,8 @@ const HandoffNode = z.object({ pseudocodeEnabled: z.boolean().optional(), force: z.boolean().optional(), pinned: z.boolean().optional(), + pinOutputMode: z.enum(["DEFAULT", "MOCK"]).optional(), + pinMockOutput: z.string().optional(), }), }); @@ -87,6 +95,8 @@ const ApprovalNode = z.object({ pseudocodeEnabled: z.boolean().optional(), force: z.boolean().optional(), pinned: z.boolean().optional(), + pinOutputMode: z.enum(["DEFAULT", "MOCK"]).optional(), + pinMockOutput: z.string().optional(), }), }); diff --git a/dashboard/src/components/BlueprintFlow/PinNodeDialog.tsx b/dashboard/src/components/BlueprintFlow/PinNodeDialog.tsx new file mode 100644 index 00000000..22a7b263 --- /dev/null +++ b/dashboard/src/components/BlueprintFlow/PinNodeDialog.tsx @@ -0,0 +1,178 @@ +import { + Box, + Button, + Dialog, + DialogActions, + DialogContent, + DialogContentText, + DialogTitle, + FormControl, + FormControlLabel, + Radio, + RadioGroup, + TextField, + Typography, +} from "@mui/material"; +import { useEffect, useState } from "react"; + +const FALLBACK_MOCK_OUTPUT = `{ + "result": "" +}`; + +export type PinOutputMode = "DEFAULT" | "MOCK"; + +export type PinNodeProperties = { + pinned: true; + pinOutputMode: PinOutputMode; + pinMockOutput?: string; +}; + +function blankMockOutput(outputFields?: string[]) { + if (!outputFields?.length) return FALLBACK_MOCK_OUTPUT; + + const skeleton = Object.fromEntries(outputFields.map((field) => [field, ""])); + return JSON.stringify(skeleton, null, 2); +} + +export default function PinNodeDialog({ + open, + node, + outputFields, + onClose, + onSave, + onUnpin, +}: { + open: boolean; + node?: { + id: string; + label: string; + raw?: { properties?: Record }; + }; + outputFields?: string[]; + onClose: () => void; + onSave: (properties: PinNodeProperties) => void; + onUnpin: () => void; +}) { + const [mode, setMode] = useState("DEFAULT"); + const [mockDraft, setMockDraft] = useState(""); + + useEffect(() => { + if (!open || !node) return; + const properties = node.raw?.properties ?? {}; + setMode(properties.pinOutputMode === "MOCK" ? "MOCK" : "DEFAULT"); + setMockDraft( + typeof properties.pinMockOutput === "string" && properties.pinMockOutput + ? properties.pinMockOutput + : blankMockOutput(outputFields) + ); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [open, node]); + + const isMock = mode === "MOCK"; + let jsonError: string | undefined; + if (isMock) { + try { + JSON.parse(mockDraft); + } catch { + jsonError = "Invalid JSON"; + } + } + + const isPinned = Boolean(node?.raw?.properties?.pinned); + + const handleSave = () => { + onSave({ + pinned: true, + pinOutputMode: mode, + ...(isMock ? { pinMockOutput: mockDraft } : {}), + }); + }; + + return ( + theme.zIndex.modal + 3 }} + slotProps={{ + paper: { sx: { borderRadius: 2 } }, + }} + > + Pin node: {node?.label} + + + Test runs skip this step and return your mock JSON. Production + execution is not affected. + + + + Output source + + + setMode(e.target.value as PinOutputMode)} + > + } + label="Default" + /> + } + label="Mock output" + /> + + + + {isMock && ( + + + Mock output (JSON) + + setMockDraft(e.target.value)} + error={Boolean(jsonError)} + helperText={jsonError} + inputProps={{ + "aria-label": "Mock output JSON", + style: { + fontFamily: + '"JetBrains Mono", "SFMono-Regular", Menlo, Consolas, monospace', + fontSize: 13, + }, + }} + /> + + )} + + + {isPinned ? ( + + ) : ( + + )} + + + + + + + ); +} diff --git a/dashboard/src/components/SettingsDialog/SettingsDialog.tsx b/dashboard/src/components/SettingsDialog/SettingsDialog.tsx index dc9ae39d..00c760e7 100644 --- a/dashboard/src/components/SettingsDialog/SettingsDialog.tsx +++ b/dashboard/src/components/SettingsDialog/SettingsDialog.tsx @@ -35,6 +35,8 @@ const SettingsDialog = ({ mode = "CHAT", setMode, blueprintId, + debugMode = false, + setDebugMode, }: { showSettings: boolean; setShowSettings: (value: boolean) => void; @@ -47,6 +49,8 @@ const SettingsDialog = ({ mode?: BlueprintMode; setMode?: (value: BlueprintMode) => void; blueprintId?: string; + debugMode?: boolean; + setDebugMode?: (value: boolean) => void; }) => { const theme = useTheme(); @@ -204,6 +208,36 @@ const SettingsDialog = ({ )} + + {setDebugMode && ( + <> + + Debug Mode + + + Shows developer-only controls on the canvas, such as pin + buttons on nodes. + + + + )} )} diff --git a/dashboard/src/layouts/BlueprintDrawerLayout.tsx b/dashboard/src/layouts/BlueprintDrawerLayout.tsx index 47312657..531101b4 100644 --- a/dashboard/src/layouts/BlueprintDrawerLayout.tsx +++ b/dashboard/src/layouts/BlueprintDrawerLayout.tsx @@ -115,6 +115,14 @@ const BlueprintDrawerLayout = ({ "showconnections", false ); + const [debugMode] = useStorage( + "nuc", + "blueprintdrawerlayout", + "debugmode", + false + ); + const setDebugMode = (value: boolean) => + storage.set("nuc", "blueprintdrawerlayout", "debugmode", value); const [superviseChatOpen, setSuperviseChatOpen] = useState( !!supervise ); @@ -288,6 +296,7 @@ const BlueprintDrawerLayout = ({ liteMode={liteMode} mode={mode} showConnections={showConnections} + debugMode={debugMode} onSkillChange={setSkill} onSkillLoadingChange={setSkillLoading} onNodesChange={setLiveNodes} @@ -440,6 +449,8 @@ const BlueprintDrawerLayout = ({ mode={mode} setMode={setMode} blueprintId={selectedItem?.id} + debugMode={debugMode} + setDebugMode={setDebugMode} /> ); diff --git a/dashboard/src/widgets/AgentDevToolWidget/AgentDevToolWidget.tsx b/dashboard/src/widgets/AgentDevToolWidget/AgentDevToolWidget.tsx index fd438062..e9cf5b48 100644 --- a/dashboard/src/widgets/AgentDevToolWidget/AgentDevToolWidget.tsx +++ b/dashboard/src/widgets/AgentDevToolWidget/AgentDevToolWidget.tsx @@ -135,11 +135,11 @@ const AgentDevToolWidget = ({ }, [conversations]); useEffect(() => { - if (open && sessionId) { + if (sessionId) { getSession(sessionId); } // eslint-disable-next-line react-hooks/exhaustive-deps - }, [open, sessionId]); + }, [sessionId]); useEffect(() => { if (!context) setContextOpen(false); diff --git a/dashboard/src/widgets/BlueprintFlowWidget/BlueprintFlowWidget.tsx b/dashboard/src/widgets/BlueprintFlowWidget/BlueprintFlowWidget.tsx index 8511654d..e3a9d518 100644 --- a/dashboard/src/widgets/BlueprintFlowWidget/BlueprintFlowWidget.tsx +++ b/dashboard/src/widgets/BlueprintFlowWidget/BlueprintFlowWidget.tsx @@ -3,6 +3,8 @@ import BlueprintFlow from "../../components/BlueprintFlow/BlueprintFlow"; import BlueprintFlowSkeleton from "../../components/Skeletons/BlueprintFlowSkeleton"; import NodeEditorWidget from "../NodeEditorWidget/NodeEditorWidget"; import type { ParameterBinding } from "../../components/BlueprintFlow/NodeConnectionOverlay"; +import PinNodeDialog from "../../components/BlueprintFlow/PinNodeDialog"; +import type { PinNodeProperties } from "../../components/BlueprintFlow/PinNodeDialog"; import StartNode from "../../components/BlueprintFlow/StartNode/StartNode"; import type { SwitchCase } from "../../components/BlueprintFlow/helper"; import { publish } from "@nucleoidai/react-event"; @@ -67,6 +69,10 @@ function graphToNodes(graphData: DefinitionGraph) { ...(node.raw?.properties?.pinned && { pinned: true, }), + ...(node.raw?.properties?.pinOutputMode === "MOCK" && { + pinOutputMode: "MOCK", + pinMockOutput: node.raw?.properties?.pinMockOutput, + }), ...(node.nodeType === "NORMAL" && node.raw?.properties?.parameters && Object.keys(node.raw.properties.parameters).length > 0 && { @@ -144,6 +150,7 @@ function BlueprintFlowWidget({ liteMode = false, mode, showConnections: showConnectionsProp, + debugMode = false, onDescriptionChange, onDescriptionLoadingChange, onSkillChange, @@ -178,6 +185,7 @@ function BlueprintFlowWidget({ liteMode?: boolean; mode?: BlueprintMode; showConnections?: boolean; + debugMode?: boolean; onSave?: () => void; }) { const [graphData, setGraphData] = useState(null); @@ -665,29 +673,72 @@ function BlueprintFlowWidget({ setApiNodeId(null); }; + const [pinNodeId, setPinNodeId] = useState(null); + const handlePinNodeClick = (node: { id: string }) => { + setPinNodeId(node.id); + }; + + const pinNodeOutputFields = useMemo(() => { + const action = pinNodeId + ? graphData?.nodes?.[pinNodeId]?.action + : undefined; + if (!action) return undefined; + + const integration = allIntegrations.find((i) => i.action === action); + const outputProperties = integration?.outputSchema?.properties; + if (!outputProperties || Object.keys(outputProperties).length === 0) { + return undefined; + } + + return Object.keys(outputProperties); + }, [pinNodeId, graphData, allIntegrations]); + + const handlePinNodeSave = (properties: PinNodeProperties) => { setGraphData((prev) => { - if (!prev) return prev; - const targetNode = prev.nodes[node.id]; + if (!prev || !pinNodeId) return prev; + const targetNode = prev.nodes[pinNodeId]; if (!targetNode) return prev; - const wasPinned = Boolean(targetNode.raw?.properties?.pinned); + const rest = { ...targetNode.raw?.properties }; + delete rest.pinMockOutput; const currentNodes = { ...prev.nodes }; - currentNodes[node.id] = { + currentNodes[pinNodeId] = { ...targetNode, raw: { ...targetNode.raw, - properties: { - ...targetNode.raw?.properties, - pinned: !wasPinned, - }, + properties: { ...rest, ...properties }, }, }; return { ...prev, nodes: currentNodes }; }); setHasLocalChanges(true); + setPinNodeId(null); + }; + + const handleUnpinNode = () => { + setGraphData((prev) => { + if (!prev || !pinNodeId) return prev; + const targetNode = prev.nodes[pinNodeId]; + if (!targetNode) return prev; + + const rest = { ...targetNode.raw?.properties }; + delete rest.pinned; + delete rest.pinOutputMode; + delete rest.pinMockOutput; + + const currentNodes = { ...prev.nodes }; + currentNodes[pinNodeId] = { + ...targetNode, + raw: { ...targetNode.raw, properties: rest }, + }; + + return { ...prev, nodes: currentNodes }; + }); + setHasLocalChanges(true); + setPinNodeId(null); }; const handleEditNodeClick = (node) => { @@ -2157,7 +2208,7 @@ function BlueprintFlowWidget({ onFlowChange={handleFlowChange} onAddNodeClick={handleAddNodeClick} onEditNodeClick={handleEditNodeClick} - onPinNodeClick={handlePinNodeClick} + onPinNodeClick={debugMode ? handlePinNodeClick : undefined} onSwapBranchClick={handleSwapBranch} onDeleteNodeClick={handleDeleteNode} onSave={handleSaveFlow} @@ -2187,6 +2238,15 @@ function BlueprintFlowWidget({ onSave={handleApiNodeSave} /> + setPinNodeId(null)} + onSave={handlePinNodeSave} + onUnpin={handleUnpinNode} + /> +