Skip to main content

floopy/
options.rs

1//! Gateway behaviour toggles ([`FloopyOptions`]) and per-call overrides
2//! ([`RequestOptions`]). Field names map 1:1 to the other Floopy SDKs.
3
4use std::collections::HashMap;
5use std::time::Duration;
6
7/// Cache controls. Maps to the `Floopy-Cache-*` headers. A `None` field is
8/// omitted (the gateway default applies).
9#[derive(Debug, Clone, Default)]
10pub struct CacheOptions {
11    /// Toggle the exact + semantic cache for the request.
12    pub enabled: Option<bool>,
13    /// Maximum number of entries per semantic cache bucket.
14    pub bucket_max_size: Option<u32>,
15}
16
17/// Gateway behaviour toggles, mapped to `Floopy-*` headers and forwarded to
18/// **every** request (both OpenAI-compatible and Floopy-only). Empty / `None`
19/// fields are omitted.
20#[derive(Debug, Clone, Default)]
21pub struct FloopyOptions {
22    /// Cache controls. Maps to `Floopy-Cache-*` headers.
23    pub cache: Option<CacheOptions>,
24    /// Stored prompt id; the gateway resolves it to the active prompt
25    /// content. Maps to `Floopy-Prompt-Id`.
26    pub prompt_id: Option<String>,
27    /// Pinned prompt version. Use with `prompt_id`. Maps to
28    /// `Floopy-Prompt-Version`.
29    pub prompt_version: Option<String>,
30    /// Toggle the LLM firewall pre-check. Maps to
31    /// `floopy-llm-security-enabled`.
32    pub llm_security_enabled: Option<bool>,
33}
34
35/// Per-call overrides, merged on top of the client defaults. Construct with
36/// [`RequestOptions::new`] and the builder-style setters.
37#[derive(Debug, Clone, Default)]
38pub struct RequestOptions {
39    pub(crate) headers: HashMap<String, String>,
40    pub(crate) timeout: Option<Duration>,
41    pub(crate) options: Option<FloopyOptions>,
42}
43
44impl RequestOptions {
45    /// An empty set of per-call overrides.
46    #[must_use]
47    pub fn new() -> Self {
48        Self::default()
49    }
50
51    /// Add (or replace) a single per-call header. Highest precedence.
52    #[must_use]
53    pub fn header(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
54        self.headers.insert(key.into(), value.into());
55        self
56    }
57
58    /// Override the client timeout for this call.
59    #[must_use]
60    pub fn timeout(mut self, timeout: Duration) -> Self {
61        self.timeout = Some(timeout);
62        self
63    }
64
65    /// Override the Floopy options for this call.
66    #[must_use]
67    pub fn options(mut self, options: FloopyOptions) -> Self {
68        self.options = Some(options);
69        self
70    }
71}