Skip to content

Commit 689f13c

Browse files
Initial response (aws#2796)
* initial response support for event streams
1 parent b6b07c4 commit 689f13c

File tree

58 files changed

+4141
-35
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+4141
-35
lines changed

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.11.232
1+
1.11.232

generated/src/aws-cpp-sdk-bedrock-agent-runtime/include/aws/bedrock-agent-runtime/model/InvokeAgentHandler.h

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <aws/bedrock-agent-runtime/BedrockAgentRuntime_EXPORTS.h>
1111
#include <aws/bedrock-agent-runtime/BedrockAgentRuntimeErrors.h>
1212

13+
#include <aws/bedrock-agent-runtime/model/InvokeAgentInitialResponse.h>
1314
#include <aws/bedrock-agent-runtime/model/PayloadPart.h>
1415
#include <aws/bedrock-agent-runtime/model/TracePart.h>
1516

@@ -21,13 +22,15 @@ namespace Model
2122
{
2223
enum class InvokeAgentEventType
2324
{
25+
INITIAL_RESPONSE,
2426
CHUNK,
2527
TRACE,
2628
UNKNOWN
2729
};
2830

2931
class InvokeAgentHandler : public Aws::Utils::Event::EventStreamHandler
3032
{
33+
typedef std::function<void(const InvokeAgentInitialResponse&)> InvokeAgentInitialResponseCallback;
3134
typedef std::function<void(const PayloadPart&)> PayloadPartCallback;
3235
typedef std::function<void(const TracePart&)> TracePartCallback;
3336
typedef std::function<void(const Aws::Client::AWSError<BedrockAgentRuntimeErrors>& error)> ErrorCallback;
@@ -38,6 +41,7 @@ namespace Model
3841

3942
AWS_BEDROCKAGENTRUNTIME_API virtual void OnEvent() override;
4043

44+
inline void SetInitialResponseCallback(const InvokeAgentInitialResponseCallback& callback) { m_onInitialResponse = callback; }
4145
inline void SetPayloadPartCallback(const PayloadPartCallback& callback) { m_onPayloadPart = callback; }
4246
inline void SetTracePartCallback(const TracePartCallback& callback) { m_onTracePart = callback; }
4347
inline void SetOnErrorCallback(const ErrorCallback& callback) { m_onError = callback; }
@@ -47,6 +51,7 @@ namespace Model
4751
AWS_BEDROCKAGENTRUNTIME_API void HandleErrorInMessage();
4852
AWS_BEDROCKAGENTRUNTIME_API void MarshallError(const Aws::String& errorCode, const Aws::String& errorMessage);
4953

54+
InvokeAgentInitialResponseCallback m_onInitialResponse;
5055
PayloadPartCallback m_onPayloadPart;
5156
TracePartCallback m_onTracePart;
5257
ErrorCallback m_onError;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/**
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*/
5+
6+
#pragma once
7+
#include <aws/bedrock-agent-runtime/BedrockAgentRuntime_EXPORTS.h>
8+
#include <aws/core/utils/memory/stl/AWSString.h>
9+
#include <utility>
10+
11+
namespace Aws
12+
{
13+
namespace Utils
14+
{
15+
namespace Json
16+
{
17+
class JsonValue;
18+
class JsonView;
19+
} // namespace Json
20+
} // namespace Utils
21+
namespace BedrockAgentRuntime
22+
{
23+
namespace Model
24+
{
25+
26+
class InvokeAgentInitialResponse
27+
{
28+
public:
29+
AWS_BEDROCKAGENTRUNTIME_API InvokeAgentInitialResponse();
30+
AWS_BEDROCKAGENTRUNTIME_API InvokeAgentInitialResponse(Aws::Utils::Json::JsonView jsonValue);
31+
AWS_BEDROCKAGENTRUNTIME_API InvokeAgentInitialResponse& operator=(Aws::Utils::Json::JsonView jsonValue);
32+
AWS_BEDROCKAGENTRUNTIME_API Aws::Utils::Json::JsonValue Jsonize() const;
33+
34+
35+
/**
36+
* <p>streaming response mimetype of the model</p>
37+
*/
38+
inline const Aws::String& GetSessionId() const{ return m_sessionId; }
39+
40+
/**
41+
* <p>streaming response mimetype of the model</p>
42+
*/
43+
inline bool SessionIdHasBeenSet() const { return m_sessionIdHasBeenSet; }
44+
45+
/**
46+
* <p>streaming response mimetype of the model</p>
47+
*/
48+
inline void SetSessionId(const Aws::String& value) { m_sessionIdHasBeenSet = true; m_sessionId = value; }
49+
50+
/**
51+
* <p>streaming response mimetype of the model</p>
52+
*/
53+
inline void SetSessionId(Aws::String&& value) { m_sessionIdHasBeenSet = true; m_sessionId = std::move(value); }
54+
55+
/**
56+
* <p>streaming response mimetype of the model</p>
57+
*/
58+
inline void SetSessionId(const char* value) { m_sessionIdHasBeenSet = true; m_sessionId.assign(value); }
59+
60+
/**
61+
* <p>streaming response mimetype of the model</p>
62+
*/
63+
inline InvokeAgentInitialResponse& WithSessionId(const Aws::String& value) { SetSessionId(value); return *this;}
64+
65+
/**
66+
* <p>streaming response mimetype of the model</p>
67+
*/
68+
inline InvokeAgentInitialResponse& WithSessionId(Aws::String&& value) { SetSessionId(std::move(value)); return *this;}
69+
70+
/**
71+
* <p>streaming response mimetype of the model</p>
72+
*/
73+
inline InvokeAgentInitialResponse& WithSessionId(const char* value) { SetSessionId(value); return *this;}
74+
75+
76+
/**
77+
* <p>streaming response mimetype of the model</p>
78+
*/
79+
inline const Aws::String& GetContentType() const{ return m_contentType; }
80+
81+
/**
82+
* <p>streaming response mimetype of the model</p>
83+
*/
84+
inline bool ContentTypeHasBeenSet() const { return m_contentTypeHasBeenSet; }
85+
86+
/**
87+
* <p>streaming response mimetype of the model</p>
88+
*/
89+
inline void SetContentType(const Aws::String& value) { m_contentTypeHasBeenSet = true; m_contentType = value; }
90+
91+
/**
92+
* <p>streaming response mimetype of the model</p>
93+
*/
94+
inline void SetContentType(Aws::String&& value) { m_contentTypeHasBeenSet = true; m_contentType = std::move(value); }
95+
96+
/**
97+
* <p>streaming response mimetype of the model</p>
98+
*/
99+
inline void SetContentType(const char* value) { m_contentTypeHasBeenSet = true; m_contentType.assign(value); }
100+
101+
/**
102+
* <p>streaming response mimetype of the model</p>
103+
*/
104+
inline InvokeAgentInitialResponse& WithContentType(const Aws::String& value) { SetContentType(value); return *this;}
105+
106+
/**
107+
* <p>streaming response mimetype of the model</p>
108+
*/
109+
inline InvokeAgentInitialResponse& WithContentType(Aws::String&& value) { SetContentType(std::move(value)); return *this;}
110+
111+
/**
112+
* <p>streaming response mimetype of the model</p>
113+
*/
114+
inline InvokeAgentInitialResponse& WithContentType(const char* value) { SetContentType(value); return *this;}
115+
116+
private:
117+
118+
Aws::String m_sessionId;
119+
bool m_sessionIdHasBeenSet = false;
120+
121+
Aws::String m_contentType;
122+
bool m_contentTypeHasBeenSet = false;
123+
};
124+
125+
} // namespace Model
126+
} // namespace BedrockAgentRuntime
127+
} // namespace Aws

generated/src/aws-cpp-sdk-bedrock-agent-runtime/source/model/InvokeAgentHandler.cpp

+30-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ namespace Model
2929

3030
InvokeAgentHandler::InvokeAgentHandler() : EventStreamHandler()
3131
{
32+
m_onInitialResponse = [&](const InvokeAgentInitialResponse&)
33+
{
34+
AWS_LOGSTREAM_TRACE(INVOKEAGENT_HANDLER_CLASS_TAG,
35+
"InvokeAgent initial response received.");
36+
};
37+
3238
m_onPayloadPart = [&](const PayloadPart&)
3339
{
3440
AWS_LOGSTREAM_TRACE(INVOKEAGENT_HANDLER_CLASS_TAG, "PayloadPart received.");
@@ -93,6 +99,21 @@ namespace Model
9399
}
94100
switch (InvokeAgentEventMapper::GetInvokeAgentEventTypeForName(eventTypeHeaderIter->second.GetEventHeaderValueAsString()))
95101
{
102+
103+
case InvokeAgentEventType::INITIAL_RESPONSE:
104+
{
105+
JsonValue json(GetEventPayloadAsString());
106+
if (!json.WasParseSuccessful())
107+
{
108+
AWS_LOGSTREAM_WARN(INVOKEAGENT_HANDLER_CLASS_TAG, "Unable to generate a proper InvokeAgentInitialResponse object from the response in JSON format.");
109+
break;
110+
}
111+
112+
InvokeAgentInitialResponse event(json.View());
113+
m_onInitialResponse(event);
114+
break;
115+
}
116+
96117
case InvokeAgentEventType::CHUNK:
97118
{
98119
JsonValue json(GetEventPayloadAsString());
@@ -209,13 +230,19 @@ namespace Model
209230

210231
namespace InvokeAgentEventMapper
211232
{
233+
static const int INITIAL_RESPONSE_HASH = Aws::Utils::HashingUtils::HashString("initial-response");
212234
static const int CHUNK_HASH = Aws::Utils::HashingUtils::HashString("chunk");
213235
static const int TRACE_HASH = Aws::Utils::HashingUtils::HashString("trace");
214236

215237
InvokeAgentEventType GetInvokeAgentEventTypeForName(const Aws::String& name)
216238
{
217239
int hashCode = Aws::Utils::HashingUtils::HashString(name.c_str());
218-
if (hashCode == CHUNK_HASH)
240+
241+
if (hashCode == INITIAL_RESPONSE_HASH)
242+
{
243+
return InvokeAgentEventType::INITIAL_RESPONSE;
244+
}
245+
else if (hashCode == CHUNK_HASH)
219246
{
220247
return InvokeAgentEventType::CHUNK;
221248
}
@@ -230,6 +257,8 @@ namespace InvokeAgentEventMapper
230257
{
231258
switch (value)
232259
{
260+
case InvokeAgentEventType::INITIAL_RESPONSE:
261+
return "initial-response";
233262
case InvokeAgentEventType::CHUNK:
234263
return "chunk";
235264
case InvokeAgentEventType::TRACE:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*/
5+
6+
#include <aws/bedrock-agent-runtime/model/InvokeAgentInitialResponse.h>
7+
#include <aws/core/utils/json/JsonSerializer.h>
8+
#include <aws/core/utils/memory/stl/AWSStringStream.h>
9+
10+
#include <utility>
11+
12+
using namespace Aws::Utils::Json;
13+
using namespace Aws::Utils;
14+
15+
namespace Aws
16+
{
17+
namespace BedrockAgentRuntime
18+
{
19+
namespace Model
20+
{
21+
22+
InvokeAgentInitialResponse::InvokeAgentInitialResponse() :
23+
m_sessionIdHasBeenSet(false),
24+
m_contentTypeHasBeenSet(false)
25+
{
26+
}
27+
28+
InvokeAgentInitialResponse::InvokeAgentInitialResponse(JsonView jsonValue) :
29+
m_sessionIdHasBeenSet(false),
30+
m_contentTypeHasBeenSet(false)
31+
{
32+
*this = jsonValue;
33+
}
34+
35+
InvokeAgentInitialResponse& InvokeAgentInitialResponse::operator =(JsonView jsonValue)
36+
{
37+
AWS_UNREFERENCED_PARAM(jsonValue);
38+
return *this;
39+
}
40+
41+
JsonValue InvokeAgentInitialResponse::Jsonize() const
42+
{
43+
JsonValue payload;
44+
45+
return payload;
46+
}
47+
48+
} // namespace Model
49+
} // namespace BedrockAgentRuntime
50+
} // namespace Aws

generated/src/aws-cpp-sdk-bedrock-runtime/include/aws/bedrock-runtime/model/InvokeModelWithResponseStreamHandler.h

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <aws/bedrock-runtime/BedrockRuntime_EXPORTS.h>
1111
#include <aws/bedrock-runtime/BedrockRuntimeErrors.h>
1212

13+
#include <aws/bedrock-runtime/model/InvokeModelWithResponseStreamInitialResponse.h>
1314
#include <aws/bedrock-runtime/model/PayloadPart.h>
1415

1516
namespace Aws
@@ -20,12 +21,14 @@ namespace Model
2021
{
2122
enum class InvokeModelWithResponseStreamEventType
2223
{
24+
INITIAL_RESPONSE,
2325
CHUNK,
2426
UNKNOWN
2527
};
2628

2729
class InvokeModelWithResponseStreamHandler : public Aws::Utils::Event::EventStreamHandler
2830
{
31+
typedef std::function<void(const InvokeModelWithResponseStreamInitialResponse&)> InvokeModelWithResponseStreamInitialResponseCallback;
2932
typedef std::function<void(const PayloadPart&)> PayloadPartCallback;
3033
typedef std::function<void(const Aws::Client::AWSError<BedrockRuntimeErrors>& error)> ErrorCallback;
3134

@@ -35,6 +38,7 @@ namespace Model
3538

3639
AWS_BEDROCKRUNTIME_API virtual void OnEvent() override;
3740

41+
inline void SetInitialResponseCallback(const InvokeModelWithResponseStreamInitialResponseCallback& callback) { m_onInitialResponse = callback; }
3842
inline void SetPayloadPartCallback(const PayloadPartCallback& callback) { m_onPayloadPart = callback; }
3943
inline void SetOnErrorCallback(const ErrorCallback& callback) { m_onError = callback; }
4044

@@ -43,6 +47,7 @@ namespace Model
4347
AWS_BEDROCKRUNTIME_API void HandleErrorInMessage();
4448
AWS_BEDROCKRUNTIME_API void MarshallError(const Aws::String& errorCode, const Aws::String& errorMessage);
4549

50+
InvokeModelWithResponseStreamInitialResponseCallback m_onInitialResponse;
4651
PayloadPartCallback m_onPayloadPart;
4752
ErrorCallback m_onError;
4853
};

0 commit comments

Comments
 (0)