@aws-sdk/client-bedrock-agent-runtime 3.461.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +229 -0
  3. package/dist-cjs/BedrockAgentRuntime.js +17 -0
  4. package/dist-cjs/BedrockAgentRuntimeClient.js +45 -0
  5. package/dist-cjs/commands/InvokeAgentCommand.js +52 -0
  6. package/dist-cjs/commands/RetrieveAndGenerateCommand.js +52 -0
  7. package/dist-cjs/commands/RetrieveCommand.js +52 -0
  8. package/dist-cjs/commands/index.js +6 -0
  9. package/dist-cjs/endpoint/EndpointParameters.js +12 -0
  10. package/dist-cjs/endpoint/endpointResolver.js +12 -0
  11. package/dist-cjs/endpoint/ruleset.js +7 -0
  12. package/dist-cjs/extensionConfiguration.js +2 -0
  13. package/dist-cjs/index.js +12 -0
  14. package/dist-cjs/models/BedrockAgentRuntimeServiceException.js +12 -0
  15. package/dist-cjs/models/index.js +4 -0
  16. package/dist-cjs/models/models_0.js +439 -0
  17. package/dist-cjs/pagination/Interfaces.js +2 -0
  18. package/dist-cjs/pagination/RetrievePaginator.js +28 -0
  19. package/dist-cjs/pagination/index.js +5 -0
  20. package/dist-cjs/protocols/Aws_restJson1.js +689 -0
  21. package/dist-cjs/runtimeConfig.browser.js +41 -0
  22. package/dist-cjs/runtimeConfig.js +52 -0
  23. package/dist-cjs/runtimeConfig.native.js +15 -0
  24. package/dist-cjs/runtimeConfig.shared.js +24 -0
  25. package/dist-cjs/runtimeExtensions.js +22 -0
  26. package/dist-es/BedrockAgentRuntime.js +13 -0
  27. package/dist-es/BedrockAgentRuntimeClient.js +41 -0
  28. package/dist-es/commands/InvokeAgentCommand.js +48 -0
  29. package/dist-es/commands/RetrieveAndGenerateCommand.js +48 -0
  30. package/dist-es/commands/RetrieveCommand.js +48 -0
  31. package/dist-es/commands/index.js +3 -0
  32. package/dist-es/endpoint/EndpointParameters.js +8 -0
  33. package/dist-es/endpoint/endpointResolver.js +8 -0
  34. package/dist-es/endpoint/ruleset.js +4 -0
  35. package/dist-es/extensionConfiguration.js +1 -0
  36. package/dist-es/index.js +7 -0
  37. package/dist-es/models/BedrockAgentRuntimeServiceException.js +8 -0
  38. package/dist-es/models/index.js +1 -0
  39. package/dist-es/models/models_0.js +396 -0
  40. package/dist-es/pagination/Interfaces.js +1 -0
  41. package/dist-es/pagination/RetrievePaginator.js +24 -0
  42. package/dist-es/pagination/index.js +2 -0
  43. package/dist-es/protocols/Aws_restJson1.js +680 -0
  44. package/dist-es/runtimeConfig.browser.js +36 -0
  45. package/dist-es/runtimeConfig.js +47 -0
  46. package/dist-es/runtimeConfig.native.js +11 -0
  47. package/dist-es/runtimeConfig.shared.js +20 -0
  48. package/dist-es/runtimeExtensions.js +18 -0
  49. package/dist-types/BedrockAgentRuntime.d.ts +31 -0
  50. package/dist-types/BedrockAgentRuntimeClient.d.ts +177 -0
  51. package/dist-types/commands/InvokeAgentCommand.d.ts +321 -0
  52. package/dist-types/commands/RetrieveAndGenerateCommand.d.ts +142 -0
  53. package/dist-types/commands/RetrieveCommand.d.ts +123 -0
  54. package/dist-types/commands/index.d.ts +3 -0
  55. package/dist-types/endpoint/EndpointParameters.d.ts +22 -0
  56. package/dist-types/endpoint/endpointResolver.d.ts +5 -0
  57. package/dist-types/endpoint/ruleset.d.ts +2 -0
  58. package/dist-types/extensionConfiguration.d.ts +8 -0
  59. package/dist-types/index.d.ts +15 -0
  60. package/dist-types/models/BedrockAgentRuntimeServiceException.d.ts +13 -0
  61. package/dist-types/models/index.d.ts +1 -0
  62. package/dist-types/models/models_0.d.ts +1598 -0
  63. package/dist-types/pagination/Interfaces.d.ts +8 -0
  64. package/dist-types/pagination/RetrievePaginator.d.ts +7 -0
  65. package/dist-types/pagination/index.d.ts +2 -0
  66. package/dist-types/protocols/Aws_restJson1.d.ts +29 -0
  67. package/dist-types/runtimeConfig.browser.d.ts +47 -0
  68. package/dist-types/runtimeConfig.d.ts +47 -0
  69. package/dist-types/runtimeConfig.native.d.ts +46 -0
  70. package/dist-types/runtimeConfig.shared.d.ts +19 -0
  71. package/dist-types/runtimeExtensions.d.ts +17 -0
  72. package/dist-types/ts3.4/BedrockAgentRuntime.d.ts +58 -0
  73. package/dist-types/ts3.4/BedrockAgentRuntimeClient.d.ts +147 -0
  74. package/dist-types/ts3.4/commands/InvokeAgentCommand.d.ts +35 -0
  75. package/dist-types/ts3.4/commands/RetrieveAndGenerateCommand.d.ts +39 -0
  76. package/dist-types/ts3.4/commands/RetrieveCommand.d.ts +35 -0
  77. package/dist-types/ts3.4/commands/index.d.ts +3 -0
  78. package/dist-types/ts3.4/endpoint/EndpointParameters.d.ts +33 -0
  79. package/dist-types/ts3.4/endpoint/endpointResolver.d.ts +8 -0
  80. package/dist-types/ts3.4/endpoint/ruleset.d.ts +2 -0
  81. package/dist-types/ts3.4/extensionConfiguration.d.ts +7 -0
  82. package/dist-types/ts3.4/index.d.ts +10 -0
  83. package/dist-types/ts3.4/models/BedrockAgentRuntimeServiceException.d.ts +8 -0
  84. package/dist-types/ts3.4/models/index.d.ts +1 -0
  85. package/dist-types/ts3.4/models/models_0.d.ts +737 -0
  86. package/dist-types/ts3.4/pagination/Interfaces.d.ts +6 -0
  87. package/dist-types/ts3.4/pagination/RetrievePaginator.d.ts +11 -0
  88. package/dist-types/ts3.4/pagination/index.d.ts +2 -0
  89. package/dist-types/ts3.4/protocols/Aws_restJson1.d.ts +44 -0
  90. package/dist-types/ts3.4/runtimeConfig.browser.d.ts +100 -0
  91. package/dist-types/ts3.4/runtimeConfig.d.ts +100 -0
  92. package/dist-types/ts3.4/runtimeConfig.native.d.ts +91 -0
  93. package/dist-types/ts3.4/runtimeConfig.shared.d.ts +21 -0
  94. package/dist-types/ts3.4/runtimeExtensions.d.ts +13 -0
  95. package/package.json +105 -0
@@ -0,0 +1,689 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.de_RetrieveAndGenerateCommand = exports.de_RetrieveCommand = exports.de_InvokeAgentCommand = exports.se_RetrieveAndGenerateCommand = exports.se_RetrieveCommand = exports.se_InvokeAgentCommand = void 0;
4
+ const core_1 = require("@aws-sdk/core");
5
+ const protocol_http_1 = require("@smithy/protocol-http");
6
+ const smithy_client_1 = require("@smithy/smithy-client");
7
+ const BedrockAgentRuntimeServiceException_1 = require("../models/BedrockAgentRuntimeServiceException");
8
+ const models_0_1 = require("../models/models_0");
9
+ const se_InvokeAgentCommand = async (input, context) => {
10
+ const { hostname, protocol = "https", port, path: basePath } = await context.endpoint();
11
+ const headers = {
12
+ "content-type": "application/json",
13
+ };
14
+ let resolvedPath = `${basePath?.endsWith("/") ? basePath.slice(0, -1) : basePath || ""}` +
15
+ "/agents/{agentId}/agentAliases/{agentAliasId}/sessions/{sessionId}/text";
16
+ resolvedPath = (0, smithy_client_1.resolvedPath)(resolvedPath, input, "agentId", () => input.agentId, "{agentId}", false);
17
+ resolvedPath = (0, smithy_client_1.resolvedPath)(resolvedPath, input, "agentAliasId", () => input.agentAliasId, "{agentAliasId}", false);
18
+ resolvedPath = (0, smithy_client_1.resolvedPath)(resolvedPath, input, "sessionId", () => input.sessionId, "{sessionId}", false);
19
+ let body;
20
+ body = JSON.stringify((0, smithy_client_1.take)(input, {
21
+ enableTrace: [],
22
+ endSession: [],
23
+ inputText: [],
24
+ sessionState: (_) => (0, smithy_client_1._json)(_),
25
+ }));
26
+ return new protocol_http_1.HttpRequest({
27
+ protocol,
28
+ hostname,
29
+ port,
30
+ method: "POST",
31
+ headers,
32
+ path: resolvedPath,
33
+ body,
34
+ });
35
+ };
36
+ exports.se_InvokeAgentCommand = se_InvokeAgentCommand;
37
+ const se_RetrieveCommand = async (input, context) => {
38
+ const { hostname, protocol = "https", port, path: basePath } = await context.endpoint();
39
+ const headers = {
40
+ "content-type": "application/json",
41
+ };
42
+ let resolvedPath = `${basePath?.endsWith("/") ? basePath.slice(0, -1) : basePath || ""}` +
43
+ "/knowledgebases/{knowledgeBaseId}/retrieve";
44
+ resolvedPath = (0, smithy_client_1.resolvedPath)(resolvedPath, input, "knowledgeBaseId", () => input.knowledgeBaseId, "{knowledgeBaseId}", false);
45
+ let body;
46
+ body = JSON.stringify((0, smithy_client_1.take)(input, {
47
+ nextToken: [],
48
+ retrievalConfiguration: (_) => (0, smithy_client_1._json)(_),
49
+ retrievalQuery: (_) => (0, smithy_client_1._json)(_),
50
+ }));
51
+ return new protocol_http_1.HttpRequest({
52
+ protocol,
53
+ hostname,
54
+ port,
55
+ method: "POST",
56
+ headers,
57
+ path: resolvedPath,
58
+ body,
59
+ });
60
+ };
61
+ exports.se_RetrieveCommand = se_RetrieveCommand;
62
+ const se_RetrieveAndGenerateCommand = async (input, context) => {
63
+ const { hostname, protocol = "https", port, path: basePath } = await context.endpoint();
64
+ const headers = {
65
+ "content-type": "application/json",
66
+ };
67
+ const resolvedPath = `${basePath?.endsWith("/") ? basePath.slice(0, -1) : basePath || ""}` + "/retrieveAndGenerate";
68
+ let body;
69
+ body = JSON.stringify((0, smithy_client_1.take)(input, {
70
+ input: (_) => (0, smithy_client_1._json)(_),
71
+ retrieveAndGenerateConfiguration: (_) => (0, smithy_client_1._json)(_),
72
+ sessionConfiguration: (_) => (0, smithy_client_1._json)(_),
73
+ sessionId: [],
74
+ }));
75
+ return new protocol_http_1.HttpRequest({
76
+ protocol,
77
+ hostname,
78
+ port,
79
+ method: "POST",
80
+ headers,
81
+ path: resolvedPath,
82
+ body,
83
+ });
84
+ };
85
+ exports.se_RetrieveAndGenerateCommand = se_RetrieveAndGenerateCommand;
86
+ const de_InvokeAgentCommand = async (output, context) => {
87
+ if (output.statusCode !== 200 && output.statusCode >= 300) {
88
+ return de_InvokeAgentCommandError(output, context);
89
+ }
90
+ const contents = (0, smithy_client_1.map)({
91
+ $metadata: deserializeMetadata(output),
92
+ contentType: [, output.headers["x-amzn-bedrock-agent-content-type"]],
93
+ sessionId: [, output.headers["x-amz-bedrock-agent-session-id"]],
94
+ });
95
+ const data = output.body;
96
+ contents.completion = de_ResponseStream(data, context);
97
+ return contents;
98
+ };
99
+ exports.de_InvokeAgentCommand = de_InvokeAgentCommand;
100
+ const de_InvokeAgentCommandError = async (output, context) => {
101
+ const parsedOutput = {
102
+ ...output,
103
+ body: await parseErrorBody(output.body, context),
104
+ };
105
+ const errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
106
+ switch (errorCode) {
107
+ case "AccessDeniedException":
108
+ case "com.amazonaws.bedrockagentruntime#AccessDeniedException":
109
+ throw await de_AccessDeniedExceptionRes(parsedOutput, context);
110
+ case "BadGatewayException":
111
+ case "com.amazonaws.bedrockagentruntime#BadGatewayException":
112
+ throw await de_BadGatewayExceptionRes(parsedOutput, context);
113
+ case "ConflictException":
114
+ case "com.amazonaws.bedrockagentruntime#ConflictException":
115
+ throw await de_ConflictExceptionRes(parsedOutput, context);
116
+ case "DependencyFailedException":
117
+ case "com.amazonaws.bedrockagentruntime#DependencyFailedException":
118
+ throw await de_DependencyFailedExceptionRes(parsedOutput, context);
119
+ case "InternalServerException":
120
+ case "com.amazonaws.bedrockagentruntime#InternalServerException":
121
+ throw await de_InternalServerExceptionRes(parsedOutput, context);
122
+ case "ResourceNotFoundException":
123
+ case "com.amazonaws.bedrockagentruntime#ResourceNotFoundException":
124
+ throw await de_ResourceNotFoundExceptionRes(parsedOutput, context);
125
+ case "ServiceQuotaExceededException":
126
+ case "com.amazonaws.bedrockagentruntime#ServiceQuotaExceededException":
127
+ throw await de_ServiceQuotaExceededExceptionRes(parsedOutput, context);
128
+ case "ThrottlingException":
129
+ case "com.amazonaws.bedrockagentruntime#ThrottlingException":
130
+ throw await de_ThrottlingExceptionRes(parsedOutput, context);
131
+ case "ValidationException":
132
+ case "com.amazonaws.bedrockagentruntime#ValidationException":
133
+ throw await de_ValidationExceptionRes(parsedOutput, context);
134
+ default:
135
+ const parsedBody = parsedOutput.body;
136
+ return throwDefaultError({
137
+ output,
138
+ parsedBody,
139
+ errorCode,
140
+ });
141
+ }
142
+ };
143
+ const de_RetrieveCommand = async (output, context) => {
144
+ if (output.statusCode !== 200 && output.statusCode >= 300) {
145
+ return de_RetrieveCommandError(output, context);
146
+ }
147
+ const contents = (0, smithy_client_1.map)({
148
+ $metadata: deserializeMetadata(output),
149
+ });
150
+ const data = (0, smithy_client_1.expectNonNull)((0, smithy_client_1.expectObject)(await parseBody(output.body, context)), "body");
151
+ const doc = (0, smithy_client_1.take)(data, {
152
+ nextToken: smithy_client_1.expectString,
153
+ retrievalResults: (_) => de_KnowledgeBaseRetrievalResults(_, context),
154
+ });
155
+ Object.assign(contents, doc);
156
+ return contents;
157
+ };
158
+ exports.de_RetrieveCommand = de_RetrieveCommand;
159
+ const de_RetrieveCommandError = async (output, context) => {
160
+ const parsedOutput = {
161
+ ...output,
162
+ body: await parseErrorBody(output.body, context),
163
+ };
164
+ const errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
165
+ switch (errorCode) {
166
+ case "AccessDeniedException":
167
+ case "com.amazonaws.bedrockagentruntime#AccessDeniedException":
168
+ throw await de_AccessDeniedExceptionRes(parsedOutput, context);
169
+ case "BadGatewayException":
170
+ case "com.amazonaws.bedrockagentruntime#BadGatewayException":
171
+ throw await de_BadGatewayExceptionRes(parsedOutput, context);
172
+ case "ConflictException":
173
+ case "com.amazonaws.bedrockagentruntime#ConflictException":
174
+ throw await de_ConflictExceptionRes(parsedOutput, context);
175
+ case "DependencyFailedException":
176
+ case "com.amazonaws.bedrockagentruntime#DependencyFailedException":
177
+ throw await de_DependencyFailedExceptionRes(parsedOutput, context);
178
+ case "InternalServerException":
179
+ case "com.amazonaws.bedrockagentruntime#InternalServerException":
180
+ throw await de_InternalServerExceptionRes(parsedOutput, context);
181
+ case "ResourceNotFoundException":
182
+ case "com.amazonaws.bedrockagentruntime#ResourceNotFoundException":
183
+ throw await de_ResourceNotFoundExceptionRes(parsedOutput, context);
184
+ case "ServiceQuotaExceededException":
185
+ case "com.amazonaws.bedrockagentruntime#ServiceQuotaExceededException":
186
+ throw await de_ServiceQuotaExceededExceptionRes(parsedOutput, context);
187
+ case "ThrottlingException":
188
+ case "com.amazonaws.bedrockagentruntime#ThrottlingException":
189
+ throw await de_ThrottlingExceptionRes(parsedOutput, context);
190
+ case "ValidationException":
191
+ case "com.amazonaws.bedrockagentruntime#ValidationException":
192
+ throw await de_ValidationExceptionRes(parsedOutput, context);
193
+ default:
194
+ const parsedBody = parsedOutput.body;
195
+ return throwDefaultError({
196
+ output,
197
+ parsedBody,
198
+ errorCode,
199
+ });
200
+ }
201
+ };
202
+ const de_RetrieveAndGenerateCommand = async (output, context) => {
203
+ if (output.statusCode !== 200 && output.statusCode >= 300) {
204
+ return de_RetrieveAndGenerateCommandError(output, context);
205
+ }
206
+ const contents = (0, smithy_client_1.map)({
207
+ $metadata: deserializeMetadata(output),
208
+ });
209
+ const data = (0, smithy_client_1.expectNonNull)((0, smithy_client_1.expectObject)(await parseBody(output.body, context)), "body");
210
+ const doc = (0, smithy_client_1.take)(data, {
211
+ citations: smithy_client_1._json,
212
+ output: smithy_client_1._json,
213
+ sessionId: smithy_client_1.expectString,
214
+ });
215
+ Object.assign(contents, doc);
216
+ return contents;
217
+ };
218
+ exports.de_RetrieveAndGenerateCommand = de_RetrieveAndGenerateCommand;
219
+ const de_RetrieveAndGenerateCommandError = async (output, context) => {
220
+ const parsedOutput = {
221
+ ...output,
222
+ body: await parseErrorBody(output.body, context),
223
+ };
224
+ const errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
225
+ switch (errorCode) {
226
+ case "AccessDeniedException":
227
+ case "com.amazonaws.bedrockagentruntime#AccessDeniedException":
228
+ throw await de_AccessDeniedExceptionRes(parsedOutput, context);
229
+ case "BadGatewayException":
230
+ case "com.amazonaws.bedrockagentruntime#BadGatewayException":
231
+ throw await de_BadGatewayExceptionRes(parsedOutput, context);
232
+ case "ConflictException":
233
+ case "com.amazonaws.bedrockagentruntime#ConflictException":
234
+ throw await de_ConflictExceptionRes(parsedOutput, context);
235
+ case "DependencyFailedException":
236
+ case "com.amazonaws.bedrockagentruntime#DependencyFailedException":
237
+ throw await de_DependencyFailedExceptionRes(parsedOutput, context);
238
+ case "InternalServerException":
239
+ case "com.amazonaws.bedrockagentruntime#InternalServerException":
240
+ throw await de_InternalServerExceptionRes(parsedOutput, context);
241
+ case "ResourceNotFoundException":
242
+ case "com.amazonaws.bedrockagentruntime#ResourceNotFoundException":
243
+ throw await de_ResourceNotFoundExceptionRes(parsedOutput, context);
244
+ case "ServiceQuotaExceededException":
245
+ case "com.amazonaws.bedrockagentruntime#ServiceQuotaExceededException":
246
+ throw await de_ServiceQuotaExceededExceptionRes(parsedOutput, context);
247
+ case "ThrottlingException":
248
+ case "com.amazonaws.bedrockagentruntime#ThrottlingException":
249
+ throw await de_ThrottlingExceptionRes(parsedOutput, context);
250
+ case "ValidationException":
251
+ case "com.amazonaws.bedrockagentruntime#ValidationException":
252
+ throw await de_ValidationExceptionRes(parsedOutput, context);
253
+ default:
254
+ const parsedBody = parsedOutput.body;
255
+ return throwDefaultError({
256
+ output,
257
+ parsedBody,
258
+ errorCode,
259
+ });
260
+ }
261
+ };
262
+ const throwDefaultError = (0, smithy_client_1.withBaseException)(BedrockAgentRuntimeServiceException_1.BedrockAgentRuntimeServiceException);
263
+ const de_AccessDeniedExceptionRes = async (parsedOutput, context) => {
264
+ const contents = (0, smithy_client_1.map)({});
265
+ const data = parsedOutput.body;
266
+ const doc = (0, smithy_client_1.take)(data, {
267
+ message: smithy_client_1.expectString,
268
+ });
269
+ Object.assign(contents, doc);
270
+ const exception = new models_0_1.AccessDeniedException({
271
+ $metadata: deserializeMetadata(parsedOutput),
272
+ ...contents,
273
+ });
274
+ return (0, smithy_client_1.decorateServiceException)(exception, parsedOutput.body);
275
+ };
276
+ const de_BadGatewayExceptionRes = async (parsedOutput, context) => {
277
+ const contents = (0, smithy_client_1.map)({});
278
+ const data = parsedOutput.body;
279
+ const doc = (0, smithy_client_1.take)(data, {
280
+ message: smithy_client_1.expectString,
281
+ resourceName: smithy_client_1.expectString,
282
+ });
283
+ Object.assign(contents, doc);
284
+ const exception = new models_0_1.BadGatewayException({
285
+ $metadata: deserializeMetadata(parsedOutput),
286
+ ...contents,
287
+ });
288
+ return (0, smithy_client_1.decorateServiceException)(exception, parsedOutput.body);
289
+ };
290
+ const de_ConflictExceptionRes = async (parsedOutput, context) => {
291
+ const contents = (0, smithy_client_1.map)({});
292
+ const data = parsedOutput.body;
293
+ const doc = (0, smithy_client_1.take)(data, {
294
+ message: smithy_client_1.expectString,
295
+ });
296
+ Object.assign(contents, doc);
297
+ const exception = new models_0_1.ConflictException({
298
+ $metadata: deserializeMetadata(parsedOutput),
299
+ ...contents,
300
+ });
301
+ return (0, smithy_client_1.decorateServiceException)(exception, parsedOutput.body);
302
+ };
303
+ const de_DependencyFailedExceptionRes = async (parsedOutput, context) => {
304
+ const contents = (0, smithy_client_1.map)({});
305
+ const data = parsedOutput.body;
306
+ const doc = (0, smithy_client_1.take)(data, {
307
+ message: smithy_client_1.expectString,
308
+ resourceName: smithy_client_1.expectString,
309
+ });
310
+ Object.assign(contents, doc);
311
+ const exception = new models_0_1.DependencyFailedException({
312
+ $metadata: deserializeMetadata(parsedOutput),
313
+ ...contents,
314
+ });
315
+ return (0, smithy_client_1.decorateServiceException)(exception, parsedOutput.body);
316
+ };
317
+ const de_InternalServerExceptionRes = async (parsedOutput, context) => {
318
+ const contents = (0, smithy_client_1.map)({});
319
+ const data = parsedOutput.body;
320
+ const doc = (0, smithy_client_1.take)(data, {
321
+ message: smithy_client_1.expectString,
322
+ });
323
+ Object.assign(contents, doc);
324
+ const exception = new models_0_1.InternalServerException({
325
+ $metadata: deserializeMetadata(parsedOutput),
326
+ ...contents,
327
+ });
328
+ return (0, smithy_client_1.decorateServiceException)(exception, parsedOutput.body);
329
+ };
330
+ const de_ResourceNotFoundExceptionRes = async (parsedOutput, context) => {
331
+ const contents = (0, smithy_client_1.map)({});
332
+ const data = parsedOutput.body;
333
+ const doc = (0, smithy_client_1.take)(data, {
334
+ message: smithy_client_1.expectString,
335
+ });
336
+ Object.assign(contents, doc);
337
+ const exception = new models_0_1.ResourceNotFoundException({
338
+ $metadata: deserializeMetadata(parsedOutput),
339
+ ...contents,
340
+ });
341
+ return (0, smithy_client_1.decorateServiceException)(exception, parsedOutput.body);
342
+ };
343
+ const de_ServiceQuotaExceededExceptionRes = async (parsedOutput, context) => {
344
+ const contents = (0, smithy_client_1.map)({});
345
+ const data = parsedOutput.body;
346
+ const doc = (0, smithy_client_1.take)(data, {
347
+ message: smithy_client_1.expectString,
348
+ });
349
+ Object.assign(contents, doc);
350
+ const exception = new models_0_1.ServiceQuotaExceededException({
351
+ $metadata: deserializeMetadata(parsedOutput),
352
+ ...contents,
353
+ });
354
+ return (0, smithy_client_1.decorateServiceException)(exception, parsedOutput.body);
355
+ };
356
+ const de_ThrottlingExceptionRes = async (parsedOutput, context) => {
357
+ const contents = (0, smithy_client_1.map)({});
358
+ const data = parsedOutput.body;
359
+ const doc = (0, smithy_client_1.take)(data, {
360
+ message: smithy_client_1.expectString,
361
+ });
362
+ Object.assign(contents, doc);
363
+ const exception = new models_0_1.ThrottlingException({
364
+ $metadata: deserializeMetadata(parsedOutput),
365
+ ...contents,
366
+ });
367
+ return (0, smithy_client_1.decorateServiceException)(exception, parsedOutput.body);
368
+ };
369
+ const de_ValidationExceptionRes = async (parsedOutput, context) => {
370
+ const contents = (0, smithy_client_1.map)({});
371
+ const data = parsedOutput.body;
372
+ const doc = (0, smithy_client_1.take)(data, {
373
+ message: smithy_client_1.expectString,
374
+ });
375
+ Object.assign(contents, doc);
376
+ const exception = new models_0_1.ValidationException({
377
+ $metadata: deserializeMetadata(parsedOutput),
378
+ ...contents,
379
+ });
380
+ return (0, smithy_client_1.decorateServiceException)(exception, parsedOutput.body);
381
+ };
382
+ const de_ResponseStream = (output, context) => {
383
+ return context.eventStreamMarshaller.deserialize(output, async (event) => {
384
+ if (event["chunk"] != null) {
385
+ return {
386
+ chunk: await de_PayloadPart_event(event["chunk"], context),
387
+ };
388
+ }
389
+ if (event["trace"] != null) {
390
+ return {
391
+ trace: await de_TracePart_event(event["trace"], context),
392
+ };
393
+ }
394
+ if (event["internalServerException"] != null) {
395
+ return {
396
+ internalServerException: await de_InternalServerException_event(event["internalServerException"], context),
397
+ };
398
+ }
399
+ if (event["validationException"] != null) {
400
+ return {
401
+ validationException: await de_ValidationException_event(event["validationException"], context),
402
+ };
403
+ }
404
+ if (event["resourceNotFoundException"] != null) {
405
+ return {
406
+ resourceNotFoundException: await de_ResourceNotFoundException_event(event["resourceNotFoundException"], context),
407
+ };
408
+ }
409
+ if (event["serviceQuotaExceededException"] != null) {
410
+ return {
411
+ serviceQuotaExceededException: await de_ServiceQuotaExceededException_event(event["serviceQuotaExceededException"], context),
412
+ };
413
+ }
414
+ if (event["throttlingException"] != null) {
415
+ return {
416
+ throttlingException: await de_ThrottlingException_event(event["throttlingException"], context),
417
+ };
418
+ }
419
+ if (event["accessDeniedException"] != null) {
420
+ return {
421
+ accessDeniedException: await de_AccessDeniedException_event(event["accessDeniedException"], context),
422
+ };
423
+ }
424
+ if (event["conflictException"] != null) {
425
+ return {
426
+ conflictException: await de_ConflictException_event(event["conflictException"], context),
427
+ };
428
+ }
429
+ if (event["dependencyFailedException"] != null) {
430
+ return {
431
+ dependencyFailedException: await de_DependencyFailedException_event(event["dependencyFailedException"], context),
432
+ };
433
+ }
434
+ if (event["badGatewayException"] != null) {
435
+ return {
436
+ badGatewayException: await de_BadGatewayException_event(event["badGatewayException"], context),
437
+ };
438
+ }
439
+ return { $unknown: output };
440
+ });
441
+ };
442
+ const de_AccessDeniedException_event = async (output, context) => {
443
+ const parsedOutput = {
444
+ ...output,
445
+ body: await parseBody(output.body, context),
446
+ };
447
+ return de_AccessDeniedExceptionRes(parsedOutput, context);
448
+ };
449
+ const de_BadGatewayException_event = async (output, context) => {
450
+ const parsedOutput = {
451
+ ...output,
452
+ body: await parseBody(output.body, context),
453
+ };
454
+ return de_BadGatewayExceptionRes(parsedOutput, context);
455
+ };
456
+ const de_ConflictException_event = async (output, context) => {
457
+ const parsedOutput = {
458
+ ...output,
459
+ body: await parseBody(output.body, context),
460
+ };
461
+ return de_ConflictExceptionRes(parsedOutput, context);
462
+ };
463
+ const de_DependencyFailedException_event = async (output, context) => {
464
+ const parsedOutput = {
465
+ ...output,
466
+ body: await parseBody(output.body, context),
467
+ };
468
+ return de_DependencyFailedExceptionRes(parsedOutput, context);
469
+ };
470
+ const de_InternalServerException_event = async (output, context) => {
471
+ const parsedOutput = {
472
+ ...output,
473
+ body: await parseBody(output.body, context),
474
+ };
475
+ return de_InternalServerExceptionRes(parsedOutput, context);
476
+ };
477
+ const de_PayloadPart_event = async (output, context) => {
478
+ const contents = {};
479
+ const data = await parseBody(output.body, context);
480
+ Object.assign(contents, de_PayloadPart(data, context));
481
+ return contents;
482
+ };
483
+ const de_ResourceNotFoundException_event = async (output, context) => {
484
+ const parsedOutput = {
485
+ ...output,
486
+ body: await parseBody(output.body, context),
487
+ };
488
+ return de_ResourceNotFoundExceptionRes(parsedOutput, context);
489
+ };
490
+ const de_ServiceQuotaExceededException_event = async (output, context) => {
491
+ const parsedOutput = {
492
+ ...output,
493
+ body: await parseBody(output.body, context),
494
+ };
495
+ return de_ServiceQuotaExceededExceptionRes(parsedOutput, context);
496
+ };
497
+ const de_ThrottlingException_event = async (output, context) => {
498
+ const parsedOutput = {
499
+ ...output,
500
+ body: await parseBody(output.body, context),
501
+ };
502
+ return de_ThrottlingExceptionRes(parsedOutput, context);
503
+ };
504
+ const de_TracePart_event = async (output, context) => {
505
+ const contents = {};
506
+ const data = await parseBody(output.body, context);
507
+ Object.assign(contents, de_TracePart(data, context));
508
+ return contents;
509
+ };
510
+ const de_ValidationException_event = async (output, context) => {
511
+ const parsedOutput = {
512
+ ...output,
513
+ body: await parseBody(output.body, context),
514
+ };
515
+ return de_ValidationExceptionRes(parsedOutput, context);
516
+ };
517
+ const de_InferenceConfiguration = (output, context) => {
518
+ return (0, smithy_client_1.take)(output, {
519
+ maximumLength: smithy_client_1.expectInt32,
520
+ stopSequences: smithy_client_1._json,
521
+ temperature: smithy_client_1.limitedParseFloat32,
522
+ topK: smithy_client_1.expectInt32,
523
+ topP: smithy_client_1.limitedParseFloat32,
524
+ });
525
+ };
526
+ const de_KnowledgeBaseRetrievalResult = (output, context) => {
527
+ return (0, smithy_client_1.take)(output, {
528
+ content: smithy_client_1._json,
529
+ location: smithy_client_1._json,
530
+ score: smithy_client_1.limitedParseDouble,
531
+ });
532
+ };
533
+ const de_KnowledgeBaseRetrievalResults = (output, context) => {
534
+ const retVal = (output || [])
535
+ .filter((e) => e != null)
536
+ .map((entry) => {
537
+ return de_KnowledgeBaseRetrievalResult(entry, context);
538
+ });
539
+ return retVal;
540
+ };
541
+ const de_ModelInvocationInput = (output, context) => {
542
+ return (0, smithy_client_1.take)(output, {
543
+ inferenceConfiguration: (_) => de_InferenceConfiguration(_, context),
544
+ overrideLambda: smithy_client_1.expectString,
545
+ parserMode: smithy_client_1.expectString,
546
+ promptCreationMode: smithy_client_1.expectString,
547
+ text: smithy_client_1.expectString,
548
+ traceId: smithy_client_1.expectString,
549
+ type: smithy_client_1.expectString,
550
+ });
551
+ };
552
+ const de_OrchestrationTrace = (output, context) => {
553
+ if (output.invocationInput != null) {
554
+ return {
555
+ invocationInput: (0, smithy_client_1._json)(output.invocationInput),
556
+ };
557
+ }
558
+ if (output.modelInvocationInput != null) {
559
+ return {
560
+ modelInvocationInput: de_ModelInvocationInput(output.modelInvocationInput, context),
561
+ };
562
+ }
563
+ if (output.observation != null) {
564
+ return {
565
+ observation: (0, smithy_client_1._json)(output.observation),
566
+ };
567
+ }
568
+ if (output.rationale != null) {
569
+ return {
570
+ rationale: (0, smithy_client_1._json)(output.rationale),
571
+ };
572
+ }
573
+ return { $unknown: Object.entries(output)[0] };
574
+ };
575
+ const de_PayloadPart = (output, context) => {
576
+ return (0, smithy_client_1.take)(output, {
577
+ attribution: smithy_client_1._json,
578
+ bytes: context.base64Decoder,
579
+ });
580
+ };
581
+ const de_PostProcessingTrace = (output, context) => {
582
+ if (output.modelInvocationInput != null) {
583
+ return {
584
+ modelInvocationInput: de_ModelInvocationInput(output.modelInvocationInput, context),
585
+ };
586
+ }
587
+ if (output.modelInvocationOutput != null) {
588
+ return {
589
+ modelInvocationOutput: (0, smithy_client_1._json)(output.modelInvocationOutput),
590
+ };
591
+ }
592
+ return { $unknown: Object.entries(output)[0] };
593
+ };
594
+ const de_PreProcessingTrace = (output, context) => {
595
+ if (output.modelInvocationInput != null) {
596
+ return {
597
+ modelInvocationInput: de_ModelInvocationInput(output.modelInvocationInput, context),
598
+ };
599
+ }
600
+ if (output.modelInvocationOutput != null) {
601
+ return {
602
+ modelInvocationOutput: (0, smithy_client_1._json)(output.modelInvocationOutput),
603
+ };
604
+ }
605
+ return { $unknown: Object.entries(output)[0] };
606
+ };
607
+ const de_Trace = (output, context) => {
608
+ if (output.failureTrace != null) {
609
+ return {
610
+ failureTrace: (0, smithy_client_1._json)(output.failureTrace),
611
+ };
612
+ }
613
+ if (output.orchestrationTrace != null) {
614
+ return {
615
+ orchestrationTrace: de_OrchestrationTrace((0, core_1.awsExpectUnion)(output.orchestrationTrace), context),
616
+ };
617
+ }
618
+ if (output.postProcessingTrace != null) {
619
+ return {
620
+ postProcessingTrace: de_PostProcessingTrace((0, core_1.awsExpectUnion)(output.postProcessingTrace), context),
621
+ };
622
+ }
623
+ if (output.preProcessingTrace != null) {
624
+ return {
625
+ preProcessingTrace: de_PreProcessingTrace((0, core_1.awsExpectUnion)(output.preProcessingTrace), context),
626
+ };
627
+ }
628
+ return { $unknown: Object.entries(output)[0] };
629
+ };
630
+ const de_TracePart = (output, context) => {
631
+ return (0, smithy_client_1.take)(output, {
632
+ agentAliasId: smithy_client_1.expectString,
633
+ agentId: smithy_client_1.expectString,
634
+ sessionId: smithy_client_1.expectString,
635
+ trace: (_) => de_Trace((0, core_1.awsExpectUnion)(_), context),
636
+ });
637
+ };
638
+ const deserializeMetadata = (output) => ({
639
+ httpStatusCode: output.statusCode,
640
+ requestId: output.headers["x-amzn-requestid"] ?? output.headers["x-amzn-request-id"] ?? output.headers["x-amz-request-id"],
641
+ extendedRequestId: output.headers["x-amz-id-2"],
642
+ cfId: output.headers["x-amz-cf-id"],
643
+ });
644
+ const collectBodyString = (streamBody, context) => (0, smithy_client_1.collectBody)(streamBody, context).then((body) => context.utf8Encoder(body));
645
+ const isSerializableHeaderValue = (value) => value !== undefined &&
646
+ value !== null &&
647
+ value !== "" &&
648
+ (!Object.getOwnPropertyNames(value).includes("length") || value.length != 0) &&
649
+ (!Object.getOwnPropertyNames(value).includes("size") || value.size != 0);
650
+ const parseBody = (streamBody, context) => collectBodyString(streamBody, context).then((encoded) => {
651
+ if (encoded.length) {
652
+ return JSON.parse(encoded);
653
+ }
654
+ return {};
655
+ });
656
+ const parseErrorBody = async (errorBody, context) => {
657
+ const value = await parseBody(errorBody, context);
658
+ value.message = value.message ?? value.Message;
659
+ return value;
660
+ };
661
+ const loadRestJsonErrorCode = (output, data) => {
662
+ const findKey = (object, key) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase());
663
+ const sanitizeErrorCode = (rawValue) => {
664
+ let cleanValue = rawValue;
665
+ if (typeof cleanValue === "number") {
666
+ cleanValue = cleanValue.toString();
667
+ }
668
+ if (cleanValue.indexOf(",") >= 0) {
669
+ cleanValue = cleanValue.split(",")[0];
670
+ }
671
+ if (cleanValue.indexOf(":") >= 0) {
672
+ cleanValue = cleanValue.split(":")[0];
673
+ }
674
+ if (cleanValue.indexOf("#") >= 0) {
675
+ cleanValue = cleanValue.split("#")[1];
676
+ }
677
+ return cleanValue;
678
+ };
679
+ const headerKey = findKey(output.headers, "x-amzn-errortype");
680
+ if (headerKey !== undefined) {
681
+ return sanitizeErrorCode(output.headers[headerKey]);
682
+ }
683
+ if (data.code !== undefined) {
684
+ return sanitizeErrorCode(data.code);
685
+ }
686
+ if (data["__type"] !== undefined) {
687
+ return sanitizeErrorCode(data["__type"]);
688
+ }
689
+ };