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
//! Palace and drawer CRUD handlers, plus status and config endpoints.
//!
//! Why: Palace and drawer operations form the core data-plane REST API. The
//! status and config endpoints are small and co-located here because they
//! read the same service layer.
//! What: `GET /api/v1/status`, `GET /api/v1/config`, the full palace CRUD
//! (`/api/v1/palaces` + `/{id}` variants), and drawer CRUD under
//! `/api/v1/palaces/{id}/drawers` (with the `/memories` alias).
//! Test: `create_then_list_palace`, `delete_palace_*`,
//! `update_palace_name_*`, `status_endpoint_returns_payload`,
//! `memories_alias_routes_to_drawers` in `web::tests`.
use ;
use ;
use ;
use crate::;
use ApiError;
use creator_info_from_http;
pub use crateStatusPayload;
/// `GET /api/v1/status` — daemon and palace summary.
///
/// Why: The admin UI header and external health tooling need a quick summary
/// of how many palaces, drawers, and KG triples exist.
/// What: delegates to `MemoryService::status()`.
/// Test: `status_endpoint_returns_payload`.
pub async
/// Wire shape for `GET /api/v1/config`.
///
/// Why: The admin UI settings panel needs to show whether an OpenRouter key
/// is configured and which model is active, without exposing the key itself.
/// What: `openrouter_configured` bool + `model` string + `data_root` path.
/// Test: Indirectly through integration; shape is stable.
pub
/// `GET /api/v1/config` — serialise the current daemon configuration.
///
/// Why: The admin UI settings panel reads this to pre-fill the configuration
/// form on load.
/// What: Loads the user config file, maps relevant fields to the response
/// struct, and returns JSON.
/// Test: Indirectly covered by integration; no dedicated unit test at this time.
pub async
pub use crateload_user_config;
pub use crateLoadedUserConfig;
pub use crate;
/// `GET /api/v1/palaces` — list user-visible palaces.
///
/// Why: The admin UI palace sidebar and the MCP tool both need a structured
/// list. Using the service layer keeps hidden palaces (`__`-prefixed) out of
/// the response automatically.
/// What: Delegates to `MemoryService::list_palaces`.
/// Test: `create_then_list_palace`.
pub async
/// `POST /api/v1/palaces` — create a new palace.
///
/// Why: The admin UI "New Palace" form and external tooling need an HTTP
/// endpoint to provision a palace directory without using MCP.
/// What: Delegates to `MemoryService::create_palace`; returns `{"id": "<id>"}`.
/// Test: `create_then_list_palace`.
pub async
/// `GET /api/v1/palaces/{id}` — fetch a single palace by id.
///
/// Why: The admin UI detail view and tooling need a way to fetch a single
/// palace without listing all palaces.
/// What: Delegates to `MemoryService::get_palace`; returns the `PalaceInfo`
/// struct as JSON.
/// Test: Covered implicitly by `create_then_list_palace`.
pub async
/// Query parameters for `DELETE /api/v1/palaces/{id}`.
///
/// Why: Issue #180 — `force=true` is the explicit opt-in to delete a
/// palace that still has drawers. Defaulting to `false` keeps the
/// "must be empty" guard active when callers omit the flag.
/// What: a single optional bool that the handler unwraps to `false`.
/// Test: `delete_palace_refuses_when_drawers_present`,
/// `delete_palace_force_removes_populated_palace`.
pub
/// `DELETE /api/v1/palaces/{id}?force=<bool>` — drop an entire palace.
///
/// Why: Issue #180 — operators need a single call to clean up a palace
/// they no longer want. The legacy drawer-by-drawer delete path is too
/// noisy and leaves the palace's KG / vector index behind.
/// What: delegates to `MemoryService::delete_palace`. Returns
/// `204 No Content` on success, `404 Not Found` when the id is unknown,
/// and `409 Conflict` when the palace still has drawers and `force` is
/// not set. Other failures bubble up as 500.
/// Test: `delete_palace_removes_dir_when_empty`,
/// `delete_palace_refuses_when_drawers_present`,
/// `delete_palace_force_removes_populated_palace`,
/// `delete_palace_returns_not_found_for_missing_id`.
pub async
/// Request body for `PATCH /api/v1/palaces/{id}`.
///
/// Why: The only mutable palace metadata exposed today is the display name;
/// keeping the body to a single field keeps the wire contract obvious and
/// lets us extend later without breaking older clients (additive fields
/// only). Issue #180 follow-up.
/// What: a single required `name` string. Empty / whitespace-only values
/// are rejected with 400 by the handler.
/// Test: `update_palace_name_renames_palace`,
/// `update_palace_name_rejects_empty_name`.
pub
/// `PATCH /api/v1/palaces/{id}` — rename a palace's display name.
///
/// Why: Issue #180 follow-up — operators need to relabel palaces without
/// re-creating them (which would lose all stored drawers / KG / vectors).
/// Only the human-readable `name` changes; the directory name (which is the
/// palace id) is immutable.
/// What: delegates to `MemoryService::update_palace_name_typed`. Returns
/// `200 OK` with the updated palace info on success, `404 Not Found` when
/// the id is unknown, and `400 Bad Request` when the supplied name is
/// empty after trimming.
/// Test: `update_palace_name_renames_palace`,
/// `update_palace_name_rejects_empty_name`,
/// `update_palace_name_returns_not_found_for_missing_id`.
pub async
// ---------------------------------------------------------------------------
// Drawers
// ---------------------------------------------------------------------------
pub use crate;
/// `GET /api/v1/palaces/{id}/drawers` — list drawers in a palace.
///
/// Why: The admin UI drawer panel and external tooling need a structured
/// list with optional filters (tags, search, pagination).
/// What: Delegates to `MemoryService::list_drawers`.
/// Test: `create_then_list_palace`, `memories_alias_routes_to_drawers`.
pub async
/// `POST /api/v1/palaces/{id}/drawers` — create a drawer in a palace.
///
/// Why: The admin UI "Add Memory" form and the `trusty-memory note` CLI
/// write via this path when callers want HTTP rather than MCP.
/// What: Delegates to `MemoryService::create_drawer`; extracts creator
/// attribution from request headers and returns `{"id": "<uuid>"}`.
/// Test: `http_create_drawer_runs_auto_kg_extraction`.
pub async
/// `DELETE /api/v1/palaces/{id}/drawers/{drawer_id}` — delete a drawer.
///
/// Why: Provides the HTTP counterpart to the MCP forget tool.
/// What: Delegates to `MemoryService::delete_drawer`; returns `204 No Content`.
/// Test: `delete_palace_force_removes_populated_palace` uses this indirectly.
pub async : ,
)