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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
//! Telemetry-related record marshalling. Opaque handles wrap
//! `blazen_uniffi::telemetry::WorkflowHistoryEntry` with accessor + free
//! entry points.
//!
//! ## Ownership conventions
//!
//! `WorkflowHistoryEntry` is output-only — values come from parsing a
//! JSON-serialised `blazen_telemetry::WorkflowHistory` on the Rust side
//! (see `blazen_uniffi::telemetry::parse_workflow_history`), never
//! constructed from C. The Phase R3 wrapper around
//! `parse_workflow_history` will hand out heap-allocated
//! `BlazenWorkflowHistoryEntry` handles using
//! [`BlazenWorkflowHistoryEntry::into_ptr`]; this module exposes only
//! the readers plus a destructor.
//!
//! - String getters (`*_workflow_id`, `*_step_name`, `*_event_type`,
//! `*_event_data_json`, `*_error`) return caller-owned heap C strings.
//! Free with [`crate::string::blazen_string_free`].
//! - The `*_error` accessor returns null on the `error: None` case
//! (matching the inner `Option<String>`).
//! - `*_timestamp_ms` returns the value by `u64` directly.
//! - `*_duration_ms` returns `i64`, with `-1` as the sentinel for the
//! inner `duration_ms: None` case (mirrors
//! `blazen_error_retry_after_ms`'s `-1`-on-absent convention).
// `into_ptr` and the `From<Inner>` impl are crate-private factories used
// by the Phase R3 `parse_workflow_history` wrapper to mint handles out
// of parsed history entries. Allowing `dead_code` until that wrapper
// lands keeps clippy quiet without affecting the public extern surface.
use c_char;
use WorkflowHistoryEntry as InnerWorkflowHistoryEntry;
use cratealloc_cstring;
/// Opaque handle wrapping a `blazen_uniffi::telemetry::WorkflowHistoryEntry`.
///
/// Produced exclusively by the Rust side (the cabi `parse_workflow_history`
/// wrapper landing in Phase R3 will allocate a heap array of these).
/// Foreign callers read individual fields via the getters below and
/// release with [`blazen_workflow_history_entry_free`].
InnerWorkflowHistoryEntry);
/// Returns the history entry's `workflow_id` (UUID string of the
/// enclosing run) as a heap-allocated C string. Returns null if `entry`
/// is null.
///
/// # Ownership
///
/// Caller frees with [`crate::string::blazen_string_free`].
///
/// # Safety
///
/// `entry` must be null OR a valid pointer to a
/// `BlazenWorkflowHistoryEntry` previously produced by the cabi surface.
pub unsafe extern "C"
/// Returns the history entry's `step_name` as a heap-allocated C string.
/// The value is the step name for step- or LLM-call-scoped events and
/// the empty string for workflow-level events (mirroring the inner
/// record's plain-string field — there is no `Option<String>` here, only
/// `""`).
///
/// Returns null if `entry` is null.
///
/// # Ownership
///
/// Caller frees with [`crate::string::blazen_string_free`].
///
/// # Safety
///
/// `entry` must be null OR a valid pointer to a
/// `BlazenWorkflowHistoryEntry` previously produced by the cabi surface.
pub unsafe extern "C"
/// Returns the history entry's `event_type` variant tag (e.g.
/// `"WorkflowStarted"`, `"StepCompleted"`, `"LlmCallFailed"`) as a
/// heap-allocated C string. Returns null if `entry` is null.
///
/// # Ownership
///
/// Caller frees with [`crate::string::blazen_string_free`].
///
/// # Safety
///
/// `entry` must be null OR a valid pointer to a
/// `BlazenWorkflowHistoryEntry` previously produced by the cabi surface.
pub unsafe extern "C"
/// Returns the history entry's full `event_data_json` payload (the serde
/// JSON of the upstream `HistoryEventKind` variant) as a heap-allocated
/// C string. Returns null if `entry` is null.
///
/// # Ownership
///
/// Caller frees with [`crate::string::blazen_string_free`].
///
/// # Safety
///
/// `entry` must be null OR a valid pointer to a
/// `BlazenWorkflowHistoryEntry` previously produced by the cabi surface.
pub unsafe extern "C"
/// Returns the history entry's `timestamp_ms` (Unix-epoch milliseconds),
/// or `0` if `entry` is null.
///
/// # Safety
///
/// `entry` must be null OR a valid pointer to a
/// `BlazenWorkflowHistoryEntry` previously produced by the cabi surface.
pub unsafe extern "C"
/// Returns the history entry's `duration_ms` as an `i64`. The sentinel
/// `-1` covers the `entry == null` case AND the inner
/// `duration_ms: None` case (which the upstream record uses for events
/// that have no duration concept, e.g. `WorkflowStarted`,
/// `StepDispatched`, `LlmCallStarted`).
///
/// If the inner `duration_ms: Some(value)` exceeds `i64::MAX`, the
/// result saturates to `i64::MAX` rather than overflowing — in practice
/// no real-world duration crosses that threshold (it would represent
/// hundreds of millions of years).
///
/// # Safety
///
/// `entry` must be null OR a valid pointer to a
/// `BlazenWorkflowHistoryEntry` previously produced by the cabi surface.
pub unsafe extern "C"
/// Returns the history entry's `error` message as a heap-allocated C
/// string, or null if `entry` is null OR the inner `error: None` (i.e.
/// the event is not a failure variant).
///
/// # Ownership
///
/// Caller frees with [`crate::string::blazen_string_free`].
///
/// # Safety
///
/// `entry` must be null OR a valid pointer to a
/// `BlazenWorkflowHistoryEntry` previously produced by the cabi surface.
pub unsafe extern "C"
/// Frees a `BlazenWorkflowHistoryEntry` handle previously produced by
/// the cabi surface. No-op on a null pointer.
///
/// # Safety
///
/// `entry` must be null OR a pointer previously produced by the cabi
/// surface as a `BlazenWorkflowHistoryEntry`. Calling this twice on the
/// same non-null pointer is a double-free.
pub unsafe extern "C"