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
|
//! Contract API methods.
use serde::Serialize;
use uuid::Uuid;
use super::client::{ApiClient, ApiError};
use super::supervisor::JsonValue;
// Request types
#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ReportRequest {
pub message: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub task_id: Option<Uuid>,
}
#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CompletionActionRequest {
pub lines_added: i32,
pub lines_removed: i32,
pub has_code_changes: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub task_id: Option<Uuid>,
#[serde(skip_serializing_if = "Option::is_none")]
pub files_modified: Option<Vec<String>>,
}
#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
pub struct UpdateFileRequest {
pub content: String,
}
#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CreateFileRequest {
pub name: String,
pub content: String,
}
/// Request to update a contract.
#[derive(Serialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct UpdateContractRequest {
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
}
/// Request to create a new contract.
#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CreateContractRequest {
pub name: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub contract_type: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub initial_phase: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub autonomous_loop: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub phase_guard: Option<bool>,
}
impl ApiClient {
/// List all contracts for the authenticated user.
pub async fn list_contracts(&self) -> Result<JsonValue, ApiError> {
self.get("/api/v1/contracts").await
}
/// Create a new contract.
pub async fn create_contract(&self, req: CreateContractRequest) -> Result<JsonValue, ApiError> {
self.post("/api/v1/contracts", &req).await
}
/// Get a contract with its tasks, files, and repositories.
pub async fn get_contract(&self, contract_id: Uuid) -> Result<JsonValue, ApiError> {
self.get(&format!("/api/v1/contracts/{}", contract_id)).await
}
/// Delete a contract.
pub async fn delete_contract(&self, contract_id: Uuid) -> Result<(), ApiError> {
self.delete(&format!("/api/v1/contracts/{}", contract_id))
.await
}
/// Update a contract.
pub async fn update_contract(
&self,
contract_id: Uuid,
name: Option<String>,
description: Option<String>,
) -> Result<JsonValue, ApiError> {
let req = UpdateContractRequest { name, description };
self.put(&format!("/api/v1/contracts/{}", contract_id), &req)
.await
}
/// Get contract status.
pub async fn contract_status(&self, contract_id: Uuid) -> Result<JsonValue, ApiError> {
self.get(&format!("/api/v1/contracts/{}/daemon/status", contract_id))
.await
}
/// Get phase checklist.
pub async fn contract_checklist(&self, contract_id: Uuid) -> Result<JsonValue, ApiError> {
self.get(&format!("/api/v1/contracts/{}/daemon/checklist", contract_id))
.await
}
/// Get contract goals.
pub async fn contract_goals(&self, contract_id: Uuid) -> Result<JsonValue, ApiError> {
self.get(&format!("/api/v1/contracts/{}/daemon/goals", contract_id))
.await
}
/// List contract files.
pub async fn contract_files(&self, contract_id: Uuid) -> Result<JsonValue, ApiError> {
self.get(&format!("/api/v1/contracts/{}/daemon/files", contract_id))
.await
}
/// Get a specific file.
pub async fn contract_file(
&self,
contract_id: Uuid,
file_id: Uuid,
) -> Result<JsonValue, ApiError> {
self.get(&format!(
"/api/v1/contracts/{}/daemon/files/{}",
contract_id, file_id
))
.await
}
/// Report progress.
pub async fn contract_report(
&self,
contract_id: Uuid,
message: &str,
task_id: Option<Uuid>,
) -> Result<JsonValue, ApiError> {
let req = ReportRequest {
message: message.to_string(),
task_id,
};
self.post(&format!("/api/v1/contracts/{}/daemon/report", contract_id), &req)
.await
}
/// Get suggested action.
pub async fn contract_suggest_action(&self, contract_id: Uuid) -> Result<JsonValue, ApiError> {
self.post_empty(&format!(
"/api/v1/contracts/{}/daemon/suggest-action",
contract_id
))
.await
}
/// Get completion action recommendation.
pub async fn contract_completion_action(
&self,
contract_id: Uuid,
task_id: Option<Uuid>,
files_modified: Option<Vec<String>>,
lines_added: i32,
lines_removed: i32,
has_code_changes: bool,
) -> Result<JsonValue, ApiError> {
let req = CompletionActionRequest {
task_id,
files_modified,
lines_added,
lines_removed,
has_code_changes,
};
self.post(
&format!("/api/v1/contracts/{}/daemon/completion-action", contract_id),
&req,
)
.await
}
/// Update a file.
pub async fn contract_update_file(
&self,
contract_id: Uuid,
file_id: Uuid,
content: &str,
) -> Result<JsonValue, ApiError> {
let req = UpdateFileRequest {
content: content.to_string(),
};
self.put(
&format!("/api/v1/contracts/{}/daemon/files/{}", contract_id, file_id),
&req,
)
.await
}
/// Create a new file.
pub async fn contract_create_file(
&self,
contract_id: Uuid,
name: &str,
content: &str,
) -> Result<JsonValue, ApiError> {
let req = CreateFileRequest {
name: name.to_string(),
content: content.to_string(),
};
self.post(&format!("/api/v1/contracts/{}/daemon/files", contract_id), &req)
.await
}
/// Get task output history.
pub async fn get_task_output(&self, task_id: Uuid) -> Result<JsonValue, ApiError> {
self.get(&format!("/api/v1/mesh/tasks/{}/output", task_id))
.await
}
/// Get repository suggestions for autocomplete.
/// Returns recently used repositories sorted by usage frequency and recency.
pub async fn get_repository_suggestions(
&self,
source_type: Option<&str>,
limit: Option<i32>,
) -> Result<JsonValue, ApiError> {
let mut params = Vec::new();
if let Some(st) = source_type {
params.push(format!("source_type={}", st));
}
if let Some(l) = limit {
params.push(format!("limit={}", l));
}
let query_string = if params.is_empty() {
String::new()
} else {
format!("?{}", params.join("&"))
};
self.get(&format!("/api/v1/settings/repository-history/suggestions{}", query_string))
.await
}
/// Add a remote repository to a contract.
pub async fn add_remote_repository(
&self,
contract_id: Uuid,
name: &str,
repository_url: &str,
is_primary: bool,
) -> Result<JsonValue, ApiError> {
let req = AddRemoteRepositoryRequest {
name: name.to_string(),
repository_url: repository_url.to_string(),
is_primary,
};
self.post(&format!("/api/v1/contracts/{}/repositories/remote", contract_id), &req)
.await
}
}
#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
struct AddRemoteRepositoryRequest {
name: String,
repository_url: String,
is_primary: bool,
}
|