dex_sdk/flow_info.rs
1// Copyright (c) 2026 Super Durable, Inc.
2//
3// Licensed under the Sustainable Use 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-Sustainable-Use-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}
28
29#[derive(Clone, Copy, Debug, Eq, PartialEq)]
30/// Categorizes the failure recorded for an uncompleted Flow.
31pub enum FlowErrorType {
32 /// A Step returned an invalid or failing decision.
33 StepDecisionFailed,
34 /// A client API operation failed the Flow.
35 ClientApiFailed,
36 /// A Worker Step or RPC handler failed.
37 WorkerApiFailed,
38 /// The registered Flow or Step definition violated an SDK contract.
39 InvalidUserFlowCode,
40 /// Dex encountered an internal failure.
41 Internal,
42 /// A Dex soft Flow timeout expired under the fail policy.
43 FlowTimeout,
44}
45
46#[derive(Clone, Debug, Eq, PartialEq)]
47/// Summarizes one Flow run returned by [`crate::Client::describe_flow`].
48pub struct FlowInfo {
49 /// Application-assigned Flow ID.
50 pub flow_id: String,
51 /// Server-assigned run ID for the described execution.
52 pub run_id: String,
53 /// Registered Flow type name.
54 pub flow_type: String,
55 /// Current or terminal status.
56 pub status: FlowStatus,
57 /// Server-recorded start time.
58 pub started_at: SystemTime,
59}
60
61#[derive(Clone, Debug, PartialEq)]
62/// Contains one Flow row returned by a search query.
63pub struct SearchFlowEntry {
64 /// Application-assigned Flow ID.
65 pub flow_id: String,
66 /// Server-assigned run ID.
67 pub run_id: String,
68 /// Registered Flow type name.
69 pub flow_type: String,
70 /// Status captured by the search index.
71 pub status: FlowStatus,
72 /// Indexed start time, or `None` when unavailable.
73 pub started_at: Option<SystemTime>,
74 /// Indexed close time, or `None` while open or unavailable.
75 pub closed_at: Option<SystemTime>,
76 /// Values keyed by their physical Indexed Attribute names.
77 pub indexed_attributes: BTreeMap<String, serde_json::Value>,
78}
79
80#[derive(Clone, Debug, PartialEq)]
81/// Contains one page of [`crate::Client::search_flows`] results.
82pub struct SearchFlowsPage {
83 /// Flow rows in server-defined query order.
84 pub flows: Vec<SearchFlowEntry>,
85 /// Opaque token for [`crate::Client::search_flows_page`], or empty on the last page.
86 pub next_page_token: String,
87}