Skip to main content

hyprstream_rpc_std/
lib.rs

1//! Standard hyprstream service schemas and generated clients.
2//!
3//! This crate contains the Cap'n Proto service protocol definitions and
4//! generated client types for all standard hyprstream services (model,
5//! registry, inference, policy, mcp, etc.).
6//!
7//! The generated service client/data surface is Apache-2.0.  The
8//! `pay_client` module is a license-preserving re-export of the separately
9//! MIT-licensed `hyprstream-pay` protocol.  No AGPL service implementation is
10//! in this dependency graph. Compiles to native and wasm32.
11
12#![allow(dead_code, unused_imports)]
13
14// ============================================================================
15// Re-export shared capnp modules from hyprstream-rpc so that generated code
16// using `crate::common_capnp`, `crate::streaming_capnp`, etc. resolves
17// ============================================================================
18
19pub use hyprstream_rpc::annotations_capnp;
20pub use hyprstream_rpc::common_capnp;
21pub use hyprstream_rpc::events_capnp;
22pub use hyprstream_rpc::nine_capnp;
23pub use hyprstream_rpc::optional_capnp;
24pub use hyprstream_rpc::streaming_capnp;
25
26// ============================================================================
27// Cap'n Proto generated modules — service schemas
28// ============================================================================
29
30pub mod inference_capnp {
31    #![allow(clippy::all, clippy::unwrap_used, clippy::expect_used)]
32    #![allow(clippy::semicolon_if_nothing_returned, clippy::doc_markdown)]
33    #![allow(
34        clippy::cast_possible_truncation,
35        clippy::cast_sign_loss,
36        clippy::cast_possible_wrap
37    )]
38    include!(concat!(env!("OUT_DIR"), "/inference_capnp.rs"));
39}
40
41pub mod model_capnp {
42    #![allow(clippy::all, clippy::unwrap_used, clippy::expect_used)]
43    #![allow(clippy::semicolon_if_nothing_returned, clippy::doc_markdown)]
44    #![allow(
45        clippy::cast_possible_truncation,
46        clippy::cast_sign_loss,
47        clippy::cast_possible_wrap
48    )]
49    include!(concat!(env!("OUT_DIR"), "/model_capnp.rs"));
50}
51
52pub mod registry_capnp {
53    #![allow(clippy::all, clippy::unwrap_used, clippy::expect_used)]
54    #![allow(clippy::semicolon_if_nothing_returned, clippy::doc_markdown)]
55    #![allow(
56        clippy::cast_possible_truncation,
57        clippy::cast_sign_loss,
58        clippy::cast_possible_wrap
59    )]
60    include!(concat!(env!("OUT_DIR"), "/registry_capnp.rs"));
61}
62
63pub mod policy_capnp {
64    #![allow(clippy::all, clippy::unwrap_used, clippy::expect_used)]
65    #![allow(clippy::semicolon_if_nothing_returned, clippy::doc_markdown)]
66    #![allow(
67        clippy::cast_possible_truncation,
68        clippy::cast_sign_loss,
69        clippy::cast_possible_wrap
70    )]
71    include!(concat!(env!("OUT_DIR"), "/policy_capnp.rs"));
72}
73
74pub mod mcp_capnp {
75    #![allow(clippy::all, clippy::unwrap_used, clippy::expect_used)]
76    #![allow(clippy::semicolon_if_nothing_returned, clippy::doc_markdown)]
77    #![allow(
78        clippy::cast_possible_truncation,
79        clippy::cast_sign_loss,
80        clippy::cast_possible_wrap
81    )]
82    include!(concat!(env!("OUT_DIR"), "/mcp_capnp.rs"));
83}
84
85pub mod metrics_capnp {
86    #![allow(clippy::all, clippy::unwrap_used, clippy::expect_used)]
87    #![allow(clippy::semicolon_if_nothing_returned, clippy::doc_markdown)]
88    #![allow(
89        clippy::cast_possible_truncation,
90        clippy::cast_sign_loss,
91        clippy::cast_possible_wrap
92    )]
93    include!(concat!(env!("OUT_DIR"), "/metrics_capnp.rs"));
94}
95
96pub mod service_events_capnp {
97    #![allow(clippy::all, clippy::unwrap_used, clippy::expect_used)]
98    #![allow(clippy::semicolon_if_nothing_returned, clippy::doc_markdown)]
99    #![allow(
100        clippy::cast_possible_truncation,
101        clippy::cast_sign_loss,
102        clippy::cast_possible_wrap
103    )]
104    include!(concat!(env!("OUT_DIR"), "/service_events_capnp.rs"));
105}
106
107pub mod chat_core_capnp {
108    #![allow(clippy::all, clippy::unwrap_used, clippy::expect_used)]
109    #![allow(clippy::semicolon_if_nothing_returned, clippy::doc_markdown)]
110    #![allow(
111        clippy::cast_possible_truncation,
112        clippy::cast_sign_loss,
113        clippy::cast_possible_wrap
114    )]
115    include!(concat!(env!("OUT_DIR"), "/chat_core_capnp.rs"));
116}
117
118pub mod oauth_capnp {
119    #![allow(clippy::all, clippy::unwrap_used, clippy::expect_used)]
120    #![allow(clippy::semicolon_if_nothing_returned, clippy::doc_markdown)]
121    #![allow(
122        clippy::cast_possible_truncation,
123        clippy::cast_sign_loss,
124        clippy::cast_possible_wrap
125    )]
126    include!(concat!(env!("OUT_DIR"), "/oauth_capnp.rs"));
127}
128
129pub mod worker_capnp {
130    #![allow(clippy::all, clippy::unwrap_used, clippy::expect_used)]
131    #![allow(clippy::semicolon_if_nothing_returned, clippy::doc_markdown)]
132    #![allow(
133        clippy::cast_possible_truncation,
134        clippy::cast_sign_loss,
135        clippy::cast_possible_wrap
136    )]
137    include!(concat!(env!("OUT_DIR"), "/worker_capnp.rs"));
138}
139
140pub mod workflow_capnp {
141    #![allow(clippy::all, clippy::unwrap_used, clippy::expect_used)]
142    #![allow(clippy::semicolon_if_nothing_returned, clippy::doc_markdown)]
143    #![allow(
144        clippy::cast_possible_truncation,
145        clippy::cast_sign_loss,
146        clippy::cast_possible_wrap
147    )]
148    include!(concat!(env!("OUT_DIR"), "/workflow_capnp.rs"));
149}
150
151pub mod discovery_capnp {
152    #![allow(clippy::all, clippy::unwrap_used, clippy::expect_used)]
153    #![allow(clippy::semicolon_if_nothing_returned, clippy::doc_markdown)]
154    #![allow(
155        clippy::cast_possible_truncation,
156        clippy::cast_sign_loss,
157        clippy::cast_possible_wrap
158    )]
159    include!(concat!(env!("OUT_DIR"), "/discovery_capnp.rs"));
160}
161
162pub mod tui_capnp {
163    #![allow(clippy::all, clippy::unwrap_used, clippy::expect_used)]
164    #![allow(clippy::semicolon_if_nothing_returned, clippy::doc_markdown)]
165    #![allow(
166        clippy::cast_possible_truncation,
167        clippy::cast_sign_loss,
168        clippy::cast_possible_wrap
169    )]
170    include!(concat!(env!("OUT_DIR"), "/tui_capnp.rs"));
171}
172
173pub mod compositor_ipc_capnp {
174    #![allow(clippy::all, clippy::unwrap_used, clippy::expect_used)]
175    #![allow(clippy::semicolon_if_nothing_returned, clippy::doc_markdown)]
176    #![allow(
177        clippy::cast_possible_truncation,
178        clippy::cast_sign_loss,
179        clippy::cast_possible_wrap
180    )]
181    include!(concat!(env!("OUT_DIR"), "/compositor_ipc_capnp.rs"));
182}
183
184// ============================================================================
185// Generated client types (from proc macro)
186// Client-only: data structs, response enums, metadata. No server handlers.
187// Compiles to all targets including wasm32.
188// ============================================================================
189
190pub mod inference_client {
191    #![allow(dead_code, unused_imports, unused_variables)]
192    #![allow(clippy::all)]
193    extern crate self as hyprstream_rpc_std;
194    hyprstream_rpc_derive::generate_rpc_client!("inference");
195}
196
197pub mod model_client {
198    #![allow(dead_code, unused_imports, unused_variables)]
199    #![allow(clippy::all)]
200    extern crate self as hyprstream_rpc_std;
201    hyprstream_rpc_derive::generate_rpc_client!("model");
202}
203
204pub mod registry_client {
205    #![allow(dead_code, unused_imports, unused_variables)]
206    #![allow(clippy::all)]
207    extern crate self as hyprstream_rpc_std;
208    hyprstream_rpc_derive::generate_rpc_client!("registry");
209}
210
211pub mod policy_client {
212    #![allow(dead_code, unused_imports, unused_variables)]
213    #![allow(clippy::all)]
214    extern crate self as hyprstream_rpc_std;
215    hyprstream_rpc_derive::generate_rpc_client!("policy");
216}
217
218pub mod mcp_client {
219    #![allow(dead_code, unused_imports, unused_variables)]
220    #![allow(clippy::all)]
221    extern crate self as hyprstream_rpc_std;
222    hyprstream_rpc_derive::generate_rpc_client!("mcp");
223}
224
225pub mod metrics_client {
226    #![allow(dead_code, unused_imports, unused_variables)]
227    #![allow(clippy::all)]
228    extern crate self as hyprstream_rpc_std;
229    hyprstream_rpc_derive::generate_rpc_client!("metrics");
230}
231
232pub mod oauth_client {
233    #![allow(dead_code, unused_imports, unused_variables)]
234    #![allow(clippy::all)]
235    extern crate self as hyprstream_rpc_std;
236    hyprstream_rpc_derive::generate_rpc_client!("oauth");
237}
238
239pub mod worker_client {
240    #![allow(dead_code, unused_imports, unused_variables)]
241    #![allow(clippy::all)]
242    extern crate self as hyprstream_rpc_std;
243    hyprstream_rpc_derive::generate_rpc_client!("worker");
244}
245
246pub mod workflow_client {
247    #![allow(dead_code, unused_imports, unused_variables)]
248    #![allow(clippy::all)]
249    extern crate self as hyprstream_rpc_std;
250    hyprstream_rpc_derive::generate_rpc_client!("workflow");
251}
252
253pub mod discovery_client {
254    #![allow(dead_code, unused_imports, unused_variables)]
255    #![allow(clippy::all)]
256    extern crate self as hyprstream_rpc_std;
257    hyprstream_rpc_derive::generate_rpc_client!("discovery");
258}
259
260pub mod tui_client {
261    #![allow(dead_code, unused_imports, unused_variables)]
262    #![allow(clippy::all)]
263    extern crate self as hyprstream_rpc_std;
264    hyprstream_rpc_derive::generate_rpc_client!("tui");
265}
266
267/// Data contracts for compositor/ChatApp IPC. This schema has no RPC request
268/// union, so the generated module contains only serializable data types.
269pub mod compositor_ipc_types {
270    #![allow(dead_code, unused_imports, unused_variables)]
271    #![allow(clippy::all)]
272    extern crate self as hyprstream_rpc_std;
273    hyprstream_rpc_derive::generate_rpc_client!("compositor_ipc");
274}
275
276/// MIT settlement/tariff protocol surface.
277///
278/// This is a license-preserving re-export of `hyprstream-pay`; the AGPL
279/// settlement service remains in `hyprstream::services::pay` and is not a
280/// dependency of this SDK crate.
281pub mod pay_client {
282    pub use hyprstream_pay::{
283        attestation, capability, types, IssueRequest, IssueResponse, PayError,
284        SettlementAttestation, SettlementIssuer, TariffProvider, TariffQuote, TariffRequest,
285        UnitRef, ALL_SCOPES, ATTESTATION_V1_TAG,
286    };
287}
288
289/// Stable, discoverable imports for third-party Rust consumers. Service
290/// implementations intentionally do not re-export these client/data modules;
291/// this Apache-2.0 crate is the single public SDK surface.
292pub mod prelude {
293    pub use crate::{
294        compositor_ipc_types, discovery_client, inference_client, mcp_client, metrics_client,
295        model_client, oauth_client, pay_client, policy_client, registry_client, tui_client,
296        worker_client, workflow_client,
297    };
298    pub use hyprstream_rpc::{CallOptions, FromCapnp, RpcClient, RpcClientProvider, ToCapnp};
299}
300
301// Compile-time smoke test for the split codegen boundary.  The test module
302// deliberately generates a server surface for an existing standard schema
303// while importing its contracts from this crate; it ensures the server macro
304// cannot accidentally grow a second client/data implementation.
305#[cfg(test)]
306mod server_codegen_smoke {
307    pub mod model_server {
308        hyprstream_rpc_derive::generate_rpc_server!("model", types_crate = crate, scope_handlers);
309    }
310}
311
312#[cfg(test)]
313mod contract_compat_tests {
314    /// Schema IDs are wire identities. Keeping these assertions next to the
315    /// canonical generated modules catches an accidental schema replacement
316    /// before a client/service release can drift apart.
317    #[test]
318    fn first_party_schema_ids_are_stable() {
319        use capnp::traits::HasTypeId;
320
321        assert_eq!(
322            <crate::worker_capnp::worker_request::Reader<'static> as HasTypeId>::TYPE_ID,
323            0xbd3a_6a4e_7920_5f9c
324        );
325        assert_eq!(
326            <crate::workflow_capnp::workflow_request::Reader<'static> as HasTypeId>::TYPE_ID,
327            0x90a9_1c80_c0f0_7c3d
328        );
329        assert_eq!(
330            <crate::discovery_capnp::discovery_request::Reader<'static> as HasTypeId>::TYPE_ID,
331            0xecbd_7dea_6f0a_0715
332        );
333        assert_eq!(
334            <crate::tui_capnp::tui_request::Reader<'static> as HasTypeId>::TYPE_ID,
335            0x9e27_3fdc_e270_b381
336        );
337        assert_eq!(
338            <crate::compositor_ipc_capnp::compositor_ipc_in::Reader<'static> as HasTypeId>::TYPE_ID,
339            0x8c6b_4203_2547_6ee5
340        );
341    }
342}
343
344// ============================================================================
345// WASM exports (browser only)
346// ============================================================================
347
348// Generic codegen-driven service→9p projection (`ServiceMount`) + stream pipes.
349// Native and wasm both: the same generated dispatch drives the file surface on
350// either target. (#539 T3)
351#[cfg(any(target_arch = "wasm32", test))]
352mod browser_moq_stream;
353#[cfg(target_arch = "wasm32")]
354pub mod browser_session;
355#[cfg(any(target_arch = "wasm32", test))]
356mod federate_proof_time;
357#[cfg(any(target_arch = "wasm32", test))]
358mod model_stream_response;
359pub mod stream_mount;
360pub mod vfs_mount;
361#[cfg(target_arch = "wasm32")]
362pub mod wasm_exports;
363#[cfg(target_arch = "wasm32")]
364pub mod wasm_rpc_client;
365// Pure framing/reach-parsing for the moq worker — host-testable (not wasm-gated).
366pub mod moq_frame;
367#[cfg(target_arch = "wasm32")]
368pub mod moq_worker;
369#[cfg(target_arch = "wasm32")]
370pub mod moq_wt_session;
371
372// Phase 2: iroh peer identity + pkarr helpers exported to JavaScript.
373#[cfg(target_arch = "wasm32")]
374pub mod iroh_exports;
375
376#[cfg(all(test, not(target_arch = "wasm32")))]
377#[allow(clippy::expect_used, clippy::unwrap_used)]
378mod did_field_domain_type_tests {
379    use crate::mcp_client::CallTool;
380    use hyprstream_rpc::identity::Did;
381    use hyprstream_rpc::{serialize_message, FromCapnp, ToCapnp};
382
383    /// Field-level `$domainType("hyprstream_rpc::identity::Did")` on
384    /// `CallTool.callerIdentity` must generate a `Did` newtype field (not `String`),
385    /// and the value must round-trip through the capnp wire (which stays `Text`).
386    #[test]
387    fn call_tool_caller_identity_is_did_and_roundtrips() {
388        let original = CallTool {
389            tool_name: "model_list".to_owned(),
390            arguments: "{}".to_owned(),
391            caller_identity: Did::new("did:key:z6MkcallerExample".to_owned()),
392        };
393        // Type-level proof: the codegen emitted a `Did` field, not a `String`.
394        let _typecheck: &Did = &original.caller_identity;
395
396        let bytes = serialize_message(|msg| {
397            let mut b = msg.init_root::<crate::mcp_capnp::call_tool::Builder>();
398            original.write_to(&mut b);
399        })
400        .expect("serialize");
401
402        let reader =
403            capnp::serialize::read_message(&mut &bytes[..], capnp::message::ReaderOptions::new())
404                .expect("read message");
405        let root = reader
406            .get_root::<crate::mcp_capnp::call_tool::Reader>()
407            .expect("root reader");
408        let back = CallTool::read_from(root).expect("read_from");
409
410        assert_eq!(back.caller_identity, original.caller_identity);
411        assert_eq!(back.caller_identity.as_str(), "did:key:z6MkcallerExample");
412        assert!(back.caller_identity.is_did_key());
413        assert_eq!(back.tool_name, "model_list");
414        assert_eq!(back.arguments, "{}");
415    }
416}