All files / web/src/constants/workflow states.ts

100% Statements 70/70
100% Branches 0/0
100% Functions 0/0
100% Lines 70/70

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110              1x 1x 1x 1x 1x 1x 1x 1x         1x 1x 1x 1x 1x 1x 1x         1x 1x 1x 1x 1x 1x 1x 1x 1x         1x 1x 1x 1x 1x 1x 1x 1x           1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x         1x 1x 1x 1x 1x 1x 1x 1x   1x 1x 1x 1x 1x 1x 1x 1x 1x         1x 1x 1x 1x 1x 1x 1x 1x              
/**
 * Workflow and execution state constants
 */
 
/**
 * Workflow states
 */
export const WORKFLOW_STATE = {
  IDLE: 'idle',
  RUNNING: 'running',
  PAUSED: 'paused',
  COMPLETED: 'completed',
  FAILED: 'failed',
  CANCELLED: 'cancelled',
} as const
 
/**
 * Execution modes
 */
export const EXECUTION_MODE = {
  SYNC: 'sync',
  ASYNC: 'async',
  SCHEDULED: 'scheduled',
  MANUAL: 'manual',
  WEBHOOK: 'webhook',
} as const
 
/**
 * Node execution states
 */
export const NODE_EXECUTION_STATE = {
  PENDING: 'pending',
  RUNNING: 'running',
  SUCCESS: 'success',
  ERROR: 'error',
  SKIPPED: 'skipped',
  RETRYING: 'retrying',
  CANCELLED: 'cancelled',
} as const
 
/**
 * Task status (corresponds to backend TaskStatus)
 */
export const TASK_STATUS = {
  PENDING: 'pending',
  RUNNING: 'running',
  COMPLETED: 'completed',
  FAILED: 'failed',
  RETRYING: 'retrying',
  CANCELLED: 'cancelled',
} as const
 
/**
 * State transition mapping
 * Defines which states can transition to next states
 */
export const WORKFLOW_STATE_TRANSITIONS = {
  [WORKFLOW_STATE.IDLE]: [WORKFLOW_STATE.RUNNING],
  [WORKFLOW_STATE.RUNNING]: [
    WORKFLOW_STATE.PAUSED,
    WORKFLOW_STATE.COMPLETED,
    WORKFLOW_STATE.FAILED,
    WORKFLOW_STATE.CANCELLED,
  ],
  [WORKFLOW_STATE.PAUSED]: [WORKFLOW_STATE.RUNNING, WORKFLOW_STATE.CANCELLED],
  [WORKFLOW_STATE.COMPLETED]: [WORKFLOW_STATE.IDLE],
  [WORKFLOW_STATE.FAILED]: [WORKFLOW_STATE.IDLE],
  [WORKFLOW_STATE.CANCELLED]: [WORKFLOW_STATE.IDLE],
} as const
 
/**
 * State color mapping (for UI display)
 */
export const WORKFLOW_STATE_COLORS = {
  [WORKFLOW_STATE.IDLE]: '#6b7280',
  [WORKFLOW_STATE.RUNNING]: '#3b82f6',
  [WORKFLOW_STATE.PAUSED]: '#f59e0b',
  [WORKFLOW_STATE.COMPLETED]: '#10b981',
  [WORKFLOW_STATE.FAILED]: '#ef4444',
  [WORKFLOW_STATE.CANCELLED]: '#6b7280',
} as const
 
export const NODE_STATE_COLORS = {
  [NODE_EXECUTION_STATE.PENDING]: '#6b7280',
  [NODE_EXECUTION_STATE.RUNNING]: '#3b82f6',
  [NODE_EXECUTION_STATE.SUCCESS]: '#10b981',
  [NODE_EXECUTION_STATE.ERROR]: '#ef4444',
  [NODE_EXECUTION_STATE.SKIPPED]: '#9ca3af',
  [NODE_EXECUTION_STATE.RETRYING]: '#f59e0b',
  [NODE_EXECUTION_STATE.CANCELLED]: '#6b7280',
} as const
 
/**
 * State icon mapping
 */
export const STATE_ICONS = {
  [WORKFLOW_STATE.IDLE]: 'circle',
  [WORKFLOW_STATE.RUNNING]: 'play-circle',
  [WORKFLOW_STATE.PAUSED]: 'pause-circle',
  [WORKFLOW_STATE.COMPLETED]: 'check-circle',
  [WORKFLOW_STATE.FAILED]: 'x-circle',
  [WORKFLOW_STATE.CANCELLED]: 'stop-circle',
} as const
 
// Type exports
export type WorkflowState = typeof WORKFLOW_STATE[keyof typeof WORKFLOW_STATE]
export type ExecutionMode = typeof EXECUTION_MODE[keyof typeof EXECUTION_MODE]
export type NodeExecutionState = typeof NODE_EXECUTION_STATE[keyof typeof NODE_EXECUTION_STATE]
export type TaskStatus = typeof TASK_STATUS[keyof typeof TASK_STATUS]