File size: 1,432 Bytes
854994d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//! Guardian V2 classifier and fast-decision facts, enriched by the existing reducer.
//! Payloads contain attribution and bounded outcomes, never prompts or tool arguments.

use crate::events::CodexAppServerClientMetadata;
use crate::events::CodexRuntimeMetadata;
use codex_protocol::protocol::ThreadSource;
use serde::Serialize;

#[derive(Serialize)]
pub struct GuardianV2Event {
    pub thread_id: String,
    pub turn_id: String,
    pub item_id: Option<String>,
    pub model: Option<String>,
    pub occurred_at_ms: u64,
    #[serde(flatten)]
    pub kind: GuardianV2EventKind,
}

#[derive(Serialize)]
#[serde(untagged)]
pub enum GuardianV2EventKind {
    Classification {
        outcome: &'static str,
        risk_level: Option<&'static str>,
        duration_ms: u64,
    },
    FastDecision {
        decision: &'static str,
    },
}

#[derive(Serialize)]
pub(crate) struct GuardianV2EventRequest {
    pub(crate) event_type: &'static str,
    pub(crate) event_params: GuardianV2EventParams,
}

#[derive(Serialize)]
pub(crate) struct GuardianV2EventParams {
    pub(crate) session_id: String,
    pub(crate) app_server_client: CodexAppServerClientMetadata,
    pub(crate) runtime: CodexRuntimeMetadata,
    pub(crate) thread_source: Option<ThreadSource>,
    pub(crate) subagent_source: Option<String>,
    pub(crate) parent_thread_id: Option<String>,
    #[serde(flatten)]
    pub(crate) guardian_v2: GuardianV2Event,
}