1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

/// The Event sent to Lambda from Agents for Amazon Bedrock.
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct AgentEvent {
    ///The version of the message that identifies the format of the event data going into the Lambda function and the expected format of the response from a Lambda function. Amazon Bedrock only supports version 1.0.
    pub message_version: String,
    ///Contains information about the name, ID, alias, and version of the agent that the action group belongs to.
    pub agent: Agent,
    ///The user input for the conversation turn.
    pub input_text: String,
    /// The unique identifier of the agent session.
    pub session_id: String,
    /// The name of the action group.
    pub action_group: String,
    /// The path to the API operation, as defined in the OpenAPI schema.
    pub api_path: String,
    /// The method of the API operation, as defined in the OpenAPI schema.
    pub http_method: String,
    /// Contains a list of objects. Each object contains the name, type, and value of a parameter in the API operation, as defined in the OpenAPI schema.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub parameters: Option<Vec<Parameter>>,
    /// Contains the request body and its properties, as defined in the OpenAPI schema.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub request_body: Option<RequestBody>,
    /// Contains session attributes and their values.
    pub session_attributes: HashMap<String, String>,
    /// Contains prompt attributes and their values.
    pub prompt_session_attributes: HashMap<String, String>,
}

#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct RequestBody {
    /// Contains the request body and its properties
    pub content: HashMap<String, Content>,
}

#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Content {
    /// The content of the request body
    pub properties: Vec<Property>,
}

#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Property {
    /// The name of the parameter
    pub name: String,
    /// The type of the parameter
    pub r#type: String,
    /// The value of the parameter
    pub value: String,
}

#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Parameter {
    /// The name of the parameter
    pub name: String,
    /// The type of the parameter
    pub r#type: String,
    /// The value of the parameter
    pub value: String,
}

#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Agent {
    /// The name of the agent.
    pub name: String,
    /// The unique identifier of the agent.
    pub id: String,
    /// The alias of the agent.
    pub alias: String,
    /// The version of the agent.
    pub version: String,
}

#[cfg(test)]
mod tests {
    #[test]
    #[cfg(feature = "bedrock-agent-runtime")]
    fn example_bedrock_agent__runtime_event() {
        let data = include!("../../fixtures/example-bedrock-agent-runtime-event.json");
        let parsed: AgentEvent = serde_json::from_str(&data).unwrap();
        let output: String = serde_json::to_string(&parsed).unwrap();
        let reparsed: AgentEvent = serde_json::from_slice(&output.as_bytes()).unwrap();
        assert_eq!(parsed, reparsed);
    }
    #[test]
    #[cfg(feature = "bedrock-agent-runtime")]
    fn example_bedrock_agent_runtime_event_without_parameters() {
        let data = include!("../../fixtures/example-bedrock-agent-runtime-event-without-parameters.json");
        let parsed: AgentEvent = serde_json::from_str(&data).unwrap();
        let output: String = serde_json::to_string(&parsed).unwrap();
        let reparsed: AgentEvent = serde_json::from_slice(&output.as_bytes()).unwrap();
        assert_eq!(parsed, reparsed);
    }
    #[test]
    #[cfg(feature = "bedrock-agent-runtime")]
    fn example_bedrock_agent_runtime_event_without_request_body() {
        let data = include!("../../fixtures/example-bedrock-agent-runtime-event-without-request-body.json");
        let parsed: AgentEvent = serde_json::from_str(&data).unwrap();
        let output: String = serde_json::to_string(&parsed).unwrap();
        let reparsed: AgentEvent = serde_json::from_slice(&output.as_bytes()).unwrap();
        assert_eq!(parsed, reparsed);
    }
}