Skip to main content

adk_computer_use/contracts/
lease.rs

1//! One-writer control leases and non-authoritative target reservations.
2
3use super::action::ExecutionMode;
4use serde::{Deserialize, Serialize};
5use serde_json::Value;
6
7/// One-writer desktop control lease.
8#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9#[serde(rename_all = "camelCase")]
10pub struct ControlLease {
11    /// Unique lease identifier.
12    pub lease_id: String,
13    /// Monotonic lease revision.
14    pub revision: u64,
15    /// The session that holds the lease.
16    pub session_id: String,
17    /// The principal that holds the lease.
18    pub principal_id: String,
19    /// Optional agent identifier holding the lease.
20    #[serde(skip_serializing_if = "Option::is_none")]
21    pub agent_id: Option<String>,
22    /// Lease kind (e.g. `exclusive`, `cooperative`).
23    pub kind: String,
24    /// Execution mode the lease authorizes.
25    pub execution_mode: ExecutionMode,
26    /// Lease state (e.g. `active`).
27    pub state: String,
28    /// RFC 3339 acquisition timestamp, when active.
29    #[serde(skip_serializing_if = "Option::is_none")]
30    pub acquired_at: Option<String>,
31    /// RFC 3339 expiry timestamp.
32    pub expires_at: String,
33    /// Maximum number of actions the lease permits.
34    pub action_budget: u32,
35    /// Actions used against the lease so far.
36    pub actions_used: u32,
37    /// Boundaries restricting the lease scope.
38    #[serde(default)]
39    pub boundaries: LeaseBoundaries,
40}
41
42/// App/window/display boundaries restricting a [`ControlLease`].
43#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
44#[serde(rename_all = "camelCase")]
45pub struct LeaseBoundaries {
46    /// Application/bundle identifiers within the lease scope.
47    #[serde(default)]
48    pub app_ids: Vec<String>,
49    /// Window identifiers within the lease scope.
50    #[serde(default)]
51    pub window_ids: Vec<Value>,
52    /// Display identifiers within the lease scope.
53    #[serde(default)]
54    pub display_ids: Vec<String>,
55}
56
57/// Non-authoritative, expiring planner intent for multi-agent conflict checks.
58#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
59#[serde(rename_all = "camelCase")]
60pub struct TargetReservation {
61    /// Unique reservation identifier.
62    pub reservation_id: String,
63    /// Monotonic reservation revision.
64    pub revision: u64,
65    /// The planner intent identifier this reservation serves.
66    pub intent_id: String,
67    /// The session that holds the reservation.
68    pub session_id: String,
69    /// The principal that holds the reservation.
70    pub principal_id: String,
71    /// Optional execution group for multi-agent coordination.
72    #[serde(skip_serializing_if = "Option::is_none")]
73    pub execution_group_id: Option<String>,
74    /// Optional agent identifier holding the reservation.
75    #[serde(skip_serializing_if = "Option::is_none")]
76    pub agent_id: Option<String>,
77    /// The app/window scope of the reservation.
78    pub scope: TargetReservationScope,
79    /// Reservation state (e.g. `active`).
80    pub state: String,
81    /// RFC 3339 acquisition timestamp.
82    pub acquired_at: String,
83    /// RFC 3339 expiry timestamp.
84    pub expires_at: String,
85    /// Reason the reservation reached a terminal state, when applicable.
86    #[serde(skip_serializing_if = "Option::is_none")]
87    pub terminal_reason: Option<String>,
88}
89
90/// Application/window scope of a [`TargetReservation`].
91#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
92#[serde(rename_all = "camelCase")]
93pub struct TargetReservationScope {
94    /// Application/bundle identifier.
95    pub app_id: String,
96    /// Optional window identifier.
97    #[serde(skip_serializing_if = "Option::is_none")]
98    pub window_id: Option<Value>,
99}