Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions api/src/functions/task.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand Down Expand Up @@ -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(
Expand Down
10 changes: 10 additions & 0 deletions api/src/lib/blueprintNodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends { properties?: object }>(nodes: T[]) {
return nodes.map((node) => ({
...node,
Expand Down
2 changes: 2 additions & 0 deletions api/src/schemas/Blueprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
10 changes: 10 additions & 0 deletions api/src/schemas/Node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}),
});

Expand All @@ -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(),
}),
});
Expand All @@ -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({
Expand All @@ -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(),
}),
});

Expand All @@ -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(),
}),
});

Expand Down
178 changes: 178 additions & 0 deletions dashboard/src/components/BlueprintFlow/PinNodeDialog.tsx
Original file line number Diff line number Diff line change
@@ -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<string, unknown> };
};
outputFields?: string[];
onClose: () => void;
onSave: (properties: PinNodeProperties) => void;
onUnpin: () => void;
}) {
const [mode, setMode] = useState<PinOutputMode>("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 (
<Dialog
open={open}
onClose={onClose}
type="small"
sx={{ zIndex: (theme) => theme.zIndex.modal + 3 }}
slotProps={{
paper: { sx: { borderRadius: 2 } },
}}
>
<DialogTitle>Pin node: {node?.label}</DialogTitle>
<DialogContent>
<DialogContentText sx={{ mb: 2 }}>
Test runs skip this step and return your mock JSON. Production
execution is not affected.
</DialogContentText>

<Typography variant="subtitle2" sx={{ mb: 1 }}>
Output source
</Typography>
<FormControl>
<RadioGroup
row
value={mode}
onChange={(e) => setMode(e.target.value as PinOutputMode)}
>
<FormControlLabel
value="DEFAULT"
control={<Radio />}
label="Default"
/>
<FormControlLabel
value="MOCK"
control={<Radio />}
label="Mock output"
/>
</RadioGroup>
</FormControl>

{isMock && (
<Box sx={{ mt: 1.5 }}>
<Typography variant="subtitle2" sx={{ mb: 1 }}>
Mock output (JSON)
</Typography>
<TextField
autoFocus
fullWidth
multiline
minRows={6}
maxRows={16}
value={mockDraft}
onChange={(e) => 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,
},
}}
/>
</Box>
)}
</DialogContent>
<DialogActions sx={{ justifyContent: "space-between", px: 3, pb: 2 }}>
{isPinned ? (
<Button color="error" onClick={onUnpin}>
Unpin
</Button>
) : (
<Box />
)}
<Box sx={{ display: "flex", gap: 1 }}>
<Button onClick={onClose}>Cancel</Button>
<Button
variant="contained"
disabled={isMock && Boolean(jsonError)}
onClick={handleSave}
>
Save
</Button>
</Box>
</DialogActions>
</Dialog>
);
}
34 changes: 34 additions & 0 deletions dashboard/src/components/SettingsDialog/SettingsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const SettingsDialog = ({
mode = "CHAT",
setMode,
blueprintId,
debugMode = false,
setDebugMode,
}: {
showSettings: boolean;
setShowSettings: (value: boolean) => void;
Expand All @@ -47,6 +49,8 @@ const SettingsDialog = ({
mode?: BlueprintMode;
setMode?: (value: BlueprintMode) => void;
blueprintId?: string;
debugMode?: boolean;
setDebugMode?: (value: boolean) => void;
}) => {
const theme = useTheme();

Expand Down Expand Up @@ -204,6 +208,36 @@ const SettingsDialog = ({
</Typography>
</>
)}

{setDebugMode && (
<>
<Typography variant="subtitle2" gutterBottom sx={{ mt: 4 }}>
Debug Mode
</Typography>
<Typography
variant="body2"
color="text.secondary"
sx={{ mb: 2 }}
>
Shows developer-only controls on the canvas, such as pin
buttons on nodes.
</Typography>
<LinkSwipe
checked={debugMode}
onChange={setDebugMode}
theme={theme}
color="primary"
variant="solid"
showThumbIcon={false}
offLabel="Off"
onLabel="On"
ariaLabel="Debug mode"
width={70}
height={30}
thumbSize={20}
/>
</>
)}
</Box>
)}
</Box>
Expand Down
11 changes: 11 additions & 0 deletions dashboard/src/layouts/BlueprintDrawerLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean>(
!!supervise
);
Expand Down Expand Up @@ -288,6 +296,7 @@ const BlueprintDrawerLayout = ({
liteMode={liteMode}
mode={mode}
showConnections={showConnections}
debugMode={debugMode}
onSkillChange={setSkill}
onSkillLoadingChange={setSkillLoading}
onNodesChange={setLiveNodes}
Expand Down Expand Up @@ -440,6 +449,8 @@ const BlueprintDrawerLayout = ({
mode={mode}
setMode={setMode}
blueprintId={selectedItem?.id}
debugMode={debugMode}
setDebugMode={setDebugMode}
/>
</Box>
);
Expand Down
Loading
Loading