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::sync::outbound::EventsBatchBody;
5use crate::sync::smart::{RepoSnapshotsBatchBody, ToolSpansBatchBody, WorkspaceFactsBatchBody};
6
7#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
8pub struct SessionEvalsBatchBody {
9    pub evals: Vec<crate::eval::types::EvalRow>,
10}
11
12/// Same JSON bodies as the ingest API; used for both primary sync and optional exporters.
13#[derive(Debug, Clone)]
14pub enum IngestExportBatch {
15    Events(EventsBatchBody),
16    ToolSpans(ToolSpansBatchBody),
17    RepoSnapshots(RepoSnapshotsBatchBody),
18    WorkspaceFacts(WorkspaceFactsBatchBody),
19    SessionEvals(SessionEvalsBatchBody),
20}
21
22impl IngestExportBatch {
23    pub fn kind_name(&self) -> &'static str {
24        match self {
25            IngestExportBatch::Events(_) => "events",
26            IngestExportBatch::ToolSpans(_) => "tool_spans",
27            IngestExportBatch::RepoSnapshots(_) => "repo_snapshots",
28            IngestExportBatch::WorkspaceFacts(_) => "workspace_facts",
29            IngestExportBatch::SessionEvals(_) => "session_evals",
30        }
31    }
32
33    pub fn item_count(&self) -> usize {
34        match self {
35            IngestExportBatch::Events(b) => b.events.len(),
36            IngestExportBatch::ToolSpans(b) => b.spans.len(),
37            IngestExportBatch::RepoSnapshots(b) => b.snapshots.len(),
38            IngestExportBatch::WorkspaceFacts(b) => b.facts.len(),
39            IngestExportBatch::SessionEvals(b) => b.evals.len(),
40        }
41    }
42}