providers-kit 0.0.2

Portable enum-dispatch Kit over multiple model provider APIs.
Documentation
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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
//! Provider-native interactive values and the unique session handle.
//!
//! [`SessionConfig`] carries no model selector: open it through one exact
//! [`crate::ModelBackend`]. Drive [`SessionBackend::send`] and [`SessionBackend::recv`]
//! through a unique mutable Session, then consume it with [`SessionBackend::close`].
//! Provider shutdown remains shared. Ordinary multi-turn generation uses messages
//! and opaque continuation; it does not require a native Session.
//!
//! # Supplied support and a complete text turn
//!
//! The supplied Session implementation is **OpenAI-only**. Supplied Gemini,
//! Anthropic and Ollama Models return Unsupported; their stateless operations remain
//! separate. The portable trait also supports independently implemented caller
//! Sessions, as illustrated on [`crate::ProviderBackend`]. Stateless OpenAI audio
//! input is unsupported; OpenAI Realtime audio is a Session operation.
//!
//! This example requires OpenAI credentials and access to `gpt-realtime-2.1`.
//! A text turn may produce several audio and transcription events before completion.
//! Advisory usage/output is not a terminal signal; cancellation is not completion.
//! The caller applies a single turn deadline and consumes close even after a turn
//! error. Function requests would need a configured application handler and exact
//! `FunctionResult` correlation; this text-only example configures no functions.
//!
//! ```no_run
//! use std::time::Duration;
//! use providers_kit::{
//!     ModelBackend, ModelId, Provider, ProviderBackend, ProviderConfig, SessionBackend,
//! };
//! use providers_kit::config::{ApiKey, OpenAiConfig, ProviderKind, TransportConfig};
//! use providers_kit::session::{SessionConfig, SessionEvent, SessionInput};
//! # #[tokio::main(flavor = "current_thread")]
//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let provider = Provider::from_config(ProviderConfig::new(
//!     ProviderKind::OpenAi(OpenAiConfig::new(ApiKey::new("replace-with-your-key")?)),
//!     TransportConfig::default(),
//! ))?;
//! let work = async {
//!     let model = provider.model(ModelId::new("gpt-realtime-2.1")?)?;
//!     let config = SessionConfig::default().with_output_audio("audio/pcm;rate=24000", true)?;
//!     let mut session = model.open_session(config).await?;
//!     let turn = tokio::time::timeout(Duration::from_secs(90), async {
//!         session.send(SessionInput::Text { text: "Describe one use of a bicycle.".into() }).await?;
//!         let mut audio_bytes = 0usize;
//!         let mut transcript_bytes = 0usize;
//!         let mut substantive_transcript = false;
//!         loop {
//!             match session.recv().await? {
//!                 SessionEvent::Audio { data, .. } => audio_bytes += data.len(),
//!                 SessionEvent::OutputTranscriptionDelta { delta } => {
//!                     transcript_bytes += delta.len();
//!                     substantive_transcript |= !delta.trim().is_empty();
//!                 }
//!                 SessionEvent::Completed => break,
//!                 SessionEvent::TurnCancelled | SessionEvent::FunctionCall(_)
//!                 | SessionEvent::FunctionCallsCancelled { .. } => return Err("unexpected control event".into()),
//!                 SessionEvent::TextDelta { .. } | SessionEvent::InputTranscriptionDelta { .. }
//!                 | SessionEvent::Usage(_) => {}
//!             }
//!             if audio_bytes > 8 * 1024 * 1024 || transcript_bytes > 1024 * 1024 {
//!                 return Err("example output bound exceeded".into());
//!             }
//!         }
//!         if audio_bytes == 0 || !substantive_transcript { return Err("missing output".into()); }
//!         Ok::<(), Box<dyn std::error::Error>>(())
//!     }).await;
//!     let closed = session.close().await;
//!     if let Err(error) = &closed {
//!         eprintln!("Cleanup failed: {error}");
//!     }
//!     turn??;
//!     closed?;
//!     Ok::<(), Box<dyn std::error::Error>>(())
//! }.await;
//! let shutdown = provider.shutdown().await;
//! if let Err(error) = &shutdown {
//!     eprintln!("Cleanup failed: {error}");
//! }
//! work?;
//! shutdown?;
//! # Ok(())
//! # }
//! ```
//!
//! For manual audio, send `TurnStart`, one or more raw `Audio` chunks in the exact
//! configured format, then `TurnEnd`; receive until a native terminal event. A raw
//! chunk is not a whole-turn or automatic flush operation. Output wording is
//! model-authored, not a Kit exact-copy guarantee.

use std::collections::BTreeSet;
use std::convert::Infallible;
use std::fmt;
use std::future::Future;
use std::sync::Arc;

use reqwest::multipart::Part;
use serde::{Deserialize, Serialize};

use crate::KitError;
use crate::core::filter_tools_for_choice;
use crate::error::Operation;
use crate::error::ValidationViolation;
use crate::generation::{
    FunctionCall, FunctionResult, ProviderFunctionTool, ProviderToolSpec, ToolChoice, Usage,
};
use crate::models::ModelId;
use crate::provider::ProviderRuntime;
use crate::providers::openai::OpenAiSession;

/// Defaults applied to one provider-native interactive session.
///
/// Configuration is passive. Select the exact model first and call
/// [`crate::ModelBackend::open_session`] only when native sessions are supported.
///
/// # Examples
///
/// ```
/// use providers_kit::session::SessionConfig;
/// let config = SessionConfig::default().with_instructions("Answer briefly")?;
/// assert_eq!(config.instructions(), Some("Answer briefly"));
///
/// # Ok::<(), providers_kit::KitError>(())
/// ```
///
#[derive(Clone, Debug, PartialEq)]
pub struct SessionConfig {
    instructions: Option<String>,
    input_audio: Option<(String, bool)>,
    output_audio: Option<(String, bool)>,
    turn_detection: SessionTurnDetection,
    functions: Vec<ProviderFunctionTool>,
    tool_choice: Option<ToolChoice>,
}

impl Default for SessionConfig {
    fn default() -> Self {
        Self {
            instructions: None,
            input_audio: None,
            output_audio: None,
            turn_detection: SessionTurnDetection::Automatic,
            functions: Vec::new(),
            tool_choice: None,
        }
    }
}

impl SessionConfig {
    /// Sets nonblank text instructions for the session.
    ///
    /// # Errors
    ///
    /// Returns an input error for empty or whitespace-only instructions.
    ///
    /// See [`crate::session::SessionConfig`] for a complete example.
    ///
    pub fn with_instructions(mut self, instructions: impl Into<String>) -> Result<Self, KitError> {
        let instructions = instructions.into();
        if instructions.trim().is_empty() {
            return Err(KitError::invalid_input(
                ValidationViolation::Empty {
                    field: "session.instructions",
                },
                "interactive session instructions must not be blank",
            ));
        }
        self.instructions = Some(instructions);
        Ok(self)
    }

    /// Enables audio input with an exact IANA media type.
    ///
    /// # Errors
    ///
    /// Returns an input error unless the value is an unpadded valid IANA audio media type without control characters. Exact format/model support is checked on session opening.
    ///
    /// # Examples
    ///
    /// ```
    /// use providers_kit::session::SessionConfig;
    /// let config = SessionConfig::default().with_input_audio("audio/pcm", true)?;
    /// assert_eq!(config.input_audio_format(), Some("audio/pcm"));
    /// assert!(config.input_transcription());
    ///
    /// # Ok::<(), providers_kit::KitError>(())
    /// ```
    ///
    pub fn with_input_audio(
        mut self,
        media_type: impl Into<String>,
        transcription: bool,
    ) -> Result<Self, KitError> {
        self.input_audio = Some((
            Self::validate_audio_format(media_type.into())?,
            transcription,
        ));
        Ok(self)
    }

    /// Enables audio output with an exact IANA media type.
    ///
    /// # Errors
    ///
    /// Returns an input error unless the value is an unpadded valid IANA audio media type without control characters. Exact format/model support is checked on session opening.
    ///
    /// # Examples
    ///
    /// ```
    /// use providers_kit::session::SessionConfig;
    /// let config = SessionConfig::default().with_output_audio("audio/pcm", true)?;
    /// assert_eq!(config.output_audio_format(), Some("audio/pcm"));
    /// assert!(config.output_transcription());
    ///
    /// # Ok::<(), providers_kit::KitError>(())
    /// ```
    ///
    pub fn with_output_audio(
        mut self,
        media_type: impl Into<String>,
        transcription: bool,
    ) -> Result<Self, KitError> {
        self.output_audio = Some((
            Self::validate_audio_format(media_type.into())?,
            transcription,
        ));
        Ok(self)
    }

    /// Selects provider-managed or caller-managed turn boundaries.
    ///
    /// # Examples
    ///
    /// ```
    /// use providers_kit::session::{SessionConfig, SessionTurnDetection};
    /// let config = SessionConfig::default().with_turn_detection(SessionTurnDetection::Manual);
    /// assert_eq!(config.turn_detection(), SessionTurnDetection::Manual);
    /// ```
    ///
    #[must_use]
    pub const fn with_turn_detection(mut self, turn_detection: SessionTurnDetection) -> Self {
        self.turn_detection = turn_detection;
        self
    }

    /// Sets the client functions available throughout the session.
    ///
    /// # Errors
    ///
    /// Returns an input error for duplicate functions, required tool choice with an empty inventory, or a selection that cannot be resolved against the supplied functions.
    ///
    /// # Examples
    ///
    /// ```
    /// use providers_kit::generation::{ProviderFunctionTool, JsonSchema};
    /// let tool = ProviderFunctionTool::new(
    ///     "lookup",
    ///     Some("Find a record".into()),
    ///     JsonSchema::new(serde_json::json!({"type":"object"}))?,
    /// )?;
    /// use providers_kit::{session::SessionConfig, generation::ToolChoice};
    /// let config = SessionConfig::default().with_functions(vec![tool], Some(ToolChoice::Auto))?;
    /// assert_eq!(config.functions()[0].name(), "lookup");
    /// assert_eq!(config.tool_choice(), Some(&ToolChoice::Auto));
    ///
    /// # Ok::<(), providers_kit::KitError>(())
    /// ```
    ///
    pub fn with_functions(
        mut self,
        functions: Vec<ProviderFunctionTool>,
        tool_choice: Option<ToolChoice>,
    ) -> Result<Self, KitError> {
        let mut names = BTreeSet::new();
        for function in &functions {
            if !names.insert(function.name()) {
                return Err(KitError::invalid_input(
                    ValidationViolation::Duplicate {
                        field: "session.functions.name",
                    },
                    format!(
                        "interactive function name `{}` is duplicated",
                        function.name()
                    ),
                ));
            }
        }
        if functions.is_empty()
            && matches!(
                tool_choice.as_ref(),
                Some(ToolChoice::Required | ToolChoice::Any)
            )
        {
            return Err(KitError::invalid_input(
                ValidationViolation::MissingField {
                    field: "session.functions",
                },
                "interactive required tool choice needs at least one function",
            ));
        }
        let specs = functions
            .iter()
            .cloned()
            .map(ProviderToolSpec::Function)
            .collect::<Vec<_>>();
        filter_tools_for_choice(&specs, tool_choice.as_ref())?;
        self.functions = functions;
        self.tool_choice = tool_choice;
        Ok(self)
    }

    /// Returns the session instructions, when configured.
    ///
    /// See [`crate::session::SessionConfig`] for a complete example.
    ///
    #[must_use]
    pub fn instructions(&self) -> Option<&str> {
        self.instructions.as_deref()
    }

    /// Returns the required input-audio media type, when enabled.
    ///
    /// See [`crate::session::SessionConfig::with_input_audio`] for a complete example.
    ///
    #[must_use]
    pub fn input_audio_format(&self) -> Option<&str> {
        self.input_audio
            .as_ref()
            .map(|(media_type, _)| media_type.as_str())
    }

    /// Returns the requested output-audio media type, when enabled.
    ///
    /// See [`crate::session::SessionConfig::with_output_audio`] for a complete example.
    ///
    #[must_use]
    pub fn output_audio_format(&self) -> Option<&str> {
        self.output_audio
            .as_ref()
            .map(|(media_type, _)| media_type.as_str())
    }

    /// Reports whether input transcription was requested.
    ///
    /// See [`crate::session::SessionConfig::with_input_audio`] for a complete example.
    ///
    #[must_use]
    pub fn input_transcription(&self) -> bool {
        self.input_audio
            .as_ref()
            .is_some_and(|(_, transcription)| *transcription)
    }

    /// Reports whether output transcription was requested.
    ///
    /// See [`crate::session::SessionConfig::with_output_audio`] for a complete example.
    ///
    #[must_use]
    pub fn output_transcription(&self) -> bool {
        self.output_audio
            .as_ref()
            .is_some_and(|(_, transcription)| *transcription)
    }

    /// Returns the configured turn-boundary policy.
    ///
    /// See [`crate::session::SessionConfig::with_turn_detection`] for a complete example.
    ///
    #[must_use]
    pub const fn turn_detection(&self) -> SessionTurnDetection {
        self.turn_detection
    }

    /// Returns the client functions available to the session.
    ///
    /// See [`crate::session::SessionConfig::with_functions`] for a complete example.
    ///
    #[must_use]
    pub fn functions(&self) -> &[ProviderFunctionTool] {
        &self.functions
    }

    /// Returns the configured function-selection policy.
    ///
    /// See [`crate::session::SessionConfig::with_functions`] for a complete example.
    ///
    #[must_use]
    pub const fn tool_choice(&self) -> Option<&ToolChoice> {
        self.tool_choice.as_ref()
    }

    fn validate_audio_format(media_type: String) -> Result<String, KitError> {
        if !media_type.starts_with("audio/")
            || media_type.trim() != media_type
            || media_type.chars().any(char::is_control)
            || Part::bytes(Vec::new()).mime_str(&media_type).is_err()
        {
            return Err(KitError::invalid_input(
                ValidationViolation::InvalidFormat {
                    field: "session.audio_format",
                    rule: "unpadded IANA audio media type",
                },
                "interactive audio format must be an unpadded IANA audio media type",
            ));
        }
        Ok(media_type)
    }
}

/// Portable interactive audio turn detection.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum SessionTurnDetection {
    /// Provider-managed boundaries.
    #[default]
    Automatic,
    /// Caller-managed boundaries.
    Manual,
}

/// Input sent to an interactive session.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case", deny_unknown_fields)]
pub enum SessionInput {
    /// One complete text turn.
    Text {
        /// Nonblank caller text.
        text: String,
    },
    /// One raw audio chunk in the configured input format.
    Audio {
        /// Exact media type configured for session input.
        media_type: String,
        /// Raw, unencoded audio bytes.
        #[serde(with = "crate::core::content::base64_bytes")]
        data: Vec<u8>,
    },
    /// A completed client-function result.
    FunctionResult(FunctionResult),
    /// Starts a caller-managed audio turn.
    TurnStart,
    /// Ends caller-managed audio input or, where supported, explicitly ends
    /// the currently submitted automatic-audio segment.
    ///
    /// The supplied OpenAI backend requires manual turn detection.
    /// This input does not complete or cancel the provider response.
    TurnEnd,
    /// Cancels the active provider response when supported.
    CancelTurn,
}

/// Event received from an interactive session.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(tag = "event", rename_all = "snake_case", deny_unknown_fields)]
pub enum SessionEvent {
    /// Incremental model text.
    TextDelta {
        /// Newly received text.
        delta: String,
    },
    /// Raw model audio in its declared media type.
    Audio {
        /// Provider-declared audio media type.
        media_type: String,
        /// Raw, decoded audio bytes.
        #[serde(with = "crate::core::content::base64_bytes")]
        data: Vec<u8>,
    },
    /// Incremental transcription of caller audio.
    InputTranscriptionDelta {
        /// Newly transcribed caller text.
        delta: String,
    },
    /// Incremental transcription of model audio.
    OutputTranscriptionDelta {
        /// Newly transcribed model text.
        delta: String,
    },
    /// Client function requested by the model.
    FunctionCall(FunctionCall),
    /// Provider-cancelled client-function calls.
    FunctionCallsCancelled {
        /// Provider correlation identifiers for the cancelled calls.
        call_ids: Vec<String>,
    },
    /// Usage update.
    Usage(Usage),
    /// The active model turn was interrupted or cancelled.
    TurnCancelled,
    /// Current interactive turn completed.
    Completed,
}

/// Public implementation contract for one unique provider-native session.
///
/// Caller models return their concrete session implementation directly through
/// [`crate::ModelBackend::Session`].
///
/// Sessions are unique, mutable, and non-Clone. Consuming close settles
/// the session transport; the Provider retains separate shared shutdown authority.
/// Ordinary multi-turn generation instead uses messages and continuation.
///
/// See the [complete native turn](crate::session) for service setup and cleanup,
/// or [`crate::ProviderBackend`] for an executable caller-owned session.
///
pub trait SessionBackend: Send + 'static {
    /// Stable session identifier.
    ///
    /// See [`crate::SessionBackend`] for a complete example.
    ///
    fn id(&self) -> &str;
    /// Exact selected model.
    ///
    /// See [`crate::SessionBackend`] for a complete example.
    ///
    fn model_id(&self) -> &ModelId;
    /// Sends interactive input.
    ///
    /// # Errors
    ///
    /// Returns the owning input, unsupported, closed, transport, deadline, service-rejection, or protocol error.
    ///
    /// See the [complete session turn](crate::session) for bounded observation and cleanup.
    ///
    fn send(
        &mut self,
        input: SessionInput,
    ) -> impl Future<Output = Result<(), KitError>> + Send + '_;
    /// Receives the next interactive event.
    ///
    /// A delta or usage event does not finish the turn. Continue receiving until
    /// its terminal event, as in the [complete session turn](crate::session).
    ///
    /// # Errors
    ///
    /// Returns the owning input, unsupported, closed, transport, deadline, service-rejection, or protocol error.
    ///
    /// See the [complete session turn](crate::session) for bounded observation and cleanup.
    ///
    fn recv(&mut self) -> impl Future<Output = Result<SessionEvent, KitError>> + Send + '_;
    /// Closes the unique session and its transport.
    ///
    /// Consuming close does not make the session reusable, even when it fails.
    ///
    /// # Errors
    ///
    /// Returns the owning input, unsupported, closed, transport, deadline, service-rejection, or protocol error.
    ///
    /// See the [complete session turn](crate::session) for bounded observation and cleanup.
    ///
    fn close(self) -> impl Future<Output = Result<(), KitError>> + Send;
}

impl SessionBackend for Infallible {
    fn id(&self) -> &str {
        match *self {}
    }

    fn model_id(&self) -> &ModelId {
        match *self {}
    }

    async fn send(&mut self, _input: SessionInput) -> Result<(), KitError> {
        match *self {}
    }

    async fn recv(&mut self) -> Result<SessionEvent, KitError> {
        match *self {}
    }

    async fn close(self) -> Result<(), KitError> {
        match self {}
    }
}

pub(crate) enum SessionInner {
    OpenAi(OpenAiSession),
}

/// Unique opaque provider-native interactive session supplied for OpenAI models.
///
/// Sessions are unique, mutable, and non-Clone. Consuming close settles
/// the session transport; the Provider retains separate shared shutdown authority.
/// Ordinary multi-turn generation instead uses messages and continuation.
///
/// See [`crate::SessionBackend`] for a complete example.
///
pub struct Session {
    inner: SessionInner,
    provider: Arc<ProviderRuntime>,
}

impl Session {
    pub(crate) fn new(inner: SessionInner, provider: Arc<ProviderRuntime>) -> Self {
        Self { inner, provider }
    }
}

impl SessionBackend for SessionInner {
    fn id(&self) -> &str {
        match self {
            Self::OpenAi(session) => session.id(),
        }
    }

    fn model_id(&self) -> &ModelId {
        match self {
            Self::OpenAi(session) => session.model_id(),
        }
    }

    async fn send(&mut self, input: SessionInput) -> Result<(), KitError> {
        match self {
            Self::OpenAi(session) => session.send(input).await,
        }
    }

    async fn recv(&mut self) -> Result<SessionEvent, KitError> {
        match self {
            Self::OpenAi(session) => session.recv().await,
        }
    }

    async fn close(self) -> Result<(), KitError> {
        match self {
            Self::OpenAi(session) => session.close().await,
        }
    }
}

impl SessionBackend for Session {
    fn id(&self) -> &str {
        self.inner.id()
    }

    fn model_id(&self) -> &ModelId {
        self.inner.model_id()
    }

    async fn send(&mut self, input: SessionInput) -> Result<(), KitError> {
        let _admission = self.provider.admit(Operation::SessionSend)?;
        self.inner
            .send(input)
            .await
            .map_err(|error| error.at_operation(Operation::SessionSend))
    }

    async fn recv(&mut self) -> Result<SessionEvent, KitError> {
        let _admission = self.provider.admit(Operation::SessionReceive)?;
        self.inner
            .recv()
            .await
            .map_err(|error| error.at_operation(Operation::SessionReceive))
    }

    async fn close(self) -> Result<(), KitError> {
        self.inner
            .close()
            .await
            .map_err(|error| error.at_operation(Operation::SessionClose))
    }
}

impl fmt::Debug for Session {
    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
        formatter
            .debug_struct("Session")
            .field("id", &self.id())
            .field("model_id", &self.model_id())
            .finish()
    }
}