gproxy_protocol/aws/converse/
tools.rs1use serde::{Deserialize, Serialize};
2use serde_json::Value;
3
4use crate::aws::{EmptyObject, Rest, ToolResultStatus, ToolUseType};
5
6use super::{CachePointBlock, DocumentBlock, ImageBlock};
7
8#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9#[serde(rename_all = "camelCase")]
10#[derive(gproxy_protocol_macros::WireBuilder)]
11#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
12pub struct ToolUseBlock {
13 pub tool_use_id: String,
14 pub name: String,
15 pub input: Value,
16 #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
17 pub type_: Option<ToolUseType>,
18 #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
19 pub rest: Rest,
20}
21
22#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
23#[serde(rename_all = "camelCase")]
24#[derive(gproxy_protocol_macros::WireBuilder)]
25#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
26pub struct ToolResultBlock {
27 pub tool_use_id: String,
28 pub content: Vec<ToolResultContentBlock>,
29 #[serde(skip_serializing_if = "Option::is_none")]
30 pub status: Option<ToolResultStatus>,
31 #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
32 pub type_: Option<String>,
33 #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
34 pub rest: Rest,
35}
36
37#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
38#[serde(untagged)]
39#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
40pub enum ToolResultContentBlock {
41 Json {
42 json: Value,
43 #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
44 rest: Rest,
45 },
46 Text {
47 text: String,
48 #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
49 rest: Rest,
50 },
51 Image {
52 image: ImageBlock,
53 #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
54 rest: Rest,
55 },
56 Document {
57 document: DocumentBlock,
58 #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
59 rest: Rest,
60 },
61 Raw(Value),
62}
63
64#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
65#[serde(rename_all = "camelCase")]
66#[derive(gproxy_protocol_macros::WireBuilder)]
67#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
68pub struct ToolConfiguration {
69 pub tools: Vec<Tool>,
70 #[serde(skip_serializing_if = "Option::is_none")]
71 pub tool_choice: Option<ToolChoice>,
72 #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
73 pub rest: Rest,
74}
75
76#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
77#[serde(untagged)]
78#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
79pub enum Tool {
80 ToolSpec {
81 #[serde(rename = "toolSpec")]
82 tool_spec: ToolSpecification,
83 #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
84 rest: Rest,
85 },
86 CachePoint {
87 #[serde(rename = "cachePoint")]
88 cache_point: CachePointBlock,
89 #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
90 rest: Rest,
91 },
92 Raw(Value),
93}
94
95#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
96#[serde(rename_all = "camelCase")]
97#[derive(gproxy_protocol_macros::WireBuilder)]
98#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
99pub struct ToolSpecification {
100 pub name: String,
101 #[serde(skip_serializing_if = "Option::is_none")]
102 pub description: Option<String>,
103 pub input_schema: ToolInputSchema,
104 #[serde(skip_serializing_if = "Option::is_none")]
105 pub strict: Option<bool>,
106 #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
107 pub rest: Rest,
108}
109
110#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
111#[serde(untagged)]
112#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
113pub enum ToolInputSchema {
114 Json {
115 json: Value,
116 #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
117 rest: Rest,
118 },
119 Raw(Value),
120}
121
122#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
123#[serde(untagged)]
124#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
125pub enum ToolChoice {
126 Auto {
127 auto: EmptyObject,
128 #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
129 rest: Rest,
130 },
131 Any {
132 any: EmptyObject,
133 #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
134 rest: Rest,
135 },
136 Specific {
137 tool: SpecificToolChoice,
138 #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
139 rest: Rest,
140 },
141 Raw(Value),
142}
143
144#[derive(
145 Debug, Clone, PartialEq, Eq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder,
146)]
147#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
148pub struct SpecificToolChoice {
149 pub name: String,
150 #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
151 pub rest: Rest,
152}