import { HttpRequest as __HttpRequest , HttpResponse as __HttpResponse } from "@aws-sdk/protocol-http" ; import { expectInt32 as __expectInt32 , expectNonNull as __expectNonNull , expectObject as __expectObject , expectString as __expectString , extendedEncodeURIComponent as __extendedEncodeURIComponent , LazyJsonString as __LazyJsonString , limitedParseDouble as __limitedParseDouble , } from "@aws-sdk/smithy-client" ; import { Endpoint as __Endpoint , MetadataBearer as __MetadataBearer , ResponseMetadata as __ResponseMetadata , SerdeContext as __SerdeContext , SmithyException as __SmithyException , } from "@aws-sdk/types" ; import { DeleteSessionCommandInput , DeleteSessionCommandOutput } from "../commands/DeleteSessionCommand" ; import { GetSessionCommandInput , GetSessionCommandOutput } from "../commands/GetSessionCommand" ; import { PostContentCommandInput , PostContentCommandOutput } from "../commands/PostContentCommand" ; import { PostTextCommandInput , PostTextCommandOutput } from "../commands/PostTextCommand" ; import { PutSessionCommandInput , PutSessionCommandOutput } from "../commands/PutSessionCommand" ; import { ActiveContext , ActiveContextTimeToLive , BadGatewayException , BadRequestException , Button , ConflictException , DependencyFailedException , DialogAction , GenericAttachment , IntentConfidence , IntentSummary , InternalFailureException , LimitExceededException , LoopDetectedException , NotAcceptableException , NotFoundException , PredictedIntent , RequestTimeoutException , ResponseCard , SentimentResponse , UnsupportedMediaTypeException , } from "../models/models_0" ; export const serializeAws_restJson1DeleteSessionCommand = async ( input , context ) : Promise < __HttpRequest > => { const { hostname , protocol = "https" , port , path : basePath } = await context . endpoint ( ) ; const headers = { } ; let resolvedPath = `${ basePath ?. endsWith ( "/" ) ? basePath . slice ( 0 , - 1 ) : basePath || "" }` + "/bot/{botName}/alias/{botAlias}/user/{userId}/session" ; if ( input . botName !== undefined ) { const labelValue = input . botName ; if ( labelValue . length <= 0 ) { throw new Error ( "Empty value provided for input HTTP label: botName." ) ; } resolvedPath = resolvedPath . replace ( "{botName}" , __extendedEncodeURIComponent ( labelValue ) ) ; } else { throw new Error ( "No value provided for input HTTP label: botName." ) ; } if ( input . botAlias !== undefined ) { const labelValue = input . botAlias ; if ( labelValue . length <= 0 ) { throw new Error ( "Empty value provided for input HTTP label: botAlias." ) ; } resolvedPath = resolvedPath . replace ( "{botAlias}" , __extendedEncodeURIComponent ( labelValue ) ) ; } else { throw new Error ( "No value provided for input HTTP label: botAlias." ) ; } if ( input . userId !== undefined ) { const labelValue = input . userId ; if ( labelValue . length <= 0 ) { throw new Error ( "Empty value provided for input HTTP label: userId." ) ; } resolvedPath = resolvedPath . replace ( "{userId}" , __extendedEncodeURIComponent ( labelValue ) ) ; } else { throw new Error ( "No value provided for input HTTP label: userId." ) ; } let body ; return new __HttpRequest ( { protocol , hostname , port , method : "DELETE" , headers , path : resolvedPath , body , } ) ; } ; export const serializeAws_restJson1GetSessionCommand = async ( input , context ) : Promise < __HttpRequest > => { const { hostname , protocol = "https" , port , path : basePath } = await context . endpoint ( ) ; const headers = { } ; let resolvedPath = `${ basePath ?. endsWith ( "/" ) ? basePath . slice ( 0 , - 1 ) : basePath || "" }` + "/bot/{botName}/alias/{botAlias}/user/{userId}/session" ; if ( input . botName !== undefined ) { const labelValue = input . botName ; if ( labelValue . length <= 0 ) { throw new Error ( "Empty value provided for input HTTP label: botName." ) ; } resolvedPath = resolvedPath . replace ( "{botName}" , __extendedEncodeURIComponent ( labelValue ) ) ; } else { throw new Error ( "No value provided for input HTTP label: botName." ) ; } if ( input . botAlias !== undefined ) { const labelValue = input . botAlias ; if ( labelValue . length <= 0 ) { throw new Error ( "Empty value provided for input HTTP label: botAlias." ) ; } resolvedPath = resolvedPath . replace ( "{botAlias}" , __extendedEncodeURIComponent ( labelValue ) ) ; } else { throw new Error ( "No value provided for input HTTP label: botAlias." ) ; } if ( input . userId !== undefined ) { const labelValue = input . userId ; if ( labelValue . length <= 0 ) { throw new Error ( "Empty value provided for input HTTP label: userId." ) ; } resolvedPath = resolvedPath . replace ( "{userId}" , __extendedEncodeURIComponent ( labelValue ) ) ; } else { throw new Error ( "No value provided for input HTTP label: userId." ) ; } const query = { ... ( input . checkpointLabelFilter !== undefined && { checkpointLabelFilter : input . checkpointLabelFilter } ) , } ; let body ; return new __HttpRequest ( { protocol , hostname , port , method : "GET" , headers , path : resolvedPath , query , body , } ) ; } ; export const serializeAws_restJson1PostContentCommand = async ( input , context ) : Promise < __HttpRequest > => { const { hostname , protocol = "https" , port , path : basePath } = await context . endpoint ( ) ; const headers = { "content-type" : "application/octet-stream" , "x-amz-content-sha256" : "UNSIGNED-PAYLOAD" , ... ( isSerializableHeaderValue ( input . sessionAttributes ) && { "x-amz-lex-session-attributes" : context . base64Encoder ( Buffer . from ( __LazyJsonString . fromObject ( input . sessionAttributes ! ) ) ) , } ) , ... ( isSerializableHeaderValue ( input . requestAttributes ) && { "x-amz-lex-request-attributes" : context . base64Encoder ( Buffer . from ( __LazyJsonString . fromObject ( input . requestAttributes ! ) ) ) , } ) , ... ( isSerializableHeaderValue ( input . contentType ) && { "content-type" : input . contentType ! } ) , ... ( isSerializableHeaderValue ( input . accept ) && { accept : input . accept ! } ) , ... ( isSerializableHeaderValue ( input . activeContexts ) && { "x-amz-lex-active-contexts" : context . base64Encoder ( Buffer . from ( __LazyJsonString . fromObject ( input . activeContexts ! ) ) ) , } ) , } ; let resolvedPath = `${ basePath ?. endsWith ( "/" ) ? basePath . slice ( 0 , - 1 ) : basePath || "" }` + "/bot/{botName}/alias/{botAlias}/user/{userId}/content" ; if ( input . botName !== undefined ) { const labelValue = input . botName ; if ( labelValue . length <= 0 ) { throw new Error ( "Empty value provided for input HTTP label: botName." ) ; } resolvedPath = resolvedPath . replace ( "{botName}" , __extendedEncodeURIComponent ( labelValue ) ) ; } else { throw new Error ( "No value provided for input HTTP label: botName." ) ; } if ( input . botAlias !== undefined ) { const labelValue = input . botAlias ; if ( labelValue . length <= 0 ) { throw new Error ( "Empty value provided for input HTTP label: botAlias." ) ; } resolvedPath = resolvedPath . replace ( "{botAlias}" , __extendedEncodeURIComponent ( labelValue ) ) ; } else { throw new Error ( "No value provided for input HTTP label: botAlias." ) ; } if ( input . userId !== undefined ) { const labelValue = input . userId ; if ( labelValue . length <= 0 ) { throw new Error ( "Empty value provided for input HTTP label: userId." ) ; } resolvedPath = resolvedPath . replace ( "{userId}" , __extendedEncodeURIComponent ( labelValue ) ) ; } else { throw new Error ( "No value provided for input HTTP label: userId." ) ; } let body ; if ( input . inputStream !== undefined ) { body = input . inputStream ; } return new __HttpRequest ( { protocol , hostname , port , method : "POST" , headers , path : resolvedPath , body , } ) ; } ; export const serializeAws_restJson1PostTextCommand = async ( input , context ) : Promise < __HttpRequest > => { const { hostname , protocol = "https" , port , path : basePath } = await context . endpoint ( ) ; const headers = { "content-type" : "application/json" , } ; let resolvedPath = `${ basePath ?. endsWith ( "/" ) ? basePath . slice ( 0 , - 1 ) : basePath || "" }` + "/bot/{botName}/alias/{botAlias}/user/{userId}/text" ; if ( input . botName !== undefined ) { const labelValue = input . botName ; if ( labelValue . length <= 0 ) { throw new Error ( "Empty value provided for input HTTP label: botName." ) ; } resolvedPath = resolvedPath . replace ( "{botName}" , __extendedEncodeURIComponent ( labelValue ) ) ; } else { throw new Error ( "No value provided for input HTTP label: botName." ) ; } if ( input . botAlias !== undefined ) { const labelValue = input . botAlias ; if ( labelValue . length <= 0 ) { throw new Error ( "Empty value provided for input HTTP label: botAlias." ) ; } resolvedPath = resolvedPath . replace ( "{botAlias}" , __extendedEncodeURIComponent ( labelValue ) ) ; } else { throw new Error ( "No value provided for input HTTP label: botAlias." ) ; } if ( input . userId !== undefined ) { const labelValue = input . userId ; if ( labelValue . length <= 0 ) { throw new Error ( "Empty value provided for input HTTP label: userId." ) ; } resolvedPath = resolvedPath . replace ( "{userId}" , __extendedEncodeURIComponent ( labelValue ) ) ; } else { throw new Error ( "No value provided for input HTTP label: userId." ) ; } let body ; body = JSON . stringify ( { ... ( input . activeContexts !== undefined && input . activeContexts !== null && { activeContexts : serializeAws_restJson1ActiveContextsList ( input . activeContexts , context ) , } ) , ... ( input . inputText !== undefined && input . inputText !== null && { inputText : input . inputText } ) , ... ( input . requestAttributes !== undefined && input . requestAttributes !== null && { requestAttributes : serializeAws_restJson1StringMap ( input . requestAttributes , context ) , } ) , ... ( input . sessionAttributes !== undefined && input . sessionAttributes !== null && { sessionAttributes : serializeAws_restJson1StringMap ( input . sessionAttributes , context ) , } ) , } ) ; return new __HttpRequest ( { protocol , hostname , port , method : "POST" , headers , path : resolvedPath , body , } ) ; } ; export const serializeAws_restJson1PutSessionCommand = async ( input , context ) : Promise < __HttpRequest > => { const { hostname , protocol = "https" , port , path : basePath } = await context . endpoint ( ) ; const headers = { "content-type" : "application/json" , ... ( isSerializableHeaderValue ( input . accept ) && { accept : input . accept ! } ) , } ; let resolvedPath = `${ basePath ?. endsWith ( "/" ) ? basePath . slice ( 0 , - 1 ) : basePath || "" }` + "/bot/{botName}/alias/{botAlias}/user/{userId}/session" ; if ( input . botName !== undefined ) { const labelValue = input . botName ; if ( labelValue . length <= 0 ) { throw new Error ( "Empty value provided for input HTTP label: botName." ) ; } resolvedPath = resolvedPath . replace ( "{botName}" , __extendedEncodeURIComponent ( labelValue ) ) ; } else { throw new Error ( "No value provided for input HTTP label: botName." ) ; } if ( input . botAlias !== undefined ) { const labelValue = input . botAlias ; if ( labelValue . length <= 0 ) { throw new Error ( "Empty value provided for input HTTP label: botAlias." ) ; } resolvedPath = resolvedPath . replace ( "{botAlias}" , __extendedEncodeURIComponent ( labelValue ) ) ; } else { throw new Error ( "No value provided for input HTTP label: botAlias." ) ; } if ( input . userId !== undefined ) { const labelValue = input . userId ; if ( labelValue . length <= 0 ) { throw new Error ( "Empty value provided for input HTTP label: userId." ) ; } resolvedPath = resolvedPath . replace ( "{userId}" , __extendedEncodeURIComponent ( labelValue ) ) ; } else { throw new Error ( "No value provided for input HTTP label: userId." ) ; } let body ; body = JSON . stringify ( { ... ( input . activeContexts !== undefined && input . activeContexts !== null && { activeContexts : serializeAws_restJson1ActiveContextsList ( input . activeContexts , context ) , } ) , ... ( input . dialogAction !== undefined && input . dialogAction !== null && { dialogAction : serializeAws_restJson1DialogAction ( input . dialogAction , context ) } ) , ... ( input . recentIntentSummaryView !== undefined && input . recentIntentSummaryView !== null && { recentIntentSummaryView : serializeAws_restJson1IntentSummaryList ( input . recentIntentSummaryView , context ) , } ) , ... ( input . sessionAttributes !== undefined && input . sessionAttributes !== null && { sessionAttributes : serializeAws_restJson1StringMap ( input . sessionAttributes , context ) , } ) , } ) ; return new __HttpRequest ( { protocol , hostname , port , method : "POST" , headers , path : resolvedPath , body , } ) ; } ; export const deserializeAws_restJson1DeleteSessionCommand = async ( output , context ) : Promise < DeleteSessionCommandOutput > => { if ( output . statusCode !== 200 && output . statusCode >= 300 ) { return deserializeAws_restJson1DeleteSessionCommandError ( output , context ) ; } const contents = { $metadata : deserializeMetadata ( output ) , botAlias : undefined , botName : undefined , sessionId : undefined , userId : undefined , } ; const data = __expectNonNull ( __expectObject ( await parseBody ( output . body , context ) ) , "body" ) ; if ( data . botAlias !== undefined && data . botAlias !== null ) { contents . botAlias = __expectString ( data . botAlias ) ; } if ( data . botName !== undefined && data . botName !== null ) { contents . botName = __expectString ( data . botName ) ; } if ( data . sessionId !== undefined && data . sessionId !== null ) { contents . sessionId = __expectString ( data . sessionId ) ; } if ( data . userId !== undefined && data . userId !== null ) { contents . userId = __expectString ( data . userId ) ; } return Promise . resolve ( contents ) ; } ; const deserializeAws_restJson1DeleteSessionCommandError = async ( output , context ) : Promise < DeleteSessionCommandOutput > => { const parsedOutput = { ... output , body : await parseBody ( output . body , context ) , } ; let response ; let errorCode = "UnknownError" ; errorCode = loadRestJsonErrorCode ( output , parsedOutput . body ) ; switch ( errorCode ) { case "BadRequestException" : case "com.amazonaws.lexruntimeservice#BadRequestException" : response = { ... ( await deserializeAws_restJson1BadRequestExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ConflictException" : case "com.amazonaws.lexruntimeservice#ConflictException" : response = { ... ( await deserializeAws_restJson1ConflictExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "InternalFailureException" : case "com.amazonaws.lexruntimeservice#InternalFailureException" : response = { ... ( await deserializeAws_restJson1InternalFailureExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "LimitExceededException" : case "com.amazonaws.lexruntimeservice#LimitExceededException" : response = { ... ( await deserializeAws_restJson1LimitExceededExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "NotFoundException" : case "com.amazonaws.lexruntimeservice#NotFoundException" : response = { ... ( await deserializeAws_restJson1NotFoundExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; default : const parsedBody = parsedOutput . body ; errorCode = parsedBody . code || parsedBody . Code || errorCode ; response = { ... parsedBody , name : `${ errorCode }` , message : parsedBody . message || parsedBody . Message || errorCode , $fault : "client" , $metadata : deserializeMetadata ( output ) , } as any ; } const message = response . message || response . Message || errorCode ; response . message = message ; delete response . Message ; return Promise . reject ( Object . assign ( new Error ( message ) , response ) ) ; } ; export const deserializeAws_restJson1GetSessionCommand = async ( output , context ) : Promise < GetSessionCommandOutput > => { if ( output . statusCode !== 200 && output . statusCode >= 300 ) { return deserializeAws_restJson1GetSessionCommandError ( output , context ) ; } const contents = { $metadata : deserializeMetadata ( output ) , activeContexts : undefined , dialogAction : undefined , recentIntentSummaryView : undefined , sessionAttributes : undefined , sessionId : undefined , } ; const data = __expectNonNull ( __expectObject ( await parseBody ( output . body , context ) ) , "body" ) ; if ( data . activeContexts !== undefined && data . activeContexts !== null ) { contents . activeContexts = deserializeAws_restJson1ActiveContextsList ( data . activeContexts , context ) ; } if ( data . dialogAction !== undefined && data . dialogAction !== null ) { contents . dialogAction = deserializeAws_restJson1DialogAction ( data . dialogAction , context ) ; } if ( data . recentIntentSummaryView !== undefined && data . recentIntentSummaryView !== null ) { contents . recentIntentSummaryView = deserializeAws_restJson1IntentSummaryList ( data . recentIntentSummaryView , context ) ; } if ( data . sessionAttributes !== undefined && data . sessionAttributes !== null ) { contents . sessionAttributes = deserializeAws_restJson1StringMap ( data . sessionAttributes , context ) ; } if ( data . sessionId !== undefined && data . sessionId !== null ) { contents . sessionId = __expectString ( data . sessionId ) ; } return Promise . resolve ( contents ) ; } ; const deserializeAws_restJson1GetSessionCommandError = async ( output , context ) : Promise < GetSessionCommandOutput > => { const parsedOutput = { ... output , body : await parseBody ( output . body , context ) , } ; let response ; let errorCode = "UnknownError" ; errorCode = loadRestJsonErrorCode ( output , parsedOutput . body ) ; switch ( errorCode ) { case "BadRequestException" : case "com.amazonaws.lexruntimeservice#BadRequestException" : response = { ... ( await deserializeAws_restJson1BadRequestExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "InternalFailureException" : case "com.amazonaws.lexruntimeservice#InternalFailureException" : response = { ... ( await deserializeAws_restJson1InternalFailureExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "LimitExceededException" : case "com.amazonaws.lexruntimeservice#LimitExceededException" : response = { ... ( await deserializeAws_restJson1LimitExceededExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "NotFoundException" : case "com.amazonaws.lexruntimeservice#NotFoundException" : response = { ... ( await deserializeAws_restJson1NotFoundExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; default : const parsedBody = parsedOutput . body ; errorCode = parsedBody . code || parsedBody . Code || errorCode ; response = { ... parsedBody , name : `${ errorCode }` , message : parsedBody . message || parsedBody . Message || errorCode , $fault : "client" , $metadata : deserializeMetadata ( output ) , } as any ; } const message = response . message || response . Message || errorCode ; response . message = message ; delete response . Message ; return Promise . reject ( Object . assign ( new Error ( message ) , response ) ) ; } ; export const deserializeAws_restJson1PostContentCommand = async ( output , context ) : Promise < PostContentCommandOutput > => { if ( output . statusCode !== 200 && output . statusCode >= 300 ) { return deserializeAws_restJson1PostContentCommandError ( output , context ) ; } const contents = { $metadata : deserializeMetadata ( output ) , activeContexts : undefined , alternativeIntents : undefined , audioStream : undefined , botVersion : undefined , contentType : undefined , dialogState : undefined , encodedInputTranscript : undefined , encodedMessage : undefined , inputTranscript : undefined , intentName : undefined , message : undefined , messageFormat : undefined , nluIntentConfidence : undefined , sentimentResponse : undefined , sessionAttributes : undefined , sessionId : undefined , slotToElicit : undefined , slots : undefined , } ; if ( output . headers [ "content-type" ] !== undefined ) { contents . contentType = output . headers [ "content-type" ] ; } if ( output . headers [ "x-amz-lex-intent-name" ] !== undefined ) { contents . intentName = output . headers [ "x-amz-lex-intent-name" ] ; } if ( output . headers [ "x-amz-lex-nlu-intent-confidence" ] !== undefined ) { contents . nluIntentConfidence = new __LazyJsonString ( Buffer . from ( context . base64Decoder ( output . headers [ "x-amz-lex-nlu-intent-confidence" ] ) ) . toString ( "utf8" ) ) ; } if ( output . headers [ "x-amz-lex-alternative-intents" ] !== undefined ) { contents . alternativeIntents = new __LazyJsonString ( Buffer . from ( context . base64Decoder ( output . headers [ "x-amz-lex-alternative-intents" ] ) ) . toString ( "utf8" ) ) ; } if ( output . headers [ "x-amz-lex-slots" ] !== undefined ) { contents . slots = new __LazyJsonString ( Buffer . from ( context . base64Decoder ( output . headers [ "x-amz-lex-slots" ] ) ) . toString ( "utf8" ) ) ; } if ( output . headers [ "x-amz-lex-session-attributes" ] !== undefined ) { contents . sessionAttributes = new __LazyJsonString ( Buffer . from ( context . base64Decoder ( output . headers [ "x-amz-lex-session-attributes" ] ) ) . toString ( "utf8" ) ) ; } if ( output . headers [ "x-amz-lex-sentiment" ] !== undefined ) { contents . sentimentResponse = output . headers [ "x-amz-lex-sentiment" ] ; } if ( output . headers [ "x-amz-lex-message" ] !== undefined ) { contents . message = output . headers [ "x-amz-lex-message" ] ; } if ( output . headers [ "x-amz-lex-encoded-message" ] !== undefined ) { contents . encodedMessage = output . headers [ "x-amz-lex-encoded-message" ] ; } if ( output . headers [ "x-amz-lex-message-format" ] !== undefined ) { contents . messageFormat = output . headers [ "x-amz-lex-message-format" ] ; } if ( output . headers [ "x-amz-lex-dialog-state" ] !== undefined ) { contents . dialogState = output . headers [ "x-amz-lex-dialog-state" ] ; } if ( output . headers [ "x-amz-lex-slot-to-elicit" ] !== undefined ) { contents . slotToElicit = output . headers [ "x-amz-lex-slot-to-elicit" ] ; } if ( output . headers [ "x-amz-lex-input-transcript" ] !== undefined ) { contents . inputTranscript = output . headers [ "x-amz-lex-input-transcript" ] ; } if ( output . headers [ "x-amz-lex-encoded-input-transcript" ] !== undefined ) { contents . encodedInputTranscript = output . headers [ "x-amz-lex-encoded-input-transcript" ] ; } if ( output . headers [ "x-amz-lex-bot-version" ] !== undefined ) { contents . botVersion = output . headers [ "x-amz-lex-bot-version" ] ; } if ( output . headers [ "x-amz-lex-session-id" ] !== undefined ) { contents . sessionId = output . headers [ "x-amz-lex-session-id" ] ; } if ( output . headers [ "x-amz-lex-active-contexts" ] !== undefined ) { contents . activeContexts = new __LazyJsonString ( Buffer . from ( context . base64Decoder ( output . headers [ "x-amz-lex-active-contexts" ] ) ) . toString ( "utf8" ) ) ; } const data = output . body ; contents . audioStream = data ; return Promise . resolve ( contents ) ; } ; const deserializeAws_restJson1PostContentCommandError = async ( output , context ) : Promise < PostContentCommandOutput > => { const parsedOutput = { ... output , body : await parseBody ( output . body , context ) , } ; let response ; let errorCode = "UnknownError" ; errorCode = loadRestJsonErrorCode ( output , parsedOutput . body ) ; switch ( errorCode ) { case "BadGatewayException" : case "com.amazonaws.lexruntimeservice#BadGatewayException" : response = { ... ( await deserializeAws_restJson1BadGatewayExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "BadRequestException" : case "com.amazonaws.lexruntimeservice#BadRequestException" : response = { ... ( await deserializeAws_restJson1BadRequestExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ConflictException" : case "com.amazonaws.lexruntimeservice#ConflictException" : response = { ... ( await deserializeAws_restJson1ConflictExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "DependencyFailedException" : case "com.amazonaws.lexruntimeservice#DependencyFailedException" : response = { ... ( await deserializeAws_restJson1DependencyFailedExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "InternalFailureException" : case "com.amazonaws.lexruntimeservice#InternalFailureException" : response = { ... ( await deserializeAws_restJson1InternalFailureExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "LimitExceededException" : case "com.amazonaws.lexruntimeservice#LimitExceededException" : response = { ... ( await deserializeAws_restJson1LimitExceededExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "LoopDetectedException" : case "com.amazonaws.lexruntimeservice#LoopDetectedException" : response = { ... ( await deserializeAws_restJson1LoopDetectedExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "NotAcceptableException" : case "com.amazonaws.lexruntimeservice#NotAcceptableException" : response = { ... ( await deserializeAws_restJson1NotAcceptableExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "NotFoundException" : case "com.amazonaws.lexruntimeservice#NotFoundException" : response = { ... ( await deserializeAws_restJson1NotFoundExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "RequestTimeoutException" : case "com.amazonaws.lexruntimeservice#RequestTimeoutException" : response = { ... ( await deserializeAws_restJson1RequestTimeoutExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "UnsupportedMediaTypeException" : case "com.amazonaws.lexruntimeservice#UnsupportedMediaTypeException" : response = { ... ( await deserializeAws_restJson1UnsupportedMediaTypeExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; default : const parsedBody = parsedOutput . body ; errorCode = parsedBody . code || parsedBody . Code || errorCode ; response = { ... parsedBody , name : `${ errorCode }` , message : parsedBody . message || parsedBody . Message || errorCode , $fault : "client" , $metadata : deserializeMetadata ( output ) , } as any ; } const message = response . message || response . Message || errorCode ; response . message = message ; delete response . Message ; return Promise . reject ( Object . assign ( new Error ( message ) , response ) ) ; } ; export const deserializeAws_restJson1PostTextCommand = async ( output , context ) : Promise < PostTextCommandOutput > => { if ( output . statusCode !== 200 && output . statusCode >= 300 ) { return deserializeAws_restJson1PostTextCommandError ( output , context ) ; } const contents = { $metadata : deserializeMetadata ( output ) , activeContexts : undefined , alternativeIntents : undefined , botVersion : undefined , dialogState : undefined , intentName : undefined , message : undefined , messageFormat : undefined , nluIntentConfidence : undefined , responseCard : undefined , sentimentResponse : undefined , sessionAttributes : undefined , sessionId : undefined , slotToElicit : undefined , slots : undefined , } ; const data = __expectNonNull ( __expectObject ( await parseBody ( output . body , context ) ) , "body" ) ; if ( data . activeContexts !== undefined && data . activeContexts !== null ) { contents . activeContexts = deserializeAws_restJson1ActiveContextsList ( data . activeContexts , context ) ; } if ( data . alternativeIntents !== undefined && data . alternativeIntents !== null ) { contents . alternativeIntents = deserializeAws_restJson1IntentList ( data . alternativeIntents , context ) ; } if ( data . botVersion !== undefined && data . botVersion !== null ) { contents . botVersion = __expectString ( data . botVersion ) ; } if ( data . dialogState !== undefined && data . dialogState !== null ) { contents . dialogState = __expectString ( data . dialogState ) ; } if ( data . intentName !== undefined && data . intentName !== null ) { contents . intentName = __expectString ( data . intentName ) ; } if ( data . message !== undefined && data . message !== null ) { contents . message = __expectString ( data . message ) ; } if ( data . messageFormat !== undefined && data . messageFormat !== null ) { contents . messageFormat = __expectString ( data . messageFormat ) ; } if ( data . nluIntentConfidence !== undefined && data . nluIntentConfidence !== null ) { contents . nluIntentConfidence = deserializeAws_restJson1IntentConfidence ( data . nluIntentConfidence , context ) ; } if ( data . responseCard !== undefined && data . responseCard !== null ) { contents . responseCard = deserializeAws_restJson1ResponseCard ( data . responseCard , context ) ; } if ( data . sentimentResponse !== undefined && data . sentimentResponse !== null ) { contents . sentimentResponse = deserializeAws_restJson1SentimentResponse ( data . sentimentResponse , context ) ; } if ( data . sessionAttributes !== undefined && data . sessionAttributes !== null ) { contents . sessionAttributes = deserializeAws_restJson1StringMap ( data . sessionAttributes , context ) ; } if ( data . sessionId !== undefined && data . sessionId !== null ) { contents . sessionId = __expectString ( data . sessionId ) ; } if ( data . slotToElicit !== undefined && data . slotToElicit !== null ) { contents . slotToElicit = __expectString ( data . slotToElicit ) ; } if ( data . slots !== undefined && data . slots !== null ) { contents . slots = deserializeAws_restJson1StringMap ( data . slots , context ) ; } return Promise . resolve ( contents ) ; } ; const deserializeAws_restJson1PostTextCommandError = async ( output , context ) : Promise < PostTextCommandOutput > => { const parsedOutput = { ... output , body : await parseBody ( output . body , context ) , } ; let response ; let errorCode = "UnknownError" ; errorCode = loadRestJsonErrorCode ( output , parsedOutput . body ) ; switch ( errorCode ) { case "BadGatewayException" : case "com.amazonaws.lexruntimeservice#BadGatewayException" : response = { ... ( await deserializeAws_restJson1BadGatewayExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "BadRequestException" : case "com.amazonaws.lexruntimeservice#BadRequestException" : response = { ... ( await deserializeAws_restJson1BadRequestExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ConflictException" : case "com.amazonaws.lexruntimeservice#ConflictException" : response = { ... ( await deserializeAws_restJson1ConflictExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "DependencyFailedException" : case "com.amazonaws.lexruntimeservice#DependencyFailedException" : response = { ... ( await deserializeAws_restJson1DependencyFailedExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "InternalFailureException" : case "com.amazonaws.lexruntimeservice#InternalFailureException" : response = { ... ( await deserializeAws_restJson1InternalFailureExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "LimitExceededException" : case "com.amazonaws.lexruntimeservice#LimitExceededException" : response = { ... ( await deserializeAws_restJson1LimitExceededExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "LoopDetectedException" : case "com.amazonaws.lexruntimeservice#LoopDetectedException" : response = { ... ( await deserializeAws_restJson1LoopDetectedExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "NotFoundException" : case "com.amazonaws.lexruntimeservice#NotFoundException" : response = { ... ( await deserializeAws_restJson1NotFoundExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; default : const parsedBody = parsedOutput . body ; errorCode = parsedBody . code || parsedBody . Code || errorCode ; response = { ... parsedBody , name : `${ errorCode }` , message : parsedBody . message || parsedBody . Message || errorCode , $fault : "client" , $metadata : deserializeMetadata ( output ) , } as any ; } const message = response . message || response . Message || errorCode ; response . message = message ; delete response . Message ; return Promise . reject ( Object . assign ( new Error ( message ) , response ) ) ; } ; export const deserializeAws_restJson1PutSessionCommand = async ( output , context ) : Promise < PutSessionCommandOutput > => { if ( output . statusCode !== 200 && output . statusCode >= 300 ) { return deserializeAws_restJson1PutSessionCommandError ( output , context ) ; } const contents = { $metadata : deserializeMetadata ( output ) , activeContexts : undefined , audioStream : undefined , contentType : undefined , dialogState : undefined , encodedMessage : undefined , intentName : undefined , message : undefined , messageFormat : undefined , sessionAttributes : undefined , sessionId : undefined , slotToElicit : undefined , slots : undefined , } ; if ( output . headers [ "content-type" ] !== undefined ) { contents . contentType = output . headers [ "content-type" ] ; } if ( output . headers [ "x-amz-lex-intent-name" ] !== undefined ) { contents . intentName = output . headers [ "x-amz-lex-intent-name" ] ; } if ( output . headers [ "x-amz-lex-slots" ] !== undefined ) { contents . slots = new __LazyJsonString ( Buffer . from ( context . base64Decoder ( output . headers [ "x-amz-lex-slots" ] ) ) . toString ( "utf8" ) ) ; } if ( output . headers [ "x-amz-lex-session-attributes" ] !== undefined ) { contents . sessionAttributes = new __LazyJsonString ( Buffer . from ( context . base64Decoder ( output . headers [ "x-amz-lex-session-attributes" ] ) ) . toString ( "utf8" ) ) ; } if ( output . headers [ "x-amz-lex-message" ] !== undefined ) { contents . message = output . headers [ "x-amz-lex-message" ] ; } if ( output . headers [ "x-amz-lex-encoded-message" ] !== undefined ) { contents . encodedMessage = output . headers [ "x-amz-lex-encoded-message" ] ; } if ( output . headers [ "x-amz-lex-message-format" ] !== undefined ) { contents . messageFormat = output . headers [ "x-amz-lex-message-format" ] ; } if ( output . headers [ "x-amz-lex-dialog-state" ] !== undefined ) { contents . dialogState = output . headers [ "x-amz-lex-dialog-state" ] ; } if ( output . headers [ "x-amz-lex-slot-to-elicit" ] !== undefined ) { contents . slotToElicit = output . headers [ "x-amz-lex-slot-to-elicit" ] ; } if ( output . headers [ "x-amz-lex-session-id" ] !== undefined ) { contents . sessionId = output . headers [ "x-amz-lex-session-id" ] ; } if ( output . headers [ "x-amz-lex-active-contexts" ] !== undefined ) { contents . activeContexts = new __LazyJsonString ( Buffer . from ( context . base64Decoder ( output . headers [ "x-amz-lex-active-contexts" ] ) ) . toString ( "utf8" ) ) ; } const data = output . body ; contents . audioStream = data ; return Promise . resolve ( contents ) ; } ; const deserializeAws_restJson1PutSessionCommandError = async ( output , context ) : Promise < PutSessionCommandOutput > => { const parsedOutput = { ... output , body : await parseBody ( output . body , context ) , } ; let response ; let errorCode = "UnknownError" ; errorCode = loadRestJsonErrorCode ( output , parsedOutput . body ) ; switch ( errorCode ) { case "BadGatewayException" : case "com.amazonaws.lexruntimeservice#BadGatewayException" : response = { ... ( await deserializeAws_restJson1BadGatewayExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "BadRequestException" : case "com.amazonaws.lexruntimeservice#BadRequestException" : response = { ... ( await deserializeAws_restJson1BadRequestExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ConflictException" : case "com.amazonaws.lexruntimeservice#ConflictException" : response = { ... ( await deserializeAws_restJson1ConflictExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "DependencyFailedException" : case "com.amazonaws.lexruntimeservice#DependencyFailedException" : response = { ... ( await deserializeAws_restJson1DependencyFailedExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "InternalFailureException" : case "com.amazonaws.lexruntimeservice#InternalFailureException" : response = { ... ( await deserializeAws_restJson1InternalFailureExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "LimitExceededException" : case "com.amazonaws.lexruntimeservice#LimitExceededException" : response = { ... ( await deserializeAws_restJson1LimitExceededExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "NotAcceptableException" : case "com.amazonaws.lexruntimeservice#NotAcceptableException" : response = { ... ( await deserializeAws_restJson1NotAcceptableExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "NotFoundException" : case "com.amazonaws.lexruntimeservice#NotFoundException" : response = { ... ( await deserializeAws_restJson1NotFoundExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; default : const parsedBody = parsedOutput . body ; errorCode = parsedBody . code || parsedBody . Code || errorCode ; response = { ... parsedBody , name : `${ errorCode }` , message : parsedBody . message || parsedBody . Message || errorCode , $fault : "client" , $metadata : deserializeMetadata ( output ) , } as any ; } const message = response . message || response . Message || errorCode ; response . message = message ; delete response . Message ; return Promise . reject ( Object . assign ( new Error ( message ) , response ) ) ; } ; const deserializeAws_restJson1BadGatewayExceptionResponse = async ( parsedOutput , context ) : Promise < BadGatewayException > => { const contents = { name : "BadGatewayException" , $fault : "server" , $metadata : deserializeMetadata ( parsedOutput ) , Message : undefined , } ; const data = parsedOutput . body ; if ( data . Message !== undefined && data . Message !== null ) { contents . Message = __expectString ( data . Message ) ; } return contents ; } ; const deserializeAws_restJson1BadRequestExceptionResponse = async ( parsedOutput , context ) : Promise < BadRequestException > => { const contents = { name : "BadRequestException" , $fault : "client" , $metadata : deserializeMetadata ( parsedOutput ) , message : undefined , } ; const data = parsedOutput . body ; if ( data . message !== undefined && data . message !== null ) { contents . message = __expectString ( data . message ) ; } return contents ; } ; const deserializeAws_restJson1ConflictExceptionResponse = async ( parsedOutput , context ) : Promise < ConflictException > => { const contents = { name : "ConflictException" , $fault : "client" , $metadata : deserializeMetadata ( parsedOutput ) , message : undefined , } ; const data = parsedOutput . body ; if ( data . message !== undefined && data . message !== null ) { contents . message = __expectString ( data . message ) ; } return contents ; } ; const deserializeAws_restJson1DependencyFailedExceptionResponse = async ( parsedOutput , context ) : Promise < DependencyFailedException > => { const contents = { name : "DependencyFailedException" , $fault : "client" , $metadata : deserializeMetadata ( parsedOutput ) , Message : undefined , } ; const data = parsedOutput . body ; if ( data . Message !== undefined && data . Message !== null ) { contents . Message = __expectString ( data . Message ) ; } return contents ; } ; const deserializeAws_restJson1InternalFailureExceptionResponse = async ( parsedOutput , context ) : Promise < InternalFailureException > => { const contents = { name : "InternalFailureException" , $fault : "server" , $metadata : deserializeMetadata ( parsedOutput ) , message : undefined , } ; const data = parsedOutput . body ; if ( data . message !== undefined && data . message !== null ) { contents . message = __expectString ( data . message ) ; } return contents ; } ; const deserializeAws_restJson1LimitExceededExceptionResponse = async ( parsedOutput , context ) : Promise < LimitExceededException > => { const contents = { name : "LimitExceededException" , $fault : "client" , $metadata : deserializeMetadata ( parsedOutput ) , message : undefined , retryAfterSeconds : undefined , } ; if ( parsedOutput . headers [ "retry-after" ] !== undefined ) { contents . retryAfterSeconds = parsedOutput . headers [ "retry-after" ] ; } const data = parsedOutput . body ; if ( data . message !== undefined && data . message !== null ) { contents . message = __expectString ( data . message ) ; } return contents ; } ; const deserializeAws_restJson1LoopDetectedExceptionResponse = async ( parsedOutput , context ) : Promise < LoopDetectedException > => { const contents = { name : "LoopDetectedException" , $fault : "server" , $metadata : deserializeMetadata ( parsedOutput ) , Message : undefined , } ; const data = parsedOutput . body ; if ( data . Message !== undefined && data . Message !== null ) { contents . Message = __expectString ( data . Message ) ; } return contents ; } ; const deserializeAws_restJson1NotAcceptableExceptionResponse = async ( parsedOutput , context ) : Promise < NotAcceptableException > => { const contents = { name : "NotAcceptableException" , $fault : "client" , $metadata : deserializeMetadata ( parsedOutput ) , message : undefined , } ; const data = parsedOutput . body ; if ( data . message !== undefined && data . message !== null ) { contents . message = __expectString ( data . message ) ; } return contents ; } ; const deserializeAws_restJson1NotFoundExceptionResponse = async ( parsedOutput , context ) : Promise < NotFoundException > => { const contents = { name : "NotFoundException" , $fault : "client" , $metadata : deserializeMetadata ( parsedOutput ) , message : undefined , } ; const data = parsedOutput . body ; if ( data . message !== undefined && data . message !== null ) { contents . message = __expectString ( data . message ) ; } return contents ; } ; const deserializeAws_restJson1RequestTimeoutExceptionResponse = async ( parsedOutput , context ) : Promise < RequestTimeoutException > => { const contents = { name : "RequestTimeoutException" , $fault : "client" , $metadata : deserializeMetadata ( parsedOutput ) , message : undefined , } ; const data = parsedOutput . body ; if ( data . message !== undefined && data . message !== null ) { contents . message = __expectString ( data . message ) ; } return contents ; } ; const deserializeAws_restJson1UnsupportedMediaTypeExceptionResponse = async ( parsedOutput , context ) : Promise < UnsupportedMediaTypeException > => { const contents = { name : "UnsupportedMediaTypeException" , $fault : "client" , $metadata : deserializeMetadata ( parsedOutput ) , message : undefined , } ; const data = parsedOutput . body ; if ( data . message !== undefined && data . message !== null ) { contents . message = __expectString ( data . message ) ; } return contents ; } ; const serializeAws_restJson1ActiveContext = ( input , context ) : any => { return { ... ( input . name !== undefined && input . name !== null && { name : input . name } ) , ... ( input . parameters !== undefined && input . parameters !== null && { parameters : serializeAws_restJson1ActiveContextParametersMap ( input . parameters , context ) , } ) , ... ( input . timeToLive !== undefined && input . timeToLive !== null && { timeToLive : serializeAws_restJson1ActiveContextTimeToLive ( input . timeToLive , context ) , } ) , } ; } ; const serializeAws_restJson1ActiveContextParametersMap = ( input , context ) : any => { return Object . entries ( input ) . reduce ( ( acc , [ key , value ] ) => { if ( value === null ) { return acc ; } return { ... acc , [ key ] : value , } ; } , { } ) ; } ; const serializeAws_restJson1ActiveContextsList = ( input , context ) : any => { return input . filter ( ( e ) => e != null ) . map ( ( entry ) => { if ( entry === null ) { return null as any ; } return serializeAws_restJson1ActiveContext ( entry , context ) ; } ) ; } ; const serializeAws_restJson1ActiveContextTimeToLive = ( input , context ) : any => { return { ... ( input . timeToLiveInSeconds !== undefined && input . timeToLiveInSeconds !== null && { timeToLiveInSeconds : input . timeToLiveInSeconds } ) , ... ( input . turnsToLive !== undefined && input . turnsToLive !== null && { turnsToLive : input . turnsToLive } ) , } ; } ; const serializeAws_restJson1DialogAction = ( input , context ) : any => { return { ... ( input . fulfillmentState !== undefined && input . fulfillmentState !== null && { fulfillmentState : input . fulfillmentState } ) , ... ( input . intentName !== undefined && input . intentName !== null && { intentName : input . intentName } ) , ... ( input . message !== undefined && input . message !== null && { message : input . message } ) , ... ( input . messageFormat !== undefined && input . messageFormat !== null && { messageFormat : input . messageFormat } ) , ... ( input . slotToElicit !== undefined && input . slotToElicit !== null && { slotToElicit : input . slotToElicit } ) , ... ( input . slots !== undefined && input . slots !== null && { slots : serializeAws_restJson1StringMap ( input . slots , context ) } ) , ... ( input . type !== undefined && input . type !== null && { type : input . type } ) , } ; } ; const serializeAws_restJson1IntentSummary = ( input , context ) : any => { return { ... ( input . checkpointLabel !== undefined && input . checkpointLabel !== null && { checkpointLabel : input . checkpointLabel } ) , ... ( input . confirmationStatus !== undefined && input . confirmationStatus !== null && { confirmationStatus : input . confirmationStatus } ) , ... ( input . dialogActionType !== undefined && input . dialogActionType !== null && { dialogActionType : input . dialogActionType } ) , ... ( input . fulfillmentState !== undefined && input . fulfillmentState !== null && { fulfillmentState : input . fulfillmentState } ) , ... ( input . intentName !== undefined && input . intentName !== null && { intentName : input . intentName } ) , ... ( input . slotToElicit !== undefined && input . slotToElicit !== null && { slotToElicit : input . slotToElicit } ) , ... ( input . slots !== undefined && input . slots !== null && { slots : serializeAws_restJson1StringMap ( input . slots , context ) } ) , } ; } ; const serializeAws_restJson1IntentSummaryList = ( input , context ) : any => { return input . filter ( ( e ) => e != null ) . map ( ( entry ) => { if ( entry === null ) { return null as any ; } return serializeAws_restJson1IntentSummary ( entry , context ) ; } ) ; } ; const serializeAws_restJson1StringMap = ( input , context ) : any => { return Object . entries ( input ) . reduce ( ( acc , [ key , value ] ) => { if ( value === null ) { return acc ; } return { ... acc , [ key ] : value , } ; } , { } ) ; } ; const deserializeAws_restJson1ActiveContext = ( output , context ) : ActiveContext => { return { name : __expectString ( output . name ) , parameters : output . parameters !== undefined && output . parameters !== null ? deserializeAws_restJson1ActiveContextParametersMap ( output . parameters , context ) : undefined , timeToLive : output . timeToLive !== undefined && output . timeToLive !== null ? deserializeAws_restJson1ActiveContextTimeToLive ( output . timeToLive , context ) : undefined , } as any ; } ; const deserializeAws_restJson1ActiveContextParametersMap = ( output , context ) : { [ key ] : string ; } => { return Object . entries ( output ) . reduce ( ( acc , [ key , value ] ) => { if ( value === null ) { return acc ; } return { ... acc , [ key ] : __expectString ( value ) as any , } ; } , { } ) ; } ; const deserializeAws_restJson1ActiveContextsList = ( output , context ) : ActiveContext [ ] => { return ( output || [ ] ) . filter ( ( e ) => e != null ) . map ( ( entry ) => { if ( entry === null ) { return null as any ; } return deserializeAws_restJson1ActiveContext ( entry , context ) ; } ) ; } ; const deserializeAws_restJson1ActiveContextTimeToLive = ( output , context ) : ActiveContextTimeToLive => { return { timeToLiveInSeconds : __expectInt32 ( output . timeToLiveInSeconds ) , turnsToLive : __expectInt32 ( output . turnsToLive ) , } as any ; } ; const deserializeAws_restJson1Button = ( output , context ) : Button => { return { text : __expectString ( output . text ) , value : __expectString ( output . value ) , } as any ; } ; const deserializeAws_restJson1DialogAction = ( output , context ) : DialogAction => { return { fulfillmentState : __expectString ( output . fulfillmentState ) , intentName : __expectString ( output . intentName ) , message : __expectString ( output . message ) , messageFormat : __expectString ( output . messageFormat ) , slotToElicit : __expectString ( output . slotToElicit ) , slots : output . slots !== undefined && output . slots !== null ? deserializeAws_restJson1StringMap ( output . slots , context ) : undefined , type : __expectString ( output . type ) , } as any ; } ; const deserializeAws_restJson1GenericAttachment = ( output , context ) : GenericAttachment => { return { attachmentLinkUrl : __expectString ( output . attachmentLinkUrl ) , buttons : output . buttons !== undefined && output . buttons !== null ? deserializeAws_restJson1listOfButtons ( output . buttons , context ) : undefined , imageUrl : __expectString ( output . imageUrl ) , subTitle : __expectString ( output . subTitle ) , title : __expectString ( output . title ) , } as any ; } ; const deserializeAws_restJson1genericAttachmentList = ( output , context ) : GenericAttachment [ ] => { return ( output || [ ] ) . filter ( ( e ) => e != null ) . map ( ( entry ) => { if ( entry === null ) { return null as any ; } return deserializeAws_restJson1GenericAttachment ( entry , context ) ; } ) ; } ; const deserializeAws_restJson1IntentConfidence = ( output , context ) : IntentConfidence => { return { score : __limitedParseDouble ( output . score ) , } as any ; } ; const deserializeAws_restJson1IntentList = ( output , context ) : PredictedIntent [ ] => { return ( output || [ ] ) . filter ( ( e ) => e != null ) . map ( ( entry ) => { if ( entry === null ) { return null as any ; } return deserializeAws_restJson1PredictedIntent ( entry , context ) ; } ) ; } ; const deserializeAws_restJson1IntentSummary = ( output , context ) : IntentSummary => { return { checkpointLabel : __expectString ( output . checkpointLabel ) , confirmationStatus : __expectString ( output . confirmationStatus ) , dialogActionType : __expectString ( output . dialogActionType ) , fulfillmentState : __expectString ( output . fulfillmentState ) , intentName : __expectString ( output . intentName ) , slotToElicit : __expectString ( output . slotToElicit ) , slots : output . slots !== undefined && output . slots !== null ? deserializeAws_restJson1StringMap ( output . slots , context ) : undefined , } as any ; } ; const deserializeAws_restJson1IntentSummaryList = ( output , context ) : IntentSummary [ ] => { return ( output || [ ] ) . filter ( ( e ) => e != null ) . map ( ( entry ) => { if ( entry === null ) { return null as any ; } return deserializeAws_restJson1IntentSummary ( entry , context ) ; } ) ; } ; const deserializeAws_restJson1listOfButtons = ( output , context ) : Button [ ] => { return ( output || [ ] ) . filter ( ( e ) => e != null ) . map ( ( entry ) => { if ( entry === null ) { return null as any ; } return deserializeAws_restJson1Button ( entry , context ) ; } ) ; } ; const deserializeAws_restJson1PredictedIntent = ( output , context ) : PredictedIntent => { return { intentName : __expectString ( output . intentName ) , nluIntentConfidence : output . nluIntentConfidence !== undefined && output . nluIntentConfidence !== null ? deserializeAws_restJson1IntentConfidence ( output . nluIntentConfidence , context ) : undefined , slots : output . slots !== undefined && output . slots !== null ? deserializeAws_restJson1StringMap ( output . slots , context ) : undefined , } as any ; } ; const deserializeAws_restJson1ResponseCard = ( output , context ) : ResponseCard => { return { contentType : __expectString ( output . contentType ) , genericAttachments : output . genericAttachments !== undefined && output . genericAttachments !== null ? deserializeAws_restJson1genericAttachmentList ( output . genericAttachments , context ) : undefined , version : __expectString ( output . version ) , } as any ; } ; const deserializeAws_restJson1SentimentResponse = ( output , context ) : SentimentResponse => { return { sentimentLabel : __expectString ( output . sentimentLabel ) , sentimentScore : __expectString ( output . sentimentScore ) , } as any ; } ; const deserializeAws_restJson1StringMap = ( output , context ) : { [ key ] : string ; } => { return Object . entries ( output ) . reduce ( ( acc , [ key , value ] ) => { if ( value === null ) { return acc ; } return { ... acc , [ key ] : __expectString ( value ) as any , } ; } , { } ) ; } ; const deserializeMetadata = ( output ) : __ResponseMetadata => ( { httpStatusCode : output . statusCode , requestId : output . headers [ "x-amzn-requestid" ] ?? output . headers [ "x-amzn-request-id" ] , extendedRequestId : output . headers [ "x-amz-id-2" ] , cfId : output . headers [ "x-amz-cf-id" ] , } ) ; const collectBody = ( streamBody = new Uint8Array ( ) , context ) : Promise < Uint8Array > => { if ( streamBody instanceof Uint8Array ) { return Promise . resolve ( streamBody ) ; } return context . streamCollector ( streamBody ) || Promise . resolve ( new Uint8Array ( ) ) ; } ; const collectBodyString = ( streamBody , context ) : Promise < string > => collectBody ( streamBody , context ) . then ( ( body ) => context . utf8Encoder ( body ) ) ; const isSerializableHeaderValue = ( value ) : boolean => value !== undefined && value !== null && value !== "" && ( ! Object . getOwnPropertyNames ( value ) . includes ( "length" ) || value . length != 0 ) && ( ! Object . getOwnPropertyNames ( value ) . includes ( "size" ) || value . size != 0 ) ; const parseBody = ( streamBody , context ) : any => collectBodyString ( streamBody , context ) . then ( ( encoded ) => { if ( encoded . length ) { return JSON . parse ( encoded ) ; } return { } ; } ) ; /**
 * Load an error code for the aws.rest-json-1.1 protocol.
 */ const loadRestJsonErrorCode = ( output , data ) : string => { const findKey = ( object , key ) => Object . keys ( object ) . find ( ( k ) => k . toLowerCase ( ) === key . toLowerCase ( ) ) ; const sanitizeErrorCode = ( rawValue ) : string => { let cleanValue = rawValue ; if ( cleanValue . indexOf ( ":" ) >= 0 ) { cleanValue = cleanValue . split ( ":" ) [ 0 ] ; } if ( cleanValue . indexOf ( "#" ) >= 0 ) { cleanValue = cleanValue . split ( "#" ) [ 1 ] ; } return cleanValue ; } ; const headerKey = findKey ( output . headers , "x-amzn-errortype" ) ; if ( headerKey !== undefined ) { return sanitizeErrorCode ( output . headers [ headerKey ] ) ; } if ( data . code !== undefined ) { return sanitizeErrorCode ( data . code ) ; } if ( data [ "__type" ] !== undefined ) { return sanitizeErrorCode ( data [ "__type" ] ) ; } return "" ; } ;