ultisuite-client/lib/mail-automation/types.ts
2026-05-25 13:52:40 +02:00

191 lines
3.2 KiB
TypeScript

/** Automation workflow graph — mirrors backend rules.Workflow */
export type RuleKind = 'rule' | 'function'
export type TriggerType = 'message_received' | 'label_added' | 'label_removed'
export interface AutomationTrigger {
type: TriggerType
folder_id?: string
label?: string
account_id?: string
}
export interface TriggerAndGroup {
operator: 'and'
items: AutomationTrigger[]
}
export interface TriggerOrGroup {
operator: 'or'
groups: TriggerAndGroup[]
}
export interface ExecVariable {
name: string
type: 'string' | 'number' | 'boolean'
default?: string
}
export type WorkflowNodeType =
| 'start'
| 'condition'
| 'label_check'
| 'switch'
| 'llm_check'
| 'actions'
| 'set_var'
| 'call_function'
| 'call_rule'
| 'end'
export type ConditionField =
| 'from'
| 'to'
| 'subject'
| 'body'
| 'has_attachment'
| 'label'
export type ConditionOperator =
| 'contains'
| 'equals'
| 'starts_with'
| 'ends_with'
| 'not_contains'
| 'regex'
| 'not_regex'
| 'has'
| 'not_has'
export interface ConditionNodeData {
field: ConditionField
operator: ConditionOperator
value: string
}
/** @deprecated Legacy node — migrated to condition with field=label */
export interface LabelCheckNodeData {
label: string
operator: 'has' | 'not_has'
}
export interface SwitchCase {
value: string
label?: string
}
export interface SwitchNodeData {
field: string
cases: SwitchCase[]
}
export interface LLMCheckNodeData {
prompt: string
provider?: string
model?: string
}
export type ActionType =
| 'label'
| 'remove_label'
| 'move'
| 'archive'
| 'delete'
| 'mark_read'
| 'mark_important'
| 'mark_spam'
| 'star'
| 'webhook'
| 'notify'
| 'reply'
| 'send_mail'
| 'forward'
export interface ActionItem {
type: ActionType
value: string
}
export interface ActionsNodeData {
actions: ActionItem[]
}
export interface SetVarNodeData {
name: string
value: string
}
export interface CallRuleNodeData {
rule_id: string
}
export type WorkflowNodeData =
| Record<string, never>
| ConditionNodeData
| LabelCheckNodeData
| SwitchNodeData
| LLMCheckNodeData
| ActionsNodeData
| SetVarNodeData
| CallRuleNodeData
export interface WorkflowNodeDef {
id: string
type: WorkflowNodeType
position: { x: number; y: number }
data: WorkflowNodeData
}
export interface WorkflowEdgeDef {
id: string
source: string
target: string
sourceHandle?: string
}
export interface AutomationWorkflow {
version: 1
kind: RuleKind
triggers: TriggerOrGroup
variables: ExecVariable[]
nodes: WorkflowNodeDef[]
edges: WorkflowEdgeDef[]
}
export interface RuleSimulationMessage {
from: string
to: string[]
subject: string
body_text: string
has_attachments: boolean
labels?: string[]
}
export interface RuleSimulationStep {
node_id: string
node_type: string
handle?: string
}
export interface RuleSimulationResult {
matched: boolean
steps?: RuleSimulationStep[]
actions?: Array<{
type: string
value: string
ok: boolean
error?: string
simulated_payload?: string
}>
}
export interface RuleEditorState {
name: string
priority: number
is_active: boolean
rule_kind: RuleKind
account_id?: string
workflow: AutomationWorkflow
}