Skip to main content

nanocodex_core/responses/
content.rs

1use std::collections::HashMap;
2
3use serde::{Deserialize, Serialize};
4
5use crate::ImageDetail;
6
7#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
8#[serde(rename_all = "lowercase")]
9pub enum MessageRole {
10    Developer,
11    User,
12    Assistant,
13}
14
15#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
16#[serde(rename_all = "snake_case")]
17pub enum MessagePhase {
18    Commentary,
19    FinalAnswer,
20}
21
22#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
23#[serde(rename_all = "snake_case")]
24pub enum ItemStatus {
25    InProgress,
26    Completed,
27    Incomplete,
28    Failed,
29}
30
31#[derive(Clone, Debug, Deserialize, Serialize)]
32pub struct InternalMessageMetadata {
33    #[serde(default, skip_serializing_if = "Option::is_none")]
34    pub turn_id: Option<Box<str>>,
35}
36
37#[derive(Clone, Debug, Deserialize, Serialize)]
38#[serde(tag = "type", rename_all = "snake_case")]
39pub enum ContentItem {
40    InputText {
41        text: Box<str>,
42    },
43    InputImage {
44        image_url: Box<str>,
45        #[serde(default, skip_serializing_if = "Option::is_none")]
46        detail: Option<ImageDetail>,
47    },
48    InputAudio {
49        audio_url: Box<str>,
50    },
51    OutputText {
52        text: Box<str>,
53        #[serde(default, skip_serializing_if = "Option::is_none")]
54        annotations: Option<Vec<OutputTextAnnotation>>,
55        #[serde(default, skip_serializing_if = "Option::is_none")]
56        logprobs: Option<Vec<OutputTextLogprob>>,
57    },
58}
59
60impl ContentItem {
61    #[must_use]
62    pub fn output_text(text: impl Into<Box<str>>) -> Self {
63        Self::OutputText {
64            text: text.into(),
65            annotations: None,
66            logprobs: None,
67        }
68    }
69}
70
71#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
72#[serde(rename_all = "snake_case")]
73pub enum LocalShellStatus {
74    Completed,
75    InProgress,
76    Incomplete,
77}
78
79#[derive(Clone, Debug, Deserialize, Serialize)]
80#[serde(tag = "type", rename_all = "snake_case")]
81pub enum LocalShellAction {
82    Exec(LocalShellExecAction),
83}
84
85#[derive(Clone, Debug, Deserialize, Serialize)]
86pub struct LocalShellExecAction {
87    pub command: Vec<String>,
88    pub timeout_ms: Option<u64>,
89    pub working_directory: Option<Box<str>>,
90    pub env: Option<HashMap<Box<str>, Box<str>>>,
91    pub user: Option<Box<str>>,
92}
93
94#[derive(Clone, Debug, Deserialize, Serialize)]
95#[serde(tag = "type", rename_all = "snake_case")]
96pub enum WebSearchAction {
97    Search {
98        #[serde(default, skip_serializing_if = "Option::is_none")]
99        query: Option<Box<str>>,
100        #[serde(default, skip_serializing_if = "Option::is_none")]
101        queries: Option<Vec<Box<str>>>,
102    },
103    OpenPage {
104        #[serde(default, skip_serializing_if = "Option::is_none")]
105        url: Option<Box<str>>,
106    },
107    FindInPage {
108        #[serde(default, skip_serializing_if = "Option::is_none")]
109        url: Option<Box<str>>,
110        #[serde(default, skip_serializing_if = "Option::is_none")]
111        pattern: Option<Box<str>>,
112    },
113    #[serde(other)]
114    Other,
115}
116
117#[derive(Clone, Debug, Deserialize, Serialize)]
118#[serde(tag = "type", rename_all = "snake_case")]
119pub enum OutputTextAnnotation {
120    FileCitation {
121        file_id: Box<str>,
122        filename: Box<str>,
123        index: u64,
124    },
125    UrlCitation {
126        end_index: u64,
127        start_index: u64,
128        title: Box<str>,
129        url: Box<str>,
130    },
131    ContainerFileCitation {
132        container_id: Box<str>,
133        end_index: u64,
134        file_id: Box<str>,
135        filename: Box<str>,
136        start_index: u64,
137    },
138    FilePath {
139        file_id: Box<str>,
140        index: u64,
141    },
142}
143
144#[derive(Clone, Debug, Deserialize, Serialize)]
145pub struct OutputTextLogprob {
146    pub token: Box<str>,
147    pub bytes: Vec<u8>,
148    pub logprob: f64,
149    pub top_logprobs: Vec<OutputTextTopLogprob>,
150}
151
152#[derive(Clone, Debug, Deserialize, Serialize)]
153pub struct OutputTextTopLogprob {
154    pub token: Box<str>,
155    pub bytes: Vec<u8>,
156    pub logprob: f64,
157}
158
159#[derive(Clone, Debug, Deserialize, Serialize)]
160#[serde(tag = "type", rename_all = "snake_case")]
161pub enum ToolCaller {
162    Direct,
163    Program { caller_id: Box<str> },
164}
165
166#[derive(Clone, Debug, Deserialize, Serialize)]
167#[serde(tag = "type", rename_all = "snake_case")]
168pub enum AgentMessageContent {
169    InputText { text: Box<str> },
170    EncryptedContent { encrypted_content: Box<str> },
171}
172
173#[derive(Clone, Debug, Deserialize, Serialize)]
174#[serde(tag = "type", rename_all = "snake_case")]
175pub enum ReasoningSummary {
176    SummaryText { text: Box<str> },
177}
178
179#[derive(Clone, Debug, Deserialize, Serialize)]
180#[serde(tag = "type", rename_all = "snake_case")]
181pub enum ReasoningContent {
182    ReasoningText { text: Box<str> },
183    Text { text: Box<str> },
184}
185
186#[derive(Clone, Debug, Deserialize, Serialize)]
187#[serde(untagged)]
188pub enum FunctionOutputBody {
189    Text(Box<str>),
190    Content(Vec<FunctionOutputContent>),
191}
192
193#[derive(Clone, Debug, Deserialize, Serialize)]
194#[serde(tag = "type", rename_all = "snake_case")]
195pub enum FunctionOutputContent {
196    InputText {
197        text: Box<str>,
198    },
199    InputImage {
200        image_url: Box<str>,
201        #[serde(default, skip_serializing_if = "Option::is_none")]
202        detail: Option<ImageDetail>,
203    },
204    EncryptedContent {
205        encrypted_content: Box<str>,
206    },
207}