aws-cdk-lib
Version:
Version 2 of the AWS Cloud Development Kit library
2 lines (1 loc) • 6.18 kB
JavaScript
;Object.defineProperty(exports,"__esModule",{value:!0}),exports.S3ToolSchema=exports.InlineToolSchema=exports.AssetToolSchema=exports.ToolSchema=exports.SchemaDefinitionType=void 0;var jsiiDeprecationWarnings=()=>{var tmp=require("../../../../../.warnings.jsii.js");return jsiiDeprecationWarnings=()=>tmp,tmp};const JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti");var base_schema_1=()=>{var tmp=require("./base-schema");return base_schema_1=()=>tmp,tmp},aws_iam_1=()=>{var tmp=require("../../../../../aws-iam");return aws_iam_1=()=>tmp,tmp},s3_assets=()=>{var tmp=require("../../../../../aws-s3-assets");return s3_assets=()=>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};class SchemaDefinitionType{static[JSII_RTTI_SYMBOL_1]={fqn:"aws-cdk-lib.aws_bedrockagentcore.SchemaDefinitionType",version:"2.257.0"};static STRING=new SchemaDefinitionType("string");static NUMBER=new SchemaDefinitionType("number");static OBJECT=new SchemaDefinitionType("object");static ARRAY=new SchemaDefinitionType("array");static BOOLEAN=new SchemaDefinitionType("boolean");static INTEGER=new SchemaDefinitionType("integer");static of(value){return new SchemaDefinitionType(value)}value;constructor(value){this.value=value}toString(){return this.value}}exports.SchemaDefinitionType=SchemaDefinitionType;class ToolSchema extends base_schema_1().TargetSchema{static[JSII_RTTI_SYMBOL_1]={fqn:"aws-cdk-lib.aws_bedrockagentcore.ToolSchema",version:"2.257.0"};static fromLocalAsset(path){return new AssetToolSchema(path)}static fromInline(schema){return new InlineToolSchema(schema)}static fromS3File(bucket,objectKey,bucketOwnerAccountId){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_s3_IBucket(bucket)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.fromS3File),error}return new S3ToolSchema({bucketName:bucket.bucketName,objectKey},bucketOwnerAccountId)}s3File;inlineSchema;bucketOwnerAccountId;constructor(s3File,bucketOwnerAccountId,inlineSchema){super();try{jsiiDeprecationWarnings().aws_cdk_lib_aws_s3_Location(s3File)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,ToolSchema),error}this.s3File=s3File,this.inlineSchema=inlineSchema,this.bucketOwnerAccountId=bucketOwnerAccountId}}exports.ToolSchema=ToolSchema;class AssetToolSchema extends ToolSchema{path;options;static[JSII_RTTI_SYMBOL_1]={fqn:"aws-cdk-lib.aws_bedrockagentcore.AssetToolSchema",version:"2.257.0"};asset;constructor(path,options={}){super(),this.path=path,this.options=options;try{jsiiDeprecationWarnings().aws_cdk_lib_aws_s3_assets_AssetOptions(options)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,AssetToolSchema),error}}bind(scope){this.asset||(this.asset=new(s3_assets()).Asset(scope,`Schema${(0,helpers_internal_1().md5hash)(this.path)}`,{path:this.path,...this.options}))}_render(){if(!this.asset)throw new(errors_1()).UnscopedValidationError((0,helpers_internal_1().lit)`ToolSchemaNotBound`,"ToolSchema must be bound to a scope before rendering. Call bind() first.");return{s3:{uri:`s3://${this.asset.s3BucketName}/${this.asset.s3ObjectKey}`}}}grantPermissionsToRole(role){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_iam_IRole(role)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.grantPermissionsToRole),error}if(!this.asset)throw new(errors_1()).UnscopedValidationError((0,helpers_internal_1().lit)`ToolSchemaNotBound`,"ToolSchema must be bound to a scope before rendering. Call bind() first.");this.asset.grantRead(role)}}exports.AssetToolSchema=AssetToolSchema;class InlineToolSchema extends ToolSchema{schema;static[JSII_RTTI_SYMBOL_1]={fqn:"aws-cdk-lib.aws_bedrockagentcore.InlineToolSchema",version:"2.257.0"};constructor(schema){super(void 0,void 0,schema),this.schema=schema}_render(){return{inlinePayload:this.schema.map(tool=>({...tool,inputSchema:this.renderSchemaDefinition(tool.inputSchema),...tool.outputSchema&&{outputSchema:this.renderSchemaDefinition(tool.outputSchema)}}))}}renderSchemaDefinition(def){return{type:def.type.value,...def.description&&{description:def.description},...def.items&&{items:this.renderSchemaDefinition(def.items)},...def.properties&&{properties:Object.fromEntries(Object.entries(def.properties).map(([k,v])=>[k,this.renderSchemaDefinition(v)]))},...def.required&&{required:def.required}}}bind(scope){}grantPermissionsToRole(_role){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_iam_IRole(_role)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.grantPermissionsToRole),error}}}exports.InlineToolSchema=InlineToolSchema;class S3ToolSchema extends ToolSchema{location;bucketOwnerAccountId;static[JSII_RTTI_SYMBOL_1]={fqn:"aws-cdk-lib.aws_bedrockagentcore.S3ToolSchema",version:"2.257.0"};constructor(location,bucketOwnerAccountId){super(location,bucketOwnerAccountId,void 0),this.location=location,this.bucketOwnerAccountId=bucketOwnerAccountId;try{jsiiDeprecationWarnings().aws_cdk_lib_aws_s3_Location(location)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,S3ToolSchema),error}}_render(){return{s3:{uri:`s3://${this.location.bucketName}/${this.location.objectKey}`,...this.bucketOwnerAccountId&&{bucketOwnerAccountId:this.bucketOwnerAccountId}}}}bind(scope){}grantPermissionsToRole(role){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_iam_IRole(role)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.grantPermissionsToRole),error}aws_iam_1().Grant.addToPrincipal({grantee:role,actions:["s3:GetObject"],resourceArns:[`arn:${core_1().Aws.PARTITION}:s3:::${this.location.bucketName}/${this.location.objectKey}`]})}}exports.S3ToolSchema=S3ToolSchema;