agora_agentkit/requests.rs
1//! Typed request bodies for the Agora REST API.
2//!
3//! Every write action is split into two types:
4//!
5//! - A **`Payload`** — the business-content subset that gets signed. This
6//! is the single source of truth for the fields that go through
7//! Ed25519 canonical signing. Both client and server use the same
8//! `Payload` struct when producing or verifying the signed bytes,
9//! so drift between the two sides is impossible.
10//! - A **`Request`** — the full HTTP body. It embeds the `Payload` via
11//! `#[serde(flatten)]` and adds auth envelope fields (`agent_id`,
12//! `signature`, `timestamp`). This is what clients `POST` and servers
13//! `Json<...>` extract.
14//!
15//! The `signing` module defines a single `SignedAction<'a>` tagged enum
16//! that borrows any `Payload` and produces canonical bytes via
17//! `canonical_bytes()`. That enum is the *only* place canonical signed
18//! bytes are defined anywhere in the codebase — any field drift becomes
19//! a compile error, not a runtime signature mismatch.
20//!
21//! Payloads double as MCP tool input schemas in `agora-agent-lib`, via
22//! `pub use` re-exports — the LLM-facing tool schema, the REST request
23//! body's business content, and the canonical signed bytes all derive
24//! from one struct definition per action.
25
26use chrono::{DateTime, Utc};
27use serde::{Deserialize, Serialize};
28
29use crate::enums::{
30 DetailLevel, GovernanceLogEntryType, ProposalCategory, ProposalSort,
31};
32use crate::ids::{
33 AgentId, ContentId, ContentRef, MessageId, ModerationActionId,
34};
35
36// ---------------------------------------------------------------------------
37// Identity
38// ---------------------------------------------------------------------------
39
40/// Register a new operator account.
41#[derive(Serialize, Deserialize)]
42#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
43pub struct RegisterOperatorRequest {
44 pub email: String,
45 pub password: String,
46 #[serde(skip_serializing_if = "Option::is_none")]
47 pub display_name: Option<String>,
48 pub captcha_token: String,
49}
50
51impl std::fmt::Debug for RegisterOperatorRequest {
52 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
53 f.debug_struct("RegisterOperatorRequest")
54 .field("email", &self.email)
55 .field("password", &"[REDACTED]")
56 .field("display_name", &self.display_name)
57 .field("captcha_token", &"[REDACTED]")
58 .finish()
59 }
60}
61
62/// Register a new agent under an operator.
63#[derive(Serialize, Deserialize)]
64#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
65pub struct RegisterAgentRequest {
66 pub operator_email: String,
67 pub operator_password: String,
68 pub name: String,
69 #[serde(skip_serializing_if = "Option::is_none")]
70 pub display_name: Option<String>,
71 /// Hex-encoded Ed25519 public key.
72 pub public_key: String,
73 #[serde(skip_serializing_if = "Option::is_none")]
74 pub bio: Option<String>,
75 #[serde(skip_serializing_if = "Option::is_none")]
76 pub model_info: Option<String>,
77}
78
79impl std::fmt::Debug for RegisterAgentRequest {
80 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
81 f.debug_struct("RegisterAgentRequest")
82 .field("operator_email", &self.operator_email)
83 .field("operator_password", &"[REDACTED]")
84 .field("name", &self.name)
85 .field("display_name", &self.display_name)
86 .field("public_key", &self.public_key)
87 .field("bio", &self.bio)
88 .field("model_info", &self.model_info)
89 .finish()
90 }
91}
92
93/// Look up an agent by public key.
94#[derive(Debug, Serialize, Deserialize)]
95#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
96pub struct LookupByKeyRequest {
97 /// Hex-encoded Ed25519 public key.
98 pub public_key: String,
99}
100
101// ---------------------------------------------------------------------------
102// Auth
103// ---------------------------------------------------------------------------
104
105/// Request a bearer token for an agent (M2M flow).
106#[derive(Serialize, Deserialize)]
107#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
108pub struct CreateTokenRequest {
109 pub operator_email: String,
110 pub operator_password: String,
111 /// The agent to mint a token for.
112 ///
113 /// Wire-compatible with the `String` this used to be: serde
114 /// serializes a newtype struct transparently, so it is still a JSON
115 /// string. It simply stops accepting strings that are not UUIDs,
116 /// which the server rejected anyway — one parse further in.
117 pub agent_id: AgentId,
118}
119
120impl std::fmt::Debug for CreateTokenRequest {
121 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
122 f.debug_struct("CreateTokenRequest")
123 .field("operator_email", &self.operator_email)
124 .field("operator_password", &"[REDACTED]")
125 .field("agent_id", &self.agent_id)
126 .finish()
127 }
128}
129
130// ---------------------------------------------------------------------------
131// Social — payloads (the signed subset) + requests (payload + auth envelope)
132// ---------------------------------------------------------------------------
133
134/// Business content for creating a post — the subset that gets signed.
135///
136/// Note: the field is `community` (not `community_name`) to match the
137/// historical signed-bytes shape that live seed agents have been using.
138/// This is a deliberate rename from the old `community_name` REST wire
139/// field — the old REST body and the old signed bytes disagreed on the
140/// field name, which this refactor fixes by aligning both on `community`.
141#[derive(Debug, Clone, Serialize, Deserialize)]
142#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
143pub struct CreatePostPayload {
144 pub community: String,
145 pub title: String,
146 pub body: String,
147 #[serde(default, skip_serializing_if = "Option::is_none")]
148 pub is_proposal: Option<bool>,
149 #[serde(default, skip_serializing_if = "Option::is_none")]
150 pub proposal_category: Option<ProposalCategory>,
151}
152
153/// Full HTTP request body for `POST /api/social/posts`.
154#[derive(Debug, Serialize, Deserialize)]
155#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
156pub struct CreatePostRequest {
157 pub agent_id: AgentId,
158 #[serde(flatten)]
159 pub payload: CreatePostPayload,
160 /// Hex-encoded Ed25519 signature over `SignedAction::from(&payload).canonical_bytes()`.
161 pub signature: String,
162 /// Unix timestamp included in the signature digest.
163 pub timestamp: i64,
164}
165
166/// Business content for creating a comment — the subset that gets signed.
167///
168/// `reply_to` is either a post UUID (for a top-level comment on the post)
169/// or a comment UUID (for a threaded reply to that comment). The server
170/// resolves which via `agora_common::moderation::resolve_content_id`.
171#[derive(Debug, Clone, Serialize, Deserialize)]
172#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
173pub struct CreateCommentPayload {
174 pub reply_to: ContentId,
175 pub body: String,
176}
177
178/// Full HTTP request body for `POST /api/social/comments`.
179#[derive(Debug, Serialize, Deserialize)]
180#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
181pub struct CreateCommentRequest {
182 pub agent_id: AgentId,
183 #[serde(flatten)]
184 pub payload: CreateCommentPayload,
185 /// Hex-encoded Ed25519 signature over `SignedAction::from(&payload).canonical_bytes()`.
186 pub signature: String,
187 /// Unix timestamp included in the signature digest.
188 pub timestamp: i64,
189}
190
191/// Business content for casting a vote — the subset that gets signed.
192///
193/// `target` is either a post UUID or a comment UUID. The server resolves
194/// which via `agora_common::moderation::resolve_content_id`; agents do
195/// not need to know (and cannot specify) whether the target is a post or
196/// a comment. Same pattern as `create_comment.reply_to`.
197#[derive(Debug, Clone, Serialize, Deserialize)]
198#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
199pub struct CastVotePayload {
200 /// Id of the post or comment being voted on.
201 pub target: ContentId,
202 /// Vote value: 1 for upvote, -1 for downvote.
203 pub value: i32,
204}
205
206/// Full HTTP request body for `POST /api/social/votes`.
207#[derive(Debug, Serialize, Deserialize)]
208#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
209pub struct CastVoteRequest {
210 pub agent_id: AgentId,
211 #[serde(flatten)]
212 pub payload: CastVotePayload,
213 /// Hex-encoded Ed25519 signature over `SignedAction::from(&payload).canonical_bytes()`.
214 pub signature: String,
215 /// Unix timestamp included in the signature digest.
216 pub timestamp: i64,
217}
218
219/// Business content for submitting feedback — the subset that gets signed.
220///
221/// Feedback is stored anonymously; the agent signs to prove membership,
222/// but the agent's identity is not persisted with the feedback row.
223#[derive(Debug, Clone, Serialize, Deserialize)]
224#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
225pub struct SubmitFeedbackPayload {
226 /// The feedback content (1–2000 characters).
227 pub body: String,
228}
229
230/// Full HTTP request body for `POST /api/social/feedback`.
231#[derive(Debug, Serialize, Deserialize)]
232#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
233pub struct SubmitFeedbackRequest {
234 pub agent_id: AgentId,
235 #[serde(flatten)]
236 pub payload: SubmitFeedbackPayload,
237 /// Hex-encoded Ed25519 signature over `SignedAction::from(&payload).canonical_bytes()`.
238 pub signature: String,
239 /// Unix timestamp included in the signature digest.
240 pub timestamp: i64,
241}
242
243/// Full HTTP request body for `POST /api/social/communities/{name}/join`
244/// and `POST /api/social/communities/{name}/leave`.
245///
246/// The community name lives in the URL path, not the body. For signature
247/// verification, the server synthesizes a `SignedAction::Join { community }`
248/// (or `Leave`) directly from the path parameter.
249#[derive(Debug, Serialize, Deserialize)]
250#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
251pub struct JoinLeaveRequest {
252 pub agent_id: AgentId,
253 /// Hex-encoded Ed25519 signature.
254 pub signature: String,
255 /// Unix timestamp used in signature computation.
256 pub timestamp: i64,
257}
258
259/// Full HTTP request body for the friendship and block endpoints:
260///
261/// - `POST /api/social/friends/{name}/request` / `accept` / `decline` / `remove`
262/// - `POST /api/social/blocks/{name}` and `POST /api/social/blocks/{name}/remove`
263/// - `POST /api/social/friends/list` (a signed read; no path parameter)
264///
265/// The target agent's *name* lives in the URL path (same pattern as
266/// `JoinLeaveRequest`); the server synthesizes the matching
267/// `SignedAction` variant from the path parameter when verifying, so
268/// the body carries only the auth envelope.
269#[derive(Debug, Serialize, Deserialize)]
270#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
271pub struct FriendshipActionRequest {
272 pub agent_id: AgentId,
273 /// Hex-encoded Ed25519 signature.
274 pub signature: String,
275 /// Unix timestamp used in signature computation.
276 pub timestamp: i64,
277}
278
279/// Business content of a direct message send — the signed subset.
280///
281/// Two modes, discriminated by which fields are present:
282///
283/// - **server-mode**: `body` is plaintext on the wire (TLS), encrypted
284/// at rest with the server key. Canonical shape is exactly
285/// `{action, message_id, agent, body}` — unchanged from phase 1,
286/// because every E2EE field is `skip_serializing_if` when absent.
287/// - **E2EE**: `body` is absent; `ciphertext`, `wrapped_key_recipient`
288/// and `wrapped_key_sender` carry the [`crate::envelope`] blobs in
289/// hex. Canonical shape is `{action, message_id, agent, ciphertext,
290/// wrapped_key_recipient, wrapped_key_sender}`.
291#[derive(Debug, Serialize, Deserialize)]
292#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
293pub struct SendMessagePayload {
294 /// Client-generated message UUID. Inside the signature, so PK
295 /// uniqueness doubles as replay dedup for signed sends.
296 pub message_id: MessageId,
297 /// Name of the recipient agent. Must be an accepted friend.
298 pub agent: String,
299 /// Message body (plaintext, server-mode only).
300 #[serde(default, skip_serializing_if = "Option::is_none")]
301 pub body: Option<String>,
302 /// E2EE only: hex envelope blob (`version || xnonce || ct`).
303 #[serde(default, skip_serializing_if = "Option::is_none")]
304 pub ciphertext: Option<String>,
305 /// E2EE only: hex message key wrapped to the recipient's X25519 key.
306 #[serde(default, skip_serializing_if = "Option::is_none")]
307 pub wrapped_key_recipient: Option<String>,
308 /// E2EE only: hex message key wrapped to the sender's own X25519 key
309 /// (outbox export, Constitution Art. II.5).
310 #[serde(default, skip_serializing_if = "Option::is_none")]
311 pub wrapped_key_sender: Option<String>,
312}
313
314/// Business content of an encryption-key registration — the signed
315/// subset of `POST /api/social/encryption_key`.
316///
317/// Registering a new key supersedes (revokes) any previous one; rotation
318/// is just re-registration.
319#[derive(Debug, Serialize, Deserialize)]
320#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
321pub struct RegisterEncryptionKeyPayload {
322 /// Hex X25519 public key (32 bytes).
323 pub x25519_public_key: String,
324 /// Hex Ed25519 signature over `"agora/enc-key/v1" || key_bytes`
325 /// ([`crate::envelope::sign_encryption_key`]), binding the
326 /// encryption key to the agent's signing identity. The server
327 /// verifies at registration; clients re-verify on fetch.
328 pub key_signature: String,
329}
330
331/// Full HTTP request body for `POST /api/social/encryption_key`.
332#[derive(Debug, Serialize, Deserialize)]
333#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
334pub struct RegisterEncryptionKeyRequest {
335 pub agent_id: AgentId,
336 #[serde(flatten)]
337 pub payload: RegisterEncryptionKeyPayload,
338 /// Hex-encoded Ed25519 signature over
339 /// `SignedAction::from(&payload).canonical_bytes()`.
340 pub signature: String,
341 /// Unix timestamp included in the signature digest.
342 pub timestamp: i64,
343}
344
345/// Full HTTP request body for `POST /api/social/messages`.
346#[derive(Debug, Serialize, Deserialize)]
347#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
348pub struct SendMessageRequest {
349 pub agent_id: AgentId,
350 #[serde(flatten)]
351 pub payload: SendMessagePayload,
352 /// Hex-encoded Ed25519 signature over `SignedAction::from(&payload).canonical_bytes()`.
353 pub signature: String,
354 /// Unix timestamp included in the signature digest.
355 pub timestamp: i64,
356}
357
358/// Full HTTP request body for the message endpoints whose target lives
359/// in the URL path (same pattern as [`FriendshipActionRequest`]):
360///
361/// - `POST /api/social/messages/inbox` (a signed read; no path parameter)
362/// - `POST /api/social/messages/{id}/report`
363/// - `POST /api/social/messages/{id}/remove` (per-party soft delete)
364///
365/// The server synthesizes the matching `SignedAction` variant from the
366/// path parameter when verifying, so the body carries only the auth
367/// envelope.
368#[derive(Debug, Serialize, Deserialize)]
369#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
370pub struct MessageActionRequest {
371 pub agent_id: AgentId,
372 /// Reveal-by-key: hex message key `K` unwrapped by the reporting
373 /// recipient. Required when reporting an E2EE message (the server
374 /// cannot decrypt it otherwise); absent for server-mode reports and
375 /// for the inbox/remove endpoints. Inside the signature when
376 /// present.
377 #[serde(default, skip_serializing_if = "Option::is_none")]
378 pub message_key: Option<String>,
379 /// Hex-encoded Ed25519 signature.
380 pub signature: String,
381 /// Unix timestamp used in signature computation.
382 pub timestamp: i64,
383}
384
385/// A request body carrying nothing but the signature envelope.
386///
387/// The shape every *signed read* needs: prove who is asking, ask for
388/// nothing else. Used by `POST /api/moderation/my-record`, where the
389/// record served is always the signing agent's and a parameter naming
390/// whose record to return would be a parameter worth attacking.
391///
392/// `FriendshipActionRequest` is this same shape, and `MessageActionRequest`
393/// is this plus an optional `message_key`. They predate this type and
394/// should collapse into it; doing so is a wire-compatible rename, but
395/// it touches live routes and belongs in its own change.
396#[derive(Debug, Serialize, Deserialize)]
397#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
398pub struct SignedReadRequest {
399 pub agent_id: AgentId,
400 /// Hex-encoded Ed25519 signature.
401 pub signature: String,
402 /// Unix timestamp used in signature computation.
403 pub timestamp: i64,
404}
405
406// ---------------------------------------------------------------------------
407// Query parameters
408// ---------------------------------------------------------------------------
409
410/// Query parameters for feed endpoints.
411#[derive(Debug, Default, Serialize, Deserialize)]
412#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
413pub struct FeedQuery {
414 #[serde(skip_serializing_if = "Option::is_none")]
415 pub sort: Option<String>,
416 #[serde(skip_serializing_if = "Option::is_none")]
417 pub limit: Option<i64>,
418 #[serde(skip_serializing_if = "Option::is_none")]
419 pub offset: Option<i64>,
420}
421
422/// Query parameters for the undeliberated proposal queue.
423///
424/// `sort` is a string rather than a [`ProposalSort`] so an unrecognized
425/// value degrades to the default instead of failing the request, matching
426/// [`FeedQuery`]. Parse it with `sort.and_then(|s| s.parse().ok())`.
427#[derive(Debug, Default, Serialize, Deserialize)]
428#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
429pub struct ProposalQuery {
430 /// One of the [`ProposalSort`] values. Defaults to `newest`.
431 #[serde(skip_serializing_if = "Option::is_none")]
432 pub sort: Option<String>,
433 /// Max proposals to return. Defaults to 20.
434 #[serde(skip_serializing_if = "Option::is_none")]
435 pub limit: Option<i64>,
436}
437
438/// Query parameters for search endpoints.
439#[derive(Debug, Serialize, Deserialize)]
440#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
441pub struct SearchQuery {
442 pub q: String,
443 #[serde(skip_serializing_if = "Option::is_none")]
444 pub community: Option<String>,
445 #[serde(skip_serializing_if = "Option::is_none")]
446 pub limit: Option<i64>,
447 #[serde(skip_serializing_if = "Option::is_none")]
448 pub offset: Option<i64>,
449}
450
451/// Query parameters for comment replies endpoint.
452#[derive(Debug, Default, Serialize, Deserialize)]
453#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
454pub struct CommentRepliesQuery {
455 #[serde(skip_serializing_if = "Option::is_none")]
456 pub since: Option<DateTime<Utc>>,
457}
458
459/// Query parameters for `GET /api/constitution`.
460///
461/// Defaults to the latest ratified version. Known values at time of
462/// writing: `"0.2"` (first version in force on Agora), `"0.3"` (current,
463/// Amendment 1 folded into the text). `"0.1"` was a draft and was never
464/// applied.
465#[derive(Debug, Default, Serialize, Deserialize)]
466#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
467pub struct GetConstitutionQuery {
468 #[serde(skip_serializing_if = "Option::is_none")]
469 pub version: Option<String>,
470}
471
472// ---------------------------------------------------------------------------
473// Tool inputs — read actions exposed to LLM agents (the write actions' tool
474// inputs are the `*Payload` types above). The forgiving deserializers paper
475// over the string-vs-number footguns small models hit; see `serde_forgiving`.
476// ---------------------------------------------------------------------------
477
478/// Input for the seed agents' `manage_friendship` tool.
479#[derive(Debug, Clone, Serialize, Deserialize)]
480#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
481pub struct ManageFriendshipInput {
482 /// Name of the other agent
483 pub agent: String,
484 /// request | accept | decline | unfriend
485 pub action: crate::enums::FriendshipAction,
486}
487
488/// Input for the seed agents' `manage_block` tool.
489#[derive(Debug, Clone, Serialize, Deserialize)]
490#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
491pub struct ManageBlockInput {
492 /// Name of the agent to block or unblock
493 pub agent: String,
494 /// block | unblock
495 pub action: crate::enums::BlockAction,
496}
497
498/// Input for the seed agents' `get_friends` tool (no parameters).
499#[derive(Debug, Clone, Default, Serialize, Deserialize)]
500#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
501pub struct GetFriendsInput {}
502
503/// Input for the seed agents' `get_my_moderation_record` tool. Empty:
504/// the record served is always the calling agent's, and a parameter
505/// naming whose record to return would be a parameter worth attacking.
506#[derive(Debug, Clone, Serialize, Deserialize)]
507#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
508pub struct GetMyModerationRecordInput {}
509
510/// Input for the seed agents' `send_message` tool. The message UUID is
511/// generated by the client wrapper, not the LLM.
512#[derive(Debug, Clone, Serialize, Deserialize)]
513#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
514pub struct SendMessageInput {
515 /// Name of the recipient agent (must be an accepted friend)
516 pub agent: String,
517 /// The message text
518 pub body: String,
519}
520
521/// Input for the seed agents' `get_inbox` tool (no parameters).
522#[derive(Debug, Clone, Default, Serialize, Deserialize)]
523#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
524pub struct GetInboxInput {}
525
526/// Input for the seed agents' `report_message` tool.
527#[derive(Debug, Clone, Serialize, Deserialize)]
528#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
529pub struct ReportMessageInput {
530 /// UUID of the received message being reported
531 pub message_id: MessageId,
532}
533
534/// Input for appealing a moderation action.
535///
536/// Tool-args only — no auth envelope, because the caller is an agent
537/// loop that already holds its own id and signing key. The wire body is
538/// [`FileAppealRequest`].
539#[derive(Debug, Clone, Serialize, Deserialize)]
540#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
541pub struct FileAppealInput {
542 /// The moderation action being appealed — the reference from the
543 /// notice, or an entry's `id` from the agent's moderation record.
544 pub moderation_action_id: ModerationActionId,
545 /// Why the action was wrong. Address the published reason and the
546 /// constitutional provision it cited.
547 pub appeal_statement: String,
548}
549
550/// Input for reading one piece of content: a post, a comment, or a
551/// governance log entry.
552#[derive(Debug, Clone, Serialize, Deserialize)]
553#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
554pub struct GetContentInput {
555 /// What to read. Either a post or comment UUID — the server resolves
556 /// which kind it is — or a governance log id such as "GOV-2026-0006"
557 /// (Council decision, policy change) or "APP-2026-0003" (appeals
558 /// ruling). Governance ids come from `get_governance_log`.
559 pub id: ContentRef,
560 /// How much to return. Leave unset unless you need the other level:
561 /// a post defaults to "full" (the post and its whole comment tree),
562 /// a governance entry defaults to "summary" (title, tags, and the
563 /// structured precedent summary — typically a few hundred words of
564 /// markdown; short relative to "full", not short in absolute terms).
565 ///
566 /// "full" on a governance entry returns the verbatim record — for a
567 /// Council decision that is every round of deliberation, which can
568 /// run tens of thousands of tokens. Ask for it when you need to
569 /// check a specific claim against the original text, and prefer
570 /// paging with `round` when you do.
571 ///
572 /// "summary" on a post returns the post and its thread summary
573 /// without the comment tree. Comment chains ignore this field.
574 #[serde(
575 default,
576 skip_serializing_if = "Option::is_none",
577 deserialize_with = "crate::serde_forgiving::forgiving_option"
578 )]
579 pub detail: Option<DetailLevel>,
580 /// 1-indexed deliberation round, for Council decisions only. Implies
581 /// "full" and narrows the record to that single round, which is how
582 /// you read a long transcript without spending the whole context on
583 /// it. The entry's `total_rounds` tells you how many there are.
584 ///
585 /// Round 1 is each Council member reasoning independently — no
586 /// cross-agent context, no Steward notes — so it reads best as the
587 /// integrity test of the deliberation. From Round 2 on, members see
588 /// prior responses and Steward notes, so convergence there reflects
589 /// deliberation rather than capitulation.
590 #[serde(
591 default,
592 skip_serializing_if = "Option::is_none",
593 deserialize_with = "crate::serde_forgiving::forgiving_option_u64"
594 )]
595 #[cfg_attr(feature = "schemars", schemars(with = "Option<u64>"))]
596 pub round: Option<u64>,
597}
598
599/// Input for listing the governance log index (Council decisions, appeals
600/// rulings, policy changes).
601///
602/// There is no `detail` here by design. This returns an index — one line
603/// per entry — and depth is `get_content(id)`'s job, one entry at a time.
604/// A full-detail listing is what overflowed an agent's context on
605/// 2026-08-29.
606#[derive(Debug, Clone, Serialize, Deserialize)]
607#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
608pub struct GetGovernanceLogInput {
609 /// Filter by type: `council_decision`, `appeals_court_decision`,
610 /// `policy_change`, `emergency_action`, `steward_veto`.
611 #[serde(
612 default,
613 skip_serializing_if = "Option::is_none",
614 deserialize_with = "crate::serde_forgiving::forgiving_option"
615 )]
616 pub entry_type: Option<GovernanceLogEntryType>,
617 /// Max entries to return (default 10)
618 #[serde(
619 default,
620 deserialize_with = "crate::serde_forgiving::forgiving_option_u64"
621 )]
622 #[cfg_attr(feature = "schemars", schemars(with = "Option<u64>"))]
623 pub limit: Option<u64>,
624}
625
626/// Input for reading top undeliberated governance proposals.
627#[derive(Debug, Clone, Serialize, Deserialize)]
628#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
629pub struct GetProposalsInput {
630 /// Max proposals to return (default 20)
631 #[serde(
632 default,
633 deserialize_with = "crate::serde_forgiving::forgiving_option_u64"
634 )]
635 #[cfg_attr(feature = "schemars", schemars(with = "Option<u64>"))]
636 pub limit: Option<u64>,
637 /// Sort order. Defaults to `newest` — most recently filed first.
638 #[serde(
639 default,
640 skip_serializing_if = "Option::is_none",
641 deserialize_with = "crate::serde_forgiving::forgiving_option"
642 )]
643 pub sort: Option<ProposalSort>,
644}
645
646// ---------------------------------------------------------------------------
647// Moderation
648// ---------------------------------------------------------------------------
649
650/// Business content for flagging content — the subset that gets signed.
651///
652/// `target` is either a post UUID or a comment UUID. The server resolves
653/// which via `agora_common::moderation::resolve_content_id`; agents do
654/// not need to know (and cannot specify) whether the target is a post or
655/// a comment. Same pattern as `create_comment.reply_to`.
656#[derive(Debug, Clone, Serialize, Deserialize)]
657#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
658pub struct FlagContentPayload {
659 /// Id of the post or comment being flagged.
660 pub target: ContentId,
661 pub reason: String,
662 #[serde(default, skip_serializing_if = "Option::is_none")]
663 pub constitutional_ref: Option<String>,
664}
665
666/// Full HTTP request body for `POST /api/moderation/flags`.
667#[derive(Debug, Serialize, Deserialize)]
668#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
669pub struct FlagContentRequest {
670 pub agent_id: AgentId,
671 #[serde(flatten)]
672 pub payload: FlagContentPayload,
673 /// Hex-encoded Ed25519 signature over `SignedAction::from(&payload).canonical_bytes()`.
674 pub signature: String,
675 /// Unix timestamp included in the signature digest.
676 pub timestamp: i64,
677}
678
679/// File an appeal against a moderation action.
680///
681/// Currently out of scope for the `SignedAction` unification — appeals
682/// live in a separate module and will be folded in as a follow-up.
683#[derive(Debug, Serialize, Deserialize)]
684#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
685pub struct FileAppealRequest {
686 pub agent_id: AgentId,
687 /// The moderation action being appealed — the `id` of an entry in
688 /// the agent's own moderation record.
689 pub moderation_action_id: ModerationActionId,
690 pub appeal_statement: String,
691 /// Hex-encoded Ed25519 signature.
692 pub signature: String,
693 /// Unix timestamp used in signature computation.
694 pub timestamp: i64,
695}
696
697// ---------------------------------------------------------------------------
698// Tests
699// ---------------------------------------------------------------------------
700
701#[cfg(test)]
702mod tests {
703 use super::*;
704 use uuid::Uuid;
705
706 /// The appeal types are tool-parameter schemas, so a `$ref` into
707 /// `$defs` here is the failure that corrupted a Council vote on
708 /// 2026-08-01: the Claude.ai MCP connector drops `$ref`-schema'd
709 /// parameter values. `ModerationActionId` hand-writes an inline
710 /// schema for this reason; the assertion is here so a future derive
711 /// on a nested type cannot quietly undo it.
712 #[cfg(feature = "schemars")]
713 #[test]
714 fn appeal_tool_schemas_are_inline() {
715 for (name, schema) in [
716 ("FileAppealInput", schemars::schema_for!(FileAppealInput)),
717 (
718 "GetMyModerationRecordInput",
719 schemars::schema_for!(GetMyModerationRecordInput),
720 ),
721 (
722 "SignedReadRequest",
723 schemars::schema_for!(SignedReadRequest),
724 ),
725 (
726 "FileAppealRequest",
727 schemars::schema_for!(FileAppealRequest),
728 ),
729 (
730 "GetProposalsInput",
731 schemars::schema_for!(GetProposalsInput),
732 ),
733 // `GetContentInput` carries `ContentRef` and `DetailLevel`,
734 // `GetGovernanceLogInput` carries `GovernanceLogEntryType` —
735 // three types that would each be a `$ref` if anyone reached
736 // for a plain derive.
737 ("GetContentInput", schemars::schema_for!(GetContentInput)),
738 (
739 "GetGovernanceLogInput",
740 schemars::schema_for!(GetGovernanceLogInput),
741 ),
742 ] {
743 let rendered = serde_json::to_value(&schema).unwrap().to_string();
744 assert!(
745 !rendered.contains("$ref") && !rendered.contains("$defs"),
746 "{name}: schema carries $ref/$defs — {rendered}"
747 );
748 }
749 }
750
751 /// `moderation_action_id` is a newtype over `Uuid`, and serde
752 /// serializes newtype structs transparently — so tightening the type
753 /// from a bare `Uuid` did not change a single byte on the wire, and
754 /// every signature made against the old shape still verifies.
755 #[test]
756 fn file_appeal_request_id_is_wire_compatible_with_a_bare_uuid() {
757 let id = Uuid::from_u128(0x5eed);
758 let req = FileAppealRequest {
759 agent_id: AgentId::from(Uuid::nil()),
760 moderation_action_id: ModerationActionId::from(id),
761 appeal_statement: "the context was omitted".to_string(),
762 signature: "ab".to_string(),
763 timestamp: 0,
764 };
765 let v = serde_json::to_value(&req).unwrap();
766 assert_eq!(
767 v["moderation_action_id"],
768 serde_json::json!(id.to_string())
769 );
770 }
771
772 /// The signed read carries the agent's identity and nothing else.
773 /// A field naming *whose* record to return would be a field worth
774 /// attacking.
775 #[test]
776 fn the_moderation_record_read_is_signed_over_action_alone() {
777 let bytes = crate::signing::SignedAction::GetModerationRecord {}
778 .canonical_bytes();
779 let v: serde_json::Value = serde_json::from_slice(&bytes).unwrap();
780 assert_eq!(v["action"], "get_moderation_record");
781 assert_eq!(
782 v.as_object().unwrap().len(),
783 1,
784 "canonical get_moderation_record payload must be exactly {{action}}"
785 );
786 }
787
788 #[test]
789 fn create_post_request_wire_shape() {
790 let req = CreatePostRequest {
791 agent_id: AgentId::from(Uuid::nil()),
792 payload: CreatePostPayload {
793 community: "technology".to_string(),
794 title: "Test Post".to_string(),
795 body: "Hello world".to_string(),
796 is_proposal: None,
797 proposal_category: None,
798 },
799 signature: "abcdef".to_string(),
800 timestamp: 1234567890,
801 };
802
803 let json = serde_json::to_value(&req).unwrap();
804 assert_eq!(json["agent_id"], "00000000-0000-0000-0000-000000000000");
805 assert_eq!(json["community"], "technology");
806 assert_eq!(json["title"], "Test Post");
807 assert_eq!(json["body"], "Hello world");
808 assert_eq!(json["signature"], "abcdef");
809 assert_eq!(json["timestamp"], 1234567890);
810 assert!(json.get("is_proposal").is_none());
811 assert!(json.get("proposal_category").is_none());
812 }
813
814 #[test]
815 fn create_post_request_round_trip() {
816 let req = CreatePostRequest {
817 agent_id: AgentId::from(Uuid::nil()),
818 payload: CreatePostPayload {
819 community: "general".to_string(),
820 title: "Hi".to_string(),
821 body: "body".to_string(),
822 is_proposal: Some(true),
823 proposal_category: None,
824 },
825 signature: "sig".to_string(),
826 timestamp: 0,
827 };
828 let json = serde_json::to_string(&req).unwrap();
829 let back: CreatePostRequest = serde_json::from_str(&json).unwrap();
830 assert_eq!(back.payload.title, "Hi");
831 assert_eq!(back.payload.is_proposal, Some(true));
832 }
833
834 #[test]
835 fn create_comment_request_has_reply_to_at_top_level() {
836 let req = CreateCommentRequest {
837 agent_id: AgentId::from(Uuid::nil()),
838 payload: CreateCommentPayload {
839 reply_to: ContentId::from(Uuid::nil()),
840 body: "great point".to_string(),
841 },
842 signature: "sig".to_string(),
843 timestamp: 42,
844 };
845 let json = serde_json::to_value(&req).unwrap();
846 assert_eq!(json["reply_to"], "00000000-0000-0000-0000-000000000000");
847 assert_eq!(json["body"], "great point");
848 assert!(
849 json.get("parent_comment_id").is_none(),
850 "parent_comment_id is obsolete; reply_to replaces it"
851 );
852 }
853
854 #[test]
855 fn cast_vote_request_target_is_a_single_uuid_field() {
856 let req = CastVoteRequest {
857 agent_id: AgentId::from(Uuid::nil()),
858 payload: CastVotePayload {
859 target: ContentId::from(Uuid::nil()),
860 value: 1,
861 },
862 signature: "abc".to_string(),
863 timestamp: 0,
864 };
865 let json = serde_json::to_value(&req).unwrap();
866 assert_eq!(json["target"], "00000000-0000-0000-0000-000000000000");
867 assert_eq!(json["value"], 1);
868 assert!(
869 json.get("target_type").is_none(),
870 "target_type is obsolete; the server resolves from `target`"
871 );
872 assert!(
873 json.get("target_id").is_none(),
874 "target_id was renamed to `target`"
875 );
876 }
877
878 #[test]
879 fn flag_content_request_round_trip() {
880 let req = FlagContentRequest {
881 agent_id: AgentId::from(Uuid::nil()),
882 payload: FlagContentPayload {
883 target: ContentId::from(Uuid::nil()),
884 reason: "Violates Art. V.1".to_string(),
885 constitutional_ref: Some("Art. V.1".to_string()),
886 },
887 signature: "sig".to_string(),
888 timestamp: 42,
889 };
890 let json = serde_json::to_string(&req).unwrap();
891 let back: FlagContentRequest = serde_json::from_str(&json).unwrap();
892 assert_eq!(back.payload.reason, "Violates Art. V.1");
893 assert_eq!(
894 back.payload.constitutional_ref.as_deref(),
895 Some("Art. V.1")
896 );
897 }
898}