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
//! `workstream.events` — the streaming method a UDS client observes one
//! workstream through (#6637).
//!
//! Why: `crate::workstreams::sse::routes` serves the same fan-out over HTTP,
//! and the TUI consumed it as SSE. The socket transport has no long-lived GET,
//! so the fan-out is registered as a
//! [`trusty_common::uds::server::RpcRouter::typed_stream`] method instead. The
//! fan-out itself is NOT reimplemented — [`crate::workstreams::sse::aggregate_live`]
//! stays the single definition of which events belong to a workstream, and
//! this module is the bridge from its `Stream` onto the router's channel.
//!
//! What: [`open`](crate::workstreams::events_stream::open) validates the id
//! and the workstream's existence exactly as
//! `workstream_events_sse` does, then forwards
//! [`crate::workstreams::WorkstreamEventEnvelope`]s until the client
//! disconnects.
//!
//! **There is no `after_seq` here, and there cannot be.** `aggregate_live` is
//! live-only by construction: a workstream has no ring buffer of its own, only
//! the per-session rings its bound sessions each hold, and those carry
//! per-session `seq` values with no workstream-wide ordering to resume from. A
//! client that reconnects re-subscribes bare and observes from that moment —
//! the same contract the HTTP route always had. `session.events`'s resume is
//! not portable to this method.
//!
//! Test: `crate::serve::uds_tests::stream_names_win_over_the_fallback` pins
//! the registration; the fan-out rules themselves are covered by `sse_tests`.
use Deserialize;
use mpsc;
use StreamExt as _;
use ;
use Uuid;
use SharedWorkstreamStore;
use WorkstreamId;
use StoreError;
/// The method name this stream is registered under.
pub const METHOD: &str = "workstream.events";
/// How many event frames may sit unwritten before the producer waits — see
/// `crate::session::events_stream`'s constant of the same name.
const CHANNEL_CAPACITY: usize = 256;
/// `workstream.events`' params.
/// Open one `workstream.events` stream.
///
/// Why/What: see module docs.
///
/// # Errors
///
/// `invalid_params` for an id that is not a UUID, and `not_found` for one that
/// names no workstream — the `400` and `404` `workstream_events_sse` answers.
/// A CLOSED workstream is observable, not an error (DOC-48 §4.4).
///
/// Test: `crate::serve::uds_tests::workstream_events_refuses_an_unknown_id`.
pub async
/// Map a [`StoreError`] onto the transport's error type.
///
/// Delegates to [`crate::workstreams::sse::map_store_err`] rather than
/// restating the taxonomy — the HTTP route and this stream must refuse an
/// unknown workstream with the same code.