Skip to main content

agentics_persistence/db/challenges/
records.rs

1use chrono::{DateTime, Utc};
2use serde_json::Value;
3
4use agentics_domain::models::challenge::{ChallengeBundleSpec, ChallengeLifecycleStatus};
5use agentics_domain::models::evaluation::{MetricValue, SolutionSubmissionStatus};
6use agentics_domain::models::hashes::Sha256Digest;
7use agentics_domain::models::ids::{
8    AgentId, ChallengeShortlistRevisionId, HumanId, SolutionSubmissionId,
9};
10use agentics_domain::models::localization::LocalizedText;
11use agentics_domain::models::names::{ChallengeKeyword, ChallengeName, MetricName, TargetName};
12use agentics_domain::models::urls::MoltbookPostUrl;
13use agentics_domain::storage::StorageKey;
14
15/// Published challenge list plus the unbounded count for pagination previews.
16#[derive(Debug, Clone)]
17pub struct PublishedChallengeList {
18    pub items: Vec<PublishedChallengeListItemRecord>,
19    pub total_count: i64,
20    pub limit: i64,
21    pub offset: i64,
22    pub has_more: bool,
23}
24
25/// Published challenge catalog record before public API projection.
26#[derive(Debug, Clone)]
27pub struct PublishedChallengeListItemRecord {
28    pub challenge_name: ChallengeName,
29    pub title: String,
30    pub summary: LocalizedText,
31    pub spec_json: Value,
32    pub moltbook_discussion_url: Option<MoltbookPostUrl>,
33}
34
35/// Search and keyword filters applied before public challenge pagination.
36#[derive(Debug, Clone, Default)]
37pub struct ChallengeCatalogFilters {
38    pub search: Option<String>,
39    pub keywords: Vec<ChallengeKeyword>,
40}
41
42/// Published challenge joined with challenge metadata.
43#[derive(Debug, Clone)]
44pub struct ChallengeRecord {
45    pub challenge_name: ChallengeName,
46    pub title: String,
47    pub summary: LocalizedText,
48    pub bundle_key: StorageKey,
49    pub public_bundle_key: StorageKey,
50    pub statement_key: StorageKey,
51    pub spec_json: Value,
52    pub moltbook_discussion_url: Option<MoltbookPostUrl>,
53}
54
55/// Moltbook discussion anchor attached to one published challenge.
56#[derive(Debug, Clone)]
57pub struct ChallengeMoltbookDiscussionRecord {
58    pub challenge_name: ChallengeName,
59    pub discussion_url: Option<MoltbookPostUrl>,
60}
61
62/// Admin challenge catalog row before DTO projection.
63#[derive(Debug, Clone)]
64pub struct AdminChallengeListItemRecord {
65    pub challenge_name: ChallengeName,
66    pub title: String,
67    pub summary: LocalizedText,
68    pub status: ChallengeLifecycleStatus,
69    pub spec_json: Option<Value>,
70    pub moltbook_discussion_url: Option<MoltbookPostUrl>,
71    pub created_at: DateTime<Utc>,
72    pub updated_at: DateTime<Utc>,
73}
74
75/// Challenge publish inputs.
76#[derive(Debug)]
77pub struct PublishChallengeInput<'a> {
78    pub challenge_name: &'a ChallengeName,
79    pub bundle_key: &'a StorageKey,
80    pub public_bundle_key: &'a StorageKey,
81    pub statement_key: &'a StorageKey,
82    pub spec: &'a ChallengeBundleSpec,
83    pub title: &'a str,
84    pub summary: &'a LocalizedText,
85}
86
87/// Published challenge storage row returned by publish primitives.
88#[derive(Debug, Clone)]
89pub struct PublishChallengeRecord {
90    pub challenge_name: ChallengeName,
91    pub title: String,
92    pub bundle_key: StorageKey,
93    pub public_bundle_key: StorageKey,
94    pub statement_key: StorageKey,
95}
96
97/// Input for one shortlist delta revision.
98#[derive(Debug, Clone)]
99pub struct CreateChallengeShortlistRevisionInput {
100    pub revision_id: ChallengeShortlistRevisionId,
101    pub challenge_name: ChallengeName,
102    pub uploader_human_id: HumanId,
103    pub storage_key: StorageKey,
104    pub sha256: Sha256Digest,
105    pub requested_count: i64,
106    pub agent_ids_to_add: Vec<AgentId>,
107}
108
109/// Persisted shortlist revision row before DTO projection.
110#[derive(Debug, Clone)]
111pub struct ChallengeShortlistRevisionRecord {
112    pub id: ChallengeShortlistRevisionId,
113    pub challenge_name: ChallengeName,
114    pub uploader_human_id: HumanId,
115    pub requested_count: i64,
116    pub added_count: i64,
117    pub sha256: Sha256Digest,
118    pub storage_key: StorageKey,
119    pub created_at: DateTime<Utc>,
120}
121
122/// Effective shortlisted agent row before DTO projection.
123#[derive(Debug, Clone)]
124pub struct ChallengeShortlistedAgentRecord {
125    pub agent_id: AgentId,
126    pub agent_display_name: String,
127    pub added_by_human_id: HumanId,
128    pub created_at: DateTime<Utc>,
129}
130
131/// Effective challenge shortlist before DTO projection.
132#[derive(Debug, Clone)]
133pub struct ChallengeShortlistRecord {
134    pub challenge_name: ChallengeName,
135    pub items: Vec<ChallengeShortlistedAgentRecord>,
136}
137
138/// Challenge-owner aggregate statistics before DTO projection.
139#[derive(Debug, Clone)]
140pub struct CreatorChallengeStatsRecord {
141    pub challenge_name: ChallengeName,
142    pub target: Option<TargetName>,
143    pub agent_count: i64,
144    pub solution_submission_count: i64,
145    pub completed_solution_submission_count: i64,
146    pub failed_solution_submission_count: i64,
147    pub queued_or_running_solution_submission_count: i64,
148    pub visible_solution_submission_count: i64,
149    pub validation_run_count: i64,
150    pub official_run_count: i64,
151    pub latest_solution_submission_at: Option<DateTime<Utc>>,
152    pub latest_completed_evaluation_at: Option<DateTime<Utc>>,
153    pub primary_metric_name: MetricName,
154    pub primary_metric_min: Option<f64>,
155    pub primary_metric_max: Option<f64>,
156    pub primary_metric_mean: Option<f64>,
157}
158
159/// Challenge-owner participant row before DTO projection.
160#[derive(Debug, Clone)]
161pub struct CreatorChallengeParticipantRecord {
162    pub agent_id: AgentId,
163    pub agent_display_name: String,
164    pub solution_submission_count: i64,
165    pub best_solution_submission_id: Option<SolutionSubmissionId>,
166    pub best_primary_metric: Option<MetricValue>,
167    pub best_aggregate_metrics: Option<Vec<MetricValue>>,
168    pub best_updated_at: Option<DateTime<Utc>>,
169    pub latest_status: Option<SolutionSubmissionStatus>,
170    pub latest_solution_submission_at: Option<DateTime<Utc>>,
171}
172
173/// Challenge-owner participant list before DTO projection.
174#[derive(Debug, Clone)]
175pub struct CreatorChallengeParticipantsRecord {
176    pub challenge_name: ChallengeName,
177    pub target: Option<TargetName>,
178    pub items: Vec<CreatorChallengeParticipantRecord>,
179}