feat(dashboard): workflow API client functions (U5)
Add fetch/create/update/delete/compile workflow client wrappers plus select/fetch task workflow and get/set project default, mirroring the existing WorkflowStep client conventions (api/withProjectId/dedupe).
This commit is contained in:
@@ -4897,6 +4897,96 @@ export function fetchWorkflowResults(taskId: string, projectId?: string): Promis
|
||||
return api<WorkflowStepResult[]>(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<import("@fusion/core").WorkflowDefinition[]> {
|
||||
const path = withProjectId("/workflows", projectId);
|
||||
return dedupe(path, () => api<import("@fusion/core").WorkflowDefinition[]>(path));
|
||||
}
|
||||
|
||||
/** Fetch a single workflow definition. */
|
||||
export function fetchWorkflow(id: string, projectId?: string): Promise<import("@fusion/core").WorkflowDefinition> {
|
||||
return api<import("@fusion/core").WorkflowDefinition>(withProjectId(`/workflows/${encodeURIComponent(id)}`, projectId));
|
||||
}
|
||||
|
||||
/** Create a workflow definition. */
|
||||
export function createWorkflow(
|
||||
input: import("@fusion/core").WorkflowDefinitionInput,
|
||||
projectId?: string,
|
||||
): Promise<import("@fusion/core").WorkflowDefinition> {
|
||||
return api<import("@fusion/core").WorkflowDefinition>(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<import("@fusion/core").WorkflowDefinition> {
|
||||
return api<import("@fusion/core").WorkflowDefinition>(withProjectId(`/workflows/${encodeURIComponent(id)}`, projectId), {
|
||||
method: "PATCH",
|
||||
body: JSON.stringify(updates),
|
||||
});
|
||||
}
|
||||
|
||||
/** Delete a workflow definition. */
|
||||
export function deleteWorkflow(id: string, projectId?: string): Promise<void> {
|
||||
return api<void>(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 */
|
||||
|
||||
Reference in New Issue
Block a user