1use anyhow::Result;
2use serde::Serialize;
3use serde_json::Value;
4
5use crate::diag_output;
6
7pub const AUTH_SCHEMA_VERSION: &str = "codex-cli.auth.v1";
8
9#[derive(Debug, Clone, Serialize)]
10pub struct AuthUseResult {
11 pub target: String,
12 pub matched_secret: Option<String>,
13 pub applied: bool,
14 pub auth_file: String,
15}
16
17#[derive(Debug, Clone, Serialize)]
18pub struct AuthRefreshResult {
19 pub target_file: String,
20 pub refreshed: bool,
21 pub synced: bool,
22 #[serde(skip_serializing_if = "Option::is_none")]
23 pub refreshed_at: Option<String>,
24}
25
26#[derive(Debug, Clone, Serialize)]
27pub struct AuthAutoRefreshTargetResult {
28 pub target_file: String,
29 pub status: String,
30 #[serde(skip_serializing_if = "Option::is_none")]
31 pub reason: Option<String>,
32}
33
34#[derive(Debug, Clone, Serialize)]
35pub struct AuthAutoRefreshResult {
36 pub refreshed: i64,
37 pub skipped: i64,
38 pub failed: i64,
39 pub min_age_days: i64,
40 pub targets: Vec<AuthAutoRefreshTargetResult>,
41}
42
43#[derive(Debug, Clone, Serialize)]
44pub struct AuthCurrentResult {
45 pub auth_file: String,
46 pub matched: bool,
47 #[serde(skip_serializing_if = "Option::is_none")]
48 pub matched_secret: Option<String>,
49 #[serde(skip_serializing_if = "Option::is_none")]
50 pub match_mode: Option<String>,
51}
52
53#[derive(Debug, Clone, Serialize)]
54pub struct AuthSyncResult {
55 pub auth_file: String,
56 pub synced: usize,
57 pub skipped: usize,
58 pub failed: usize,
59 #[serde(skip_serializing_if = "Vec::is_empty")]
60 pub updated_files: Vec<String>,
61}
62
63pub fn emit_result<T: Serialize>(command: &str, result: T) -> Result<()> {
64 diag_output::emit_success_result(AUTH_SCHEMA_VERSION, command, result)
65}
66
67pub fn emit_error(
68 command: &str,
69 code: &str,
70 message: impl Into<String>,
71 details: Option<Value>,
72) -> Result<()> {
73 diag_output::emit_error(AUTH_SCHEMA_VERSION, command, code, message, details)
74}