Skip to main content

wire/answer/
config.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4// Copyright (c) 2026 2youg1 and the sprawling contributors
5
6//! What one address is actually governed by, and which file said so.
7
8use kernel::config::SearchConfiguration;
9use kernel::{Address, Effort, Proxying, ServerLabel};
10use serde::{Deserialize, Serialize};
11
12/// Which file settled one value.
13///
14/// **Every value in a [`ConfigAnswer`] carries one.** A settings page
15/// that was told only the resolved figure could not say whether the
16/// person is looking at their own entry, at something the building
17/// inherited, or at the city's — so pressing "reset" and pressing
18/// nothing looked the same, and the page had to climb the ladder a
19/// second time to find out. This is that answer, stated once by the
20/// layer that resolved it.
21#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
22#[serde(rename_all = "snake_case")]
23#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
24/// The rungs are named as `city::Layer` names them, and the two lists
25/// are held together by the one match that turns the city's rung into
26/// this one: a wire that called the building's file `resident` while
27/// the ladder called the room's file that is a wire whose readers
28/// disagree with the run about which file they are looking at.
29pub enum ConfigLayer {
30    /// No file states the value, and the city's built-in figure is in
31    /// force. A layer rather than an absence, so the page that draws
32    /// the value is told the figure instead of keeping a copy of it.
33    Default,
34    /// The city's own `CONFIG.toml`, which covers every building.
35    City,
36    /// The building's file, which covers every room under it.
37    Building,
38    /// The room's own file, which covers one session.
39    Resident,
40}
41
42/// `[model] effort`, and the file that settled it.
43#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
44#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
45pub struct SettledEffort {
46    pub effort: Effort,
47    pub from: ConfigLayer,
48}
49
50/// `[context] second_threshold`, and the file that settled it.
51#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
52#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
53pub struct SettledSecond {
54    /// A whole percent of the window, already taken by
55    /// `kernel::config::SecondThreshold`'s one construction point.
56    pub percent: u64,
57    pub from: ConfigLayer,
58    pub domain: SecondDomain,
59}
60
61/// The whole percents a file may state for the second rung, both ends
62/// included: the two figures `kernel::config::SecondThreshold`'s one
63/// construction point reads, answered so a page that states the span
64/// does not spell it a second time.
65#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
66#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
67pub struct SecondDomain {
68    pub min: u64,
69    pub max: u64,
70}
71
72/// What an endpoint that settled nothing is called with.
73///
74/// **These are the gateway's figures, read out rather than restated.**
75/// A form that shipped its own numbers as placeholder text would make
76/// an endpoint attached through the form and one attached by import
77/// behave differently while the person had filled in nothing; the form
78/// draws what this carries, and the numbers have one home.
79#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
80#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
81pub struct TuningDefaults {
82    /// Where these figures were stated. No file on the ladder states
83    /// them today, so this is [`ConfigLayer::Default`]; it is answered
84    /// rather than implied so a page never decides for itself that a
85    /// figure is the build's own.
86    pub from: ConfigLayer,
87    /// How long one settled request may take, in total.
88    pub timeout_ms: u64,
89    /// The ceiling on making a failed request again, as
90    /// `kernel::Retries::stated` spells it: absent is "until this city
91    /// is halted", which is what this build asks for and what no
92    /// number says. Zero is a real answer and means "once, then
93    /// report".
94    pub request_max_retries: Option<u32>,
95    /// How long a streamed answer may stay silent before the call is
96    /// abandoned. Absent means a stream is held to the same bound as a
97    /// settled call, which is the only figure this city can state
98    /// without inventing one.
99    pub stream_idle_timeout_ms: Option<u64>,
100    /// Which calls go through the machine's proxy.
101    pub proxying: Proxying,
102    /// How many more times one account is asked the same request before
103    /// the next account takes it, where an endpoint lists two or more.
104    pub account_retries: kernel::account_recovery::AccountRetries,
105}
106
107/// What one address is governed by, value by value, with the file each
108/// value came from.
109///
110/// Answered for an address rather than for the city, because the ladder
111/// has three rungs and only an address says which room's rung is in
112/// play. An address naming a building answers with two rungs climbed
113/// and no room entry, which is what a building with no open session is.
114#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
115#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
116pub struct ConfigAnswer {
117    /// The address the ladder was climbed for.
118    pub addr: Address,
119    /// How hard the model is asked to think here. Absent means no
120    /// layer stated it and the provider's own default answers, which
121    /// is a statement this city deliberately makes rather than filling
122    /// in a level nobody chose.
123    pub effort: Option<SettledEffort>,
124    /// Where the context reminder's second rung sits at this address.
125    /// Always answered: where no file states it, the figure is
126    /// `kernel::consts_policy::CTX_REMINDER_SECOND_DEFAULT` and the
127    /// layer is [`ConfigLayer::Default`].
128    pub second: SettledSecond,
129    /// Where the context reminder's first rung sits, as a whole percent
130    /// of the window: `kernel::consts_policy::CTX_REMINDER_FIRST_PERCENT`.
131    /// No layer moves it, so no layer travels with it. Always answered by
132    /// this build; absent only in a frame from a city written before it
133    /// was (`crates/wire/Spec.lean` D13).
134    #[serde(default)]
135    pub first: Option<u64>,
136    pub tuning: TuningDefaults,
137    /// Which outside service `web_search` reaches here, and what the
138    /// settings page edits (`crates/wire/spec/Answer/Config.lean` §8-86).
139    pub search: SettledSearch,
140}
141
142/// `[search]` at one address, beside the city's own statement of it.
143///
144/// The value in force and the value the page edits are answered apart:
145/// the page edits the city's file only, and a building that states its
146/// own `[search]` would otherwise hand the page the building's value to
147/// edit as the city's.
148#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
149#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
150pub struct SettledSearch {
151    /// What `web_search` reaches at this address.
152    pub configuration: SearchConfiguration,
153    /// The file that stated it; [`ConfigLayer::Default`] when none has a
154    /// `[search]` table.
155    pub from: ConfigLayer,
156    /// What the city's own file states, which is what the page edits;
157    /// absent when that file has no `[search]` table.
158    pub city: Option<SearchConfiguration>,
159    /// The address the default supplier is reached at, read from the one
160    /// place it is declared, so the page draws it without a copy.
161    pub default_url: String,
162    /// Whether each key of every supplier `city` lists is there.
163    pub account_status: Vec<SupplierAccounts>,
164}
165
166/// The key of each account of one listed search supplier.
167#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
168#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
169pub struct SupplierAccounts {
170    pub supplier: ServerLabel,
171    pub accounts: Vec<super::AccountStatus>,
172}