Skip to main content

objectiveai_sdk/functions/inventions/
schema.rs

1use indexmap::IndexMap;
2use serde::Deserialize;
3
4pub trait JsonSchema {
5    fn json_schema() -> serde_json::Map<String, serde_json::Value>;
6    fn indexmap_json_schema() -> IndexMap<String, serde_json::Value> {
7        Self::json_schema().into_iter().collect()
8    }
9}
10
11pub struct EmptyObjectJsonSchema;
12
13impl JsonSchema for EmptyObjectJsonSchema {
14    fn json_schema() -> serde_json::Map<String, serde_json::Value> {
15        let mut map = serde_json::Map::new();
16        map.insert(
17            "type".to_string(),
18            serde_json::Value::String("object".to_string()),
19        );
20        map.insert(
21            "additionalProperties".to_string(),
22            serde_json::Value::Bool(false),
23        );
24        map
25    }
26}
27
28pub struct AnyObjectJsonSchema;
29
30impl JsonSchema for AnyObjectJsonSchema {
31    fn json_schema() -> serde_json::Map<String, serde_json::Value> {
32        let mut map = serde_json::Map::new();
33        map.insert(
34            "type".to_string(),
35            serde_json::Value::String("object".to_string()),
36        );
37        map
38    }
39}
40
41/// Helper to build a single-string-property schema with a description.
42fn string_property_schema(
43    prop_name: &str,
44    description: &str,
45) -> serde_json::Map<String, serde_json::Value> {
46    let mut prop = serde_json::Map::with_capacity(2);
47    prop.insert(
48        "type".to_string(),
49        serde_json::Value::String("string".to_string()),
50    );
51    prop.insert(
52        "description".to_string(),
53        serde_json::Value::String(description.to_string()),
54    );
55
56    let mut properties = serde_json::Map::with_capacity(1);
57    properties.insert(prop_name.to_string(), serde_json::Value::Object(prop));
58
59    let mut map = serde_json::Map::with_capacity(4);
60    map.insert(
61        "type".to_string(),
62        serde_json::Value::String("object".to_string()),
63    );
64    map.insert(
65        "properties".to_string(),
66        serde_json::Value::Object(properties),
67    );
68    map.insert(
69        "required".to_string(),
70        serde_json::Value::Array(vec![serde_json::Value::String(
71            prop_name.to_string(),
72        )]),
73    );
74    map.insert(
75        "additionalProperties".to_string(),
76        serde_json::Value::Bool(false),
77    );
78    map
79}
80
81/// Schema for WriteInputSchema on scalar functions.
82/// Takes a `schema` property: a JSON string conforming to `functions.expression.ObjectInputSchema`.
83#[derive(Deserialize, schemars::JsonSchema)]
84#[schemars(rename = "functions.inventions.ScalarInputSchemaObject")]
85pub struct ScalarInputSchemaObject {
86    pub schema: String,
87}
88
89impl JsonSchema for ScalarInputSchemaObject {
90    fn json_schema() -> serde_json::Map<String, serde_json::Value> {
91        string_property_schema(
92            "schema",
93            "A JSON string conforming to the functions.expression.ObjectInputSchema schema. Use the ReadObjectInputSchemaSchema tool to see the schema definition.",
94        )
95    }
96}
97
98/// Schema for WriteInputSchema on vector functions.
99/// Takes a `schema` property: a JSON string conforming to `functions.alpha_vector.expression.VectorFunctionInputSchema`.
100#[derive(Deserialize, schemars::JsonSchema)]
101#[schemars(rename = "functions.inventions.VectorInputSchemaObject")]
102pub struct VectorInputSchemaObject {
103    pub schema: String,
104}
105
106impl JsonSchema for VectorInputSchemaObject {
107    fn json_schema() -> serde_json::Map<String, serde_json::Value> {
108        string_property_schema(
109            "schema",
110            "A JSON string conforming to the functions.alpha_vector.expression.VectorFunctionInputSchema schema. Use the Readfunctions_alpha_vector_expression_VectorFunctionInputSchemaSchema tool to see the schema definition.",
111        )
112    }
113}
114
115/// Schema for AppendTask on scalar leaf functions.
116/// Takes a `task` property: a JSON string conforming to `functions.alpha_scalar.LeafTaskExpression`.
117#[derive(Deserialize, schemars::JsonSchema)]
118#[schemars(rename = "functions.inventions.ScalarLeafTaskObject")]
119pub struct ScalarLeafTaskObject {
120    pub task: String,
121}
122
123impl JsonSchema for ScalarLeafTaskObject {
124    fn json_schema() -> serde_json::Map<String, serde_json::Value> {
125        string_property_schema(
126            "task",
127            "A JSON string conforming to the functions.alpha_scalar.LeafTaskExpression schema. Use the Readfunctions_alpha_scalar_LeafTaskExpressionSchema tool to see the schema definition.",
128        )
129    }
130}
131
132/// Schema for AppendTask on scalar branch functions.
133/// Takes a `task` property: a JSON string conforming to `functions.alpha_scalar.PartialPlaceholderBranchTaskExpression`.
134#[derive(Deserialize, schemars::JsonSchema)]
135#[schemars(rename = "functions.inventions.ScalarBranchTaskObject")]
136pub struct ScalarBranchTaskObject {
137    pub task: String,
138}
139
140impl JsonSchema for ScalarBranchTaskObject {
141    fn json_schema() -> serde_json::Map<String, serde_json::Value> {
142        string_property_schema(
143            "task",
144            "A JSON string conforming to the functions.alpha_scalar.PartialPlaceholderBranchTaskExpression schema. Use the Readfunctions_alpha_scalar_PartialPlaceholderBranchTaskExpressionSchema tool to see the schema definition.",
145        )
146    }
147}
148
149/// Schema for AppendTask on vector leaf functions.
150/// Takes a `task` property: a JSON string conforming to `functions.alpha_vector.LeafTaskExpression`.
151#[derive(Deserialize, schemars::JsonSchema)]
152#[schemars(rename = "functions.inventions.VectorLeafTaskObject")]
153pub struct VectorLeafTaskObject {
154    pub task: String,
155}
156
157impl JsonSchema for VectorLeafTaskObject {
158    fn json_schema() -> serde_json::Map<String, serde_json::Value> {
159        string_property_schema(
160            "task",
161            "A JSON string conforming to the functions.alpha_vector.LeafTaskExpression schema. Use the Readfunctions_alpha_vector_LeafTaskExpressionSchema tool to see the schema definition.",
162        )
163    }
164}
165
166/// Schema for AppendTask on vector branch functions.
167/// Takes a `task` property: a JSON string conforming to `functions.alpha_vector.PartialPlaceholderBranchTaskExpression`.
168#[derive(Deserialize, schemars::JsonSchema)]
169#[schemars(rename = "functions.inventions.VectorBranchTaskObject")]
170pub struct VectorBranchTaskObject {
171    pub task: String,
172}
173
174impl JsonSchema for VectorBranchTaskObject {
175    fn json_schema() -> serde_json::Map<String, serde_json::Value> {
176        string_property_schema(
177            "task",
178            "A JSON string conforming to the functions.alpha_vector.PartialPlaceholderBranchTaskExpression schema. Use the Readfunctions_alpha_vector_PartialPlaceholderBranchTaskExpressionSchema tool to see the schema definition.",
179        )
180    }
181}
182
183#[derive(Deserialize, schemars::JsonSchema)]
184#[schemars(rename = "functions.inventions.IndexObject")]
185pub struct IndexObject {
186    pub index: u64,
187}
188
189impl JsonSchema for IndexObject {
190    fn json_schema() -> serde_json::Map<String, serde_json::Value> {
191        let mut index_prop = serde_json::Map::with_capacity(1);
192        index_prop.insert(
193            "type".to_string(),
194            serde_json::Value::String("integer".to_string()),
195        );
196
197        let mut properties = serde_json::Map::with_capacity(1);
198        properties
199            .insert("index".to_string(), serde_json::Value::Object(index_prop));
200
201        let mut map = serde_json::Map::with_capacity(4);
202        map.insert(
203            "type".to_string(),
204            serde_json::Value::String("object".to_string()),
205        );
206        map.insert(
207            "properties".to_string(),
208            serde_json::Value::Object(properties),
209        );
210        map.insert(
211            "required".to_string(),
212            serde_json::Value::Array(vec![serde_json::Value::String(
213                "index".to_string(),
214            )]),
215        );
216        map.insert(
217            "additionalProperties".to_string(),
218            serde_json::Value::Bool(false),
219        );
220        map
221    }
222}
223
224#[derive(Deserialize, schemars::JsonSchema)]
225#[schemars(rename = "functions.inventions.EssayObject")]
226pub struct EssayObject {
227    pub essay: String,
228}
229
230impl JsonSchema for EssayObject {
231    fn json_schema() -> serde_json::Map<String, serde_json::Value> {
232        let mut essay_prop = serde_json::Map::with_capacity(1);
233        essay_prop.insert(
234            "type".to_string(),
235            serde_json::Value::String("string".to_string()),
236        );
237
238        let mut properties = serde_json::Map::with_capacity(1);
239        properties
240            .insert("essay".to_string(), serde_json::Value::Object(essay_prop));
241
242        let mut map = serde_json::Map::with_capacity(4);
243        map.insert(
244            "type".to_string(),
245            serde_json::Value::String("object".to_string()),
246        );
247        map.insert(
248            "properties".to_string(),
249            serde_json::Value::Object(properties),
250        );
251        map.insert(
252            "required".to_string(),
253            serde_json::Value::Array(vec![serde_json::Value::String(
254                "essay".to_string(),
255            )]),
256        );
257        map.insert(
258            "additionalProperties".to_string(),
259            serde_json::Value::Bool(false),
260        );
261        map
262    }
263}
264
265#[derive(Deserialize, schemars::JsonSchema)]
266#[schemars(rename = "functions.inventions.EssayTasksObject")]
267pub struct EssayTasksObject {
268    pub essay_tasks: String,
269}
270
271impl JsonSchema for EssayTasksObject {
272    fn json_schema() -> serde_json::Map<String, serde_json::Value> {
273        let mut essay_tasks_prop = serde_json::Map::with_capacity(1);
274        essay_tasks_prop.insert(
275            "type".to_string(),
276            serde_json::Value::String("string".to_string()),
277        );
278
279        let mut properties = serde_json::Map::with_capacity(1);
280        properties.insert(
281            "essay_tasks".to_string(),
282            serde_json::Value::Object(essay_tasks_prop),
283        );
284
285        let mut map = serde_json::Map::with_capacity(4);
286        map.insert(
287            "type".to_string(),
288            serde_json::Value::String("object".to_string()),
289        );
290        map.insert(
291            "properties".to_string(),
292            serde_json::Value::Object(properties),
293        );
294        map.insert(
295            "required".to_string(),
296            serde_json::Value::Array(vec![serde_json::Value::String(
297                "essay_tasks".to_string(),
298            )]),
299        );
300        map.insert(
301            "additionalProperties".to_string(),
302            serde_json::Value::Bool(false),
303        );
304        map
305    }
306}
307
308#[derive(Deserialize, schemars::JsonSchema)]
309#[schemars(rename = "functions.inventions.TasksLengthObject")]
310pub struct TasksLengthObject {
311    pub tasks_length: u64,
312}
313
314impl JsonSchema for TasksLengthObject {
315    fn json_schema() -> serde_json::Map<String, serde_json::Value> {
316        let mut tasks_length_prop = serde_json::Map::with_capacity(1);
317        tasks_length_prop.insert(
318            "type".to_string(),
319            serde_json::Value::String("integer".to_string()),
320        );
321
322        let mut properties = serde_json::Map::with_capacity(1);
323        properties.insert(
324            "tasks_length".to_string(),
325            serde_json::Value::Object(tasks_length_prop),
326        );
327
328        let mut map = serde_json::Map::with_capacity(4);
329        map.insert(
330            "type".to_string(),
331            serde_json::Value::String("object".to_string()),
332        );
333        map.insert(
334            "properties".to_string(),
335            serde_json::Value::Object(properties),
336        );
337        map.insert(
338            "required".to_string(),
339            serde_json::Value::Array(vec![serde_json::Value::String(
340                "tasks_length".to_string(),
341            )]),
342        );
343        map.insert(
344            "additionalProperties".to_string(),
345            serde_json::Value::Bool(false),
346        );
347        map
348    }
349}
350
351#[derive(Deserialize, schemars::JsonSchema)]
352#[schemars(rename = "functions.inventions.DescriptionObject")]
353pub struct DescriptionObject {
354    pub description: String,
355}
356
357impl JsonSchema for DescriptionObject {
358    fn json_schema() -> serde_json::Map<String, serde_json::Value> {
359        let mut description_prop = serde_json::Map::with_capacity(1);
360        description_prop.insert(
361            "type".to_string(),
362            serde_json::Value::String("string".to_string()),
363        );
364
365        let mut properties = serde_json::Map::with_capacity(1);
366        properties.insert(
367            "description".to_string(),
368            serde_json::Value::Object(description_prop),
369        );
370
371        let mut map = serde_json::Map::with_capacity(4);
372        map.insert(
373            "type".to_string(),
374            serde_json::Value::String("object".to_string()),
375        );
376        map.insert(
377            "properties".to_string(),
378            serde_json::Value::Object(properties),
379        );
380        map.insert(
381            "required".to_string(),
382            serde_json::Value::Array(vec![serde_json::Value::String(
383                "description".to_string(),
384            )]),
385        );
386        map.insert(
387            "additionalProperties".to_string(),
388            serde_json::Value::Bool(false),
389        );
390        map
391    }
392}