AWS_restJson1.mjs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. // Copied from https://github.com/aws/aws-sdk-js-v3/blob/bee66fbd2a519a16b57c787b2689af857af720af/clients/client-bedrock-runtime/src/protocols/Aws_restJson1.ts
  2. // Modified to remove unnecessary code (we only need to call `de_ResponseStream`) and to adjust imports.
  3. import { collectBody, decorateServiceException as __decorateServiceException, expectInt32 as __expectInt32, expectString as __expectString, map, take, } from '@smithy/smithy-client';
  4. import { InternalServerException, ModelStreamErrorException, ThrottlingException, ValidationException, } from '@aws-sdk/client-bedrock-runtime';
  5. /**
  6. * deserializeAws_restJson1InternalServerExceptionRes
  7. */
  8. const de_InternalServerExceptionRes = async (parsedOutput, context) => {
  9. const contents = map({});
  10. const data = parsedOutput.body;
  11. const doc = take(data, {
  12. message: __expectString,
  13. });
  14. Object.assign(contents, doc);
  15. const exception = new InternalServerException({
  16. $metadata: deserializeMetadata(parsedOutput),
  17. ...contents,
  18. });
  19. return __decorateServiceException(exception, parsedOutput.body);
  20. };
  21. /**
  22. * deserializeAws_restJson1ModelStreamErrorExceptionRes
  23. */
  24. const de_ModelStreamErrorExceptionRes = async (parsedOutput, context) => {
  25. const contents = map({});
  26. const data = parsedOutput.body;
  27. const doc = take(data, {
  28. message: __expectString,
  29. originalMessage: __expectString,
  30. originalStatusCode: __expectInt32,
  31. });
  32. Object.assign(contents, doc);
  33. const exception = new ModelStreamErrorException({
  34. $metadata: deserializeMetadata(parsedOutput),
  35. ...contents,
  36. });
  37. return __decorateServiceException(exception, parsedOutput.body);
  38. };
  39. /**
  40. * deserializeAws_restJson1ThrottlingExceptionRes
  41. */
  42. const de_ThrottlingExceptionRes = async (parsedOutput, context) => {
  43. const contents = map({});
  44. const data = parsedOutput.body;
  45. const doc = take(data, {
  46. message: __expectString,
  47. });
  48. Object.assign(contents, doc);
  49. const exception = new ThrottlingException({
  50. $metadata: deserializeMetadata(parsedOutput),
  51. ...contents,
  52. });
  53. return __decorateServiceException(exception, parsedOutput.body);
  54. };
  55. /**
  56. * deserializeAws_restJson1ValidationExceptionRes
  57. */
  58. const de_ValidationExceptionRes = async (parsedOutput, context) => {
  59. const contents = map({});
  60. const data = parsedOutput.body;
  61. const doc = take(data, {
  62. message: __expectString,
  63. });
  64. Object.assign(contents, doc);
  65. const exception = new ValidationException({
  66. $metadata: deserializeMetadata(parsedOutput),
  67. ...contents,
  68. });
  69. return __decorateServiceException(exception, parsedOutput.body);
  70. };
  71. /**
  72. * deserializeAws_restJson1ResponseStream
  73. */
  74. export const de_ResponseStream = (output, context) => {
  75. return context.eventStreamMarshaller.deserialize(output, async (event) => {
  76. if (event['chunk'] != null) {
  77. return {
  78. chunk: await de_PayloadPart_event(event['chunk'], context),
  79. };
  80. }
  81. if (event['internalServerException'] != null) {
  82. return {
  83. internalServerException: await de_InternalServerException_event(event['internalServerException'], context),
  84. };
  85. }
  86. if (event['modelStreamErrorException'] != null) {
  87. return {
  88. modelStreamErrorException: await de_ModelStreamErrorException_event(event['modelStreamErrorException'], context),
  89. };
  90. }
  91. if (event['validationException'] != null) {
  92. return {
  93. validationException: await de_ValidationException_event(event['validationException'], context),
  94. };
  95. }
  96. if (event['throttlingException'] != null) {
  97. return {
  98. throttlingException: await de_ThrottlingException_event(event['throttlingException'], context),
  99. };
  100. }
  101. return { $unknown: output };
  102. });
  103. };
  104. const de_InternalServerException_event = async (output, context) => {
  105. const parsedOutput = {
  106. ...output,
  107. body: await parseBody(output.body, context),
  108. };
  109. return de_InternalServerExceptionRes(parsedOutput, context);
  110. };
  111. const de_ModelStreamErrorException_event = async (output, context) => {
  112. const parsedOutput = {
  113. ...output,
  114. body: await parseBody(output.body, context),
  115. };
  116. return de_ModelStreamErrorExceptionRes(parsedOutput, context);
  117. };
  118. const de_PayloadPart_event = async (output, context) => {
  119. const contents = {};
  120. const data = await parseBody(output.body, context);
  121. Object.assign(contents, de_PayloadPart(data, context));
  122. return contents;
  123. };
  124. const de_ThrottlingException_event = async (output, context) => {
  125. const parsedOutput = {
  126. ...output,
  127. body: await parseBody(output.body, context),
  128. };
  129. return de_ThrottlingExceptionRes(parsedOutput, context);
  130. };
  131. const de_ValidationException_event = async (output, context) => {
  132. const parsedOutput = {
  133. ...output,
  134. body: await parseBody(output.body, context),
  135. };
  136. return de_ValidationExceptionRes(parsedOutput, context);
  137. };
  138. /**
  139. * deserializeAws_restJson1PayloadPart
  140. */
  141. const de_PayloadPart = (output, context) => {
  142. return take(output, {
  143. bytes: context.base64Decoder,
  144. });
  145. };
  146. const deserializeMetadata = (output) => ({
  147. httpStatusCode: output.statusCode,
  148. requestId: output.headers['x-amzn-requestid'] ??
  149. output.headers['x-amzn-request-id'] ??
  150. output.headers['x-amz-request-id'] ??
  151. '',
  152. extendedRequestId: output.headers['x-amz-id-2'] ?? '',
  153. cfId: output.headers['x-amz-cf-id'] ?? '',
  154. });
  155. // Encode Uint8Array data into string with utf-8.
  156. const collectBodyString = (streamBody, context) => collectBody(streamBody, context).then((body) => context.utf8Encoder(body));
  157. const parseBody = (streamBody, context) => collectBodyString(streamBody, context).then((encoded) => {
  158. if (encoded.length) {
  159. return JSON.parse(encoded);
  160. }
  161. return {};
  162. });
  163. //# sourceMappingURL=AWS_restJson1.mjs.map