Skip to content

Commit d513b13

Browse files
KUrushicalavera
andauthored
Made some properties of Bedrock's Event optional. (#748)
* change some properties to optional value * Update lambda-events/src/event/bedrock_agent_runtime/mod.rs add default value to parameters Co-authored-by: David Calavera <[email protected]> * Update lambda-events/src/event/bedrock_agent_runtime/mod.rs add default to request_body Co-authored-by: David Calavera <[email protected]> --------- Co-authored-by: David Calavera <[email protected]>
1 parent 3231e9f commit d513b13

File tree

3 files changed

+82
-2
lines changed

3 files changed

+82
-2
lines changed

lambda-events/src/event/bedrock_agent_runtime/mod.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ pub struct AgentEvent {
2020
/// The method of the API operation, as defined in the OpenAPI schema.
2121
pub http_method: String,
2222
/// 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.
23-
pub parameters: Vec<Parameter>,
23+
#[serde(default, skip_serializing_if = "Option::is_none")]
24+
pub parameters: Option<Vec<Parameter>>,
2425
/// Contains the request body and its properties, as defined in the OpenAPI schema.
25-
pub request_body: RequestBody,
26+
#[serde(default, skip_serializing_if = "Option::is_none")]
27+
pub request_body: Option<RequestBody>,
2628
/// Contains session attributes and their values.
2729
pub session_attributes: HashMap<String, String>,
2830
/// Contains prompt attributes and their values.
@@ -91,4 +93,22 @@ mod tests {
9193
let reparsed: AgentEvent = serde_json::from_slice(&output.as_bytes()).unwrap();
9294
assert_eq!(parsed, reparsed);
9395
}
96+
#[test]
97+
#[cfg(feature = "bedrock-agent-runtime")]
98+
fn example_bedrock_agent_runtime_event_without_parameters() {
99+
let data = include!("../../fixtures/example-bedrock-agent-runtime-event-without-parameters.json");
100+
let parsed: AgentEvent = serde_json::from_str(&data).unwrap();
101+
let output: String = serde_json::to_string(&parsed).unwrap();
102+
let reparsed: AgentEvent = serde_json::from_slice(&output.as_bytes()).unwrap();
103+
assert_eq!(parsed, reparsed);
104+
}
105+
#[test]
106+
#[cfg(feature = "bedrock-agent-runtime")]
107+
fn example_bedrock_agent_runtime_event_without_request_body() {
108+
let data = include!("../../fixtures/example-bedrock-agent-runtime-event-without-request-body.json");
109+
let parsed: AgentEvent = serde_json::from_str(&data).unwrap();
110+
let output: String = serde_json::to_string(&parsed).unwrap();
111+
let reparsed: AgentEvent = serde_json::from_slice(&output.as_bytes()).unwrap();
112+
assert_eq!(parsed, reparsed);
113+
}
94114
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"messageVersion": "1.0",
3+
"agent": {
4+
"name": "AgentName",
5+
"id": "AgentID",
6+
"alias": "AgentAlias",
7+
"version": "AgentVersion"
8+
},
9+
"inputText": "InputText",
10+
"sessionId": "SessionID",
11+
"actionGroup": "ActionGroup",
12+
"apiPath": "/api/path",
13+
"httpMethod": "POST",
14+
"requestBody": {
15+
"content": {
16+
"application/json": {
17+
"properties": [
18+
{
19+
"name": "prop1",
20+
"type": "string",
21+
"value": "value1"
22+
}
23+
]
24+
}
25+
}
26+
},
27+
"sessionAttributes": {
28+
"attr1": "value1"
29+
},
30+
"promptSessionAttributes": {
31+
"promptAttr1": "value1"
32+
}
33+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"messageVersion": "1.0",
3+
"agent": {
4+
"name": "AgentName",
5+
"id": "AgentID",
6+
"alias": "AgentAlias",
7+
"version": "AgentVersion"
8+
},
9+
"inputText": "InputText",
10+
"sessionId": "SessionID",
11+
"actionGroup": "ActionGroup",
12+
"apiPath": "/api/path",
13+
"httpMethod": "POST",
14+
"parameters": [
15+
{
16+
"name": "param1",
17+
"type": "string",
18+
"value": "value1"
19+
}
20+
],
21+
"sessionAttributes": {
22+
"attr1": "value1"
23+
},
24+
"promptSessionAttributes": {
25+
"promptAttr1": "value1"
26+
}
27+
}

0 commit comments

Comments
 (0)