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