import { apiRequest } from "./_shared"; import type { ScriptType, Visibility } from "./scripts"; import type { DagValidation, ScheduleEdge, ScheduleNode, ScheduleNodeRun, } from "./scheduleGraph"; export type ScheduleArtifact = { versions_id: string; version_label: string; script_id: string; script_name: string; script_type: ScriptType; content_hash: string; file_size_bytes: number; visibility: Visibility; created_by: string; created_at: string; }; export type PythonVersion = "3.8" | "3.10" | "3.12"; export type Schedule = { schedule_id: string; workspace_id: string; schedule_name: string; description: string | null; trigger_type: "manual" | "cron" | "api"; cron_expression: string | null; timezone: string; enabled: boolean; workflow_version: number; max_concurrency: number; failure_policy: "stop" | "continue"; last_run_at: string | null; next_run_at: string | null; created_by: string; updated_by: string; created_at: string; updated_at: string; node_count: number; edge_count: number; nodes: ScheduleNode[]; edges: ScheduleEdge[]; dag_validation: DagValidation; }; export type CronPreview = { cron_expression: string; timezone: string; base_time: string; occurrences: Array<{ local_time: string; utc_time: string; }>; }; export type ScheduleRunStatus = | "queued" | "running" | "succeeded" | "failed" | "cancelled" | "timed_out"; export type ScheduleRunSummary = { run_id: string; schedule_id: string; workspace_id: string; workflow_version: number; trigger_type: "manual" | "cron" | "api" | "retry"; run_status: ScheduleRunStatus; state_version: number; queued_at: string; started_at: string | null; finished_at: string | null; duration_ms: number | null; error_code: string | null; error_message: string | null; logs_object_id: string | null; result_object_id: string | null; }; export type ScheduleRunDetail = ScheduleRunSummary & { node_runs: ScheduleNodeRun[]; }; export type ScheduleRunArtifact = { url: string; file_name: string; mime_type: string | null; size_bytes: number; }; export type ScheduleNodeRunArtifacts = { run_id: string; node_run_id: string; log: ScheduleRunArtifact | null; result: ScheduleRunArtifact | null; }; export async function listSchedules(workspaceId: string): Promise { return apiRequest("/api/v1/schedules", {}, workspaceId); } export async function getSchedule( workspaceId: string, scheduleId: string, ): Promise { return apiRequest( `/api/v1/schedules/${scheduleId}`, {}, workspaceId, ); } export async function createSchedule( workspaceId: string, input: { schedule_name: string; description?: string | null; trigger_type?: "manual" | "cron" | "api"; cron_expression?: string | null; timezone?: string; enabled?: boolean; max_concurrency?: number; failure_policy?: "stop" | "continue"; }, ): Promise { return apiRequest( "/api/v1/schedules", { method: "POST", body: JSON.stringify(input) }, workspaceId, ); } export async function updateSchedule( workspaceId: string, scheduleId: string, input: { workflow_version: number; schedule_name?: string; description?: string | null; trigger_type?: "manual" | "cron" | "api"; cron_expression?: string | null; timezone?: string; enabled?: boolean; max_concurrency?: number; failure_policy?: "stop" | "continue"; }, ): Promise { return apiRequest( `/api/v1/schedules/${scheduleId}`, { method: "PATCH", body: JSON.stringify(input) }, workspaceId, ); } export async function deleteSchedule( workspaceId: string, scheduleId: string, workflowVersion: number, ): Promise<{ schedule_id: string; deleted: boolean; workflow_version: number }> { return apiRequest( `/api/v1/schedules/${scheduleId}`, { method: "DELETE", body: JSON.stringify({ workflow_version: workflowVersion }) }, workspaceId, ); } export async function listScheduleArtifacts( workspaceId: string, ): Promise { return apiRequest( "/api/v1/schedule-artifacts", {}, workspaceId, ); } export async function hideScheduleArtifact( workspaceId: string, versionsId: string, ): Promise<{ versions_id: string; deleted: boolean; artifact_preserved: boolean; }> { return apiRequest( `/api/v1/versions/${versionsId}`, { method: "DELETE" }, workspaceId, ); }