Skip to main content

kaizen/sync/
export_batch.rs

1// SPDX-License-Identifier: AGPL-3.0-or-later
2//! Redacted batch payload shared by Kaizen sync POST and pluggable exporter fan-out.
3
4use crate::feedback::types::FeedbackRecord;
5use crate::sync::outbound::EventsBatchBody;
6use crate::sync::smart::{RepoSnapshotsBatchBody, ToolSpansBatchBody, WorkspaceFactsBatchBody};
7
8#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
9pub struct SessionEvalsBatchBody {
10    pub evals: Vec<crate::eval::types::EvalRow>,
11}
12
13#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
14pub struct SessionFeedbackBatchBody {
15    pub feedback: Vec<FeedbackRecord>,
16}
17
18/// Same JSON bodies as the ingest API; used for both primary sync and optional exporters.
19#[derive(Debug, Clone)]
20pub enum IngestExportBatch {
21    Events(EventsBatchBody),
22    ToolSpans(ToolSpansBatchBody),
23    RepoSnapshots(RepoSnapshotsBatchBody),
24    WorkspaceFacts(WorkspaceFactsBatchBody),
25    SessionEvals(SessionEvalsBatchBody),
26    SessionFeedback(SessionFeedbackBatchBody),
27}
28
29impl IngestExportBatch {
30    pub fn kind_name(&self) -> &'static str {
31        match self {
32            IngestExportBatch::Events(_) => "events",
33            IngestExportBatch::ToolSpans(_) => "tool_spans",
34            IngestExportBatch::RepoSnapshots(_) => "repo_snapshots",
35            IngestExportBatch::WorkspaceFacts(_) => "workspace_facts",
36            IngestExportBatch::SessionEvals(_) => "session_evals",
37            IngestExportBatch::SessionFeedback(_) => "session_feedback",
38        }
39    }
40
41    pub fn item_count(&self) -> usize {
42        match self {
43            IngestExportBatch::Events(b) => b.events.len(),
44            IngestExportBatch::ToolSpans(b) => b.spans.len(),
45            IngestExportBatch::RepoSnapshots(b) => b.snapshots.len(),
46            IngestExportBatch::WorkspaceFacts(b) => b.facts.len(),
47            IngestExportBatch::SessionEvals(b) => b.evals.len(),
48            IngestExportBatch::SessionFeedback(b) => b.feedback.len(),
49        }
50    }
51}