transcribe_cpp_types/streaming.rs
1//! Streaming data types: the owned option/result types a
2//! `transcribe_cpp::Stream` exchanges.
3
4use crate::family::StreamExtension;
5use crate::types::CommitPolicy;
6
7/// Options for beginning a stream.
8#[derive(Debug, Clone, PartialEq, Eq, Default)]
9#[cfg_attr(
10 feature = "serde",
11 derive(serde::Serialize, serde::Deserialize),
12 serde(default)
13)]
14pub struct StreamOptions {
15 /// When committed text grows. Default [`CommitPolicy::Auto`].
16 pub commit_policy: CommitPolicy,
17 /// Consecutive agreeing hypotheses required before a prefix commits
18 /// (stable-prefix policies). 0 selects the library default (3).
19 pub stable_prefix_agreement_n: u32,
20 /// Optional family-specific stream extension.
21 pub family: Option<StreamExtension>,
22}
23
24/// Per-call change metadata from `feed`/`finalize`.
25#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
26#[cfg_attr(
27 feature = "serde",
28 derive(serde::Serialize, serde::Deserialize),
29 serde(default)
30)]
31pub struct StreamUpdate {
32 /// Any observable property of the snapshot changed this call.
33 pub result_changed: bool,
34 /// True only on the `finalize` call's update.
35 pub is_final: bool,
36 /// Monotonic snapshot revision; diff against the previous value.
37 pub revision: i32,
38 /// Total audio received since begin (ms).
39 pub input_received_ms: i64,
40 /// Family-reported audio progress / drain hint (ms).
41 pub audio_committed_ms: i64,
42 /// Audio still buffered inside the family's streaming state (ms).
43 pub buffered_ms: i64,
44 /// `committed_text` changed this call.
45 pub committed_changed: bool,
46 /// `tentative_text` changed this call.
47 pub tentative_changed: bool,
48}
49
50/// A UI-facing snapshot of the stream's text, fully owned.
51#[derive(Debug, Clone, Default, PartialEq, Eq)]
52#[cfg_attr(
53 feature = "serde",
54 derive(serde::Serialize, serde::Deserialize),
55 serde(default)
56)]
57pub struct StreamText {
58 /// The raw current model hypothesis (authoritative; may rewrite anywhere).
59 pub full: String,
60 /// The append-only, flicker-free display/input prefix.
61 pub committed: String,
62 /// The volatile raw suffix after the committed prefix.
63 pub tentative: String,
64}
65
66impl StreamText {
67 /// `committed + tentative` — the flicker-free render most UIs want.
68 pub fn display(&self) -> String {
69 format!("{}{}", self.committed, self.tentative)
70 }
71}