aws-cdk-lib
Version:
Version 2 of the AWS Cloud Development Kit library
2 lines (1 loc) • 6.17 kB
JavaScript
;Object.defineProperty(exports,"__esModule",{value:!0}),exports.SelfManagedMemoryStrategy=void 0;var jsiiDeprecationWarnings=()=>{var tmp=require("../../../../.warnings.jsii.js");return jsiiDeprecationWarnings=()=>tmp,tmp};const JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti");var iam=()=>{var tmp=require("../../../../aws-iam");return iam=()=>tmp,tmp},cdk=()=>{var tmp=require("../../../../core");return cdk=()=>tmp,tmp},validation_helpers_1=()=>{var tmp=require("../../common/validation-helpers");return validation_helpers_1=()=>tmp,tmp},memory_strategy_1=()=>{var tmp=require("../memory-strategy");return memory_strategy_1=()=>tmp,tmp};const TIME_BASED_TRIGGER_MIN=10,TIME_BASED_TRIGGER_MAX=3e3,TOKEN_BASED_TRIGGER_MIN=100,TOKEN_BASED_TRIGGER_MAX=5e5,MESSAGE_BASED_TRIGGER_MIN=1,MESSAGE_BASED_TRIGGER_MAX=50,HISTORICAL_CONTEXT_WINDOW_SIZE_MIN=0,HISTORICAL_CONTEXT_WINDOW_SIZE_MAX=50,DEFAULT_HISTORICAL_CONTEXT_WINDOW_SIZE=4,DEFAULT_MESSAGE_BASED_TRIGGER=1,DEFAULT_TIME_BASED_TRIGGER=cdk().Duration.seconds(10),DEFAULT_TOKEN_BASED_TRIGGER=100;class SelfManagedMemoryStrategy{static[JSII_RTTI_SYMBOL_1]={fqn:"aws-cdk-lib.aws_bedrockagentcore.SelfManagedMemoryStrategy",version:"2.257.0"};strategyName;description;strategyType;invocationConfiguration;triggerConditions;historicalContextWindowSize;constructor(strategyType,props){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_bedrockagentcore_MemoryStrategyType(strategyType),jsiiDeprecationWarnings().aws_cdk_lib_aws_bedrockagentcore_SelfManagedStrategyProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,SelfManagedMemoryStrategy),error}this.strategyName=props.strategyName,this.description=props.description,this.strategyType=strategyType,this.invocationConfiguration=props.invocationConfiguration,this.triggerConditions={messageBasedTrigger:props.triggerConditions?.messageBasedTrigger??DEFAULT_MESSAGE_BASED_TRIGGER,timeBasedTrigger:props.triggerConditions?.timeBasedTrigger??DEFAULT_TIME_BASED_TRIGGER,tokenBasedTrigger:props.triggerConditions?.tokenBasedTrigger??DEFAULT_TOKEN_BASED_TRIGGER},this.historicalContextWindowSize=props.historicalContextWindowSize??DEFAULT_HISTORICAL_CONTEXT_WINDOW_SIZE,(0,validation_helpers_1().throwIfInvalid)(this._validateMemoryStrategyName,this.strategyName),(0,validation_helpers_1().throwIfInvalid)(this._validateHistoricalContextWindowSize,this.historicalContextWindowSize),(0,validation_helpers_1().throwIfInvalid)(this._validateTriggerConditions,this.triggerConditions)}render(){return{customMemoryStrategy:{name:this.strategyName,description:this.description,type:this.strategyType,configuration:{selfManagedConfiguration:{historicalContextWindowSize:this.historicalContextWindowSize,invocationConfiguration:{topicArn:this.invocationConfiguration.topic.topicArn,payloadDeliveryBucketName:this.invocationConfiguration.s3Location.bucketName},triggerConditions:[{messageBasedTrigger:{messageCount:this.triggerConditions.messageBasedTrigger}},{timeBasedTrigger:{idleSessionTimeout:this.triggerConditions.timeBasedTrigger?.toSeconds()}},{tokenBasedTrigger:{tokenCount:this.triggerConditions.tokenBasedTrigger}}]}}}}}grant(grantee){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_iam_IGrantable(grantee)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.grant),error}const grant1=iam().Grant.addToPrincipal({grantee,actions:["sns:GetTopicAttributes","sns:Publish"],resourceArns:[this.invocationConfiguration.topic.topicArn]});let grant2;return this.invocationConfiguration?.s3Location&&(grant2=iam().Grant.addToPrincipal({grantee,actions:["s3:GetBucketLocation","s3:PutObject"],resourceArns:[`arn:${cdk().Aws.PARTITION}:s3:::${this.invocationConfiguration.s3Location.bucketName}`,`arn:${cdk().Aws.PARTITION}:s3:::${this.invocationConfiguration.s3Location.bucketName}/*`]})),grant1&&grant2?grant1.combine(grant2):grant1||grant2}_validateMemoryStrategyName=(name,scope)=>{let errors=[];errors.push(...(0,validation_helpers_1().validateStringFieldLength)({value:name,fieldName:"Memory name",minLength:memory_strategy_1().MEMORY_NAME_MIN_LENGTH,maxLength:memory_strategy_1().MEMORY_NAME_MAX_LENGTH},scope));const validNamePattern=/^[a-zA-Z][a-zA-Z0-9_]{0,47}$/;return errors.push(...(0,validation_helpers_1().validateFieldPattern)(name,"Memory name",validNamePattern,void 0,scope)),errors};_validateHistoricalContextWindowSize=historicalContextWindowSize=>{let errors=[];return cdk().Token.isUnresolved(historicalContextWindowSize)||(historicalContextWindowSize<HISTORICAL_CONTEXT_WINDOW_SIZE_MIN||historicalContextWindowSize>HISTORICAL_CONTEXT_WINDOW_SIZE_MAX)&&errors.push(`Historical context window size must be between ${HISTORICAL_CONTEXT_WINDOW_SIZE_MIN} and ${HISTORICAL_CONTEXT_WINDOW_SIZE_MAX}, got ${historicalContextWindowSize}`),errors};_validateTriggerConditions=triggerConditions=>{let errors=[];if(triggerConditions.messageBasedTrigger!==void 0&&!cdk().Token.isUnresolved(triggerConditions.messageBasedTrigger)&&(triggerConditions.messageBasedTrigger<MESSAGE_BASED_TRIGGER_MIN||triggerConditions.messageBasedTrigger>MESSAGE_BASED_TRIGGER_MAX)&&errors.push(`Message-based trigger must be between ${MESSAGE_BASED_TRIGGER_MIN} and ${MESSAGE_BASED_TRIGGER_MAX}, got ${triggerConditions.messageBasedTrigger}`),triggerConditions.timeBasedTrigger!==void 0&&!triggerConditions.timeBasedTrigger.isUnresolved()){const seconds=triggerConditions.timeBasedTrigger.toSeconds();(seconds<TIME_BASED_TRIGGER_MIN||seconds>TIME_BASED_TRIGGER_MAX)&&errors.push(`Time-based trigger must be between ${TIME_BASED_TRIGGER_MIN} and ${TIME_BASED_TRIGGER_MAX} seconds, got ${seconds}`)}return triggerConditions.tokenBasedTrigger!==void 0&&!cdk().Token.isUnresolved(triggerConditions.tokenBasedTrigger)&&(triggerConditions.tokenBasedTrigger<TOKEN_BASED_TRIGGER_MIN||triggerConditions.tokenBasedTrigger>TOKEN_BASED_TRIGGER_MAX)&&errors.push(`Token-based trigger must be between ${TOKEN_BASED_TRIGGER_MIN} and ${TOKEN_BASED_TRIGGER_MAX}, got ${triggerConditions.tokenBasedTrigger}`),errors}}exports.SelfManagedMemoryStrategy=SelfManagedMemoryStrategy;