dex_sdk/flow_info.rs
1// Copyright (c) 2026 Super Durable, Inc.
2//
3// Licensed under the Super Durable Source License 1.0.
4// You may not use this file except in compliance with the License.
5// See the LICENSE file in the repository root.
6//
7// SPDX-License-Identifier: LicenseRef-Super-Durable-1.0
8
9use std::collections::BTreeMap;
10use std::time::SystemTime;
11
12#[derive(Clone, Copy, Debug, Eq, PartialEq)]
13/// Describes the current or terminal state of a Flow run.
14pub enum FlowStatus {
15 /// The Flow can still execute Steps or receive RPCs and Channel messages.
16 Running,
17 /// The Flow completed successfully.
18 Completed,
19 /// The Flow ended because a Step, RPC, or user-code failure was not recovered.
20 Failed,
21 /// Reserved for backend hard-timeout reporting. Applications must not depend on this status.
22 ServerSideTimeoutInternalOnly,
23 /// An operator terminated the Flow immediately.
24 Terminated,
25 /// The Flow completed cooperative cancellation.
26 Canceled,
27 /// The run rolled its history into a successor run.
28 ContinuedAsNew,
29}
30
31#[derive(Clone, Copy, Debug, Eq, PartialEq)]
32/// Categorizes the failure recorded for an uncompleted Flow.
33pub enum FlowErrorType {
34 /// A Step returned an invalid or failing decision.
35 StepDecisionFailed,
36 /// A client API operation failed the Flow.
37 ClientApiFailed,
38 /// A Worker Step or RPC handler failed.
39 WorkerApiFailed,
40 /// The registered Flow or Step definition violated an SDK contract.
41 InvalidUserFlowCode,
42 /// Dex encountered an internal failure.
43 Internal,
44 /// A Dex soft Flow timeout expired under the fail policy.
45 FlowTimeout,
46}
47
48#[derive(Clone, Debug, Eq, PartialEq)]
49/// Summarizes one Flow run returned by [`crate::Client::describe_flow`].
50pub struct FlowInfo {
51 /// Application-assigned Flow ID.
52 pub flow_id: String,
53 /// Server-assigned run ID for the described execution.
54 pub run_id: String,
55 /// Registered Flow type name.
56 pub flow_type: String,
57 /// Current or terminal status.
58 pub status: FlowStatus,
59 /// Server-recorded start time.
60 pub started_at: SystemTime,
61}
62
63#[derive(Clone, Debug, PartialEq)]
64/// Contains one Flow row returned by a search query.
65pub struct SearchFlowEntry {
66 /// Application-assigned Flow ID.
67 pub flow_id: String,
68 /// Server-assigned run ID.
69 pub run_id: String,
70 /// Registered Flow type name.
71 pub flow_type: String,
72 /// Status captured by the search index.
73 pub status: FlowStatus,
74 /// Indexed start time, or `None` when unavailable.
75 pub started_at: Option<SystemTime>,
76 /// Indexed close time, or `None` while open or unavailable.
77 pub closed_at: Option<SystemTime>,
78 /// Values keyed by their physical Indexed Attribute names.
79 pub indexed_attributes: BTreeMap<String, serde_json::Value>,
80}
81
82#[derive(Clone, Debug, PartialEq)]
83/// Contains one page of [`crate::Client::search_flows`] results.
84pub struct SearchFlowsPage {
85 /// Flow rows in server-defined query order.
86 pub flows: Vec<SearchFlowEntry>,
87 /// Opaque token for [`crate::Client::search_flows_page`], or empty on the last page.
88 pub next_page_token: String,
89}