diff --git a/packages/dashboard/app/api/legacy.ts b/packages/dashboard/app/api/legacy.ts index 0a987a4900..d2350e96e9 100644 --- a/packages/dashboard/app/api/legacy.ts +++ b/packages/dashboard/app/api/legacy.ts @@ -4897,6 +4897,96 @@ export function fetchWorkflowResults(taskId: string, projectId?: string): Promis return api(withProjectId(`/tasks/${encodeURIComponent(taskId)}/workflow-results`, projectId)); } +// ── Workflow definitions (graph-authored custom workflows) ─────────────── + +export type { + WorkflowDefinition, + WorkflowDefinitionInput, + WorkflowDefinitionUpdate, + WorkflowIr, +} from "@fusion/core"; + +/** List all workflow definitions for the project. */ +export function fetchWorkflows(projectId?: string): Promise { + const path = withProjectId("/workflows", projectId); + return dedupe(path, () => api(path)); +} + +/** Fetch a single workflow definition. */ +export function fetchWorkflow(id: string, projectId?: string): Promise { + return api(withProjectId(`/workflows/${encodeURIComponent(id)}`, projectId)); +} + +/** Create a workflow definition. */ +export function createWorkflow( + input: import("@fusion/core").WorkflowDefinitionInput, + projectId?: string, +): Promise { + return api(withProjectId("/workflows", projectId), { + method: "POST", + body: JSON.stringify(input), + }); +} + +/** Update a workflow definition (partial). */ +export function updateWorkflow( + id: string, + updates: import("@fusion/core").WorkflowDefinitionUpdate, + projectId?: string, +): Promise { + return api(withProjectId(`/workflows/${encodeURIComponent(id)}`, projectId), { + method: "PATCH", + body: JSON.stringify(updates), + }); +} + +/** Delete a workflow definition. */ +export function deleteWorkflow(id: string, projectId?: string): Promise { + return api(withProjectId(`/workflows/${encodeURIComponent(id)}`, projectId), { method: "DELETE" }); +} + +/** Preview the compiled steps for a workflow. Rejects (422) for non-linear graphs. */ +export function compileWorkflow(id: string, projectId?: string): Promise<{ steps: WorkflowStepInput[] }> { + return api<{ steps: WorkflowStepInput[] }>(withProjectId(`/workflows/${encodeURIComponent(id)}/compile`, projectId), { + method: "POST", + }); +} + +/** Read the workflow currently selected for a task. */ +export function fetchTaskWorkflow(taskId: string, projectId?: string): Promise<{ workflowId: string | null }> { + return api<{ workflowId: string | null }>( + withProjectId(`/tasks/${encodeURIComponent(taskId)}/workflow`, projectId), + ); +} + +/** Select (or clear, with null) a workflow for a task. */ +export function selectTaskWorkflow( + taskId: string, + workflowId: string | null, + projectId?: string, +): Promise<{ workflowId: string | null }> { + return api<{ workflowId: string | null }>(withProjectId(`/tasks/${encodeURIComponent(taskId)}/workflow`, projectId), { + method: "PUT", + body: JSON.stringify({ workflowId }), + }); +} + +/** Read the project default workflow. */ +export function fetchProjectDefaultWorkflow(projectId?: string): Promise<{ workflowId: string | null }> { + return api<{ workflowId: string | null }>(withProjectId("/project/default-workflow", projectId)); +} + +/** Set (or clear, with null) the project default workflow. */ +export function setProjectDefaultWorkflow( + workflowId: string | null, + projectId?: string, +): Promise<{ workflowId: string | null }> { + return api<{ workflowId: string | null }>(withProjectId("/project/default-workflow", projectId), { + method: "PUT", + body: JSON.stringify({ workflowId }), + }); +} + // ── Workflow Step Templates ────────────────────────────────────────────── /** Re-export WorkflowStepTemplate type from core */