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
//! Canonical `ureq::Agent` construction + named HTTP timeout constants.
//!
//! Before this module, `ureq::AgentBuilder::new().timeout(...).build()` was
//! inlined at 7 production sites (server_client, daemon, oci x3, upgrade x2)
//! with three of the timeouts already drifted. Worse, `cfgd/src/ai/client.rs`
//! used bare `ureq::post(...)` with no timeout at all — the Anthropic call
//! could hang the CLI indefinitely. Using these constants + `http_agent`
//! replaces every inline `Duration::from_secs(...)` literal and keeps future
//! timeout changes in one place.
use Duration;
/// Device gateway API calls (checkin, drift, enrollment) — small JSON payloads.
/// Kept short because the gateway is nearby and responses are small.
pub const HTTP_API_TIMEOUT: Duration = from_secs;
/// OCI registry blob / manifest operations (push, pull, multi-platform index).
/// Module layers and image blobs can be hundreds of MiB; 300s accommodates
/// cold caches and slow registry peers.
pub const HTTP_OCI_TIMEOUT: Duration = from_secs;
/// GitHub Releases API queries + binary archive downloads for self-upgrade.
/// 300s covers slow mirrors; the streaming download applies per-chunk.
pub const HTTP_UPGRADE_TIMEOUT: Duration = from_secs;
/// Anthropic API requests from `cfgd generate` and `cfgd ai`.
/// Claude latency for agentic tool use is normally a few seconds; 120s is a
/// ceiling for pathological slow networks. Must have *some* timeout — before
/// this constant the request had none at all.
pub const HTTP_AI_TIMEOUT: Duration = from_secs;
/// Outbound webhook notifications (drift alerts, check-in callbacks).
/// Short — the caller doesn't wait on user-visible output; a slow peer
/// should not starve the daemon's notification loop.
pub const HTTP_WEBHOOK_TIMEOUT: Duration = from_secs;
/// Build a `ureq::Agent` with `timeout` applied. Exists so every call site
/// that wants a timeout can use one line and we can change `AgentBuilder`
/// configuration (user-agent defaults, connection pooling, TLS options)
/// in exactly one place if it becomes necessary.