feat(desktop): workflow builder UI with form editor, CRUD, and channel picker (#231)

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Wes
2026-04-03 18:41:31 -07:00
committed by GitHub
co-authored by Claude Opus 4.6
parent 26155003bd
commit 5923a7ba1c
21 changed files with 1824 additions and 211 deletions
+121
View File
@@ -999,6 +999,95 @@ let mockRelayAgents: RawRelayAgent[] = [
status: "away",
},
];
// ── Workflow mocks ─────────────────────────────────────────────────────────
type MockWorkflow = {
id: string;
name: string;
owner_pubkey: string;
channel_id: string | null;
definition: Record<string, unknown>;
status: "active" | "disabled" | "archived";
created_at: number;
updated_at: number;
};
const mockWorkflows: MockWorkflow[] = [];
let mockWorkflowIdCounter = 0;
function handleGetChannelWorkflows(args: { channelId: string }) {
return mockWorkflows.filter((w) => w.channel_id === args.channelId);
}
function handleGetWorkflow(args: { workflowId: string }) {
const workflow = mockWorkflows.find((w) => w.id === args.workflowId);
if (!workflow) throw new Error(`Workflow ${args.workflowId} not found`);
return workflow;
}
function handleCreateWorkflow(args: {
channelId: string;
yamlDefinition: string;
}) {
mockWorkflowIdCounter += 1;
const now = Math.floor(Date.now() / 1000);
// Parse the name from the YAML definition (simple extraction)
const nameMatch = args.yamlDefinition.match(/^name:\s*(.+)$/m);
const name = nameMatch
? nameMatch[1].trim()
: `workflow_${mockWorkflowIdCounter}`;
const workflow: MockWorkflow = {
id: `mock-wf-${mockWorkflowIdCounter}`,
name,
owner_pubkey: MOCK_IDENTITY_PUBKEY,
channel_id: args.channelId,
definition: { raw: args.yamlDefinition },
status: "active",
created_at: now,
updated_at: now,
};
mockWorkflows.push(workflow);
return workflow;
}
function handleUpdateWorkflow(args: {
workflowId: string;
yamlDefinition: string;
}) {
const workflow = mockWorkflows.find((w) => w.id === args.workflowId);
if (!workflow) throw new Error(`Workflow ${args.workflowId} not found`);
const nameMatch = args.yamlDefinition.match(/^name:\s*(.+)$/m);
if (nameMatch) workflow.name = nameMatch[1].trim();
workflow.definition = { raw: args.yamlDefinition };
workflow.updated_at = Math.floor(Date.now() / 1000);
return workflow;
}
function handleDeleteWorkflow(args: { workflowId: string }) {
const index = mockWorkflows.findIndex((w) => w.id === args.workflowId);
if (index === -1) throw new Error(`Workflow ${args.workflowId} not found`);
mockWorkflows.splice(index, 1);
}
function handleTriggerWorkflow(args: { workflowId: string }) {
const workflow = mockWorkflows.find((w) => w.id === args.workflowId);
if (!workflow) throw new Error(`Workflow ${args.workflowId} not found`);
return {
run_id: `mock-run-${Date.now()}`,
workflow_id: workflow.id,
status: "pending",
};
}
function handleGetWorkflowRuns(_args: { workflowId: string }) {
return [];
}
function handleGetRunApprovals(_args: { workflowId: string; runId: string }) {
return [];
}
const mockProfiles = new Map<string, RawProfile>([
[
MOCK_IDENTITY_PUBKEY,
@@ -3552,6 +3641,38 @@ export function maybeInstallE2eTauriMocks() {
}
return disconnectMockSocket((payload as { id: number }).id);
case "get_channel_workflows":
return handleGetChannelWorkflows(
payload as Parameters<typeof handleGetChannelWorkflows>[0],
);
case "get_workflow":
return handleGetWorkflow(
payload as Parameters<typeof handleGetWorkflow>[0],
);
case "create_workflow":
return handleCreateWorkflow(
payload as Parameters<typeof handleCreateWorkflow>[0],
);
case "update_workflow":
return handleUpdateWorkflow(
payload as Parameters<typeof handleUpdateWorkflow>[0],
);
case "delete_workflow":
return handleDeleteWorkflow(
payload as Parameters<typeof handleDeleteWorkflow>[0],
);
case "trigger_workflow":
return handleTriggerWorkflow(
payload as Parameters<typeof handleTriggerWorkflow>[0],
);
case "get_workflow_runs":
return handleGetWorkflowRuns(
payload as Parameters<typeof handleGetWorkflowRuns>[0],
);
case "get_run_approvals":
return handleGetRunApprovals(
payload as Parameters<typeof handleGetRunApprovals>[0],
);
case "plugin:webview|set_webview_zoom":
window.__SPROUT_E2E_WEBVIEW_ZOOM__ = (
payload as { value: number }