(arn: string, region?: string)
| 977 | } |
| 978 | |
| 979 | private parseArn(arn: string, region?: string) { |
| 980 | /* |
| 981 | * VIA Roo analysis: platform-independent Regex. It's designed to parse Amazon Bedrock ARNs and doesn't rely on any platform-specific features |
| 982 | * like file path separators, line endings, or case sensitivity behaviors. The forward slashes in the regex are properly escaped and |
| 983 | * represent literal characters in the AWS ARN format, not filesystem paths. This regex will function consistently across Windows, |
| 984 | * macOS, Linux, and any other operating system where JavaScript runs. |
| 985 | * |
| 986 | * Supports any AWS partition (aws, aws-us-gov, aws-cn, or future partitions). |
| 987 | * The partition is not captured since we don't need to use it. |
| 988 | * |
| 989 | * This matches ARNs like: |
| 990 | * - Foundation Model: arn:aws:bedrock:us-west-2::foundation-model/anthropic.claude-v2 |
| 991 | * - GovCloud Inference Profile: arn:aws-us-gov:bedrock:us-gov-west-1:123456789012:inference-profile/us-gov.anthropic.claude-sonnet-4-5-20250929-v1:0 |
| 992 | * - Prompt Router: arn:aws:bedrock:us-west-2:123456789012:prompt-router/anthropic-claude |
| 993 | * - Inference Profile: arn:aws:bedrock:us-west-2:123456789012:inference-profile/anthropic.claude-v2 |
| 994 | * - Cross Region Inference Profile: arn:aws:bedrock:us-west-2:123456789012:inference-profile/us.anthropic.claude-3-5-sonnet-20241022-v2:0 |
| 995 | * - Custom Model (Provisioned Throughput): arn:aws:bedrock:us-west-2:123456789012:provisioned-model/my-custom-model |
| 996 | * - Imported Model: arn:aws:bedrock:us-west-2:123456789012:imported-model/my-imported-model |
| 997 | * |
| 998 | * match[0] - The entire matched string |
| 999 | * match[1] - The region (e.g., "us-east-1", "us-gov-west-1") |
| 1000 | * match[2] - The account ID (can be empty string for AWS-managed resources) |
| 1001 | * match[3] - The resource type (e.g., "foundation-model") |
| 1002 | * match[4] - The resource ID (e.g., "anthropic.claude-3-sonnet-20240229-v1:0") |
| 1003 | */ |
| 1004 | |
| 1005 | const arnRegex = /^arn:[^:]+:(?:bedrock|sagemaker):([^:]+):([^:]*):(?:([^\/]+)\/([\w\.\-:]+)|([^\/]+))$/ |
| 1006 | const match = arn.match(arnRegex) |
| 1007 | |
| 1008 | if (match && match[1] && match[3] && match[4]) { |
| 1009 | // Create the result object |
| 1010 | const result: { |
| 1011 | isValid: boolean |
| 1012 | region?: string |
| 1013 | modelType?: string |
| 1014 | modelId?: string |
| 1015 | errorMessage?: string |
| 1016 | crossRegionInference: boolean |
| 1017 | } = { |
| 1018 | isValid: true, |
| 1019 | crossRegionInference: false, // Default to false |
| 1020 | } |
| 1021 | |
| 1022 | result.modelType = match[3] |
| 1023 | const originalModelId = match[4] |
| 1024 | result.modelId = this.parseBaseModelId(originalModelId) |
| 1025 | |
| 1026 | // Extract the region from the first capture group |
| 1027 | const arnRegion = match[1] |
| 1028 | result.region = arnRegion |
| 1029 | |
| 1030 | // Check if the original model ID had a region prefix |
| 1031 | if (originalModelId && result.modelId !== originalModelId) { |
| 1032 | // If the model ID changed after parsing, it had a region prefix |
| 1033 | const prefix = originalModelId.replace(result.modelId, "") |
| 1034 | result.crossRegionInference = AwsBedrockHandler.isSystemInferenceProfile(prefix) |
| 1035 | } |
| 1036 |
no test coverage detected