Skip to main content

openbutler_protocol/runtime/
view.rs

1//! Runtime view: what the active runtime offers this attachment.
2
3use serde::{Deserialize, Serialize};
4use serde_json::{Map, Value};
5
6/// Permission posture of a workspace (TS `ApprovalMode`).
7///
8/// [`ApprovalMode::Ask`] is not selectable going forward: it is accepted only
9/// when an older host reports it, and readers canonicalize it to
10/// [`ApprovalMode::Workspace`] (the TS migration rule).
11#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
12#[serde(rename_all = "kebab-case")]
13pub enum ApprovalMode {
14    Workspace,
15    AutoReview,
16    FullAccess,
17    Ask,
18}
19
20/// Which local surface owns a socket (TS `LocalClientKind`).
21#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
22#[serde(rename_all = "lowercase")]
23pub enum LocalClientKind {
24    Terminal,
25    Web,
26}
27
28/// Whether the model's reasoning is available, unsupported, or simply
29/// unmapped by the adapter (TS `ReasoningSupport`).
30#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
31#[serde(rename_all = "kebab-case")]
32pub enum ReasoningSupport {
33    Available,
34    ModelUnsupported,
35    AdapterUnmapped,
36}
37
38/// One selectable reasoning level with its provider payload
39/// (TS `ReasoningVariant`: `{id, label, providerOptions}`).
40///
41/// `providerOptions` is a namespace-keyed object whose values are themselves
42/// JSON objects (`Record<string, Record<string, JSONValue>>`); the inner
43/// objects ride as [`Value`] to keep the wire bytes identical.
44#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
45#[serde(rename_all = "camelCase")]
46pub struct ReasoningVariant {
47    pub id: String,
48    pub label: String,
49    pub provider_options: Map<String, Value>,
50}
51
52/// A display-only reasoning level reference on a saved session
53/// (`{id, label}` — no provider payload).
54#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
55#[serde(rename_all = "camelCase")]
56pub struct ReasoningLabel {
57    pub id: String,
58    pub label: String,
59}
60
61/// View of the active runtime, as sent in `snapshot` events and attach
62/// results (TS `RuntimeViewData`).
63///
64/// The TypeScript interface also carries *function* members
65/// (`saveReasoningPreference`, `saveShowReasoningPreference`,
66/// `saveApprovalModePreference`, `reportRetry`). `JSON.stringify` never emits
67/// function values, so they are absent from the wire and omitted here; serde
68/// ignores them if a peer ever sends anything under those names anyway.
69#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
70#[serde(rename_all = "camelCase")]
71pub struct RuntimeViewData {
72    #[serde(default, skip_serializing_if = "Option::is_none")]
73    pub supports_session_attachments: Option<bool>,
74    #[serde(default, skip_serializing_if = "Option::is_none")]
75    pub supports_projects: Option<bool>,
76    pub workspace_root: String,
77    pub model_name: String,
78    /// Absent until the host supplies one; readers fall back to `provider_id`.
79    #[serde(default, skip_serializing_if = "Option::is_none")]
80    pub provider_name: Option<String>,
81    pub provider_id: String,
82    pub model_id: String,
83    #[serde(deserialize_with = "Option::<i64>::deserialize")]
84    pub context_window_tokens: Option<i64>,
85    /// The head's configured compaction budget; absent means the identity
86    /// default.
87    #[serde(default, skip_serializing_if = "Option::is_none")]
88    pub custodian_context_limit_tokens: Option<i64>,
89    pub supports_vision: bool,
90    pub reasoning_variants: Vec<ReasoningVariant>,
91    #[serde(deserialize_with = "Option::<String>::deserialize")]
92    pub reasoning_metadata_source: Option<String>,
93    pub reasoning_support: ReasoningSupport,
94    /// Resolved against the runtime's model — already usable as-is.
95    pub reasoning_default: String,
96    /// The machine's raw stored preference, unresolved; each chat resolves it
97    /// against the levels its own model offers.
98    pub reasoning_preference: String,
99    pub show_reasoning_default: bool,
100    #[serde(default, skip_serializing_if = "Option::is_none")]
101    pub reasoning_titles: Option<bool>,
102    #[serde(default, skip_serializing_if = "Option::is_none")]
103    pub approval_mode: Option<ApprovalMode>,
104}