super-tts-shared/src/daemon/http_client/mod.rs
Line | Count | Source |
1 | | // SPDX-License-Identifier: GPL-3.0-only |
2 | | //! HTTP client for the daemon protocol: `super_engine_client::http_client`, |
3 | | //! which Super TTS shares with Super STT, plus Super TTS's own endpoints. |
4 | | //! |
5 | | //! The transport is HTTP/1.1 over the daemon's Unix socket |
6 | | //! (`super_tts_shared::validation::get_http_socket_path()`). Authentication is |
7 | | //! per-request: callers pass a session token (obtained from |
8 | | //! [`crate::daemon::session::obtain`]) and it is attached as |
9 | | //! `Authorization: Bearer <token>` on every call except [`auth_request`]. |
10 | | |
11 | | mod speak; |
12 | | |
13 | | use std::path::PathBuf; |
14 | | |
15 | | pub use speak::{speak, speak_stop}; |
16 | | pub use super_engine_client::http_client::{ |
17 | | AuthOk, AuthStatusInfo, HttpError, HttpResult, WidgetEvent, auth_request, auth_status, |
18 | | events_stream, ping, |
19 | | }; |
20 | | |
21 | | use crate::models::protocol::DaemonResponse; |
22 | | |
23 | | /// `GET /status` — current model + device. |
24 | | /// |
25 | | /// # Errors |
26 | | /// Returns an error if the daemon HTTP listener isn't reachable or the |
27 | | /// response can't be parsed. |
28 | 4 | pub async fn status(socket_path: PathBuf, token: &str) -> HttpResult<DaemonResponse> { |
29 | 4 | super_engine_client::http_client::status(socket_path, token).await |
30 | 4 | } |
31 | | |
32 | | /// Public transport surface for downstream clients that compose their own |
33 | | /// per-scope endpoint wrappers (e.g. the settings app): the engine's, plus |
34 | | /// the `settings_*` calls that read Super TTS's [`DaemonResponse`]. Returns |
35 | | /// [`HttpError`] on transport/auth failure; `401` becomes |
36 | | /// [`HttpError::InvalidSession`]. |
37 | | pub mod transport { |
38 | | use std::path::PathBuf; |
39 | | |
40 | | pub use super_engine_client::http_client::transport::*; |
41 | | |
42 | | use super::HttpResult; |
43 | | use crate::models::protocol::DaemonResponse; |
44 | | |
45 | | /// `GET <path>` → `DaemonResponse`. The standard settings read. |
46 | | /// |
47 | | /// # Errors |
48 | | /// Returns [`super::HttpError::InvalidSession`] on `401`; |
49 | | /// [`super::HttpError::Other`] on connection, HTTP, or parse failure. |
50 | 0 | pub async fn settings_get( |
51 | 0 | socket_path: PathBuf, |
52 | 0 | token: &str, |
53 | 0 | path: &str, |
54 | 0 | ) -> HttpResult<DaemonResponse> { |
55 | 0 | get_json(socket_path, token, path).await |
56 | 0 | } |
57 | | |
58 | | /// `POST <path>` with a JSON body → `DaemonResponse`. The standard |
59 | | /// settings write. |
60 | | /// |
61 | | /// # Errors |
62 | | /// Returns [`super::HttpError::InvalidSession`] on `401`; |
63 | | /// [`super::HttpError::Other`] on connection, HTTP, body encoding, or |
64 | | /// parse failure. |
65 | 0 | pub async fn settings_post( |
66 | 0 | socket_path: PathBuf, |
67 | 0 | token: &str, |
68 | 0 | path: &str, |
69 | 0 | body: &serde_json::Value, |
70 | 0 | ) -> HttpResult<DaemonResponse> { |
71 | 0 | post_json(socket_path, token, path, body).await |
72 | 0 | } |
73 | | |
74 | | /// Like [`settings_post`] but without the fixed header timeout — for a |
75 | | /// long-running write whose response the daemon only sends once the work |
76 | | /// completes (notably `POST /active_model`, a model switch that may stream |
77 | | /// multi-GB weights first). See [`post_json_no_timeout`]. |
78 | | /// |
79 | | /// # Errors |
80 | | /// Returns [`super::HttpError::InvalidSession`] on `401`; |
81 | | /// [`super::HttpError::Other`] on connection, HTTP, body encoding, or |
82 | | /// parse failure. |
83 | 0 | pub async fn settings_post_no_timeout( |
84 | 0 | socket_path: PathBuf, |
85 | 0 | token: &str, |
86 | 0 | path: &str, |
87 | 0 | body: &serde_json::Value, |
88 | 0 | ) -> HttpResult<DaemonResponse> { |
89 | 0 | post_json_no_timeout(socket_path, token, path, body).await |
90 | 0 | } |
91 | | |
92 | | /// `DELETE <path>` → `DaemonResponse`. |
93 | | /// |
94 | | /// # Errors |
95 | | /// Returns [`super::HttpError::InvalidSession`] on `401`; |
96 | | /// [`super::HttpError::Other`] on connection, HTTP, or parse failure. |
97 | 0 | pub async fn settings_delete( |
98 | 0 | socket_path: PathBuf, |
99 | 0 | token: &str, |
100 | 0 | path: &str, |
101 | 0 | ) -> HttpResult<DaemonResponse> { |
102 | 0 | delete_json(socket_path, token, path).await |
103 | 0 | } |
104 | | } |