Skip to main content

brainos_httpadapter/
types.rs

1//! Request/response types and error enums for the HTTP adapter.
2
3use std::collections::HashMap;
4
5use serde::{Deserialize, Serialize};
6
7// ─── Errors ──────────────────────────────────────────────────────────────────
8
9#[derive(Debug, thiserror::Error)]
10pub enum HttpAdapterError {
11    #[error("Server error: {0}")]
12    Server(String),
13}
14
15// ─── Request / Response DTOs ─────────────────────────────────────────────────
16
17/// Incoming signal body (POST /v1/signals).
18#[derive(Debug, Deserialize)]
19pub struct SignalRequest {
20    pub source: Option<String>,
21    pub channel: Option<String>,
22    pub sender: Option<String>,
23    pub content: String,
24    pub metadata: Option<HashMap<String, String>>,
25    /// Memory namespace (default: "personal").
26    pub namespace: Option<String>,
27    /// Originating agent identity (e.g. "claude-code", "open-code").
28    pub agent: Option<String>,
29    /// Session ID for conversation continuity. Send back to reuse a session.
30    pub session_id: Option<String>,
31}
32
33/// Search request body (POST /v1/memory/search).
34#[derive(Debug, Deserialize)]
35pub struct SearchRequest {
36    pub query: String,
37    pub top_k: Option<usize>,
38    /// Filter results to this namespace only (optional).
39    pub namespace: Option<String>,
40}
41
42/// Namespace statistics (GET /v1/memory/namespaces).
43#[derive(Debug, Serialize)]
44pub struct NamespaceJson {
45    pub namespace: String,
46    pub fact_count: i64,
47    pub episode_count: i64,
48}
49
50/// Export envelope (GET /v1/memory/export).
51#[derive(Debug, Serialize)]
52pub struct ExportJson {
53    pub version: String,
54    pub exported_at: String,
55    pub facts: Vec<signal::ExportedFact>,
56    pub episodes: Vec<signal::ExportedEpisode>,
57}
58
59/// Import request body (POST /v1/memory/import).
60#[derive(Debug, Deserialize)]
61pub struct ImportRequest {
62    pub facts: Vec<signal::ExportedFact>,
63    pub episodes: Vec<signal::ExportedEpisode>,
64    /// If true, preview what would be imported without writing.
65    #[serde(default)]
66    pub dry_run: bool,
67}
68
69/// Import response (POST /v1/memory/import).
70#[derive(Debug, Serialize)]
71pub struct ImportResponse {
72    pub facts_imported: usize,
73    pub episodes_imported: usize,
74    pub facts_already_existed: usize,
75    pub episodes_already_existed: usize,
76    pub embedded: usize,
77    pub embed_failed: usize,
78}
79
80/// A single fact in JSON form (GET /v1/memory/facts, search results).
81#[derive(Debug, Serialize)]
82pub struct FactJson {
83    pub id: String,
84    pub namespace: String,
85    pub category: String,
86    pub subject: String,
87    pub predicate: String,
88    pub object: String,
89    pub confidence: f64,
90    pub distance: Option<f32>,
91}
92
93/// Health check response.
94#[derive(Debug, Serialize)]
95pub struct HealthResponse {
96    pub status: &'static str,
97    pub version: &'static str,
98}