| /* | |
| * Licensed to the Apache Software Foundation (ASF) under one | |
| * or more contributor license agreements. See the NOTICE file | |
| * distributed with this work for additional information | |
| * regarding copyright ownership. The ASF licenses this file | |
| * to you under the Apache License, Version 2.0 (the | |
| * "License"); you may not use this file except in compliance | |
| * with the License. You may obtain a copy of the License at | |
| * | |
| * http://www.apache.org/licenses/LICENSE-2.0 | |
| * | |
| * Unless required by applicable law or agreed to in writing, | |
| * software distributed under the License is distributed on an | |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
| * KIND, either express or implied. See the License for the | |
| * specific language governing permissions and limitations | |
| * under the License. | |
| */ | |
| use serde::{Deserialize, Serialize}; | |
| use serde_json::Value; | |
| #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] | |
| #[serde(rename_all = "camelCase")] | |
| pub struct CallResult { | |
| pub content: Vec<ContentBlock>, | |
| #[serde( | |
| default, | |
| deserialize_with = "present_json", | |
| skip_serializing_if = "Option::is_none" | |
| )] | |
| pub structured_content: Option<Value>, | |
| } | |
| // An absent field differs from explicitly returned JSON null, including replay. | |
| fn present_json<'de, D: serde::Deserializer<'de>>( | |
| deserializer: D, | |
| ) -> Result<Option<Value>, D::Error> { | |
| Value::deserialize(deserializer).map(Some) | |
| } | |
| #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] | |
| #[serde( | |
| tag = "type", | |
| rename_all = "snake_case", | |
| rename_all_fields = "camelCase" | |
| )] | |
| pub enum ContentBlock { | |
| Text { | |
| text: String, | |
| }, | |
| Image { | |
| data: String, | |
| mime_type: String, | |
| }, | |
| Audio { | |
| data: String, | |
| mime_type: String, | |
| }, | |
| Resource { | |
| uri: String, | |
| #[serde(skip_serializing_if = "Option::is_none")] | |
| mime_type: Option<String>, | |
| #[serde(skip_serializing_if = "Option::is_none")] | |
| text: Option<String>, | |
| #[serde(skip_serializing_if = "Option::is_none")] | |
| blob: Option<String>, | |
| }, | |
| ResourceLink { | |
| uri: String, | |
| #[serde(skip_serializing_if = "Option::is_none")] | |
| name: Option<String>, | |
| #[serde(skip_serializing_if = "Option::is_none")] | |
| description: Option<String>, | |
| #[serde(skip_serializing_if = "Option::is_none")] | |
| mime_type: Option<String>, | |
| }, | |
| Unknown { | |
| value: Value, | |
| }, | |
| } |