"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ApiGatewayTargetConfiguration=exports.ApiGatewayHttpMethod=exports.McpServerTargetConfiguration=exports.SmithyTargetConfiguration=exports.OpenApiTargetConfiguration=exports.LambdaTargetConfiguration=exports.McpTargetConfiguration=void 0;var jsiiDeprecationWarnings=()=>{var tmp=require("../../../../.warnings.jsii.js");return jsiiDeprecationWarnings=()=>tmp,tmp};const JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti");var fs=()=>{var tmp=require("fs");return fs=()=>tmp,tmp},api_schema_1=()=>{var tmp=require("./schema/api-schema");return api_schema_1=()=>tmp,tmp},target_base_1=()=>{var tmp=require("./target-base");return target_base_1=()=>tmp,tmp},iam=()=>{var tmp=require("../../../../aws-iam");return iam=()=>tmp,tmp},core_1=()=>{var tmp=require("../../../../core");return core_1=()=>tmp,tmp},errors_1=()=>{var tmp=require("../../../../core/lib/errors");return errors_1=()=>tmp,tmp},helpers_internal_1=()=>{var tmp=require("../../../../core/lib/helpers-internal");return helpers_internal_1=()=>tmp,tmp},validation_helpers_1=()=>{var tmp=require("../../common/validation-helpers");return validation_helpers_1=()=>tmp,tmp},validation_helpers_2=()=>{var tmp=require("../validation-helpers");return validation_helpers_2=()=>tmp,tmp};class McpTargetConfiguration{static[JSII_RTTI_SYMBOL_1]={fqn:"aws-cdk-lib.aws_bedrockagentcore.McpTargetConfiguration",version:"2.256.1"};_render(){return{mcp:this.renderMcpConfiguration()}}}exports.McpTargetConfiguration=McpTargetConfiguration;class LambdaTargetConfiguration extends McpTargetConfiguration{static[JSII_RTTI_SYMBOL_1]={fqn:"aws-cdk-lib.aws_bedrockagentcore.LambdaTargetConfiguration",version:"2.256.1"};static create(lambdaFunction,toolSchema){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_lambda_IFunction(lambdaFunction),jsiiDeprecationWarnings().aws_cdk_lib_aws_bedrockagentcore_ToolSchema(toolSchema)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.create),error}return new LambdaTargetConfiguration(lambdaFunction,toolSchema)}targetType=target_base_1().McpTargetType.LAMBDA;lambdaFunction;toolSchema;constructor(lambdaFunction,toolSchema){super();try{jsiiDeprecationWarnings().aws_cdk_lib_aws_lambda_IFunction(lambdaFunction),jsiiDeprecationWarnings().aws_cdk_lib_aws_bedrockagentcore_ToolSchema(toolSchema)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,LambdaTargetConfiguration),error}this.lambdaFunction=lambdaFunction,this.toolSchema=toolSchema}bind(scope,gateway){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_bedrockagentcore_IGateway(gateway)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.bind),error}return this.toolSchema.bind(scope),this.toolSchema.grantPermissionsToRole(gateway.role),this.lambdaFunction.grantInvoke(gateway.role),{bound:!0}}renderMcpConfiguration(){return{lambda:{lambdaArn:this.lambdaFunction.functionArn,toolSchema:this.toolSchema._render()}}}}exports.LambdaTargetConfiguration=LambdaTargetConfiguration;class OpenApiTargetConfiguration extends McpTargetConfiguration{static[JSII_RTTI_SYMBOL_1]={fqn:"aws-cdk-lib.aws_bedrockagentcore.OpenApiTargetConfiguration",version:"2.256.1"};static create(apiSchema,validateSchema){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_bedrockagentcore_ApiSchema(apiSchema)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.create),error}return new OpenApiTargetConfiguration(apiSchema,validateSchema)}targetType=target_base_1().McpTargetType.OPENAPI_SCHEMA;apiSchema;shouldValidateSchema;constructor(apiSchema,validateSchema){super();try{jsiiDeprecationWarnings().aws_cdk_lib_aws_bedrockagentcore_ApiSchema(apiSchema)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,OpenApiTargetConfiguration),error}this.apiSchema=apiSchema,this.shouldValidateSchema=validateSchema??!0}bind(scope,gateway){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_bedrockagentcore_IGateway(gateway)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.bind),error}if(this.shouldValidateSchema){if(this.apiSchema.inlineSchema){const errors=(0,validation_helpers_2().validateOpenApiSchema)({schema:this.apiSchema.inlineSchema,schemaName:"OpenAPI schema for target"});if(errors.length>0)throw new(errors_1()).UnscopedValidationError((0,helpers_internal_1().lit)`OpenApiSchemaValidationFailed`,`OpenAPI schema validation failed:
${errors.join(`
`)}`)}else if(this.apiSchema instanceof api_schema_1().AssetApiSchema)try{const schemaContent=fs().readFileSync(this.apiSchema._getFilePath(),"utf-8"),errors=(0,validation_helpers_2().validateOpenApiSchema)({schema:schemaContent,schemaName:`OpenAPI schema from file ${this.apiSchema._getFilePath()}`});if(errors.length>0)throw new(errors_1()).UnscopedValidationError((0,helpers_internal_1().lit)`OpenApiSchemaValidationFailed`,`OpenAPI schema validation failed:
${errors.join(`
`)}`)}catch(e){throw e instanceof errors_1().ValidationError?e:new(errors_1()).UnscopedValidationError((0,helpers_internal_1().lit)`OpenApiSchemaFileReadFailed`,`Failed to read OpenAPI schema from ${this.apiSchema._getFilePath()}: ${e instanceof Error?e.message:String(e)}`)}}return this.apiSchema.bind(scope),this.apiSchema.grantPermissionsToRole(gateway.role),{bound:!0}}renderMcpConfiguration(){return{openApiSchema:this.apiSchema._render()}}}exports.OpenApiTargetConfiguration=OpenApiTargetConfiguration;class SmithyTargetConfiguration extends McpTargetConfiguration{static[JSII_RTTI_SYMBOL_1]={fqn:"aws-cdk-lib.aws_bedrockagentcore.SmithyTargetConfiguration",version:"2.256.1"};static create(smithyModel){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_bedrockagentcore_ApiSchema(smithyModel)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.create),error}return new SmithyTargetConfiguration(smithyModel)}targetType=target_base_1().McpTargetType.SMITHY_MODEL;smithyModel;constructor(smithyModel){super();try{jsiiDeprecationWarnings().aws_cdk_lib_aws_bedrockagentcore_ApiSchema(smithyModel)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,SmithyTargetConfiguration),error}this.smithyModel=smithyModel}bind(scope,gateway){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_bedrockagentcore_IGateway(gateway)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.bind),error}return this.smithyModel.bind(scope),this.smithyModel.grantPermissionsToRole(gateway.role),{bound:!0}}renderMcpConfiguration(){return{smithyModel:this.smithyModel._render()}}}exports.SmithyTargetConfiguration=SmithyTargetConfiguration;class McpServerTargetConfiguration extends McpTargetConfiguration{static[JSII_RTTI_SYMBOL_1]={fqn:"aws-cdk-lib.aws_bedrockagentcore.McpServerTargetConfiguration",version:"2.256.1"};static create(endpoint){return new McpServerTargetConfiguration(endpoint)}targetType=target_base_1().McpTargetType.MCP_SERVER;endpoint;constructor(endpoint){super(),this.endpoint=endpoint,this.validateEndpoint(endpoint)}bind(_scope,_gateway){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_bedrockagentcore_IGateway(_gateway)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.bind),error}return{bound:!0}}renderMcpConfiguration(){return{mcpServer:{endpoint:this.endpoint}}}validateEndpoint(endpoint){if(core_1().Token.isUnresolved(endpoint))return;const errors=(0,validation_helpers_1().validateFieldPattern)(endpoint,"MCP server endpoint",/^https:\/\/.+/,"MCP server endpoint must use HTTPS protocol (e.g., https://my-server.example.com). Ensure the URL is properly encoded.");if(errors.length>0)throw new(errors_1()).UnscopedValidationError((0,helpers_internal_1().lit)`McpServerEndpointInvalid`,errors.join(`
`));if(endpoint.includes(" ")||endpoint.includes("<")||endpoint.includes(">"))throw new(errors_1()).UnscopedValidationError((0,helpers_internal_1().lit)`McpServerEndpointEncodingInvalid`,"MCP server endpoint contains characters that should be URL-encoded. Please ensure the URL is properly encoded before passing to the construct.")}}exports.McpServerTargetConfiguration=McpServerTargetConfiguration;class ApiGatewayHttpMethod{static[JSII_RTTI_SYMBOL_1]={fqn:"aws-cdk-lib.aws_bedrockagentcore.ApiGatewayHttpMethod",version:"2.256.1"};static GET=new ApiGatewayHttpMethod("GET");static POST=new ApiGatewayHttpMethod("POST");static PUT=new ApiGatewayHttpMethod("PUT");static DELETE=new ApiGatewayHttpMethod("DELETE");static PATCH=new ApiGatewayHttpMethod("PATCH");static HEAD=new ApiGatewayHttpMethod("HEAD");static OPTIONS=new ApiGatewayHttpMethod("OPTIONS");static of(value){return new ApiGatewayHttpMethod(value)}value;constructor(value){this.value=value}toString(){return this.value}}exports.ApiGatewayHttpMethod=ApiGatewayHttpMethod;class ApiGatewayTargetConfiguration extends McpTargetConfiguration{static[JSII_RTTI_SYMBOL_1]={fqn:"aws-cdk-lib.aws_bedrockagentcore.ApiGatewayTargetConfiguration",version:"2.256.1"};static create(props){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_bedrockagentcore_ApiGatewayTargetConfigurationProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.create),error}return new ApiGatewayTargetConfiguration(props)}targetType=target_base_1().McpTargetType.API_GATEWAY;_restApi;restApiId;stage;apiGatewayToolConfiguration;metadataConfiguration;constructor(props){super();try{jsiiDeprecationWarnings().aws_cdk_lib_aws_bedrockagentcore_ApiGatewayTargetConfigurationProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,ApiGatewayTargetConfiguration),error}this._restApi=props.restApi,this.restApiId=props.restApi.restApiId,this.stage=props.stage??props.restApi.deploymentStage.stageName,this.apiGatewayToolConfiguration=props.apiGatewayToolConfiguration,this.metadataConfiguration=props.metadataConfiguration,this.validateConfiguration()}bind(_scope,gateway){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_bedrockagentcore_IGateway(gateway)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.bind),error}return gateway.role.addToPrincipalPolicy(new(iam()).PolicyStatement({effect:iam().Effect.ALLOW,actions:["execute-api:Invoke"],resources:[this._restApi.arnForExecuteApi("*","/*",this.stage)]})),{bound:!0}}renderMcpConfiguration(){return{apiGateway:{restApiId:this.restApiId,stage:this.stage,apiGatewayToolConfiguration:{toolFilters:this.apiGatewayToolConfiguration.toolFilters.map(filter=>({filterPath:filter.filterPath,methods:filter.methods.map(m=>m.value)})),...this.apiGatewayToolConfiguration.toolOverrides&&{toolOverrides:this.apiGatewayToolConfiguration.toolOverrides.map(override=>({path:override.path,method:override.method.value,name:override.name,...override.description&&{description:override.description}}))}},...this.metadataConfiguration&&{metadataConfiguration:{...this.metadataConfiguration.allowedQueryParameters&&{allowedQueryParameters:this.metadataConfiguration.allowedQueryParameters},...this.metadataConfiguration.allowedRequestHeaders&&{allowedRequestHeaders:this.metadataConfiguration.allowedRequestHeaders},...this.metadataConfiguration.allowedResponseHeaders&&{allowedResponseHeaders:this.metadataConfiguration.allowedResponseHeaders}}}}}}validateConfiguration(){if(!core_1().Token.isUnresolved(this.restApiId)){const restApiIdErrors=(0,validation_helpers_1().validateStringFieldLength)({value:this.restApiId,fieldName:"REST API ID",minLength:1,maxLength:256});if(restApiIdErrors.length>0)throw new(errors_1()).UnscopedValidationError((0,helpers_internal_1().lit)`RestApiIdInvalid`,restApiIdErrors.join(`
`))}if(!core_1().Token.isUnresolved(this.stage)){const stageErrors=(0,validation_helpers_1().validateStringFieldLength)({value:this.stage,fieldName:"Stage name",minLength:1,maxLength:128});if(stageErrors.length>0)throw new(errors_1()).UnscopedValidationError((0,helpers_internal_1().lit)`StageNameInvalid`,stageErrors.join(`
`))}if(!this.apiGatewayToolConfiguration.toolFilters||this.apiGatewayToolConfiguration.toolFilters.length===0)throw new(errors_1()).UnscopedValidationError((0,helpers_internal_1().lit)`ToolFiltersRequired`,"At least one tool filter is required for API Gateway target configuration");for(const filter of this.apiGatewayToolConfiguration.toolFilters)this.validateToolFilter(filter);if(this.apiGatewayToolConfiguration.toolOverrides)for(const override of this.apiGatewayToolConfiguration.toolOverrides)this.validateToolOverride(override);this.metadataConfiguration&&this.validateMetadataConfiguration(this.metadataConfiguration)}validateMetadataConfiguration(config){config.allowedQueryParameters!==void 0&&this.validateMetadataArray(config.allowedQueryParameters,"allowedQueryParameters",1,10,1,40),config.allowedRequestHeaders!==void 0&&this.validateMetadataArray(config.allowedRequestHeaders,"allowedRequestHeaders",1,10,1,100),config.allowedResponseHeaders!==void 0&&this.validateMetadataArray(config.allowedResponseHeaders,"allowedResponseHeaders",1,10,1,100)}validateMetadataArray(array,fieldName,minItems,maxItems,minStringLength,maxStringLength){if(!core_1().Token.isUnresolved(array)){if(array.length===0)throw new(errors_1()).UnscopedValidationError((0,helpers_internal_1().lit)`MetadataArrayEmpty`,`${fieldName} cannot be an empty array. It must contain at least ${minItems} item(s)`);if(array.length<minItems)throw new(errors_1()).UnscopedValidationError((0,helpers_internal_1().lit)`MetadataArrayTooFew`,`${fieldName} must contain at least ${minItems} item(s). Found ${array.length} item(s)`);if(array.length>maxItems)throw new(errors_1()).UnscopedValidationError((0,helpers_internal_1().lit)`MetadataArrayTooMany`,`${fieldName} cannot exceed ${maxItems} items. Found ${array.length} items`);array.forEach((item,index)=>{if(core_1().Token.isUnresolved(item))return;const errors=(0,validation_helpers_1().validateStringFieldLength)({value:item,fieldName:`${fieldName}[${index}]`,minLength:minStringLength,maxLength:maxStringLength});if(errors.length>0)throw new(errors_1()).UnscopedValidationError((0,helpers_internal_1().lit)`MetadataArrayItemInvalid`,errors.join(`
`))})}}validateToolFilter(filter){if(core_1().Token.isUnresolved(filter.filterPath))return;const pathErrors=(0,validation_helpers_1().validateFieldPattern)(filter.filterPath,"Filter path",/^\/[\w\-{}/*]*$/,"Filter path must start with a forward slash and contain only alphanumeric characters, hyphens, underscores, curly braces, forward slashes, and asterisks");if(pathErrors.length>0)throw new(errors_1()).UnscopedValidationError((0,helpers_internal_1().lit)`ToolFilterPathInvalid`,pathErrors.join(`
`));if(!filter.methods||filter.methods.length===0)throw new(errors_1()).UnscopedValidationError((0,helpers_internal_1().lit)`ToolFilterMethodsRequired`,`At least one HTTP method is required for filter path: ${filter.filterPath}`)}validateToolOverride(override){if(core_1().Token.isUnresolved(override.path))return;if(override.path.includes("*"))throw new(errors_1()).UnscopedValidationError((0,helpers_internal_1().lit)`ToolOverridePathWildcardNotAllowed`,`Tool override path cannot contain wildcards. Path: ${override.path}. Tool overrides must specify an explicit path that matches an existing operation in your API.`);const pathErrors=(0,validation_helpers_1().validateFieldPattern)(override.path,"Override path",/^\/[\w\-{}/]*$/,"Override path must start with a forward slash and contain only alphanumeric characters, hyphens, underscores, curly braces, and forward slashes");if(pathErrors.length>0)throw new(errors_1()).UnscopedValidationError((0,helpers_internal_1().lit)`ToolOverridePathInvalid`,pathErrors.join(`
`));if(core_1().Token.isUnresolved(override.name))return;const nameErrors=(0,validation_helpers_1().validateStringFieldLength)({value:override.name,fieldName:"Override tool name",minLength:1,maxLength:64});if(nameErrors.length>0)throw new(errors_1()).UnscopedValidationError((0,helpers_internal_1().lit)`ToolOverrideNameInvalid`,nameErrors.join(`
`));if(override.description&&!core_1().Token.isUnresolved(override.description)){const descErrors=(0,validation_helpers_1().validateStringFieldLength)({value:override.description,fieldName:"Override description",minLength:1,maxLength:200});if(descErrors.length>0)throw new(errors_1()).UnscopedValidationError((0,helpers_internal_1().lit)`ToolOverrideDescriptionInvalid`,descErrors.join(`
`))}}}exports.ApiGatewayTargetConfiguration=ApiGatewayTargetConfiguration;
