sapphire-framework-server-api 7.0.0

The methods every sapphire-framework app server serves, and their types
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
//! What a client says to an application's server, and how the server answers: the
//! framework's methods every app server serves, their parameters and their results.
//!
//! Kept apart from the rest of the framework so that its version moves only when this
//! API does. An application's own API crate depends on this one and nothing heavier;
//! a client that only talks to a server links neither the search stack nor the IPC
//! transport through it. Its types are plain serde data: the transport is
//! `sapphire-framework-ipc`, the typed client `IpcBackend` in
//! `sapphire-framework-backend`.
//!
//! A server serves one workspace at a time (#215), so no request names one: every
//! `workspace.*` and `sync.*` method acts on the server's current workspace, which
//! [`WORKSPACE_SELECT`] and [`WORKSPACE_INIT`] change, [`WORKSPACE_MOVE`] and
//! [`WORKSPACE_REMOVE`] relocate or let go of, and [`WORKSPACE_CURRENT`] reports.

#![warn(missing_docs)]

use std::path::PathBuf;

use serde::{Deserialize, Serialize};

pub use grain_id::GrainId;

/// The bridge's API, for the methods an app server relays to it ([`bridge::RELAYED`]) and
/// the types they carry, so a client needs no second dependency.
pub use sapphire_bridge_api as bridge;

/// The version of the app server's API: the framework's methods below and their types.
///
/// It is this crate's major version, parsed at compile time, so the two cannot drift: a
/// breaking change to a method, a parameter or a result here is a major release of this
/// crate, and that release is the new API version. The handshake compares this number,
/// not the framework's version, so a framework release that leaves this crate alone
/// does not demand a service restart.
///
/// 2: `workspace.list`, `workspace.forget`.
///
/// 3: search results carry `snippet` in place of `chunks` (#184).
///
/// 4: one workspace per server (#215): no `ws` parameter, `workspace.select` and
/// `workspace.current` in place of `workspace.list` and `workspace.forget`.
pub const API_VERSION: u32 = parse_major(env!("CARGO_PKG_VERSION_MAJOR"));

/// `CARGO_PKG_VERSION_MAJOR` as a number. Cargo guarantees it is decimal digits.
const fn parse_major(s: &str) -> u32 {
    let bytes = s.as_bytes();
    let mut i = 0;
    let mut n = 0u32;
    while i < bytes.len() {
        n = n * 10 + (bytes[i] - b'0') as u32;
        i += 1;
    }
    n
}

/// How a server process came to exist, as `server.info` reports it.
///
/// The same shape as `sapphire_ipc::ManagedBy`, defined here so this crate does not
/// depend on the transport.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum ManagedBy {
    /// Started by the OS service manager.
    Service,
    /// Started on demand by a client.
    Spawned,
}

/// Which retrieval strategy a search uses.
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum SearchMode {
    /// Full-text search only (BM25 / trigram).
    Fts,
    /// Semantic (vector) search only. Falls back to full text if no embedder is
    /// configured.
    Semantic,
    /// Combine full-text and semantic results via Reciprocal Rank Fusion (default).
    #[default]
    Hybrid,
}

/// One file matching a search.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct FileSearchResult {
    /// The index's id for the file. Stable only within one server's index.
    pub id: i64,
    /// The file's path, relative to the workspace root.
    pub path: String,
    /// Full text: BM25 (higher is better). Semantic: L2 distance (lower is better).
    /// Hybrid: RRF (higher is better).
    pub score: f64,
    /// A short excerpt, on one line: the match's surroundings, else the leading text.
    pub snippet: String,
}

/// Events a server publishes so a client can react without polling.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub enum BackendEvent {
    /// A sync cycle finished.
    Synced {
        /// Documents added/updated.
        upserted: usize,
        /// Documents removed.
        removed: usize,
    },
    /// A single file changed through the server.
    FileChanged {
        /// The affected path.
        path: PathBuf,
    },
    /// A single file was removed through the server.
    FileRemoved {
        /// The affected path.
        path: PathBuf,
    },
    /// A background operation failed. Carries a human-readable message.
    Error {
        /// Failure description.
        message: String,
    },
    /// Every edit this device made to the synced workspace has reached at least one peer:
    /// the peer applied it and wrote its content, so it survives this device going to sleep
    /// or away.
    ///
    /// Sent once per batch of edits, when the last of them lands, not once per peer: a second
    /// peer catching up later says nothing new. Edits made before sync started on this
    /// server are not waited for. [`SyncStatusResult::pending_delivery`] says the same thing
    /// to a client that asks instead.
    SyncDelivered {
        /// The peer that confirmed them.
        device_id: grain_id::GrainId,
        /// That peer's name, as the workgroup lists it; its id when the name is not known.
        device_name: String,
    },
}

/// Search the workspace.
pub const SEARCH: &str = "workspace.search";
/// Read a text file in full.
pub const READ_FILE: &str = "workspace.read_file";
/// Create or overwrite a text file.
pub const WRITE_FILE: &str = "workspace.write_file";
/// Append to a text file.
pub const APPEND_FILE: &str = "workspace.append_file";
/// Delete a file.
pub const DELETE_FILE: &str = "workspace.delete_file";
/// List a directory's direct children.
pub const LIST_DIR: &str = "workspace.list_dir";
/// Rebuild the index from disk.
///
/// Named `reindex`, not `sync`: `WorkspaceBackend::sync`
/// means "walk the files and update the index", which reads as peer-to-peer sync once the
/// bridge exists.
pub const REINDEX: &str = "workspace.reindex";
/// Start receiving [`EVENT`] notifications for the current workspace, and for whichever
/// workspace is current after a switch.
pub const SUBSCRIBE: &str = "workspace.subscribe";
/// Create this app's workspace home in a directory — the folder when missing, and its marker —
/// and make it the current workspace.
pub const WORKSPACE_INIT: &str = "workspace.init";
/// Make an existing workspace of this app the current one.
pub const WORKSPACE_SELECT: &str = "workspace.select";
/// Report the current workspace.
pub const WORKSPACE_CURRENT: &str = "workspace.current";
/// Move the current workspace's folder elsewhere on this host, and keep serving it there.
pub const WORKSPACE_MOVE: &str = "workspace.move";
/// Stop serving the current workspace, optionally deleting its folder.
pub const WORKSPACE_REMOVE: &str = "workspace.remove";

/// Parameters of [`WORKSPACE_MOVE`]. The result is the [`CurrentWorkspace`] at its new
/// root.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct WorkspaceMoveParams {
    /// The new root: absolute, or relative to the server's cwd. It must not exist yet;
    /// its parent must.
    pub dir: PathBuf,
}

/// Parameters of [`WORKSPACE_REMOVE`]. The result is an [`Ack`]; the server has no
/// workspace afterwards.
///
/// Sync stops for this host only: the workspace stays in the workgroup, and other
/// devices keep their copies.
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct WorkspaceRemoveParams {
    /// Also delete the workspace's folder, every file in it, and its cache.
    #[serde(default)]
    pub delete: bool,
}

/// Parameters of [`WORKSPACE_SELECT`].
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct WorkspaceSelectParams {
    /// The workspace's root: absolute, or relative to the server's cwd.
    pub dir: PathBuf,
}

/// Result of [`WORKSPACE_CURRENT`].
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct WorkspaceCurrentResult {
    /// The current workspace; `None` before one is selected.
    pub workspace: Option<CurrentWorkspace>,
}

/// The workspace a server serves, as [`WORKSPACE_CURRENT`] and [`WORKSPACE_SELECT`]
/// report it.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct CurrentWorkspace {
    /// Its root on this host.
    pub root: PathBuf,
    /// Its identity across devices, when one has been minted. Read, never minted.
    pub workspace_id: Option<grain_id::GrainId>,
    /// Whether the root still holds this application's marker directory.
    pub reachable: bool,
    /// Its replication state, as [`SYNC_STATUS`] reports it.
    pub sync: SyncStatusResult,
}

/// Parameters of [`WORKSPACE_INIT`].
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct WorkspaceInitParams {
    /// Where the workspace root goes, relative to nothing: absolute, or relative
    /// to the process's cwd, resolved by the server.
    pub dir: PathBuf,
}

/// Result of [`WORKSPACE_INIT`].
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct WorkspaceInitResult {
    /// The workspace's canonical root.
    pub root: PathBuf,
    /// The root's directory name, slugified. Nothing keys by it any more: it was the id
    /// of the `[workspace]` registry entry `workspace.init` used to write into the
    /// marker's `config.toml`, and stays for clients that print it.
    pub workspace_id: String,
    /// `false` when the workspace already existed (exit 0 either way).
    pub created: bool,
}
/// Notification carrying one [`BackendEvent`].
pub const EVENT: &str = "workspace.event";
/// What the server knows about itself.
pub const SERVER_INFO: &str = "server.info";
/// What the server last learnt about newer releases of itself: [`UpdateStatus`].
///
/// A server older than this method answers method-not-found; a client reads that as
/// "nothing known" rather than an error.
pub const SERVER_UPDATE: &str = "server.update";
/// Restart the app server in place: it answers [`Ack`], stops what it serves (HTTP, sync,
/// the update check, open connections), reads its settings again and serves anew on the
/// same endpoint, in the same process. A client reconnects to reach the new server.
///
/// A server that cannot restart itself (one not run by the framework's restarting entry
/// point) answers an error; a server older than this method answers method-not-found.
pub const SERVER_RESTART: &str = "server.restart";

/// Parameters naming a path inside the workspace.
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct PathParams {
    /// Workspace-relative path.
    pub path: PathBuf,
}

/// Parameters naming a path and the text to put there.
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct ContentParams {
    /// Workspace-relative path.
    pub path: PathBuf,
    /// The text.
    pub content: String,
}

/// Parameters of [`SEARCH`].
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct SearchParams {
    /// The query.
    pub query: String,
    /// Maximum number of files to return.
    pub limit: usize,
    /// Which retrieval strategy to use.
    #[serde(default)]
    pub mode: SearchMode,
}

/// Result of [`SEARCH`].
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct SearchResult {
    /// File-level hits, best first.
    pub hits: Vec<FileSearchResult>,
}

/// Result of [`READ_FILE`].
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct ReadResult {
    /// The file's contents.
    pub content: String,
}

/// One entry of a directory listing.
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct DirEntry {
    /// The child's path.
    pub path: PathBuf,
    /// Whether it is a directory.
    pub is_dir: bool,
}

/// Result of [`LIST_DIR`].
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct ListDirResult {
    /// The direct children.
    pub entries: Vec<DirEntry>,
}

/// Result of [`REINDEX`].
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
pub struct ReindexResult {
    /// Documents added or updated.
    pub upserted: usize,
    /// Documents removed.
    pub removed: usize,
}

/// The success payload of a method that returns nothing.
///
/// An empty object rather than `null`, so that a later release can add a field without
/// changing the shape of the response.
#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize)]
pub struct Ack {}

/// Parameters of an [`EVENT`] notification.
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct EventParams {
    /// The root of the workspace the event came from: the current one when it was sent.
    pub ws: PathBuf,
    /// What happened.
    pub event: BackendEvent,
}

#[cfg(test)]
mod tests {
    use super::*;

    fn round_trip<T>(value: &T) -> T
    where
        T: serde::Serialize + serde::de::DeserializeOwned,
    {
        serde_json::from_value(serde_json::to_value(value).unwrap()).unwrap()
    }

    #[test]
    fn search_parameters_round_trip() {
        let params = SearchParams {
            query: "hello".into(),
            limit: 10,
            mode: SearchMode::Fts,
        };
        let back = round_trip(&params);
        assert_eq!(back.query, "hello");
        assert_eq!(back.limit, 10);
        assert_eq!(back.mode, SearchMode::Fts);
    }

    #[test]
    fn every_search_mode_has_a_stable_lowercase_name() {
        for (mode, name) in [
            (SearchMode::Fts, "fts"),
            (SearchMode::Semantic, "semantic"),
            (SearchMode::Hybrid, "hybrid"),
        ] {
            assert_eq!(serde_json::to_value(mode).unwrap(), serde_json::json!(name));
            assert_eq!(
                serde_json::from_value::<SearchMode>(serde_json::json!(name)).unwrap(),
                mode
            );
        }
    }

    #[test]
    fn a_missing_mode_defaults_to_hybrid() {
        let value = serde_json::json!({ "query": "q", "limit": 5 });
        let params: SearchParams = serde_json::from_value(value).unwrap();
        assert_eq!(params.mode, SearchMode::Hybrid);
    }

    #[test]
    fn every_backend_event_round_trips() {
        for event in [
            BackendEvent::Synced {
                upserted: 3,
                removed: 1,
            },
            BackendEvent::FileChanged {
                path: PathBuf::from("a.md"),
            },
            BackendEvent::FileRemoved {
                path: PathBuf::from("b.md"),
            },
            BackendEvent::Error {
                message: "boom".into(),
            },
            BackendEvent::SyncDelivered {
                device_id: grain_id::GrainId::random(),
                device_name: "laptop".into(),
            },
        ] {
            assert_eq!(round_trip(&event), event);
        }
    }

    #[test]
    fn a_directory_listing_round_trips() {
        let listing = ListDirResult {
            entries: vec![
                DirEntry {
                    path: PathBuf::from("notes"),
                    is_dir: true,
                },
                DirEntry {
                    path: PathBuf::from("a.md"),
                    is_dir: false,
                },
            ],
        };
        let back = round_trip(&listing);
        assert_eq!(back.entries.len(), 2);
        assert!(back.entries[0].is_dir);
        assert!(!back.entries[1].is_dir);
    }

    #[test]
    fn an_ack_is_an_object_not_null() {
        assert_eq!(serde_json::to_value(Ack {}).unwrap(), serde_json::json!({}));
    }

    #[test]
    fn workspace_init_params_and_result_round_trip() {
        let params = WorkspaceInitParams {
            dir: PathBuf::from("/home/me/papers"),
        };
        let back = round_trip(&params);
        assert_eq!(back.dir, params.dir);

        let result = WorkspaceInitResult {
            root: PathBuf::from("/home/me/papers"),
            workspace_id: "g123".into(),
            created: true,
        };
        let back = round_trip(&result);
        assert_eq!(back.root, result.root);
        assert_eq!(back.workspace_id, result.workspace_id);
        assert!(back.created);
    }

    #[test]
    fn the_current_workspace_round_trips() {
        let current = CurrentWorkspace {
            root: PathBuf::from("/home/me/notes"),
            workspace_id: Some(grain_id::GrainId::random()),
            reachable: true,
            sync: SyncStatusResult::not_synced(),
        };
        let back = round_trip(&WorkspaceCurrentResult {
            workspace: Some(current.clone()),
        });
        let back = back.workspace.unwrap();
        assert_eq!(back.root, current.root);
        assert_eq!(back.workspace_id, current.workspace_id);
        assert!(
            round_trip(&WorkspaceCurrentResult::default())
                .workspace
                .is_none()
        );
        assert_eq!(
            round_trip(&WorkspaceSelectParams {
                dir: PathBuf::from("/x")
            })
            .dir,
            PathBuf::from("/x")
        );
        assert_eq!(API_VERSION, 7, "the crate's major is the API version");
    }

    #[test]
    fn method_names_are_namespaced() {
        for name in [
            SEARCH,
            READ_FILE,
            WRITE_FILE,
            APPEND_FILE,
            DELETE_FILE,
            LIST_DIR,
            REINDEX,
            SUBSCRIBE,
            WORKSPACE_INIT,
            WORKSPACE_SELECT,
            WORKSPACE_CURRENT,
            WORKSPACE_MOVE,
            WORKSPACE_REMOVE,
        ] {
            assert!(name.starts_with("workspace."), "{name}");
        }
        assert_eq!(EVENT, "workspace.event");
    }
}

/// Start syncing the current workspace.
pub const SYNC_ENABLE: &str = "sync.enable";
/// Stop syncing the current workspace. Files stay.
pub const SYNC_DISABLE: &str = "sync.disable";
/// Report the current workspace's replication state.
pub const SYNC_STATUS: &str = "sync.status";

/// Place a workspace's directory, by name or id.
pub const SYNC_MAP: &str = "sync.map";

/// Parameters of [`SYNC_MAP`]. The mapped directory becomes the current workspace.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct SyncMapParams {
    /// The workspace, by name or id, as the workgroup lists it.
    pub workspace: String,
    /// Where the workspace's root is on this host.
    pub dir: PathBuf,
}

/// Result of [`SYNC_ENABLE`].
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct SyncEnableResult {
    /// The workspace's identity across devices.
    pub workspace_id: grain_id::GrainId,
}

/// How a synced workspace is wired to its peers right now.
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Eq, Serialize)]
#[serde(tag = "kind", rename_all = "snake_case")]
pub enum Topology {
    /// Every device syncs with every other. Also the answer when no device was elected.
    #[default]
    Mesh,
    /// Devices that are neither primary nor secondary sync only with those two.
    Star {
        /// The primary device.
        primary: grain_id::GrainId,
        /// The secondary device, if there is a second candidate.
        secondary: Option<grain_id::GrainId>,
    },
}

/// Result of [`SYNC_STATUS`].
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct SyncStatusResult {
    /// Whether this workspace is synced.
    pub enabled: bool,
    /// Its identity across devices, when it is.
    pub workspace_id: Option<grain_id::GrainId>,
    /// How many other devices the workgroup has.
    pub peers: usize,
    /// Why replication is paused, if it is.
    pub paused: Option<String>,
    /// The last failure, if any.
    pub last_error: Option<String>,
    /// Whether the bridge is reachable. `false` does not mean the app server is down.
    pub bridge_available: bool,
    /// How the workspace is wired to its peers. Absent from older servers: a mesh.
    #[serde(default)]
    pub topology: Topology,
    /// How far embedding has got, when this host embeds (#188).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub embedding: Option<EmbeddingProgress>,
    /// Some edit this device made since sync started on this server has not reached any
    /// peer yet. [`BackendEvent::SyncDelivered`] is sent when it has.
    #[serde(default)]
    pub pending_delivery: bool,
    /// How many peers have a live session open that confirms what it is sent. With none, a
    /// pending edit is confirmed only by the next session's exchange — a peer from before
    /// confirmations never confirms a live push.
    #[serde(default)]
    pub acknowledging_peers: usize,
}

/// How far a workspace's embedding has got on this host.
#[derive(Clone, Debug, Default, PartialEq, Eq, Deserialize, Serialize)]
pub struct EmbeddingProgress {
    /// Documents with a vector.
    pub vectors: u64,
    /// Documents still without one.
    pub pending: u64,
    /// Whether an embedding pass is running now.
    pub running: bool,
}

impl SyncStatusResult {
    /// The state of a workspace nothing syncs.
    pub fn not_synced() -> SyncStatusResult {
        SyncStatusResult {
            enabled: false,
            workspace_id: None,
            peers: 0,
            paused: None,
            last_error: None,
            bridge_available: false,
            topology: Topology::Mesh,
            embedding: None,
            pending_delivery: false,
            acknowledging_peers: 0,
        }
    }
}

/// The typed answer to a status question, shared by the CLI and the IPC `server.info`
/// response (spec decision 4).
///
/// When a server answers, the CLI prints the framework's fields and then the
/// application's [rows](StatusReport::app) as `name: value` lines; a GUI could read the
/// same serialised shape from the IPC method instead. When nothing is listening, the
/// report is [`StatusReport::running`] = `false` and the app rows are skipped.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StatusReport {
    /// Whether a server is answering at all.
    pub running: bool,
    /// The server's version, when it is running.
    pub version: Option<String>,
    /// Its pid, when it is running.
    pub pid: Option<u32>,
    /// How the running server was started, when it is running.
    pub managed_by: Option<ManagedBy>,
    /// The application's own rows, rendered after the framework's.
    pub app: Vec<StatusRow>,
}

/// The answer to [`SERVER_UPDATE`]: whether a newer release of the running server exists.
///
/// The server only looks; it never downloads or installs anything. Installing the
/// release and restarting the server are the user's.
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct UpdateStatus {
    /// Whether the server looks for releases at all: the application named where its
    /// releases are published, and `server.toml` did not turn the check off.
    pub enabled: bool,
    /// The newest release the last successful check found, whether or not it is newer
    /// than the running server. `None` until a check has succeeded.
    pub latest: Option<ReleaseInfo>,
    /// Whether [`latest`](Self::latest) is newer than the running server.
    pub update_available: bool,
    /// Why the last check failed, when it did. A later success clears it; the last
    /// [`latest`](Self::latest) is kept meanwhile.
    pub last_error: Option<String>,
}

/// One published release, as [`UpdateStatus`] reports it.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ReleaseInfo {
    /// The release's version, without the tag's prefix: `0.20.0`.
    pub version: String,
    /// The release's web page, where its notes and downloads are.
    pub url: String,
}

/// One application-provided line of the status report.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct StatusRow {
    /// The row's name, e.g. `sync`.
    pub name: String,
    /// The value shown beside it.
    pub value: String,
}